Browse Source

Added DrawableButton::ButtonStyle::ImageOnButtonBackgroundOriginalSize

tags/2021-05-28
ed 6 years ago
parent
commit
b5a2d03a8c
2 changed files with 29 additions and 11 deletions
  1. +19
    -3
      modules/juce_gui_basics/buttons/juce_DrawableButton.cpp
  2. +10
    -8
      modules/juce_gui_basics/buttons/juce_DrawableButton.h

+ 19
- 3
modules/juce_gui_basics/buttons/juce_DrawableButton.cpp View File

@@ -119,11 +119,27 @@ void DrawableButton::resized()
if (currentImage != nullptr)
{
if (style == ImageRaw)
{
currentImage->setOriginWithOriginalSize (Point<float>());
}
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);
}
}
}


+ 10
- 8
modules/juce_gui_basics/buttons/juce_DrawableButton.h View File

@@ -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. */
};
//==============================================================================


Loading…
Cancel
Save