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.

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