From: Mikael Magnusson Date: Wed, 14 Jun 2006 19:20:46 +0000 (+0000) Subject: initial commit of split gradient, looks like some RrColor leaking perhaps X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=335a0eecc748153036be7611237ed52632473de9;p=chaz%2Fopenbox initial commit of split gradient, looks like some RrColor leaking perhaps --- diff --git a/render/gradient.c b/render/gradient.c index 53f7e25c..5a5986e6 100644 --- a/render/gradient.c +++ b/render/gradient.c @@ -23,7 +23,8 @@ #include static void highlight(RrPixel32 *x, RrPixel32 *y, gboolean raised); -static void gradient_solid(RrAppearance *l, gint w, gint h); +static void gradient_solid(RrSurface *sf, gint w, gint h); +static void gradient_split(RrSurface *sf, gint w, gint h); static void gradient_vertical(RrSurface *sf, gint w, gint h); static void gradient_horizontal(RrSurface *sf, gint w, gint h); static void gradient_diagonal(RrSurface *sf, gint w, gint h); @@ -39,7 +40,10 @@ void RrRender(RrAppearance *a, gint w, gint h) switch (a->surface.grad) { case RR_SURFACE_SOLID: - gradient_solid(a, w, h); + gradient_solid(&a->surface, w, h); + break; + case RR_SURFACE_SPLIT: + gradient_split(&a->surface, w, h); break; case RR_SURFACE_VERTICAL: gradient_vertical(&a->surface, w, h); @@ -181,57 +185,57 @@ static void create_bevel_colors(RrAppearance *l) l->surface.bevel_dark = RrColorNew(l->inst, r, g, b); } -static void gradient_solid(RrAppearance *l, gint w, gint h) +static void gradient_solid(RrSurface *sf, gint w, gint h) { RrPixel32 pix; gint i, a, b; - RrSurface *sp = &l->surface; + RrAppearance *l = &sf->parent; gint left = 0, top = 0, right = w - 1, bottom = h - 1; - pix = (sp->primary->r << RrDefaultRedOffset) - + (sp->primary->g << RrDefaultGreenOffset) - + (sp->primary->b << RrDefaultBlueOffset); + pix = (sf->primary->r << RrDefaultRedOffset) + + (sf->primary->g << RrDefaultGreenOffset) + + (sf->primary->b << RrDefaultBlueOffset); for (a = 0; a < w; a++) for (b = 0; b < h; b++) - sp->pixel_data[a + b * w] = pix; + sf->pixel_data[a + b * w] = pix; - XFillRectangle(RrDisplay(l->inst), l->pixmap, RrColorGC(sp->primary), + XFillRectangle(RrDisplay(l->inst), l->pixmap, RrColorGC(sf->primary), 0, 0, w, h); - if (sp->interlaced) { + if (sf->interlaced) { for (i = 0; i < h; i += 2) XDrawLine(RrDisplay(l->inst), l->pixmap, - RrColorGC(sp->interlace_color), + RrColorGC(sf->interlace_color), 0, i, w, i); } - switch (sp->relief) { + switch (sf->relief) { case RR_RELIEF_RAISED: - if (!sp->bevel_dark) + if (!sf->bevel_dark) create_bevel_colors(l); - switch (sp->bevel) { + switch (sf->bevel) { case RR_BEVEL_1: - XDrawLine(RrDisplay(l->inst), l->pixmap, RrColorGC(sp->bevel_dark), + XDrawLine(RrDisplay(l->inst), l->pixmap, RrColorGC(sf->bevel_dark), left, bottom, right, bottom); - XDrawLine(RrDisplay(l->inst), l->pixmap, RrColorGC(sp->bevel_dark), + XDrawLine(RrDisplay(l->inst), l->pixmap, RrColorGC(sf->bevel_dark), right, bottom, right, top); - XDrawLine(RrDisplay(l->inst), l->pixmap,RrColorGC(sp->bevel_light), + XDrawLine(RrDisplay(l->inst), l->pixmap,RrColorGC(sf->bevel_light), left, top, right, top); - XDrawLine(RrDisplay(l->inst), l->pixmap,RrColorGC(sp->bevel_light), + XDrawLine(RrDisplay(l->inst), l->pixmap,RrColorGC(sf->bevel_light), left, bottom, left, top); break; case RR_BEVEL_2: - XDrawLine(RrDisplay(l->inst), l->pixmap, RrColorGC(sp->bevel_dark), + XDrawLine(RrDisplay(l->inst), l->pixmap, RrColorGC(sf->bevel_dark), left + 1, bottom - 2, right - 2, bottom - 2); - XDrawLine(RrDisplay(l->inst), l->pixmap, RrColorGC(sp->bevel_dark), + XDrawLine(RrDisplay(l->inst), l->pixmap, RrColorGC(sf->bevel_dark), right - 2, bottom - 2, right - 2, top + 1); - XDrawLine(RrDisplay(l->inst), l->pixmap,RrColorGC(sp->bevel_light), + XDrawLine(RrDisplay(l->inst), l->pixmap,RrColorGC(sf->bevel_light), left + 1, top + 1, right - 2, top + 1); - XDrawLine(RrDisplay(l->inst), l->pixmap,RrColorGC(sp->bevel_light), + XDrawLine(RrDisplay(l->inst), l->pixmap,RrColorGC(sf->bevel_light), left + 1, bottom - 2, left + 1, top + 1); break; default: @@ -239,30 +243,30 @@ static void gradient_solid(RrAppearance *l, gint w, gint h) } break; case RR_RELIEF_SUNKEN: - if (!sp->bevel_dark) + if (!sf->bevel_dark) create_bevel_colors(l); - switch (sp->bevel) { + switch (sf->bevel) { case RR_BEVEL_1: - XDrawLine(RrDisplay(l->inst), l->pixmap,RrColorGC(sp->bevel_light), + XDrawLine(RrDisplay(l->inst), l->pixmap,RrColorGC(sf->bevel_light), left, bottom, right, bottom); - XDrawLine(RrDisplay(l->inst), l->pixmap,RrColorGC(sp->bevel_light), + XDrawLine(RrDisplay(l->inst), l->pixmap,RrColorGC(sf->bevel_light), right, bottom, right, top); - XDrawLine(RrDisplay(l->inst), l->pixmap, RrColorGC(sp->bevel_dark), + XDrawLine(RrDisplay(l->inst), l->pixmap, RrColorGC(sf->bevel_dark), left, top, right, top); - XDrawLine(RrDisplay(l->inst), l->pixmap, RrColorGC(sp->bevel_dark), + XDrawLine(RrDisplay(l->inst), l->pixmap, RrColorGC(sf->bevel_dark), left, bottom, left, top); break; case RR_BEVEL_2: - XDrawLine(RrDisplay(l->inst), l->pixmap,RrColorGC(sp->bevel_light), + XDrawLine(RrDisplay(l->inst), l->pixmap,RrColorGC(sf->bevel_light), left + 1, bottom - 2, right - 2, bottom - 2); - XDrawLine(RrDisplay(l->inst), l->pixmap,RrColorGC(sp->bevel_light), + XDrawLine(RrDisplay(l->inst), l->pixmap,RrColorGC(sf->bevel_light), right - 2, bottom - 2, right - 2, top + 1); - XDrawLine(RrDisplay(l->inst), l->pixmap, RrColorGC(sp->bevel_dark), + XDrawLine(RrDisplay(l->inst), l->pixmap, RrColorGC(sf->bevel_dark), left + 1, top + 1, right - 2, top + 1); - XDrawLine(RrDisplay(l->inst), l->pixmap, RrColorGC(sp->bevel_dark), + XDrawLine(RrDisplay(l->inst), l->pixmap, RrColorGC(sf->bevel_dark), left + 1, bottom - 2, left + 1, top + 1); break; @@ -271,9 +275,9 @@ static void gradient_solid(RrAppearance *l, gint w, gint h) } break; case RR_RELIEF_FLAT: - if (sp->border) { + if (sf->border) { XDrawRectangle(RrDisplay(l->inst), l->pixmap, - RrColorGC(sp->border_color), + RrColorGC(sf->border_color), left, top, right, bottom); } break; @@ -359,6 +363,64 @@ static void gradient_solid(RrAppearance *l, gint w, gint h) } \ } +static void gradient_split(RrSurface *sf, gint w, gint h) +{ + gint x, y1, y3, r, g, b; + RrAppearance *a = &a->parent; + RrPixel32 *data = sf->pixel_data; + RrPixel32 current; + RrColor *primary_light, *secondary_light; + + r = sf->primary->r; + r += r >> 2; + g = sf->primary->g; + g += g >> 2; + b = sf->primary->b; + b += b >> 2; + if (r > 0xFF) r = 0xFF; + if (g > 0xFF) g = 0xFF; + if (b > 0xFF) b = 0xFF; + primary_light = RrColorNew(a->inst, r, g, b); + + r = sf->secondary->r; + r += r >> 4; + g = sf->secondary->g; + g += g >> 4; + b = sf->secondary->b; + b += b >> 4; + if (r > 0xFF) r = 0xFF; + if (g > 0xFF) g = 0xFF; + if (b > 0xFF) b = 0xFF; + secondary_light = RrColorNew(a->inst, r, g, b); + + VARS(y1); + SETUP(y1, primary_light, sf->primary, (h / 2) -1); + + VARS(y3); + SETUP(y3, sf->secondary, secondary_light, (h / 2) -1); + + for (y1 = h - 1; y1 > (h / 2) -1; --y1) { /* 0 -> h-1 */ + current = COLOR(y1); + for (x = w - 1; x >= 0; --x) /* 0 -> w */ + *(data++) = current; + + NEXT(y1); + } + + + for (y3 = (h / 2) - 1; y3 > 0; --y3) { + current = COLOR(y3); + for (x = w - 1; x >= 0; --x) + *(data++) = current; + + NEXT(y3); + } + + current = COLOR(y3); + for (x = w - 1; x >= 0; --x) /* 0 -> w */ + *(data++) = current; +} + static void gradient_horizontal(RrSurface *sf, gint w, gint h) { gint x, y; diff --git a/render/render.h b/render/render.h index 3ff0636b..19563137 100644 --- a/render/render.h +++ b/render/render.h @@ -61,6 +61,7 @@ typedef enum { RR_SURFACE_NONE, RR_SURFACE_PARENTREL, RR_SURFACE_SOLID, + RR_SURFACE_SPLIT, RR_SURFACE_HORIZONTAL, RR_SURFACE_VERTICAL, RR_SURFACE_DIAGONAL, diff --git a/render/theme.c b/render/theme.c index 3b44b525..e89e4dc9 100644 --- a/render/theme.c +++ b/render/theme.c @@ -1200,6 +1200,8 @@ static void parse_appearance(gchar *tex, RrSurfaceColorType *grad, *grad = RR_SURFACE_HORIZONTAL; else if (strstr(tex, "vertical") != NULL) *grad = RR_SURFACE_VERTICAL; + else if (strstr(tex, "split") != NULL) + *grad = RR_SURFACE_SPLIT; else *grad = RR_SURFACE_DIAGONAL; } else {