X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=render%2Fmask.c;h=60e89d489bf8f4718ad18bb1373110525cc1c3f7;hb=a09984bbc076bc37b11058237f51fa15114129e2;hp=7aa702950c7b78ec69ce20ce4744230925bfc10f;hpb=1f63f7b331887a192ddf927670471c3f00f307f5;p=chaz%2Fopenbox diff --git a/render/mask.c b/render/mask.c index 7aa70295..60e89d48 100644 --- a/render/mask.c +++ b/render/mask.c @@ -1,3 +1,63 @@ +#include "render.h" +#include "color.h" #include "mask.h" -/* DO YOUR MAGIC MANNY WOOT \m/ */ +RrPixmapMask *RrPixmapMaskNew(const RrInstance *inst, + gint w, gint h, const gchar *data) +{ + RrPixmapMask *m = g_new(RrPixmapMask, 1); + m->inst = inst; + m->width = w; + m->height = h; + /* round up to nearest byte */ + m->data = g_memdup(data, (w * h + 7) / 8); + m->mask = XCreateBitmapFromData(RrDisplay(inst), RrRootWindow(inst), + data, w, h); + return m; +} + +void RrPixmapMaskFree(RrPixmapMask *m) +{ + if (m) { + XFreePixmap(RrDisplay(m->inst), m->mask); + g_free(m->data); + g_free(m); + } +} + +void RrPixmapMaskDraw(Pixmap p, const RrTextureMask *m, const RrRect *area) +{ + int x, y; + if (m->mask == None) return; /* no mask given */ + + /* set the clip region */ + x = area->x + (area->width - m->mask->width) / 2; + y = area->y + (area->height - m->mask->height) / 2; + + if (x < 0) x = 0; + if (y < 0) y = 0; + + XSetClipMask(RrDisplay(m->mask->inst), m->color->gc, m->mask->mask); + XSetClipOrigin(RrDisplay(m->mask->inst), m->color->gc, x, y); + + /* fill in the clipped region */ + XFillRectangle(RrDisplay(m->mask->inst), p, m->color->gc, x, y, + x + m->mask->width, y + m->mask->height); + + /* unset the clip region */ + XSetClipMask(RrDisplay(m->mask->inst), m->color->gc, None); + XSetClipOrigin(RrDisplay(m->mask->inst), m->color->gc, 0, 0); +} + +RrPixmapMask *RrPixmapMaskCopy(const RrPixmapMask *src) +{ + RrPixmapMask *m = g_new(RrPixmapMask, 1); + m->inst = src->inst; + m->width = src->width; + m->height = src->height; + /* round up to nearest byte */ + m->data = g_memdup(src->data, (src->width * src->height + 7) / 8); + m->mask = XCreateBitmapFromData(RrDisplay(m->inst), RrRootWindow(m->inst), + m->data, m->width, m->height); + return m; +}