Mercurial > sdl-ios-xcode
annotate src/video/cocoa/SDL_cocoashape.m @ 5151:5429daf5e3f9
The DrawRect API is implemented using lines
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 01 Feb 2011 20:50:04 -0800 |
parents | 514f811a4887 |
children |
rev | line source |
---|---|
4809
329708ffe2a7
Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff
changeset
|
1 /* |
329708ffe2a7
Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
329708ffe2a7
Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff
changeset
|
3 Copyright (C) 2010 Eli Gottlieb |
329708ffe2a7
Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff
changeset
|
4 |
329708ffe2a7
Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
329708ffe2a7
Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
329708ffe2a7
Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
329708ffe2a7
Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
329708ffe2a7
Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff
changeset
|
9 |
329708ffe2a7
Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
329708ffe2a7
Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
329708ffe2a7
Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
329708ffe2a7
Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
329708ffe2a7
Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff
changeset
|
14 |
329708ffe2a7
Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
329708ffe2a7
Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
329708ffe2a7
Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
329708ffe2a7
Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff
changeset
|
18 |
329708ffe2a7
Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff
changeset
|
19 Eli Gottlieb |
329708ffe2a7
Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff
changeset
|
20 eligottlieb@gmail.com |
329708ffe2a7
Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff
changeset
|
21 */ |
329708ffe2a7
Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff
changeset
|
22 |
4811
d79939f20c45
Working on Cocoa implementation.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4810
diff
changeset
|
23 #include "SDL_cocoavideo.h" |
4809
329708ffe2a7
Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff
changeset
|
24 #include "SDL_shape.h" |
4810
7a602fd2121f
OK, it appears that dramatic hacks are not necessary to make Cocoa work...
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4809
diff
changeset
|
25 #include "SDL_cocoashape.h" |
4907
a2cf0174e5ab
Fix incorrect shape include and add HAVE_ATAN and HAVE_ATAN2 for OSX builds.
Andreas Schiffler <aschiffler@ferzkopp.net>
parents:
4860
diff
changeset
|
26 #include "../SDL_sysvideo.h" |
4809
329708ffe2a7
Rejiggering the way shaped windows are created as preparation for OS X implementation. Fixed overdrive bug in test program that appears to have been introduced by someone other than myself.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff
changeset
|
27 |
4838
1f9915666afd
Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4811
diff
changeset
|
28 SDL_WindowShaper* |
1f9915666afd
Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4811
diff
changeset
|
29 Cocoa_CreateShaper(SDL_Window* window) { |
4859
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
30 SDL_WindowData* windata = (SDL_WindowData*)window->driverdata; |
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
31 [windata->nswindow setOpaque:NO]; |
4925
514f811a4887
Removed support for 10.3.9
Sam Lantinga <slouken@libsdl.org>
parents:
4907
diff
changeset
|
32 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6 |
4859
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
33 [windata->nswindow setStyleMask:NSBorderlessWindowMask]; |
4925
514f811a4887
Removed support for 10.3.9
Sam Lantinga <slouken@libsdl.org>
parents:
4907
diff
changeset
|
34 #endif |
4859
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
35 SDL_WindowShaper* result = result = malloc(sizeof(SDL_WindowShaper)); |
4838
1f9915666afd
Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4811
diff
changeset
|
36 result->window = window; |
1f9915666afd
Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4811
diff
changeset
|
37 result->mode.mode = ShapeModeDefault; |
1f9915666afd
Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4811
diff
changeset
|
38 result->mode.parameters.binarizationCutoff = 1; |
4859
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
39 result->userx = result->usery = 0; |
4838
1f9915666afd
Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4811
diff
changeset
|
40 window->shaper = result; |
1f9915666afd
Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4811
diff
changeset
|
41 |
1f9915666afd
Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4811
diff
changeset
|
42 SDL_ShapeData* data = malloc(sizeof(SDL_ShapeData)); |
1f9915666afd
Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4811
diff
changeset
|
43 result->driverdata = data; |
4859
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
44 data->context = [windata->nswindow graphicsContext]; |
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
45 data->saved = SDL_FALSE; |
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
46 data->shape = NULL; |
4838
1f9915666afd
Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4811
diff
changeset
|
47 |
1f9915666afd
Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4811
diff
changeset
|
48 int resized_properly = Cocoa_ResizeWindowShape(window); |
1f9915666afd
Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4811
diff
changeset
|
49 assert(resized_properly == 0); |
1f9915666afd
Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4811
diff
changeset
|
50 return result; |
4829
7160e833c4ac
Implemented shaped windows for Cocoa. Still need to see if they actually work.
egottlieb
parents:
4827
diff
changeset
|
51 } |
7160e833c4ac
Implemented shaped windows for Cocoa. Still need to see if they actually work.
egottlieb
parents:
4827
diff
changeset
|
52 |
4859
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
53 typedef struct { |
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
54 NSView* view; |
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
55 NSBezierPath* path; |
4860
8f1994e8d886
Create all shaped windows at -1000,-1000 and save the real coordinates.
egottlieb
parents:
4859
diff
changeset
|
56 SDL_Window* window; |
4859
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
57 } SDL_CocoaClosure; |
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
58 |
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
59 void |
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
60 ConvertRects(SDL_ShapeTree* tree,void* closure) { |
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
61 SDL_CocoaClosure* data = (SDL_CocoaClosure*)closure; |
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
62 if(tree->kind == OpaqueShape) { |
4860
8f1994e8d886
Create all shaped windows at -1000,-1000 and save the real coordinates.
egottlieb
parents:
4859
diff
changeset
|
63 NSRect rect = NSMakeRect(tree->data.shape.x,data->window->h - tree->data.shape.y,tree->data.shape.w,tree->data.shape.h); |
4859
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
64 [data->path appendBezierPathWithRect:[data->view convertRect:rect toView:nil]]; |
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
65 } |
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
66 } |
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
67 |
4838
1f9915666afd
Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4811
diff
changeset
|
68 int |
4859
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
69 Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode) { |
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
70 SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata; |
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
71 SDL_WindowData* windata = (SDL_WindowData*)shaper->window->driverdata; |
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
72 SDL_CocoaClosure closure; |
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
73 NSAutoreleasePool *pool = NULL; |
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
74 if(data->saved == SDL_TRUE) { |
4838
1f9915666afd
Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4811
diff
changeset
|
75 [data->context restoreGraphicsState]; |
4859
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
76 data->saved = SDL_FALSE; |
4838
1f9915666afd
Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4811
diff
changeset
|
77 } |
1f9915666afd
Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4811
diff
changeset
|
78 |
4859
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
79 //[data->context saveGraphicsState]; |
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
80 //data->saved = SDL_TRUE; |
4860
8f1994e8d886
Create all shaped windows at -1000,-1000 and save the real coordinates.
egottlieb
parents:
4859
diff
changeset
|
81 [NSGraphicsContext setCurrentContext:data->context]; |
4838
1f9915666afd
Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4811
diff
changeset
|
82 |
1f9915666afd
Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4811
diff
changeset
|
83 [[NSColor clearColor] set]; |
4859
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
84 NSRectFill([[windata->nswindow contentView] frame]); |
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
85 data->shape = SDL_CalculateShapeTree(*shape_mode,shape); |
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
86 |
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
87 pool = [[NSAutoreleasePool alloc] init]; |
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
88 closure.view = [windata->nswindow contentView]; |
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
89 closure.path = [[NSBezierPath bezierPath] autorelease]; |
4860
8f1994e8d886
Create all shaped windows at -1000,-1000 and save the real coordinates.
egottlieb
parents:
4859
diff
changeset
|
90 closure.window = shaper->window; |
4859
91f4d4d5c395
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents:
4839
diff
changeset
|
91 SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure); |
4860
8f1994e8d886
Create all shaped windows at -1000,-1000 and save the real coordinates.
egottlieb
parents:
4859
diff
changeset
|
92 [closure.path addClip]; |
4829
7160e833c4ac
Implemented shaped windows for Cocoa. Still need to see if they actually work.
egottlieb
parents:
4827
diff
changeset
|
93 } |
7160e833c4ac
Implemented shaped windows for Cocoa. Still need to see if they actually work.
egottlieb
parents:
4827
diff
changeset
|
94 |
4838
1f9915666afd
Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4811
diff
changeset
|
95 int |
1f9915666afd
Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4811
diff
changeset
|
96 Cocoa_ResizeWindowShape(SDL_Window *window) { |
1f9915666afd
Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4811
diff
changeset
|
97 SDL_ShapeData* data = window->shaper->driverdata; |
1f9915666afd
Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4811
diff
changeset
|
98 assert(data != NULL); |
1f9915666afd
Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4811
diff
changeset
|
99 return 0; |
4811
d79939f20c45
Working on Cocoa implementation.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4810
diff
changeset
|
100 } |