diff --git a/modules/juce_gui_basics/buttons/juce_DrawableButton.cpp b/modules/juce_gui_basics/buttons/juce_DrawableButton.cpp index 3a3ec96ce7..74b7e1248d 100644 --- a/modules/juce_gui_basics/buttons/juce_DrawableButton.cpp +++ b/modules/juce_gui_basics/buttons/juce_DrawableButton.cpp @@ -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); } //============================================================================== diff --git a/modules/juce_gui_basics/buttons/juce_DrawableButton.h b/modules/juce_gui_basics/buttons/juce_DrawableButton.h index a9187a8f73..34a286202d 100644 --- a/modules/juce_gui_basics/buttons/juce_DrawableButton.h +++ b/modules/juce_gui_basics/buttons/juce_DrawableButton.h @@ -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. diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp index 0f4513ff07..4140ce6459 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp @@ -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, diff --git a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.h b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.h index c02a32dcf4..2dee7eb00c 100644 --- a/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.h +++ b/modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.h @@ -182,6 +182,11 @@ public: bool isMouseOverButton, bool isButtonDown); + virtual void drawDrawableButton (Graphics& g, + DrawableButton& button, + bool isMouseOverButton, + bool isButtonDown); + //============================================================================== // AlertWindow handling..