1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Moved DrawableButton painting into a new method LookAndFeel::drawDrawableButton()

This commit is contained in:
jules 2013-08-12 12:13:15 +01:00
parent 74390295ad
commit cfe45720cc
4 changed files with 42 additions and 29 deletions

View file

@ -175,37 +175,15 @@ void DrawableButton::paintButton (Graphics& g,
const bool isMouseOverButton,
const bool isButtonDown)
{
LookAndFeel& lf = getLookAndFeel();
if (style == ImageOnButtonBackground)
{
getLookAndFeel().drawButtonBackground (g, *this,
findColour (getToggleState() ? TextButton::buttonOnColourId
: TextButton::buttonColourId),
isMouseOverButton,
isButtonDown);
}
lf.drawButtonBackground (g, *this,
findColour (getToggleState() ? TextButton::buttonOnColourId
: TextButton::buttonColourId),
isMouseOverButton, isButtonDown);
else
{
g.fillAll (findColour (getToggleState() ? backgroundOnColourId
: backgroundColourId));
const int textH = (style == ImageAboveTextLabel)
? jmin (16, proportionOfHeight (0.25f))
: 0;
if (textH > 0)
{
g.setFont ((float) textH);
g.setColour (findColour (getToggleState() ? DrawableButton::textColourOnId
: DrawableButton::textColourId)
.withMultipliedAlpha (isEnabled() ? 1.0f : 0.4f));
g.drawFittedText (getButtonText(),
2, getHeight() - textH - 1,
getWidth() - 4, textH,
Justification::centred, 1);
}
}
lf.drawDrawableButton (g, *this, isMouseOverButton, isButtonDown);
}
//==============================================================================

View file

@ -115,6 +115,9 @@ public:
*/
void setButtonStyle (ButtonStyle newStyle);
/** Returns the current style. */
ButtonStyle getStyle() const noexcept { return style; }
//==============================================================================
/** Gives the button an optional amount of space around the edge of the drawable.
By default there's a gap of about 3 pixels.

View file

@ -447,6 +447,33 @@ void LookAndFeel::changeToggleButtonWidthToFitText (ToggleButton& button)
button.getHeight());
}
void LookAndFeel::drawDrawableButton (Graphics& g, DrawableButton& button,
bool /*isMouseOverButton*/, bool /*isButtonDown*/)
{
bool toggleState = button.getToggleState();
g.fillAll (button.findColour (toggleState ? DrawableButton::backgroundOnColourId
: DrawableButton::backgroundColourId));
const int textH = (button.getStyle() == DrawableButton::ImageAboveTextLabel)
? jmin (16, button.proportionOfHeight (0.25f))
: 0;
if (textH > 0)
{
g.setFont ((float) textH);
g.setColour (button.findColour (toggleState ? DrawableButton::textColourOnId
: DrawableButton::textColourId)
.withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.4f));
g.drawFittedText (button.getButtonText(),
2, button.getHeight() - textH - 1,
button.getWidth() - 4, textH,
Justification::centred, 1);
}
}
//==============================================================================
AlertWindow* LookAndFeel::createAlertWindow (const String& title,
const String& message,

View file

@ -182,6 +182,11 @@ public:
bool isMouseOverButton,
bool isButtonDown);
virtual void drawDrawableButton (Graphics& g,
DrawableButton& button,
bool isMouseOverButton,
bool isButtonDown);
//==============================================================================
// AlertWindow handling..