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