Fixing wxGLCanvas under 10.14, preparing for layer based drawing
see https://github.com/wxWidgets/wxWidgets/pull/846 , thanks to dkulp
This commit is contained in:
@@ -2291,84 +2291,96 @@ void wxWidgetCocoaImpl::drawRect(void* rect, WXWidget slf, void *WXUNUSED(_cmd))
|
||||
wxpeer->GetUpdateRegion() = updateRgn;
|
||||
|
||||
// setting up the drawing context
|
||||
|
||||
// note that starting from 10.14 this may be NULL in certain views
|
||||
CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
|
||||
CGContextSaveGState( context );
|
||||
|
||||
#if OSX_DEBUG_DRAWING
|
||||
CGContextBeginPath( context );
|
||||
CGContextMoveToPoint(context, 0, 0);
|
||||
NSRect bounds = [slf bounds];
|
||||
CGContextAddLineToPoint(context, 10, 0);
|
||||
CGContextMoveToPoint(context, 0, 0);
|
||||
CGContextAddLineToPoint(context, 0, 10);
|
||||
CGContextMoveToPoint(context, bounds.size.width, bounds.size.height);
|
||||
CGContextAddLineToPoint(context, bounds.size.width, bounds.size.height-10);
|
||||
CGContextMoveToPoint(context, bounds.size.width, bounds.size.height);
|
||||
CGContextAddLineToPoint(context, bounds.size.width-10, bounds.size.height);
|
||||
CGContextClosePath( context );
|
||||
CGContextStrokePath(context);
|
||||
#endif
|
||||
|
||||
if ( ![slf isFlipped] )
|
||||
{
|
||||
CGContextTranslateCTM( context, 0, [m_osxView bounds].size.height );
|
||||
CGContextScaleCTM( context, 1, -1 );
|
||||
}
|
||||
|
||||
wxpeer->MacSetCGContextRef( context );
|
||||
if ( context != NULL )
|
||||
{
|
||||
CGContextSaveGState( context );
|
||||
|
||||
#if OSX_DEBUG_DRAWING
|
||||
CGContextBeginPath( context );
|
||||
CGContextMoveToPoint(context, 0, 0);
|
||||
NSRect bounds = [slf bounds];
|
||||
CGContextAddLineToPoint(context, 10, 0);
|
||||
CGContextMoveToPoint(context, 0, 0);
|
||||
CGContextAddLineToPoint(context, 0, 10);
|
||||
CGContextMoveToPoint(context, bounds.size.width, bounds.size.height);
|
||||
CGContextAddLineToPoint(context, bounds.size.width, bounds.size.height-10);
|
||||
CGContextMoveToPoint(context, bounds.size.width, bounds.size.height);
|
||||
CGContextAddLineToPoint(context, bounds.size.width-10, bounds.size.height);
|
||||
CGContextClosePath( context );
|
||||
CGContextStrokePath(context);
|
||||
#endif
|
||||
|
||||
if ( ![slf isFlipped] )
|
||||
{
|
||||
CGContextTranslateCTM( context, 0, [m_osxView bounds].size.height );
|
||||
CGContextScaleCTM( context, 1, -1 );
|
||||
}
|
||||
}
|
||||
|
||||
bool handled = wxpeer->MacDoRedraw( 0 );
|
||||
CGContextRestoreGState( context );
|
||||
|
||||
CGContextSaveGState( context );
|
||||
if ( context != NULL )
|
||||
{
|
||||
CGContextRestoreGState( context );
|
||||
CGContextSaveGState( context );
|
||||
}
|
||||
|
||||
if ( !handled )
|
||||
{
|
||||
// call super
|
||||
SEL _cmd = @selector(drawRect:);
|
||||
wxOSX_DrawRectHandlerPtr superimpl = (wxOSX_DrawRectHandlerPtr) [[slf superclass] instanceMethodForSelector:_cmd];
|
||||
superimpl(slf, _cmd, *(NSRect*)rect);
|
||||
CGContextRestoreGState( context );
|
||||
CGContextSaveGState( context );
|
||||
}
|
||||
// as we called restore above, we have to flip again if necessary
|
||||
if ( ![slf isFlipped] )
|
||||
{
|
||||
CGContextTranslateCTM( context, 0, [m_osxView bounds].size.height );
|
||||
CGContextScaleCTM( context, 1, -1 );
|
||||
}
|
||||
|
||||
if ( isTopLevel )
|
||||
{
|
||||
// We also need to explicitly draw the part of the top level window
|
||||
// outside of its region with transparent colour to ensure that it is
|
||||
// really transparent.
|
||||
if ( clearRgn.IsOk() )
|
||||
if ( context != NULL )
|
||||
{
|
||||
wxMacCGContextStateSaver saveState(context);
|
||||
wxWindowDC dc(wxpeer);
|
||||
dc.SetBackground(wxBrush(wxTransparentColour));
|
||||
dc.SetDeviceClippingRegion(clearRgn);
|
||||
dc.Clear();
|
||||
CGContextRestoreGState( context );
|
||||
CGContextSaveGState( context );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( context != NULL )
|
||||
{
|
||||
// as we called restore above, we have to flip again if necessary
|
||||
if ( ![slf isFlipped] )
|
||||
{
|
||||
CGContextTranslateCTM( context, 0, [m_osxView bounds].size.height );
|
||||
CGContextScaleCTM( context, 1, -1 );
|
||||
}
|
||||
|
||||
if ( isTopLevel )
|
||||
{
|
||||
// We also need to explicitly draw the part of the top level window
|
||||
// outside of its region with transparent colour to ensure that it is
|
||||
// really transparent.
|
||||
if ( clearRgn.IsOk() )
|
||||
{
|
||||
wxMacCGContextStateSaver saveState(context);
|
||||
wxWindowDC dc(wxpeer);
|
||||
dc.SetBackground(wxBrush(wxTransparentColour));
|
||||
dc.SetDeviceClippingRegion(clearRgn);
|
||||
dc.Clear();
|
||||
}
|
||||
|
||||
#if wxUSE_GRAPHICS_CONTEXT
|
||||
// If the window shape is defined by a path, stroke the path to show
|
||||
// the window border.
|
||||
const wxGraphicsPath& path = tlwParent->GetShapePath();
|
||||
if ( !path.IsNull() )
|
||||
{
|
||||
CGContextSetLineWidth(context, 1);
|
||||
CGContextSetStrokeColorWithColor(context, wxLIGHT_GREY->GetCGColor());
|
||||
CGContextAddPath(context, (CGPathRef) path.GetNativePath());
|
||||
CGContextStrokePath(context);
|
||||
}
|
||||
// If the window shape is defined by a path, stroke the path to show
|
||||
// the window border.
|
||||
const wxGraphicsPath& path = tlwParent->GetShapePath();
|
||||
if ( !path.IsNull() )
|
||||
{
|
||||
CGContextSetLineWidth(context, 1);
|
||||
CGContextSetStrokeColorWithColor(context, wxLIGHT_GREY->GetCGColor());
|
||||
CGContextAddPath(context, (CGPathRef) path.GetNativePath());
|
||||
CGContextStrokePath(context);
|
||||
}
|
||||
#endif // wxUSE_GRAPHICS_CONTEXT
|
||||
}
|
||||
|
||||
wxpeer->MacPaintChildrenBorders();
|
||||
CGContextRestoreGState( context );
|
||||
}
|
||||
|
||||
wxpeer->MacPaintChildrenBorders();
|
||||
wxpeer->MacSetCGContextRef( NULL );
|
||||
CGContextRestoreGState( context );
|
||||
}
|
||||
|
||||
void wxWidgetCocoaImpl::controlAction( WXWidget WXUNUSED(slf), void *WXUNUSED(_cmd), void *WXUNUSED(sender))
|
||||
|
||||
Reference in New Issue
Block a user