From b5a2d03a8c98a1a9986306d0ab44f5db2d11cd9b Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 24 Jun 2019 11:50:13 +0100 Subject: [PATCH] Added DrawableButton::ButtonStyle::ImageOnButtonBackgroundOriginalSize --- .../buttons/juce_DrawableButton.cpp | 22 ++++++++++++++++--- .../buttons/juce_DrawableButton.h | 18 ++++++++------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/modules/juce_gui_basics/buttons/juce_DrawableButton.cpp b/modules/juce_gui_basics/buttons/juce_DrawableButton.cpp index 66146752e7..d906d12d59 100644 --- a/modules/juce_gui_basics/buttons/juce_DrawableButton.cpp +++ b/modules/juce_gui_basics/buttons/juce_DrawableButton.cpp @@ -119,11 +119,27 @@ void DrawableButton::resized() if (currentImage != nullptr) { if (style == ImageRaw) + { currentImage->setOriginWithOriginalSize (Point()); + } else - currentImage->setTransformToFit (getImageBounds(), - style == ImageStretched ? RectanglePlacement::stretchToFit - : RectanglePlacement::centred); + { + int transformFlags = 0; + + if (style == ImageStretched) + { + transformFlags |= RectanglePlacement::stretchToFit; + } + else + { + transformFlags |= RectanglePlacement::centred; + + if (style == ImageOnButtonBackgroundOriginalSize) + transformFlags |= RectanglePlacement::doNotResize; + } + + currentImage->setTransformToFit (getImageBounds(), transformFlags); + } } } diff --git a/modules/juce_gui_basics/buttons/juce_DrawableButton.h b/modules/juce_gui_basics/buttons/juce_DrawableButton.h index 1602130e76..d826b49415 100644 --- a/modules/juce_gui_basics/buttons/juce_DrawableButton.h +++ b/modules/juce_gui_basics/buttons/juce_DrawableButton.h @@ -44,14 +44,16 @@ public: //============================================================================== enum ButtonStyle { - ImageFitted, /**< The button will just display the images, but will resize and centre them to fit inside it. */ - 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. - 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. */ + ImageFitted, /**< The button will just display the images, but will resize and centre them to fit inside it. */ + 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. The image will be resized + to match the button's proportions. + Note that if you use this style, the colour IDs that control the button colour are + TextButton::buttonColourId and TextButton::buttonOnColourId. */ + ImageOnButtonBackgroundOriginalSize, /** Same as ImageOnButtonBackground, but keeps the original image size. */ + ImageStretched /**< Fills the button with a stretched version of the image. */ }; //==============================================================================