comparison src/video/x11/SDL_x11shape.c @ 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 c68e7490e4cf
children 05d172e92b52
comparison
equal deleted inserted replaced
4826:d532a5a114cd 4838:1f9915666afd
23 #include <assert.h> 23 #include <assert.h>
24 #include "SDL_x11video.h" 24 #include "SDL_x11video.h"
25 #include "SDL_x11shape.h" 25 #include "SDL_x11shape.h"
26 #include "SDL_x11window.h" 26 #include "SDL_x11window.h"
27 27
28 SDL_Window* X11_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags) { 28 SDL_Window*
29 return SDL_CreateWindow(title,x,y,w,h,flags); 29 X11_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags) {
30 return SDL_CreateWindow(title,x,y,w,h,flags);
30 } 31 }
31 32
32 SDL_WindowShaper* X11_CreateShaper(SDL_Window* window) { 33 SDL_WindowShaper*
33 SDL_WindowShaper* result = NULL; 34 X11_CreateShaper(SDL_Window* window) {
35 SDL_WindowShaper* result = NULL;
34 36
35 #if SDL_VIDEO_DRIVER_X11_XSHAPE 37 #if SDL_VIDEO_DRIVER_X11_XSHAPE
36 if (SDL_X11_HAVE_XSHAPE) { /* Make sure X server supports it. */ 38 if (SDL_X11_HAVE_XSHAPE) { /* Make sure X server supports it. */
37 result = malloc(sizeof(SDL_WindowShaper)); 39 result = malloc(sizeof(SDL_WindowShaper));
38 result->window = window; 40 result->window = window;
39 result->mode.mode = ShapeModeDefault; 41 result->mode.mode = ShapeModeDefault;
40 result->mode.parameters.binarizationCutoff = 1; 42 result->mode.parameters.binarizationCutoff = 1;
41 result->usershownflag = 0; 43 result->usershownflag = 0;
42 SDL_ShapeData* data = malloc(sizeof(SDL_ShapeData)); 44 SDL_ShapeData* data = malloc(sizeof(SDL_ShapeData));
43 result->driverdata = data; 45 result->driverdata = data;
44 data->bitmapsize = 0; 46 data->bitmapsize = 0;
45 data->bitmap = NULL; 47 data->bitmap = NULL;
46 window->shaper = result; 48 window->shaper = result;
47 int resized_properly = X11_ResizeWindowShape(window); 49 int resized_properly = X11_ResizeWindowShape(window);
48 assert(resized_properly == 0); 50 assert(resized_properly == 0);
49 } 51 }
50 #endif 52 #endif
51 53
52 return result; 54 return result;
53 } 55 }
54 56
55 int X11_ResizeWindowShape(SDL_Window* window) { 57 int
56 SDL_ShapeData* data = window->shaper->driverdata; 58 X11_ResizeWindowShape(SDL_Window* window) {
57 assert(data != NULL); 59 SDL_ShapeData* data = window->shaper->driverdata;
58 60 assert(data != NULL);
59 unsigned int bitmapsize = window->w / 8; 61
60 if(window->w % 8 > 0) 62 unsigned int bitmapsize = window->w / 8;
61 bitmapsize += 1; 63 if(window->w % 8 > 0)
62 bitmapsize *= window->h; 64 bitmapsize += 1;
63 if(data->bitmapsize != bitmapsize || data->bitmap == NULL) { 65 bitmapsize *= window->h;
64 data->bitmapsize = bitmapsize; 66 if(data->bitmapsize != bitmapsize || data->bitmap == NULL) {
65 if(data->bitmap != NULL) 67 data->bitmapsize = bitmapsize;
66 free(data->bitmap); 68 if(data->bitmap != NULL)
67 data->bitmap = malloc(data->bitmapsize); 69 free(data->bitmap);
68 if(data->bitmap == NULL) { 70 data->bitmap = malloc(data->bitmapsize);
69 SDL_SetError("Could not allocate memory for shaped-window bitmap."); 71 if(data->bitmap == NULL) {
70 return -1; 72 SDL_SetError("Could not allocate memory for shaped-window bitmap.");
71 } 73 return -1;
72 } 74 }
73 memset(data->bitmap,0,data->bitmapsize); 75 }
74 76 memset(data->bitmap,0,data->bitmapsize);
75 window->shaper->usershownflag |= window->flags & SDL_WINDOW_SHOWN; 77
76 78 window->shaper->usershownflag |= window->flags & SDL_WINDOW_SHOWN;
77 return 0; 79
80 return 0;
78 } 81 }
79 82
80 int X11_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) { 83 int
81 if(shaper == NULL || shape == NULL || shaper->driverdata == NULL) 84 X11_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) {
82 return -1; 85 if(shaper == NULL || shape == NULL || shaper->driverdata == NULL)
86 return -1;
83 87
84 #if SDL_VIDEO_DRIVER_X11_XSHAPE 88 #if SDL_VIDEO_DRIVER_X11_XSHAPE
85 if(!SDL_ISPIXELFORMAT_ALPHA(SDL_MasksToPixelFormatEnum(shape->format->BitsPerPixel,shape->format->Rmask,shape->format->Gmask,shape->format->Bmask,shape->format->Amask))) 89 if(!SDL_ISPIXELFORMAT_ALPHA(SDL_MasksToPixelFormatEnum(shape->format->BitsPerPixel,shape->format->Rmask,shape->format->Gmask,shape->format->Bmask,shape->format->Amask)))
86 return -2; 90 return -2;
87 if(shape->w != shaper->window->w || shape->h != shaper->window->h) 91 if(shape->w != shaper->window->w || shape->h != shaper->window->h)
88 return -3; 92 return -3;
89 SDL_ShapeData *data = shaper->driverdata; 93 SDL_ShapeData *data = shaper->driverdata;
90 94
91 /* Assume that shaper->alphacutoff already has a value, because SDL_SetWindowShape() should have given it one. */ 95 /* Assume that shaper->alphacutoff already has a value, because SDL_SetWindowShape() should have given it one. */
92 SDL_CalculateShapeBitmap(shaper->mode,shape,data->bitmap,8); 96 SDL_CalculateShapeBitmap(shaper->mode,shape,data->bitmap,8);
93 97
94 SDL_WindowData *windowdata = (SDL_WindowData*)(shaper->window->driverdata); 98 SDL_WindowData *windowdata = (SDL_WindowData*)(shaper->window->driverdata);
95 Pixmap shapemask = XCreateBitmapFromData(windowdata->videodata->display,windowdata->xwindow,data->bitmap,shaper->window->w,shaper->window->h); 99 Pixmap shapemask = XCreateBitmapFromData(windowdata->videodata->display,windowdata->xwindow,data->bitmap,shaper->window->w,shaper->window->h);
96 100
97 XShapeCombineMask(windowdata->videodata->display,windowdata->xwindow, ShapeBounding, 0, 0,shapemask, ShapeSet); 101 XShapeCombineMask(windowdata->videodata->display,windowdata->xwindow, ShapeBounding, 0, 0,shapemask, ShapeSet);
98 XSync(windowdata->videodata->display,False); 102 XSync(windowdata->videodata->display,False);
99 103
100 XFreePixmap(windowdata->videodata->display,shapemask); 104 XFreePixmap(windowdata->videodata->display,shapemask);
101 #endif 105 #endif
102 106
103 return 0; 107 return 0;
104 } 108 }