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_ColourSelector.h 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. /**
  22. A component that lets the user choose a colour.
  23. This shows RGB sliders and a colourspace that the user can pick colours from.
  24. This class is also a ChangeBroadcaster, so listeners can register to be told
  25. when the colour changes.
  26. @tags{GUI}
  27. */
  28. class JUCE_API ColourSelector : public Component,
  29. public ChangeBroadcaster
  30. {
  31. public:
  32. //==============================================================================
  33. /** Options for the type of selector to show. These are passed into the constructor. */
  34. enum ColourSelectorOptions
  35. {
  36. showAlphaChannel = 1 << 0, /**< if set, the colour's alpha channel can be changed as well as its RGB. */
  37. showColourAtTop = 1 << 1, /**< if set, a swatch of the colour is shown at the top of the component. */
  38. editableColour = 1 << 2, /**< if set, the colour shows at the top of the component is editable. */
  39. showSliders = 1 << 3, /**< if set, RGB sliders are shown at the bottom of the component. */
  40. showColourspace = 1 << 4 /**< if set, a big HSV selector is shown. */
  41. };
  42. //==============================================================================
  43. /** Creates a ColourSelector object.
  44. The flags are a combination of values from the ColourSelectorOptions enum, specifying
  45. which of the selector's features should be visible.
  46. The edgeGap value specifies the amount of space to leave around the edge.
  47. gapAroundColourSpaceComponent indicates how much of a gap to put around the
  48. colourspace and hue selector components.
  49. */
  50. ColourSelector (int flags = (showAlphaChannel | showColourAtTop | showSliders | showColourspace),
  51. int edgeGap = 4,
  52. int gapAroundColourSpaceComponent = 7);
  53. /** Destructor. */
  54. ~ColourSelector() override;
  55. //==============================================================================
  56. /** Returns the colour that the user has currently selected.
  57. The ColourSelector class is also a ChangeBroadcaster, so listeners can
  58. register to be told when the colour changes.
  59. @see setCurrentColour
  60. */
  61. Colour getCurrentColour() const;
  62. /** Changes the colour that is currently being shown.
  63. @param newColour the new colour to show
  64. @param notificationType whether to send a notification of the change to listeners.
  65. A notification will only be sent if the colour has changed.
  66. */
  67. void setCurrentColour (Colour newColour, NotificationType notificationType = sendNotification);
  68. //==============================================================================
  69. /** Tells the selector how many preset colour swatches you want to have on the component.
  70. To enable swatches, you'll need to override getNumSwatches(), getSwatchColour(), and
  71. setSwatchColour(), to return the number of colours you want, and to set and retrieve
  72. their values.
  73. */
  74. virtual int getNumSwatches() const;
  75. /** Called by the selector to find out the colour of one of the swatches.
  76. Your subclass should return the colour of the swatch with the given index.
  77. To enable swatches, you'll need to override getNumSwatches(), getSwatchColour(), and
  78. setSwatchColour(), to return the number of colours you want, and to set and retrieve
  79. their values.
  80. */
  81. virtual Colour getSwatchColour (int index) const;
  82. /** Called by the selector when the user puts a new colour into one of the swatches.
  83. Your subclass should change the colour of the swatch with the given index.
  84. To enable swatches, you'll need to override getNumSwatches(), getSwatchColour(), and
  85. setSwatchColour(), to return the number of colours you want, and to set and retrieve
  86. their values.
  87. */
  88. virtual void setSwatchColour (int index, const Colour& newColour);
  89. //==============================================================================
  90. /** A set of colour IDs to use to change the colour of various aspects of the keyboard.
  91. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  92. methods.
  93. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  94. */
  95. enum ColourIds
  96. {
  97. backgroundColourId = 0x1007000, /**< the colour used to fill the component's background. */
  98. labelTextColourId = 0x1007001 /**< the colour used for the labels next to the sliders. */
  99. };
  100. //==============================================================================
  101. // These need to be public otherwise the Projucer's live-build engine will complain
  102. class ColourSpaceView;
  103. class HueSelectorComp;
  104. class ColourPreviewComp;
  105. private:
  106. //==============================================================================
  107. class SwatchComponent;
  108. Colour colour;
  109. float h, s, v;
  110. std::unique_ptr<Slider> sliders[4];
  111. std::unique_ptr<ColourSpaceView> colourSpace;
  112. std::unique_ptr<HueSelectorComp> hueSelector;
  113. std::unique_ptr<ColourPreviewComp> previewComponent;
  114. OwnedArray<SwatchComponent> swatchComponents;
  115. const int flags;
  116. int edgeGap;
  117. void setHue (float newH);
  118. void setSV (float newS, float newV);
  119. void updateHSV();
  120. void update (NotificationType);
  121. void changeColour();
  122. void paint (Graphics&) override;
  123. void resized() override;
  124. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ColourSelector)
  125. };
  126. } // namespace juce