comparison src/video/x11/SDL_x11shape.c @ 4782:b6930aefd008

Finished X11 shaped-window functionality and removed ellipse+polygon rendering.
author Eli Gottlieb <eligottlieb@gmail.com>
date Wed, 30 Jun 2010 16:19:44 -0400
parents 6e03d73054d7
children 2878650e0dc9
comparison
equal deleted inserted replaced
4781:fc4c775b468a 4782:b6930aefd008
18 18
19 Eli Gottlieb 19 Eli Gottlieb
20 eligottlieb@gmail.com 20 eligottlieb@gmail.com
21 */ 21 */
22 22
23 #include "SDL_shape.h" 23 #include <X11/Xos.h>
24 #include <X11/IntrinsicP.h>
25 #include <X11/StringDefs.h>
26 #include <X11/Xmu/Converters.h>
27 #include <X11/extensions/shape.h>
28 #include "SDL_x11shape.h"
29 #include "SDL_x11window.h"
30 #include "SDL_x11video.h"
24 31
25 /* Functions implementing shaped-window functionality for X Window System will be implemented when the API is decided. */ 32 SDL_WindowShaper* X11_CreateShaper(SDL_Window* window) {
33 SDL_WindowShaper* result = malloc(sizeof(SDL_WindowShaper));
34 result->window = window;
35 result->alphacutoff = 0;
36 result->usershownflag = 0;
37 result->driverdata = malloc(sizeof(SDL_ShapeData));
38 window->shaper = result;
39 int resized_properly = X11ResizeWindowShape(window);
40 assert(resized_properly == 0);
41 return result;
42 }
43
44 int X11_ResizeWindowShape(SDL_Window* window) {
45 SDL_ShapeData* data = window->shaper->driverdata;
46 assert(data != NULL);
47
48 unsigned int bitmapsize = window->w / 8;
49 if(window->w % 8 > 0)
50 bitmapsize += 1;
51 bitmapsize *= window->h;
52 if(data->bitmapsize != bitmapsize || data->bitmap == NULL) {
53 data->bitmapsize = bitmapsize;
54 if(data->bitmap != NULL)
55 free(data->bitmap);
56 data->bitmap = malloc(data->bitmapsize);
57 if(data->bitmap == NULL) {
58 SDL_SetError("Could not allocate memory for shaped-window bitmap.");
59 return -1;
60 }
61 }
62
63 window->shaper->usershownflag = window->flags & SDL_WINDOW_SHOWN;
64
65 return 0;
66 }
67
68 int X11_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) {
69 if(!SDL_ISPIXELFORMAT_ALPHA(SDL_MasksToPixelFormatEnum(shape->format->BitsPerPixel,shape->format->Rmask,shape->format->Gmask,shape->format->Bmask,shape->format->Amask)))
70 return -2;
71 if(shape->w != shaper->window->w || shape->h != shaper->window->h)
72 return -3;
73 SDL_ShapeData *data = shaper->driverdata;
74 assert(data != NULL);
75
76 /* Assume that shaper->alphacutoff already has a value. */
77 SDL_CalculateShapeBitmap(shaper->alphacutoff,shape,data->bitmap);
78
79 SDL_WindowData *windowdata = (SDL_WindowData*)(shaper->window->driverdata);
80 Pixmap shapemask = XCreateBitmapFromData(windowdata->videodata->display,windowdata->xwindow,data->bitmap,shaper->window->w,shaper->window->h);
81
82 XShapeCombineMask(windowdata->videodata->display,windowdata->xwindow, ShapeBounding, 0, 0,shapemask, ShapeSet);
83 XSync(windowdata->videodata->display,False);
84
85 XFreePixmap(windowdata->videodata->display,shapemask);
86
87 return 0;
88 }