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

Added a stretch-to-fit option to DrawableButton.

This commit is contained in:
jules 2012-09-21 13:26:08 +01:00
parent faf92ea026
commit 4fefd0bb52
2 changed files with 20 additions and 11 deletions

View file

@ -23,8 +23,7 @@
==============================================================================
*/
DrawableButton::DrawableButton (const String& name,
const DrawableButton::ButtonStyle buttonStyle)
DrawableButton::DrawableButton (const String& name, const DrawableButton::ButtonStyle buttonStyle)
: Button (name),
style (buttonStyle),
currentImage (nullptr),
@ -37,6 +36,11 @@ DrawableButton::~DrawableButton()
}
//==============================================================================
static Drawable* copyDrawableIfNotNull (const Drawable* const d)
{
return d != nullptr ? d->createCopy() : nullptr;
}
void DrawableButton::setImages (const Drawable* normal,
const Drawable* over,
const Drawable* down,
@ -48,14 +52,14 @@ void DrawableButton::setImages (const Drawable* normal,
{
jassert (normal != nullptr); // you really need to give it at least a normal image..
if (normal != nullptr) normalImage = normal->createCopy();
if (over != nullptr) overImage = over->createCopy();
if (down != nullptr) downImage = down->createCopy();
if (disabled != nullptr) disabledImage = disabled->createCopy();
if (normalOn != nullptr) normalImageOn = normalOn->createCopy();
if (overOn != nullptr) overImageOn = overOn->createCopy();
if (downOn != nullptr) downImageOn = downOn->createCopy();
if (disabledOn != nullptr) disabledImageOn = disabledOn->createCopy();
normalImage = copyDrawableIfNotNull (normal);
overImage = copyDrawableIfNotNull (over);
downImage = copyDrawableIfNotNull (down);
disabledImage = copyDrawableIfNotNull (disabled);
normalImageOn = copyDrawableIfNotNull (normalOn);
overImageOn = copyDrawableIfNotNull (overOn);
downImageOn = copyDrawableIfNotNull (downOn);
disabledImageOn = copyDrawableIfNotNull (disabledOn);
buttonStateChanged();
}
@ -87,6 +91,10 @@ void DrawableButton::resized()
{
currentImage->setOriginWithOriginalSize (Point<float>());
}
else if (style == ImageStretched)
{
currentImage->setTransformToFit (getLocalBounds().toFloat(), RectanglePlacement::stretchToFit);
}
else
{
Rectangle<int> imageSpace;

View file

@ -49,9 +49,10 @@ public:
ImageRaw, /**< The button will just display the images in their normal size and position.
This leaves it up to the caller to make sure the images are the correct size and position for the button. */
ImageAboveTextLabel, /**< Draws the button as a text label across the bottom with the image resized and scaled to fit above it. */
ImageOnButtonBackground /**< Draws the button as a standard rounded-rectangle button with the image on top.
ImageOnButtonBackground, /**< Draws the button as a standard rounded-rectangle button with the image on top.
Note that if you use this style, the colour IDs that control the button colour are
TextButton::buttonColourId and TextButton::buttonOnColourId. */
ImageStretched /**< Fills the button with a stretched version of the image. */
};
//==============================================================================