2 #include "../kernel/openbox.h"
4 pixmap_mask *pixmap_mask_new(int w, int h, char *data)
6 pixmap_mask *m = g_new(pixmap_mask, 1);
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);
15 void pixmap_mask_free(pixmap_mask *m)
17 XFreePixmap(ob_display, m->mask);
22 void mask_draw(Pixmap p, TextureMask *m, Rect *position)
25 if (m->mask == None) return; /* no mask given */
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;
34 XSetClipMask(ob_display, m->color->gc, m->mask->mask);
35 XSetClipOrigin(ob_display, m->color->gc, x, y);
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);
41 /* unset the clip region */
42 XSetClipMask(ob_display, m->color->gc, None);
43 XSetClipOrigin(ob_display, m->color->gc, 0, 0);
46 pixmap_mask *pixmap_mask_copy(pixmap_mask *src)
48 pixmap_mask *m = g_new(pixmap_mask, 1);
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);