The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

171 lines
6.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_COLOURSELECTOR_JUCEHEADER__
  19. #define __JUCE_COLOURSELECTOR_JUCEHEADER__
  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. */
  27. class JUCE_API ColourSelector : public Component,
  28. public ChangeBroadcaster,
  29. protected SliderListener
  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. showSliders = 1 << 2, /**< if set, RGB sliders are shown at the bottom of the component. */
  39. showColourspace = 1 << 3 /**< if set, a big HSV selector is shown. */
  40. };
  41. //==============================================================================
  42. /** Creates a ColourSelector object.
  43. The flags are a combination of values from the ColourSelectorOptions enum, specifying
  44. which of the selector's features should be visible.
  45. The edgeGap value specifies the amount of space to leave around the edge.
  46. gapAroundColourSpaceComponent indicates how much of a gap to put around the
  47. colourspace and hue selector components.
  48. */
  49. ColourSelector (int sectionsToShow = (showAlphaChannel | showColourAtTop | showSliders | showColourspace),
  50. int edgeGap = 4,
  51. int gapAroundColourSpaceComponent = 7);
  52. /** Destructor. */
  53. ~ColourSelector();
  54. //==============================================================================
  55. /** Returns the colour that the user has currently selected.
  56. The ColourSelector class is also a ChangeBroadcaster, so listeners can
  57. register to be told when the colour changes.
  58. @see setCurrentColour
  59. */
  60. Colour getCurrentColour() const;
  61. /** Changes the colour that is currently being shown.
  62. */
  63. void setCurrentColour (const Colour& newColour);
  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) const;
  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. friend class ColourSpaceView;
  102. friend class ScopedPointer<ColourSpaceView>;
  103. friend class HueSelectorComp;
  104. friend class ScopedPointer<HueSelectorComp>;
  105. Colour colour;
  106. float h, s, v;
  107. ScopedPointer<Slider> sliders[4];
  108. ScopedPointer<ColourSpaceView> colourSpace;
  109. ScopedPointer<HueSelectorComp> hueSelector;
  110. OwnedArray <SwatchComponent> swatchComponents;
  111. const int flags;
  112. int edgeGap;
  113. Rectangle<int> previewArea;
  114. void setHue (float newH);
  115. void setSV (float newS, float newV);
  116. void updateHSV();
  117. void update();
  118. void sliderValueChanged (Slider*);
  119. void paint (Graphics& g);
  120. void resized();
  121. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ColourSelector);
  122. #if JUCE_CATCH_DEPRECATED_CODE_MISUSE
  123. // This constructor is here temporarily to prevent old code compiling, because the parameters
  124. // have changed - if you get an error here, update your code to use the new constructor instead..
  125. ColourSelector (bool);
  126. #endif
  127. };
  128. #endif // __JUCE_COLOURSELECTOR_JUCEHEADER__