From 66b926e0cf63da0765a3eb4b4b25bf2357d76e52 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Fri, 30 May 2008 16:47:45 +0000 Subject: [PATCH] fixing a problem where CoreGraphics didn't correctly clip to an empty region git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@53845 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/mac/carbon/graphics.cpp | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/mac/carbon/graphics.cpp b/src/mac/carbon/graphics.cpp index 2c9c1dad3d..0119269f1c 100755 --- a/src/mac/carbon/graphics.cpp +++ b/src/mac/carbon/graphics.cpp @@ -1345,9 +1345,6 @@ void wxMacCoreGraphicsContext::Init() m_cgContext = NULL; m_releaseContext = false; m_windowRef = NULL; - - HIRect r = CGRectMake(0,0,0,0); - m_clipRgn.Set(HIShapeCreateWithRect(&r)); } wxMacCoreGraphicsContext::wxMacCoreGraphicsContext( wxGraphicsRenderer* renderer, CGContextRef cgcontext ) : wxGraphicsContext(renderer) @@ -1408,7 +1405,7 @@ void wxMacCoreGraphicsContext::EnsureIsValid() CGContextConcatCTM( m_cgContext, m_windowTransform ); CGContextSaveGState( m_cgContext ); m_releaseContext = true; - if ( !HIShapeIsEmpty(m_clipRgn) ) + if ( (HIShapeRef) m_clipRgn != NULL ) { // the clip region is in device coordinates, so we convert this again to user coordinates wxMacCFRefHolder hishape ; @@ -1416,7 +1413,17 @@ void wxMacCoreGraphicsContext::EnsureIsValid() CGPoint transformedOrigin = CGPointApplyAffineTransform( CGPointZero,m_windowTransform); HIShapeOffset( hishape, -transformedOrigin.x, -transformedOrigin.y ); HIShapeReplacePathInCGContext( hishape, m_cgContext ); - CGContextClip( m_cgContext ); + // if the shape is empty, HIShapeReplacePathInCGContext doesn't work + if ( HIShapeIsEmpty(hishape)) + { + CGRect empty = CGRectMake( 0,0,0,0 ); + CGContextClipToRect( m_cgContext, empty ); + } + else + { + HIShapeReplacePathInCGContext( hishape, m_cgContext ); + CGContextClip( m_cgContext ); + } } CGContextSaveGState( m_cgContext ); } @@ -1464,10 +1471,19 @@ void wxMacCoreGraphicsContext::Clip( const wxRegion ®ion ) { if( m_cgContext ) { - HIShapeRef shape = HIShapeCreateWithQDRgn( (RgnHandle) region.GetWXHRGN() ); - HIShapeReplacePathInCGContext( shape, m_cgContext ); - CGContextClip( m_cgContext ); - CFRelease( shape ); + wxMacCFRefHolder shape; + shape = HIShapeCreateWithQDRgn( (RgnHandle) region.GetWXHRGN() ); + // if the shape is empty, HIShapeReplacePathInCGContext doesn't work + if ( HIShapeIsEmpty(shape)) + { + CGRect empty = CGRectMake( 0,0,0,0 ); + CGContextClipToRect( m_cgContext, empty ); + } + else + { + HIShapeReplacePathInCGContext( shape, m_cgContext ); + CGContextClip( m_cgContext ); + } } else { @@ -1517,8 +1533,7 @@ void wxMacCoreGraphicsContext::ResetClip() } else { - HIRect r = CGRectMake(0,0,0,0); - m_clipRgn.Set(HIShapeCreateWithRect(&r)); + m_clipRgn.Release(); } }