Browse Source

Added a new Graphics::drawImage method that takes a Rectangle<float>

tags/2021-05-28
jules 9 years ago
parent
commit
31f935cc60
7 changed files with 34 additions and 18 deletions
  1. +1
    -1
      examples/SimpleFFTExample/Source/SpectrogramComponent.h
  2. +1
    -4
      extras/Projucer/Source/Project/jucer_ConfigTree_Exporter.h
  3. +10
    -6
      modules/juce_graphics/contexts/juce_GraphicsContext.cpp
  4. +17
    -1
      modules/juce_graphics/contexts/juce_GraphicsContext.h
  5. +2
    -3
      modules/juce_gui_basics/native/juce_linux_Windowing.cpp
  6. +1
    -1
      modules/juce_gui_basics/widgets/juce_ImageComponent.cpp
  7. +2
    -2
      modules/juce_gui_extra/native/juce_linux_SystemTrayIcon.cpp

+ 1
- 1
examples/SimpleFFTExample/Source/SpectrogramComponent.h View File

@@ -56,7 +56,7 @@ public:
g.fillAll (Colours::black); g.fillAll (Colours::black);
g.setOpacity (1.0f); g.setOpacity (1.0f);
g.drawImageWithin (spectrogramImage, 0, 0, getWidth(), getHeight(), RectanglePlacement::stretchToFit);
g.drawImage (spectrogramImage, getLocalBounds().toFloat());
} }
void timerCallback() override void timerCallback() override


+ 1
- 4
extras/Projucer/Source/Project/jucer_ConfigTree_Exporter.h View File

@@ -46,10 +46,7 @@ public:
void paintIcon (Graphics& g, Rectangle<int> area) override void paintIcon (Graphics& g, Rectangle<int> area) override
{ {
g.setColour (Colours::black); 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 void deleteItem() override


+ 10
- 6
modules/juce_graphics/contexts/juce_GraphicsContext.cpp View File

@@ -642,18 +642,22 @@ void Graphics::drawImageAt (const Image& imageToDraw, int x, int y, bool fillAlp
fillAlphaChannel); 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()) if (imageToDraw.isValid())
drawImageTransformed (imageToDraw, drawImageTransformed (imageToDraw,
placementWithinTarget.getTransformToFit (imageToDraw.getBounds().toFloat(),
coordsToRectangle (dx, dy, dw, dh).toFloat()),
placementWithinTarget.getTransformToFit (imageToDraw.getBounds().toFloat(), targetArea),
fillAlphaChannelWithCurrentBrush); 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, void Graphics::drawImage (const Image& imageToDraw,
int dx, int dy, int dw, int dh, int dx, int dy, int dw, int dh,
int sx, int sy, int sw, int sh, int sx, int sy, int sw, int sh,


+ 17
- 1
modules/juce_graphics/contexts/juce_GraphicsContext.h View File

@@ -542,6 +542,23 @@ public:
const AffineTransform& transform, const AffineTransform& transform,
bool fillAlphaChannelWithCurrentBrush = false) const; 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. /** 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 If the image is too big or too small for the space, it will be rescaled
@@ -568,7 +585,6 @@ public:
RectanglePlacement placementWithinTarget, RectanglePlacement placementWithinTarget,
bool fillAlphaChannelWithCurrentBrush = false) const; bool fillAlphaChannelWithCurrentBrush = false) const;
//============================================================================== //==============================================================================
/** Returns the position of the bounding box for the current clipping region. /** Returns the position of the bounding box for the current clipping region.
@see getClipRegion, clipRegionIntersects @see getClipRegion, clipRegionIntersects


+ 2
- 3
modules/juce_gui_basics/native/juce_linux_Windowing.cpp View File

@@ -3962,9 +3962,8 @@ void* CustomMouseCursorInfo::create() const
hotspotX = (hotspotX * (int) cursorW) / (int) imageW; hotspotX = (hotspotX * (int) cursorW) / (int) imageW;
hotspotY = (hotspotY * (int) cursorH) / (int) imageH; 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 else
{ {


+ 1
- 1
modules/juce_gui_basics/widgets/juce_ImageComponent.cpp View File

@@ -73,5 +73,5 @@ RectanglePlacement ImageComponent::getImagePlacement() const
void ImageComponent::paint (Graphics& g) void ImageComponent::paint (Graphics& g)
{ {
g.setOpacity (1.0f); g.setOpacity (1.0f);
g.drawImageWithin (image, 0, 0, getWidth(), getHeight(), placement, false);
g.drawImage (image, getLocalBounds().toFloat(), placement);
} }

+ 2
- 2
modules/juce_gui_extra/native/juce_linux_SystemTrayIcon.cpp View File

@@ -112,8 +112,8 @@ void SystemTrayIconComponent::setIconImage (const Image& newImage)
void SystemTrayIconComponent::paint (Graphics& g) void SystemTrayIconComponent::paint (Graphics& g)
{ {
if (pimpl != nullptr) 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*/) void SystemTrayIconComponent::setIconTooltip (const String& /*tooltip*/)


Loading…
Cancel
Save