diff --git a/modules/juce_gui_basics/buttons/juce_ShapeButton.cpp b/modules/juce_gui_basics/buttons/juce_ShapeButton.cpp index 7d6e903195..6c58a219f1 100644 --- a/modules/juce_gui_basics/buttons/juce_ShapeButton.cpp +++ b/modules/juce_gui_basics/buttons/juce_ShapeButton.cpp @@ -24,7 +24,9 @@ ShapeButton::ShapeButton (const String& t, Colour n, Colour o, Colour d) : Button (t), - normalColour (n), overColour (o), downColour (d), + normalColour (n), overColour (o), downColour (d), + normalColourOn (n), overColourOn (o), downColourOn (d), + useOnColours(false), maintainShapeProportions (false), outlineWidth (0.0f) { @@ -35,8 +37,20 @@ ShapeButton::~ShapeButton() {} void ShapeButton::setColours (Colour newNormalColour, Colour newOverColour, Colour newDownColour) { normalColour = newNormalColour; - overColour = newOverColour; - downColour = newDownColour; + overColour = newOverColour; + downColour = newDownColour; +} + +void ShapeButton::setOnColours (Colour newNormalColourOn, Colour newOverColourOn, Colour newDownColourOn) +{ + normalColourOn = newNormalColourOn; + overColourOn = newOverColourOn; + downColourOn = newDownColourOn; +} + +void ShapeButton::shouldUseOnColours (bool shouldUse) +{ + useOnColours = shouldUse; } void ShapeButton::setOutline (Colour newOutlineColour, const float newOutlineWidth) @@ -101,9 +115,10 @@ void ShapeButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButto const AffineTransform trans (shape.getTransformToScaleToFit (r, maintainShapeProportions)); - g.setColour (isButtonDown || getToggleState() ? downColour - : isMouseOverButton ? overColour - : normalColour); + if (isButtonDown) g.setColour (getToggleState() && useOnColours ? downColourOn : downColour); + else if (isMouseOverButton) g.setColour (getToggleState() && useOnColours ? overColourOn : overColour); + else g.setColour (getToggleState() && useOnColours ? normalColourOn : normalColour); + g.fillPath (shape, trans); if (outlineWidth > 0.0f) diff --git a/modules/juce_gui_basics/buttons/juce_ShapeButton.h b/modules/juce_gui_basics/buttons/juce_ShapeButton.h index 624a231439..40329f256e 100644 --- a/modules/juce_gui_basics/buttons/juce_ShapeButton.h +++ b/modules/juce_gui_basics/buttons/juce_ShapeButton.h @@ -75,6 +75,23 @@ public: Colour overColour, Colour downColour); + /** Sets the colours to use for drawing the shape when the button's toggle state is 'on'. To enable this behaviour, use the + shouldUseOnColours() method. + + @param normalColour the colour to fill the shape with when the mouse isn't over and the button's toggle state is 'on' + @param overColour the colour to use when the mouse is over the shape and the button's toggle state is 'on' + @param downColour the colour to use when the button is in the pressed-down state and the button's toggle state is 'on' + */ + void setOnColours (Colour normalColourOn, + Colour overColourOn, + Colour downColourOn); + + /** Set whether the button should use the 'on' set of colours when its toggle state is 'on'. + By default these will be the same as the normal colours but the setOnColours method can be + used to provide a different set of colours. + */ + void shouldUseOnColours (bool shouldUse); + /** Sets up an outline to draw around the shape. @param outlineColour the colour to use @@ -92,7 +109,9 @@ public: private: //============================================================================== - Colour normalColour, overColour, downColour, outlineColour; + Colour normalColour, overColour, downColour, + normalColourOn, overColourOn, downColourOn, outlineColour; + bool useOnColours; DropShadowEffect shadow; Path shape; BorderSize border;