annotate src/video/win32/SDL_win32shape.c @ 4813:5b4c7d7d8953

Wrote out the system for breaking shape-masks into quad-trees of rectangles, and added code to conglomerate those quad-trees of rectangles into regions for setting shapes under Win32.
author Eli Gottlieb <eligottlieb@gmail.com>
date Wed, 28 Jul 2010 23:35:24 -0400
parents 329708ffe2a7
children 93402b9dd20c
rev   line source
4777
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
1 /*
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
3 Copyright (C) 2010 Eli Gottlieb
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
4
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
9
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
13 Lesser General Public License for more details.
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
14
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
18
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
19 Eli Gottlieb
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
20 eligottlieb@gmail.com
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
21 */
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
22
4785
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
23 #include <windows.h>
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
24 #include "SDL_win32shape.h"
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
25
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
26 SDL_WindowShaper* Win32_CreateShaper(SDL_Window * window) {
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
27 SDL_WindowShaper* result = malloc(sizeof(SDL_WindowShaper));
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
28 result->window = window;
4807
c9eb95f29770 Added color-key mode and redid the code to work with it.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4802
diff changeset
29 result->mode.mode = ShapeModeDefault;
c9eb95f29770 Added color-key mode and redid the code to work with it.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4802
diff changeset
30 result->mode.parameters.binarizationCutoff = 1;
4785
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
31 result->usershownflag = 0;
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
32 //Put some driver-data here.
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
33 window->shaper = result;
4813
5b4c7d7d8953 Wrote out the system for breaking shape-masks into quad-trees of rectangles, and added code to conglomerate those quad-trees of rectangles into regions for setting shapes under Win32.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
34 int resized_properly = Win32_ResizeWindowShape(window);
4785
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
35 assert(resized_properly == 0);
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
36 return result;
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
37 }
4777
6e03d73054d7 Fixed names of driver-specific implementation files.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
38
4813
5b4c7d7d8953 Wrote out the system for breaking shape-masks into quad-trees of rectangles, and added code to conglomerate those quad-trees of rectangles into regions for setting shapes under Win32.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
39 void CombineRectRegions(SDL_ShapeTree* node,HRGN* mask_region) {
5b4c7d7d8953 Wrote out the system for breaking shape-masks into quad-trees of rectangles, and added code to conglomerate those quad-trees of rectangles into regions for setting shapes under Win32.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
40 if(node->kind == OpaqueShape) {
5b4c7d7d8953 Wrote out the system for breaking shape-masks into quad-trees of rectangles, and added code to conglomerate those quad-trees of rectangles into regions for setting shapes under Win32.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
41 HRGN temp_region = CreateRectRgn(node->data.shape.x,node->data.shape.y,node->data.shape.w,node->data.shape.h);
5b4c7d7d8953 Wrote out the system for breaking shape-masks into quad-trees of rectangles, and added code to conglomerate those quad-trees of rectangles into regions for setting shapes under Win32.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
42 CombineRgn(*mask_region,*mask_region,temp_region, RGN_OR);
5b4c7d7d8953 Wrote out the system for breaking shape-masks into quad-trees of rectangles, and added code to conglomerate those quad-trees of rectangles into regions for setting shapes under Win32.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
43 DeleteObject(temp_region);
5b4c7d7d8953 Wrote out the system for breaking shape-masks into quad-trees of rectangles, and added code to conglomerate those quad-trees of rectangles into regions for setting shapes under Win32.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
44 }
5b4c7d7d8953 Wrote out the system for breaking shape-masks into quad-trees of rectangles, and added code to conglomerate those quad-trees of rectangles into regions for setting shapes under Win32.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
45 }
5b4c7d7d8953 Wrote out the system for breaking shape-masks into quad-trees of rectangles, and added code to conglomerate those quad-trees of rectangles into regions for setting shapes under Win32.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
46
4785
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
47 int Win32_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) {
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
48 assert(shaper != NULL && shape != NULL);
4813
5b4c7d7d8953 Wrote out the system for breaking shape-masks into quad-trees of rectangles, and added code to conglomerate those quad-trees of rectangles into regions for setting shapes under Win32.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
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)
5b4c7d7d8953 Wrote out the system for breaking shape-masks into quad-trees of rectangles, and added code to conglomerate those quad-trees of rectangles into regions for setting shapes under Win32.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
50 return SDL_INVALID_SHAPE_ARGUMENT;
5b4c7d7d8953 Wrote out the system for breaking shape-masks into quad-trees of rectangles, and added code to conglomerate those quad-trees of rectangles into regions for setting shapes under Win32.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
51
5b4c7d7d8953 Wrote out the system for breaking shape-masks into quad-trees of rectangles, and added code to conglomerate those quad-trees of rectangles into regions for setting shapes under Win32.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
52 SDL_ShapeData *data = (SDL_ShapeData*)shaper->driverdata;
5b4c7d7d8953 Wrote out the system for breaking shape-masks into quad-trees of rectangles, and added code to conglomerate those quad-trees of rectangles into regions for setting shapes under Win32.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
53 data->mask_tree = SDL_CalculateShapeTree(shapeMode,shape,SDL_FALSE);
4785
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
54
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
55 /*
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
56 * Start with empty region
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
57 */
4813
5b4c7d7d8953 Wrote out the system for breaking shape-masks into quad-trees of rectangles, and added code to conglomerate those quad-trees of rectangles into regions for setting shapes under Win32.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
58 HRGN mask_region = CreateRectRgn(0, 0, 0, 0);
4787
e25ad8d97027 Ported over, to the best of my ability, the code for Win32 shaped windows and patched in the correct C syntax and coding conventions of SDL.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
59
4813
5b4c7d7d8953 Wrote out the system for breaking shape-masks into quad-trees of rectangles, and added code to conglomerate those quad-trees of rectangles into regions for setting shapes under Win32.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
60 SDL_TraverseShapeTree(data->mask_tree,&CombineRectRegions,&mask_region);
4785
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
61
4787
e25ad8d97027 Ported over, to the best of my ability, the code for Win32 shaped windows and patched in the correct C syntax and coding conventions of SDL.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
62 /*
e25ad8d97027 Ported over, to the best of my ability, the code for Win32 shaped windows and patched in the correct C syntax and coding conventions of SDL.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
63 * Set the new region mask for the window
e25ad8d97027 Ported over, to the best of my ability, the code for Win32 shaped windows and patched in the correct C syntax and coding conventions of SDL.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4785
diff changeset
64 */
4813
5b4c7d7d8953 Wrote out the system for breaking shape-masks into quad-trees of rectangles, and added code to conglomerate those quad-trees of rectangles into regions for setting shapes under Win32.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
65 SetWindowRgn((SDL_WindowData*)(shaper->window->driverdata)->hwnd, mask_region, TRUE);
5b4c7d7d8953 Wrote out the system for breaking shape-masks into quad-trees of rectangles, and added code to conglomerate those quad-trees of rectangles into regions for setting shapes under Win32.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
66
5b4c7d7d8953 Wrote out the system for breaking shape-masks into quad-trees of rectangles, and added code to conglomerate those quad-trees of rectangles into regions for setting shapes under Win32.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
67 return 0;
4785
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
68 }
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
69
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
70 int Win32_ResizeWindowShape(SDL_Window *window) {
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
71 SDL_ShapeData* data = window->shaper->driverdata;
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
72 assert(data != NULL);
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
73
4813
5b4c7d7d8953 Wrote out the system for breaking shape-masks into quad-trees of rectangles, and added code to conglomerate those quad-trees of rectangles into regions for setting shapes under Win32.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
74 if(data->mask_tree != NULL)
5b4c7d7d8953 Wrote out the system for breaking shape-masks into quad-trees of rectangles, and added code to conglomerate those quad-trees of rectangles into regions for setting shapes under Win32.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4809
diff changeset
75 SDL_FreeShapeTree(&data->mask_tree);
4785
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
76
4802
f14a8c05f5bb Minor bugfixes. testshape now draws a shaped window with bizarre, pixellated gashes of transparency across it, and in doing so seems to hog a system resource and slow the rest of the video system down.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4787
diff changeset
77 window->shaper->usershownflag |= window->flags & SDL_WINDOW_SHOWN;
4785
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
78
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
79 return 0;
ef8b32ef9793 Updated test code, updated win32 code a bit (still not complete, but hopefully tonight), and removed the last vestiges of ellipse and polygon drawing support.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4777
diff changeset
80 }