comparison src/video/win32/SDL_win32shape.c @ 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 5b4c7d7d8953
children 55f32099a4b5
comparison
equal deleted inserted replaced
4814:4f7133445367 4815:93402b9dd20c
18 18
19 Eli Gottlieb 19 Eli Gottlieb
20 eligottlieb@gmail.com 20 eligottlieb@gmail.com
21 */ 21 */
22 22
23 #include <windows.h>
24 #include "SDL_win32shape.h" 23 #include "SDL_win32shape.h"
24 #include "SDL_win32video.h"
25 25
26 SDL_WindowShaper* Win32_CreateShaper(SDL_Window * window) { 26 SDL_WindowShaper* Win32_CreateShaper(SDL_Window * window) {
27 SDL_WindowShaper* result = malloc(sizeof(SDL_WindowShaper)); 27 int resized_properly;
28 SDL_WindowShaper* result = (SDL_WindowShaper *)SDL_malloc(sizeof(SDL_WindowShaper));
28 result->window = window; 29 result->window = window;
29 result->mode.mode = ShapeModeDefault; 30 result->mode.mode = ShapeModeDefault;
30 result->mode.parameters.binarizationCutoff = 1; 31 result->mode.parameters.binarizationCutoff = 1;
31 result->usershownflag = 0; 32 result->usershownflag = 0;
32 //Put some driver-data here. 33 //Put some driver-data here.
33 window->shaper = result; 34 window->shaper = result;
34 int resized_properly = Win32_ResizeWindowShape(window); 35 resized_properly = Win32_ResizeWindowShape(window);
35 assert(resized_properly == 0); 36 if (resized_properly != 0)
37 return NULL;
38
36 return result; 39 return result;
37 } 40 }
38 41
39 void CombineRectRegions(SDL_ShapeTree* node,HRGN* mask_region) { 42 void CombineRectRegions(SDL_ShapeTree* node, void* closure) {
43 HRGN* mask_region = (HRGN *)closure;
40 if(node->kind == OpaqueShape) { 44 if(node->kind == OpaqueShape) {
41 HRGN temp_region = CreateRectRgn(node->data.shape.x,node->data.shape.y,node->data.shape.w,node->data.shape.h); 45 HRGN temp_region = CreateRectRgn(node->data.shape.x,node->data.shape.y,node->data.shape.w,node->data.shape.h);
42 CombineRgn(*mask_region,*mask_region,temp_region, RGN_OR); 46 CombineRgn(*mask_region,*mask_region,temp_region, RGN_OR);
43 DeleteObject(temp_region); 47 DeleteObject(temp_region);
44 } 48 }
45 } 49 }
46 50
47 int Win32_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) { 51 int Win32_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) {
48 assert(shaper != NULL && shape != NULL); 52 SDL_ShapeData *data;
53 HRGN mask_region;
54 SDL_WindowData *windowdata;
55 HWND hwnd;
56
57 if (shaper == NULL || shape == NULL)
58 return SDL_INVALID_SHAPE_ARGUMENT;
49 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) 59 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)
50 return SDL_INVALID_SHAPE_ARGUMENT; 60 return SDL_INVALID_SHAPE_ARGUMENT;
51 61
52 SDL_ShapeData *data = (SDL_ShapeData*)shaper->driverdata; 62 data = (SDL_ShapeData*)shaper->driverdata;
53 data->mask_tree = SDL_CalculateShapeTree(shapeMode,shape,SDL_FALSE); 63 data->mask_tree = SDL_CalculateShapeTree(*shapeMode,shape,SDL_FALSE);
54 64
55 /* 65 /*
56 * Start with empty region 66 * Start with empty region
57 */ 67 */
58 HRGN mask_region = CreateRectRgn(0, 0, 0, 0); 68 mask_region = CreateRectRgn(0, 0, 0, 0);
59 69
60 SDL_TraverseShapeTree(data->mask_tree,&CombineRectRegions,&mask_region); 70 SDL_TraverseShapeTree(data->mask_tree,&CombineRectRegions,&mask_region);
61 71
62 /* 72 /*
63 * Set the new region mask for the window 73 * Set the new region mask for the window
64 */ 74 */
65 SetWindowRgn((SDL_WindowData*)(shaper->window->driverdata)->hwnd, mask_region, TRUE); 75 windowdata=(SDL_WindowData *)(shaper->window->driverdata);
76 hwnd = windowdata->hwnd;
77 SetWindowRgn(hwnd, mask_region, TRUE);
66 78
67 return 0; 79 return 0;
68 } 80 }
69 81
70 int Win32_ResizeWindowShape(SDL_Window *window) { 82 int Win32_ResizeWindowShape(SDL_Window *window) {
71 SDL_ShapeData* data = window->shaper->driverdata; 83 SDL_ShapeData* data;
72 assert(data != NULL); 84
85 if (window == NULL)
86 return -1;
87 data = (SDL_ShapeData *)window->shaper->driverdata;
88 if (data == NULL)
89 return -1;
73 90
74 if(data->mask_tree != NULL) 91 if(data->mask_tree != NULL)
75 SDL_FreeShapeTree(&data->mask_tree); 92 SDL_FreeShapeTree(&data->mask_tree);
76 93
77 window->shaper->usershownflag |= window->flags & SDL_WINDOW_SHOWN; 94 window->shaper->usershownflag |= window->flags & SDL_WINDOW_SHOWN;