Browse Source

Added an optional border size to ShapeButton.

tags/2021-05-28
jules 11 years ago
parent
commit
286c256eeb
2 changed files with 19 additions and 16 deletions
  1. +12
    -14
      modules/juce_gui_basics/buttons/juce_ShapeButton.cpp
  2. +7
    -2
      modules/juce_gui_basics/buttons/juce_ShapeButton.h

+ 12
- 14
modules/juce_gui_basics/buttons/juce_ShapeButton.cpp View File

@@ -24,34 +24,32 @@
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),
maintainShapeProportions (false),
outlineWidth (0.0f)
{
}
ShapeButton::~ShapeButton()
{
}
ShapeButton::~ShapeButton() {}
void ShapeButton::setColours (Colour newNormalColour,
Colour newOverColour,
Colour newDownColour)
void ShapeButton::setColours (Colour newNormalColour, Colour newOverColour, Colour newDownColour)
{
normalColour = newNormalColour;
overColour = newOverColour;
downColour = newDownColour;
}
void ShapeButton::setOutline (Colour newOutlineColour,
const float newOutlineWidth)
void ShapeButton::setOutline (Colour newOutlineColour, const float newOutlineWidth)
{
outlineColour = newOutlineColour;
outlineWidth = newOutlineWidth;
}
void ShapeButton::setBorderSize (BorderSize<int> newBorder)
{
border = newBorder;
}
void ShapeButton::setShape (const Path& newShape,
const bool resizeNowToFitThisShape,
const bool maintainShapeProportions_,
@@ -73,8 +71,8 @@ void ShapeButton::setShape (const Path& newShape,
shape.applyTransform (AffineTransform::translation (-newBounds.getX(),
-newBounds.getY()));
setSize (1 + (int) (newBounds.getWidth() + outlineWidth),
1 + (int) (newBounds.getHeight() + outlineWidth));
setSize (1 + (int) (newBounds.getWidth() + outlineWidth) + border.getLeftAndRight(),
1 + (int) (newBounds.getHeight() + outlineWidth) + border.getTopAndBottom());
}
repaint();
@@ -88,7 +86,7 @@ void ShapeButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButto
isButtonDown = false;
}
Rectangle<float> r (getLocalBounds().toFloat().reduced (outlineWidth * 0.5f));
Rectangle<float> r (border.subtractedFrom (getLocalBounds()).toFloat().reduced (outlineWidth * 0.5f));
if (getComponentEffect() != nullptr)
r = r.reduced (2.0f);


+ 7
- 2
modules/juce_gui_basics/buttons/juce_ShapeButton.h View File

@@ -80,8 +80,12 @@ public:
@param outlineColour the colour to use
@param outlineStrokeWidth the thickness of line to draw
*/
void setOutline (Colour outlineColour,
float outlineStrokeWidth);
void setOutline (Colour outlineColour, float outlineStrokeWidth);
/** This lets you specify a border to be left around the edge of the button when
drawing the shape.
*/
void setBorderSize (BorderSize<int> border);
/** @internal */
void paintButton (Graphics&, bool isMouseOverButton, bool isButtonDown) override;
@@ -91,6 +95,7 @@ private:
Colour normalColour, overColour, downColour, outlineColour;
DropShadowEffect shadow;
Path shape;
BorderSize<int> border;
bool maintainShapeProportions;
float outlineWidth;


Loading…
Cancel
Save