mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Added a new Graphics::drawImage method that takes a Rectangle<float>
This commit is contained in:
parent
3969000010
commit
31f935cc60
7 changed files with 34 additions and 18 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -46,10 +46,7 @@ public:
|
|||
void paintIcon (Graphics& g, Rectangle<int> 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
|
||||
|
|
|
|||
|
|
@ -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<float> 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,
|
||||
|
|
|
|||
|
|
@ -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<float> 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
|
||||
|
|
|
|||
|
|
@ -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> ((float) imageW, (float) imageH),
|
||||
RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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*/)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue