comparison src/video/cocoa/SDL_cocoashape.m @ 4834:fd5bb97ec05d

Improving Cocoa implementation and fixed a small bug in SDL_shape.c.
author egottlieb
date Thu, 05 Aug 2010 18:58:45 -0400
parents 34fb492cefe3
children 40b5293d0598
comparison
equal deleted inserted replaced
4833:34fb492cefe3 4834:fd5bb97ec05d
27 #include "SDL_cocoashape.h" 27 #include "SDL_cocoashape.h"
28 #include "../SDL_sysvideo.h" 28 #include "../SDL_sysvideo.h"
29 29
30 SDL_WindowShaper* Cocoa_CreateShaper(SDL_Window* window) { 30 SDL_WindowShaper* Cocoa_CreateShaper(SDL_Window* window) {
31 SDL_WindowData* data = (SDL_WindowData*)window->driverdata; 31 SDL_WindowData* data = (SDL_WindowData*)window->driverdata;
32 [data->nswindow setAlphaValue:1.0]; 32 [data->nswindow setOpaque:NO];
33 [data->nswindow setOpaque:YES]; 33 [data->nswindow setBackgroundColor:[NSColor clearColor]];
34 [data->nswindow setStyleMask:NSBorderlessWindowMask]; 34 [data->nswindow setStyleMask:NSBorderlessWindowMask];
35 SDL_WindowShaper* result = SDL_malloc(sizeof(SDL_WindowShaper)); 35 SDL_WindowShaper* result = SDL_malloc(sizeof(SDL_WindowShaper));
36 result->window = window; 36 result->window = window;
37 result->mode.mode = ShapeModeDefault; 37 result->mode.mode = ShapeModeDefault;
38 result->mode.parameters.binarizationCutoff = 1; 38 result->mode.parameters.binarizationCutoff = 1;
40 window->shaper = result; 40 window->shaper = result;
41 41
42 SDL_ShapeData* shape_data = SDL_malloc(sizeof(SDL_ShapeData)); 42 SDL_ShapeData* shape_data = SDL_malloc(sizeof(SDL_ShapeData));
43 result->driverdata = shape_data; 43 result->driverdata = shape_data;
44 shape_data->context = [data->nswindow graphicsContext]; 44 shape_data->context = [data->nswindow graphicsContext];
45 SDL_assert(shape_data->context != NULL);
45 shape_data->saved = SDL_FALSE; 46 shape_data->saved = SDL_FALSE;
46 shape_data->shape = NULL; 47 shape_data->shape = NULL;
47 48
48 int resized_properly = Cocoa_ResizeWindowShape(window); 49 int resized_properly = Cocoa_ResizeWindowShape(window);
49 SDL_assert(resized_properly == 0); 50 SDL_assert(resized_properly == 0);
68 } 69 }
69 } 70 }
70 71
71 int Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) { 72 int Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) {
72 SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata; 73 SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata;
73 if(data->saved == SDL_TRUE) { 74 /* if(data->saved == SDL_TRUE) {
74 [data->context restoreGraphicsState]; 75 [data->context restoreGraphicsState];
75 data->saved = SDL_FALSE; 76 data->saved = SDL_FALSE;
76 } 77 }*/
77 78
78 [data->context saveGraphicsState]; 79 /*[data->context saveGraphicsState];
79 data->saved = SDL_TRUE; 80 data->saved = SDL_TRUE;*/
80 81
81 //[[NSColor clearColor] set]; 82 [NSGraphicsContext saveGraphicsState];
82 //NSRectFill([[((SDL_WindowData*)shaper->window->driverdata)->nswindow contentView] frame]); 83
83 /* TODO: It looks like Cocoa can set a clipping path based on a list of rectangles. That's what we get from the 84 [NSGraphicsContext setCurrentContext:data->context];
84 Windoze shape-calculation code: a list of rectangles. This will work... I think. */ 85 SDL_WindowData* window_data = (SDL_WindowData*)shaper->window->driverdata;
86
85 data->shape = SDL_CalculateShapeTree(*shapeMode,shape,SDL_FALSE); 87 data->shape = SDL_CalculateShapeTree(*shapeMode,shape,SDL_FALSE);
86 NSBezierPath* clipPath = [NSBezierPath bezierPath]; 88 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
89 NSBezierPath* clipPath = [[NSBezierPath bezierPath] autorelease];
87 90
88 SDL_PathConglomeration cong = {clipPath,shaper->window}; 91 SDL_PathConglomeration cong = {clipPath,shaper->window};
89 92
90 SDL_TraverseShapeTree(data->shape,(SDL_TraversalFunction)&ConglomerateShapeTree,(void*)&cong); 93 SDL_TraverseShapeTree(data->shape,(SDL_TraversalFunction)&ConglomerateShapeTree,(void*)&cong);
91 94
95 SDL_assert([NSGraphicsContext currentContext] != NULL);
92 [clipPath addClip]; 96 [clipPath addClip];
97
98 [NSGraphicsContext restoreGraphicsState];
99 [pool release];
93 } 100 }
94 101
95 int Cocoa_ResizeWindowShape(SDL_Window *window) { 102 int Cocoa_ResizeWindowShape(SDL_Window *window) {
96 SDL_ShapeData* data = window->shaper->driverdata; 103 SDL_ShapeData* data = window->shaper->driverdata;
97 SDL_assert(data != NULL); 104 SDL_assert(data != NULL);