1 /*
2   ==============================================================================
3 
4    This file is part of the JUCE library.
5    Copyright (c) 2020 - Raw Material Software Limited
6 
7    JUCE is an open source library subject to commercial or open-source
8    licensing.
9 
10    By using JUCE, you agree to the terms of both the JUCE 6 End-User License
11    Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
12 
13    End User License Agreement: www.juce.com/juce-6-licence
14    Privacy Policy: www.juce.com/juce-privacy-policy
15 
16    Or: You may also use this code under the terms of the GPL v3 (see
17    www.gnu.org/licenses).
18 
19    JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20    EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21    DISCLAIMED.
22 
23   ==============================================================================
24 */
25 
26 namespace juce
27 {
28 
29 //==============================================================================
30 /**
31     A PropertyComponent that contains an on/off toggle button.
32 
33     This type of property component can be used if you have a boolean value to
34     toggle on/off.
35 
36     @see PropertyComponent
37 
38     @tags{GUI}
39 */
40 class JUCE_API  BooleanPropertyComponent  : public PropertyComponent
41 {
42 protected:
43     //==============================================================================
44     /** Creates a button component.
45 
46         If you use this constructor, you must override the getState() and setState()
47         methods.
48 
49         @param propertyName         the property name to be passed to the PropertyComponent
50         @param buttonTextWhenTrue   the text shown in the button when the value is true
51         @param buttonTextWhenFalse  the text shown in the button when the value is false
52     */
53     BooleanPropertyComponent (const String& propertyName,
54                               const String& buttonTextWhenTrue,
55                               const String& buttonTextWhenFalse);
56 
57 public:
58     /** Creates a button component.
59 
60         Note that if you call this constructor then you must use the Value to interact with the
61         button state, and you can't override the class with your own setState or getState methods.
62         If you want to use getState and setState, call the other constructor instead.
63 
64         @param valueToControl       a Value object that this property should refer to.
65         @param propertyName         the property name to be passed to the PropertyComponent
66         @param buttonText           the text shown in the ToggleButton component
67     */
68     BooleanPropertyComponent (const Value& valueToControl,
69                               const String& propertyName,
70                               const String& buttonText);
71 
72     /** Destructor. */
73     ~BooleanPropertyComponent() override;
74 
75     //==============================================================================
76     /** Called to change the state of the boolean value. */
77     virtual void setState (bool newState);
78 
79     /** Must return the current value of the property. */
80     virtual bool getState() const;
81 
82     //==============================================================================
83     /** A set of colour IDs to use to change the colour of various aspects of the component.
84 
85         These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
86         methods.
87 
88         @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
89     */
90     enum ColourIds
91     {
92         backgroundColourId          = 0x100e801,    /**< The colour to fill the background of the button area. */
93         outlineColourId             = 0x100e803,    /**< The colour to use to draw an outline around the text area. */
94     };
95 
96     //==============================================================================
97     /** @internal */
98     void paint (Graphics&) override;
99     /** @internal */
100     void refresh() override;
101 
102 private:
103     ToggleButton button;
104     String onText, offText;
105 
106     JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BooleanPropertyComponent)
107 };
108 
109 } // namespace juce
110