]> Dogcows Code - chaz/openbox/blob - render/mask.c
add a Rect to the textures for positioning them
[chaz/openbox] / render / mask.c
1 #include "mask.h"
2 #include "../kernel/openbox.h"
3
4 pixmap_mask *pixmap_mask_new(int w, int h, char *data)
5 {
6 pixmap_mask *m = g_new(pixmap_mask, 1);
7 m->w = w;
8 m->h = h;
9 m->mask = XCreateBitmapFromData(ob_display, ob_root, data, w, h);
10 return m;
11 }
12
13 void pixmap_mask_free(pixmap_mask *m)
14 {
15 XFreePixmap(ob_display, m->mask);
16 g_free(m);
17 }
18
19 void mask_draw(Pixmap p, TextureMask *m, Rect *position)
20 {
21 int x, y;
22 if (m->mask == None) return; /* no mask given */
23
24 /* set the clip region */
25 x = position->x + (position->width - m->mask->w) / 2;
26 y = position->y + (position->height - m->mask->h) / 2;
27
28 if (x < 0) x = 0;
29 if (y < 0) y = 0;
30
31 XSetClipMask(ob_display, m->color->gc, m->mask->mask);
32 XSetClipOrigin(ob_display, m->color->gc, x, y);
33
34 /* fill in the clipped region */
35 XFillRectangle(ob_display, p, m->color->gc, x, y,
36 x + m->mask->w, y + m->mask->h);
37
38 /* unset the clip region */
39 XSetClipMask(ob_display, m->color->gc, None);
40 XSetClipOrigin(ob_display, m->color->gc, 0, 0);
41 }
This page took 0.040019 seconds and 5 git commands to generate.