The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

102 lines
3.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. class CurrentActivitiesComp : public Component,
  18. private ChangeListener,
  19. private ListBoxModel,
  20. private Timer
  21. {
  22. public:
  23. CurrentActivitiesComp (ActivityList& activities)
  24. : Component ("Activities"), activityList (activities)
  25. {
  26. addAndMakeVisible (&list);
  27. list.setColour (ListBox::backgroundColourId, Colours::transparentBlack);
  28. list.setRowHeight (16);
  29. list.setModel (this);
  30. activityList.addChangeListener (this);
  31. }
  32. ~CurrentActivitiesComp()
  33. {
  34. activityList.removeChangeListener (this);
  35. }
  36. void resized() override { list.setBounds (getLocalBounds()); }
  37. int getNumRows() override
  38. {
  39. return activityList.getNumActivities();
  40. }
  41. void paintListBoxItem (int rowNumber, Graphics& g,
  42. int width, int height, bool /*rowIsSelected*/) override
  43. {
  44. const StringArray activities (activityList.getActivities());
  45. if (rowNumber >= 0 && rowNumber < activities.size())
  46. {
  47. g.setColour (findColour (defaultTextColourId));
  48. g.setFont (height * 0.7f);
  49. g.drawText (activities [rowNumber],
  50. 4, 0, width - 5, height, Justification::centredLeft, true);
  51. }
  52. }
  53. void paint (Graphics& g) override
  54. {
  55. if (getNumRows() == 0)
  56. TreePanelBase::drawEmptyPanelMessage (*this, g, "(No activities)");
  57. }
  58. static int getMaxPanelHeight() { return 200; }
  59. private:
  60. ActivityList& activityList;
  61. ListBox list;
  62. int panelHeightToSet;
  63. void timerCallback() override
  64. {
  65. stopTimer();
  66. if (ConcertinaPanel* cp = findParentComponentOfClass<ConcertinaPanel>())
  67. cp->setPanelSize (this, panelHeightToSet, true);
  68. }
  69. void changeListenerCallback (ChangeBroadcaster*) override
  70. {
  71. list.updateContent();
  72. panelHeightToSet = jmax (3, getNumRows()) * list.getRowHeight() + 15;
  73. if (! isTimerRunning())
  74. startTimer (100);
  75. repaint();
  76. }
  77. };