18 static void RrPixel32_to_pixmap(RrAppearance *l,
19 gint x, gint y, gint w, gint h);
21 void RrPaint(RrAppearance *l, Window win, gint w, gint h)
23 int i, transferred = 0, sw;
24 RrPixel32 *source, *dest;
26 Rect tarea; /* area in which to draw textures */
29 if (w <= 0 || h <= 0) return;
31 resized = (l->w != w || l->h != h);
34 oldp = l->pixmap; /* save to free after changing the visible pixmap */
35 l->pixmap = XCreatePixmap(RrDisplay(l->inst),
36 RrRootWindow(l->inst),
37 w, h, RrDepth(l->inst));
41 g_assert(l->pixmap != None);
45 if (l->xftdraw != NULL)
46 XftDrawDestroy(l->xftdraw);
47 l->xftdraw = XftDrawCreate(RrDisplay(l->inst), l->pixmap,
48 RrVisual(l->inst), RrColormap(l->inst));
49 g_assert(l->xftdraw != NULL);
51 g_free(l->surface.RrPixel_data);
52 l->surface.RrPixel_data = g_new(RrPixel32, w * h);
54 if (l->surface.grad == RR_SURFACE_PARENTREL) {
55 g_assert (l->surface.parent);
56 g_assert (l->surface.parent->w);
58 sw = l->surface.parent->w;
59 source = (l->surface.parent->surface.RrPixel_data + l->surface.parentx +
60 sw * l->surface.parenty);
61 dest = l->surface.RrPixel_data;
62 for (i = 0; i < h; i++, source += sw, dest += w) {
63 memcpy(dest, source, w * sizeof(RrPixel32));
68 RECT_SET(tarea, 0, 0, w, h);
69 if (l->surface.grad != RR_SURFACE_PARENTREL) {
70 if (l->surface.relief != RR_RELIEF_FLAT) {
71 switch (l->surface.bevel) {
73 tarea.x += 1; tarea.y += 1;
74 tarea.width -= 2; tarea.height -= 2;
77 tarea.x += 2; tarea.y += 2;
78 tarea.width -= 4; tarea.height -= 4;
81 } else if (l->surface.border) {
82 tarea.x += 1; tarea.y += 1;
83 tarea.width -= 2; tarea.height -= 2;
87 for (i = 0; i < l->textures; i++) {
88 switch (l->texture[i].type) {
94 if (l->surface.grad != RR_SURFACE_SOLID)
95 RrPixel32_to_pixmap(l, 0, 0, w, h);
97 if (l->xftdraw == NULL) {
98 l->xftdraw = XftDrawCreate(RrDisplay(l->inst), l->pixmap,
100 RrColormap(l->inst));
102 RrFontDraw(l->xftdraw, &l->texture[i].data.text, &tarea);
104 case RR_TEXTURE_MASK:
107 if (l->surface.grad != RR_SURFACE_SOLID)
108 RrPixel32_to_pixmap(l, 0, 0, w, h);
110 if (l->texture[i].data.mask.color->gc == None)
111 RrColorAllocateGC(l->texture[i].data.mask.color);
112 RrPixmapMaskDraw(l->pixmap, &l->texture[i].data.mask, &tarea);
114 case RR_TEXTURE_RGBA:
115 RrImageDraw(l->surface.RrPixel_data,
116 &l->texture[i].data.rgba, &tarea);
123 if (l->surface.grad != RR_SURFACE_SOLID)
124 RrPixel32_to_pixmap(l, 0, 0, w, h);
128 XSetWindowBackgroundPixmap(RrDisplay(l->inst), win, l->pixmap);
129 XClearWindow(RrDisplay(l->inst), win);
130 if (oldp) XFreePixmap(RrDisplay(l->inst), oldp);
133 RrAppearance *RrAppearanceNew(const RrInstance *inst, gint numtex)
137 out = g_new0(RrAppearance, 1);
139 out->textures = numtex;
140 if (numtex) out->texture = g_new0(RrTexture, numtex);
145 RrAppearance *RrAppearanceCopy(RrAppearance *orig)
147 RrSurface *spo, *spc;
148 RrAppearance *copy = g_new(RrAppearance, 1);
150 copy->inst = orig->inst;
152 spo = &(orig->surface);
153 spc = &(copy->surface);
154 spc->grad = spo->grad;
155 spc->relief = spo->relief;
156 spc->bevel = spo->bevel;
157 if (spo->primary != NULL)
158 spc->primary = RrColorNew(copy->inst,
162 else spc->primary = NULL;
164 if (spo->secondary != NULL)
165 spc->secondary = RrColorNew(copy->inst,
169 else spc->secondary = NULL;
171 if (spo->border_color != NULL)
172 spc->border_color = RrColorNew(copy->inst,
173 spo->border_color->r,
174 spo->border_color->g,
175 spo->border_color->b);
176 else spc->border_color = NULL;
178 if (spo->bevel_dark != NULL)
179 spc->bevel_dark = RrColorNew(copy->inst,
183 else spc->bevel_dark = NULL;
185 if (spo->bevel_light != NULL)
186 spc->bevel_light = RrColorNew(copy->inst,
189 spo->bevel_light->b);
190 else spc->bevel_light = NULL;
192 spc->interlaced = spo->interlaced;
193 spc->border = spo->border;
194 spc->RrPixel_data = NULL;
196 copy->textures = orig->textures;
197 copy->texture = g_memdup(orig->texture,
198 orig->textures * sizeof(RrTexture));
200 copy->xftdraw = NULL;
201 copy->w = copy->h = 0;
205 void RrAppearanceFree(RrAppearance *a)
209 if (a->pixmap != None) XFreePixmap(RrDisplay(a->inst), a->pixmap);
210 if (a->xftdraw != NULL) XftDrawDestroy(a->xftdraw);
214 RrColorFree(p->primary);
215 RrColorFree(p->secondary);
216 RrColorFree(p->border_color);
217 RrColorFree(p->bevel_dark);
218 RrColorFree(p->bevel_light);
219 g_free(p->RrPixel_data);
226 static void RrPixel32_to_pixmap(RrAppearance *l, gint x, gint y, gint w, gint h)
228 RrPixel32 *in, *scratch;
231 im = XCreateImage(RrDisplay(l->inst), RrVisual(l->inst), RrDepth(l->inst),
232 ZPixmap, 0, NULL, w, h, 32, 0);
233 g_assert(im != NULL);
235 in = l->surface.RrPixel_data;
238 im->byte_order = RrEndian;
239 /* this malloc is a complete waste of time on normal 32bpp
240 as reduce_depth just sets im->data = data and returns
242 scratch = g_new(RrPixel32, im->width * im->height);
243 im->data = (char*) scratch;
244 RrReduceDepth(l->inst, in, im);
245 XPutImage(RrDisplay(l->inst), out,
246 DefaultGC(RrDisplay(l->inst), RrScreen(l->inst)),
247 im, 0, 0, x, y, w, h);
253 void RrMinsize(RrAppearance *l, gint *w, gint *h)
259 for (i = 0; i < l->textures; ++i) {
260 switch (l->texture[i].type) {
261 case RR_TEXTURE_NONE:
263 case RR_TEXTURE_MASK:
264 *w = MAX(*w, l->texture[i].data.mask.mask->width);
265 *h = MAX(*h, l->texture[i].data.mask.mask->height);
267 case RR_TEXTURE_TEXT:
268 m = RrFontMeasureString(l->texture[i].data.text.font,
269 l->texture[i].data.text.string,
270 l->texture[i].data.text.shadow,
271 l->texture[i].data.text.offset);
273 m = RrFontHeight(l->texture[i].data.text.font,
274 l->texture[i].data.text.shadow,
275 l->texture[i].data.text.offset);
278 case RR_TEXTURE_RGBA:
279 *w += MAX(*w, l->texture[i].data.rgba.width);
280 *h += MAX(*h, l->texture[i].data.rgba.height);
285 if (l->surface.relief != RR_RELIEF_FLAT) {
286 switch (l->surface.bevel) {
296 } else if (l->surface.border) {
305 gboolean RrPixmapToRGBA(const RrInstance *inst,
306 Pixmap pmap, Pixmap mask,
307 gint *w, gint *h, RrPixel32 **data)
311 guint pw, ph, mw, mh, xb, xd, i, x, y, di;
312 XImage *xi, *xm = NULL;
314 if (!XGetGeometry(RrDisplay(inst),
315 pmap, &xr, &xx, &xy, &pw, &ph, &xb, &xd))
318 if (!XGetGeometry(RrDisplay(inst), mask,
319 &xr, &xx, &xy, &mw, &mh, &xb, &xd))
321 if (pw != mw || ph != mh || xd != 1)
325 xi = XGetImage(RrDisplay(inst), pmap,
326 0, 0, pw, ph, 0xffffffff, ZPixmap);
331 xm = XGetImage(RrDisplay(inst), mask,
332 0, 0, mw, mh, 0xffffffff, ZPixmap);
337 *data = g_new(RrPixel32, pw * ph);
338 RrIncreaseDepth(inst, *data, xi);
341 /* apply transparency from the mask */
343 for (i = 0, y = 0; y < ph; ++y) {
344 for (x = 0; x < pw; ++x, ++i) {
345 if (!((((unsigned)xm->data[di + x / 8]) >> (x % 8)) & 0x1))
346 (*data)[i] &= ~(0xff << RrDefaultAlphaOffset);
348 di += xm->bytes_per_line;