diff --git a/examples/SimpleFFTExample/Source/SpectrogramComponent.h b/examples/SimpleFFTExample/Source/SpectrogramComponent.h index a715eff5e3..9f9ab4d4fc 100644 --- a/examples/SimpleFFTExample/Source/SpectrogramComponent.h +++ b/examples/SimpleFFTExample/Source/SpectrogramComponent.h @@ -56,7 +56,7 @@ public: g.fillAll (Colours::black); g.setOpacity (1.0f); - g.drawImageWithin (spectrogramImage, 0, 0, getWidth(), getHeight(), RectanglePlacement::stretchToFit); + g.drawImage (spectrogramImage, getLocalBounds().toFloat()); } void timerCallback() override diff --git a/extras/Projucer/Source/Project/jucer_ConfigTree_Exporter.h b/extras/Projucer/Source/Project/jucer_ConfigTree_Exporter.h index 15be8db10b..a103cbd6b3 100644 --- a/extras/Projucer/Source/Project/jucer_ConfigTree_Exporter.h +++ b/extras/Projucer/Source/Project/jucer_ConfigTree_Exporter.h @@ -46,10 +46,7 @@ public: void paintIcon (Graphics& g, Rectangle area) override { g.setColour (Colours::black); - - g.drawImageWithin (icon, area.getX(), area.getY(), - area.getWidth(), area.getHeight(), - RectanglePlacement::centred, false); + g.drawImage (icon, area.toFloat(), RectanglePlacement::centred); } void deleteItem() override diff --git a/modules/juce_graphics/contexts/juce_GraphicsContext.cpp b/modules/juce_graphics/contexts/juce_GraphicsContext.cpp index fd45ad824e..4f3df52454 100644 --- a/modules/juce_graphics/contexts/juce_GraphicsContext.cpp +++ b/modules/juce_graphics/contexts/juce_GraphicsContext.cpp @@ -642,18 +642,22 @@ void Graphics::drawImageAt (const Image& imageToDraw, int x, int y, bool fillAlp fillAlphaChannel); } -void Graphics::drawImageWithin (const Image& imageToDraw, - int dx, int dy, int dw, int dh, - RectanglePlacement placementWithinTarget, - const bool fillAlphaChannelWithCurrentBrush) const +void Graphics::drawImage (const Image& imageToDraw, Rectangle targetArea, + RectanglePlacement placementWithinTarget, bool fillAlphaChannelWithCurrentBrush) const { if (imageToDraw.isValid()) drawImageTransformed (imageToDraw, - placementWithinTarget.getTransformToFit (imageToDraw.getBounds().toFloat(), - coordsToRectangle (dx, dy, dw, dh).toFloat()), + placementWithinTarget.getTransformToFit (imageToDraw.getBounds().toFloat(), targetArea), fillAlphaChannelWithCurrentBrush); } +void Graphics::drawImageWithin (const Image& imageToDraw, int dx, int dy, int dw, int dh, + RectanglePlacement placementWithinTarget, bool fillAlphaChannelWithCurrentBrush) const +{ + drawImage (imageToDraw, coordsToRectangle (dx, dy, dw, dh).toFloat(), + placementWithinTarget, fillAlphaChannelWithCurrentBrush); +} + void Graphics::drawImage (const Image& imageToDraw, int dx, int dy, int dw, int dh, int sx, int sy, int sw, int sh, diff --git a/modules/juce_graphics/contexts/juce_GraphicsContext.h b/modules/juce_graphics/contexts/juce_GraphicsContext.h index 9c89b9370f..98205394fd 100644 --- a/modules/juce_graphics/contexts/juce_GraphicsContext.h +++ b/modules/juce_graphics/contexts/juce_GraphicsContext.h @@ -542,6 +542,23 @@ public: const AffineTransform& transform, bool fillAlphaChannelWithCurrentBrush = false) const; + /** Draws an image to fit within a designated rectangle. + + @param imageToDraw the source image to draw + @param destArea the target rectangle to fit it into + @param placementWithinTarget this specifies how the image should be positioned + within the target rectangle - see the RectanglePlacement + class for more details about this. + @param fillAlphaChannelWithCurrentBrush if true, then instead of drawing the image, just its + alpha channel will be used as a mask with which to + draw with the current brush or colour. This is + similar to fillAlphaMap(), and see also drawImage() + @see drawImage, drawImageTransformed, drawImageAt, RectanglePlacement + */ + void drawImage (const Image& imageToDraw, Rectangle targetArea, + RectanglePlacement placementWithinTarget = RectanglePlacement::stretchToFit, + bool fillAlphaChannelWithCurrentBrush = false) const; + /** Draws an image to fit within a designated rectangle. If the image is too big or too small for the space, it will be rescaled @@ -568,7 +585,6 @@ public: RectanglePlacement placementWithinTarget, bool fillAlphaChannelWithCurrentBrush = false) const; - //============================================================================== /** Returns the position of the bounding box for the current clipping region. @see getClipRegion, clipRegionIntersects diff --git a/modules/juce_gui_basics/native/juce_linux_Windowing.cpp b/modules/juce_gui_basics/native/juce_linux_Windowing.cpp index 925ee0d5e5..5896787c9f 100644 --- a/modules/juce_gui_basics/native/juce_linux_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_linux_Windowing.cpp @@ -3962,9 +3962,8 @@ void* CustomMouseCursorInfo::create() const hotspotX = (hotspotX * (int) cursorW) / (int) imageW; hotspotY = (hotspotY * (int) cursorH) / (int) imageH; - g.drawImageWithin (image, 0, 0, (int) imageW, (int) imageH, - RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize, - false); + g.drawImage (image, Rectangle ((float) imageW, (float) imageH), + RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize); } else { diff --git a/modules/juce_gui_basics/widgets/juce_ImageComponent.cpp b/modules/juce_gui_basics/widgets/juce_ImageComponent.cpp index 86cb548705..9d75060852 100644 --- a/modules/juce_gui_basics/widgets/juce_ImageComponent.cpp +++ b/modules/juce_gui_basics/widgets/juce_ImageComponent.cpp @@ -73,5 +73,5 @@ RectanglePlacement ImageComponent::getImagePlacement() const void ImageComponent::paint (Graphics& g) { g.setOpacity (1.0f); - g.drawImageWithin (image, 0, 0, getWidth(), getHeight(), placement, false); + g.drawImage (image, getLocalBounds().toFloat(), placement); } diff --git a/modules/juce_gui_extra/native/juce_linux_SystemTrayIcon.cpp b/modules/juce_gui_extra/native/juce_linux_SystemTrayIcon.cpp index 40d6970036..a5224830c8 100644 --- a/modules/juce_gui_extra/native/juce_linux_SystemTrayIcon.cpp +++ b/modules/juce_gui_extra/native/juce_linux_SystemTrayIcon.cpp @@ -112,8 +112,8 @@ void SystemTrayIconComponent::setIconImage (const Image& newImage) void SystemTrayIconComponent::paint (Graphics& g) { if (pimpl != nullptr) - g.drawImageWithin (pimpl->image, 0, 0, getWidth(), getHeight(), - RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize, false); + g.drawImage (pimpl->image, getLocalBounds().toFloat(), + RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize); } void SystemTrayIconComponent::setIconTooltip (const String& /*tooltip*/)