1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-09 23:34:20 +00:00

CoreGraphics: fillAll() fills a larger area to avoid alpha blended edges

Alternatively we could disable antialiasing before the fill operation
but this could cause neighbouring Components to overlap on the screen
even if their coordinates don't.
This commit is contained in:
attila 2022-09-05 11:21:34 +02:00
parent 0816dbbae7
commit c0f31aa12a
4 changed files with 24 additions and 4 deletions

View file

@ -540,18 +540,16 @@ void Graphics::fillRectList (const RectangleList<int>& rects) const
void Graphics::fillAll() const
{
fillRect (context.getClipBounds());
context.fillAll();
}
void Graphics::fillAll (Colour colourToUse) const
{
if (! colourToUse.isTransparent())
{
auto clip = context.getClipBounds();
context.saveState();
context.setFill (colourToUse);
context.fillRect (clip, false);
context.fillAll();
context.restoreState();
}
}

View file

@ -86,6 +86,7 @@ public:
virtual void setInterpolationQuality (Graphics::ResamplingQuality) = 0;
//==============================================================================
virtual void fillAll() { fillRect (getClipBounds(), false); }
virtual void fillRect (const Rectangle<int>&, bool replaceExistingContents) = 0;
virtual void fillRect (const Rectangle<float>&) = 0;
virtual void fillRectList (const RectangleList<float>&) = 0;

View file

@ -95,6 +95,7 @@ public:
void setInterpolationQuality (Graphics::ResamplingQuality) override;
//==============================================================================
void fillAll() override;
void fillRect (const Rectangle<int>&, bool replaceExistingContents) override;
void fillRect (const Rectangle<float>&) override;
void fillRectList (const RectangleList<float>&) override;

View file

@ -428,6 +428,26 @@ void CoreGraphicsContext::setInterpolationQuality (Graphics::ResamplingQuality q
}
//==============================================================================
void CoreGraphicsContext::fillAll()
{
// The clip rectangle is expanded in order to avoid having alpha blended pixels at the edges.
// The clipping mechanism will take care of cutting off pixels beyond the clip bounds. This is
// a hard cutoff and will ensure that no semi-transparent pixels will remain inside the filled
// area.
const auto clipBounds = getClipBounds();
const auto clipBoundsOnDevice = CGContextConvertSizeToDeviceSpace (context.get(),
CGSize { (CGFloat) clipBounds.getWidth(),
(CGFloat) clipBounds.getHeight() });
const auto inverseScale = clipBoundsOnDevice.width > (CGFloat) 0.0
? (int) (clipBounds.getWidth() / clipBoundsOnDevice.width)
: 0;
const auto expansion = jmax (1, inverseScale);
fillRect (clipBounds.expanded (expansion), false);
}
void CoreGraphicsContext::fillRect (const Rectangle<int>& r, bool replaceExistingContents)
{
fillCGRect (CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()), replaceExistingContents);