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.

173 lines
6.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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_COLOURSELECTOR_H_INCLUDED
  18. #define JUCE_COLOURSELECTOR_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A component that lets the user choose a colour.
  22. This shows RGB sliders and a colourspace that the user can pick colours from.
  23. This class is also a ChangeBroadcaster, so listeners can register to be told
  24. when the colour changes.
  25. */
  26. class JUCE_API ColourSelector : public Component,
  27. public ChangeBroadcaster,
  28. protected SliderListener
  29. {
  30. public:
  31. //==============================================================================
  32. /** Options for the type of selector to show. These are passed into the constructor. */
  33. enum ColourSelectorOptions
  34. {
  35. showAlphaChannel = 1 << 0, /**< if set, the colour's alpha channel can be changed as well as its RGB. */
  36. showColourAtTop = 1 << 1, /**< if set, a swatch of the colour is shown at the top of the component. */
  37. showSliders = 1 << 2, /**< if set, RGB sliders are shown at the bottom of the component. */
  38. showColourspace = 1 << 3 /**< if set, a big HSV selector is shown. */
  39. };
  40. //==============================================================================
  41. /** Creates a ColourSelector object.
  42. The flags are a combination of values from the ColourSelectorOptions enum, specifying
  43. which of the selector's features should be visible.
  44. The edgeGap value specifies the amount of space to leave around the edge.
  45. gapAroundColourSpaceComponent indicates how much of a gap to put around the
  46. colourspace and hue selector components.
  47. */
  48. ColourSelector (int sectionsToShow = (showAlphaChannel | showColourAtTop | showSliders | showColourspace),
  49. int edgeGap = 4,
  50. int gapAroundColourSpaceComponent = 7);
  51. /** Destructor. */
  52. ~ColourSelector();
  53. //==============================================================================
  54. /** Returns the colour that the user has currently selected.
  55. The ColourSelector class is also a ChangeBroadcaster, so listeners can
  56. register to be told when the colour changes.
  57. @see setCurrentColour
  58. */
  59. Colour getCurrentColour() const;
  60. /** Changes the colour that is currently being shown.
  61. */
  62. void setCurrentColour (Colour newColour);
  63. //==============================================================================
  64. /** Tells the selector how many preset colour swatches you want to have on the component.
  65. To enable swatches, you'll need to override getNumSwatches(), getSwatchColour(), and
  66. setSwatchColour(), to return the number of colours you want, and to set and retrieve
  67. their values.
  68. */
  69. virtual int getNumSwatches() const;
  70. /** Called by the selector to find out the colour of one of the swatches.
  71. Your subclass should return the colour of the swatch with the given index.
  72. To enable swatches, you'll need to override getNumSwatches(), getSwatchColour(), and
  73. setSwatchColour(), to return the number of colours you want, and to set and retrieve
  74. their values.
  75. */
  76. virtual Colour getSwatchColour (int index) const;
  77. /** Called by the selector when the user puts a new colour into one of the swatches.
  78. Your subclass should change the colour of the swatch with the given index.
  79. To enable swatches, you'll need to override getNumSwatches(), getSwatchColour(), and
  80. setSwatchColour(), to return the number of colours you want, and to set and retrieve
  81. their values.
  82. */
  83. virtual void setSwatchColour (int index, const Colour& newColour) const;
  84. //==============================================================================
  85. /** A set of colour IDs to use to change the colour of various aspects of the keyboard.
  86. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  87. methods.
  88. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  89. */
  90. enum ColourIds
  91. {
  92. backgroundColourId = 0x1007000, /**< the colour used to fill the component's background. */
  93. labelTextColourId = 0x1007001 /**< the colour used for the labels next to the sliders. */
  94. };
  95. private:
  96. //==============================================================================
  97. class ColourSpaceView;
  98. class HueSelectorComp;
  99. class SwatchComponent;
  100. class ColourComponentSlider;
  101. class ColourSpaceMarker;
  102. class HueSelectorMarker;
  103. friend class ColourSpaceView;
  104. friend struct ContainerDeletePolicy<ColourSpaceView>;
  105. friend class HueSelectorComp;
  106. friend struct ContainerDeletePolicy<HueSelectorComp>;
  107. Colour colour;
  108. float h, s, v;
  109. ScopedPointer<Slider> sliders[4];
  110. ScopedPointer<ColourSpaceView> colourSpace;
  111. ScopedPointer<HueSelectorComp> hueSelector;
  112. OwnedArray <SwatchComponent> swatchComponents;
  113. const int flags;
  114. int edgeGap;
  115. Rectangle<int> previewArea;
  116. void setHue (float newH);
  117. void setSV (float newS, float newV);
  118. void updateHSV();
  119. void update();
  120. void sliderValueChanged (Slider*);
  121. void paint (Graphics&) override;
  122. void resized() override;
  123. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ColourSelector)
  124. #if JUCE_CATCH_DEPRECATED_CODE_MISUSE
  125. // This constructor is here temporarily to prevent old code compiling, because the parameters
  126. // have changed - if you get an error here, update your code to use the new constructor instead..
  127. ColourSelector (bool);
  128. #endif
  129. };
  130. #endif // JUCE_COLOURSELECTOR_H_INCLUDED