Commit 18dce59e authored by egottlieb's avatar egottlieb

Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.

parent c510c4d9
...@@ -1184,14 +1184,14 @@ ...@@ -1184,14 +1184,14 @@
isa = PBXContainerItemProxy; isa = PBXContainerItemProxy;
containerPortal = 003FA63A093FFD41000C53B3 /* SDL.xcodeproj */; containerPortal = 003FA63A093FFD41000C53B3 /* SDL.xcodeproj */;
proxyType = 2; proxyType = 2;
remoteGlobalIDString = 00D8D9EF1195090700638393 /* testsdl.app */; remoteGlobalIDString = 00D8D9EF1195090700638393;
remoteInfo = testsdl; remoteInfo = testsdl;
}; };
4537749D1209152D002F0F45 /* PBXContainerItemProxy */ = { 4537749D1209152D002F0F45 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy; isa = PBXContainerItemProxy;
containerPortal = 08FB7793FE84155DC02AAC07 /* Project object */; containerPortal = 08FB7793FE84155DC02AAC07 /* Project object */;
proxyType = 1; proxyType = 1;
remoteGlobalIDString = BEC567F70761D90600A33029 /* sdlcommon */; remoteGlobalIDString = BEC567F70761D90600A33029;
remoteInfo = sdlcommon; remoteInfo = sdlcommon;
}; };
BEC568300761D90600A33029 /* PBXContainerItemProxy */ = { BEC568300761D90600A33029 /* PBXContainerItemProxy */ = {
......
...@@ -38,7 +38,7 @@ typedef struct { ...@@ -38,7 +38,7 @@ typedef struct {
} SDL_ShapeData; } SDL_ShapeData;
extern SDL_WindowShaper* Cocoa_CreateShaper(SDL_Window* window); extern SDL_WindowShaper* Cocoa_CreateShaper(SDL_Window* window);
extern int Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode); extern int Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
extern int Cocoa_ResizeWindowShape(SDL_Window *window); extern int Cocoa_ResizeWindowShape(SDL_Window *window);
#endif #endif
...@@ -23,47 +23,72 @@ ...@@ -23,47 +23,72 @@
#include "SDL_cocoavideo.h" #include "SDL_cocoavideo.h"
#include "SDL_shape.h" #include "SDL_shape.h"
#include "SDL_cocoashape.h" #include "SDL_cocoashape.h"
#include "../src/video/SDL_sysvideo.h"
SDL_WindowShaper* SDL_WindowShaper*
Cocoa_CreateShaper(SDL_Window* window) { Cocoa_CreateShaper(SDL_Window* window) {
SDL_WindowData* data = (SDL_WindowData*)window->driverdata; SDL_WindowData* windata = (SDL_WindowData*)window->driverdata;
[data->nswindow setAlpha:1.0]; [windata->nswindow setOpaque:NO];
[data->nswindow setOpaque:YES]; [windata->nswindow setStyleMask:NSBorderlessWindowMask];
[data->nswindow setStyleMask:NSBorderlessWindowMask]; SDL_WindowShaper* result = result = malloc(sizeof(SDL_WindowShaper));
SDL_Shaper* result = result = malloc(sizeof(SDL_WindowShaper));
result->window = window; result->window = window;
result->mode.mode = ShapeModeDefault; result->mode.mode = ShapeModeDefault;
result->mode.parameters.binarizationCutoff = 1; result->mode.parameters.binarizationCutoff = 1;
result->usershownflag = 0; result->userx = result->usery = 0;
window->shaper = result; window->shaper = result;
SDL_ShapeData* data = malloc(sizeof(SDL_ShapeData)); SDL_ShapeData* data = malloc(sizeof(SDL_ShapeData));
result->driverdata = data; result->driverdata = data;
data->context = [data->nswindow graphicsContext]; data->context = [windata->nswindow graphicsContext];
data->saved = SDL_False; data->saved = SDL_FALSE;
data->rects = NULL; data->shape = NULL;
data->count = 0;
int resized_properly = Cocoa_ResizeWindowShape(window); int resized_properly = Cocoa_ResizeWindowShape(window);
assert(resized_properly == 0); assert(resized_properly == 0);
return result; return result;
} }
typedef struct {
NSView* view;
NSBezierPath* path;
} SDL_CocoaClosure;
void
ConvertRects(SDL_ShapeTree* tree,void* closure) {
SDL_CocoaClosure* data = (SDL_CocoaClosure*)closure;
if(tree->kind == OpaqueShape) {
NSRect rect = NSMakeRect(tree->data.shape.x,tree->data.shape.y,tree->data.shape.w,tree->data.shape.h);
[data->path appendBezierPathWithRect:[data->view convertRect:rect toView:nil]];
}
}
int int
Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) { Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode) {
SDL_WindowData* data = (SDL_WindowData*)shaper->window->driverdata; SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata;
if(data->saved == SDL_True) { SDL_WindowData* windata = (SDL_WindowData*)shaper->window->driverdata;
SDL_CocoaClosure closure;
NSAutoreleasePool *pool = NULL;
if(data->saved == SDL_TRUE) {
[data->context restoreGraphicsState]; [data->context restoreGraphicsState];
data->saved = SDL_False; data->saved = SDL_FALSE;
} }
[data->context saveGraphicsState]; //[data->context saveGraphicsState];
data->saved = SDL_True; //data->saved = SDL_TRUE;
[[NSColor clearColor] set]; [[NSColor clearColor] set];
NSRectFill([[data->nswindow contentView] frame]); NSRectFill([[windata->nswindow contentView] frame]);
/* TODO: It looks like Cocoa can set a clipping path based on a list of rectangles. That's what we get from the /* TODO: It looks like Cocoa can set a clipping path based on a list of rectangles. That's what we get from the
Windoze shape-calculation code: a list of rectangles. This will work... I think. */ Windoze shape-calculation code: a list of rectangles. This will work... I think. */
data->shape = SDL_CalculateShapeTree(*shape_mode,shape);
pool = [[NSAutoreleasePool alloc] init];
closure.view = [windata->nswindow contentView];
closure.path = [[NSBezierPath bezierPath] autorelease];
SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure);
[NSGraphicsContext setCurrentContext:data->context];
[closure.path setClip];
[pool drain];
} }
int int
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment