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.

107 lines
3.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #pragma once
  19. //==============================================================================
  20. class CurrentActivitiesComp : public Component,
  21. private ChangeListener,
  22. private ListBoxModel,
  23. private Timer
  24. {
  25. public:
  26. CurrentActivitiesComp (ActivityList& activities)
  27. : Component ("Activities"), activityList (activities)
  28. {
  29. addAndMakeVisible (&list);
  30. list.setColour (ListBox::backgroundColourId, Colours::transparentBlack);
  31. list.setRowHeight (16);
  32. list.setModel (this);
  33. activityList.addChangeListener (this);
  34. }
  35. ~CurrentActivitiesComp() override
  36. {
  37. activityList.removeChangeListener (this);
  38. }
  39. void resized() override { list.setBounds (getLocalBounds()); }
  40. int getNumRows() override
  41. {
  42. return activityList.getNumActivities();
  43. }
  44. void paintListBoxItem (int rowNumber, Graphics& g,
  45. int width, int height, bool /*rowIsSelected*/) override
  46. {
  47. const StringArray activities (activityList.getActivities());
  48. if (rowNumber >= 0 && rowNumber < activities.size())
  49. {
  50. g.setColour (findColour (defaultTextColourId));
  51. g.setFont ((float) height * 0.7f);
  52. g.drawText (activities [rowNumber],
  53. 4, 0, width - 5, height, Justification::centredLeft, true);
  54. }
  55. }
  56. void paint (Graphics& g) override
  57. {
  58. if (getNumRows() == 0)
  59. TreePanelBase::drawEmptyPanelMessage (*this, g, "(No activities)");
  60. }
  61. static int getMaxPanelHeight() { return 200; }
  62. private:
  63. ActivityList& activityList;
  64. ListBox list;
  65. int panelHeightToSet;
  66. void timerCallback() override
  67. {
  68. stopTimer();
  69. if (ConcertinaPanel* cp = findParentComponentOfClass<ConcertinaPanel>())
  70. cp->setPanelSize (this, panelHeightToSet, true);
  71. }
  72. void changeListenerCallback (ChangeBroadcaster*) override
  73. {
  74. list.updateContent();
  75. panelHeightToSet = jmax (3, getNumRows()) * list.getRowHeight() + 15;
  76. if (! isTimerRunning())
  77. startTimer (100);
  78. repaint();
  79. }
  80. };