juce_BooleanPropertyComponent.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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_BOOLEANPROPERTYCOMPONENT_H_INCLUDED
  18. #define JUCE_BOOLEANPROPERTYCOMPONENT_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A PropertyComponent that contains an on/off toggle button.
  22. This type of property component can be used if you have a boolean value to
  23. toggle on/off.
  24. @see PropertyComponent
  25. */
  26. class JUCE_API BooleanPropertyComponent : public PropertyComponent,
  27. private ButtonListener // (can't use Button::Listener due to idiotic VC2005 bug)
  28. {
  29. protected:
  30. //==============================================================================
  31. /** Creates a button component.
  32. If you use this constructor, you must override the getState() and setState()
  33. methods.
  34. @param propertyName the property name to be passed to the PropertyComponent
  35. @param buttonTextWhenTrue the text shown in the button when the value is true
  36. @param buttonTextWhenFalse the text shown in the button when the value is false
  37. */
  38. BooleanPropertyComponent (const String& propertyName,
  39. const String& buttonTextWhenTrue,
  40. const String& buttonTextWhenFalse);
  41. public:
  42. /** Creates a button component.
  43. Note that if you call this constructor then you must use the Value to interact with the
  44. button state, and you can't override the class with your own setState or getState methods.
  45. If you want to use getState and setState, call the other constructor instead.
  46. @param valueToControl a Value object that this property should refer to.
  47. @param propertyName the property name to be passed to the PropertyComponent
  48. @param buttonText the text shown in the ToggleButton component
  49. */
  50. BooleanPropertyComponent (const Value& valueToControl,
  51. const String& propertyName,
  52. const String& buttonText);
  53. /** Destructor. */
  54. ~BooleanPropertyComponent();
  55. //==============================================================================
  56. /** Called to change the state of the boolean value. */
  57. virtual void setState (bool newState);
  58. /** Must return the current value of the property. */
  59. virtual bool getState() const;
  60. //==============================================================================
  61. /** A set of colour IDs to use to change the colour of various aspects of the component.
  62. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  63. methods.
  64. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  65. */
  66. enum ColourIds
  67. {
  68. backgroundColourId = 0x100e801, /**< The colour to fill the background of the button area. */
  69. outlineColourId = 0x100e803, /**< The colour to use to draw an outline around the text area. */
  70. };
  71. //==============================================================================
  72. /** @internal */
  73. void paint (Graphics&) override;
  74. /** @internal */
  75. void refresh() override;
  76. /** @internal */
  77. void buttonClicked (Button*) override;
  78. private:
  79. ToggleButton button;
  80. String onText, offText;
  81. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BooleanPropertyComponent)
  82. };
  83. #endif // JUCE_BOOLEANPROPERTYCOMPONENT_H_INCLUDED