Audio plugin host https://kx.studio/carla
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.

juce_PropertyComponent.h 6.1KB

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