Browse Source

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

tags/2021-05-28
jules 12 years ago
parent
commit
cfe45720cc
4 changed files with 42 additions and 29 deletions
  1. +7
    -29
      modules/juce_gui_basics/buttons/juce_DrawableButton.cpp
  2. +3
    -0
      modules/juce_gui_basics/buttons/juce_DrawableButton.h
  3. +27
    -0
      modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp
  4. +5
    -0
      modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.h

+ 7
- 29
modules/juce_gui_basics/buttons/juce_DrawableButton.cpp 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);
}
//==============================================================================


+ 3
- 0
modules/juce_gui_basics/buttons/juce_DrawableButton.h 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.


+ 27
- 0
modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.cpp 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,


+ 5
- 0
modules/juce_gui_basics/lookandfeel/juce_LookAndFeel.h View File

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


Loading…
Cancel
Save