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.

172 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 flags = (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. void setCurrentColour (Colour newColour);
  62. //==============================================================================
  63. /** Tells the selector how many preset colour swatches you want to have on the component.
  64. To enable swatches, you'll need to override getNumSwatches(), getSwatchColour(), and
  65. setSwatchColour(), to return the number of colours you want, and to set and retrieve
  66. their values.
  67. */
  68. virtual int getNumSwatches() const;
  69. /** Called by the selector to find out the colour of one of the swatches.
  70. Your subclass should return the colour of the swatch with the given index.
  71. To enable swatches, you'll need to override getNumSwatches(), getSwatchColour(), and
  72. setSwatchColour(), to return the number of colours you want, and to set and retrieve
  73. their values.
  74. */
  75. virtual Colour getSwatchColour (int index) const;
  76. /** Called by the selector when the user puts a new colour into one of the swatches.
  77. Your subclass should change the colour of the swatch with the given index.
  78. To enable swatches, you'll need to override getNumSwatches(), getSwatchColour(), and
  79. setSwatchColour(), to return the number of colours you want, and to set and retrieve
  80. their values.
  81. */
  82. virtual void setSwatchColour (int index, const Colour& newColour) const;
  83. //==============================================================================
  84. /** A set of colour IDs to use to change the colour of various aspects of the keyboard.
  85. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  86. methods.
  87. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  88. */
  89. enum ColourIds
  90. {
  91. backgroundColourId = 0x1007000, /**< the colour used to fill the component's background. */
  92. labelTextColourId = 0x1007001 /**< the colour used for the labels next to the sliders. */
  93. };
  94. private:
  95. //==============================================================================
  96. class ColourSpaceView;
  97. class HueSelectorComp;
  98. class SwatchComponent;
  99. class ColourComponentSlider;
  100. class ColourSpaceMarker;
  101. class HueSelectorMarker;
  102. friend class ColourSpaceView;
  103. friend struct ContainerDeletePolicy<ColourSpaceView>;
  104. friend class HueSelectorComp;
  105. friend struct ContainerDeletePolicy<HueSelectorComp>;
  106. Colour colour;
  107. float h, s, v;
  108. ScopedPointer<Slider> sliders[4];
  109. ScopedPointer<ColourSpaceView> colourSpace;
  110. ScopedPointer<HueSelectorComp> hueSelector;
  111. OwnedArray<SwatchComponent> swatchComponents;
  112. const int flags;
  113. int edgeGap;
  114. Rectangle<int> previewArea;
  115. void setHue (float newH);
  116. void setSV (float newS, float newV);
  117. void updateHSV();
  118. void update();
  119. void sliderValueChanged (Slider*);
  120. void paint (Graphics&) override;
  121. void resized() override;
  122. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ColourSelector)
  123. #if JUCE_CATCH_DEPRECATED_CODE_MISUSE
  124. // This constructor is here temporarily to prevent old code compiling, because the parameters
  125. // have changed - if you get an error here, update your code to use the new constructor instead..
  126. ColourSelector (bool);
  127. #endif
  128. };
  129. #endif // JUCE_COLOURSELECTOR_H_INCLUDED