changeset 4811:d79939f20c45

Working on Cocoa implementation.
author Eli Gottlieb <eligottlieb@gmail.com>
date Mon, 26 Jul 2010 21:48:53 -0400
parents 7a602fd2121f
children 06a03d08cefb
files TODO src/video/cocoa/SDL_cocoashape.m src/video/cocoa/SDL_cocoawindow.m
diffstat 3 files changed, 35 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/TODO	Mon Jul 26 20:41:45 2010 -0400
+++ b/TODO	Mon Jul 26 21:48:53 2010 -0400
@@ -13,8 +13,8 @@
 4. Implement the SDL shaped-windows API for Mac OS X using Cocoa.  STATUS: IN PROGRESS
 --> Locate (once more) the API documentation for shaped windows under Cocoa.  STATUS: NEARLY FINISHED.
 --> Design and encode a version of SDL_ShapeData for Cocoa.  STATUS: IN PROGRESS.
---> Write Cocoa_CreateShaper().  STATUS: IN PROGRESS.
---> Write Cocoa_ResizeWindowShape().  STATUS: IN PROGRESS.
+--> Write Cocoa_CreateShaper().  STATUS: MOSTLY DONE, AFAIK.
+--> Write Cocoa_ResizeWindowShape().  STATUS: DONE, AFAIK.
 --> Write Cocoa_SetWindowShape().  STATUS: IN PROGRESS.
 --> If necessary, implement functionality adjunct to SDL_CalculateShapeBitmap() for Cocoa usage.
 5. Use testeyes to debug all implementations. STATUS: SPRINT + 2.
--- a/src/video/cocoa/SDL_cocoashape.m	Mon Jul 26 20:41:45 2010 -0400
+++ b/src/video/cocoa/SDL_cocoashape.m	Mon Jul 26 21:48:53 2010 -0400
@@ -20,6 +20,7 @@
     eligottlieb@gmail.com
 */
 
+#include "SDL_cocoavideo.h"
 #include "SDL_shape.h"
 #include "SDL_cocoashape.h"
 
@@ -27,16 +28,44 @@
 	SDL_WindowData* data = (SDL_WindowData*)window->driverdata;
 	[data->nswindow setAlpha:1.0];
 	[data->nswindow setOpaque:YES];
+	[data->nswindow setStyleMask:NSBorderlessWindowMask];
 	SDL_Shaper* result = result = malloc(sizeof(SDL_WindowShaper));
 	result->window = window;
 	result->mode.mode = ShapeModeDefault;
 	result->mode.parameters.binarizationCutoff = 1;
 	result->usershownflag = 0;
 	window->shaper = result;
+	
+	SDL_ShapeData* data = malloc(sizeof(SDL_ShapeData));
+	result->driverdata = data;
+	data->context = [data->nswindow graphicsContext];
+	data->saved = SDL_False;
+	data->rects = NULL;
+	data->count = 0;
+	
 	int resized_properly = Cocoa_ResizeWindowShape(window);
 	assert(resized_properly == 0);
 	return result;
 }
 
-extern int Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode);
-extern int Cocoa_ResizeWindowShape(SDL_Window *window);
+int Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) {
+	SDL_WindowData* data = (SDL_WindowData*)shaper->window->driverdata;
+	if(data->saved == SDL_True) {
+		[data->context restoreGraphicsState];
+		data->saved = SDL_False;
+	}
+		
+	[data->context saveGraphicsState];
+	data->saved = SDL_True;
+	
+	[[NSColor clearColor] set];
+	NSRectFill([[data->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
+           Windoze shape-calculation code: a list of rectangles.  This will work... I think. */
+}
+
+int Cocoa_ResizeWindowShape(SDL_Window *window) {
+	SDL_ShapeData* data = window->shaper->driverdata;
+	assert(data != NULL);
+	return 0;
+}
--- a/src/video/cocoa/SDL_cocoawindow.m	Mon Jul 26 20:41:45 2010 -0400
+++ b/src/video/cocoa/SDL_cocoawindow.m	Mon Jul 26 21:48:53 2010 -0400
@@ -28,6 +28,7 @@
 #include "../../events/SDL_windowevents_c.h"
 
 #include "SDL_cocoavideo.h"
+#include "SDL_cocoashape.h"
 
 static __inline__ void ConvertNSRect(NSRect *r)
 {
@@ -111,6 +112,7 @@
     NSRect rect = [_data->nswindow contentRectForFrameRect:[_data->nswindow frame]];
     w = (int)rect.size.width;
     h = (int)rect.size.height;
+    Cocoa_ResizeWindowShape(_data->window);
     SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESIZED, w, h);
 }