Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
authoregottlieb
Mon, 16 Aug 2010 14:01:00 -0400
changeset 485991f4d4d5c395
parent 4858 10b96029e734
child 4860 8f1994e8d886
Recoded Cocoa code that got erased by... failure to commit? Merge? Eh.
Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj
src/video/cocoa/SDL_cocoashape.h
src/video/cocoa/SDL_cocoashape.m
     1.1 --- a/Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj	Mon Aug 16 10:48:54 2010 -0400
     1.2 +++ b/Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj	Mon Aug 16 14:01:00 2010 -0400
     1.3 @@ -1184,14 +1184,14 @@
     1.4  			isa = PBXContainerItemProxy;
     1.5  			containerPortal = 003FA63A093FFD41000C53B3 /* SDL.xcodeproj */;
     1.6  			proxyType = 2;
     1.7 -			remoteGlobalIDString = 00D8D9EF1195090700638393 /* testsdl.app */;
     1.8 +			remoteGlobalIDString = 00D8D9EF1195090700638393;
     1.9  			remoteInfo = testsdl;
    1.10  		};
    1.11  		4537749D1209152D002F0F45 /* PBXContainerItemProxy */ = {
    1.12  			isa = PBXContainerItemProxy;
    1.13  			containerPortal = 08FB7793FE84155DC02AAC07 /* Project object */;
    1.14  			proxyType = 1;
    1.15 -			remoteGlobalIDString = BEC567F70761D90600A33029 /* sdlcommon */;
    1.16 +			remoteGlobalIDString = BEC567F70761D90600A33029;
    1.17  			remoteInfo = sdlcommon;
    1.18  		};
    1.19  		BEC568300761D90600A33029 /* PBXContainerItemProxy */ = {
     2.1 --- a/src/video/cocoa/SDL_cocoashape.h	Mon Aug 16 10:48:54 2010 -0400
     2.2 +++ b/src/video/cocoa/SDL_cocoashape.h	Mon Aug 16 14:01:00 2010 -0400
     2.3 @@ -38,7 +38,7 @@
     2.4  } SDL_ShapeData;
     2.5  
     2.6  extern SDL_WindowShaper* Cocoa_CreateShaper(SDL_Window* window);
     2.7 -extern int Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode);
     2.8 +extern int Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
     2.9  extern int Cocoa_ResizeWindowShape(SDL_Window *window);
    2.10  
    2.11  #endif
     3.1 --- a/src/video/cocoa/SDL_cocoashape.m	Mon Aug 16 10:48:54 2010 -0400
     3.2 +++ b/src/video/cocoa/SDL_cocoashape.m	Mon Aug 16 14:01:00 2010 -0400
     3.3 @@ -23,47 +23,72 @@
     3.4  #include "SDL_cocoavideo.h"
     3.5  #include "SDL_shape.h"
     3.6  #include "SDL_cocoashape.h"
     3.7 +#include "../src/video/SDL_sysvideo.h"
     3.8  
     3.9  SDL_WindowShaper*
    3.10  Cocoa_CreateShaper(SDL_Window* window) {
    3.11 -    SDL_WindowData* data = (SDL_WindowData*)window->driverdata;
    3.12 -    [data->nswindow setAlpha:1.0];
    3.13 -    [data->nswindow setOpaque:YES];
    3.14 -    [data->nswindow setStyleMask:NSBorderlessWindowMask];
    3.15 -    SDL_Shaper* result = result = malloc(sizeof(SDL_WindowShaper));
    3.16 +    SDL_WindowData* windata = (SDL_WindowData*)window->driverdata;
    3.17 +    [windata->nswindow setOpaque:NO];
    3.18 +    [windata->nswindow setStyleMask:NSBorderlessWindowMask];
    3.19 +    SDL_WindowShaper* result = result = malloc(sizeof(SDL_WindowShaper));
    3.20      result->window = window;
    3.21      result->mode.mode = ShapeModeDefault;
    3.22      result->mode.parameters.binarizationCutoff = 1;
    3.23 -    result->usershownflag = 0;
    3.24 +    result->userx = result->usery = 0;
    3.25      window->shaper = result;
    3.26      
    3.27      SDL_ShapeData* data = malloc(sizeof(SDL_ShapeData));
    3.28      result->driverdata = data;
    3.29 -    data->context = [data->nswindow graphicsContext];
    3.30 -    data->saved = SDL_False;
    3.31 -    data->rects = NULL;
    3.32 -    data->count = 0;
    3.33 +    data->context = [windata->nswindow graphicsContext];
    3.34 +    data->saved = SDL_FALSE;
    3.35 +    data->shape = NULL;
    3.36      
    3.37      int resized_properly = Cocoa_ResizeWindowShape(window);
    3.38      assert(resized_properly == 0);
    3.39      return result;
    3.40  }
    3.41  
    3.42 +typedef struct {
    3.43 +    NSView* view;
    3.44 +    NSBezierPath* path;
    3.45 +} SDL_CocoaClosure;
    3.46 +
    3.47 +void
    3.48 +ConvertRects(SDL_ShapeTree* tree,void* closure) {
    3.49 +    SDL_CocoaClosure* data = (SDL_CocoaClosure*)closure;
    3.50 +    if(tree->kind == OpaqueShape) {
    3.51 +        NSRect rect = NSMakeRect(tree->data.shape.x,tree->data.shape.y,tree->data.shape.w,tree->data.shape.h);
    3.52 +        [data->path appendBezierPathWithRect:[data->view convertRect:rect toView:nil]];
    3.53 +    }
    3.54 +}
    3.55 +
    3.56  int
    3.57 -Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) {
    3.58 -    SDL_WindowData* data = (SDL_WindowData*)shaper->window->driverdata;
    3.59 -    if(data->saved == SDL_True) {
    3.60 +Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode) {
    3.61 +    SDL_ShapeData* data = (SDL_ShapeData*)shaper->driverdata;
    3.62 +	SDL_WindowData* windata = (SDL_WindowData*)shaper->window->driverdata;
    3.63 +	SDL_CocoaClosure closure;
    3.64 +	NSAutoreleasePool *pool = NULL;
    3.65 +    if(data->saved == SDL_TRUE) {
    3.66          [data->context restoreGraphicsState];
    3.67 -        data->saved = SDL_False;
    3.68 +        data->saved = SDL_FALSE;
    3.69      }
    3.70          
    3.71 -    [data->context saveGraphicsState];
    3.72 -    data->saved = SDL_True;
    3.73 +    //[data->context saveGraphicsState];
    3.74 +    //data->saved = SDL_TRUE;
    3.75      
    3.76      [[NSColor clearColor] set];
    3.77 -    NSRectFill([[data->nswindow contentView] frame]);
    3.78 +    NSRectFill([[windata->nswindow contentView] frame]);
    3.79      /* TODO: It looks like Cocoa can set a clipping path based on a list of rectangles.  That's what we get from the
    3.80             Windoze shape-calculation code: a list of rectangles.  This will work... I think. */
    3.81 +    data->shape = SDL_CalculateShapeTree(*shape_mode,shape);
    3.82 +	
    3.83 +	pool = [[NSAutoreleasePool alloc] init];
    3.84 +    closure.view = [windata->nswindow contentView];
    3.85 +    closure.path = [[NSBezierPath bezierPath] autorelease];
    3.86 +    SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure);
    3.87 +    [NSGraphicsContext setCurrentContext:data->context];
    3.88 +    [closure.path setClip];
    3.89 +    [pool drain];
    3.90  }
    3.91  
    3.92  int