Working on Cocoa implementation.
authorEli Gottlieb <eligottlieb@gmail.com>
Mon, 26 Jul 2010 21:48:53 -0400
changeset 4811d79939f20c45
parent 4810 7a602fd2121f
child 4812 06a03d08cefb
Working on Cocoa implementation.
TODO
src/video/cocoa/SDL_cocoashape.m
src/video/cocoa/SDL_cocoawindow.m
     1.1 --- a/TODO	Mon Jul 26 20:41:45 2010 -0400
     1.2 +++ b/TODO	Mon Jul 26 21:48:53 2010 -0400
     1.3 @@ -13,8 +13,8 @@
     1.4  4. Implement the SDL shaped-windows API for Mac OS X using Cocoa.  STATUS: IN PROGRESS
     1.5  --> Locate (once more) the API documentation for shaped windows under Cocoa.  STATUS: NEARLY FINISHED.
     1.6  --> Design and encode a version of SDL_ShapeData for Cocoa.  STATUS: IN PROGRESS.
     1.7 ---> Write Cocoa_CreateShaper().  STATUS: IN PROGRESS.
     1.8 ---> Write Cocoa_ResizeWindowShape().  STATUS: IN PROGRESS.
     1.9 +--> Write Cocoa_CreateShaper().  STATUS: MOSTLY DONE, AFAIK.
    1.10 +--> Write Cocoa_ResizeWindowShape().  STATUS: DONE, AFAIK.
    1.11  --> Write Cocoa_SetWindowShape().  STATUS: IN PROGRESS.
    1.12  --> If necessary, implement functionality adjunct to SDL_CalculateShapeBitmap() for Cocoa usage.
    1.13  5. Use testeyes to debug all implementations. STATUS: SPRINT + 2.
     2.1 --- a/src/video/cocoa/SDL_cocoashape.m	Mon Jul 26 20:41:45 2010 -0400
     2.2 +++ b/src/video/cocoa/SDL_cocoashape.m	Mon Jul 26 21:48:53 2010 -0400
     2.3 @@ -20,6 +20,7 @@
     2.4      eligottlieb@gmail.com
     2.5  */
     2.6  
     2.7 +#include "SDL_cocoavideo.h"
     2.8  #include "SDL_shape.h"
     2.9  #include "SDL_cocoashape.h"
    2.10  
    2.11 @@ -27,16 +28,44 @@
    2.12  	SDL_WindowData* data = (SDL_WindowData*)window->driverdata;
    2.13  	[data->nswindow setAlpha:1.0];
    2.14  	[data->nswindow setOpaque:YES];
    2.15 +	[data->nswindow setStyleMask:NSBorderlessWindowMask];
    2.16  	SDL_Shaper* result = result = malloc(sizeof(SDL_WindowShaper));
    2.17  	result->window = window;
    2.18  	result->mode.mode = ShapeModeDefault;
    2.19  	result->mode.parameters.binarizationCutoff = 1;
    2.20  	result->usershownflag = 0;
    2.21  	window->shaper = result;
    2.22 +	
    2.23 +	SDL_ShapeData* data = malloc(sizeof(SDL_ShapeData));
    2.24 +	result->driverdata = data;
    2.25 +	data->context = [data->nswindow graphicsContext];
    2.26 +	data->saved = SDL_False;
    2.27 +	data->rects = NULL;
    2.28 +	data->count = 0;
    2.29 +	
    2.30  	int resized_properly = Cocoa_ResizeWindowShape(window);
    2.31  	assert(resized_properly == 0);
    2.32  	return result;
    2.33  }
    2.34  
    2.35 -extern int Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode);
    2.36 -extern int Cocoa_ResizeWindowShape(SDL_Window *window);
    2.37 +int Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) {
    2.38 +	SDL_WindowData* data = (SDL_WindowData*)shaper->window->driverdata;
    2.39 +	if(data->saved == SDL_True) {
    2.40 +		[data->context restoreGraphicsState];
    2.41 +		data->saved = SDL_False;
    2.42 +	}
    2.43 +		
    2.44 +	[data->context saveGraphicsState];
    2.45 +	data->saved = SDL_True;
    2.46 +	
    2.47 +	[[NSColor clearColor] set];
    2.48 +	NSRectFill([[data->nswindow contentView] frame]);
    2.49 +	/* TODO: It looks like Cocoa can set a clipping path based on a list of rectangles.  That's what we get from the
    2.50 +           Windoze shape-calculation code: a list of rectangles.  This will work... I think. */
    2.51 +}
    2.52 +
    2.53 +int Cocoa_ResizeWindowShape(SDL_Window *window) {
    2.54 +	SDL_ShapeData* data = window->shaper->driverdata;
    2.55 +	assert(data != NULL);
    2.56 +	return 0;
    2.57 +}
     3.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Mon Jul 26 20:41:45 2010 -0400
     3.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Mon Jul 26 21:48:53 2010 -0400
     3.3 @@ -28,6 +28,7 @@
     3.4  #include "../../events/SDL_windowevents_c.h"
     3.5  
     3.6  #include "SDL_cocoavideo.h"
     3.7 +#include "SDL_cocoashape.h"
     3.8  
     3.9  static __inline__ void ConvertNSRect(NSRect *r)
    3.10  {
    3.11 @@ -111,6 +112,7 @@
    3.12      NSRect rect = [_data->nswindow contentRectForFrameRect:[_data->nswindow frame]];
    3.13      w = (int)rect.size.width;
    3.14      h = (int)rect.size.height;
    3.15 +    Cocoa_ResizeWindowShape(_data->window);
    3.16      SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESIZED, w, h);
    3.17  }
    3.18