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.

92 lines
3.0KB

  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. BEGIN_JUCE_NAMESPACE
  19. //==============================================================================
  20. BooleanPropertyComponent::BooleanPropertyComponent (const String& name,
  21. const String& buttonTextWhenTrue,
  22. const String& buttonTextWhenFalse)
  23. : PropertyComponent (name),
  24. onText (buttonTextWhenTrue),
  25. offText (buttonTextWhenFalse)
  26. {
  27. addAndMakeVisible (&button);
  28. button.setClickingTogglesState (false);
  29. button.addListener (this);
  30. }
  31. BooleanPropertyComponent::BooleanPropertyComponent (const Value& valueToControl,
  32. const String& name,
  33. const String& buttonText)
  34. : PropertyComponent (name),
  35. onText (buttonText),
  36. offText (buttonText)
  37. {
  38. addAndMakeVisible (&button);
  39. button.setClickingTogglesState (false);
  40. button.setButtonText (buttonText);
  41. button.getToggleStateValue().referTo (valueToControl);
  42. button.setClickingTogglesState (true);
  43. }
  44. BooleanPropertyComponent::~BooleanPropertyComponent()
  45. {
  46. }
  47. void BooleanPropertyComponent::setState (const bool newState)
  48. {
  49. button.setToggleState (newState, true);
  50. }
  51. bool BooleanPropertyComponent::getState() const
  52. {
  53. return button.getToggleState();
  54. }
  55. void BooleanPropertyComponent::paint (Graphics& g)
  56. {
  57. PropertyComponent::paint (g);
  58. g.setColour (Colours::white);
  59. g.fillRect (button.getBounds());
  60. g.setColour (findColour (ComboBox::outlineColourId));
  61. g.drawRect (button.getBounds());
  62. }
  63. void BooleanPropertyComponent::refresh()
  64. {
  65. button.setToggleState (getState(), false);
  66. button.setButtonText (button.getToggleState() ? onText : offText);
  67. }
  68. void BooleanPropertyComponent::buttonClicked (Button*)
  69. {
  70. setState (! getState());
  71. }
  72. END_JUCE_NAMESPACE