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.

144 lines
6.0KB

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