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.

140 lines
6.0KB

  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. #pragma once
  18. //==============================================================================
  19. /**
  20. A base class for a component that goes in a PropertyPanel and displays one of
  21. an item's properties.
  22. Subclasses of this are used to display a property in various forms, e.g. a
  23. ChoicePropertyComponent shows its value as a combo box; a SliderPropertyComponent
  24. shows its value as a slider; a TextPropertyComponent as a text box, etc.
  25. A subclass must implement the refresh() method which will be called to tell the
  26. component to update itself, and is also responsible for calling this it when the
  27. item that it refers to is changed.
  28. @see PropertyPanel, TextPropertyComponent, SliderPropertyComponent,
  29. ChoicePropertyComponent, ButtonPropertyComponent, BooleanPropertyComponent
  30. */
  31. class JUCE_API PropertyComponent : public Component,
  32. public SettableTooltipClient
  33. {
  34. public:
  35. //==============================================================================
  36. /** Creates a PropertyComponent.
  37. @param propertyName the name is stored as this component's name, and is
  38. used as the name displayed next to this component in
  39. a property panel
  40. @param preferredHeight the height that the component should be given - some
  41. items may need to be larger than a normal row height.
  42. This value can also be set if a subclass changes the
  43. preferredHeight member variable.
  44. */
  45. PropertyComponent (const String& propertyName,
  46. int preferredHeight = 25);
  47. /** Destructor. */
  48. ~PropertyComponent();
  49. //==============================================================================
  50. /** Returns this item's preferred height.
  51. This value is specified either in the constructor or by a subclass changing the
  52. preferredHeight member variable.
  53. */
  54. int getPreferredHeight() const noexcept { return preferredHeight; }
  55. void setPreferredHeight (int newHeight) noexcept { preferredHeight = newHeight; }
  56. //==============================================================================
  57. /** Updates the property component if the item it refers to has changed.
  58. A subclass must implement this method, and other objects may call it to
  59. force it to refresh itself.
  60. The subclass should be economical in the amount of work is done, so for
  61. example it should check whether it really needs to do a repaint rather than
  62. just doing one every time this method is called, as it may be called when
  63. the value being displayed hasn't actually changed.
  64. */
  65. virtual void refresh() = 0;
  66. /** The default paint method fills the background and draws a label for the
  67. item's name.
  68. @see LookAndFeel::drawPropertyComponentBackground(), LookAndFeel::drawPropertyComponentLabel()
  69. */
  70. void paint (Graphics&) override;
  71. /** The default resize method positions any child component to the right of this
  72. one, based on the look and feel's default label size.
  73. */
  74. void resized() override;
  75. /** By default, this just repaints the component. */
  76. void enablementChanged() override;
  77. //==============================================================================
  78. /** A set of colour IDs to use to change the colour of various aspects of the combo box.
  79. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  80. methods.
  81. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  82. */
  83. enum ColourIds
  84. {
  85. backgroundColourId = 0x1008300, /**< The background colour to fill the component with. */
  86. labelTextColourId = 0x1008301, /**< The colour for the property's label text. */
  87. };
  88. //==============================================================================
  89. /** This abstract base class is implemented by LookAndFeel classes. */
  90. struct JUCE_API LookAndFeelMethods
  91. {
  92. virtual ~LookAndFeelMethods() {}
  93. virtual void drawPropertyPanelSectionHeader (Graphics&, const String& name, bool isOpen, int width, int height) = 0;
  94. virtual void drawPropertyComponentBackground (Graphics&, int width, int height, PropertyComponent&) = 0;
  95. virtual void drawPropertyComponentLabel (Graphics&, int width, int height, PropertyComponent&) = 0;
  96. virtual Rectangle<int> getPropertyComponentContentPosition (PropertyComponent&) = 0;
  97. };
  98. protected:
  99. /** Used by the PropertyPanel to determine how high this component needs to be.
  100. A subclass can update this value in its constructor but shouldn't alter it later
  101. as changes won't necessarily be picked up.
  102. */
  103. int preferredHeight;
  104. private:
  105. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PropertyComponent)
  106. };