X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;ds=sidebyside;f=render%2Frender.c;h=cd4607bbd465d696d1d897aadfff8e229be54033;hb=43139ed3734c11c858f92f1c2cc7ed4cdba169cb;hp=71bf7fa3323369e25a4558de34f11feca4b2ee35;hpb=214fa8714ea0d2182c155eeb4b32ec32d7df337f;p=chaz%2Fopenbox diff --git a/render/render.c b/render/render.c index 71bf7fa3..cd4607bb 100644 --- a/render/render.c +++ b/render/render.c @@ -7,7 +7,11 @@ #include "mask.h" #include "color.h" #include "image.h" -#include "../kernel/openbox.h" +#include "kernel/openbox.h" + +#ifdef HAVE_STDLIB_H +# include +#endif int render_depth; Visual *render_visual; @@ -193,6 +197,7 @@ void x_paint(Window win, Appearance *l) int y = l->area.y; int w = l->area.width; int h = l->area.height; + Rect tarea; /* area in which to draw textures */ if (w <= 0 || h <= 0 || x+w <= 0 || y+h <= 0) return; @@ -227,6 +232,23 @@ void x_paint(Window win, Appearance *l) else gradient_render(&l->surface, w, h); for (i = 0; i < l->textures; i++) { + tarea = l->texture[i].position; + if (l->surface.data.planar.relief != Flat) { + switch (l->surface.data.planar.bevel) { + case Bevel1: + tarea.x += 1; tarea.y += 1; + tarea.width -= 2; tarea.height -= 2; + break; + case Bevel2: + tarea.x += 2; tarea.y += 2; + tarea.width -= 4; tarea.height -= 4; + break; + } + } else if (l->surface.data.planar.border) { + tarea.x += 1; tarea.y += 1; + tarea.width -= 2; tarea.height -= 2; + } + switch (l->texture[i].type) { case Text: if (!transferred) { @@ -240,7 +262,7 @@ void x_paint(Window win, Appearance *l) render_visual, render_colormap); } font_draw(l->xftdraw, &l->texture[i].data.text, - &l->texture[i].position); + &tarea); break; case Bitmask: if (!transferred) { @@ -252,12 +274,12 @@ void x_paint(Window win, Appearance *l) if (l->texture[i].data.mask.color->gc == None) color_allocate_gc(l->texture[i].data.mask.color); mask_draw(l->pixmap, &l->texture[i].data.mask, - &l->texture[i].position); + &tarea); break; case RGBA: image_draw(l->surface.data.planar.pixel_data, &l->texture[i].data.rgba, - &l->texture[i].position); + &tarea); break; } } @@ -355,33 +377,86 @@ Appearance *appearance_copy(Appearance *orig) void appearance_free(Appearance *a) { - PlanarSurface *p; - if (a->pixmap != None) XFreePixmap(ob_display, a->pixmap); - if (a->xftdraw != NULL) XftDrawDestroy(a->xftdraw); - if (a->textures) - g_free(a->texture); - if (a->surface.type == Surface_Planar) { - p = &a->surface.data.planar; - if (p->primary != NULL) color_free(p->primary); - if (p->secondary != NULL) color_free(p->secondary); - if (p->border_color != NULL) color_free(p->border_color); - if (p->pixel_data != NULL) g_free(p->pixel_data); + if (a) { + PlanarSurface *p; + if (a->pixmap != None) XFreePixmap(ob_display, a->pixmap); + if (a->xftdraw != NULL) XftDrawDestroy(a->xftdraw); + if (a->textures) + g_free(a->texture); + if (a->surface.type == Surface_Planar) { + p = &a->surface.data.planar; + if (p->primary != NULL) color_free(p->primary); + if (p->secondary != NULL) color_free(p->secondary); + if (p->border_color != NULL) color_free(p->border_color); + if (p->pixel_data != NULL) g_free(p->pixel_data); + } + g_free(a); } - g_free(a); } void pixel32_to_pixmap(pixel32 *in, Pixmap out, int x, int y, int w, int h) { + unsigned char *scratch; XImage *im = NULL; im = XCreateImage(ob_display, render_visual, render_depth, ZPixmap, 0, NULL, w, h, 32, 0); g_assert(im != NULL); im->byte_order = endian; - im->data = (char *)in; - reduce_depth((pixel32*)im->data, im); +/* this malloc is a complete waste of time on normal 32bpp + as reduce_depth just sets im->data = data and returns +*/ + scratch = malloc(im->width * im->height * sizeof(pixel32)); + im->data = (char*) scratch; + reduce_depth(in, im); XPutImage(ob_display, out, DefaultGC(ob_display, ob_screen), im, 0, 0, x, y, w, h); im->data = NULL; XDestroyImage(im); + free(scratch); +} + +void appearance_minsize(Appearance *l, int *w, int *h) +{ + int i; + *w = *h = 1; + + switch (l->surface.type) { + case Surface_Planar: + if (l->surface.data.planar.relief != Flat) { + switch (l->surface.data.planar.bevel) { + case Bevel1: + *w = *h = 2; + break; + case Bevel2: + *w = *h = 4; + break; + } + } else if (l->surface.data.planar.border) + *w = *h = 2; + + for (i = 0; i < l->textures; ++i) + switch (l->texture[i].type) { + case Bitmask: + *w += l->texture[i].data.mask.mask->w; + *h += l->texture[i].data.mask.mask->h; + break; + case Text: + *w +=font_measure_string(l->texture[i].data.text.font, + l->texture[i].data.text.string, + l->texture[i].data.text.shadow, + l->texture[i].data.text.offset); + *h += font_height(l->texture[i].data.text.font, + l->texture[i].data.text.shadow, + l->texture[i].data.text.offset); + break; + case RGBA: + *w += l->texture[i].data.rgba.width; + *h += l->texture[i].data.rgba.height; + break; + case NoTexture: + break; + } + break; + } }