comparison src/video/SDL_shape.c @ 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.
author Eli Gottlieb <eligottlieb@gmail.com>
date Thu, 08 Jul 2010 22:52:49 -0400
parents 175da36d1342
children a6bc01875d20
comparison
equal deleted inserted replaced
4786:175da36d1342 4787:e25ad8d97027
39 39
40 SDL_bool SDL_IsShapedWindow(const SDL_Window *window) { 40 SDL_bool SDL_IsShapedWindow(const SDL_Window *window) {
41 if(window == NULL) 41 if(window == NULL)
42 return SDL_FALSE; 42 return SDL_FALSE;
43 else 43 else
44 return window->shaper != NULL; 44 return (SDL_bool)(window->shaper != NULL)
45 } 45 }
46 46
47 /* REQUIRES that bitmap point to a w-by-h bitmap with 1bpp. */ 47 /* REQUIRES that bitmap point to a w-by-h bitmap with 1bpp. */
48 void SDL_CalculateShapeBitmap(Uint8 alphacutoff,SDL_Surface *shape,Uint8* bitmap,Uint8 ppb,Uint8 value) { 48 void SDL_CalculateShapeBitmap(Uint8 alphacutoff,SDL_Surface *shape,Uint8* bitmap,Uint8 ppb,Uint8 value) {
49 int x = 0;
50 int y = 0;
51 Uint8 alpha = 0;
52 Uint8* pixel;
53 Uint32 bitmap_pixel;
49 if(SDL_MUSTLOCK(shape)) 54 if(SDL_MUSTLOCK(shape))
50 SDL_LockSurface(shape); 55 SDL_LockSurface(shape);
51 int x = 0,y = 0;
52 for(x = 0;x<shape->w;x++) 56 for(x = 0;x<shape->w;x++)
53 for(y = 0;y<shape->h;y++) { 57 for(y = 0;y<shape->h;y++) {
54 void* pixel = shape->pixels + (y*shape->pitch) + (x*shape->format->BytesPerPixel); 58 pixel = shape->pixels + (y*shape->pitch) + (x*shape->format->BytesPerPixel);
55 Uint8 alpha = 0; 59 alpha = 0;
56 SDL_GetRGBA(*(Uint32*)pixel,shape->format,NULL,NULL,NULL,&alpha); 60 SDL_GetRGBA(*(Uint32*)pixel,shape->format,NULL,NULL,NULL,&alpha);
57 Uint32 bitmap_pixel = y*shape->w + x; 61 Uint32 bitmap_pixel = y*shape->w + x;
58 bitmap[bitmap_pixel / ppb] |= (alpha >= alphacutoff ? value : 0) << ((ppb - 1) - (bitmap_pixel % ppb)); 62 bitmap[bitmap_pixel / ppb] |= (alpha >= alphacutoff ? value : 0) << ((ppb - 1) - (bitmap_pixel % ppb));
59 } 63 }
60 if(SDL_MUSTLOCK(shape)) 64 if(SDL_MUSTLOCK(shape))
61 SDL_UnlockSurface(shape); 65 SDL_UnlockSurface(shape);
62 } 66 }
63 67
64 int SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) { 68 int SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) {
69 int result;
65 if(window == NULL || !SDL_IsShapedWindow(window)) 70 if(window == NULL || !SDL_IsShapedWindow(window))
66 //The window given was not a shapeable window. 71 //The window given was not a shapeable window.
67 return -2; 72 return -2;
68 if(shape == NULL) 73 if(shape == NULL)
69 //Invalid shape argument. 74 //Invalid shape argument.
80 break; 85 break;
81 } 86 }
82 } 87 }
83 } 88 }
84 //TODO: Platform-specific implementations of SetWindowShape. X11 is finished. Win32 is in progress. 89 //TODO: Platform-specific implementations of SetWindowShape. X11 is finished. Win32 is in progress.
85 int result = window->display->device->shape_driver.SetWindowShape(window->shaper,shape,shapeMode); 90 result = window->display->device->shape_driver.SetWindowShape(window->shaper,shape,shapeMode);
86 window->shaper->hasshape = SDL_TRUE; 91 window->shaper->hasshape = SDL_TRUE;
87 if(window->shaper->usershownflag & SDL_WINDOW_SHOWN == SDL_WINDOW_SHOWN) { 92 if((window->shaper->usershownflag & SDL_WINDOW_SHOWN) == SDL_WINDOW_SHOWN) {
88 SDL_ShowWindow(window); 93 SDL_ShowWindow(window);
89 window->shaper->usershownflag &= !SDL_WINDOW_SHOWN; 94 window->shaper->usershownflag &= !SDL_WINDOW_SHOWN;
90 } 95 }
91 return result; 96 return result;
92 } 97 }
93 98
94 SDL_bool SDL_WindowHasAShape(SDL_Window *window) { 99 SDL_bool SDL_WindowHasAShape(SDL_Window *window) {
95 assert(window != NULL && SDL_IsShapedWindow(window)); 100 if (window == NULL && !SDL_IsShapedWindow(window))
101 return SDL_FALSE;
96 return window->shaper->hasshape; 102 return window->shaper->hasshape;
97 } 103 }
98 104
99 int SDL_GetShapedWindowMode(SDL_Window *window,SDL_WindowShapeMode *shapeMode) { 105 int SDL_GetShapedWindowMode(SDL_Window *window,SDL_WindowShapeMode *shapeMode) {
100 if(window != NULL && SDL_IsShapedWindow(window)) { 106 if(window != NULL && SDL_IsShapedWindow(window)) {