Mercurial > dwindows
comparison mac/dw.m @ 1938:5a88fff43d99
Mac: Fixed deprecation warnings relating to the GraphicsPort now using CoreGraphics.
Still need to fix warnings related to drawing to the NSView.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 21 Jun 2019 19:37:57 +0000 |
parents | ebde5ef666a6 |
children | 83148aaa35a5 |
comparison
equal
deleted
inserted
replaced
1937:eb488c379969 | 1938:5a88fff43d99 |
---|---|
1 /* | 1 /* |
2 * Dynamic Windows: | 2 * Dynamic Windows: |
3 * A GTK like implementation of the MacOS GUI using Cocoa | 3 * A GTK like implementation of the MacOS GUI using Cocoa |
4 * | 4 * |
5 * (C) 2011-2017 Brian Smith <brian@dbsoft.org> | 5 * (C) 2011-2019 Brian Smith <brian@dbsoft.org> |
6 * (C) 2011 Mark Hessling <mark@rexx.org> | 6 * (C) 2011-2018 Mark Hessling <mark@rexx.org> |
7 * | 7 * |
8 * Requires 10.5 or later. | 8 * Requires 10.5 or later. |
9 * clang -std=c99 -g -o dwtest -D__MAC__ -I. dwtest.c mac/dw.m -framework Cocoa -framework WebKit | 9 * clang -std=c99 -g -o dwtest -D__MAC__ -I. dwtest.c mac/dw.m -framework Cocoa -framework WebKit |
10 */ | 10 */ |
11 #import <Cocoa/Cocoa.h> | 11 #import <Cocoa/Cocoa.h> |
1118 { | 1118 { |
1119 DWButton *button = object; | 1119 DWButton *button = object; |
1120 | 1120 |
1121 if(button != self && [button buttonType] == DWButtonTypeRadio) | 1121 if(button != self && [button buttonType] == DWButtonTypeRadio) |
1122 { | 1122 { |
1123 [button setState:NSOffState]; | 1123 [button setState:DWControlStateValueOff]; |
1124 } | 1124 } |
1125 } | 1125 } |
1126 } | 1126 } |
1127 } | 1127 } |
1128 } | 1128 } |
5918 value = DW_RGB((int)(red * 255), (int)(green *255), (int)(blue *255)); | 5918 value = DW_RGB((int)(red * 255), (int)(green *255), (int)(blue *255)); |
5919 DW_LOCAL_POOL_OUT; | 5919 DW_LOCAL_POOL_OUT; |
5920 return value; | 5920 return value; |
5921 } | 5921 } |
5922 | 5922 |
5923 /* Set the current context to be a flipped image, | |
5924 * On 10.10 or higher use CoreGraphics otherwise Graphics Port | |
5925 */ | |
5926 NSGraphicsContext *_dw_draw_context(NSBitmapImageRep *image) | |
5927 { | |
5928 #ifdef BUILDING_FOR_YOSEMITE | |
5929 return [NSGraphicsContext graphicsContextWithCGContext:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] CGContext] flipped:YES]; | |
5930 #else | |
5931 return [NSGraphicsContext graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort] flipped:YES]; | |
5932 #endif | |
5933 } | |
5934 | |
5923 /* Draw a point on a window (preferably a render window). | 5935 /* Draw a point on a window (preferably a render window). |
5924 * Parameters: | 5936 * Parameters: |
5925 * handle: Handle to the window. | 5937 * handle: Handle to the window. |
5926 * pixmap: Handle to the pixmap. (choose only one of these) | 5938 * pixmap: Handle to the pixmap. (choose only one of these) |
5927 * x: X coordinate. | 5939 * x: X coordinate. |
5935 id image = handle; | 5947 id image = handle; |
5936 if(pixmap) | 5948 if(pixmap) |
5937 { | 5949 { |
5938 image = (id)pixmap->image; | 5950 image = (id)pixmap->image; |
5939 [NSGraphicsContext saveGraphicsState]; | 5951 [NSGraphicsContext saveGraphicsState]; |
5940 [NSGraphicsContext setCurrentContext:[NSGraphicsContext | 5952 [NSGraphicsContext setCurrentContext:_dw_draw_context(image)]; |
5941 graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort] flipped:YES]]; | |
5942 } | 5953 } |
5943 else | 5954 else |
5944 { | 5955 { |
5945 if([image lockFocusIfCanDraw] == NO) | 5956 if([image lockFocusIfCanDraw] == NO) |
5946 { | 5957 { |
5986 id image = handle; | 5997 id image = handle; |
5987 if(pixmap) | 5998 if(pixmap) |
5988 { | 5999 { |
5989 image = (id)pixmap->image; | 6000 image = (id)pixmap->image; |
5990 [NSGraphicsContext saveGraphicsState]; | 6001 [NSGraphicsContext saveGraphicsState]; |
5991 [NSGraphicsContext setCurrentContext:[NSGraphicsContext | 6002 [NSGraphicsContext setCurrentContext:_dw_draw_context(image)]; |
5992 graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort] flipped:YES]]; | |
5993 } | 6003 } |
5994 else | 6004 else |
5995 { | 6005 { |
5996 if([image lockFocusIfCanDraw] == NO) | 6006 if([image lockFocusIfCanDraw] == NO) |
5997 { | 6007 { |
6073 { | 6083 { |
6074 font = [render font]; | 6084 font = [render font]; |
6075 } | 6085 } |
6076 image = (id)pixmap->image; | 6086 image = (id)pixmap->image; |
6077 [NSGraphicsContext saveGraphicsState]; | 6087 [NSGraphicsContext saveGraphicsState]; |
6078 [NSGraphicsContext setCurrentContext:[NSGraphicsContext | 6088 [NSGraphicsContext setCurrentContext:_dw_draw_context(image)]; |
6079 graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort] flipped:YES]]; | |
6080 NSColor *fgcolor = pthread_getspecific(_dw_fg_color_key); | 6089 NSColor *fgcolor = pthread_getspecific(_dw_fg_color_key); |
6081 NSColor *bgcolor = pthread_getspecific(_dw_bg_color_key); | 6090 NSColor *bgcolor = pthread_getspecific(_dw_bg_color_key); |
6082 NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:fgcolor, NSForegroundColorAttributeName, nil]; | 6091 NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:fgcolor, NSForegroundColorAttributeName, nil]; |
6083 if(bgcolor) | 6092 if(bgcolor) |
6084 { | 6093 { |
6148 /* Internal function to create an image graphics context... | 6157 /* Internal function to create an image graphics context... |
6149 * with or without antialiasing enabled. | 6158 * with or without antialiasing enabled. |
6150 */ | 6159 */ |
6151 id _create_gc(id image, bool antialiased) | 6160 id _create_gc(id image, bool antialiased) |
6152 { | 6161 { |
6162 #ifdef BUILDING_FOR_YOSEMITE | |
6163 CGContextRef context = (CGContextRef)[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] CGContext]; | |
6164 NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithCGContext:context flipped:YES]; | |
6165 #else | |
6153 CGContextRef context = (CGContextRef)[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort]; | 6166 CGContextRef context = (CGContextRef)[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort]; |
6154 NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:YES]; | 6167 NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:YES]; |
6168 #endif | |
6155 [gc setShouldAntialias:antialiased]; | 6169 [gc setShouldAntialias:antialiased]; |
6156 CGContextSetAllowsAntialiasing(context, antialiased); | 6170 CGContextSetAllowsAntialiasing(context, antialiased); |
6157 return gc; | 6171 return gc; |
6158 } | 6172 } |
6159 | 6173 |
7733 NSCompositingOperation op =NSCompositingOperationSourceOver; | 7747 NSCompositingOperation op =NSCompositingOperationSourceOver; |
7734 #else | 7748 #else |
7735 NSCompositingOperation op =NSCompositeSourceOver; | 7749 NSCompositingOperation op =NSCompositeSourceOver; |
7736 #endif | 7750 #endif |
7737 [NSGraphicsContext saveGraphicsState]; | 7751 [NSGraphicsContext saveGraphicsState]; |
7738 [NSGraphicsContext setCurrentContext:[NSGraphicsContext | 7752 [NSGraphicsContext setCurrentContext:_dw_draw_context(image)]; |
7739 graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort] | |
7740 flipped:YES]]; | |
7741 [[[NSDictionary alloc] initWithObjectsAndKeys:image, NSGraphicsContextDestinationAttributeName, nil] autorelease]; | 7753 [[[NSDictionary alloc] initWithObjectsAndKeys:image, NSGraphicsContextDestinationAttributeName, nil] autorelease]; |
7742 /* Make a new transform */ | 7754 /* Make a new transform */ |
7743 NSAffineTransform *t = [NSAffineTransform transform]; | 7755 NSAffineTransform *t = [NSAffineTransform transform]; |
7744 | 7756 |
7745 /* By scaling Y negatively, we effectively flip the image */ | 7757 /* By scaling Y negatively, we effectively flip the image */ |