]> Dogcows Code - chaz/openbox/blob - render/mask.c
X allocs more bytes than i thought, new algo to pick the amount of memory for the...
[chaz/openbox] / render / mask.c
1 #include "render.h"
2 #include "color.h"
3 #include "mask.h"
4
5 RrPixmapMask *RrPixmapMaskNew(const RrInstance *inst,
6 gint w, gint h, const gchar *data)
7 {
8 RrPixmapMask *m = g_new(RrPixmapMask, 1);
9 m->inst = inst;
10 m->width = w;
11 m->height = h;
12 /* round up to nearest byte */
13 m->data = g_memdup(data, (w + 7) / 8 * h);
14 m->mask = XCreateBitmapFromData(RrDisplay(inst), RrRootWindow(inst),
15 data, w, h);
16 return m;
17 }
18
19 void RrPixmapMaskFree(RrPixmapMask *m)
20 {
21 if (m) {
22 XFreePixmap(RrDisplay(m->inst), m->mask);
23 g_free(m->data);
24 g_free(m);
25 }
26 }
27
28 void RrPixmapMaskDraw(Pixmap p, const RrTextureMask *m, const RrRect *area)
29 {
30 int x, y;
31 if (m->mask == None) return; /* no mask given */
32
33 /* set the clip region */
34 x = area->x + (area->width - m->mask->width) / 2;
35 y = area->y + (area->height - m->mask->height) / 2;
36
37 if (x < 0) x = 0;
38 if (y < 0) y = 0;
39
40 XSetClipMask(RrDisplay(m->mask->inst), RrColorGC(m->color), m->mask->mask);
41 XSetClipOrigin(RrDisplay(m->mask->inst), RrColorGC(m->color), x, y);
42
43 /* fill in the clipped region */
44 XFillRectangle(RrDisplay(m->mask->inst), p, RrColorGC(m->color), x, y,
45 x + m->mask->width, y + m->mask->height);
46
47 /* unset the clip region */
48 XSetClipMask(RrDisplay(m->mask->inst), RrColorGC(m->color), None);
49 XSetClipOrigin(RrDisplay(m->mask->inst), RrColorGC(m->color), 0, 0);
50 }
51
52 RrPixmapMask *RrPixmapMaskCopy(const RrPixmapMask *src)
53 {
54 RrPixmapMask *m = g_new(RrPixmapMask, 1);
55 m->inst = src->inst;
56 m->width = src->width;
57 m->height = src->height;
58 /* round up to nearest byte */
59 m->data = g_memdup(src->data, (src->width + 7) / 8 * src->height);
60 m->mask = XCreateBitmapFromData(RrDisplay(m->inst), RrRootWindow(m->inst),
61 m->data, m->width, m->height);
62 return m;
63 }
This page took 0.040996 seconds and 5 git commands to generate.