comparison src/video/cocoa/SDL_cocoashape.m @ 4827:5660aac926e9

Got basic, pre-actually-writing-anything Cocoa to build.
author egottlieb
date Tue, 03 Aug 2010 00:47:33 -0400
parents d79939f20c45
children 7160e833c4ac
comparison
equal deleted inserted replaced
4826:d532a5a114cd 4827:5660aac926e9
18 18
19 Eli Gottlieb 19 Eli Gottlieb
20 eligottlieb@gmail.com 20 eligottlieb@gmail.com
21 */ 21 */
22 22
23 #include "SDL_stdinc.h"
23 #include "SDL_cocoavideo.h" 24 #include "SDL_cocoavideo.h"
24 #include "SDL_shape.h" 25 #include "SDL_shape.h"
25 #include "SDL_cocoashape.h" 26 #include "SDL_cocoashape.h"
27 #include "SDL_sysvideo.h"
26 28
27 SDL_WindowShaper* Cocoa_CreateShaper(SDL_Window* window) { 29 SDL_WindowShaper* Cocoa_CreateShaper(SDL_Window* window) {
28 SDL_WindowData* data = (SDL_WindowData*)window->driverdata; 30 SDL_WindowData* data = (SDL_WindowData*)window->driverdata;
29 [data->nswindow setAlpha:1.0]; 31 [data->nswindow setAlpha:1.0];
30 [data->nswindow setOpaque:YES]; 32 [data->nswindow setOpaque:YES];
31 [data->nswindow setStyleMask:NSBorderlessWindowMask]; 33 [data->nswindow setStyleMask:NSBorderlessWindowMask];
32 SDL_Shaper* result = result = malloc(sizeof(SDL_WindowShaper)); 34 SDL_WindowShaper* result = SDL_malloc(sizeof(SDL_WindowShaper));
33 result->window = window; 35 result->window = window;
34 result->mode.mode = ShapeModeDefault; 36 result->mode.mode = ShapeModeDefault;
35 result->mode.parameters.binarizationCutoff = 1; 37 result->mode.parameters.binarizationCutoff = 1;
36 result->usershownflag = 0; 38 result->usershownflag = 0;
37 window->shaper = result; 39 window->shaper = result;
38 40
39 SDL_ShapeData* data = malloc(sizeof(SDL_ShapeData)); 41 SDL_ShapeData* shape_data = SDL_malloc(sizeof(SDL_ShapeData));
40 result->driverdata = data; 42 result->driverdata = shape_data;
41 data->context = [data->nswindow graphicsContext]; 43 shape_data->context = [data->nswindow graphicsContext];
42 data->saved = SDL_False; 44 shape_data->saved = SDL_FALSE;
43 data->rects = NULL; 45 shape_data->shape = NULL;
44 data->count = 0;
45 46
46 int resized_properly = Cocoa_ResizeWindowShape(window); 47 int resized_properly = Cocoa_ResizeWindowShape(window);
47 assert(resized_properly == 0); 48 assert(resized_properly == 0);
48 return result; 49 return result;
49 } 50 }
50 51
51 int Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) { 52 int Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) {
52 SDL_WindowData* data = (SDL_WindowData*)shaper->window->driverdata; 53 SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata;
53 if(data->saved == SDL_True) { 54 if(data->saved == SDL_TRUE) {
54 [data->context restoreGraphicsState]; 55 [data->context restoreGraphicsState];
55 data->saved = SDL_False; 56 data->saved = SDL_FALSE;
56 } 57 }
57 58
58 [data->context saveGraphicsState]; 59 [data->context saveGraphicsState];
59 data->saved = SDL_True; 60 data->saved = SDL_TRUE;
60 61
61 [[NSColor clearColor] set]; 62 [[NSColor clearColor] set];
62 NSRectFill([[data->nswindow contentView] frame]); 63 NSRectFill([[((SDL_WindowData*)shaper->window->driverdata)->nswindow contentView] frame]);
63 /* TODO: It looks like Cocoa can set a clipping path based on a list of rectangles. That's what we get from the 64 /* TODO: It looks like Cocoa can set a clipping path based on a list of rectangles. That's what we get from the
64 Windoze shape-calculation code: a list of rectangles. This will work... I think. */ 65 Windoze shape-calculation code: a list of rectangles. This will work... I think. */
65 } 66 }
66 67
67 int Cocoa_ResizeWindowShape(SDL_Window *window) { 68 int Cocoa_ResizeWindowShape(SDL_Window *window) {
68 SDL_ShapeData* data = window->shaper->driverdata; 69 SDL_ShapeData* data = window->shaper->driverdata;
69 assert(data != NULL); 70 assert(data != NULL);
71
72 if(data->shape != NULL)
73 SDL_FreeShapeTree(&data->shape);
74
70 return 0; 75 return 0;
71 } 76 }