changeset 4815:93402b9dd20c

Added Andreas's patch to fix my silly C++-style errors.
author Eli Gottlieb <eligottlieb@gmail.com>
date Thu, 29 Jul 2010 22:57:39 -0400
parents 4f7133445367
children eb433f0d2ac5
files VisualC/SDL/SDL_VS2010.vcxproj src/video/SDL_shape.c src/video/win32/SDL_win32events.c src/video/win32/SDL_win32shape.c
diffstat 4 files changed, 53 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/VisualC/SDL/SDL_VS2010.vcxproj	Thu Jul 29 12:49:17 2010 -0400
+++ b/VisualC/SDL/SDL_VS2010.vcxproj	Thu Jul 29 22:57:39 2010 -0400
@@ -285,6 +285,7 @@
     <ClInclude Include="..\..\src\video\SDL_blit_auto.h" />
     <ClInclude Include="..\..\src\video\SDL_blit_copy.h" />
     <ClInclude Include="..\..\src\video\SDL_blit_slow.h" />
+    <ClInclude Include="..\..\src\video\SDL_shape_internals.h" />
     <ClInclude Include="..\..\src\video\win32\SDL_d3drender.h" />
     <ClInclude Include="..\..\src\audio\windib\SDL_dibaudio.h" />
     <ClInclude Include="..\..\src\audio\disk\SDL_diskaudio.h" />
--- a/src/video/SDL_shape.c	Thu Jul 29 12:49:17 2010 -0400
+++ b/src/video/SDL_shape.c	Thu Jul 29 22:57:39 2010 -0400
@@ -114,7 +114,7 @@
 	SDL_bool pixel_transparent = SDL_FALSE;
 	int last_transparent = -1;
 	SDL_Color key;
-	SDL_ShapeTree* result = malloc(sizeof(SDL_ShapeTree));
+	SDL_ShapeTree* result = (SDL_ShapeTree*)SDL_malloc(sizeof(SDL_ShapeTree));
 	SDL_Rect next = {0,0,0,0};
 	for(y=dimensions.y;y<dimensions.h;y++)
 		for(x=dimensions.x;x<dimensions.w;x++) {
@@ -134,17 +134,17 @@
 			SDL_GetRGBA(pixel_value,mask->format,&r,&g,&b,&a);
 			switch(mode.mode) {
 				case(ShapeModeDefault):
-					pixel_transparent = (a >= 1 ? !invert : invert);
+					pixel_transparent = (SDL_bool)(a >= 1 ? !invert : invert);
 					break;
 				case(ShapeModeBinarizeAlpha):
-					pixel_transparent = (a >= mode.parameters.binarizationCutoff ? !invert : invert);
+					pixel_transparent = (SDL_bool)(a >= mode.parameters.binarizationCutoff ? !invert : invert);
 					break;
 				case(ShapeModeReverseBinarizeAlpha):
-					pixel_transparent = (a <= mode.parameters.binarizationCutoff ? !invert : invert);
+					pixel_transparent = (SDL_bool)(a <= mode.parameters.binarizationCutoff ? !invert : invert);
 					break;
 				case(ShapeModeColorKey):
 					key = mode.parameters.colorKey;
-					pixel_transparent = ((key.r == r && key.g == g && key.b == b) ? !invert : invert);
+					pixel_transparent = (SDL_bool)((key.r == r && key.g == g && key.b == b) ? !invert : invert);
 					break;
 			}
 			if(last_transparent == -1) {
@@ -159,16 +159,16 @@
 				//These will change from recursion to recursion.
 				next.x = dimensions.x;
 				next.y = dimensions.y;
-				result->data.children.upleft = RecursivelyCalculateShapeTree(mode,mask,invert,next);
+				result->data.children.upleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next);
 				next.x = dimensions.w / 2 + 1;
 				//Unneeded: next.y = dimensions.y;
-				result->data.children.upright = RecursivelyCalculateShapeTree(mode,mask,invert,next);
+				result->data.children.upright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next);
 				next.x = dimensions.x;
 				next.y = dimensions.h / 2 + 1;
-				result->data.children.downleft = RecursivelyCalculateShapeTree(mode,mask,invert,next);
+				result->data.children.downleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next);
 				next.x = dimensions.w / 2 + 1;
 				//Unneeded: next.y = dimensions.h / 2 + 1;
-				result->data.children.downright = RecursivelyCalculateShapeTree(mode,mask,invert,next);
+				result->data.children.downright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next);
 				return result;
 			}
 		}
@@ -191,10 +191,10 @@
 
 void SDL_TraverseShapeTree(SDL_ShapeTree *tree,void(*function)(SDL_ShapeTree*,void*),void* closure) {
 	if(tree->kind == QuadShape) {
-		SDL_TraverseShapeTree(tree->data.children.upleft,function,closure);
-		SDL_TraverseShapeTree(tree->data.children.upright,function,closure);
-		SDL_TraverseShapeTree(tree->data.children.downleft,function,closure);
-		SDL_TraverseShapeTree(tree->data.children.downright,function,closure);
+		SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upleft,function,closure);
+		SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upright,function,closure);
+		SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downleft,function,closure);
+		SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downright,function,closure);
 	}
 	else
 		function(tree,closure);
@@ -202,12 +202,12 @@
 
 void SDL_FreeShapeTree(SDL_ShapeTree** shapeTree) {
 	if((*shapeTree)->kind == QuadShape) {
-		SDL_FreeShapeTree(&(*shapeTree)->data.children.upleft);
-		SDL_FreeShapeTree(&(*shapeTree)->data.children.upright);
-		SDL_FreeShapeTree(&(*shapeTree)->data.children.downleft);
-		SDL_FreeShapeTree(&(*shapeTree)->data.children.downright);
+		SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.upleft);
+		SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.upright);
+		SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.downleft);
+		SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.downright);
 	}
-	free(*shapeTree);
+	SDL_free(*shapeTree);
 	*shapeTree = NULL;
 }
 
--- a/src/video/win32/SDL_win32events.c	Thu Jul 29 12:49:17 2010 -0400
+++ b/src/video/win32/SDL_win32events.c	Thu Jul 29 22:57:39 2010 -0400
@@ -28,6 +28,7 @@
 #include "SDL_config.h"
 
 #include "SDL_win32video.h"
+#include "SDL_win32shape.h"
 #include "SDL_syswm.h"
 #include "SDL_vkeys.h"
 #include "../../events/SDL_events_c.h"
@@ -249,10 +250,10 @@
             int w, h;
 
             /* we're collecting raw data to be able to identify the mouse (if there are several) */
-            GetRawInputData((HRAWINPUT) lParam, RID_INPUT, NULL, &size,
+            GetRawInputData((HRAWINPUT) lParam, RID_INPUT, NULL, (PUINT)&size,
                             sizeof(RAWINPUTHEADER));
             lpb = SDL_stack_alloc(BYTE, size);
-            GetRawInputData((HRAWINPUT) lParam, RID_INPUT, lpb, &size,
+            GetRawInputData((HRAWINPUT) lParam, RID_INPUT, lpb, (PUINT)&size,
                             sizeof(RAWINPUTHEADER));
             raw = (RAWINPUT *) lpb;
             header = &raw->header;
@@ -493,7 +494,7 @@
 
             /* If we allow resizing, let the resize happen naturally */
             if(SDL_IsShapedWindow(data->window))
-                SDL_ResizeWindowShape(data->window);
+                Win32_ResizeWindowShape(data->window);
             if (SDL_GetWindowFlags(data->window) & SDL_WINDOW_RESIZABLE) {
                 returnCode = 0;
                 break;
--- a/src/video/win32/SDL_win32shape.c	Thu Jul 29 12:49:17 2010 -0400
+++ b/src/video/win32/SDL_win32shape.c	Thu Jul 29 22:57:39 2010 -0400
@@ -20,23 +20,27 @@
     eligottlieb@gmail.com
 */
 
-#include <windows.h>
-#include "SDL_win32shape.h"
+#include "SDL_win32shape.h"
+#include "SDL_win32video.h"
 
 SDL_WindowShaper* Win32_CreateShaper(SDL_Window * window) {
-	SDL_WindowShaper* result = malloc(sizeof(SDL_WindowShaper));
+	int resized_properly;
+	SDL_WindowShaper* result = (SDL_WindowShaper *)SDL_malloc(sizeof(SDL_WindowShaper));
 	result->window = window;
 	result->mode.mode = ShapeModeDefault;
 	result->mode.parameters.binarizationCutoff = 1;
 	result->usershownflag = 0;
 	//Put some driver-data here.
 	window->shaper = result;
-	int resized_properly = Win32_ResizeWindowShape(window);
-	assert(resized_properly == 0);
+	resized_properly = Win32_ResizeWindowShape(window);
+	if (resized_properly != 0)
+			return NULL;
+
 	return result;
 }
 
-void CombineRectRegions(SDL_ShapeTree* node,HRGN* mask_region) {
+void CombineRectRegions(SDL_ShapeTree* node, void* closure) {
+	HRGN* mask_region = (HRGN *)closure;
 	if(node->kind == OpaqueShape) {
 		HRGN temp_region = CreateRectRgn(node->data.shape.x,node->data.shape.y,node->data.shape.w,node->data.shape.h);
 		CombineRgn(*mask_region,*mask_region,temp_region, RGN_OR);
@@ -45,31 +49,44 @@
 }
 
 int Win32_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) {
-	assert(shaper != NULL && shape != NULL);
+	SDL_ShapeData *data;
+	HRGN mask_region;
+    SDL_WindowData *windowdata;
+    HWND hwnd;
+
+	if (shaper == NULL || shape == NULL)
+		return SDL_INVALID_SHAPE_ARGUMENT;
 	if(!SDL_ISPIXELFORMAT_ALPHA(SDL_MasksToPixelFormatEnum(shape->format->BitsPerPixel,shape->format->Rmask,shape->format->Gmask,shape->format->Bmask,shape->format->Amask)) && shapeMode->mode != ShapeModeColorKey || shape->w != shaper->window->w || shape->h != shaper->window->h)
 		return SDL_INVALID_SHAPE_ARGUMENT;
 	
-	SDL_ShapeData *data = (SDL_ShapeData*)shaper->driverdata;
-	data->mask_tree = SDL_CalculateShapeTree(shapeMode,shape,SDL_FALSE);
+	data = (SDL_ShapeData*)shaper->driverdata;
+	data->mask_tree = SDL_CalculateShapeTree(*shapeMode,shape,SDL_FALSE);
 	
 	/*
 	 * Start with empty region 
 	 */
-	HRGN mask_region = CreateRectRgn(0, 0, 0, 0);
+	mask_region = CreateRectRgn(0, 0, 0, 0);
 	
 	SDL_TraverseShapeTree(data->mask_tree,&CombineRectRegions,&mask_region);
 	
 	/*
 	 * Set the new region mask for the window 
 	 */
-	SetWindowRgn((SDL_WindowData*)(shaper->window->driverdata)->hwnd, mask_region, TRUE);
+	windowdata=(SDL_WindowData *)(shaper->window->driverdata);
+	hwnd = windowdata->hwnd;
+	SetWindowRgn(hwnd, mask_region, TRUE);
 	
 	return 0;
 }
 
 int Win32_ResizeWindowShape(SDL_Window *window) {
-	SDL_ShapeData* data = window->shaper->driverdata;
-	assert(data != NULL);
+	SDL_ShapeData* data;
+
+	if (window == NULL)
+		return -1;
+	data = (SDL_ShapeData *)window->shaper->driverdata;
+	if (data == NULL)
+		return -1;
 	
 	if(data->mask_tree != NULL)
 		SDL_FreeShapeTree(&data->mask_tree);