diff --git a/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp b/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp index 78da78f..08f51cc 100644 --- a/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp +++ b/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp @@ -482,6 +482,41 @@ private: Component* createIntegerSlider (LivePropertyEditorBase& editor) { return new SliderComp (editor, false); } Component* createFloatSlider (LivePropertyEditorBase& editor) { return new SliderComp (editor, true); } +//============================================================================== +class BoolSliderComp +: public Component +, private Slider::Listener +{ +public: + BoolSliderComp (LivePropertyEditorBase& e) + : editor (e) + { + slider.setTextBoxStyle (Slider::NoTextBox, true, 0, 0); + addAndMakeVisible (slider); + slider.setRange(0, 1); + slider.addListener (this); + } + +private: + LivePropertyEditorBase& editor; + Slider slider; + + void sliderValueChanged (Slider*) + { + editor.applyNewValue (slider.getValue() == 1 ? "true" : "false"); + } + + void sliderDragStarted (Slider*) {} + void sliderDragEnded (Slider*) {} + + void resized() + { + slider.setBounds (getLocalBounds().removeFromTop (25)); + } +}; + +Component* createBoolSlider (LivePropertyEditorBase& editor) { return new BoolSliderComp (editor); } + } #endif diff --git a/modules/juce_gui_extra/misc/juce_LiveConstantEditor.h b/modules/juce_gui_extra/misc/juce_LiveConstantEditor.h index 20deb09..c43a814 100644 --- a/modules/juce_gui_extra/misc/juce_LiveConstantEditor.h +++ b/modules/juce_gui_extra/misc/juce_LiveConstantEditor.h @@ -54,6 +54,7 @@ namespace LiveConstantEditor inline void setFromString (float& v, const String& s) { v = (float) parseDouble (s); } inline void setFromString (String& v, const String& s) { v = s; } inline void setFromString (Colour& v, const String& s) { v = Colour ((uint32) parseInt (s)); } + inline void setFromString (bool& v, const String& s) { v = (s == "true"); } template inline String getAsString (const Type& v, bool) { return String (v); } @@ -66,6 +67,7 @@ namespace LiveConstantEditor inline String getAsString (int64 v, bool preferHex) { return intToString ((int64) v, preferHex); } inline String getAsString (uint64 v, bool preferHex) { return intToString ((int64) v, preferHex); } inline String getAsString (Colour v, bool) { return intToString ((int) v.getARGB(), true); } + inline String getAsString (bool v, bool) { return v ? String("true") : String("false"); } template struct isStringType { enum { value = 0 }; }; template <> struct isStringType { enum { value = 1 }; }; @@ -135,6 +137,7 @@ namespace LiveConstantEditor Component* createColourEditor (LivePropertyEditorBase&); Component* createIntegerSlider (LivePropertyEditorBase&); Component* createFloatSlider (LivePropertyEditorBase&); + Component* createBoolSlider (LivePropertyEditorBase&); template struct CustomEditor { static Component* create (LivePropertyEditorBase&) { return nullptr; } }; template<> struct CustomEditor { static Component* create (LivePropertyEditorBase& e) { return createIntegerSlider (e); } }; @@ -148,6 +151,7 @@ namespace LiveConstantEditor template<> struct CustomEditor { static Component* create (LivePropertyEditorBase& e) { return createFloatSlider (e); } }; template<> struct CustomEditor { static Component* create (LivePropertyEditorBase& e) { return createFloatSlider (e); } }; template<> struct CustomEditor { static Component* create (LivePropertyEditorBase& e) { return createColourEditor (e); } }; + template<> struct CustomEditor { static Component* create (LivePropertyEditorBase& e) { return createBoolSlider (e); } }; template struct LivePropertyEditor : public LivePropertyEditorBase