comparison 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
comparison
equal deleted inserted replaced
4858:10b96029e734 4859:91f4d4d5c395
21 */ 21 */
22 22
23 #include "SDL_cocoavideo.h" 23 #include "SDL_cocoavideo.h"
24 #include "SDL_shape.h" 24 #include "SDL_shape.h"
25 #include "SDL_cocoashape.h" 25 #include "SDL_cocoashape.h"
26 #include "../src/video/SDL_sysvideo.h"
26 27
27 SDL_WindowShaper* 28 SDL_WindowShaper*
28 Cocoa_CreateShaper(SDL_Window* window) { 29 Cocoa_CreateShaper(SDL_Window* window) {
29 SDL_WindowData* data = (SDL_WindowData*)window->driverdata; 30 SDL_WindowData* windata = (SDL_WindowData*)window->driverdata;
30 [data->nswindow setAlpha:1.0]; 31 [windata->nswindow setOpaque:NO];
31 [data->nswindow setOpaque:YES]; 32 [windata->nswindow setStyleMask:NSBorderlessWindowMask];
32 [data->nswindow setStyleMask:NSBorderlessWindowMask]; 33 SDL_WindowShaper* result = result = malloc(sizeof(SDL_WindowShaper));
33 SDL_Shaper* result = result = malloc(sizeof(SDL_WindowShaper));
34 result->window = window; 34 result->window = window;
35 result->mode.mode = ShapeModeDefault; 35 result->mode.mode = ShapeModeDefault;
36 result->mode.parameters.binarizationCutoff = 1; 36 result->mode.parameters.binarizationCutoff = 1;
37 result->usershownflag = 0; 37 result->userx = result->usery = 0;
38 window->shaper = result; 38 window->shaper = result;
39 39
40 SDL_ShapeData* data = malloc(sizeof(SDL_ShapeData)); 40 SDL_ShapeData* data = malloc(sizeof(SDL_ShapeData));
41 result->driverdata = data; 41 result->driverdata = data;
42 data->context = [data->nswindow graphicsContext]; 42 data->context = [windata->nswindow graphicsContext];
43 data->saved = SDL_False; 43 data->saved = SDL_FALSE;
44 data->rects = NULL; 44 data->shape = NULL;
45 data->count = 0;
46 45
47 int resized_properly = Cocoa_ResizeWindowShape(window); 46 int resized_properly = Cocoa_ResizeWindowShape(window);
48 assert(resized_properly == 0); 47 assert(resized_properly == 0);
49 return result; 48 return result;
50 } 49 }
51 50
51 typedef struct {
52 NSView* view;
53 NSBezierPath* path;
54 } SDL_CocoaClosure;
55
56 void
57 ConvertRects(SDL_ShapeTree* tree,void* closure) {
58 SDL_CocoaClosure* data = (SDL_CocoaClosure*)closure;
59 if(tree->kind == OpaqueShape) {
60 NSRect rect = NSMakeRect(tree->data.shape.x,tree->data.shape.y,tree->data.shape.w,tree->data.shape.h);
61 [data->path appendBezierPathWithRect:[data->view convertRect:rect toView:nil]];
62 }
63 }
64
52 int 65 int
53 Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) { 66 Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode) {
54 SDL_WindowData* data = (SDL_WindowData*)shaper->window->driverdata; 67 SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata;
55 if(data->saved == SDL_True) { 68 SDL_WindowData* windata = (SDL_WindowData*)shaper->window->driverdata;
69 SDL_CocoaClosure closure;
70 NSAutoreleasePool *pool = NULL;
71 if(data->saved == SDL_TRUE) {
56 [data->context restoreGraphicsState]; 72 [data->context restoreGraphicsState];
57 data->saved = SDL_False; 73 data->saved = SDL_FALSE;
58 } 74 }
59 75
60 [data->context saveGraphicsState]; 76 //[data->context saveGraphicsState];
61 data->saved = SDL_True; 77 //data->saved = SDL_TRUE;
62 78
63 [[NSColor clearColor] set]; 79 [[NSColor clearColor] set];
64 NSRectFill([[data->nswindow contentView] frame]); 80 NSRectFill([[windata->nswindow contentView] frame]);
65 /* TODO: It looks like Cocoa can set a clipping path based on a list of rectangles. That's what we get from the 81 /* TODO: It looks like Cocoa can set a clipping path based on a list of rectangles. That's what we get from the
66 Windoze shape-calculation code: a list of rectangles. This will work... I think. */ 82 Windoze shape-calculation code: a list of rectangles. This will work... I think. */
83 data->shape = SDL_CalculateShapeTree(*shape_mode,shape);
84
85 pool = [[NSAutoreleasePool alloc] init];
86 closure.view = [windata->nswindow contentView];
87 closure.path = [[NSBezierPath bezierPath] autorelease];
88 SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure);
89 [NSGraphicsContext setCurrentContext:data->context];
90 [closure.path setClip];
91 [pool drain];
67 } 92 }
68 93
69 int 94 int
70 Cocoa_ResizeWindowShape(SDL_Window *window) { 95 Cocoa_ResizeWindowShape(SDL_Window *window) {
71 SDL_ShapeData* data = window->shaper->driverdata; 96 SDL_ShapeData* data = window->shaper->driverdata;