Mercurial > sdl-ios-xcode
annotate src/video/SDL_shape.c @ 4829:7160e833c4ac
Implemented shaped windows for Cocoa. Still need to see if they actually work.
author | egottlieb |
---|---|
date | Tue, 03 Aug 2010 21:56:05 -0400 |
parents | 5660aac926e9 |
children | 3dfe779900f5 |
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" |
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
|
25 #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
|
26 #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
|
27 #include "SDL_pixels.h" |
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
28 #include "SDL_surface.h" |
4765
5ff305de5834
Added stub files, working on sample program SDLeyes.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
diff
changeset
|
29 #include "SDL_shape.h" |
4827
5660aac926e9
Got basic, pre-actually-writing-anything Cocoa to build.
egottlieb
parents:
4822
diff
changeset
|
30 #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
|
31 |
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
|
32 SDL_Window* SDL_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags) { |
4810
7a602fd2121f
OK, it appears that dramatic hacks are not necessary to make Cocoa work...
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4809
diff
changeset
|
33 SDL_Window *result = SDL_CreateWindow(title,x,y,w,h,SDL_WINDOW_BORDERLESS | flags & !SDL_WINDOW_FULLSCREEN & !SDL_WINDOW_SHOWN); |
4796
e8caf178d082
Added in Visual Studio patch.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4795
diff
changeset
|
34 if(result != NULL) { |
e8caf178d082
Added in Visual Studio patch.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4795
diff
changeset
|
35 result->shaper = result->display->device->shape_driver.CreateShaper(result); |
e8caf178d082
Added in Visual Studio patch.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4795
diff
changeset
|
36 if(result->shaper != NULL) { |
e8caf178d082
Added in Visual Studio patch.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4795
diff
changeset
|
37 result->shaper->usershownflag = flags & SDL_WINDOW_SHOWN; |
4807
c9eb95f29770
Added color-key mode and redid the code to work with it.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4806
diff
changeset
|
38 result->shaper->mode.mode = ShapeModeDefault; |
c9eb95f29770
Added color-key mode and redid the code to work with it.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4806
diff
changeset
|
39 result->shaper->mode.parameters.binarizationCutoff = 1; |
4796
e8caf178d082
Added in Visual Studio patch.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4795
diff
changeset
|
40 result->shaper->hasshape = SDL_FALSE; |
e8caf178d082
Added in Visual Studio patch.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4795
diff
changeset
|
41 return result; |
e8caf178d082
Added in Visual Studio patch.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4795
diff
changeset
|
42 } |
e8caf178d082
Added in Visual Studio patch.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4795
diff
changeset
|
43 else { |
e8caf178d082
Added in Visual Studio patch.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4795
diff
changeset
|
44 SDL_DestroyWindow(result); |
e8caf178d082
Added in Visual Studio patch.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4795
diff
changeset
|
45 return NULL; |
e8caf178d082
Added in Visual Studio patch.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4795
diff
changeset
|
46 } |
e8caf178d082
Added in Visual Studio patch.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4795
diff
changeset
|
47 } |
e8caf178d082
Added in Visual Studio patch.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4795
diff
changeset
|
48 else |
e8caf178d082
Added in Visual Studio patch.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4795
diff
changeset
|
49 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
|
50 } |
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 |
4781
fc4c775b468a
Added Andreas's fixes to the header and stub file for SDL_shape.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4780
diff
changeset
|
52 SDL_bool SDL_IsShapedWindow(const SDL_Window *window) { |
4782
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
53 if(window == NULL) |
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
54 return SDL_FALSE; |
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
55 else |
4789
a6bc01875d20
Fixed a pair of syntax errors.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4787
diff
changeset
|
56 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
|
57 } |
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
58 |
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
|
59 /* REQUIRES that bitmap point to a w-by-h bitmap with ppb pixels-per-byte. */ |
4817
c68e7490e4cf
Fixed a couple of bugs in the general and X11 shape code, and fixed a bug in testshape that was keeping it from recognizing surfaces without alpha. Thanks to Andreas's bit-bashing tip, X11 shaped windows now work entirely, AFAICT.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4815
diff
changeset
|
60 void SDL_CalculateShapeBitmap(SDL_WindowShapeMode mode,SDL_Surface *shape,Uint8* bitmap,Uint8 ppb) { |
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:
4786
diff
changeset
|
61 int x = 0; |
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:
4786
diff
changeset
|
62 int y = 0; |
4795
6f0bc179771c
Numerous bug fixes that keep testeyes from crashing and dying.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4789
diff
changeset
|
63 Uint8 r = 0,g = 0,b = 0,alpha = 0; |
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:
4801
diff
changeset
|
64 Uint8* pixel = NULL; |
4817
c68e7490e4cf
Fixed a couple of bugs in the general and X11 shape code, and fixed a bug in testshape that was keeping it from recognizing surfaces without alpha. Thanks to Andreas's bit-bashing tip, X11 shaped windows now work entirely, AFAICT.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4815
diff
changeset
|
65 Uint32 bitmap_pixel,pixel_value = 0,mask_value = 0; |
4807
c9eb95f29770
Added color-key mode and redid the code to work with it.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4806
diff
changeset
|
66 SDL_Color key; |
4782
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
67 if(SDL_MUSTLOCK(shape)) |
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
68 SDL_LockSurface(shape); |
4799
a0e096916474
Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4796
diff
changeset
|
69 pixel = (Uint8*)shape->pixels; |
a0e096916474
Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4796
diff
changeset
|
70 for(y = 0;y<shape->h;y++) { |
a0e096916474
Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4796
diff
changeset
|
71 for(x=0;x<shape->w;x++) { |
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:
4786
diff
changeset
|
72 alpha = 0; |
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:
4801
diff
changeset
|
73 pixel_value = 0; |
4806
007567dbb8c1
Reapplied Win32 make-it-build patch. What's going on? Still get rendering artifacts when testing on x11, have literally no idea why.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4802
diff
changeset
|
74 pixel = (Uint8 *)(shape->pixels) + (y*shape->pitch) + (x*shape->format->BytesPerPixel); |
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:
4801
diff
changeset
|
75 switch(shape->format->BytesPerPixel) { |
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:
4801
diff
changeset
|
76 case(1): |
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:
4801
diff
changeset
|
77 pixel_value = *(Uint8*)pixel; |
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:
4801
diff
changeset
|
78 break; |
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:
4801
diff
changeset
|
79 case(2): |
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:
4801
diff
changeset
|
80 pixel_value = *(Uint16*)pixel; |
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:
4801
diff
changeset
|
81 break; |
4817
c68e7490e4cf
Fixed a couple of bugs in the general and X11 shape code, and fixed a bug in testshape that was keeping it from recognizing surfaces without alpha. Thanks to Andreas's bit-bashing tip, X11 shaped windows now work entirely, AFAICT.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4815
diff
changeset
|
82 case(3): |
c68e7490e4cf
Fixed a couple of bugs in the general and X11 shape code, and fixed a bug in testshape that was keeping it from recognizing surfaces without alpha. Thanks to Andreas's bit-bashing tip, X11 shaped windows now work entirely, AFAICT.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4815
diff
changeset
|
83 pixel_value = *(Uint32*)pixel & (~shape->format->Amask); |
c68e7490e4cf
Fixed a couple of bugs in the general and X11 shape code, and fixed a bug in testshape that was keeping it from recognizing surfaces without alpha. Thanks to Andreas's bit-bashing tip, X11 shaped windows now work entirely, AFAICT.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4815
diff
changeset
|
84 break; |
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:
4801
diff
changeset
|
85 case(4): |
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:
4801
diff
changeset
|
86 pixel_value = *(Uint32*)pixel; |
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:
4801
diff
changeset
|
87 break; |
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:
4801
diff
changeset
|
88 } |
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:
4801
diff
changeset
|
89 SDL_GetRGBA(pixel_value,shape->format,&r,&g,&b,&alpha); |
4796
e8caf178d082
Added in Visual Studio patch.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4795
diff
changeset
|
90 bitmap_pixel = y*shape->w + x; |
4807
c9eb95f29770
Added color-key mode and redid the code to work with it.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4806
diff
changeset
|
91 switch(mode.mode) { |
c9eb95f29770
Added color-key mode and redid the code to work with it.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4806
diff
changeset
|
92 case(ShapeModeDefault): |
4817
c68e7490e4cf
Fixed a couple of bugs in the general and X11 shape code, and fixed a bug in testshape that was keeping it from recognizing surfaces without alpha. Thanks to Andreas's bit-bashing tip, X11 shaped windows now work entirely, AFAICT.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4815
diff
changeset
|
93 mask_value = (alpha >= 1 ? 1 : 0); |
4807
c9eb95f29770
Added color-key mode and redid the code to work with it.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4806
diff
changeset
|
94 break; |
c9eb95f29770
Added color-key mode and redid the code to work with it.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4806
diff
changeset
|
95 case(ShapeModeBinarizeAlpha): |
4817
c68e7490e4cf
Fixed a couple of bugs in the general and X11 shape code, and fixed a bug in testshape that was keeping it from recognizing surfaces without alpha. Thanks to Andreas's bit-bashing tip, X11 shaped windows now work entirely, AFAICT.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4815
diff
changeset
|
96 mask_value = (alpha >= mode.parameters.binarizationCutoff ? 1 : 0); |
4807
c9eb95f29770
Added color-key mode and redid the code to work with it.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4806
diff
changeset
|
97 break; |
c9eb95f29770
Added color-key mode and redid the code to work with it.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4806
diff
changeset
|
98 case(ShapeModeReverseBinarizeAlpha): |
4817
c68e7490e4cf
Fixed a couple of bugs in the general and X11 shape code, and fixed a bug in testshape that was keeping it from recognizing surfaces without alpha. Thanks to Andreas's bit-bashing tip, X11 shaped windows now work entirely, AFAICT.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4815
diff
changeset
|
99 mask_value = (alpha <= mode.parameters.binarizationCutoff ? 1 : 0); |
4807
c9eb95f29770
Added color-key mode and redid the code to work with it.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4806
diff
changeset
|
100 break; |
c9eb95f29770
Added color-key mode and redid the code to work with it.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4806
diff
changeset
|
101 case(ShapeModeColorKey): |
c9eb95f29770
Added color-key mode and redid the code to work with it.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4806
diff
changeset
|
102 key = mode.parameters.colorKey; |
4817
c68e7490e4cf
Fixed a couple of bugs in the general and X11 shape code, and fixed a bug in testshape that was keeping it from recognizing surfaces without alpha. Thanks to Andreas's bit-bashing tip, X11 shaped windows now work entirely, AFAICT.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4815
diff
changeset
|
103 mask_value = ((key.r != r && key.g != g && key.b != b) ? 1 : 0); |
4807
c9eb95f29770
Added color-key mode and redid the code to work with it.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4806
diff
changeset
|
104 break; |
c9eb95f29770
Added color-key mode and redid the code to work with it.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4806
diff
changeset
|
105 } |
4817
c68e7490e4cf
Fixed a couple of bugs in the general and X11 shape code, and fixed a bug in testshape that was keeping it from recognizing surfaces without alpha. Thanks to Andreas's bit-bashing tip, X11 shaped windows now work entirely, AFAICT.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4815
diff
changeset
|
106 bitmap[bitmap_pixel / ppb] |= mask_value << (7 - ((ppb - 1) - (bitmap_pixel % ppb))); |
4782
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
107 } |
4799
a0e096916474
Rewrote test program for shaped windows. It definitely displays recognizable pictures now, but the resizing and shaping functionality isn't behaving correctly, possibly due to a miscalculation of alpha values.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4796
diff
changeset
|
108 } |
4782
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
109 if(SDL_MUSTLOCK(shape)) |
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
110 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
|
111 } |
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 |
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
|
113 SDL_ShapeTree* RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* mask,SDL_bool invert,SDL_Rect dimensions) { |
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
|
114 int x = 0,y = 0; |
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
|
115 Uint8* pixel = 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:
4810
diff
changeset
|
116 Uint32 pixel_value = 0; |
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
|
117 Uint8 r = 0,g = 0,b = 0,a = 0; |
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
|
118 SDL_bool pixel_transparent = SDL_FALSE; |
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
|
119 int last_transparent = -1; |
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
|
120 SDL_Color key; |
4815
93402b9dd20c
Added Andreas's patch to fix my silly C++-style errors.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4813
diff
changeset
|
121 SDL_ShapeTree* result = (SDL_ShapeTree*)SDL_malloc(sizeof(SDL_ShapeTree)); |
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
|
122 SDL_Rect next = {0,0,0,0}; |
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
|
123 for(y=dimensions.y;y<dimensions.h;y++) |
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
|
124 for(x=dimensions.x;x<dimensions.w;x++) { |
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
|
125 pixel_value = 0; |
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
|
126 pixel = (Uint8 *)(mask->pixels) + (y*mask->pitch) + (x*mask->format->BytesPerPixel); |
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
|
127 switch(mask->format->BytesPerPixel) { |
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
|
128 case(1): |
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
|
129 pixel_value = *(Uint8*)pixel; |
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
|
130 break; |
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
|
131 case(2): |
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
|
132 pixel_value = *(Uint16*)pixel; |
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
|
133 break; |
4822
55f32099a4b5
Worked on Windows implementation and the quad-trees.
egottlieb
parents:
4817
diff
changeset
|
134 case(3): |
55f32099a4b5
Worked on Windows implementation and the quad-trees.
egottlieb
parents:
4817
diff
changeset
|
135 pixel_value = *(Uint32*)pixel & (~mask->format->Amask); |
55f32099a4b5
Worked on Windows implementation and the quad-trees.
egottlieb
parents:
4817
diff
changeset
|
136 break; |
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
|
137 case(4): |
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
|
138 pixel_value = *(Uint32*)pixel; |
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
|
139 break; |
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
|
140 } |
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
|
141 SDL_GetRGBA(pixel_value,mask->format,&r,&g,&b,&a); |
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
|
142 switch(mode.mode) { |
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
|
143 case(ShapeModeDefault): |
4815
93402b9dd20c
Added Andreas's patch to fix my silly C++-style errors.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4813
diff
changeset
|
144 pixel_transparent = (SDL_bool)(a >= 1 ? !invert : invert); |
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
|
145 break; |
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
|
146 case(ShapeModeBinarizeAlpha): |
4815
93402b9dd20c
Added Andreas's patch to fix my silly C++-style errors.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4813
diff
changeset
|
147 pixel_transparent = (SDL_bool)(a >= mode.parameters.binarizationCutoff ? !invert : invert); |
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
|
148 break; |
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
|
149 case(ShapeModeReverseBinarizeAlpha): |
4815
93402b9dd20c
Added Andreas's patch to fix my silly C++-style errors.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4813
diff
changeset
|
150 pixel_transparent = (SDL_bool)(a <= mode.parameters.binarizationCutoff ? !invert : invert); |
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
|
151 break; |
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
|
152 case(ShapeModeColorKey): |
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
|
153 key = mode.parameters.colorKey; |
4815
93402b9dd20c
Added Andreas's patch to fix my silly C++-style errors.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4813
diff
changeset
|
154 pixel_transparent = (SDL_bool)((key.r == r && key.g == g && key.b == b) ? !invert : invert); |
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
|
155 break; |
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
|
156 } |
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
|
157 if(last_transparent == -1) { |
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
|
158 last_transparent = pixel_transparent; |
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
|
159 break; |
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
|
160 } |
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
|
161 if(last_transparent != pixel_transparent) { |
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
|
162 result->kind = QuadShape; |
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
|
163 //These will stay the same. |
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
|
164 next.w = dimensions.w / 2; |
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
|
165 next.h = dimensions.h / 2; |
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
|
166 //These will change from recursion to recursion. |
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
|
167 next.x = dimensions.x; |
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
|
168 next.y = dimensions.y; |
4815
93402b9dd20c
Added Andreas's patch to fix my silly C++-style errors.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4813
diff
changeset
|
169 result->data.children.upleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next); |
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
|
170 next.x = dimensions.w / 2 + 1; |
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
|
171 //Unneeded: next.y = dimensions.y; |
4815
93402b9dd20c
Added Andreas's patch to fix my silly C++-style errors.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4813
diff
changeset
|
172 result->data.children.upright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next); |
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
|
173 next.x = dimensions.x; |
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
|
174 next.y = dimensions.h / 2 + 1; |
4815
93402b9dd20c
Added Andreas's patch to fix my silly C++-style errors.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4813
diff
changeset
|
175 result->data.children.downleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next); |
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
|
176 next.x = dimensions.w / 2 + 1; |
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
|
177 //Unneeded: next.y = dimensions.h / 2 + 1; |
4815
93402b9dd20c
Added Andreas's patch to fix my silly C++-style errors.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4813
diff
changeset
|
178 result->data.children.downright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next); |
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
|
179 return result; |
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
|
180 } |
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
|
181 } |
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
|
182 //If we never recursed, all the pixels in this quadrant have the same "value". |
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
|
183 result->kind = (last_transparent == SDL_FALSE ? OpaqueShape : TransparentShape); |
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
|
184 result->data.shape = dimensions; |
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 return result; |
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 } |
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
|
187 |
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
|
188 SDL_ShapeTree* SDL_CalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* shape,SDL_bool invert) { |
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
|
189 SDL_Rect dimensions = {0,0,shape->w,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:
4810
diff
changeset
|
190 SDL_ShapeTree* result = 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:
4810
diff
changeset
|
191 if(SDL_MUSTLOCK(shape)) |
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
|
192 SDL_LockSurface(shape); |
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
|
193 result = RecursivelyCalculateShapeTree(mode,shape,invert,dimensions); |
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
|
194 if(SDL_MUSTLOCK(shape)) |
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
|
195 SDL_UnlockSurface(shape); |
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 return result; |
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 } |
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
|
198 |
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
|
199 void SDL_TraverseShapeTree(SDL_ShapeTree *tree,void(*function)(SDL_ShapeTree*,void*),void* closure) { |
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
|
200 if(tree->kind == QuadShape) { |
4815
93402b9dd20c
Added Andreas's patch to fix my silly C++-style errors.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4813
diff
changeset
|
201 SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upleft,function,closure); |
93402b9dd20c
Added Andreas's patch to fix my silly C++-style errors.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4813
diff
changeset
|
202 SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upright,function,closure); |
93402b9dd20c
Added Andreas's patch to fix my silly C++-style errors.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4813
diff
changeset
|
203 SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downleft,function,closure); |
93402b9dd20c
Added Andreas's patch to fix my silly C++-style errors.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4813
diff
changeset
|
204 SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downright,function,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
|
205 } |
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
|
206 else |
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
|
207 function(tree,closure); |
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 |
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
|
210 void SDL_FreeShapeTree(SDL_ShapeTree** shapeTree) { |
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
|
211 if((*shapeTree)->kind == QuadShape) { |
4815
93402b9dd20c
Added Andreas's patch to fix my silly C++-style errors.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4813
diff
changeset
|
212 SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.upleft); |
93402b9dd20c
Added Andreas's patch to fix my silly C++-style errors.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4813
diff
changeset
|
213 SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.upright); |
93402b9dd20c
Added Andreas's patch to fix my silly C++-style errors.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4813
diff
changeset
|
214 SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.downleft); |
93402b9dd20c
Added Andreas's patch to fix my silly C++-style errors.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4813
diff
changeset
|
215 SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.downright); |
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
|
216 } |
4815
93402b9dd20c
Added Andreas's patch to fix my silly C++-style errors.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4813
diff
changeset
|
217 SDL_free(*shapeTree); |
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
|
218 *shapeTree = 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:
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 |
4781
fc4c775b468a
Added Andreas's fixes to the header and stub file for SDL_shape.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4780
diff
changeset
|
221 int SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) { |
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:
4786
diff
changeset
|
222 int result; |
4786
175da36d1342
Fixed up shape files as best I can.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4785
diff
changeset
|
223 if(window == NULL || !SDL_IsShapedWindow(window)) |
4782
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
224 //The window given was not a shapeable window. |
4801
506a9165491b
Added #define's for error codes returned from SDL shaped-window API.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4799
diff
changeset
|
225 return SDL_NONSHAPEABLE_WINDOW; |
4780
4f915a47b995
Replaced the model of treating a window's shape as a render target with treating a window's shape as a surface passed into an SDL_SetWindowShape() function. I'll send this off to Andreas and Sam and start coding.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4778
diff
changeset
|
226 if(shape == NULL) |
4782
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
227 //Invalid shape argument. |
4801
506a9165491b
Added #define's for error codes returned from SDL shaped-window API.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4799
diff
changeset
|
228 return SDL_INVALID_SHAPE_ARGUMENT; |
4782
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
229 |
4807
c9eb95f29770
Added color-key mode and redid the code to work with it.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4806
diff
changeset
|
230 if(shapeMode != NULL) |
c9eb95f29770
Added color-key mode and redid the code to work with it.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4806
diff
changeset
|
231 window->shaper->mode = *shapeMode; |
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:
4801
diff
changeset
|
232 //TODO: Platform-specific implementations of SetWindowShape. X11 is finished. Win32 is finished. Debugging is in progress on both. |
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:
4786
diff
changeset
|
233 result = window->display->device->shape_driver.SetWindowShape(window->shaper,shape,shapeMode); |
4782
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
234 window->shaper->hasshape = SDL_TRUE; |
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:
4786
diff
changeset
|
235 if((window->shaper->usershownflag & SDL_WINDOW_SHOWN) == SDL_WINDOW_SHOWN) { |
4782
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
236 SDL_ShowWindow(window); |
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
237 window->shaper->usershownflag &= !SDL_WINDOW_SHOWN; |
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
238 } |
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
239 return result; |
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 |
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
242 SDL_bool SDL_WindowHasAShape(SDL_Window *window) { |
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:
4786
diff
changeset
|
243 if (window == NULL && !SDL_IsShapedWindow(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:
4786
diff
changeset
|
244 return SDL_FALSE; |
4782
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
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 |
4781
fc4c775b468a
Added Andreas's fixes to the header and stub file for SDL_shape.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4780
diff
changeset
|
248 int SDL_GetShapedWindowMode(SDL_Window *window,SDL_WindowShapeMode *shapeMode) { |
4782
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
249 if(window != NULL && SDL_IsShapedWindow(window)) { |
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
250 if(shapeMode == NULL) { |
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
251 if(SDL_WindowHasAShape(window)) |
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
252 //The window given has a shape. |
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
253 return 0; |
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
254 else |
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
255 //The window given is shapeable but lacks a shape. |
4801
506a9165491b
Added #define's for error codes returned from SDL shaped-window API.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4799
diff
changeset
|
256 return SDL_WINDOW_LACKS_SHAPE; |
4782
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
257 } |
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
258 else { |
4807
c9eb95f29770
Added color-key mode and redid the code to work with it.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4806
diff
changeset
|
259 *shapeMode = window->shaper->mode; |
4782
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
260 return 0; |
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
261 } |
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
262 } |
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
263 else |
b6930aefd008
Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4781
diff
changeset
|
264 //The window given is not a valid shapeable window. |
4801
506a9165491b
Added #define's for error codes returned from SDL shaped-window API.
Eli Gottlieb <eligottlieb@gmail.com>
parents:
4799
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 } |