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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 component that lets the user choose a colour.
  24. This shows RGB sliders and a colourspace that the user can pick colours from.
  25. This class is also a ChangeBroadcaster, so listeners can register to be told
  26. when the colour changes.
  27. */
  28. class JUCE_API ColourSelector : public Component,
  29. public ChangeBroadcaster,
  30. protected Slider::Listener
  31. {
  32. public:
  33. //==============================================================================
  34. /** Options for the type of selector to show. These are passed into the constructor. */
  35. enum ColourSelectorOptions
  36. {
  37. showAlphaChannel = 1 << 0, /**< if set, the colour's alpha channel can be changed as well as its RGB. */
  38. showColourAtTop = 1 << 1, /**< if set, a swatch of the colour is shown at the top of the component. */
  39. showSliders = 1 << 2, /**< if set, RGB sliders are shown at the bottom of the component. */
  40. showColourspace = 1 << 3 /**< 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();
  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. void setCurrentColour (Colour newColour, NotificationType notificationType = sendNotification);
  64. //==============================================================================
  65. /** Tells the selector how many preset colour swatches you want to have on the component.
  66. To enable swatches, you'll need to override getNumSwatches(), getSwatchColour(), and
  67. setSwatchColour(), to return the number of colours you want, and to set and retrieve
  68. their values.
  69. */
  70. virtual int getNumSwatches() const;
  71. /** Called by the selector to find out the colour of one of the swatches.
  72. Your subclass should return the colour of the swatch with the given index.
  73. To enable swatches, you'll need to override getNumSwatches(), getSwatchColour(), and
  74. setSwatchColour(), to return the number of colours you want, and to set and retrieve
  75. their values.
  76. */
  77. virtual Colour getSwatchColour (int index) const;
  78. /** Called by the selector when the user puts a new colour into one of the swatches.
  79. Your subclass should change the colour of the swatch with the given index.
  80. To enable swatches, you'll need to override getNumSwatches(), getSwatchColour(), and
  81. setSwatchColour(), to return the number of colours you want, and to set and retrieve
  82. their values.
  83. */
  84. virtual void setSwatchColour (int index, const Colour& newColour);
  85. //==============================================================================
  86. /** A set of colour IDs to use to change the colour of various aspects of the keyboard.
  87. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  88. methods.
  89. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  90. */
  91. enum ColourIds
  92. {
  93. backgroundColourId = 0x1007000, /**< the colour used to fill the component's background. */
  94. labelTextColourId = 0x1007001 /**< the colour used for the labels next to the sliders. */
  95. };
  96. private:
  97. //==============================================================================
  98. class ColourSpaceView;
  99. class HueSelectorComp;
  100. class SwatchComponent;
  101. class ColourComponentSlider;
  102. class ColourSpaceMarker;
  103. class HueSelectorMarker;
  104. friend class ColourSpaceView;
  105. friend struct ContainerDeletePolicy<ColourSpaceView>;
  106. friend class HueSelectorComp;
  107. friend struct ContainerDeletePolicy<HueSelectorComp>;
  108. Colour colour;
  109. float h, s, v;
  110. ScopedPointer<Slider> sliders[4];
  111. ScopedPointer<ColourSpaceView> colourSpace;
  112. ScopedPointer<HueSelectorComp> hueSelector;
  113. OwnedArray<SwatchComponent> swatchComponents;
  114. const int flags;
  115. int edgeGap;
  116. Rectangle<int> previewArea;
  117. void setHue (float newH);
  118. void setSV (float newS, float newV);
  119. void updateHSV();
  120. void update (NotificationType);
  121. void sliderValueChanged (Slider*) override;
  122. void paint (Graphics&) override;
  123. void resized() override;
  124. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ColourSelector)
  125. #if JUCE_CATCH_DEPRECATED_CODE_MISUSE
  126. // This constructor is here temporarily to prevent old code compiling, because the parameters
  127. // have changed - if you get an error here, update your code to use the new constructor instead..
  128. ColourSelector (bool);
  129. #endif
  130. };
  131. } // namespace juce