comparison src/video/win32/SDL_win32shape.c @ 4838:1f9915666afd

Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
author Eli Gottlieb <eligottlieb@gmail.com>
date Mon, 09 Aug 2010 15:37:20 -0400
parents 55f32099a4b5
children 05d172e92b52
comparison
equal deleted inserted replaced
4826:d532a5a114cd 4838:1f9915666afd
21 */ 21 */
22 22
23 #include "SDL_win32shape.h" 23 #include "SDL_win32shape.h"
24 #include "SDL_win32video.h" 24 #include "SDL_win32video.h"
25 25
26 SDL_WindowShaper* Win32_CreateShaper(SDL_Window * window) { 26 SDL_WindowShaper*
27 int resized_properly; 27 Win32_CreateShaper(SDL_Window * window) {
28 SDL_WindowShaper* result = (SDL_WindowShaper *)SDL_malloc(sizeof(SDL_WindowShaper)); 28 int resized_properly;
29 result->window = window; 29 SDL_WindowShaper* result = (SDL_WindowShaper *)SDL_malloc(sizeof(SDL_WindowShaper));
30 result->mode.mode = ShapeModeDefault; 30 result->window = window;
31 result->mode.parameters.binarizationCutoff = 1; 31 result->mode.mode = ShapeModeDefault;
32 result->usershownflag = 0; 32 result->mode.parameters.binarizationCutoff = 1;
33 result->driverdata = (SDL_ShapeData*)SDL_malloc(sizeof(SDL_ShapeData)); 33 result->usershownflag = 0;
34 ((SDL_ShapeData*)result->driverdata)->mask_tree = NULL; 34 result->driverdata = (SDL_ShapeData*)SDL_malloc(sizeof(SDL_ShapeData));
35 //Put some driver-data here. 35 ((SDL_ShapeData*)result->driverdata)->mask_tree = NULL;
36 window->shaper = result; 36 //Put some driver-data here.
37 resized_properly = Win32_ResizeWindowShape(window); 37 window->shaper = result;
38 if (resized_properly != 0) 38 resized_properly = Win32_ResizeWindowShape(window);
39 return NULL; 39 if (resized_properly != 0)
40 return NULL;
40 41
41 return result; 42 return result;
42 } 43 }
43 44
44 void CombineRectRegions(SDL_ShapeTree* node, void* closure) { 45 void
45 HRGN* mask_region = (HRGN *)closure; 46 CombineRectRegions(SDL_ShapeTree* node, void* closure) {
46 if(node->kind == OpaqueShape) { 47 HRGN* mask_region = (HRGN *)closure;
47 HRGN temp_region = CreateRectRgn(node->data.shape.x,node->data.shape.y,node->data.shape.w,node->data.shape.h); 48 if(node->kind == OpaqueShape) {
48 CombineRgn(*mask_region,*mask_region,temp_region, RGN_OR); 49 HRGN temp_region = CreateRectRgn(node->data.shape.x,node->data.shape.y,node->data.shape.w,node->data.shape.h);
49 DeleteObject(temp_region); 50 CombineRgn(*mask_region,*mask_region,temp_region, RGN_OR);
50 } 51 DeleteObject(temp_region);
52 }
51 } 53 }
52 54
53 int Win32_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) { 55 int
54 SDL_ShapeData *data; 56 Win32_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) {
55 HRGN mask_region; 57 SDL_ShapeData *data;
58 HRGN mask_region;
56 SDL_WindowData *windowdata; 59 SDL_WindowData *windowdata;
57 HWND hwnd; 60 HWND hwnd;
58 61
59 if (shaper == NULL || shape == NULL) 62 if (shaper == NULL || shape == NULL)
60 return SDL_INVALID_SHAPE_ARGUMENT; 63 return SDL_INVALID_SHAPE_ARGUMENT;
61 if(shape->format->Amask == 0 && shapeMode->mode != ShapeModeColorKey || shape->w != shaper->window->w || shape->h != shaper->window->h) 64 if(shape->format->Amask == 0 && shapeMode->mode != ShapeModeColorKey || shape->w != shaper->window->w || shape->h != shaper->window->h)
62 return SDL_INVALID_SHAPE_ARGUMENT; 65 return SDL_INVALID_SHAPE_ARGUMENT;
63 66
64 data = (SDL_ShapeData*)shaper->driverdata; 67 data = (SDL_ShapeData*)shaper->driverdata;
65 if(data->mask_tree != NULL) 68 if(data->mask_tree != NULL)
66 SDL_FreeShapeTree(&data->mask_tree); 69 SDL_FreeShapeTree(&data->mask_tree);
67 data->mask_tree = SDL_CalculateShapeTree(*shapeMode,shape,SDL_FALSE); 70 data->mask_tree = SDL_CalculateShapeTree(*shapeMode,shape,SDL_FALSE);
68 71
69 /* 72 /*
70 * Start with empty region 73 * Start with empty region
71 */ 74 */
72 mask_region = CreateRectRgn(0, 0, 0, 0); 75 mask_region = CreateRectRgn(0, 0, 0, 0);
73 76
74 SDL_TraverseShapeTree(data->mask_tree,&CombineRectRegions,&mask_region); 77 SDL_TraverseShapeTree(data->mask_tree,&CombineRectRegions,&mask_region);
75 78
76 /* 79 /*
77 * Set the new region mask for the window 80 * Set the new region mask for the window
78 */ 81 */
79 windowdata=(SDL_WindowData *)(shaper->window->driverdata); 82 windowdata=(SDL_WindowData *)(shaper->window->driverdata);
80 hwnd = windowdata->hwnd; 83 hwnd = windowdata->hwnd;
81 SetWindowRgn(hwnd, mask_region, TRUE); 84 SetWindowRgn(hwnd, mask_region, TRUE);
82 85
83 return 0; 86 return 0;
84 } 87 }
85 88
86 int Win32_ResizeWindowShape(SDL_Window *window) { 89 int
87 SDL_ShapeData* data; 90 Win32_ResizeWindowShape(SDL_Window *window) {
91 SDL_ShapeData* data;
88 92
89 if (window == NULL) 93 if (window == NULL)
90 return -1; 94 return -1;
91 data = (SDL_ShapeData *)window->shaper->driverdata; 95 data = (SDL_ShapeData *)window->shaper->driverdata;
92 if (data == NULL) 96 if (data == NULL)
93 return -1; 97 return -1;
94 98
95 if(data->mask_tree != NULL) 99 if(data->mask_tree != NULL)
96 SDL_FreeShapeTree(&data->mask_tree); 100 SDL_FreeShapeTree(&data->mask_tree);
97 101
98 window->shaper->usershownflag |= window->flags & SDL_WINDOW_SHOWN; 102 window->shaper->usershownflag |= window->flags & SDL_WINDOW_SHOWN;
99 103
100 return 0; 104 return 0;
101 } 105 }