Mercurial > sdl-ios-xcode
changeset 4838:1f9915666afd
Reformatting code to match the rest of SDL. Variable names seem OK; replaced tabs with 4 spaces each for indentation.
author | Eli Gottlieb <eligottlieb@gmail.com> |
---|---|
date | Mon, 09 Aug 2010 15:37:20 -0400 |
parents | d532a5a114cd |
children | 05d172e92b52 |
files | src/video/SDL_shape.c src/video/cocoa/SDL_cocoashape.m src/video/win32/SDL_win32shape.c src/video/x11/SDL_x11shape.c |
diffstat | 4 files changed, 401 insertions(+), 380 deletions(-) [+] |
line wrap: on
line diff
--- a/src/video/SDL_shape.c Mon Aug 02 23:58:22 2010 -0400 +++ b/src/video/SDL_shape.c Mon Aug 09 15:37:20 2010 -0400 @@ -29,238 +29,248 @@ #include "SDL_shape.h" #include "../src/video/SDL_shape_internals.h" -SDL_Window* SDL_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags) { - SDL_Window *result = SDL_CreateWindow(title,x,y,w,h,SDL_WINDOW_BORDERLESS | flags & !SDL_WINDOW_FULLSCREEN & !SDL_WINDOW_SHOWN); - if(result != NULL) { - result->shaper = result->display->device->shape_driver.CreateShaper(result); - if(result->shaper != NULL) { - result->shaper->usershownflag = flags & SDL_WINDOW_SHOWN; - result->shaper->mode.mode = ShapeModeDefault; - result->shaper->mode.parameters.binarizationCutoff = 1; - result->shaper->hasshape = SDL_FALSE; - return result; - } - else { - SDL_DestroyWindow(result); - return NULL; - } - } - else - return NULL; +SDL_Window* +SDL_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags) { + SDL_Window *result = SDL_CreateWindow(title,x,y,w,h,SDL_WINDOW_BORDERLESS | flags & !SDL_WINDOW_FULLSCREEN & !SDL_WINDOW_SHOWN); + if(result != NULL) { + result->shaper = result->display->device->shape_driver.CreateShaper(result); + if(result->shaper != NULL) { + result->shaper->usershownflag = flags & SDL_WINDOW_SHOWN; + result->shaper->mode.mode = ShapeModeDefault; + result->shaper->mode.parameters.binarizationCutoff = 1; + result->shaper->hasshape = SDL_FALSE; + return result; + } + else { + SDL_DestroyWindow(result); + return NULL; + } + } + else + return NULL; } -SDL_bool SDL_IsShapedWindow(const SDL_Window *window) { - if(window == NULL) - return SDL_FALSE; - else - return (SDL_bool)(window->shaper != NULL); +SDL_bool +SDL_IsShapedWindow(const SDL_Window *window) { + if(window == NULL) + return SDL_FALSE; + else + return (SDL_bool)(window->shaper != NULL); } /* REQUIRES that bitmap point to a w-by-h bitmap with ppb pixels-per-byte. */ -void SDL_CalculateShapeBitmap(SDL_WindowShapeMode mode,SDL_Surface *shape,Uint8* bitmap,Uint8 ppb) { - int x = 0; - int y = 0; - Uint8 r = 0,g = 0,b = 0,alpha = 0; - Uint8* pixel = NULL; - Uint32 bitmap_pixel,pixel_value = 0,mask_value = 0; - SDL_Color key; - if(SDL_MUSTLOCK(shape)) - SDL_LockSurface(shape); - pixel = (Uint8*)shape->pixels; - for(y = 0;y<shape->h;y++) { - for(x=0;x<shape->w;x++) { - alpha = 0; - pixel_value = 0; - pixel = (Uint8 *)(shape->pixels) + (y*shape->pitch) + (x*shape->format->BytesPerPixel); - switch(shape->format->BytesPerPixel) { - case(1): - pixel_value = *(Uint8*)pixel; - break; - case(2): - pixel_value = *(Uint16*)pixel; - break; - case(3): - pixel_value = *(Uint32*)pixel & (~shape->format->Amask); - break; - case(4): - pixel_value = *(Uint32*)pixel; - break; - } - SDL_GetRGBA(pixel_value,shape->format,&r,&g,&b,&alpha); - bitmap_pixel = y*shape->w + x; - switch(mode.mode) { - case(ShapeModeDefault): - mask_value = (alpha >= 1 ? 1 : 0); - break; - case(ShapeModeBinarizeAlpha): - mask_value = (alpha >= mode.parameters.binarizationCutoff ? 1 : 0); - break; - case(ShapeModeReverseBinarizeAlpha): - mask_value = (alpha <= mode.parameters.binarizationCutoff ? 1 : 0); - break; - case(ShapeModeColorKey): - key = mode.parameters.colorKey; - mask_value = ((key.r != r && key.g != g && key.b != b) ? 1 : 0); - break; - } - bitmap[bitmap_pixel / ppb] |= mask_value << (7 - ((ppb - 1) - (bitmap_pixel % ppb))); - } - } - if(SDL_MUSTLOCK(shape)) - SDL_UnlockSurface(shape); +void +SDL_CalculateShapeBitmap(SDL_WindowShapeMode mode,SDL_Surface *shape,Uint8* bitmap,Uint8 ppb) { + int x = 0; + int y = 0; + Uint8 r = 0,g = 0,b = 0,alpha = 0; + Uint8* pixel = NULL; + Uint32 bitmap_pixel,pixel_value = 0,mask_value = 0; + SDL_Color key; + if(SDL_MUSTLOCK(shape)) + SDL_LockSurface(shape); + pixel = (Uint8*)shape->pixels; + for(y = 0;y<shape->h;y++) { + for(x=0;x<shape->w;x++) { + alpha = 0; + pixel_value = 0; + pixel = (Uint8 *)(shape->pixels) + (y*shape->pitch) + (x*shape->format->BytesPerPixel); + switch(shape->format->BytesPerPixel) { + case(1): + pixel_value = *(Uint8*)pixel; + break; + case(2): + pixel_value = *(Uint16*)pixel; + break; + case(3): + pixel_value = *(Uint32*)pixel & (~shape->format->Amask); + break; + case(4): + pixel_value = *(Uint32*)pixel; + break; + } + SDL_GetRGBA(pixel_value,shape->format,&r,&g,&b,&alpha); + bitmap_pixel = y*shape->w + x; + switch(mode.mode) { + case(ShapeModeDefault): + mask_value = (alpha >= 1 ? 1 : 0); + break; + case(ShapeModeBinarizeAlpha): + mask_value = (alpha >= mode.parameters.binarizationCutoff ? 1 : 0); + break; + case(ShapeModeReverseBinarizeAlpha): + mask_value = (alpha <= mode.parameters.binarizationCutoff ? 1 : 0); + break; + case(ShapeModeColorKey): + key = mode.parameters.colorKey; + mask_value = ((key.r != r && key.g != g && key.b != b) ? 1 : 0); + break; + } + bitmap[bitmap_pixel / ppb] |= mask_value << (7 - ((ppb - 1) - (bitmap_pixel % ppb))); + } + } + if(SDL_MUSTLOCK(shape)) + SDL_UnlockSurface(shape); } -SDL_ShapeTree* RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* mask,SDL_bool invert,SDL_Rect dimensions) { - int x = 0,y = 0; - Uint8* pixel = NULL; - Uint32 pixel_value = 0; - Uint8 r = 0,g = 0,b = 0,a = 0; - SDL_bool pixel_transparent = SDL_FALSE; - int last_transparent = -1; - SDL_Color key; - SDL_ShapeTree* result = (SDL_ShapeTree*)SDL_malloc(sizeof(SDL_ShapeTree)); - SDL_Rect next = {0,0,0,0}; - for(y=dimensions.y;y<dimensions.h;y++) - for(x=dimensions.x;x<dimensions.w;x++) { - pixel_value = 0; - pixel = (Uint8 *)(mask->pixels) + (y*mask->pitch) + (x*mask->format->BytesPerPixel); - switch(mask->format->BytesPerPixel) { - case(1): - pixel_value = *(Uint8*)pixel; - break; - case(2): - pixel_value = *(Uint16*)pixel; - break; - case(3): - pixel_value = *(Uint32*)pixel & (~mask->format->Amask); - break; - case(4): - pixel_value = *(Uint32*)pixel; - break; - } - SDL_GetRGBA(pixel_value,mask->format,&r,&g,&b,&a); - switch(mode.mode) { - case(ShapeModeDefault): - pixel_transparent = (SDL_bool)(a >= 1 ? !invert : invert); - break; - case(ShapeModeBinarizeAlpha): - pixel_transparent = (SDL_bool)(a >= mode.parameters.binarizationCutoff ? !invert : invert); - break; - case(ShapeModeReverseBinarizeAlpha): - pixel_transparent = (SDL_bool)(a <= mode.parameters.binarizationCutoff ? !invert : invert); - break; - case(ShapeModeColorKey): - key = mode.parameters.colorKey; - pixel_transparent = (SDL_bool)((key.r == r && key.g == g && key.b == b) ? !invert : invert); - break; - } - if(last_transparent == -1) { - last_transparent = pixel_transparent; - break; - } - if(last_transparent != pixel_transparent) { - result->kind = QuadShape; - //These will stay the same. - next.w = dimensions.w / 2; - next.h = dimensions.h / 2; - //These will change from recursion to recursion. - next.x = dimensions.x; - next.y = dimensions.y; - result->data.children.upleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next); - next.x = dimensions.w / 2 + 1; - //Unneeded: next.y = dimensions.y; - result->data.children.upright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next); - next.x = dimensions.x; - next.y = dimensions.h / 2 + 1; - result->data.children.downleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next); - next.x = dimensions.w / 2 + 1; - //Unneeded: next.y = dimensions.h / 2 + 1; - result->data.children.downright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next); - return result; - } - } - //If we never recursed, all the pixels in this quadrant have the same "value". - result->kind = (last_transparent == SDL_FALSE ? OpaqueShape : TransparentShape); - result->data.shape = dimensions; - return result; +SDL_ShapeTree* +RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* mask,SDL_bool invert,SDL_Rect dimensions) { + int x = 0,y = 0; + Uint8* pixel = NULL; + Uint32 pixel_value = 0; + Uint8 r = 0,g = 0,b = 0,a = 0; + SDL_bool pixel_transparent = SDL_FALSE; + int last_transparent = -1; + SDL_Color key; + SDL_ShapeTree* result = (SDL_ShapeTree*)SDL_malloc(sizeof(SDL_ShapeTree)); + SDL_Rect next = {0,0,0,0}; + for(y=dimensions.y;y<dimensions.h;y++) + for(x=dimensions.x;x<dimensions.w;x++) { + pixel_value = 0; + pixel = (Uint8 *)(mask->pixels) + (y*mask->pitch) + (x*mask->format->BytesPerPixel); + switch(mask->format->BytesPerPixel) { + case(1): + pixel_value = *(Uint8*)pixel; + break; + case(2): + pixel_value = *(Uint16*)pixel; + break; + case(3): + pixel_value = *(Uint32*)pixel & (~mask->format->Amask); + break; + case(4): + pixel_value = *(Uint32*)pixel; + break; + } + SDL_GetRGBA(pixel_value,mask->format,&r,&g,&b,&a); + switch(mode.mode) { + case(ShapeModeDefault): + pixel_transparent = (SDL_bool)(a >= 1 ? !invert : invert); + break; + case(ShapeModeBinarizeAlpha): + pixel_transparent = (SDL_bool)(a >= mode.parameters.binarizationCutoff ? !invert : invert); + break; + case(ShapeModeReverseBinarizeAlpha): + pixel_transparent = (SDL_bool)(a <= mode.parameters.binarizationCutoff ? !invert : invert); + break; + case(ShapeModeColorKey): + key = mode.parameters.colorKey; + pixel_transparent = (SDL_bool)((key.r == r && key.g == g && key.b == b) ? !invert : invert); + break; + } + if(last_transparent == -1) { + last_transparent = pixel_transparent; + break; + } + if(last_transparent != pixel_transparent) { + result->kind = QuadShape; + //These will stay the same. + next.w = dimensions.w / 2; + next.h = dimensions.h / 2; + //These will change from recursion to recursion. + next.x = dimensions.x; + next.y = dimensions.y; + result->data.children.upleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next); + next.x = dimensions.w / 2 + 1; + //Unneeded: next.y = dimensions.y; + result->data.children.upright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next); + next.x = dimensions.x; + next.y = dimensions.h / 2 + 1; + result->data.children.downleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next); + next.x = dimensions.w / 2 + 1; + //Unneeded: next.y = dimensions.h / 2 + 1; + result->data.children.downright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next); + return result; + } + } + //If we never recursed, all the pixels in this quadrant have the same "value". + result->kind = (last_transparent == SDL_FALSE ? OpaqueShape : TransparentShape); + result->data.shape = dimensions; + return result; } -SDL_ShapeTree* SDL_CalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* shape,SDL_bool invert) { - SDL_Rect dimensions = {0,0,shape->w,shape->h}; - SDL_ShapeTree* result = NULL; - if(SDL_MUSTLOCK(shape)) - SDL_LockSurface(shape); - result = RecursivelyCalculateShapeTree(mode,shape,invert,dimensions); - if(SDL_MUSTLOCK(shape)) - SDL_UnlockSurface(shape); - return result; +SDL_ShapeTree* +SDL_CalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* shape,SDL_bool invert) { + SDL_Rect dimensions = {0,0,shape->w,shape->h}; + SDL_ShapeTree* result = NULL; + if(SDL_MUSTLOCK(shape)) + SDL_LockSurface(shape); + result = RecursivelyCalculateShapeTree(mode,shape,invert,dimensions); + if(SDL_MUSTLOCK(shape)) + SDL_UnlockSurface(shape); + return result; } -void SDL_TraverseShapeTree(SDL_ShapeTree *tree,void(*function)(SDL_ShapeTree*,void*),void* closure) { - if(tree->kind == QuadShape) { - SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upleft,function,closure); - SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upright,function,closure); - SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downleft,function,closure); - SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downright,function,closure); - } - else - function(tree,closure); +void +SDL_TraverseShapeTree(SDL_ShapeTree *tree,void(*function)(SDL_ShapeTree*,void*),void* closure) { + if(tree->kind == QuadShape) { + SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upleft,function,closure); + SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upright,function,closure); + SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downleft,function,closure); + SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downright,function,closure); + } + else + function(tree,closure); } -void SDL_FreeShapeTree(SDL_ShapeTree** shapeTree) { - if((*shapeTree)->kind == QuadShape) { - SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.upleft); - SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.upright); - SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.downleft); - SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.downright); - } - SDL_free(*shapeTree); - *shapeTree = NULL; +void +SDL_FreeShapeTree(SDL_ShapeTree** shapeTree) { + if((*shapeTree)->kind == QuadShape) { + SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.upleft); + SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.upright); + SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.downleft); + SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.downright); + } + SDL_free(*shapeTree); + *shapeTree = NULL; } -int SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) { - int result; - if(window == NULL || !SDL_IsShapedWindow(window)) - //The window given was not a shapeable window. - return SDL_NONSHAPEABLE_WINDOW; - if(shape == NULL) - //Invalid shape argument. - return SDL_INVALID_SHAPE_ARGUMENT; - - if(shapeMode != NULL) - window->shaper->mode = *shapeMode; - //TODO: Platform-specific implementations of SetWindowShape. X11 is finished. Win32 is finished. Debugging is in progress on both. - result = window->display->device->shape_driver.SetWindowShape(window->shaper,shape,shapeMode); - window->shaper->hasshape = SDL_TRUE; - if((window->shaper->usershownflag & SDL_WINDOW_SHOWN) == SDL_WINDOW_SHOWN) { - SDL_ShowWindow(window); - window->shaper->usershownflag &= !SDL_WINDOW_SHOWN; - } - return result; +int +SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) { + int result; + if(window == NULL || !SDL_IsShapedWindow(window)) + //The window given was not a shapeable window. + return SDL_NONSHAPEABLE_WINDOW; + if(shape == NULL) + //Invalid shape argument. + return SDL_INVALID_SHAPE_ARGUMENT; + + if(shapeMode != NULL) + window->shaper->mode = *shapeMode; + //TODO: Platform-specific implementations of SetWindowShape. X11 is finished. Win32 is finished. Debugging is in progress on both. + result = window->display->device->shape_driver.SetWindowShape(window->shaper,shape,shapeMode); + window->shaper->hasshape = SDL_TRUE; + if((window->shaper->usershownflag & SDL_WINDOW_SHOWN) == SDL_WINDOW_SHOWN) { + SDL_ShowWindow(window); + window->shaper->usershownflag &= !SDL_WINDOW_SHOWN; + } + return result; } -SDL_bool SDL_WindowHasAShape(SDL_Window *window) { - if (window == NULL && !SDL_IsShapedWindow(window)) - return SDL_FALSE; - return window->shaper->hasshape; +SDL_bool +SDL_WindowHasAShape(SDL_Window *window) { + if (window == NULL && !SDL_IsShapedWindow(window)) + return SDL_FALSE; + return window->shaper->hasshape; } -int SDL_GetShapedWindowMode(SDL_Window *window,SDL_WindowShapeMode *shapeMode) { - if(window != NULL && SDL_IsShapedWindow(window)) { - if(shapeMode == NULL) { - if(SDL_WindowHasAShape(window)) - //The window given has a shape. - return 0; - else - //The window given is shapeable but lacks a shape. - return SDL_WINDOW_LACKS_SHAPE; - } - else { - *shapeMode = window->shaper->mode; - return 0; - } - } - else - //The window given is not a valid shapeable window. - return SDL_NONSHAPEABLE_WINDOW; +int +SDL_GetShapedWindowMode(SDL_Window *window,SDL_WindowShapeMode *shapeMode) { + if(window != NULL && SDL_IsShapedWindow(window)) { + if(shapeMode == NULL) { + if(SDL_WindowHasAShape(window)) + //The window given has a shape. + return 0; + else + //The window given is shapeable but lacks a shape. + return SDL_WINDOW_LACKS_SHAPE; + } + else { + *shapeMode = window->shaper->mode; + return 0; + } + } + else + //The window given is not a valid shapeable window. + return SDL_NONSHAPEABLE_WINDOW; }
--- a/src/video/cocoa/SDL_cocoashape.m Mon Aug 02 23:58:22 2010 -0400 +++ b/src/video/cocoa/SDL_cocoashape.m Mon Aug 09 15:37:20 2010 -0400 @@ -24,48 +24,51 @@ #include "SDL_shape.h" #include "SDL_cocoashape.h" -SDL_WindowShaper* Cocoa_CreateShaper(SDL_Window* window) { - SDL_WindowData* data = (SDL_WindowData*)window->driverdata; - [data->nswindow setAlpha:1.0]; - [data->nswindow setOpaque:YES]; - [data->nswindow setStyleMask:NSBorderlessWindowMask]; - SDL_Shaper* result = result = malloc(sizeof(SDL_WindowShaper)); - result->window = window; - result->mode.mode = ShapeModeDefault; - result->mode.parameters.binarizationCutoff = 1; - result->usershownflag = 0; - window->shaper = result; - - SDL_ShapeData* data = malloc(sizeof(SDL_ShapeData)); - result->driverdata = data; - data->context = [data->nswindow graphicsContext]; - data->saved = SDL_False; - data->rects = NULL; - data->count = 0; - - int resized_properly = Cocoa_ResizeWindowShape(window); - assert(resized_properly == 0); - return result; +SDL_WindowShaper* +Cocoa_CreateShaper(SDL_Window* window) { + SDL_WindowData* data = (SDL_WindowData*)window->driverdata; + [data->nswindow setAlpha:1.0]; + [data->nswindow setOpaque:YES]; + [data->nswindow setStyleMask:NSBorderlessWindowMask]; + SDL_Shaper* result = result = malloc(sizeof(SDL_WindowShaper)); + result->window = window; + result->mode.mode = ShapeModeDefault; + result->mode.parameters.binarizationCutoff = 1; + result->usershownflag = 0; + window->shaper = result; + + SDL_ShapeData* data = malloc(sizeof(SDL_ShapeData)); + result->driverdata = data; + data->context = [data->nswindow graphicsContext]; + data->saved = SDL_False; + data->rects = NULL; + data->count = 0; + + int resized_properly = Cocoa_ResizeWindowShape(window); + assert(resized_properly == 0); + return result; } -int Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) { - SDL_WindowData* data = (SDL_WindowData*)shaper->window->driverdata; - if(data->saved == SDL_True) { - [data->context restoreGraphicsState]; - data->saved = SDL_False; - } - - [data->context saveGraphicsState]; - data->saved = SDL_True; - - [[NSColor clearColor] set]; - NSRectFill([[data->nswindow contentView] frame]); - /* TODO: It looks like Cocoa can set a clipping path based on a list of rectangles. That's what we get from the +int +Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) { + SDL_WindowData* data = (SDL_WindowData*)shaper->window->driverdata; + if(data->saved == SDL_True) { + [data->context restoreGraphicsState]; + data->saved = SDL_False; + } + + [data->context saveGraphicsState]; + data->saved = SDL_True; + + [[NSColor clearColor] set]; + NSRectFill([[data->nswindow contentView] frame]); + /* TODO: It looks like Cocoa can set a clipping path based on a list of rectangles. That's what we get from the Windoze shape-calculation code: a list of rectangles. This will work... I think. */ } -int Cocoa_ResizeWindowShape(SDL_Window *window) { - SDL_ShapeData* data = window->shaper->driverdata; - assert(data != NULL); - return 0; +int +Cocoa_ResizeWindowShape(SDL_Window *window) { + SDL_ShapeData* data = window->shaper->driverdata; + assert(data != NULL); + return 0; }
--- a/src/video/win32/SDL_win32shape.c Mon Aug 02 23:58:22 2010 -0400 +++ b/src/video/win32/SDL_win32shape.c Mon Aug 09 15:37:20 2010 -0400 @@ -23,79 +23,83 @@ #include "SDL_win32shape.h" #include "SDL_win32video.h" -SDL_WindowShaper* Win32_CreateShaper(SDL_Window * window) { - int resized_properly; - SDL_WindowShaper* result = (SDL_WindowShaper *)SDL_malloc(sizeof(SDL_WindowShaper)); - result->window = window; - result->mode.mode = ShapeModeDefault; - result->mode.parameters.binarizationCutoff = 1; - result->usershownflag = 0; - result->driverdata = (SDL_ShapeData*)SDL_malloc(sizeof(SDL_ShapeData)); - ((SDL_ShapeData*)result->driverdata)->mask_tree = NULL; - //Put some driver-data here. - window->shaper = result; - resized_properly = Win32_ResizeWindowShape(window); - if (resized_properly != 0) - return NULL; +SDL_WindowShaper* +Win32_CreateShaper(SDL_Window * window) { + int resized_properly; + SDL_WindowShaper* result = (SDL_WindowShaper *)SDL_malloc(sizeof(SDL_WindowShaper)); + result->window = window; + result->mode.mode = ShapeModeDefault; + result->mode.parameters.binarizationCutoff = 1; + result->usershownflag = 0; + result->driverdata = (SDL_ShapeData*)SDL_malloc(sizeof(SDL_ShapeData)); + ((SDL_ShapeData*)result->driverdata)->mask_tree = NULL; + //Put some driver-data here. + window->shaper = result; + resized_properly = Win32_ResizeWindowShape(window); + if (resized_properly != 0) + return NULL; - return result; + return result; } -void CombineRectRegions(SDL_ShapeTree* node, void* closure) { - HRGN* mask_region = (HRGN *)closure; - if(node->kind == OpaqueShape) { - HRGN temp_region = CreateRectRgn(node->data.shape.x,node->data.shape.y,node->data.shape.w,node->data.shape.h); - CombineRgn(*mask_region,*mask_region,temp_region, RGN_OR); - DeleteObject(temp_region); - } +void +CombineRectRegions(SDL_ShapeTree* node, void* closure) { + HRGN* mask_region = (HRGN *)closure; + if(node->kind == OpaqueShape) { + HRGN temp_region = CreateRectRgn(node->data.shape.x,node->data.shape.y,node->data.shape.w,node->data.shape.h); + CombineRgn(*mask_region,*mask_region,temp_region, RGN_OR); + DeleteObject(temp_region); + } } -int Win32_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) { - SDL_ShapeData *data; - HRGN mask_region; +int +Win32_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) { + SDL_ShapeData *data; + HRGN mask_region; SDL_WindowData *windowdata; HWND hwnd; - if (shaper == NULL || shape == NULL) - return SDL_INVALID_SHAPE_ARGUMENT; - if(shape->format->Amask == 0 && shapeMode->mode != ShapeModeColorKey || shape->w != shaper->window->w || shape->h != shaper->window->h) - return SDL_INVALID_SHAPE_ARGUMENT; - - data = (SDL_ShapeData*)shaper->driverdata; - if(data->mask_tree != NULL) - SDL_FreeShapeTree(&data->mask_tree); - data->mask_tree = SDL_CalculateShapeTree(*shapeMode,shape,SDL_FALSE); - - /* - * Start with empty region - */ - mask_region = CreateRectRgn(0, 0, 0, 0); - - SDL_TraverseShapeTree(data->mask_tree,&CombineRectRegions,&mask_region); - - /* - * Set the new region mask for the window - */ - windowdata=(SDL_WindowData *)(shaper->window->driverdata); - hwnd = windowdata->hwnd; - SetWindowRgn(hwnd, mask_region, TRUE); - - return 0; + if (shaper == NULL || shape == NULL) + return SDL_INVALID_SHAPE_ARGUMENT; + if(shape->format->Amask == 0 && shapeMode->mode != ShapeModeColorKey || shape->w != shaper->window->w || shape->h != shaper->window->h) + return SDL_INVALID_SHAPE_ARGUMENT; + + data = (SDL_ShapeData*)shaper->driverdata; + if(data->mask_tree != NULL) + SDL_FreeShapeTree(&data->mask_tree); + data->mask_tree = SDL_CalculateShapeTree(*shapeMode,shape,SDL_FALSE); + + /* + * Start with empty region + */ + mask_region = CreateRectRgn(0, 0, 0, 0); + + SDL_TraverseShapeTree(data->mask_tree,&CombineRectRegions,&mask_region); + + /* + * Set the new region mask for the window + */ + windowdata=(SDL_WindowData *)(shaper->window->driverdata); + hwnd = windowdata->hwnd; + SetWindowRgn(hwnd, mask_region, TRUE); + + return 0; } -int Win32_ResizeWindowShape(SDL_Window *window) { - SDL_ShapeData* data; +int +Win32_ResizeWindowShape(SDL_Window *window) { + SDL_ShapeData* data; - if (window == NULL) - return -1; - data = (SDL_ShapeData *)window->shaper->driverdata; - if (data == NULL) - return -1; - - if(data->mask_tree != NULL) - SDL_FreeShapeTree(&data->mask_tree); - - window->shaper->usershownflag |= window->flags & SDL_WINDOW_SHOWN; - - return 0; + if (window == NULL) + return -1; + data = (SDL_ShapeData *)window->shaper->driverdata; + if (data == NULL) + return -1; + + if(data->mask_tree != NULL) + SDL_FreeShapeTree(&data->mask_tree); + + window->shaper->usershownflag |= window->flags & SDL_WINDOW_SHOWN; + + return 0; }
--- a/src/video/x11/SDL_x11shape.c Mon Aug 02 23:58:22 2010 -0400 +++ b/src/video/x11/SDL_x11shape.c Mon Aug 09 15:37:20 2010 -0400 @@ -25,80 +25,84 @@ #include "SDL_x11shape.h" #include "SDL_x11window.h" -SDL_Window* X11_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags) { - return SDL_CreateWindow(title,x,y,w,h,flags); +SDL_Window* +X11_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags) { + return SDL_CreateWindow(title,x,y,w,h,flags); } -SDL_WindowShaper* X11_CreateShaper(SDL_Window* window) { - SDL_WindowShaper* result = NULL; +SDL_WindowShaper* +X11_CreateShaper(SDL_Window* window) { + SDL_WindowShaper* result = NULL; #if SDL_VIDEO_DRIVER_X11_XSHAPE - if (SDL_X11_HAVE_XSHAPE) { /* Make sure X server supports it. */ - result = malloc(sizeof(SDL_WindowShaper)); - result->window = window; - result->mode.mode = ShapeModeDefault; - result->mode.parameters.binarizationCutoff = 1; - result->usershownflag = 0; - SDL_ShapeData* data = malloc(sizeof(SDL_ShapeData)); - result->driverdata = data; - data->bitmapsize = 0; - data->bitmap = NULL; - window->shaper = result; - int resized_properly = X11_ResizeWindowShape(window); - assert(resized_properly == 0); - } + if (SDL_X11_HAVE_XSHAPE) { /* Make sure X server supports it. */ + result = malloc(sizeof(SDL_WindowShaper)); + result->window = window; + result->mode.mode = ShapeModeDefault; + result->mode.parameters.binarizationCutoff = 1; + result->usershownflag = 0; + SDL_ShapeData* data = malloc(sizeof(SDL_ShapeData)); + result->driverdata = data; + data->bitmapsize = 0; + data->bitmap = NULL; + window->shaper = result; + int resized_properly = X11_ResizeWindowShape(window); + assert(resized_properly == 0); + } #endif - return result; + return result; } -int X11_ResizeWindowShape(SDL_Window* window) { - SDL_ShapeData* data = window->shaper->driverdata; - assert(data != NULL); - - unsigned int bitmapsize = window->w / 8; - if(window->w % 8 > 0) - bitmapsize += 1; - bitmapsize *= window->h; - if(data->bitmapsize != bitmapsize || data->bitmap == NULL) { - data->bitmapsize = bitmapsize; - if(data->bitmap != NULL) - free(data->bitmap); - data->bitmap = malloc(data->bitmapsize); - if(data->bitmap == NULL) { - SDL_SetError("Could not allocate memory for shaped-window bitmap."); - return -1; - } - } - memset(data->bitmap,0,data->bitmapsize); - - window->shaper->usershownflag |= window->flags & SDL_WINDOW_SHOWN; - - return 0; +int +X11_ResizeWindowShape(SDL_Window* window) { + SDL_ShapeData* data = window->shaper->driverdata; + assert(data != NULL); + + unsigned int bitmapsize = window->w / 8; + if(window->w % 8 > 0) + bitmapsize += 1; + bitmapsize *= window->h; + if(data->bitmapsize != bitmapsize || data->bitmap == NULL) { + data->bitmapsize = bitmapsize; + if(data->bitmap != NULL) + free(data->bitmap); + data->bitmap = malloc(data->bitmapsize); + if(data->bitmap == NULL) { + SDL_SetError("Could not allocate memory for shaped-window bitmap."); + return -1; + } + } + memset(data->bitmap,0,data->bitmapsize); + + window->shaper->usershownflag |= window->flags & SDL_WINDOW_SHOWN; + + return 0; } - -int X11_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) { - if(shaper == NULL || shape == NULL || shaper->driverdata == NULL) - return -1; + +int +X11_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) { + if(shaper == NULL || shape == NULL || shaper->driverdata == NULL) + return -1; #if SDL_VIDEO_DRIVER_X11_XSHAPE - if(!SDL_ISPIXELFORMAT_ALPHA(SDL_MasksToPixelFormatEnum(shape->format->BitsPerPixel,shape->format->Rmask,shape->format->Gmask,shape->format->Bmask,shape->format->Amask))) - return -2; - if(shape->w != shaper->window->w || shape->h != shaper->window->h) - return -3; - SDL_ShapeData *data = shaper->driverdata; - - /* Assume that shaper->alphacutoff already has a value, because SDL_SetWindowShape() should have given it one. */ - SDL_CalculateShapeBitmap(shaper->mode,shape,data->bitmap,8); - - SDL_WindowData *windowdata = (SDL_WindowData*)(shaper->window->driverdata); - Pixmap shapemask = XCreateBitmapFromData(windowdata->videodata->display,windowdata->xwindow,data->bitmap,shaper->window->w,shaper->window->h); - - XShapeCombineMask(windowdata->videodata->display,windowdata->xwindow, ShapeBounding, 0, 0,shapemask, ShapeSet); - XSync(windowdata->videodata->display,False); + if(!SDL_ISPIXELFORMAT_ALPHA(SDL_MasksToPixelFormatEnum(shape->format->BitsPerPixel,shape->format->Rmask,shape->format->Gmask,shape->format->Bmask,shape->format->Amask))) + return -2; + if(shape->w != shaper->window->w || shape->h != shaper->window->h) + return -3; + SDL_ShapeData *data = shaper->driverdata; + + /* Assume that shaper->alphacutoff already has a value, because SDL_SetWindowShape() should have given it one. */ + SDL_CalculateShapeBitmap(shaper->mode,shape,data->bitmap,8); + + SDL_WindowData *windowdata = (SDL_WindowData*)(shaper->window->driverdata); + Pixmap shapemask = XCreateBitmapFromData(windowdata->videodata->display,windowdata->xwindow,data->bitmap,shaper->window->w,shaper->window->h); + + XShapeCombineMask(windowdata->videodata->display,windowdata->xwindow, ShapeBounding, 0, 0,shapemask, ShapeSet); + XSync(windowdata->videodata->display,False); - XFreePixmap(windowdata->videodata->display,shapemask); + XFreePixmap(windowdata->videodata->display,shapemask); #endif - return 0; + return 0; }