# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1561145877 0 # Node ID 5a88fff43d993edce1c403e72c14488a61d04a46 # Parent eb488c379969300dd1928d93d74bc3db63ada222 Mac: Fixed deprecation warnings relating to the GraphicsPort now using CoreGraphics. Still need to fix warnings related to drawing to the NSView. diff -r eb488c379969 -r 5a88fff43d99 mac/dw.m --- a/mac/dw.m Thu Jun 20 22:53:44 2019 +0000 +++ b/mac/dw.m Fri Jun 21 19:37:57 2019 +0000 @@ -2,8 +2,8 @@ * Dynamic Windows: * A GTK like implementation of the MacOS GUI using Cocoa * - * (C) 2011-2017 Brian Smith - * (C) 2011 Mark Hessling + * (C) 2011-2019 Brian Smith + * (C) 2011-2018 Mark Hessling * * Requires 10.5 or later. * clang -std=c99 -g -o dwtest -D__MAC__ -I. dwtest.c mac/dw.m -framework Cocoa -framework WebKit @@ -1120,7 +1120,7 @@ if(button != self && [button buttonType] == DWButtonTypeRadio) { - [button setState:NSOffState]; + [button setState:DWControlStateValueOff]; } } } @@ -5920,6 +5920,18 @@ return value; } +/* Set the current context to be a flipped image, + * On 10.10 or higher use CoreGraphics otherwise Graphics Port + */ +NSGraphicsContext *_dw_draw_context(NSBitmapImageRep *image) +{ +#ifdef BUILDING_FOR_YOSEMITE + return [NSGraphicsContext graphicsContextWithCGContext:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] CGContext] flipped:YES]; +#else + return [NSGraphicsContext graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort] flipped:YES]; +#endif +} + /* Draw a point on a window (preferably a render window). * Parameters: * handle: Handle to the window. @@ -5937,8 +5949,7 @@ { image = (id)pixmap->image; [NSGraphicsContext saveGraphicsState]; - [NSGraphicsContext setCurrentContext:[NSGraphicsContext - graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort] flipped:YES]]; + [NSGraphicsContext setCurrentContext:_dw_draw_context(image)]; } else { @@ -5988,8 +5999,7 @@ { image = (id)pixmap->image; [NSGraphicsContext saveGraphicsState]; - [NSGraphicsContext setCurrentContext:[NSGraphicsContext - graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort] flipped:YES]]; + [NSGraphicsContext setCurrentContext:_dw_draw_context(image)]; } else { @@ -6075,8 +6085,7 @@ } image = (id)pixmap->image; [NSGraphicsContext saveGraphicsState]; - [NSGraphicsContext setCurrentContext:[NSGraphicsContext - graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort] flipped:YES]]; + [NSGraphicsContext setCurrentContext:_dw_draw_context(image)]; NSColor *fgcolor = pthread_getspecific(_dw_fg_color_key); NSColor *bgcolor = pthread_getspecific(_dw_bg_color_key); NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:fgcolor, NSForegroundColorAttributeName, nil]; @@ -6150,8 +6159,13 @@ */ id _create_gc(id image, bool antialiased) { +#ifdef BUILDING_FOR_YOSEMITE + CGContextRef context = (CGContextRef)[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] CGContext]; + NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithCGContext:context flipped:YES]; +#else CGContextRef context = (CGContextRef)[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort]; NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:YES]; +#endif [gc setShouldAntialias:antialiased]; CGContextSetAllowsAntialiasing(context, antialiased); return gc; @@ -7735,9 +7749,7 @@ NSCompositingOperation op =NSCompositeSourceOver; #endif [NSGraphicsContext saveGraphicsState]; - [NSGraphicsContext setCurrentContext:[NSGraphicsContext - graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort] - flipped:YES]]; + [NSGraphicsContext setCurrentContext:_dw_draw_context(image)]; [[[NSDictionary alloc] initWithObjectsAndKeys:image, NSGraphicsContextDestinationAttributeName, nil] autorelease]; /* Make a new transform */ NSAffineTransform *t = [NSAffineTransform transform];