31 scaleImageToFit (true),
32 preserveProportions (true),
42 const bool rescaleImagesWhenButtonSizeChanges,
43 const bool preserveImageProportions,
44 const Image& normalImage_,
45 const float imageOpacityWhenNormal,
46 Colour overlayColourWhenNormal,
47 const Image& overImage_,
48 const float imageOpacityWhenOver,
49 Colour overlayColourWhenOver,
50 const Image& downImage_,
51 const float imageOpacityWhenDown,
52 Colour overlayColourWhenDown,
53 const float hitTestAlphaThreshold)
55 normalImage = normalImage_;
56 overImage = overImage_;
57 downImage = downImage_;
59 if (resizeButtonNowToFitThisImage && normalImage.
isValid())
67 scaleImageToFit = rescaleImagesWhenButtonSizeChanges;
68 preserveProportions = preserveImageProportions;
70 normalOpacity = imageOpacityWhenNormal;
71 normalOverlay = overlayColourWhenNormal;
72 overOpacity = imageOpacityWhenOver;
73 overOverlay = overlayColourWhenOver;
74 downOpacity = imageOpacityWhenDown;
75 downOverlay = overlayColourWhenDown;
82Image ImageButton::getCurrentImage()
const
100 return overImage.
isValid() ? overImage
106 return downImage.
isValid() ? downImage
111 bool shouldDrawButtonAsHighlighted,
112 bool shouldDrawButtonAsDown)
116 shouldDrawButtonAsHighlighted =
false;
117 shouldDrawButtonAsDown =
false;
120 Image im (getCurrentImage());
128 int x = (w - iw) / 2;
129 int y = (h - ih) / 2;
133 if (preserveProportions)
136 const float imRatio = (
float) ih / (
float) iw;
137 const float destRatio = (
float) h / (
float) w;
139 if (imRatio > destRatio)
162 if (! scaleImageToFit)
170 const bool useDownImage = shouldDrawButtonAsDown ||
getToggleState();
173 useDownImage ? downOverlay
174 : (shouldDrawButtonAsHighlighted ? overOverlay
176 useDownImage ? downOpacity
177 : (shouldDrawButtonAsHighlighted ? overOpacity
188 if (alphaThreshold == 0)
191 Image im (getCurrentImage());
Represents a colour, also including a transparency value.
int getHeight() const noexcept
Returns the component's height in pixels.
float getAlpha() const noexcept
Returns the component's current transparency level.
void repaint()
Marks the whole component as needing to be redrawn.
virtual bool hitTest(int x, int y)
Tests whether a given point is inside the component.
void setSize(int newWidth, int newHeight)
Changes the size of the component.
int getWidth() const noexcept
Returns the component's width in pixels.
bool isEnabled() const noexcept
Returns true if the component (and all its parents) are enabled.
LookAndFeel & getLookAndFeel() const noexcept
Finds the appropriate look-and-feel to use for this component.
A graphics context, used for drawing a component or image.
Holds a fixed-size bitmap.
int getWidth() const noexcept
Returns the image's width (in pixels).
Colour getPixelAt(int x, int y) const
Returns the colour of one of the pixels in the image.
int getHeight() const noexcept
Returns the image's height (in pixels).
bool isNull() const noexcept
Returns true if this image is not valid.
bool isValid() const noexcept
Returns true if this image isn't null.
ValueType getX() const noexcept
Returns the x coordinate of the rectangle's left-hand-side.
void setSize(ValueType newWidth, ValueType newHeight) noexcept
Changes the rectangle's size, leaving the position of its top-left corner unchanged.
ValueType getWidth() const noexcept
Returns the width of the rectangle.
ValueType getY() const noexcept
Returns the y coordinate of the rectangle's top edge.
bool isEmpty() const noexcept
Returns true if the rectangle's width or height are zero or less.
ValueType getHeight() const noexcept
Returns the height of the rectangle.
void setBounds(ValueType newX, ValueType newY, ValueType newWidth, ValueType newHeight) noexcept
Changes all the rectangle's coordinates.
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Constrains a value to keep it within a given range.
unsigned char uint8
A platform-independent 8-bit unsigned integer type.
int roundToInt(const FloatType value) noexcept
Fast floating-point-to-integer conversion.