annotate src/video/cocoa/SDL_cocoashape.m @ 4859:91f4d4d5c395

Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
author egottlieb
date Mon, 16 Aug 2010 14:01:00 -0400
parents 05d172e92b52
children 8f1994e8d886
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"
4859
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
26 #include "../src/video/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];
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
32 [windata->nswindow setStyleMask:NSBorderlessWindowMask];
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
33 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
34 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
35 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
36 result->mode.parameters.binarizationCutoff = 1;
4859
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
37 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
38 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
39
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 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
41 result->driverdata = data;
4859
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
42 data->context = [windata->nswindow graphicsContext];
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
43 data->saved = SDL_FALSE;
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
44 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
45
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
46 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
47 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
48 return result;
4829
7160e833c4ac Implemented shaped windows for Cocoa. Still need to see if they actually work.
egottlieb
parents: 4827
diff changeset
49 }
7160e833c4ac Implemented shaped windows for Cocoa. Still need to see if they actually work.
egottlieb
parents: 4827
diff changeset
50
4859
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
51 typedef struct {
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
52 NSView* view;
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
53 NSBezierPath* path;
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
54 } SDL_CocoaClosure;
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
55
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
56 void
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
57 ConvertRects(SDL_ShapeTree* tree,void* closure) {
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
58 SDL_CocoaClosure* data = (SDL_CocoaClosure*)closure;
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
59 if(tree->kind == OpaqueShape) {
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
60 NSRect rect = NSMakeRect(tree->data.shape.x,tree->data.shape.y,tree->data.shape.w,tree->data.shape.h);
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
61 [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
62 }
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
63 }
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
64
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
65 int
4859
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
66 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
67 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
68 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
69 SDL_CocoaClosure closure;
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
70 NSAutoreleasePool *pool = NULL;
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
71 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
72 [data->context restoreGraphicsState];
4859
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
73 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
74 }
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
4859
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
76 //[data->context saveGraphicsState];
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
77 //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
78
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
79 [[NSColor clearColor] set];
4859
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
80 NSRectFill([[windata->nswindow contentView] frame]);
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
81 /* TODO: It looks like Cocoa can set a clipping path based on a list of rectangles. That's what we get from the
4811
d79939f20c45 Working on Cocoa implementation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4810
diff changeset
82 Windoze shape-calculation code: a list of rectangles. This will work... I think. */
4859
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
83 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
84
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
85 pool = [[NSAutoreleasePool alloc] init];
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
86 closure.view = [windata->nswindow contentView];
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
87 closure.path = [[NSBezierPath bezierPath] autorelease];
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
88 SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure);
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
89 [NSGraphicsContext setCurrentContext:data->context];
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
90 [closure.path setClip];
91f4d4d5c395 Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
egottlieb
parents: 4839
diff changeset
91 [pool drain];
4829
7160e833c4ac Implemented shaped windows for Cocoa. Still need to see if they actually work.
egottlieb
parents: 4827
diff changeset
92 }
7160e833c4ac Implemented shaped windows for Cocoa. Still need to see if they actually work.
egottlieb
parents: 4827
diff changeset
93
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
94 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
95 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
96 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
97 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
98 return 0;
4811
d79939f20c45 Working on Cocoa implementation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4810
diff changeset
99 }