comparison src/video/windows/SDL_windowsshape.c @ 5062:e8916fe9cfc8

Fixed bug #925 Changed "win32" to "windows"
author Sam Lantinga <slouken@libsdl.org>
date Thu, 20 Jan 2011 18:04:05 -0800
parents src/video/win32/SDL_win32shape.c@10b96029e734
children
comparison
equal deleted inserted replaced
5061:9e9940eae455 5062:e8916fe9cfc8
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 2010 Eli Gottlieb
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Eli Gottlieb
20 eligottlieb@gmail.com
21 */
22
23 #include <stdio.h>
24 #include "SDL_assert.h"
25 #include "SDL_windowsshape.h"
26 #include "SDL_windowsvideo.h"
27
28 SDL_WindowShaper*
29 Win32_CreateShaper(SDL_Window * window) {
30 int resized_properly;
31 SDL_WindowShaper* result = (SDL_WindowShaper *)SDL_malloc(sizeof(SDL_WindowShaper));
32 result->window = window;
33 result->mode.mode = ShapeModeDefault;
34 result->mode.parameters.binarizationCutoff = 1;
35 result->userx = result->usery = 0;
36 result->driverdata = (SDL_ShapeData*)SDL_malloc(sizeof(SDL_ShapeData));
37 ((SDL_ShapeData*)result->driverdata)->mask_tree = NULL;
38 //Put some driver-data here.
39 window->shaper = result;
40 resized_properly = Win32_ResizeWindowShape(window);
41 if (resized_properly != 0)
42 return NULL;
43
44 return result;
45 }
46
47 void
48 CombineRectRegions(SDL_ShapeTree* node,void* closure) {
49 HRGN mask_region = *((HRGN*)closure),temp_region = NULL;
50 if(node->kind == OpaqueShape) {
51 //Win32 API regions exclude their outline, so we widen the region by one pixel in each direction to include the real outline.
52 temp_region = CreateRectRgn(node->data.shape.x,node->data.shape.y,node->data.shape.x + node->data.shape.w + 1,node->data.shape.y + node->data.shape.h + 1);
53 if(mask_region != NULL) {
54 CombineRgn(mask_region,mask_region,temp_region,RGN_OR);
55 DeleteObject(temp_region);
56 }
57 else
58 *((HRGN*)closure) = temp_region;
59 }
60 }
61
62 int
63 Win32_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode) {
64 SDL_ShapeData *data;
65 HRGN mask_region = NULL;
66
67 if (shaper == NULL || shape == NULL)
68 return SDL_INVALID_SHAPE_ARGUMENT;
69 if(shape->format->Amask == 0 && shape_mode->mode != ShapeModeColorKey || shape->w != shaper->window->w || shape->h != shaper->window->h)
70 return SDL_INVALID_SHAPE_ARGUMENT;
71
72 data = (SDL_ShapeData*)shaper->driverdata;
73 if(data->mask_tree != NULL)
74 SDL_FreeShapeTree(&data->mask_tree);
75 data->mask_tree = SDL_CalculateShapeTree(*shape_mode,shape);
76
77 SDL_TraverseShapeTree(data->mask_tree,&CombineRectRegions,&mask_region);
78 SDL_assert(mask_region != NULL);
79
80 SetWindowRgn(((SDL_WindowData *)(shaper->window->driverdata))->hwnd, mask_region, TRUE);
81
82 return 0;
83 }
84
85 int
86 Win32_ResizeWindowShape(SDL_Window *window) {
87 SDL_ShapeData* data;
88
89 if (window == NULL)
90 return -1;
91 data = (SDL_ShapeData *)window->shaper->driverdata;
92 if (data == NULL)
93 return -1;
94
95 if(data->mask_tree != NULL)
96 SDL_FreeShapeTree(&data->mask_tree);
97 if(window->shaper->hasshape == SDL_TRUE) {
98 window->shaper->userx = window->x;
99 window->shaper->usery = window->y;
100 SDL_SetWindowPosition(window,-1000,-1000);
101 }
102
103 return 0;
104 }