]>
Dogcows Code - chaz/openbox/blob - render/mask.c
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
)
18 XFreePixmap(ob_display
, m
->mask
);
24 void mask_draw(Pixmap p
, TextureMask
*m
, Rect
*position
)
27 if (m
->mask
== None
) return; /* no mask given */
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;
36 XSetClipMask(ob_display
, m
->color
->gc
, m
->mask
->mask
);
37 XSetClipOrigin(ob_display
, m
->color
->gc
, x
, y
);
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
);
43 /* unset the clip region */
44 XSetClipMask(ob_display
, m
->color
->gc
, None
);
45 XSetClipOrigin(ob_display
, m
->color
->gc
, 0, 0);
48 pixmap_mask
*pixmap_mask_copy(pixmap_mask
*src
)
50 pixmap_mask
*m
= g_new(pixmap_mask
, 1);
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
);
This page took 0.041335 seconds and 5 git commands to generate.