annotate src/video/cocoa/SDL_cocoashape.m @ 4838:1f9915666afd

Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
author Eli Gottlieb <eligottlieb@gmail.com>
date Mon, 09 Aug 2010 15:37:20 -0400
parents d79939f20c45
children 05d172e92b52
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"
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
26
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
27 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
28 Cocoa_CreateShaper(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
29 SDL_WindowData* data = (SDL_WindowData*)window->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
30 [data->nswindow setAlpha:1.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
31 [data->nswindow setOpaque:YES];
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
32 [data->nswindow setStyleMask:NSBorderlessWindowMask];
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
33 SDL_Shaper* result = result = malloc(sizeof(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
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;
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->usershownflag = 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
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;
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 data->context = [data->nswindow graphicsContext];
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 data->saved = SDL_False;
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
44 data->rects = 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
45 data->count = 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
46
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 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
48 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
49 return result;
4810
7a602fd2121f OK, it appears that dramatic hacks are not necessary to make Cocoa work...
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
50 }
7a602fd2121f OK, it appears that dramatic hacks are not necessary to make Cocoa work...
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
51
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
52 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
53 Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) {
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
54 SDL_WindowData* data = (SDL_WindowData*)shaper->window->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
55 if(data->saved == SDL_True) {
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
56 [data->context restoreGraphicsState];
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
57 data->saved = SDL_False;
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
58 }
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
59
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
60 [data->context saveGraphicsState];
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
61 data->saved = SDL_True;
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
62
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
63 [[NSColor clearColor] set];
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
64 NSRectFill([[data->nswindow contentView] frame]);
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 /* 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
66 Windoze shape-calculation code: a list of rectangles. This will work... I think. */
d79939f20c45 Working on Cocoa implementation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4810
diff changeset
67 }
d79939f20c45 Working on Cocoa implementation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4810
diff changeset
68
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
69 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
70 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
71 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
72 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
73 return 0;
4811
d79939f20c45 Working on Cocoa implementation.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4810
diff changeset
74 }