comparison src/video/cocoa/SDL_cocoashape.m @ 4829:7160e833c4ac

Implemented shaped windows for Cocoa. Still need to see if they actually work.
author egottlieb
date Tue, 03 Aug 2010 21:56:05 -0400
parents 5660aac926e9
children 3dfe779900f5
comparison
equal deleted inserted replaced
4828:0463365eeffa 4829:7160e833c4ac
47 int resized_properly = Cocoa_ResizeWindowShape(window); 47 int resized_properly = Cocoa_ResizeWindowShape(window);
48 assert(resized_properly == 0); 48 assert(resized_properly == 0);
49 return result; 49 return result;
50 } 50 }
51 51
52 typedef struct {
53 NSBezierPath* clipPath;
54 SDL_Window* window;
55 } SDL_PathConglomeration;
56
57 NSRect convert_rect(SDL_Rect rect,SDL_Window* window) {
58 NSRect nsrect = NSMakeRect(rect.x,window->h-(rect.y+rect.h),rect.w,rect.h);
59 return [[((SDL_WindowData*)window->driverdata)->nswindow contentView] convertRectFromBase:nsrect];
60 }
61
62 void ConglomerateShapeTree(SDL_ShapeTree* tree,SDL_PathConglomeration cong) {
63 if(tree->kind == OpaqueShape) {
64 NSRect rect = convert_rect(tree->data.shape,cong->window);
65 [cong->clipPath appendBezierPathWithRect:rect];
66 }
67 }
68
52 int Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) { 69 int Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) {
53 SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata; 70 SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata;
54 if(data->saved == SDL_TRUE) { 71 if(data->saved == SDL_TRUE) {
55 [data->context restoreGraphicsState]; 72 [data->context restoreGraphicsState];
56 data->saved = SDL_FALSE; 73 data->saved = SDL_FALSE;
57 } 74 }
58 75
59 [data->context saveGraphicsState]; 76 [data->context saveGraphicsState];
60 data->saved = SDL_TRUE; 77 data->saved = SDL_TRUE;
61 78
62 [[NSColor clearColor] set]; 79 //[[NSColor clearColor] set];
63 NSRectFill([[((SDL_WindowData*)shaper->window->driverdata)->nswindow contentView] frame]); 80 //NSRectFill([[((SDL_WindowData*)shaper->window->driverdata)->nswindow contentView] frame]);
64 /* 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
65 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 NSBezierPath* clipPath = [NSBezierPath bezierPath];
84
85 SDL_PathConglomeration cong = {clipPath,shaper->window};
86
87 SDL_TraverseShapeTree(data->shape,&ConglomerateShapeTree,cong);
88
89 [clipPath addClip];
66 } 90 }
67 91
68 int Cocoa_ResizeWindowShape(SDL_Window *window) { 92 int Cocoa_ResizeWindowShape(SDL_Window *window) {
69 SDL_ShapeData* data = window->shaper->driverdata; 93 SDL_ShapeData* data = window->shaper->driverdata;
70 assert(data != NULL); 94 assert(data != NULL);