Browse Source

Added methods to ShapeButton to allow a different set of normal/over/down colours to be used when the button's toggle state is 'on'

tags/2021-05-28
ed 8 years ago
parent
commit
c6075dec27
2 changed files with 41 additions and 7 deletions
  1. +21
    -6
      modules/juce_gui_basics/buttons/juce_ShapeButton.cpp
  2. +20
    -1
      modules/juce_gui_basics/buttons/juce_ShapeButton.h

+ 21
- 6
modules/juce_gui_basics/buttons/juce_ShapeButton.cpp View File

@@ -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)


+ 20
- 1
modules/juce_gui_basics/buttons/juce_ShapeButton.h View File

@@ -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<int> border;


Loading…
Cancel
Save