]> Dogcows Code - chaz/openbox/blob - render/mask.c
add the group.c
[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 /* round up to nearest byte */
10 m->data = g_memdup(data, (w * h + 7) / 8);
11 m->mask = XCreateBitmapFromData(ob_display, ob_root, data, w, h);
12 return m;
13 }
14
15 void pixmap_mask_free(pixmap_mask *m)
16 {
17 XFreePixmap(ob_display, m->mask);
18 g_free(m->data);
19 g_free(m);
20 }
21
22 void mask_draw(Pixmap p, TextureMask *m, Rect *position)
23 {
24 int x, y;
25 if (m->mask == None) return; /* no mask given */
26
27 /* set the clip region */
28 x = position->x + (position->width - m->mask->w) / 2;
29 y = position->y + (position->height - m->mask->h) / 2;
30
31 if (x < 0) x = 0;
32 if (y < 0) y = 0;
33
34 XSetClipMask(ob_display, m->color->gc, m->mask->mask);
35 XSetClipOrigin(ob_display, m->color->gc, x, y);
36
37 /* fill in the clipped region */
38 XFillRectangle(ob_display, p, m->color->gc, x, y,
39 x + m->mask->w, y + m->mask->h);
40
41 /* unset the clip region */
42 XSetClipMask(ob_display, m->color->gc, None);
43 XSetClipOrigin(ob_display, m->color->gc, 0, 0);
44 }
45
46 pixmap_mask *pixmap_mask_copy(pixmap_mask *src)
47 {
48 pixmap_mask *m = g_new(pixmap_mask, 1);
49 m->w = src->w;
50 m->h = src->h;
51 /* round up to nearest byte */
52 m->data = g_memdup(src->data, (src->w * src->h + 7) / 8);
53 m->mask = XCreateBitmapFromData(ob_display, ob_root, m->data, m->w, m->h);
54 return m;
55 }
This page took 0.035134 seconds and 4 git commands to generate.