annotate src/video/SDL_shape.c @ 4841:740e833b2c00

Fixed overwriting of SDL_shape.c in merge.
author Eli Gottlieb <eligottlieb@gmail.com>
date Mon, 09 Aug 2010 20:27:45 -0400
parents 05d172e92b52
children 0998d1b5dd23
rev   line source
4765
5ff305de5834 Added stub files, working on sample program SDLeyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
1 /*
5ff305de5834 Added stub files, working on sample program SDLeyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
5ff305de5834 Added stub files, working on sample program SDLeyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
3 Copyright (C) 2010 Eli Gottlieb
5ff305de5834 Added stub files, working on sample program SDLeyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
4
5ff305de5834 Added stub files, working on sample program SDLeyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
5ff305de5834 Added stub files, working on sample program SDLeyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
5ff305de5834 Added stub files, working on sample program SDLeyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
5ff305de5834 Added stub files, working on sample program SDLeyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
5ff305de5834 Added stub files, working on sample program SDLeyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
9
5ff305de5834 Added stub files, working on sample program SDLeyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
5ff305de5834 Added stub files, working on sample program SDLeyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
5ff305de5834 Added stub files, working on sample program SDLeyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ff305de5834 Added stub files, working on sample program SDLeyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
13 Lesser General Public License for more details.
5ff305de5834 Added stub files, working on sample program SDLeyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
14
5ff305de5834 Added stub files, working on sample program SDLeyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
5ff305de5834 Added stub files, working on sample program SDLeyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
5ff305de5834 Added stub files, working on sample program SDLeyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
5ff305de5834 Added stub files, working on sample program SDLeyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
18
5ff305de5834 Added stub files, working on sample program SDLeyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
19 Eli Gottlieb
5ff305de5834 Added stub files, working on sample program SDLeyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
20 eligottlieb@gmail.com
5ff305de5834 Added stub files, working on sample program SDLeyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
21 */
4769
83f9b95da263 Added the standard headers and footers that make SDL_shape.h and SDL_shape.c integrate properly into the build.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4766
diff changeset
22 #include "SDL_config.h"
4776
29dcad9c58b3 Removed and added back SDL_shape.{c,h} wholesale. Will this get them tracked properly?
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4775
diff changeset
23
4769
83f9b95da263 Added the standard headers and footers that make SDL_shape.h and SDL_shape.c integrate properly into the build.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4766
diff changeset
24 #include "SDL.h"
4841
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
25 #include "SDL_assert.h"
4769
83f9b95da263 Added the standard headers and footers that make SDL_shape.h and SDL_shape.c integrate properly into the build.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4766
diff changeset
26 #include "SDL_video.h"
83f9b95da263 Added the standard headers and footers that make SDL_shape.h and SDL_shape.c integrate properly into the build.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4766
diff changeset
27 #include "SDL_sysvideo.h"
4782
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4781
diff changeset
28 #include "SDL_pixels.h"
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4781
diff changeset
29 #include "SDL_surface.h"
4765
5ff305de5834 Added stub files, working on sample program SDLeyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff changeset
30 #include "SDL_shape.h"
4841
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
31 #include "SDL_shape_internals.h"
4766
7b50faf23907 Moved SDL_shape.h, and building out the API as needed by SDL_Eyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4765
diff changeset
32
4841
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
33 SDL_Window* SDL_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags) {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
34 SDL_Window *result = SDL_CreateWindow(title,x,y,w,h,SDL_WINDOW_BORDERLESS | flags & !SDL_WINDOW_FULLSCREEN & !SDL_WINDOW_SHOWN);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
35 if(result != NULL) {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
36 result->shaper = result->display->device->shape_driver.CreateShaper(result);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
37 if(result->shaper != NULL) {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
38 result->shaper->usershownflag = flags & SDL_WINDOW_SHOWN;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
39 result->shaper->mode.mode = ShapeModeDefault;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
40 result->shaper->mode.parameters.binarizationCutoff = 1;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
41 result->shaper->hasshape = SDL_FALSE;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
42 return result;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
43 }
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
44 else {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
45 SDL_DestroyWindow(result);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
46 return NULL;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
47 }
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
48 }
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
49 else
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
50 return NULL;
4766
7b50faf23907 Moved SDL_shape.h, and building out the API as needed by SDL_Eyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4765
diff changeset
51 }
7b50faf23907 Moved SDL_shape.h, and building out the API as needed by SDL_Eyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4765
diff changeset
52
4841
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
53 SDL_bool SDL_IsShapedWindow(const SDL_Window *window) {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
54 if(window == NULL)
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
55 return SDL_FALSE;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
56 else
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
57 return (SDL_bool)(window->shaper != NULL);
4782
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4781
diff changeset
58 }
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4781
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: 4810
diff changeset
60 /* REQUIRES that bitmap point to a w-by-h bitmap with ppb pixels-per-byte. */
4841
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
61 void SDL_CalculateShapeBitmap(SDL_WindowShapeMode mode,SDL_Surface *shape,Uint8* bitmap,Uint8 ppb) {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
62 int x = 0;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
63 int y = 0;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
64 Uint8 r = 0,g = 0,b = 0,alpha = 0;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
65 Uint8* pixel = NULL;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
66 Uint32 bitmap_pixel,pixel_value = 0,mask_value = 0;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
67 SDL_Color key;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
68 if(SDL_MUSTLOCK(shape))
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
69 SDL_LockSurface(shape);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
70 pixel = (Uint8*)shape->pixels;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
71 for(y = 0;y<shape->h;y++) {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
72 for(x=0;x<shape->w;x++) {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
73 alpha = 0;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
74 pixel_value = 0;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
75 pixel = (Uint8 *)(shape->pixels) + (y*shape->pitch) + (x*shape->format->BytesPerPixel);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
76 switch(shape->format->BytesPerPixel) {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
77 case(1):
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
78 pixel_value = *(Uint8*)pixel;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
79 break;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
80 case(2):
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
81 pixel_value = *(Uint16*)pixel;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
82 break;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
83 case(3):
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
84 pixel_value = *(Uint32*)pixel & (~shape->format->Amask);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
85 break;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
86 case(4):
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
87 pixel_value = *(Uint32*)pixel;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
88 break;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
89 }
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
90 SDL_GetRGBA(pixel_value,shape->format,&r,&g,&b,&alpha);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
91 bitmap_pixel = y*shape->w + x;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
92 switch(mode.mode) {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
93 case(ShapeModeDefault):
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
94 mask_value = (alpha >= 1 ? 1 : 0);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
95 break;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
96 case(ShapeModeBinarizeAlpha):
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
97 mask_value = (alpha >= mode.parameters.binarizationCutoff ? 1 : 0);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
98 break;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
99 case(ShapeModeReverseBinarizeAlpha):
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
100 mask_value = (alpha <= mode.parameters.binarizationCutoff ? 1 : 0);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
101 break;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
102 case(ShapeModeColorKey):
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
103 key = mode.parameters.colorKey;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
104 mask_value = ((key.r != r && key.g != g && key.b != b) ? 1 : 0);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
105 break;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
106 }
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
107 bitmap[bitmap_pixel / ppb] |= mask_value << (7 - ((ppb - 1) - (bitmap_pixel % ppb)));
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
108 }
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
109 }
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
110 if(SDL_MUSTLOCK(shape))
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
111 SDL_UnlockSurface(shape);
4766
7b50faf23907 Moved SDL_shape.h, and building out the API as needed by SDL_Eyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4765
diff changeset
112 }
7b50faf23907 Moved SDL_shape.h, and building out the API as needed by SDL_Eyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4765
diff changeset
113
4841
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
114 SDL_ShapeTree* RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* mask,SDL_Rect dimensions) {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
115 int x = 0,y = 0;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
116 Uint8* pixel = NULL;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
117 Uint32 pixel_value = 0;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
118 Uint8 r = 0,g = 0,b = 0,a = 0;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
119 SDL_bool pixel_opaque = SDL_FALSE;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
120 int last_opaque = -1;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
121 SDL_Color key;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
122 SDL_ShapeTree* result = (SDL_ShapeTree*)SDL_malloc(sizeof(SDL_ShapeTree));
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
123 SDL_Rect next = {0,0,0,0};
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
124 for(y=dimensions.y;y<dimensions.y + dimensions.h;y++)
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
125 for(x=dimensions.x;x<dimensions.x + dimensions.w;x++) {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
126 pixel_value = 0;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
127 pixel = (Uint8 *)(mask->pixels) + (y*mask->pitch) + (x*mask->format->BytesPerPixel);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
128 switch(mask->format->BytesPerPixel) {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
129 case(1):
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
130 pixel_value = *(Uint8*)pixel;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
131 break;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
132 case(2):
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
133 pixel_value = *(Uint16*)pixel;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
134 break;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
135 case(3):
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
136 pixel_value = *(Uint32*)pixel & (~mask->format->Amask);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
137 break;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
138 case(4):
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
139 pixel_value = *(Uint32*)pixel;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
140 break;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
141 }
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
142 SDL_GetRGBA(pixel_value,mask->format,&r,&g,&b,&a);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
143 switch(mode.mode) {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
144 case(ShapeModeDefault):
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
145 pixel_opaque = (a >= 1 ? SDL_TRUE : SDL_FALSE);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
146 break;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
147 case(ShapeModeBinarizeAlpha):
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
148 pixel_opaque = (a >= mode.parameters.binarizationCutoff ? SDL_TRUE : SDL_FALSE);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
149 break;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
150 case(ShapeModeReverseBinarizeAlpha):
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
151 pixel_opaque = (a <= mode.parameters.binarizationCutoff ? SDL_TRUE : SDL_FALSE);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
152 break;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
153 case(ShapeModeColorKey):
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
154 key = mode.parameters.colorKey;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
155 pixel_opaque = ((key.r == r && key.g == g && key.b == b) ? SDL_TRUE : SDL_FALSE);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
156 break;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
157 }
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
158 if(last_opaque == -1)
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
159 last_opaque = pixel_opaque;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
160 if(last_opaque != pixel_opaque) {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
161 result->kind = QuadShape;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
162 //These will stay the same.
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
163 next.w = dimensions.w / 2;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
164 next.h = dimensions.h / 2;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
165 //These will change from recursion to recursion.
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
166 next.x = dimensions.x;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
167 next.y = dimensions.y;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
168 result->data.children.upleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
169 next.x = dimensions.w / 2;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
170 //Unneeded: next.y = dimensions.y;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
171 result->data.children.upright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
172 next.x = dimensions.x;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
173 next.y = dimensions.h / 2;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
174 result->data.children.downleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
175 next.x = dimensions.w / 2;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
176 //Unneeded: next.y = dimensions.h / 2 + 1;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
177 result->data.children.downright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
178 return result;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
179 }
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
180 }
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
181 //If we never recursed, all the pixels in this quadrant have the same "value".
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
182 result->kind = (last_opaque == SDL_TRUE ? OpaqueShape : TransparentShape);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
183 result->data.shape = dimensions;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
184 return 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: 4810
diff changeset
185 }
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: 4810
diff changeset
186
4841
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
187 SDL_ShapeTree* SDL_CalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* shape) {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
188 SDL_Rect dimensions = {0,0,shape->w,shape->h};
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
189 SDL_ShapeTree* result = NULL;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
190 if(SDL_MUSTLOCK(shape))
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
191 SDL_LockSurface(shape);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
192 result = RecursivelyCalculateShapeTree(mode,shape,dimensions);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
193 if(SDL_MUSTLOCK(shape))
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
194 SDL_UnlockSurface(shape);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
195 return 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: 4810
diff changeset
196 }
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: 4810
diff changeset
197
4841
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
198 void SDL_TraverseShapeTree(SDL_ShapeTree *tree,SDL_TraversalFunction function,void* closure) {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
199 SDL_assert(tree != NULL);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
200 if(tree->kind == QuadShape) {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
201 SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upleft,function,closure);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
202 SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upright,function,closure);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
203 SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downleft,function,closure);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
204 SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downright,function,closure);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
205 }
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
206 else
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
207 function(tree,closure);
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: 4810
diff changeset
208 }
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: 4810
diff changeset
209
4841
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
210 void SDL_FreeShapeTree(SDL_ShapeTree** shapeTree) {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
211 if((*shapeTree)->kind == QuadShape) {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
212 SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.upleft);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
213 SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.upright);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
214 SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.downleft);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
215 SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.downright);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
216 }
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
217 SDL_free(*shapeTree);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
218 *shapeTree = 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: 4810
diff changeset
219 }
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: 4810
diff changeset
220
4841
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
221 int SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
222 int result;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
223 if(window == NULL || !SDL_IsShapedWindow(window))
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
224 //The window given was not a shapeable window.
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
225 return SDL_NONSHAPEABLE_WINDOW;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
226 if(shape == NULL)
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
227 //Invalid shape argument.
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
228 return SDL_INVALID_SHAPE_ARGUMENT;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
229
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
230 if(shapeMode != NULL)
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
231 window->shaper->mode = *shapeMode;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
232 //TODO: Platform-specific implementations of SetWindowShape. X11 is finished. Win32 is finished. Debugging is in progress on both.
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
233 result = window->display->device->shape_driver.SetWindowShape(window->shaper,shape,shapeMode);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
234 window->shaper->hasshape = SDL_TRUE;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
235 if((window->shaper->usershownflag & SDL_WINDOW_SHOWN) == SDL_WINDOW_SHOWN) {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
236 SDL_ShowWindow(window);
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
237 window->shaper->usershownflag &= !SDL_WINDOW_SHOWN;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
238 }
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
239 return result;
4782
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4781
diff changeset
240 }
b6930aefd008 Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4781
diff changeset
241
4841
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
242 SDL_bool SDL_WindowHasAShape(SDL_Window *window) {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
243 if (window == NULL || !SDL_IsShapedWindow(window))
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
244 return SDL_FALSE;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
245 return window->shaper->hasshape;
4778
9838d3525a1b Stubbed out the new get/set parameter functions, added the start of the enum, union, and struct for those parameters themselves, and added doxygen comments throughout the SDL_shape.h header.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4776
diff changeset
246 }
9838d3525a1b Stubbed out the new get/set parameter functions, added the start of the enum, union, and struct for those parameters themselves, and added doxygen comments throughout the SDL_shape.h header.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4776
diff changeset
247
4841
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
248 int SDL_GetShapedWindowMode(SDL_Window *window,SDL_WindowShapeMode *shapeMode) {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
249 if(window != NULL && SDL_IsShapedWindow(window)) {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
250 if(shapeMode == NULL) {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
251 if(SDL_WindowHasAShape(window))
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
252 //The window given has a shape.
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
253 return 0;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
254 else
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
255 //The window given is shapeable but lacks a shape.
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
256 return SDL_WINDOW_LACKS_SHAPE;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
257 }
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
258 else {
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
259 *shapeMode = window->shaper->mode;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
260 return 0;
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
261 }
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
262 }
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
263 else
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
264 //The window given is not a valid shapeable window.
740e833b2c00 Fixed overwriting of SDL_shape.c in merge.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4839
diff changeset
265 return SDL_NONSHAPEABLE_WINDOW;
4778
9838d3525a1b Stubbed out the new get/set parameter functions, added the start of the enum, union, and struct for those parameters themselves, and added doxygen comments throughout the SDL_shape.h header.
Eli Gottlieb <eligottlieb@gmail.com>
parents: 4776
diff changeset
266 }