diff --git a/modules/juce_graphics/native/juce_mac_CoreGraphicsContext.h b/modules/juce_graphics/native/juce_mac_CoreGraphicsContext.h index 055f12cae4..6a2ccaf8b1 100644 --- a/modules/juce_graphics/native/juce_mac_CoreGraphicsContext.h +++ b/modules/juce_graphics/native/juce_mac_CoreGraphicsContext.h @@ -115,6 +115,7 @@ private: void flip() const; void applyTransform (const AffineTransform& transform) const; void drawImage (const Image& sourceImage, const AffineTransform& transform, bool fillEntireClipAsTiles); + bool clipToRectangleListWithoutTest (const RectangleList&); JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CoreGraphicsContext); }; diff --git a/modules/juce_graphics/native/juce_mac_CoreGraphicsContext.mm b/modules/juce_graphics/native/juce_mac_CoreGraphicsContext.mm index 7a47b500bb..87418ac02d 100644 --- a/modules/juce_graphics/native/juce_mac_CoreGraphicsContext.mm +++ b/modules/juce_graphics/native/juce_mac_CoreGraphicsContext.mm @@ -193,7 +193,7 @@ bool CoreGraphicsContext::clipToRectangle (const Rectangle& r) return ! isClipEmpty(); } -bool CoreGraphicsContext::clipToRectangleList (const RectangleList& clipRegion) +bool CoreGraphicsContext::clipToRectangleListWithoutTest (const RectangleList& clipRegion) { if (clipRegion.isEmpty()) { @@ -205,26 +205,28 @@ bool CoreGraphicsContext::clipToRectangleList (const RectangleList& clipRegion) else { const int numRects = clipRegion.getNumRectangles(); - HeapBlock rects (numRects); - for (int i = 0; i < numRects; ++i) - { - const Rectangle& r = clipRegion.getRectangle(i); - rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()); - } + + int i = 0; + for (const Rectangle* r = clipRegion.begin(), * const e = clipRegion.end(); r != e; ++r) + rects[i++] = CGRectMake (r->getX(), flipHeight - r->getBottom(), r->getWidth(), r->getHeight()); CGContextClipToRects (context, rects, numRects); lastClipRectIsValid = false; - return ! isClipEmpty(); + return true; } } +bool CoreGraphicsContext::clipToRectangleList (const RectangleList& clipRegion) +{ + return clipToRectangleList (clipRegion) && ! isClipEmpty(); +} + void CoreGraphicsContext::excludeClipRectangle (const Rectangle& r) { RectangleList remaining (getClipBounds()); remaining.subtract (r); - clipToRectangleList (remaining); - lastClipRectIsValid = false; + clipToRectangleListWithoutTest (remaining); } void CoreGraphicsContext::clipToPath (const Path& path, const AffineTransform& transform) @@ -297,9 +299,7 @@ void CoreGraphicsContext::restoreState() { CGContextRestoreGState (context); - SavedState* const top = stateStack.getLast(); - - if (top != nullptr) + if (SavedState* const top = stateStack.getLast()) { state = top; stateStack.removeLast (1, false); @@ -557,9 +557,7 @@ void CoreGraphicsContext::setFont (const Font& newFont) state->fontRef = 0; state->font = newFont; - OSXTypeface* osxTypeface = dynamic_cast (state->font.getTypeface()); - - if (osxTypeface != nullptr) + if (OSXTypeface* osxTypeface = dynamic_cast (state->font.getTypeface())) { state->fontRef = osxTypeface->fontRef; CGContextSetFont (context, state->fontRef); @@ -791,11 +789,9 @@ Image juce_loadWithCoreImage (InputStream& input) #if JUCE_IOS JUCE_AUTORELEASEPOOL - UIImage* uiImage = [UIImage imageWithData: [NSData dataWithBytesNoCopy: data.getData() - length: data.getSize() - freeWhenDone: NO]]; - - if (uiImage != nil) + if (UIImage* uiImage = [UIImage imageWithData: [NSData dataWithBytesNoCopy: data.getData() + length: data.getSize() + freeWhenDone: NO]]) { CGImageRef loadedImage = uiImage.CGImage; diff --git a/modules/juce_gui_basics/components/juce_Component.cpp b/modules/juce_gui_basics/components/juce_Component.cpp index 5cc64c81ae..efa31027f9 100644 --- a/modules/juce_gui_basics/components/juce_Component.cpp +++ b/modules/juce_gui_basics/components/juce_Component.cpp @@ -295,8 +295,10 @@ struct Component::ComponentHelpers return r; } - static void clipObscuredRegions (const Component& comp, Graphics& g, const Rectangle& clipRect, const Point& delta) + static bool clipObscuredRegions (const Component& comp, Graphics& g, const Rectangle& clipRect, const Point& delta) { + bool nothingChanged = true; + for (int i = comp.childComponentList.size(); --i >= 0;) { const Component& child = *comp.childComponentList.getUnchecked(i); @@ -310,15 +312,19 @@ struct Component::ComponentHelpers if (child.isOpaque() && child.componentTransparency == 0) { g.excludeClipRegion (newClip + delta); + nothingChanged = false; } else { const Point childPos (child.getPosition()); - clipObscuredRegions (child, g, newClip - childPos, childPos + delta); + if (clipObscuredRegions (child, g, newClip - childPos, childPos + delta)) + nothingChanged = false; } } } } + + return nothingChanged; } static void subtractObscuredRegions (const Component& comp, RectangleList& result, @@ -1836,9 +1842,8 @@ void Component::paintComponentAndChildren (Graphics& g) else { g.saveState(); - ComponentHelpers::clipObscuredRegions (*this, g, clipBounds, Point()); - if (! g.isClipEmpty()) + if (ComponentHelpers::clipObscuredRegions (*this, g, clipBounds, Point()) || ! g.isClipEmpty()) paint (g); g.restoreState();