Skip to content

Commit 96224db

Browse files
committed
ImageButton: Set default image resampling quality to high
1 parent 2d36973 commit 96224db

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

modules/juce_gui_basics/buttons/juce_ImageButton.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ ImageButton::ImageButton (const String& text_)
4343
{
4444
}
4545

46-
ImageButton::~ImageButton()
47-
{
48-
}
49-
5046
void ImageButton::setImages (const bool resizeButtonNowToFitThisImage,
5147
const bool rescaleImagesWhenButtonSizeChanges,
5248
const bool preserveImageProportions,
@@ -120,6 +116,8 @@ void ImageButton::paintButton (Graphics& g,
120116
bool shouldDrawButtonAsHighlighted,
121117
bool shouldDrawButtonAsDown)
122118
{
119+
g.setImageResamplingQuality (resamplingQuality);
120+
123121
if (! isEnabled())
124122
{
125123
shouldDrawButtonAsHighlighted = false;
@@ -204,4 +202,10 @@ bool ImageButton::hitTest (int x, int y)
204202
((y - imageBounds.getY()) * im.getHeight()) / imageBounds.getHeight()).getAlpha());
205203
}
206204

205+
void ImageButton::setImageResamplingQuality (Graphics::ResamplingQuality newQuality)
206+
{
207+
if (std::exchange (resamplingQuality, newQuality) != newQuality)
208+
repaint();
209+
}
210+
207211
} // namespace juce

modules/juce_gui_basics/buttons/juce_ImageButton.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ class JUCE_API ImageButton : public Button
5959
*/
6060
explicit ImageButton (const String& name = String());
6161

62-
/** Destructor. */
63-
~ImageButton() override;
64-
6562
//==============================================================================
6663
/** Sets up the images to draw in various states.
6764
@@ -146,6 +143,15 @@ class JUCE_API ImageButton : public Button
146143
const Colour& overlayColour, float imageOpacity, ImageButton&) = 0;
147144
};
148145

146+
/** Sets the resampling quality to use when drawing the image.
147+
148+
This will have the most noticeable effect when the ImageButton size does not match the
149+
image size.
150+
151+
Defaults to highResamplingQuality.
152+
*/
153+
void setImageResamplingQuality (Graphics::ResamplingQuality newQuality);
154+
149155
protected:
150156
//==============================================================================
151157
/** @internal */
@@ -161,6 +167,7 @@ class JUCE_API ImageButton : public Button
161167
Image normalImage, overImage, downImage;
162168
float normalOpacity, overOpacity, downOpacity;
163169
Colour normalOverlay, overOverlay, downOverlay;
170+
Graphics::ResamplingQuality resamplingQuality = Graphics::ResamplingQuality::highResamplingQuality;
164171

165172
Image getCurrentImage() const;
166173

0 commit comments

Comments
 (0)