1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-15 00:24:19 +00:00

Tidied up a few bits of graphics code with Graphics::ScopedSaveState

This commit is contained in:
ed 2019-10-21 12:22:05 +01:00
parent 022e2e2bea
commit dab4741eb3
2 changed files with 22 additions and 30 deletions

View file

@ -1899,12 +1899,10 @@ void Component::paintComponentAndChildren (Graphics& g)
}
else
{
g.saveState();
Graphics::ScopedSaveState ss (g);
if (! (ComponentHelpers::clipObscuredRegions (*this, g, clipBounds, {}) && g.isClipEmpty()))
paint (g);
g.restoreState();
}
for (int i = 0; i < childComponentList.size(); ++i)
@ -1915,17 +1913,16 @@ void Component::paintComponentAndChildren (Graphics& g)
{
if (child.affineTransform != nullptr)
{
g.saveState();
Graphics::ScopedSaveState ss (g);
g.addTransform (*child.affineTransform);
if ((child.flags.dontClipGraphicsFlag && ! g.isClipEmpty()) || g.reduceClipRegion (child.getBounds()))
child.paintWithinParentContext (g);
g.restoreState();
}
else if (clipBounds.intersects (child.getBounds()))
{
g.saveState();
Graphics::ScopedSaveState ss (g);
if (child.flags.dontClipGraphicsFlag)
{
@ -1949,15 +1946,12 @@ void Component::paintComponentAndChildren (Graphics& g)
if (nothingClipped || ! g.isClipEmpty())
child.paintWithinParentContext (g);
}
g.restoreState();
}
}
}
g.saveState();
Graphics::ScopedSaveState ss (g);
paintOverChildren (g);
g.restoreState();
}
void Component::paintEntireComponent (Graphics& g, bool ignoreAlphaLevel)
@ -1989,10 +1983,10 @@ void Component::paintEntireComponent (Graphics& g, bool ignoreAlphaLevel)
paintComponentAndChildren (g2);
}
g.saveState();
Graphics::ScopedSaveState ss (g);
g.addTransform (AffineTransform::scale (1.0f / scale));
effect->applyEffect (effectImage, g, scale, ignoreAlphaLevel ? 1.0f : getAlpha());
g.restoreState();
}
else if (componentTransparency > 0 && ! ignoreAlphaLevel)
{

View file

@ -774,15 +774,16 @@ void LookAndFeel_V2::drawScrollbar (Graphics& g,
g.setGradientFill (ColourGradient (Colour (0x10000000), gx1, gy1,
Colours::transparentBlack, gx2, gy2, false));
g.saveState();
{
Graphics::ScopedSaveState ss (g);
if (isScrollbarVertical)
g.reduceClipRegion (x + width / 2, y, width, height);
else
g.reduceClipRegion (x, y + height / 2, width, height);
if (isScrollbarVertical)
g.reduceClipRegion (x + width / 2, y, width, height);
else
g.reduceClipRegion (x, y + height / 2, width, height);
g.fillPath (thumbPath);
g.restoreState();
g.fillPath (thumbPath);
}
g.setColour (Colour (0x4c000000));
g.strokePath (thumbPath, PathStrokeType (0.4f));
@ -1735,7 +1736,8 @@ void LookAndFeel_V2::drawResizableFrame (Graphics& g, int w, int h, const Border
const Rectangle<int> fullSize (0, 0, w, h);
auto centreArea = border.subtractedFrom (fullSize);
g.saveState();
Graphics::ScopedSaveState ss (g);
g.excludeClipRegion (centreArea);
g.setColour (Colour (0x50000000));
@ -1743,8 +1745,6 @@ void LookAndFeel_V2::drawResizableFrame (Graphics& g, int w, int h, const Border
g.setColour (Colour (0x19000000));
g.drawRect (centreArea.expanded (1, 1));
g.restoreState();
}
}
@ -2834,7 +2834,7 @@ void LookAndFeel_V2::drawBevel (Graphics& g, const int x, const int y, const int
if (g.clipRegionIntersects (Rectangle<int> (x, y, width, height)))
{
auto& context = g.getInternalContext();
context.saveState();
Graphics::ScopedSaveState ss (g);
for (int i = bevelThickness; --i >= 0;)
{
@ -2850,8 +2850,6 @@ void LookAndFeel_V2::drawBevel (Graphics& g, const int x, const int y, const int
context.setFill (bottomRightColour.withMultipliedAlpha (op * 0.75f));
context.fillRect (Rectangle<int> (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
}
context.restoreState();
}
}
@ -3015,11 +3013,11 @@ void LookAndFeel_V2::drawGlassLozenge (Graphics& g,
if (! (flatOnLeft || flatOnTop || flatOnBottom))
{
g.saveState();
Graphics::ScopedSaveState ss (g);
g.setGradientFill (cg);
g.reduceClipRegion (intX, intY, intEdge, intH);
g.fillPath (outline);
g.restoreState();
}
if (! (flatOnRight || flatOnTop || flatOnBottom))
@ -3027,11 +3025,11 @@ void LookAndFeel_V2::drawGlassLozenge (Graphics& g,
cg.point1.setX (x + width - edgeBlurRadius);
cg.point2.setX (x + width);
g.saveState();
Graphics::ScopedSaveState ss (g);
g.setGradientFill (cg);
g.reduceClipRegion (intX + intW - intEdge, intY, 2 + intEdge, intH);
g.fillPath (outline);
g.restoreState();
}
{