You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCETICE project - Copyright 2009 by Lucio Asnaghi.
  4. JUCETICE is based around the JUCE library - "Jules' Utility Class Extensions"
  5. Copyright 2007 by Julian Storer.
  6. ------------------------------------------------------------------------------
  7. JUCE and JUCETICE can be redistributed and/or modified under the terms of
  8. the GNU General Public License, as published by the Free Software Foundation;
  9. either version 2 of the License, or (at your option) any later version.
  10. JUCE and JUCETICE are distributed in the hope that they will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with JUCE and JUCETICE; if not, visit www.gnu.org/licenses or write to
  16. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  17. Boston, MA 02111-1307 USA
  18. ==============================================================================
  19. */
  20. BEGIN_JUCE_NAMESPACE
  21. #include "jucetice_PianoGrid.h"
  22. //==============================================================================
  23. PianoGridHeader::PianoGridHeader (MidiGrid* owner_)
  24. : owner (owner_)
  25. {
  26. setOpaque (true);
  27. }
  28. PianoGridHeader::~PianoGridHeader()
  29. {
  30. }
  31. void PianoGridHeader::mouseUp (const MouseEvent& e)
  32. {
  33. owner->notifyListenersOfPlayingPositionChanged (e.x / (float) getWidth());
  34. }
  35. void PianoGridHeader::paint (Graphics& g)
  36. {
  37. int numBars = owner->getNumBars ();
  38. int numBeats = owner->getTimeDivision ();
  39. int barWidth = getWidth () / numBars;
  40. int beatWidth = barWidth / numBeats;
  41. Colour backCol = findColour (PianoGrid::headerColourId);
  42. g.fillAll (backCol);
  43. g.setColour (backCol.contrasting ());
  44. for (int i = 0; i < numBars; i++)
  45. {
  46. g.setFont (Font (10.0f, Font::plain));
  47. g.drawText (String (i + 1),
  48. barWidth * i + 1, 0, 22, getHeight(),
  49. Justification::centredLeft,
  50. false);
  51. if (barWidth >= 80)
  52. {
  53. g.setFont (Font (8.0f, Font::plain));
  54. for (int j = 1; j < numBeats; j++)
  55. {
  56. g.drawText (String (j + 1) + "/" + String (numBeats),
  57. barWidth * i + beatWidth * j - 2, 0, 18, getHeight(),
  58. Justification::bottomLeft,
  59. false);
  60. }
  61. }
  62. }
  63. }
  64. END_JUCE_NAMESPACE