From: Dana Jansens Date: Fri, 20 Jun 2003 07:58:51 +0000 (+0000) Subject: this is going to break the kernel/ building. X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=3f32dfa87e08556d7f6a58efab9b7479e515be26;p=chaz%2Fopenbox this is going to break the kernel/ building. lots of modifications to the render API, prefixing everything, making proper names for everything. the structures are not hidden/opaque yet, but the naming scheme of the public API works much better now. --- diff --git a/render/.cvsignore b/render/.cvsignore index 54aa917c..41200f78 100644 --- a/render/.cvsignore +++ b/render/.cvsignore @@ -13,3 +13,4 @@ theme.lo Makefile.in .deps Makefile +instance.lo diff --git a/render/Makefile.am b/render/Makefile.am index 579ff681..87431ae1 100644 --- a/render/Makefile.am +++ b/render/Makefile.am @@ -15,8 +15,22 @@ rendertest_LDFLAGS=-lobrender -L. rendertest_SOURCES=test.c lib_LTLIBRARIES=libobrender.la -libobrender_la_SOURCES=color.c font.c gradient.c image.c mask.c render.c \ - theme.c +libobrender_la_SOURCES=\ + color.h \ + color.c \ + font.h \ + font.c \ + gradient.h \ + gradient.c \ + image.h \ + image.c \ + mask.h \ + mask.c \ + render.h \ + render.c \ + theme.c \ + instance.h \ + instance.c noinst_HEADERS=render.h gradient.h color.h font.h mask.h image.h diff --git a/render/color.c b/render/color.c index af57b78a..145550f3 100644 --- a/render/color.c +++ b/render/color.c @@ -3,7 +3,6 @@ #include #include "render.h" #include "color.h" -#include "../kernel/openbox.h" XColor *pseudo_colors; int pseudo_bpc; @@ -14,10 +13,12 @@ void color_allocate_gc(color_rgb *in) gcv.foreground = in->pixel; gcv.cap_style = CapProjecting; - in->gc = XCreateGC(ob_display, ob_root, GCForeground | GCCapStyle, &gcv); + in->gc = XCreateGC(RrDisplay(in->inst), + RrRootWindow(in->inst), + GCForeground | GCCapStyle, &gcv); } -color_rgb *color_parse(char *colorname) +color_rgb *RrColorParse(const RrInstance *inst, gchar *colorname) { XColor xcol; @@ -28,45 +29,44 @@ color_rgb *color_parse(char *colorname) xcol.green = 0; xcol.blue = 0; xcol.pixel = 0; - if (!XParseColor(ob_display, render_colormap, colorname, &xcol)) { + if (!XParseColor(RrDisplay(inst), RrColormap(inst), colorname, &xcol)) { g_warning("unable to parse color '%s'", colorname); return NULL; } - return color_new(xcol.red >> 8, xcol.green >> 8, xcol.blue >> 8); + return RrColorNew(inst, xcol.red >> 8, xcol.green >> 8, xcol.blue >> 8); } -color_rgb *color_new(int r, int g, int b) +color_rgb *RrColorNew(const RrInstance *inst, gint r, gint g, gint b) { -/* this should be replaced with something far cooler */ - color_rgb *out; + /* this should be replaced with something far cooler */ + color_rgb *out = NULL; XColor xcol; xcol.red = (r << 8) | r; xcol.green = (g << 8) | g; xcol.blue = (b << 8) | b; - if (XAllocColor(ob_display, render_colormap, &xcol)) { + if (XAllocColor(RrDisplay(inst), RrColormap(inst), &xcol)) { out = g_new(color_rgb, 1); + out->inst = inst; out->r = xcol.red >> 8; out->g = xcol.green >> 8; out->b = xcol.blue >> 8; out->gc = None; out->pixel = xcol.pixel; - return out; } - return NULL; + return out; } /*XXX same color could be pointed to twice, this might have to be a refcount*/ -void color_free(color_rgb *c) +void RrColorFree(color_rgb *c) { - if (c != NULL) { - if (c->gc != None) - XFreeGC(ob_display, c->gc); + if (c) { + if (c->gc) XFreeGC(RrDisplay(c->inst), c->gc); g_free(c); } } -void reduce_depth(pixel32 *data, XImage *im) +void reduce_depth(const RrInstance *inst, pixel32 *data, XImage *im) { int r, g, b; int x,y; @@ -75,17 +75,17 @@ void reduce_depth(pixel32 *data, XImage *im) unsigned char *p8 = (unsigned char *)im->data; switch (im->bits_per_pixel) { case 32: - if ((render_red_offset != default_red_offset) || - (render_blue_offset != default_blue_offset) || - (render_green_offset != default_green_offset)) { + if ((RrRedOffset(inst) != default_red_offset) || + (RrBlueOffset(inst) != default_blue_offset) || + (RrGreenOffset(inst) != default_green_offset)) { for (y = 0; y < im->height; y++) { for (x = 0; x < im->width; x++) { r = (data[x] >> default_red_offset) & 0xFF; g = (data[x] >> default_green_offset) & 0xFF; b = (data[x] >> default_blue_offset) & 0xFF; - p32[x] = (r << render_red_shift) - + (g << render_green_shift) - + (b << render_blue_shift); + p32[x] = (r << RrRedShift(inst)) + + (g << RrGreenShift(inst)) + + (b << RrBlueShift(inst)); } data += im->width; p32 += im->width; @@ -96,26 +96,27 @@ void reduce_depth(pixel32 *data, XImage *im) for (y = 0; y < im->height; y++) { for (x = 0; x < im->width; x++) { r = (data[x] >> default_red_offset) & 0xFF; - r = r >> render_red_shift; + r = r >> RrRedShift(inst); g = (data[x] >> default_green_offset) & 0xFF; - g = g >> render_green_shift; + g = g >> RrGreenShift(inst); b = (data[x] >> default_blue_offset) & 0xFF; - b = b >> render_blue_shift; - p16[x] = (r << render_red_offset) - + (g << render_green_offset) - + (b << render_blue_offset); + b = b >> RrBlueShift(inst); + p16[x] = (r << RrRedOffset(inst)) + + (g << RrGreenOffset(inst)) + + (b << RrBlueOffset(inst)); } data += im->width; p16 += im->bytes_per_line/2; } break; case 8: - g_assert(render_visual->class != TrueColor); + g_assert(RrVisual(inst)->class != TrueColor); for (y = 0; y < im->height; y++) { for (x = 0; x < im->width; x++) { - p8[x] = pickColor(data[x] >> default_red_offset, - data[x] >> default_green_offset, - data[x] >> default_blue_offset)->pixel; + p8[x] = pickColor(inst, + data[x] >> default_red_offset, + data[x] >> default_green_offset, + data[x] >> default_blue_offset)->pixel; } data += im->width; p8 += im->bytes_per_line; @@ -127,12 +128,14 @@ void reduce_depth(pixel32 *data, XImage *im) } } -XColor *pickColor(int r, int g, int b) +XColor *pickColor(const RrInstance *inst, gint r, gint g, gint b) { r = (r & 0xff) >> (8-pseudo_bpc); g = (g & 0xff) >> (8-pseudo_bpc); b = (b & 0xff) >> (8-pseudo_bpc); - return &pseudo_colors[(r << (2*pseudo_bpc)) + (g << (1*pseudo_bpc)) + b]; + return &RrPseudoColors(inst)[(r << (2*pseudo_bpc)) + + (g << (1*pseudo_bpc)) + + b]; } static void swap_byte_order(XImage *im) @@ -171,7 +174,7 @@ static void swap_byte_order(XImage *im) im->byte_order = LSBFirst; } -void increase_depth(pixel32 *data, XImage *im) +void increase_depth(const RrInstance *inst, pixel32 *data, XImage *im) { int r, g, b; int x,y; @@ -186,9 +189,9 @@ void increase_depth(pixel32 *data, XImage *im) case 32: for (y = 0; y < im->height; y++) { for (x = 0; x < im->width; x++) { - r = (p32[x] >> render_red_offset) & 0xff; - g = (p32[x] >> render_green_offset) & 0xff; - b = (p32[x] >> render_blue_offset) & 0xff; + r = (p32[x] >> RrRedOffset(inst)) & 0xff; + g = (p32[x] >> RrGreenOffset(inst)) & 0xff; + b = (p32[x] >> RrBlueOffset(inst)) & 0xff; data[x] = (r << default_red_offset) + (g << default_green_offset) + (b << default_blue_offset) @@ -201,12 +204,15 @@ void increase_depth(pixel32 *data, XImage *im) case 16: for (y = 0; y < im->height; y++) { for (x = 0; x < im->width; x++) { - r = (p16[x] & render_red_mask) >> render_red_offset << - render_red_shift; - g = (p16[x] & render_green_mask) >> render_green_offset << - render_green_shift; - b = (p16[x] & render_blue_mask) >> render_blue_offset << - render_blue_shift; + r = (p16[x] & RrRedMask(inst)) >> + RrRedOffset(inst) << + RrRedShift(inst); + g = (p16[x] & RrGreenMask(inst)) >> + RrGreenOffset(inst) << + RrGreenShift(inst); + b = (p16[x] & RrBlueMask(inst)) >> + RrBlueOffset(inst) << + RrBlueShift(inst); data[x] = (r << default_red_offset) + (g << default_green_offset) + (b << default_blue_offset) diff --git a/render/color.h b/render/color.h index fb669fb5..2ed23ddd 100644 --- a/render/color.h +++ b/render/color.h @@ -1,25 +1,11 @@ #ifndef __color_h #define __color_h +#include "render.h" + #include #include - -#ifdef HAVE_STDINT_H -# include -#else -# ifdef HAVE_SYS_TYPES_H -# include -# endif -#endif - - -#ifdef HAVE_STDINT_H -typedef uint32_t pixel32; -typedef uint16_t pixel16; -#else -typedef u_int32_t pixel32; -typedef u_int16_t pixel16; -#endif /* HAVE_STDINT_H */ +#include #if (G_BYTE_ORDER == G_BIG_ENDIAN) #define default_red_offset 0 @@ -35,36 +21,19 @@ typedef u_int16_t pixel16; #define render_endian LSBFirst #endif /* G_BYTE_ORDER == G_BIG_ENDIAN */ +struct _RrColor { + const RrInstance *inst; -typedef struct color_rgb { int r; int g; int b; unsigned long pixel; GC gc; -} color_rgb; +}; void color_allocate_gc(color_rgb *in); -XColor *pickColor(int r, int g, int b); -color_rgb *color_parse(char *colorname); -color_rgb *color_new(int r, int g, int b); -void color_free(color_rgb *in); -void reduce_depth(pixel32 *data, XImage *im); -void increase_depth(pixel32 *data, XImage *im); - -extern int render_red_offset; -extern int render_green_offset; -extern int render_blue_offset; - -extern int render_red_shift; -extern int render_green_shift; -extern int render_blue_shift; - -extern int render_red_mask; -extern int render_green_mask; -extern int render_blue_mask; +XColor *pickColor(const RrInstance *inst, gint r, gint g, gint b); +void reduce_depth(const RrInstance *inst, pixel32 *data, XImage *im); +void increase_depth(const RrInstance *inst, pixel32 *data, XImage *im); -extern int pseudo_bpc; -#define pseudo_ncolors() (1 << (pseudo_bpc * 3)) -extern XColor *pseudo_colors; #endif /* __color_h */ diff --git a/render/font.c b/render/font.c index 86660626..785b22fc 100644 --- a/render/font.c +++ b/render/font.c @@ -30,7 +30,7 @@ void font_startup(void) #endif } -static void measure_height(ObFont *f) +static void measure_height(RrFont *f) { XGlyphInfo info; @@ -40,13 +40,13 @@ static void measure_height(ObFont *f) f->elipses_length = (signed) info.xOff; } -ObFont *font_open(char *fontstring) +RrFont *font_open(char *fontstring) { - ObFont *out; + RrFont *out; XftFont *xf; if ((xf = XftFontOpenName(ob_display, ob_screen, fontstring))) { - out = g_new(ObFont, 1); + out = g_new(RrFont, 1); out->xftfont = xf; measure_height(out); return out; @@ -55,7 +55,7 @@ ObFont *font_open(char *fontstring) g_warning(_("Trying fallback font: %s\n"), "sans"); if ((xf = XftFontOpenName(ob_display, ob_screen, "sans"))) { - out = g_new(ObFont, 1); + out = g_new(RrFont, 1); out->xftfont = xf; measure_height(out); return out; @@ -66,7 +66,7 @@ ObFont *font_open(char *fontstring) exit(3); /* can't continue without a font */ } -void font_close(ObFont *f) +void font_close(RrFont *f) { if (f) { XftFontClose(ob_display, f->xftfont); @@ -74,7 +74,7 @@ void font_close(ObFont *f) } } -void font_measure_full(ObFont *f, char *str, int shadow, int offset, +void font_measure_full(RrFont *f, char *str, int shadow, int offset, int *x, int *y) { XGlyphInfo info; @@ -86,24 +86,24 @@ void font_measure_full(ObFont *f, char *str, int shadow, int offset, *y = info.height + (shadow ? ABS(offset) : 0); } -int font_measure_string(ObFont *f, char *str, int shadow, int offset) +int font_measure_string(RrFont *f, char *str, int shadow, int offset) { int x, y; font_measure_full (f, str, shadow, offset, &x, &y); return x; } -int font_height(ObFont *f, int shadow, int offset) +int font_height(RrFont *f, int shadow, int offset) { return f->xftfont->ascent + f->xftfont->descent + (shadow ? offset : 0); } -int font_max_char_width(ObFont *f) +int font_max_char_width(RrFont *f) { return (signed) f->xftfont->max_advance_width; } -void font_draw(XftDraw *d, TextureText *t, Rect *area) +void font_draw(XftDraw *d, RrTextureText *t, Rect *area) { int x,y,w,h; XftColor c; @@ -139,13 +139,13 @@ void font_draw(XftDraw *d, TextureText *t, Rect *area) if (!l) return; switch (t->justify) { - case Justify_Left: + case RR_JUSTIFY_LEFT: x = area->x + theme_bevel; break; - case Justify_Right: + case RR_JUSTIFY_RIGHT: x = area->x + (w - mw) - theme_bevel; break; - case Justify_Center: + case RR_JUSTIFY_CENTER: x = area->x + (w - mw) / 2; break; } diff --git a/render/font.h b/render/font.h index 6a5d4c65..393ac88e 100644 --- a/render/font.h +++ b/render/font.h @@ -1,14 +1,20 @@ #ifndef __font_h #define __font_h +#define _XFT_NO_COMPAT_ /* no Xft 1 API */ #include #include "render.h" #include "kernel/geom.h" +struct _RrFont { + XftFont *xftfont; + gint elipses_length; +}; + void font_startup(void); -ObFont *font_open(char *fontstring); -void font_close(ObFont *f); -int font_measure_string(ObFont *f, char *str, int shadow, int offset); -int font_height(ObFont *f, int shadow, int offset); -int font_max_char_width(ObFont *f); -void font_draw(XftDraw *d, TextureText *t, Rect *position); +RrFont *font_open(char *fontstring); +void font_close(RrFont *f); +int font_measure_string(RrFont *f, char *str, int shadow, int offset); +int font_height(RrFont *f, int shadow, int offset); +int font_max_char_width(RrFont *f); +void font_draw(XftDraw *d, RrTextureText *t, Rect *position); #endif /* __font_h */ diff --git a/render/gradient.c b/render/gradient.c index ebfdb3bb..feb4ad08 100644 --- a/render/gradient.c +++ b/render/gradient.c @@ -1,10 +1,9 @@ -#include #include "render.h" #include "gradient.h" -#include "../kernel/openbox.h" #include "color.h" +#include -void gradient_render(Surface *sf, int w, int h) +void gradient_render(RrSurface *sf, int w, int h) { pixel32 *data = sf->pixel_data; pixel32 current; @@ -12,27 +11,27 @@ void gradient_render(Surface *sf, int w, int h) int off, x; switch (sf->grad) { - case Background_Solid: /* already handled */ + case RR_SURFACE_SOLID: /* already handled */ return; - case Background_Vertical: + case RR_SURFACE_VERTICAL: gradient_vertical(sf, w, h); break; - case Background_Horizontal: + case RR_SURFACE_HORIZONTAL: gradient_horizontal(sf, w, h); break; - case Background_Diagonal: + case RR_SURFACE_DIAGONAL: gradient_diagonal(sf, w, h); break; - case Background_CrossDiagonal: + case RR_SURFACE_CROSS_DIAGONAL: gradient_crossdiagonal(sf, w, h); break; - case Background_Pyramid: + case RR_SURFACE_PYRAMID: gradient_pyramid(sf, w, h); break; - case Background_PipeCross: + case RR_SURFACE_PIPECROSS: gradient_pipecross(sf, w, h); break; - case Background_Rectangle: + case RR_SURFACE_RECTANGLE: gradient_rectangle(sf, w, h); break; default: @@ -40,7 +39,7 @@ void gradient_render(Surface *sf, int w, int h) return; } - if (sf->relief == Flat && sf->border) { + if (sf->relief == RR_RELIEF_FLAT && sf->border) { r = sf->border_color->r; g = sf->border_color->g; b = sf->border_color->b; @@ -57,34 +56,34 @@ void gradient_render(Surface *sf, int w, int h) } } - if (sf->relief != Flat) { - if (sf->bevel == Bevel1) { + if (sf->relief != RR_RELIEF_FLAT) { + if (sf->bevel == RR_BEVEL_1) { for (off = 1, x = 1; x < w - 1; ++x, off++) highlight(data + off, data + off + (h-1) * w, - sf->relief==Raised); + sf->relief==RR_RELIEF_RAISED); for (off = 0, x = 0; x < h; ++x, off++) highlight(data + off * w, data + off * w + w - 1, - sf->relief==Raised); + sf->relief==RR_RELIEF_RAISED); } - if (sf->bevel == Bevel2) { + if (sf->bevel == RR_BEVEL_2) { for (off = 2, x = 2; x < w - 2; ++x, off++) highlight(data + off + w, data + off + (h-2) * w, - sf->relief==Raised); + sf->relief==RR_RELIEF_RAISED); for (off = 1, x = 1; x < h-1; ++x, off++) highlight(data + off * w + 1, data + off * w + w - 2, - sf->relief==Raised); + sf->relief==RR_RELIEF_RAISED); } } } -void gradient_vertical(Surface *sf, int w, int h) +void gradient_vertical(RrSurface *sf, int w, int h) { pixel32 *data = sf->pixel_data; pixel32 current; @@ -113,7 +112,7 @@ void gradient_vertical(Surface *sf, int w, int h) } } -void gradient_horizontal(Surface *sf, int w, int h) +void gradient_horizontal(RrSurface *sf, int w, int h) { pixel32 *data = sf->pixel_data; pixel32 current; @@ -142,7 +141,7 @@ void gradient_horizontal(Surface *sf, int w, int h) } } -void gradient_diagonal(Surface *sf, int w, int h) +void gradient_diagonal(RrSurface *sf, int w, int h) { pixel32 *data = sf->pixel_data; pixel32 current; @@ -180,7 +179,7 @@ void gradient_diagonal(Surface *sf, int w, int h) } } -void gradient_crossdiagonal(Surface *sf, int w, int h) +void gradient_crossdiagonal(RrSurface *sf, int w, int h) { pixel32 *data = sf->pixel_data; pixel32 current; @@ -252,7 +251,7 @@ void highlight(pixel32 *x, pixel32 *y, gboolean raised) + (b << default_blue_offset); } -static void create_bevel_colors(Appearance *l) +static void create_bevel_colors(RrAppearance *l) { int r, g, b; @@ -267,7 +266,7 @@ static void create_bevel_colors(Appearance *l) if (g > 0xFF) g = 0xFF; if (b > 0xFF) b = 0xFF; g_assert(!l->surface.bevel_light); - l->surface.bevel_light = color_new(r, g, b); + l->surface.bevel_light = RrColorNew(l->inst, r, g, b); color_allocate_gc(l->surface.bevel_light); /* dark color */ @@ -278,15 +277,15 @@ static void create_bevel_colors(Appearance *l) b = l->surface.primary->b; b = (b >> 1) + (b >> 2); g_assert(!l->surface.bevel_dark); - l->surface.bevel_dark = color_new(r, g, b); + l->surface.bevel_dark = RrColorNew(l->inst, r, g, b); color_allocate_gc(l->surface.bevel_dark); } -void gradient_solid(Appearance *l, int x, int y, int w, int h) +void gradient_solid(RrAppearance *l, int x, int y, int w, int h) { pixel32 pix; int i, a, b; - Surface *sp = &l->surface; + RrSurface *sp = &l->surface; int left = x, top = y, right = x + w - 1, bottom = y + h - 1; if (sp->primary->gc == None) @@ -299,46 +298,46 @@ void gradient_solid(Appearance *l, int x, int y, int w, int h) for (b = 0; b < h; b++) sp->pixel_data[a + b * w] = pix; - XFillRectangle(ob_display, l->pixmap, sp->primary->gc, + XFillRectangle(RrDisplay(l->inst), l->pixmap, sp->primary->gc, x, y, w, h); if (sp->interlaced) { if (sp->secondary->gc == None) color_allocate_gc(sp->secondary); for (i = y; i < h; i += 2) - XDrawLine(ob_display, l->pixmap, sp->secondary->gc, + XDrawLine(RrDisplay(l->inst), l->pixmap, sp->secondary->gc, x, i, w, i); } switch (sp->relief) { - case Raised: + case RR_RELIEF_RAISED: if (!sp->bevel_dark) create_bevel_colors(l); switch (sp->bevel) { - case Bevel1: - XDrawLine(ob_display, l->pixmap, sp->bevel_dark->gc, + case RR_BEVEL_1: + XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_dark->gc, left, bottom, right, bottom); - XDrawLine(ob_display, l->pixmap, sp->bevel_dark->gc, + XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_dark->gc, right, bottom, right, top); - XDrawLine(ob_display, l->pixmap, sp->bevel_light->gc, + XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_light->gc, left, top, right, top); - XDrawLine(ob_display, l->pixmap, sp->bevel_light->gc, + XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_light->gc, left, bottom, left, top); break; - case Bevel2: - XDrawLine(ob_display, l->pixmap, + case RR_BEVEL_2: + XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_dark->gc, left + 1, bottom - 2, right - 2, bottom - 2); - XDrawLine(ob_display, l->pixmap, + XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_dark->gc, right - 2, bottom - 2, right - 2, top + 1); - XDrawLine(ob_display, l->pixmap, + XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_light->gc, left + 1, top + 1, right - 2, top + 1); - XDrawLine(ob_display, l->pixmap, + XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_light->gc, left + 1, bottom - 2, left + 1, top + 1); break; @@ -346,31 +345,31 @@ void gradient_solid(Appearance *l, int x, int y, int w, int h) g_assert_not_reached(); /* unhandled BevelType */ } break; - case Sunken: + case RR_RELIEF_SUNKEN: if (!sp->bevel_dark) create_bevel_colors(l); switch (sp->bevel) { - case Bevel1: - XDrawLine(ob_display, l->pixmap, sp->bevel_light->gc, + case RR_BEVEL_1: + XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_light->gc, left, bottom, right, bottom); - XDrawLine(ob_display, l->pixmap, sp->bevel_light->gc, + XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_light->gc, right, bottom, right, top); - XDrawLine(ob_display, l->pixmap, sp->bevel_dark->gc, + XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_dark->gc, left, top, right, top); - XDrawLine(ob_display, l->pixmap, sp->bevel_dark->gc, + XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_dark->gc, left, bottom, left, top); break; - case Bevel2: - XDrawLine(ob_display, l->pixmap, sp->bevel_light->gc, + case RR_BEVEL_2: + XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_light->gc, left + 1, bottom - 2, right - 2, bottom - 2); - XDrawLine(ob_display, l->pixmap, sp->bevel_light->gc, + XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_light->gc, right - 2, bottom - 2, right - 2, top + 1); - XDrawLine(ob_display, l->pixmap, sp->bevel_dark->gc, + XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_dark->gc, left + 1, top + 1, right - 2, top + 1); - XDrawLine(ob_display, l->pixmap, sp->bevel_dark->gc, + XDrawLine(RrDisplay(l->inst), l->pixmap, sp->bevel_dark->gc, left + 1, bottom - 2, left + 1, top + 1); break; @@ -378,11 +377,11 @@ void gradient_solid(Appearance *l, int x, int y, int w, int h) g_assert_not_reached(); /* unhandled BevelType */ } break; - case Flat: + case RR_RELIEF_FLAT: if (sp->border) { if (sp->border_color->gc == None) color_allocate_gc(sp->border_color); - XDrawRectangle(ob_display, l->pixmap, sp->border_color->gc, + XDrawRectangle(RrDisplay(l->inst), l->pixmap, sp->border_color->gc, left, top, right, bottom); } break; @@ -391,7 +390,7 @@ void gradient_solid(Appearance *l, int x, int y, int w, int h) } } -void gradient_pyramid(Surface *sf, int inw, int inh) +void gradient_pyramid(RrSurface *sf, int inw, int inh) { pixel32 *data = sf->pixel_data; pixel32 *end = data + inw*inh - 1; @@ -436,7 +435,7 @@ void gradient_pyramid(Surface *sf, int inw, int inh) } } -void gradient_rectangle(Surface *sf, int inw, int inh) +void gradient_rectangle(RrSurface *sf, int inw, int inh) { pixel32 *data = sf->pixel_data; pixel32 *end = data + inw*inh - 1; @@ -484,7 +483,7 @@ void gradient_rectangle(Surface *sf, int inw, int inh) } } -void gradient_pipecross(Surface *sf, int inw, int inh) +void gradient_pipecross(RrSurface *sf, int inw, int inh) { pixel32 *data = sf->pixel_data; pixel32 *end = data + inw*inh - 1; diff --git a/render/gradient.h b/render/gradient.h index bbadcd0d..9487ce7f 100644 --- a/render/gradient.h +++ b/render/gradient.h @@ -3,17 +3,17 @@ #include "render.h" -void gradient_render(Surface *sf, int w, int h); -void gradient_vertical(Surface *sf, int w, int h); -void gradient_horizontal(Surface *sf, int w, int h); -void gradient_diagonal(Surface *sf, int w, int h); -void gradient_crossdiagonal(Surface *sf, int w, int h); -void gradient_pyramid(Surface *sf, int w, int h); -void gradient_pipecross(Surface *sf, int w, int h); -void gradient_rectangle(Surface *sf, int w, int h); -void gradient_solid(Appearance *l, int x, int y, int w, int h); +void gradient_render(RrSurface *sf, int w, int h); +void gradient_vertical(RrSurface *sf, int w, int h); +void gradient_horizontal(RrSurface *sf, int w, int h); +void gradient_diagonal(RrSurface *sf, int w, int h); +void gradient_crossdiagonal(RrSurface *sf, int w, int h); +void gradient_pyramid(RrSurface *sf, int w, int h); +void gradient_pipecross(RrSurface *sf, int w, int h); +void gradient_rectangle(RrSurface *sf, int w, int h); +void gradient_solid(RrAppearance *l, int x, int y, int w, int h); void highlight(pixel32 *x, pixel32 *y, gboolean raised); -void render_gl_gradient(Surface *sf, int x, int y, int w, int h); +void render_gl_gradient(RrSurface *sf, int x, int y, int w, int h); #endif /* __gradient_h */ diff --git a/render/image.c b/render/image.c index 351a831d..5209d120 100644 --- a/render/image.c +++ b/render/image.c @@ -1,11 +1,13 @@ -#include #include "../kernel/geom.h" #include "image.h" +#include "color.h" + +#include -void image_draw(pixel32 *target, TextureRGBA *rgba, Rect *area) +void image_draw(pixel32 *target, RrTextureRGBA *rgba, Rect *area) { pixel32 *draw = rgba->data; - guint c, i, e, t, sfw, sfh; + gint c, i, e, t, sfw, sfh; sfw = area->width; sfh = area->height; diff --git a/render/image.h b/render/image.h index 7dd48e7d..65c2ad5c 100644 --- a/render/image.h +++ b/render/image.h @@ -4,6 +4,6 @@ #include "render.h" #include "../kernel/geom.h" -void image_draw(pixel32 *target, TextureRGBA *rgba, Rect *area); +void image_draw(pixel32 *target, RrTextureRGBA *rgba, Rect *area); #endif diff --git a/render/instance.c b/render/instance.c new file mode 100644 index 00000000..bd2b537e --- /dev/null +++ b/render/instance.c @@ -0,0 +1,247 @@ +#include "render.h" +#include "instance.h" + +static RrInstance *definst = NULL; + +void RrTrueColorSetup (RrInstance *inst); +void RrPseudoColorSetup (RrInstance *inst); + +RrInstance* RrInstanceNew (Display *display, gint screen) +{ + definst = g_new (RrInstance, 1); + definst->display = display; + definst->screen = screen; + + definst->depth = DefaultDepth(display, screen); + definst->visual = DefaultVisual(display, screen); + definst->colormap = DefaultColormap(display, screen); + + definst->pseudo_colors = NULL; + + switch (definst->visual->class) { + case TrueColor: + RrTrueColorSetup(definst); + break; + case PseudoColor: + case StaticColor: + case GrayScale: + case StaticGray: + RrPseudoColorSetup(definst); + break; + default: + g_critical("Unsupported visual class"); + g_free (definst); + return definst = NULL; + } + return definst; +} + +void RrTrueColorSetup (RrInstance *inst) +{ + unsigned long red_mask, green_mask, blue_mask; + XImage *timage = NULL; + + timage = XCreateImage(inst->display, inst->visual, inst->depth, + ZPixmap, 0, NULL, 1, 1, 32, 0); + g_assert(timage != NULL); + /* find the offsets for each color in the visual's masks */ + inst->red_mask = red_mask = timage->red_mask; + inst->green_mask = green_mask = timage->green_mask; + inst->blue_mask = blue_mask = timage->blue_mask; + + inst->red_offset = 0; + inst->green_offset = 0; + inst->blue_offset = 0; + + while (! (red_mask & 1)) { inst->red_offset++; red_mask >>= 1; } + while (! (green_mask & 1)) { inst->green_offset++; green_mask >>= 1; } + while (! (blue_mask & 1)) { inst->blue_offset++; blue_mask >>= 1; } + + inst->red_shift = inst->green_shift = inst->blue_shift = 8; + while (red_mask) { red_mask >>= 1; inst->red_shift--; } + while (green_mask) { green_mask >>= 1; inst->green_shift--; } + while (blue_mask) { blue_mask >>= 1; inst->blue_shift--; } + XFree(timage); +} + +#define RrPseudoNcolors(isnt) (1 << (inst->pseudo_bpc * 3)) + +void RrPseudoColorSetup (RrInstance *inst) +{ + XColor icolors[256]; + int tr, tg, tb, n, r, g, b, i, incolors, ii; + unsigned long dev; + int cpc, _ncolors; + g_message("Initializing PseudoColor RenderControl\n"); + + /* determine the number of colors and the bits-per-color */ + inst->pseudo_bpc = 2; /* XXX THIS SHOULD BE A USER OPTION */ + g_assert(inst->pseudo_bpc >= 1); + _ncolors = RrPseudoNcolors(inst); + + if (_ncolors > 1 << inst->depth) { + g_warning("PseudoRenderControl: Invalid colormap size. Resizing.\n"); + inst->pseudo_bpc = 1 << (inst->depth/3) >> 3; + _ncolors = 1 << (inst->pseudo_bpc * 3); + } + + /* build a color cube */ + inst->pseudo_colors = g_new(XColor, _ncolors); + cpc = 1 << inst->pseudo_bpc; /* colors per channel */ + + for (n = 0, r = 0; r < cpc; r++) + for (g = 0; g < cpc; g++) + for (b = 0; b < cpc; b++, n++) { + tr = (int)(((float)(r)/(float)(cpc-1)) * 0xFF); + tg = (int)(((float)(g)/(float)(cpc-1)) * 0xFF); + tb = (int)(((float)(b)/(float)(cpc-1)) * 0xFF); + inst->pseudo_colors[n].red = tr | tr << 8; + inst->pseudo_colors[n].green = tg | tg << 8; + inst->pseudo_colors[n].blue = tb | tb << 8; + /* used to track allocation */ + inst->pseudo_colors[n].flags = DoRed|DoGreen|DoBlue; + } + + /* allocate the colors */ + for (i = 0; i < _ncolors; i++) + if (!XAllocColor(inst->display, inst->colormap, + &inst->pseudo_colors[i])) + inst->pseudo_colors[i].flags = 0; /* mark it as unallocated */ + + /* try allocate any colors that failed allocation above */ + + /* get the allocated values from the X server + (only the first 256 XXX why!?) + */ + incolors = (((1 << inst->depth) > 256) ? 256 : (1 << inst->depth)); + for (i = 0; i < incolors; i++) + icolors[i].pixel = i; + XQueryColors(inst->display, inst->colormap, icolors, incolors); + + /* try match unallocated ones */ + for (i = 0; i < _ncolors; i++) { + if (!inst->pseudo_colors[i].flags) { /* if it wasn't allocated... */ + unsigned long closest = 0xffffffff, close = 0; + for (ii = 0; ii < incolors; ii++) { + /* find deviations */ + r = (inst->pseudo_colors[i].red - icolors[ii].red) & 0xff; + g = (inst->pseudo_colors[i].green - icolors[ii].green) & 0xff; + b = (inst->pseudo_colors[i].blue - icolors[ii].blue) & 0xff; + /* find a weighted absolute deviation */ + dev = (r * r) + (g * g) + (b * b); + + if (dev < closest) { + closest = dev; + close = ii; + } + } + + inst->pseudo_colors[i].red = icolors[close].red; + inst->pseudo_colors[i].green = icolors[close].green; + inst->pseudo_colors[i].blue = icolors[close].blue; + inst->pseudo_colors[i].pixel = icolors[close].pixel; + + /* try alloc this closest color, it had better succeed! */ + if (XAllocColor(inst->display, inst->colormap, + &inst->pseudo_colors[i])) + /* mark as alloced */ + inst->pseudo_colors[i].flags = DoRed|DoGreen|DoBlue; + else + /* wtf has gone wrong, its already alloced for chissake! */ + g_assert_not_reached(); + } + } +} + +void RrInstanceFree (RrInstance *inst) +{ + if (inst) { + if (inst == definst) definst = NULL; + g_free(inst->pseudo_colors); + } +} + +Display* RrDisplay (const RrInstance *inst) +{ + return (inst ? inst : definst)->display; +} + +gint RrScreen (const RrInstance *inst) +{ + return (inst ? inst : definst)->screen; +} + +Window RrRootWindow (const RrInstance *inst) +{ + return RootWindow (RrDisplay (inst), RrScreen (inst)); +} + +Visual *RrVisual (const RrInstance *inst) +{ + return (inst ? inst : definst)->visual; +} + +gint RrDepth (const RrInstance *inst) +{ + return (inst ? inst : definst)->depth; +} + +Colormap RrColormap (const RrInstance *inst) +{ + return (inst ? inst : definst)->colormap; +} + +gint RrRedOffset (const RrInstance *inst) +{ + return (inst ? inst : definst)->red_offset; +} + +gint RrGreenOffset (const RrInstance *inst) +{ + return (inst ? inst : definst)->green_offset; +} + +gint RrBlueOffset (const RrInstance *inst) +{ + return (inst ? inst : definst)->blue_offset; +} + +gint RrRedShift (const RrInstance *inst) +{ + return (inst ? inst : definst)->red_shift; +} + +gint RrGreenShift (const RrInstance *inst) +{ + return (inst ? inst : definst)->green_shift; +} + +gint RrBlueShift (const RrInstance *inst) +{ + return (inst ? inst : definst)->blue_shift; +} + +gint RrRedMask (const RrInstance *inst) +{ + return (inst ? inst : definst)->red_mask; +} + +gint RrGreenMask (const RrInstance *inst) +{ + return (inst ? inst : definst)->green_mask; +} + +gint RrBlueMask (const RrInstance *inst) +{ + return (inst ? inst : definst)->blue_mask; +} + +guint RrPseudoBPC (const RrInstance *inst) +{ + return (inst ? inst : definst)->pseudo_bpc; +} + +XColor *RrPseudoColors (const RrInstance *inst) +{ + return (inst ? inst : definst)->pseudo_colors; +} diff --git a/render/instance.h b/render/instance.h new file mode 100644 index 00000000..53e89d30 --- /dev/null +++ b/render/instance.h @@ -0,0 +1,31 @@ +#ifndef __render_instance_h +#define __render_instance_h + +#include +#include + +struct _RrInstance { + Display *display; + gint screen; + + Visual *visual; + gint depth; + Colormap colormap; + + gint red_offset; + gint green_offset; + gint blue_offset; + + gint red_shift; + gint green_shift; + gint blue_shift; + + gint red_mask; + gint green_mask; + gint blue_mask; + + gint pseudo_bpc; + XColor *pseudo_colors; +}; + +#endif diff --git a/render/mask.c b/render/mask.c index 22cb3fee..8b0f21c0 100644 --- a/render/mask.c +++ b/render/mask.c @@ -1,57 +1,63 @@ +#include "render.h" +#include "color.h" #include "mask.h" -#include "../kernel/openbox.h" -pixmap_mask *pixmap_mask_new(int w, int h, char *data) +RrPixmapMask *RrPixmapMaskNew(const RrInstance *inst, + gint w, gint h, const gchar *data) { - pixmap_mask *m = g_new(pixmap_mask, 1); - m->w = w; - m->h = h; + 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(ob_display, ob_root, data, w, h); + m->mask = XCreateBitmapFromData(RrDisplay(inst), RrRootWindow(inst), + data, w, h); return m; } -void pixmap_mask_free(pixmap_mask *m) +void RrPixmapMaskFree(RrPixmapMask *m) { if (m) { - XFreePixmap(ob_display, m->mask); + XFreePixmap(RrDisplay(m->inst), m->mask); g_free(m->data); g_free(m); } } -void mask_draw(Pixmap p, TextureMask *m, Rect *position) +void RrPixmapMaskDraw(Pixmap p, const RrTextureMask *m, const Rect *area) { int x, y; if (m->mask == None) return; /* no mask given */ /* set the clip region */ - x = position->x + (position->width - m->mask->w) / 2; - y = position->y + (position->height - m->mask->h) / 2; + 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(ob_display, m->color->gc, m->mask->mask); - XSetClipOrigin(ob_display, m->color->gc, x, y); + 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(ob_display, p, m->color->gc, x, y, - x + m->mask->w, y + m->mask->h); + XFillRectangle(RrDisplay(m->mask->inst), p, m->color->gc, x, y, + x + m->mask->width, y + m->mask->height); /* unset the clip region */ - XSetClipMask(ob_display, m->color->gc, None); - XSetClipOrigin(ob_display, m->color->gc, 0, 0); + XSetClipMask(RrDisplay(m->mask->inst), m->color->gc, None); + XSetClipOrigin(RrDisplay(m->mask->inst), m->color->gc, 0, 0); } -pixmap_mask *pixmap_mask_copy(pixmap_mask *src) +RrPixmapMask *RrPixmapMaskCopy(const RrPixmapMask *src) { - pixmap_mask *m = g_new(pixmap_mask, 1); - m->w = src->w; - m->h = src->h; + 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->w * src->h + 7) / 8); - m->mask = XCreateBitmapFromData(ob_display, ob_root, m->data, m->w, m->h); + 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; } diff --git a/render/mask.h b/render/mask.h index 9328daf1..b18baffc 100644 --- a/render/mask.h +++ b/render/mask.h @@ -4,9 +4,10 @@ #include "render.h" #include "kernel/geom.h" -pixmap_mask *pixmap_mask_new(int w, int h, char *data); -pixmap_mask *pixmap_mask_copy(pixmap_mask *src); -void pixmap_mask_free(pixmap_mask *m); -void mask_draw(Pixmap p, TextureMask *m, Rect *position); +RrPixmapMask *RrPixmapMaskNew(const RrInstance *inst, + gint w, gint h, const gchar *data); +void RrPixmapMaskFree(RrPixmapMask *m); +RrPixmapMask *RrPixmapMaskCopy(const RrPixmapMask *src); +void RrPixmapMaskDraw(Pixmap p, const RrTextureMask *m, const Rect *area); #endif diff --git a/render/render.c b/render/render.c index b2575c63..f2a0572f 100644 --- a/render/render.c +++ b/render/render.c @@ -1,7 +1,6 @@ #include #include -#include #include "render.h" #include "gradient.h" #include "font.h" @@ -9,157 +8,16 @@ #include "color.h" #include "image.h" #include "theme.h" -#include "kernel/openbox.h" + +#include #ifdef HAVE_STDLIB_H # include #endif -int render_depth; -XVisualInfo render_visual_info; - -Visual *render_visual; -Colormap render_colormap; - -int render_red_offset = 0, render_green_offset = 0, render_blue_offset = 0; -int render_red_shift, render_green_shift, render_blue_shift; -int render_red_mask, render_green_mask, render_blue_mask; - - -void render_startup(void) -{ - render_depth = DefaultDepth(ob_display, ob_screen); - render_visual = DefaultVisual(ob_display, ob_screen); - render_colormap = DefaultColormap(ob_display, ob_screen); - - switch (render_visual->class) { - case TrueColor: - truecolor_startup(); - break; - case PseudoColor: - case StaticColor: - case GrayScale: - case StaticGray: - pseudocolor_startup(); - break; - default: - g_critical("unsupported visual class.\n"); - exit(EXIT_FAILURE); - } -} - -void truecolor_startup(void) -{ - unsigned long red_mask, green_mask, blue_mask; - XImage *timage = NULL; - - timage = XCreateImage(ob_display, render_visual, render_depth, - ZPixmap, 0, NULL, 1, 1, 32, 0); - g_assert(timage != NULL); - /* find the offsets for each color in the visual's masks */ - render_red_mask = red_mask = timage->red_mask; - render_green_mask = green_mask = timage->green_mask; - render_blue_mask = blue_mask = timage->blue_mask; - - render_red_offset = 0; - render_green_offset = 0; - render_blue_offset = 0; - - while (! (red_mask & 1)) { render_red_offset++; red_mask >>= 1; } - while (! (green_mask & 1)) { render_green_offset++; green_mask >>= 1; } - while (! (blue_mask & 1)) { render_blue_offset++; blue_mask >>= 1; } - - render_red_shift = render_green_shift = render_blue_shift = 8; - while (red_mask) { red_mask >>= 1; render_red_shift--; } - while (green_mask) { green_mask >>= 1; render_green_shift--; } - while (blue_mask) { blue_mask >>= 1; render_blue_shift--; } - XFree(timage); -} +static void pixel32_to_pixmap(RrAppearance *l, gint x, gint y, gint w, gint h); -void pseudocolor_startup(void) -{ - XColor icolors[256]; - int tr, tg, tb, n, r, g, b, i, incolors, ii; - unsigned long dev; - int cpc, _ncolors; - g_message("Initializing PseudoColor RenderControl\n"); - - /* determine the number of colors and the bits-per-color */ - pseudo_bpc = 2; /* XXX THIS SHOULD BE A USER OPTION */ - g_assert(pseudo_bpc >= 1); - _ncolors = pseudo_ncolors(); - - if (_ncolors > 1 << render_depth) { - g_warning("PseudoRenderControl: Invalid colormap size. Resizing.\n"); - pseudo_bpc = 1 << (render_depth/3) >> 3; - _ncolors = 1 << (pseudo_bpc * 3); - } - - /* build a color cube */ - pseudo_colors = malloc(_ncolors * sizeof(XColor)); - cpc = 1 << pseudo_bpc; /* colors per channel */ - - for (n = 0, r = 0; r < cpc; r++) - for (g = 0; g < cpc; g++) - for (b = 0; b < cpc; b++, n++) { - tr = (int)(((float)(r)/(float)(cpc-1)) * 0xFF); - tg = (int)(((float)(g)/(float)(cpc-1)) * 0xFF); - tb = (int)(((float)(b)/(float)(cpc-1)) * 0xFF); - pseudo_colors[n].red = tr | tr << 8; - pseudo_colors[n].green = tg | tg << 8; - pseudo_colors[n].blue = tb | tb << 8; - pseudo_colors[n].flags = DoRed|DoGreen|DoBlue; /* used to track - allocation */ - } - - /* allocate the colors */ - for (i = 0; i < _ncolors; i++) - if (!XAllocColor(ob_display, render_colormap, &pseudo_colors[i])) - pseudo_colors[i].flags = 0; /* mark it as unallocated */ - - /* try allocate any colors that failed allocation above */ - - /* get the allocated values from the X server (only the first 256 XXX why!?) - */ - incolors = (((1 << render_depth) > 256) ? 256 : (1 << render_depth)); - for (i = 0; i < incolors; i++) - icolors[i].pixel = i; - XQueryColors(ob_display, render_colormap, icolors, incolors); - - /* try match unallocated ones */ - for (i = 0; i < _ncolors; i++) { - if (!pseudo_colors[i].flags) { /* if it wasn't allocated... */ - unsigned long closest = 0xffffffff, close = 0; - for (ii = 0; ii < incolors; ii++) { - /* find deviations */ - r = (pseudo_colors[i].red - icolors[ii].red) & 0xff; - g = (pseudo_colors[i].green - icolors[ii].green) & 0xff; - b = (pseudo_colors[i].blue - icolors[ii].blue) & 0xff; - /* find a weighted absolute deviation */ - dev = (r * r) + (g * g) + (b * b); - - if (dev < closest) { - closest = dev; - close = ii; - } - } - - pseudo_colors[i].red = icolors[close].red; - pseudo_colors[i].green = icolors[close].green; - pseudo_colors[i].blue = icolors[close].blue; - pseudo_colors[i].pixel = icolors[close].pixel; - - /* try alloc this closest color, it had better succeed! */ - if (XAllocColor(ob_display, render_colormap, &pseudo_colors[i])) - pseudo_colors[i].flags = DoRed|DoGreen|DoBlue; /* mark as alloced */ - else - g_assert(FALSE); /* wtf has gone wrong, its already alloced for - chissake! */ - } - } -} - -void paint(Window win, Appearance *l, int w, int h) +void RrPaint(RrAppearance *l, Window win, gint w, gint h) { int i, transferred = 0, sw; pixel32 *source, *dest; @@ -173,7 +31,9 @@ void paint(Window win, Appearance *l, int w, int h) if (resized) { oldp = l->pixmap; /* save to free after changing the visible pixmap */ - l->pixmap = XCreatePixmap(ob_display, ob_root, w, h, render_depth); + l->pixmap = XCreatePixmap(RrDisplay(l->inst), + RrRootWindow(l->inst), + w, h, RrDepth(l->inst)); } else oldp = None; @@ -183,14 +43,14 @@ void paint(Window win, Appearance *l, int w, int h) if (l->xftdraw != NULL) XftDrawDestroy(l->xftdraw); - l->xftdraw = XftDrawCreate(ob_display, l->pixmap, render_visual, - render_colormap); + l->xftdraw = XftDrawCreate(RrDisplay(l->inst), l->pixmap, + RrVisual(l->inst), RrColormap(l->inst)); g_assert(l->xftdraw != NULL); g_free(l->surface.pixel_data); l->surface.pixel_data = g_new(pixel32, w * h); - if (l->surface.grad == Background_ParentRelative) { + if (l->surface.grad == RR_SURFACE_PARENTREL) { g_assert (l->surface.parent); g_assert (l->surface.parent->w); @@ -201,20 +61,20 @@ void paint(Window win, Appearance *l, int w, int h) for (i = 0; i < h; i++, source += sw, dest += w) { memcpy(dest, source, w * sizeof(pixel32)); } - } - else if (l->surface.grad == Background_Solid) + } else if (l->surface.grad == RR_SURFACE_SOLID) gradient_solid(l, 0, 0, w, h); - else gradient_render(&l->surface, w, h); + else + gradient_render(&l->surface, w, h); RECT_SET(tarea, 0, 0, w, h); - if (l->surface.grad != Background_ParentRelative) { - if (l->surface.relief != Flat) { + if (l->surface.grad != RR_SURFACE_PARENTREL) { + if (l->surface.relief != RR_RELIEF_FLAT) { switch (l->surface.bevel) { - case Bevel1: + case RR_BEVEL_1: tarea.x += 1; tarea.y += 1; tarea.width -= 2; tarea.height -= 2; break; - case Bevel2: + case RR_BEVEL_2: tarea.x += 2; tarea.y += 2; tarea.width -= 4; tarea.height -= 4; break; @@ -227,33 +87,32 @@ void paint(Window win, Appearance *l, int w, int h) for (i = 0; i < l->textures; i++) { switch (l->texture[i].type) { - case NoTexture: + case RR_TEXTURE_NONE: break; - case Text: + case RR_TEXTURE_TEXT: if (!transferred) { transferred = 1; - if (l->surface.grad != Background_Solid) - pixel32_to_pixmap(l->surface.pixel_data, - l->pixmap, 0, 0, w, h); + if (l->surface.grad != RR_SURFACE_SOLID) + pixel32_to_pixmap(l, 0, 0, w, h); } if (l->xftdraw == NULL) { - l->xftdraw = XftDrawCreate(ob_display, l->pixmap, - render_visual, render_colormap); + l->xftdraw = XftDrawCreate(RrDisplay(l->inst), l->pixmap, + RrVisual(l->inst), + RrColormap(l->inst)); } font_draw(l->xftdraw, &l->texture[i].data.text, &tarea); break; - case Bitmask: + case RR_TEXTURE_MASK: if (!transferred) { transferred = 1; - if (l->surface.grad != Background_Solid) - pixel32_to_pixmap(l->surface.pixel_data, - l->pixmap, 0, 0, w, h); + if (l->surface.grad != RR_SURFACE_SOLID) + pixel32_to_pixmap(l, 0, 0, w, h); } 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, &tarea); + RrPixmapMaskDraw(l->pixmap, &l->texture[i].data.mask, &tarea); break; - case RGBA: + case RR_TEXTURE_RGBA: image_draw(l->surface.pixel_data, &l->texture[i].data.rgba, &tarea); break; @@ -262,47 +121,34 @@ void paint(Window win, Appearance *l, int w, int h) if (!transferred) { transferred = 1; - if (l->surface.grad != Background_Solid) - pixel32_to_pixmap(l->surface.pixel_data, l->pixmap, 0, 0, w, h); + if (l->surface.grad != RR_SURFACE_SOLID) + pixel32_to_pixmap(l, 0, 0, w, h); } - XSetWindowBackgroundPixmap(ob_display, win, l->pixmap); - XClearWindow(ob_display, win); - if (oldp) XFreePixmap(ob_display, oldp); + XSetWindowBackgroundPixmap(RrDisplay(l->inst), win, l->pixmap); + XClearWindow(RrDisplay(l->inst), win); + if (oldp) XFreePixmap(RrDisplay(l->inst), oldp); } -void render_shutdown(void) +RrAppearance *RrAppearanceNew(const RrInstance *inst, gint numtex) { -} + RrAppearance *out; -Appearance *appearance_new(int numtex) -{ - Surface *p; - Appearance *out; - - out = g_new(Appearance, 1); + out = g_new0(RrAppearance, 1); + out->inst = inst; out->textures = numtex; - out->xftdraw = NULL; - if (numtex) out->texture = g_new0(Texture, numtex); - else out->texture = NULL; - out->pixmap = None; - out->w = out->h = 0; - - p = &out->surface; - p->primary = NULL; - p->secondary = NULL; - p->border_color = NULL; - p->bevel_dark = NULL; - p->bevel_light = NULL; - p->pixel_data = NULL; + if (numtex) out->texture = g_new0(RrTexture, numtex); + return out; } -Appearance *appearance_copy(Appearance *orig) +RrAppearance *RrAppearanceCopy(RrAppearance *orig) { - Surface *spo, *spc; - Appearance *copy = g_new(Appearance, 1); + RrSurface *spo, *spc; + RrAppearance *copy = g_new(RrAppearance, 1); + + copy->inst = orig->inst; spo = &(orig->surface); spc = &(copy->surface); @@ -310,33 +156,38 @@ Appearance *appearance_copy(Appearance *orig) spc->relief = spo->relief; spc->bevel = spo->bevel; if (spo->primary != NULL) - spc->primary = color_new(spo->primary->r, - spo->primary->g, - spo->primary->b); + spc->primary = RrColorNew(copy->inst, + spo->primary->r, + spo->primary->g, + spo->primary->b); else spc->primary = NULL; if (spo->secondary != NULL) - spc->secondary = color_new(spo->secondary->r, - spo->secondary->g, - spo->secondary->b); + spc->secondary = RrColorNew(copy->inst, + spo->secondary->r, + spo->secondary->g, + spo->secondary->b); else spc->secondary = NULL; if (spo->border_color != NULL) - spc->border_color = color_new(spo->border_color->r, - spo->border_color->g, - spo->border_color->b); + spc->border_color = RrColorNew(copy->inst, + spo->border_color->r, + spo->border_color->g, + spo->border_color->b); else spc->border_color = NULL; if (spo->bevel_dark != NULL) - spc->bevel_dark = color_new(spo->bevel_dark->r, - spo->bevel_dark->g, - spo->bevel_dark->b); + spc->bevel_dark = RrColorNew(copy->inst, + spo->bevel_dark->r, + spo->bevel_dark->g, + spo->bevel_dark->b); else spc->bevel_dark = NULL; if (spo->bevel_light != NULL) - spc->bevel_light = color_new(spo->bevel_light->r, - spo->bevel_light->g, - spo->bevel_light->b); + spc->bevel_light = RrColorNew(copy->inst, + spo->bevel_light->r, + spo->bevel_light->g, + spo->bevel_light->b); else spc->bevel_light = NULL; spc->interlaced = spo->interlaced; @@ -344,27 +195,28 @@ Appearance *appearance_copy(Appearance *orig) spc->pixel_data = NULL; copy->textures = orig->textures; - copy->texture = g_memdup(orig->texture, orig->textures * sizeof(Texture)); + copy->texture = g_memdup(orig->texture, + orig->textures * sizeof(RrTexture)); copy->pixmap = None; copy->xftdraw = NULL; copy->w = copy->h = 0; return copy; } -void appearance_free(Appearance *a) +void RrAppearanceFree(RrAppearance *a) { if (a) { - Surface *p; - if (a->pixmap != None) XFreePixmap(ob_display, a->pixmap); + RrSurface *p; + if (a->pixmap != None) XFreePixmap(RrDisplay(a->inst), a->pixmap); if (a->xftdraw != NULL) XftDrawDestroy(a->xftdraw); if (a->textures) g_free(a->texture); p = &a->surface; - color_free(p->primary); - color_free(p->secondary); - color_free(p->border_color); - color_free(p->bevel_dark); - color_free(p->bevel_light); + RrColorFree(p->primary); + RrColorFree(p->secondary); + RrColorFree(p->border_color); + RrColorFree(p->bevel_dark); + RrColorFree(p->bevel_light); g_free(p->pixel_data); g_free(a); @@ -372,40 +224,48 @@ void appearance_free(Appearance *a) } -void pixel32_to_pixmap(pixel32 *in, Pixmap out, int x, int y, int w, int h) +static void pixel32_to_pixmap(RrAppearance *l, gint x, gint y, gint w, gint h) { - pixel32 *scratch; + pixel32 *in, *scratch; + Pixmap out; XImage *im = NULL; - im = XCreateImage(ob_display, render_visual, render_depth, + im = XCreateImage(RrDisplay(l->inst), RrVisual(l->inst), RrDepth(l->inst), ZPixmap, 0, NULL, w, h, 32, 0); g_assert(im != NULL); + + in = l->surface.pixel_data; + out = l->pixmap; + im->byte_order = render_endian; /* this malloc is a complete waste of time on normal 32bpp as reduce_depth just sets im->data = data and returns */ scratch = g_new(pixel32, im->width * im->height); im->data = (char*) scratch; - reduce_depth(in, im); - XPutImage(ob_display, out, DefaultGC(ob_display, ob_screen), + reduce_depth(l->inst, in, im); + XPutImage(RrDisplay(l->inst), out, + DefaultGC(RrDisplay(l->inst), RrScreen(l->inst)), im, 0, 0, x, y, w, h); im->data = NULL; XDestroyImage(im); g_free(scratch); } -void appearance_minsize(Appearance *l, int *w, int *h) +void RrMinsize(RrAppearance *l, gint *w, gint *h) { - int i; - int m; + gint i; + gint m; *w = *h = 0; for (i = 0; i < l->textures; ++i) { switch (l->texture[i].type) { - case Bitmask: - *w = MAX(*w, l->texture[i].data.mask.mask->w); - *h = MAX(*h, l->texture[i].data.mask.mask->h); + case RR_TEXTURE_NONE: + break; + case RR_TEXTURE_MASK: + *w = MAX(*w, l->texture[i].data.mask.mask->width); + *h = MAX(*h, l->texture[i].data.mask.mask->height); break; - case Text: + case RR_TEXTURE_TEXT: m = font_measure_string(l->texture[i].data.text.font, l->texture[i].data.text.string, l->texture[i].data.text.shadow, @@ -416,22 +276,20 @@ void appearance_minsize(Appearance *l, int *w, int *h) l->texture[i].data.text.offset); *h += MAX(*h, m); break; - case RGBA: + case RR_TEXTURE_RGBA: *w += MAX(*w, l->texture[i].data.rgba.width); *h += MAX(*h, l->texture[i].data.rgba.height); break; - case NoTexture: - break; } } - if (l->surface.relief != Flat) { + if (l->surface.relief != RR_RELIEF_FLAT) { switch (l->surface.bevel) { - case Bevel1: + case RR_BEVEL_1: *w += 2; *h += 2; break; - case Bevel2: + case RR_BEVEL_2: *w += 4; *h += 4; break; @@ -445,35 +303,40 @@ void appearance_minsize(Appearance *l, int *w, int *h) if (*h < 1) *h = 1; } -gboolean render_pixmap_to_rgba(Pixmap pmap, Pixmap mask, - int *w, int *h, pixel32 **data) +gboolean RrPixmapToRGBA(const RrInstance *inst, + Pixmap pmap, Pixmap mask, + gint *w, gint *h, pixel32 **data) { Window xr; - int xx, xy; + gint xx, xy; guint pw, ph, mw, mh, xb, xd, i, x, y, di; XImage *xi, *xm = NULL; - if (!XGetGeometry(ob_display, pmap, &xr, &xx, &xy, &pw, &ph, &xb, &xd)) + if (!XGetGeometry(RrDisplay(inst), + pmap, &xr, &xx, &xy, &pw, &ph, &xb, &xd)) return FALSE; if (mask) { - if (!XGetGeometry(ob_display, mask, &xr, &xx, &xy, &mw, &mh, &xb, &xd)) + if (!XGetGeometry(RrDisplay(inst), mask, + &xr, &xx, &xy, &mw, &mh, &xb, &xd)) return FALSE; if (pw != mw || ph != mh || xd != 1) return FALSE; } - xi = XGetImage(ob_display, pmap, 0, 0, pw, ph, 0xffffffff, ZPixmap); + xi = XGetImage(RrDisplay(inst), pmap, + 0, 0, pw, ph, 0xffffffff, ZPixmap); if (!xi) return FALSE; if (mask) { - xm = XGetImage(ob_display, mask, 0, 0, mw, mh, 0xffffffff, ZPixmap); + xm = XGetImage(RrDisplay(inst), mask, + 0, 0, mw, mh, 0xffffffff, ZPixmap); if (!xm) return FALSE; } *data = g_new(pixel32, pw * ph); - increase_depth(*data, xi); + increase_depth(inst, *data, xi); if (mask) { /* apply transparency from the mask */ diff --git a/render/render.h b/render/render.h index 31e62ee7..c6bd3556 100644 --- a/render/render.h +++ b/render/render.h @@ -1,49 +1,67 @@ #ifndef __render_h #define __render_h -#include #define _XFT_NO_COMPAT_ /* no Xft 1 API */ #include +#include #include -#include "color.h" -#include "kernel/geom.h" + +typedef union _RrTextureData RrTextureData; +typedef struct _RrAppearance RrAppearance; +typedef struct _RrSurface RrSurface; +typedef struct _RrFont RrFont; +typedef struct _RrTexture RrTexture; +typedef struct _RrTextureMask RrTextureMask; +typedef struct _RrTextureRGBA RrTextureRGBA; +typedef struct _RrTextureText RrTextureText; +typedef struct _RrPixmapMask RrPixmapMask; +typedef struct _RrInstance RrInstance; +typedef struct _RrColor color_rgb; /* XXX ugly */ + +typedef guint32 pixel32; /* XXX prefix */ +typedef guint16 pixel16; typedef enum { - Flat, - Raised, - Sunken -} ReliefType; + RR_RELIEF_FLAT, + RR_RELIEF_RAISED, + RR_RELIEF_SUNKEN +} RrReliefType; typedef enum { - Bevel1, - Bevel2 -} BevelType; + RR_BEVEL_1, + RR_BEVEL_2 +} RrBevelType; typedef enum { - Background_ParentRelative, - Background_Solid, - Background_Horizontal, - Background_Vertical, - Background_Diagonal, - Background_CrossDiagonal, - Background_PipeCross, - Background_Rectangle, - Background_Pyramid -} SurfaceColorType; + RR_SURFACE_NONE, + RR_SURFACE_PARENTREL, + RR_SURFACE_SOLID, + RR_SURFACE_HORIZONTAL, + RR_SURFACE_VERTICAL, + RR_SURFACE_DIAGONAL, + RR_SURFACE_CROSS_DIAGONAL, + RR_SURFACE_PIPECROSS, + RR_SURFACE_RECTANGLE, + RR_SURFACE_PYRAMID +} RrSurfaceColorType; typedef enum { - Bitmask, - Text, - RGBA, - NoTexture -} TextureType; - -struct Appearance; - -typedef struct Surface { - SurfaceColorType grad; - ReliefType relief; - BevelType bevel; + RR_TEXTURE_NONE, + RR_TEXTURE_MASK, + RR_TEXTURE_TEXT, + RR_TEXTURE_RGBA +} RrTextureType; + +typedef enum { + RR_JUSTIFY_LEFT, + RR_JUSTIFY_CENTER, + RR_JUSTIFY_RIGHT +} RrJustify; + +struct _RrSurface { + RrSurfaceColorType grad; + RrReliefType relief; + RrBevelType bevel; color_rgb *primary; color_rgb *secondary; color_rgb *border_color; @@ -51,95 +69,103 @@ typedef struct Surface { color_rgb *bevel_light; gboolean interlaced; gboolean border; - struct Appearance *parent; - int parentx; - int parenty; + RrAppearance *parent; + gint parentx; + gint parenty; pixel32 *pixel_data; -} Surface; - -typedef struct { - XftFont *xftfont; - int elipses_length; -} ObFont; - -typedef enum { - Justify_Center, - Justify_Left, - Justify_Right -} Justify; - -typedef struct TextureText { - ObFont *font; - Justify justify; - int shadow; - char tint; - unsigned char offset; +}; + +struct _RrTextureText { + RrFont *font; + RrJustify justify; + gint shadow; + gchar tint; + guchar offset; color_rgb *color; - char *string; -} TextureText; + gchar *string; +}; -typedef struct { +struct _RrPixmapMask { + const RrInstance *inst; Pixmap mask; - guint w, h; - char *data; -} pixmap_mask; + gint width; + gint height; + gchar *data; +}; -typedef struct TextureMask { +struct _RrTextureMask { color_rgb *color; - pixmap_mask *mask; -} TextureMask; + RrPixmapMask *mask; +}; -typedef struct TextureRGBA { - guint width; - guint height; +struct _RrTextureRGBA { + gint width; + gint height; pixel32 *data; /* cached scaled so we don't have to scale often */ - guint cwidth; - guint cheight; + gint cwidth; + gint cheight; pixel32 *cache; -} TextureRGBA; - -typedef union { - TextureRGBA rgba; - TextureText text; - TextureMask mask; -} TextureData; - -typedef struct Texture { - TextureType type; - TextureData data; -} Texture; - -typedef struct Appearance { - Surface surface; - int textures; - Texture *texture; +}; + +union _RrTextureData { + RrTextureRGBA rgba; + RrTextureText text; + RrTextureMask mask; +}; + +struct _RrTexture { + RrTextureType type; + RrTextureData data; +}; + +struct _RrAppearance { + const RrInstance *inst; + + RrSurface surface; + gint textures; + RrTexture *texture; Pixmap pixmap; XftDraw *xftdraw; /* cached for internal use */ - int w, h; -} Appearance; - -extern Visual *render_visual; -extern XVisualInfo render_visual_info; -extern int render_depth; -extern Colormap render_colormap; - -void render_startup(void); -void init_appearance(Appearance *l); -void paint(Window win, Appearance *l, int w, int h); -void render_shutdown(void); -Appearance *appearance_new(int numtex); -Appearance *appearance_copy(Appearance *a); -void appearance_free(Appearance *a); -void truecolor_startup(void); -void pseudocolor_startup(void); -void pixel32_to_pixmap(pixel32 *in, Pixmap out, int x, int y, int w, int h); - -void appearance_minsize(Appearance *l, int *w, int *h); - -gboolean render_pixmap_to_rgba(Pixmap pmap, Pixmap mask, - int *w, int *h, pixel32 **data); + gint w, h; +}; + +RrInstance* RrInstanceNew (Display *display, gint screen); +void RrInstanceFree (RrInstance *inst); + +Display* RrDisplay (const RrInstance *inst); +gint RrScreen (const RrInstance *inst); +Window RrRootWindow (const RrInstance *inst); +Visual* RrVisual (const RrInstance *inst); +gint RrDepth (const RrInstance *inst); +Colormap RrColormap (const RrInstance *inst); +gint RrRedOffset (const RrInstance *inst); +gint RrGreenOffset (const RrInstance *inst); +gint RrBlueOffset (const RrInstance *inst); +gint RrRedShift (const RrInstance *inst); +gint RrGreenShift (const RrInstance *inst); +gint RrBlueShift (const RrInstance *inst); +gint RrRedMask (const RrInstance *inst); +gint RrGreenMask (const RrInstance *inst); +gint RrBlueMask (const RrInstance *inst); +guint RrPseudoBPC (const RrInstance *inst); +XColor* RrPseudoColors (const RrInstance *inst); + +color_rgb *RrColorNew (const RrInstance *inst, gint r, gint g, gint b); +color_rgb *RrColorParse (const RrInstance *inst, gchar *colorname); +void RrColorFree (color_rgb *in); + +RrAppearance *RrAppearanceNew (const RrInstance *inst, gint numtex); +RrAppearance *RrAppearanceCopy (RrAppearance *a); +void RrAppearanceFree (RrAppearance *a); + +void RrPaint (RrAppearance *l, Window win, gint w, gint h); +void RrMinsize (RrAppearance *l, gint *w, gint *h); + +gboolean RrPixmapToRGBA(const RrInstance *inst, + Pixmap pmap, Pixmap mask, + gint *w, gint *h, pixel32 **data); #endif /*__render_h*/ diff --git a/render/test.c b/render/test.c index 9ae7eada..38cd7a99 100644 --- a/render/test.c +++ b/render/test.c @@ -21,7 +21,8 @@ Window ob_root; int main() { Window win; - Appearance *look; + RrInstance *inst; + RrAppearance *look; Window root; XEvent report; @@ -42,32 +43,35 @@ int main() XMapWindow(ob_display, win); XSelectInput(ob_display, win, ExposureMask | StructureNotifyMask); root = RootWindow (ob_display, DefaultScreen (ob_display)); - render_startup(); + inst = RrInstanceNew(ob_display, ob_screen); - look = appearance_new(0); - look->surface.grad = Background_Pyramid; - look->surface.secondary = color_parse("Yellow"); - look->surface.primary = color_parse("Blue"); + look = RrAppearanceNew(inst, 0); + look->surface.grad = RR_SURFACE_PYRAMID; + look->surface.secondary = RrColorParse(inst, "Yellow"); + look->surface.primary = RrColorParse(inst, "Blue"); look->surface.interlaced = FALSE; if (ob_display == NULL) { fprintf(stderr, "couldn't connect to X server :0\n"); return 0; } - paint(win, look, w, h); + RrPaint(look, win, w, h); while (1) { XNextEvent(ob_display, &report); switch (report.type) { case Expose: break; case ConfigureNotify: - paint(win, look, - report.xconfigure.width, - report.xconfigure.height); + RrPaint(look, win, + report.xconfigure.width, + report.xconfigure.height); break; } } + RrAppearanceFree (look); + RrInstanceFree (inst); + return 1; } diff --git a/render/theme.c b/render/theme.c index 12e54377..d2456672 100644 --- a/render/theme.c +++ b/render/theme.c @@ -7,10 +7,10 @@ #include /* style settings - geometry */ -int theme_bevel; -int theme_handle_height; -int theme_bwidth; -int theme_cbwidth; +gint theme_bevel; +gint theme_handle_height; +gint theme_bwidth; +gint theme_cbwidth; /* style settings - colors */ color_rgb *theme_b_color; color_rgb *theme_cb_focused_color; @@ -24,83 +24,87 @@ color_rgb *theme_menu_color; color_rgb *theme_menu_disabled_color; color_rgb *theme_menu_hilite_color; /* style settings - fonts */ -int theme_winfont_height; -ObFont *theme_winfont; +gint theme_winfont_height; +RrFont *theme_winfont; gboolean theme_winfont_shadow; -int theme_winfont_shadow_offset; -int theme_winfont_shadow_tint; -int theme_mtitlefont_height; -ObFont *theme_mtitlefont; +gint theme_winfont_shadow_offset; +gint theme_winfont_shadow_tint; +gint theme_mtitlefont_height; +RrFont *theme_mtitlefont; gboolean theme_mtitlefont_shadow; -int theme_mtitlefont_shadow_offset; -int theme_mtitlefont_shadow_tint; -int theme_mfont_height; -ObFont *theme_mfont; +gint theme_mtitlefont_shadow_offset; +gint theme_mtitlefont_shadow_tint; +gint theme_mfont_height; +RrFont *theme_mfont; gboolean theme_mfont_shadow; -int theme_mfont_shadow_offset; -int theme_mfont_shadow_tint; +gint theme_mfont_shadow_offset; +gint theme_mfont_shadow_tint; /* style settings - title layout */ -char *theme_title_layout; +gchar *theme_title_layout; /* style settings - masks */ -pixmap_mask *theme_max_set_mask; -pixmap_mask *theme_max_unset_mask; -pixmap_mask *theme_iconify_mask; -pixmap_mask *theme_desk_set_mask; -pixmap_mask *theme_desk_unset_mask; -pixmap_mask *theme_shade_set_mask; -pixmap_mask *theme_shade_unset_mask; -pixmap_mask *theme_close_mask; +RrPixmapMask *theme_max_set_mask; +RrPixmapMask *theme_max_unset_mask; +RrPixmapMask *theme_iconify_mask; +RrPixmapMask *theme_desk_set_mask; +RrPixmapMask *theme_desk_unset_mask; +RrPixmapMask *theme_shade_set_mask; +RrPixmapMask *theme_shade_unset_mask; +RrPixmapMask *theme_close_mask; /* global appearances */ -Appearance *theme_a_focused_unpressed_max; -Appearance *theme_a_focused_pressed_max; -Appearance *theme_a_focused_pressed_set_max; -Appearance *theme_a_unfocused_unpressed_max; -Appearance *theme_a_unfocused_pressed_max; -Appearance *theme_a_unfocused_pressed_set_max; -Appearance *theme_a_focused_unpressed_close; -Appearance *theme_a_focused_pressed_close; -Appearance *theme_a_unfocused_unpressed_close; -Appearance *theme_a_unfocused_pressed_close; -Appearance *theme_a_focused_unpressed_desk; -Appearance *theme_a_focused_pressed_desk; -Appearance *theme_a_focused_pressed_set_desk; -Appearance *theme_a_unfocused_unpressed_desk; -Appearance *theme_a_unfocused_pressed_desk; -Appearance *theme_a_unfocused_pressed_set_desk; -Appearance *theme_a_focused_unpressed_shade; -Appearance *theme_a_focused_pressed_shade; -Appearance *theme_a_focused_pressed_set_shade; -Appearance *theme_a_unfocused_unpressed_shade; -Appearance *theme_a_unfocused_pressed_shade; -Appearance *theme_a_unfocused_pressed_set_shade; -Appearance *theme_a_focused_unpressed_iconify; -Appearance *theme_a_focused_pressed_iconify; -Appearance *theme_a_unfocused_unpressed_iconify; -Appearance *theme_a_unfocused_pressed_iconify; -Appearance *theme_a_focused_grip; -Appearance *theme_a_unfocused_grip; -Appearance *theme_a_focused_title; -Appearance *theme_a_unfocused_title; -Appearance *theme_a_focused_label; -Appearance *theme_a_unfocused_label; -Appearance *theme_a_icon; /* always parentrelative, so no focused/unfocused */ -Appearance *theme_a_focused_handle; -Appearance *theme_a_unfocused_handle; -Appearance *theme_a_menu_title; -Appearance *theme_a_menu; -Appearance *theme_a_menu_item; -Appearance *theme_a_menu_disabled; -Appearance *theme_a_menu_hilite; - -Appearance *theme_app_hilite_bg; -Appearance *theme_app_unhilite_bg; -Appearance *theme_app_hilite_label; -Appearance *theme_app_unhilite_label; -Appearance *theme_app_icon; - -void theme_startup() +RrAppearance *theme_a_focused_unpressed_max; +RrAppearance *theme_a_focused_pressed_max; +RrAppearance *theme_a_focused_pressed_set_max; +RrAppearance *theme_a_unfocused_unpressed_max; +RrAppearance *theme_a_unfocused_pressed_max; +RrAppearance *theme_a_unfocused_pressed_set_max; +RrAppearance *theme_a_focused_unpressed_close; +RrAppearance *theme_a_focused_pressed_close; +RrAppearance *theme_a_unfocused_unpressed_close; +RrAppearance *theme_a_unfocused_pressed_close; +RrAppearance *theme_a_focused_unpressed_desk; +RrAppearance *theme_a_focused_pressed_desk; +RrAppearance *theme_a_focused_pressed_set_desk; +RrAppearance *theme_a_unfocused_unpressed_desk; +RrAppearance *theme_a_unfocused_pressed_desk; +RrAppearance *theme_a_unfocused_pressed_set_desk; +RrAppearance *theme_a_focused_unpressed_shade; +RrAppearance *theme_a_focused_pressed_shade; +RrAppearance *theme_a_focused_pressed_set_shade; +RrAppearance *theme_a_unfocused_unpressed_shade; +RrAppearance *theme_a_unfocused_pressed_shade; +RrAppearance *theme_a_unfocused_pressed_set_shade; +RrAppearance *theme_a_focused_unpressed_iconify; +RrAppearance *theme_a_focused_pressed_iconify; +RrAppearance *theme_a_unfocused_unpressed_iconify; +RrAppearance *theme_a_unfocused_pressed_iconify; +RrAppearance *theme_a_focused_grip; +RrAppearance *theme_a_unfocused_grip; +RrAppearance *theme_a_focused_title; +RrAppearance *theme_a_unfocused_title; +RrAppearance *theme_a_focused_label; +RrAppearance *theme_a_unfocused_label; +RrAppearance *theme_a_icon; /* always parentrelative, so no focused/unfocused */ +RrAppearance *theme_a_focused_handle; +RrAppearance *theme_a_unfocused_handle; +RrAppearance *theme_a_menu_title; +RrAppearance *theme_a_menu; +RrAppearance *theme_a_menu_item; +RrAppearance *theme_a_menu_disabled; +RrAppearance *theme_a_menu_hilite; + +RrAppearance *theme_app_hilite_bg; +RrAppearance *theme_app_unhilite_bg; +RrAppearance *theme_app_hilite_label; +RrAppearance *theme_app_unhilite_label; +RrAppearance *theme_app_icon; + +static const RrInstance *theme_inst = NULL; + +void theme_startup(const RrInstance *inst) { + theme_inst = inst; + theme_b_color = theme_cb_unfocused_color = theme_cb_focused_color = theme_title_unfocused_color = theme_title_focused_color = theme_titlebut_unfocused_color = theme_titlebut_focused_color = @@ -113,12 +117,12 @@ void theme_startup() theme_shade_set_mask = theme_shade_unset_mask = NULL; theme_iconify_mask = theme_close_mask = NULL; - theme_a_focused_unpressed_max = appearance_new(1); - theme_a_focused_pressed_max = appearance_new(1); - theme_a_focused_pressed_set_max = appearance_new(1); - theme_a_unfocused_unpressed_max = appearance_new(1); - theme_a_unfocused_pressed_max = appearance_new(1); - theme_a_unfocused_pressed_set_max = appearance_new(1); + theme_a_focused_unpressed_max = RrAppearanceNew(inst, 1); + theme_a_focused_pressed_max = RrAppearanceNew(inst, 1); + theme_a_focused_pressed_set_max = RrAppearanceNew(inst, 1); + theme_a_unfocused_unpressed_max = RrAppearanceNew(inst, 1); + theme_a_unfocused_pressed_max = RrAppearanceNew(inst, 1); + theme_a_unfocused_pressed_set_max = RrAppearanceNew(inst, 1); theme_a_focused_unpressed_close = NULL; theme_a_focused_pressed_close = NULL; theme_a_unfocused_unpressed_close = NULL; @@ -139,51 +143,51 @@ void theme_startup() theme_a_focused_pressed_iconify = NULL; theme_a_unfocused_unpressed_iconify = NULL; theme_a_unfocused_pressed_iconify = NULL; - theme_a_focused_grip = appearance_new(0); - theme_a_unfocused_grip = appearance_new(0); - theme_a_focused_title = appearance_new(0); - theme_a_unfocused_title = appearance_new(0); - theme_a_focused_label = appearance_new(1); - theme_a_unfocused_label = appearance_new(1); - theme_a_icon = appearance_new(1); - theme_a_focused_handle = appearance_new(0); - theme_a_unfocused_handle = appearance_new(0); - theme_a_menu = appearance_new(0); - theme_a_menu_title = appearance_new(1); - theme_a_menu_item = appearance_new(1); - theme_a_menu_disabled = appearance_new(1); - theme_a_menu_hilite = appearance_new(1); - - theme_app_hilite_bg = appearance_new(0); - theme_app_unhilite_bg = appearance_new(0); - theme_app_hilite_label = appearance_new(1); - theme_app_unhilite_label = appearance_new(1); - theme_app_icon = appearance_new(1); + theme_a_focused_grip = RrAppearanceNew(inst, 0); + theme_a_unfocused_grip = RrAppearanceNew(inst, 0); + theme_a_focused_title = RrAppearanceNew(inst, 0); + theme_a_unfocused_title = RrAppearanceNew(inst, 0); + theme_a_focused_label = RrAppearanceNew(inst, 1); + theme_a_unfocused_label = RrAppearanceNew(inst, 1); + theme_a_icon = RrAppearanceNew(inst, 1); + theme_a_focused_handle = RrAppearanceNew(inst, 0); + theme_a_unfocused_handle = RrAppearanceNew(inst, 0); + theme_a_menu = RrAppearanceNew(inst, 0); + theme_a_menu_title = RrAppearanceNew(inst, 1); + theme_a_menu_item = RrAppearanceNew(inst, 1); + theme_a_menu_disabled = RrAppearanceNew(inst, 1); + theme_a_menu_hilite = RrAppearanceNew(inst, 1); + + theme_app_hilite_bg = RrAppearanceNew(inst, 0); + theme_app_unhilite_bg = RrAppearanceNew(inst, 0); + theme_app_hilite_label = RrAppearanceNew(inst, 1); + theme_app_unhilite_label = RrAppearanceNew(inst, 1); + theme_app_icon = RrAppearanceNew(inst, 1); } void theme_shutdown() { - color_free(theme_b_color); - color_free(theme_cb_unfocused_color); - color_free(theme_cb_focused_color); - color_free(theme_title_unfocused_color); - color_free(theme_title_focused_color); - color_free(theme_titlebut_unfocused_color); - color_free(theme_titlebut_focused_color); - color_free(theme_menu_color); - color_free(theme_menu_title_color); - color_free(theme_menu_disabled_color); - color_free(theme_menu_hilite_color); - - pixmap_mask_free(theme_max_set_mask); - pixmap_mask_free(theme_max_unset_mask); - pixmap_mask_free(theme_desk_set_mask); - pixmap_mask_free(theme_desk_unset_mask); - pixmap_mask_free(theme_shade_set_mask); - pixmap_mask_free(theme_shade_unset_mask); - pixmap_mask_free(theme_iconify_mask); - pixmap_mask_free(theme_close_mask); + RrColorFree(theme_b_color); + RrColorFree(theme_cb_unfocused_color); + RrColorFree(theme_cb_focused_color); + RrColorFree(theme_title_unfocused_color); + RrColorFree(theme_title_focused_color); + RrColorFree(theme_titlebut_unfocused_color); + RrColorFree(theme_titlebut_focused_color); + RrColorFree(theme_menu_color); + RrColorFree(theme_menu_title_color); + RrColorFree(theme_menu_disabled_color); + RrColorFree(theme_menu_hilite_color); + + RrPixmapMaskFree(theme_max_set_mask); + RrPixmapMaskFree(theme_max_unset_mask); + RrPixmapMaskFree(theme_desk_set_mask); + RrPixmapMaskFree(theme_desk_unset_mask); + RrPixmapMaskFree(theme_shade_set_mask); + RrPixmapMaskFree(theme_shade_unset_mask); + RrPixmapMaskFree(theme_iconify_mask); + RrPixmapMaskFree(theme_close_mask); font_close(theme_winfont); font_close(theme_mtitlefont); @@ -191,47 +195,47 @@ void theme_shutdown() g_free(theme_title_layout); - appearance_free(theme_a_focused_unpressed_max); - appearance_free(theme_a_focused_pressed_max); - appearance_free(theme_a_focused_pressed_set_max); - appearance_free(theme_a_unfocused_unpressed_max); - appearance_free(theme_a_unfocused_pressed_max); - appearance_free(theme_a_unfocused_pressed_set_max); - appearance_free(theme_a_focused_unpressed_close); - appearance_free(theme_a_focused_pressed_close); - appearance_free(theme_a_unfocused_unpressed_close); - appearance_free(theme_a_unfocused_pressed_close); - appearance_free(theme_a_focused_unpressed_desk); - appearance_free(theme_a_focused_pressed_desk); - appearance_free(theme_a_unfocused_unpressed_desk); - appearance_free(theme_a_unfocused_pressed_desk); - appearance_free(theme_a_focused_unpressed_shade); - appearance_free(theme_a_focused_pressed_shade); - appearance_free(theme_a_unfocused_unpressed_shade); - appearance_free(theme_a_unfocused_pressed_shade); - appearance_free(theme_a_focused_unpressed_iconify); - appearance_free(theme_a_focused_pressed_iconify); - appearance_free(theme_a_unfocused_unpressed_iconify); - appearance_free(theme_a_unfocused_pressed_iconify); - appearance_free(theme_a_focused_grip); - appearance_free(theme_a_unfocused_grip); - appearance_free(theme_a_focused_title); - appearance_free(theme_a_unfocused_title); - appearance_free(theme_a_focused_label); - appearance_free(theme_a_unfocused_label); - appearance_free(theme_a_icon); - appearance_free(theme_a_focused_handle); - appearance_free(theme_a_unfocused_handle); - appearance_free(theme_a_menu); - appearance_free(theme_a_menu_title); - appearance_free(theme_a_menu_item); - appearance_free(theme_a_menu_disabled); - appearance_free(theme_a_menu_hilite); - appearance_free(theme_app_hilite_bg); - appearance_free(theme_app_unhilite_bg); - appearance_free(theme_app_hilite_label); - appearance_free(theme_app_unhilite_label); - appearance_free(theme_app_icon); + RrAppearanceFree(theme_a_focused_unpressed_max); + RrAppearanceFree(theme_a_focused_pressed_max); + RrAppearanceFree(theme_a_focused_pressed_set_max); + RrAppearanceFree(theme_a_unfocused_unpressed_max); + RrAppearanceFree(theme_a_unfocused_pressed_max); + RrAppearanceFree(theme_a_unfocused_pressed_set_max); + RrAppearanceFree(theme_a_focused_unpressed_close); + RrAppearanceFree(theme_a_focused_pressed_close); + RrAppearanceFree(theme_a_unfocused_unpressed_close); + RrAppearanceFree(theme_a_unfocused_pressed_close); + RrAppearanceFree(theme_a_focused_unpressed_desk); + RrAppearanceFree(theme_a_focused_pressed_desk); + RrAppearanceFree(theme_a_unfocused_unpressed_desk); + RrAppearanceFree(theme_a_unfocused_pressed_desk); + RrAppearanceFree(theme_a_focused_unpressed_shade); + RrAppearanceFree(theme_a_focused_pressed_shade); + RrAppearanceFree(theme_a_unfocused_unpressed_shade); + RrAppearanceFree(theme_a_unfocused_pressed_shade); + RrAppearanceFree(theme_a_focused_unpressed_iconify); + RrAppearanceFree(theme_a_focused_pressed_iconify); + RrAppearanceFree(theme_a_unfocused_unpressed_iconify); + RrAppearanceFree(theme_a_unfocused_pressed_iconify); + RrAppearanceFree(theme_a_focused_grip); + RrAppearanceFree(theme_a_unfocused_grip); + RrAppearanceFree(theme_a_focused_title); + RrAppearanceFree(theme_a_unfocused_title); + RrAppearanceFree(theme_a_focused_label); + RrAppearanceFree(theme_a_unfocused_label); + RrAppearanceFree(theme_a_icon); + RrAppearanceFree(theme_a_focused_handle); + RrAppearanceFree(theme_a_unfocused_handle); + RrAppearanceFree(theme_a_menu); + RrAppearanceFree(theme_a_menu_title); + RrAppearanceFree(theme_a_menu_item); + RrAppearanceFree(theme_a_menu_disabled); + RrAppearanceFree(theme_a_menu_hilite); + RrAppearanceFree(theme_app_hilite_bg); + RrAppearanceFree(theme_app_unhilite_bg); + RrAppearanceFree(theme_app_hilite_label); + RrAppearanceFree(theme_app_unhilite_label); + RrAppearanceFree(theme_app_icon); } static XrmDatabase loaddb(char *theme) @@ -303,7 +307,8 @@ static gboolean read_string(XrmDatabase db, char *rname, char **value) return ret; } -static gboolean read_color(XrmDatabase db, char *rname, color_rgb **value) +static gboolean read_color(XrmDatabase db, const RrInstance *inst, + gchar *rname, color_rgb **value) { gboolean ret = FALSE; char *rclass = create_class_name(rname); @@ -312,7 +317,7 @@ static gboolean read_color(XrmDatabase db, char *rname, color_rgb **value) if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) && retvalue.addr != NULL) { - color_rgb *c = color_parse(retvalue.addr); + color_rgb *c = RrColorParse(inst, retvalue.addr); if (c != NULL) { *value = c; ret = TRUE; @@ -323,8 +328,9 @@ static gboolean read_color(XrmDatabase db, char *rname, color_rgb **value) return ret; } -static gboolean read_mask(XrmDatabase db, char *rname, char *theme, - pixmap_mask **value) +static gboolean read_mask(XrmDatabase db, const RrInstance *inst, + gchar *rname, gchar *theme, + RrPixmapMask **value) { gboolean ret = FALSE; char *rclass = create_class_name(rname); @@ -369,7 +375,7 @@ static gboolean read_mask(XrmDatabase db, char *rname, char *theme, } if (ret) { - *value = pixmap_mask_new(w, h, (char*)b); + *value = RrPixmapMaskNew(inst, w, h, (char*)b); XFree(b); } @@ -381,8 +387,8 @@ static gboolean read_mask(XrmDatabase db, char *rname, char *theme, return ret; } -static void parse_appearance(char *tex, SurfaceColorType *grad, - ReliefType *relief, BevelType *bevel, +static void parse_appearance(gchar *tex, RrSurfaceColorType *grad, + RrReliefType *relief, RrBevelType *bevel, gboolean *interlaced, gboolean *border) { char *t; @@ -392,45 +398,45 @@ static void parse_appearance(char *tex, SurfaceColorType *grad, *t = g_ascii_tolower(*t); if (strstr(tex, "parentrelative") != NULL) { - *grad = Background_ParentRelative; + *grad = RR_SURFACE_PARENTREL; } else { if (strstr(tex, "gradient") != NULL) { if (strstr(tex, "crossdiagonal") != NULL) - *grad = Background_CrossDiagonal; + *grad = RR_SURFACE_CROSS_DIAGONAL; else if (strstr(tex, "rectangle") != NULL) - *grad = Background_Rectangle; + *grad = RR_SURFACE_RECTANGLE; else if (strstr(tex, "pyramid") != NULL) - *grad = Background_Pyramid; + *grad = RR_SURFACE_PYRAMID; else if (strstr(tex, "pipecross") != NULL) - *grad = Background_PipeCross; + *grad = RR_SURFACE_PIPECROSS; else if (strstr(tex, "elliptic") != NULL) - *grad = Background_Rectangle; + *grad = RR_SURFACE_PIPECROSS; else if (strstr(tex, "horizontal") != NULL) - *grad = Background_Horizontal; + *grad = RR_SURFACE_HORIZONTAL; else if (strstr(tex, "vertical") != NULL) - *grad = Background_Vertical; + *grad = RR_SURFACE_VERTICAL; else - *grad = Background_Diagonal; + *grad = RR_SURFACE_DIAGONAL; } else { - *grad = Background_Solid; + *grad = RR_SURFACE_SOLID; } if (strstr(tex, "sunken") != NULL) - *relief = Sunken; + *relief = RR_RELIEF_SUNKEN; else if (strstr(tex, "flat") != NULL) - *relief = Flat; + *relief = RR_RELIEF_FLAT; else - *relief = Raised; + *relief = RR_RELIEF_RAISED; *border = FALSE; - if (*relief == Flat) { + if (*relief == RR_RELIEF_FLAT) { if (strstr(tex, "border") != NULL) *border = TRUE; } else { if (strstr(tex, "bevel2") != NULL) - *bevel = Bevel2; + *bevel = RR_BEVEL_2; else - *bevel = Bevel1; + *bevel = RR_BEVEL_1; } if (strstr(tex, "interlaced") != NULL) @@ -441,7 +447,8 @@ static void parse_appearance(char *tex, SurfaceColorType *grad, } -static gboolean read_appearance(XrmDatabase db, char *rname, Appearance *value) +static gboolean read_appearance(XrmDatabase db, const RrInstance *inst, + gchar *rname, RrAppearance *value) { gboolean ret = FALSE; char *rclass = create_class_name(rname), *cname, *ctoname, *bcname; @@ -460,14 +467,14 @@ static gboolean read_appearance(XrmDatabase db, char *rname, Appearance *value) &value->surface.bevel, &value->surface.interlaced, &value->surface.border); - if (!read_color(db, cname, &value->surface.primary)) - value->surface.primary = color_new(0, 0, 0); - if (!read_color(db, ctoname, &value->surface.secondary)) - value->surface.secondary = color_new(0, 0, 0); + if (!read_color(db, inst, cname, &value->surface.primary)) + value->surface.primary = RrColorNew(inst, 0, 0, 0); + if (!read_color(db, inst, ctoname, &value->surface.secondary)) + value->surface.secondary = RrColorNew(inst, 0, 0, 0); if (value->surface.border) - if (!read_color(db, bcname, + if (!read_color(db, inst, bcname, &value->surface.border_color)) - value->surface.border_color = color_new(0, 0, 0); + value->surface.border_color = RrColorNew(inst, 0, 0, 0); ret = TRUE; } @@ -478,24 +485,25 @@ static gboolean read_appearance(XrmDatabase db, char *rname, Appearance *value) return ret; } -static void set_default_appearance(Appearance *a) +static void set_default_appearance(RrAppearance *a) { - a->surface.grad = Background_Solid; - a->surface.relief = Flat; - a->surface.bevel = Bevel1; + a->surface.grad = RR_SURFACE_SOLID; + a->surface.relief = RR_RELIEF_FLAT; + a->surface.bevel = RR_BEVEL_1; a->surface.interlaced = FALSE; a->surface.border = FALSE; - a->surface.primary = color_new(0, 0, 0); - a->surface.secondary = color_new(0, 0, 0); + a->surface.primary = RrColorNew(a->inst, 0, 0, 0); + a->surface.secondary = RrColorNew(a->inst, 0, 0, 0); } -char *theme_load(char *theme) +gchar *theme_load(gchar *theme) { XrmDatabase db = NULL; - char *loaded = NULL; - Justify winjust, mtitlejust, mjust; - char *str; - char *font_str; + gchar *loaded = NULL; + RrJustify winjust, mtitlejust, mjust; + gchar *str; + gchar *font_str; + const RrInstance *inst = theme_inst; if (theme) { db = loaddb(theme); @@ -536,12 +544,12 @@ char *theme_load(char *theme) theme_winfont_height = font_height(theme_winfont, theme_winfont_shadow, theme_winfont_shadow_offset); - winjust = Justify_Left; + winjust = RR_JUSTIFY_LEFT; if (read_string(db, "window.justify", &str)) { if (!g_ascii_strcasecmp(str, "right")) - winjust = Justify_Right; + winjust = RR_JUSTIFY_RIGHT; else if (!g_ascii_strcasecmp(str, "center")) - winjust = Justify_Center; + winjust = RR_JUSTIFY_CENTER; g_free(str); } @@ -568,12 +576,12 @@ char *theme_load(char *theme) theme_mtitlefont_shadow, theme_mtitlefont_shadow_offset); - mtitlejust = Justify_Left; + mtitlejust = RR_JUSTIFY_LEFT; if (read_string(db, "menu.title.justify", &str)) { if (!g_ascii_strcasecmp(str, "right")) - mtitlejust = Justify_Right; + mtitlejust = RR_JUSTIFY_RIGHT; else if (!g_ascii_strcasecmp(str, "center")) - mtitlejust = Justify_Center; + mtitlejust = RR_JUSTIFY_CENTER; g_free(str); } @@ -599,12 +607,12 @@ char *theme_load(char *theme) theme_mfont_height = font_height(theme_mfont, theme_mfont_shadow, theme_mfont_shadow_offset); - mjust = Justify_Left; + mjust = RR_JUSTIFY_LEFT; if (read_string(db, "menu.frame.justify", &str)) { if (!g_ascii_strcasecmp(str, "right")) - mjust = Justify_Right; + mjust = RR_JUSTIFY_RIGHT; else if (!g_ascii_strcasecmp(str, "center")) - mjust = Justify_Center; + mjust = RR_JUSTIFY_CENTER; g_free(str); } @@ -622,201 +630,237 @@ char *theme_load(char *theme) theme_cbwidth < 0 || theme_cbwidth > 100) theme_cbwidth = theme_bevel; /* load colors */ - if (!read_color(db, "borderColor", &theme_b_color)) - theme_b_color = color_new(0, 0, 0); - if (!read_color(db, "window.frame.focusColor", &theme_cb_focused_color)) - theme_cb_focused_color = color_new(0xff, 0xff, 0xff); - if (!read_color(db, "window.frame.unfocusColor",&theme_cb_unfocused_color)) - theme_cb_unfocused_color = color_new(0xff, 0xff, 0xff); - if (!read_color(db, "window.label.focus.textColor", + if (!read_color(db, inst, + "borderColor", &theme_b_color)) + theme_b_color = RrColorNew(inst, 0, 0, 0); + if (!read_color(db, inst, + "window.frame.focusColor", &theme_cb_focused_color)) + theme_cb_focused_color = RrColorNew(inst, 0xff, 0xff, 0xff); + if (!read_color(db, inst, + "window.frame.unfocusColor",&theme_cb_unfocused_color)) + theme_cb_unfocused_color = RrColorNew(inst, 0xff, 0xff, 0xff); + if (!read_color(db, inst, + "window.label.focus.textColor", &theme_title_focused_color)) - theme_title_focused_color = color_new(0x0, 0x0, 0x0); - if (!read_color(db, "window.label.unfocus.textColor", + theme_title_focused_color = RrColorNew(inst, 0x0, 0x0, 0x0); + if (!read_color(db, inst, + "window.label.unfocus.textColor", &theme_title_unfocused_color)) - theme_title_unfocused_color = color_new(0xff, 0xff, 0xff); - if (!read_color(db, "window.button.focus.picColor", + theme_title_unfocused_color = RrColorNew(inst, 0xff, 0xff, 0xff); + if (!read_color(db, inst, + "window.button.focus.picColor", &theme_titlebut_focused_color)) - theme_titlebut_focused_color = color_new(0, 0, 0); - if (!read_color(db, "window.button.unfocus.picColor", + theme_titlebut_focused_color = RrColorNew(inst, 0, 0, 0); + if (!read_color(db, inst, + "window.button.unfocus.picColor", &theme_titlebut_unfocused_color)) - theme_titlebut_unfocused_color = color_new(0xff, 0xff, 0xff); - if (!read_color(db, "menu.title.textColor", &theme_menu_title_color)) - theme_menu_title_color = color_new(0, 0, 0); - if (!read_color(db, "menu.frame.textColor", &theme_menu_color)) - theme_menu_color = color_new(0xff, 0xff, 0xff); - if (!read_color(db, "menu.frame.disableColor", &theme_menu_disabled_color)) - theme_menu_disabled_color = color_new(0, 0, 0); - if (!read_color(db, "menu.hilite.textColor", &theme_menu_hilite_color)) - theme_menu_hilite_color = color_new(0, 0, 0); - - if (read_mask(db, "window.button.max.mask", theme, &theme_max_unset_mask)){ - if (!read_mask(db, "window.button.max.toggled.mask", theme, + theme_titlebut_unfocused_color = RrColorNew(inst, 0xff, 0xff, 0xff); + if (!read_color(db, inst, + "menu.title.textColor", &theme_menu_title_color)) + theme_menu_title_color = RrColorNew(inst, 0, 0, 0); + if (!read_color(db, inst, + "menu.frame.textColor", &theme_menu_color)) + theme_menu_color = RrColorNew(inst, 0xff, 0xff, 0xff); + if (!read_color(db, inst, + "menu.frame.disableColor", &theme_menu_disabled_color)) + theme_menu_disabled_color = RrColorNew(inst, 0, 0, 0); + if (!read_color(db, inst, + "menu.hilite.textColor", &theme_menu_hilite_color)) + theme_menu_hilite_color = RrColorNew(inst, 0, 0, 0); + + if (read_mask(db, inst, + "window.button.max.mask", theme, &theme_max_unset_mask)){ + if (!read_mask(db, inst, + "window.button.max.toggled.mask", theme, &theme_max_set_mask)) { - theme_max_set_mask = pixmap_mask_copy(theme_max_unset_mask); + theme_max_set_mask = RrPixmapMaskCopy(theme_max_unset_mask); } } else { { char data[] = { 0x7f, 0x7f, 0x7f, 0x41, 0x41, 0x41, 0x7f }; - theme_max_unset_mask = pixmap_mask_new(7, 7, data); + theme_max_unset_mask = RrPixmapMaskNew(inst, 7, 7, data); } { char data[] = { 0x7c, 0x44, 0x47, 0x47, 0x7f, 0x1f, 0x1f }; - theme_max_set_mask = pixmap_mask_new(7, 7, data); + theme_max_set_mask = RrPixmapMaskNew(inst, 7, 7, data); } } - if (!read_mask(db, "window.button.icon.mask", theme, + if (!read_mask(db, inst, + "window.button.icon.mask", theme, &theme_iconify_mask)) { char data[] = { 0x00, 0x00, 0x00, 0x00, 0x7f, 0x7f, 0x7f }; - theme_iconify_mask = pixmap_mask_new(7, 7, data); + theme_iconify_mask = RrPixmapMaskNew(inst, 7, 7, data); } - if (read_mask(db, "window.button.stick.mask", theme, + if (read_mask(db, inst, + "window.button.stick.mask", theme, &theme_desk_unset_mask)) { - if (!read_mask(db, "window.button.stick.toggled.mask", theme, + if (!read_mask(db, inst, "window.button.stick.toggled.mask", theme, &theme_desk_set_mask)) { theme_desk_set_mask = - pixmap_mask_copy(theme_desk_unset_mask); + RrPixmapMaskCopy(theme_desk_unset_mask); } } else { { char data[] = { 0x63, 0x63, 0x00, 0x00, 0x00, 0x63, 0x63 }; - theme_desk_unset_mask = pixmap_mask_new(7, 7, data); + theme_desk_unset_mask = RrPixmapMaskNew(inst, 7, 7, data); } { char data[] = { 0x00, 0x36, 0x36, 0x08, 0x36, 0x36, 0x00 }; - theme_desk_set_mask = pixmap_mask_new(7, 7, data); + theme_desk_set_mask = RrPixmapMaskNew(inst, 7, 7, data); } } - if (read_mask(db, "window.button.shade.mask", theme, + if (read_mask(db, inst, "window.button.shade.mask", theme, &theme_shade_unset_mask)) { - if (!read_mask(db, "window.button.shade.toggled.mask", theme, + if (!read_mask(db, inst, "window.button.shade.toggled.mask", theme, &theme_shade_set_mask)) { theme_shade_set_mask = - pixmap_mask_copy(theme_shade_unset_mask); + RrPixmapMaskCopy(theme_shade_unset_mask); } } else { { char data[] = { 0x7f, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x00 }; - theme_shade_unset_mask = pixmap_mask_new(7, 7, data); + theme_shade_unset_mask = RrPixmapMaskNew(inst, 7, 7, data); } { char data[] = { 0x7f, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x7f }; - theme_shade_set_mask = pixmap_mask_new(7, 7, data); + theme_shade_set_mask = RrPixmapMaskNew(inst, 7, 7, data); } } - if (!read_mask(db, "window.button.close.mask", theme, + if (!read_mask(db, inst, "window.button.close.mask", theme, &theme_close_mask)) { char data[] = { 0x63, 0x77, 0x3e, 0x1c, 0x3e, 0x77, 0x63 }; - theme_close_mask = pixmap_mask_new(7, 7, data); + theme_close_mask = RrPixmapMaskNew(inst, 7, 7, data); } /* read the decoration textures */ - if (!read_appearance(db, "window.title.focus", theme_a_focused_title)) + if (!read_appearance(db, inst, + "window.title.focus", theme_a_focused_title)) set_default_appearance(theme_a_focused_title); - if (!read_appearance(db, "window.title.unfocus", theme_a_unfocused_title)) + if (!read_appearance(db, inst, + "window.title.unfocus", theme_a_unfocused_title)) set_default_appearance(theme_a_unfocused_title); - if (!read_appearance(db, "window.label.focus", theme_a_focused_label)) + if (!read_appearance(db, inst, + "window.label.focus", theme_a_focused_label)) set_default_appearance(theme_a_focused_label); - if (!read_appearance(db, "window.label.unfocus", theme_a_unfocused_label)) + if (!read_appearance(db, inst, + "window.label.unfocus", theme_a_unfocused_label)) set_default_appearance(theme_a_unfocused_label); - if (!read_appearance(db, "window.handle.focus", theme_a_focused_handle)) + if (!read_appearance(db, inst, + "window.handle.focus", theme_a_focused_handle)) set_default_appearance(theme_a_focused_handle); - if (!read_appearance(db, "window.handle.unfocus",theme_a_unfocused_handle)) + if (!read_appearance(db, inst, + "window.handle.unfocus",theme_a_unfocused_handle)) set_default_appearance(theme_a_unfocused_handle); - if (!read_appearance(db, "window.grip.focus", theme_a_focused_grip)) + if (!read_appearance(db, inst, + "window.grip.focus", theme_a_focused_grip)) set_default_appearance(theme_a_focused_grip); - if (!read_appearance(db, "window.grip.unfocus", theme_a_unfocused_grip)) + if (!read_appearance(db, inst, + "window.grip.unfocus", theme_a_unfocused_grip)) set_default_appearance(theme_a_unfocused_grip); - if (!read_appearance(db, "menu.frame", theme_a_menu)) + if (!read_appearance(db, inst, + "menu.frame", theme_a_menu)) set_default_appearance(theme_a_menu); - if (!read_appearance(db, "menu.title", theme_a_menu_title)) + if (!read_appearance(db, inst, + "menu.title", theme_a_menu_title)) set_default_appearance(theme_a_menu_title); - if (!read_appearance(db, "menu.hilite", theme_a_menu_hilite)) + if (!read_appearance(db, inst, + "menu.hilite", theme_a_menu_hilite)) set_default_appearance(theme_a_menu_hilite); /* read the appearances for rendering non-decorations */ - if (!read_appearance(db, "window.title.focus", theme_app_hilite_bg)) + if (!read_appearance(db, inst, + "window.title.focus", theme_app_hilite_bg)) set_default_appearance(theme_app_hilite_bg); - if (!read_appearance(db, "window.label.focus", theme_app_hilite_label)) + if (!read_appearance(db, inst, + "window.label.focus", theme_app_hilite_label)) set_default_appearance(theme_app_hilite_label); - if (!read_appearance(db, "window.title.unfocus", theme_app_unhilite_bg)) + if (!read_appearance(db, inst, + "window.title.unfocus", theme_app_unhilite_bg)) set_default_appearance(theme_app_unhilite_bg); - if (!read_appearance(db, "window.label.unfocus", theme_app_unhilite_label)) + if (!read_appearance(db, inst, + "window.label.unfocus", theme_app_unhilite_label)) set_default_appearance(theme_app_unhilite_label); /* read buttons textures */ - if (!read_appearance(db, "window.button.pressed.focus", + if (!read_appearance(db, inst, + "window.button.pressed.focus", theme_a_focused_pressed_max)) - if (!read_appearance(db, "window.button.pressed", + if (!read_appearance(db, inst, + "window.button.pressed", theme_a_focused_pressed_max)) set_default_appearance(theme_a_focused_pressed_max); - if (!read_appearance(db, "window.button.pressed.unfocus", + if (!read_appearance(db, inst, + "window.button.pressed.unfocus", theme_a_unfocused_pressed_max)) - if (!read_appearance(db, "window.button.pressed", + if (!read_appearance(db, inst, + "window.button.pressed", theme_a_unfocused_pressed_max)) set_default_appearance(theme_a_unfocused_pressed_max); - if (!read_appearance(db, "window.button.focus", + if (!read_appearance(db, inst, + "window.button.focus", theme_a_focused_unpressed_max)) set_default_appearance(theme_a_focused_unpressed_max); - if (!read_appearance(db, "window.button.unfocus", + if (!read_appearance(db, inst, + "window.button.unfocus", theme_a_unfocused_unpressed_max)) set_default_appearance(theme_a_unfocused_unpressed_max); theme_a_unfocused_unpressed_close = - appearance_copy(theme_a_unfocused_unpressed_max); + RrAppearanceCopy(theme_a_unfocused_unpressed_max); theme_a_unfocused_pressed_close = - appearance_copy(theme_a_unfocused_pressed_max); + RrAppearanceCopy(theme_a_unfocused_pressed_max); theme_a_focused_unpressed_close = - appearance_copy(theme_a_focused_unpressed_max); + RrAppearanceCopy(theme_a_focused_unpressed_max); theme_a_focused_pressed_close = - appearance_copy(theme_a_focused_pressed_max); + RrAppearanceCopy(theme_a_focused_pressed_max); theme_a_unfocused_unpressed_desk = - appearance_copy(theme_a_unfocused_unpressed_max); + RrAppearanceCopy(theme_a_unfocused_unpressed_max); theme_a_unfocused_pressed_desk = - appearance_copy(theme_a_unfocused_pressed_max); + RrAppearanceCopy(theme_a_unfocused_pressed_max); theme_a_unfocused_pressed_set_desk = - appearance_copy(theme_a_unfocused_pressed_max); + RrAppearanceCopy(theme_a_unfocused_pressed_max); theme_a_focused_unpressed_desk = - appearance_copy(theme_a_focused_unpressed_max); + RrAppearanceCopy(theme_a_focused_unpressed_max); theme_a_focused_pressed_desk = - appearance_copy(theme_a_focused_pressed_max); + RrAppearanceCopy(theme_a_focused_pressed_max); theme_a_focused_pressed_set_desk = - appearance_copy(theme_a_focused_pressed_max); + RrAppearanceCopy(theme_a_focused_pressed_max); theme_a_unfocused_unpressed_shade = - appearance_copy(theme_a_unfocused_unpressed_max); + RrAppearanceCopy(theme_a_unfocused_unpressed_max); theme_a_unfocused_pressed_shade = - appearance_copy(theme_a_unfocused_pressed_max); + RrAppearanceCopy(theme_a_unfocused_pressed_max); theme_a_unfocused_pressed_set_shade = - appearance_copy(theme_a_unfocused_pressed_max); + RrAppearanceCopy(theme_a_unfocused_pressed_max); theme_a_focused_unpressed_shade = - appearance_copy(theme_a_focused_unpressed_max); + RrAppearanceCopy(theme_a_focused_unpressed_max); theme_a_focused_pressed_shade = - appearance_copy(theme_a_focused_pressed_max); + RrAppearanceCopy(theme_a_focused_pressed_max); theme_a_focused_pressed_set_shade = - appearance_copy(theme_a_focused_pressed_max); + RrAppearanceCopy(theme_a_focused_pressed_max); theme_a_unfocused_unpressed_iconify = - appearance_copy(theme_a_unfocused_unpressed_max); + RrAppearanceCopy(theme_a_unfocused_unpressed_max); theme_a_unfocused_pressed_iconify = - appearance_copy(theme_a_unfocused_pressed_max); + RrAppearanceCopy(theme_a_unfocused_pressed_max); theme_a_focused_unpressed_iconify = - appearance_copy(theme_a_focused_unpressed_max); + RrAppearanceCopy(theme_a_focused_unpressed_max); theme_a_focused_pressed_iconify = - appearance_copy(theme_a_focused_pressed_max); + RrAppearanceCopy(theme_a_focused_pressed_max); theme_a_unfocused_pressed_set_max = - appearance_copy(theme_a_unfocused_pressed_max); + RrAppearanceCopy(theme_a_unfocused_pressed_max); theme_a_focused_pressed_set_max = - appearance_copy(theme_a_focused_pressed_max); + RrAppearanceCopy(theme_a_focused_pressed_max); - theme_a_icon->surface.grad = Background_ParentRelative; + theme_a_icon->surface.grad = RR_SURFACE_PARENTREL; /* set up the textures */ theme_a_focused_label->texture[0].type = - theme_app_hilite_label->texture[0].type = Text; + theme_app_hilite_label->texture[0].type = RR_TEXTURE_TEXT; theme_a_focused_label->texture[0].data.text.justify = winjust; - theme_app_hilite_label->texture[0].data.text.justify = Justify_Left; + theme_app_hilite_label->texture[0].data.text.justify = RR_JUSTIFY_LEFT; theme_a_focused_label->texture[0].data.text.font = theme_app_hilite_label->texture[0].data.text.font = theme_winfont; theme_a_focused_label->texture[0].data.text.shadow = @@ -833,9 +877,9 @@ char *theme_load(char *theme) theme_title_focused_color; theme_a_unfocused_label->texture[0].type = - theme_app_unhilite_label->texture[0].type = Text; + theme_app_unhilite_label->texture[0].type = RR_TEXTURE_TEXT; theme_a_unfocused_label->texture[0].data.text.justify = winjust; - theme_app_unhilite_label->texture[0].data.text.justify = Justify_Left; + theme_app_unhilite_label->texture[0].data.text.justify = RR_JUSTIFY_LEFT; theme_a_unfocused_label->texture[0].data.text.font = theme_app_unhilite_label->texture[0].data.text.font = theme_winfont; theme_a_unfocused_label->texture[0].data.text.shadow = @@ -851,7 +895,7 @@ char *theme_load(char *theme) theme_app_unhilite_label->texture[0].data.text.color = theme_title_unfocused_color; - theme_a_menu_title->texture[0].type = Text; + theme_a_menu_title->texture[0].type = RR_TEXTURE_TEXT; theme_a_menu_title->texture[0].data.text.justify = mtitlejust; theme_a_menu_title->texture[0].data.text.font = theme_mtitlefont; theme_a_menu_title->texture[0].data.text.shadow = theme_mtitlefont_shadow; @@ -863,11 +907,11 @@ char *theme_load(char *theme) theme_a_menu_item->surface.grad = theme_a_menu_disabled->surface.grad = - theme_app_icon->surface.grad = Background_ParentRelative; + theme_app_icon->surface.grad = RR_SURFACE_PARENTREL; theme_a_menu_item->texture[0].type = theme_a_menu_disabled->texture[0].type = - theme_a_menu_hilite->texture[0].type = Text; + theme_a_menu_hilite->texture[0].type = RR_TEXTURE_TEXT; theme_a_menu_item->texture[0].data.text.justify = theme_a_menu_disabled->texture[0].data.text.justify = theme_a_menu_hilite->texture[0].data.text.justify = mjust; @@ -915,7 +959,7 @@ char *theme_load(char *theme) theme_a_focused_unpressed_iconify->texture[0].type = theme_a_focused_pressed_iconify->texture[0].type = theme_a_unfocused_unpressed_iconify->texture[0].type = - theme_a_unfocused_pressed_iconify->texture[0].type = Bitmask; + theme_a_unfocused_pressed_iconify->texture[0].type = RR_TEXTURE_MASK; theme_a_focused_unpressed_max->texture[0].data.mask.mask = theme_a_unfocused_unpressed_max->texture[0].data.mask.mask = theme_a_focused_pressed_max->texture[0].data.mask.mask = diff --git a/render/theme.h b/render/theme.h index 0f87b808..6ffcd24b 100644 --- a/render/theme.h +++ b/render/theme.h @@ -6,10 +6,10 @@ #include "font.h" #include "mask.h" -extern int theme_bevel; -extern int theme_handle_height; -extern int theme_bwidth; -extern int theme_cbwidth; +extern gint theme_bevel; +extern gint theme_handle_height; +extern gint theme_bwidth; +extern gint theme_cbwidth; #define theme_label_height (theme_winfont_height) #define theme_title_height (theme_label_height + theme_bevel * 2) @@ -24,69 +24,69 @@ extern color_rgb *theme_title_unfocused_color; extern color_rgb *theme_titlebut_focused_color; extern color_rgb *theme_titlebut_unfocused_color; -extern int theme_winfont_height; -extern ObFont *theme_winfont; -extern char *theme_title_layout; +extern gint theme_winfont_height; +extern RrFont *theme_winfont; +extern gchar *theme_title_layout; -extern pixmap_mask *theme_max_set_mask; -extern pixmap_mask *theme_max_unset_mask; -extern pixmap_mask *theme_iconify_mask; -extern pixmap_mask *theme_desk_set_mask; -extern pixmap_mask *theme_desk_unset_mask; -extern pixmap_mask *theme_shade_set_mask; -extern pixmap_mask *theme_shade_unset_mask; -extern pixmap_mask *theme_close_mask; +extern RrPixmapMask *theme_max_set_mask; +extern RrPixmapMask *theme_max_unset_mask; +extern RrPixmapMask *theme_iconify_mask; +extern RrPixmapMask *theme_desk_set_mask; +extern RrPixmapMask *theme_desk_unset_mask; +extern RrPixmapMask *theme_shade_set_mask; +extern RrPixmapMask *theme_shade_unset_mask; +extern RrPixmapMask *theme_close_mask; -extern Appearance *theme_a_focused_unpressed_max; -extern Appearance *theme_a_focused_pressed_max; -extern Appearance *theme_a_focused_pressed_set_max; -extern Appearance *theme_a_unfocused_unpressed_max; -extern Appearance *theme_a_unfocused_pressed_max; -extern Appearance *theme_a_unfocused_pressed_set_max; -extern Appearance *theme_a_focused_unpressed_close; -extern Appearance *theme_a_focused_pressed_close; -extern Appearance *theme_a_unfocused_unpressed_close; -extern Appearance *theme_a_unfocused_pressed_close; -extern Appearance *theme_a_focused_unpressed_desk; -extern Appearance *theme_a_focused_pressed_desk; -extern Appearance *theme_a_focused_pressed_set_desk; -extern Appearance *theme_a_unfocused_unpressed_desk; -extern Appearance *theme_a_unfocused_pressed_desk; -extern Appearance *theme_a_unfocused_pressed_set_desk; -extern Appearance *theme_a_focused_unpressed_shade; -extern Appearance *theme_a_focused_pressed_shade; -extern Appearance *theme_a_focused_pressed_set_shade; -extern Appearance *theme_a_unfocused_unpressed_shade; -extern Appearance *theme_a_unfocused_pressed_shade; -extern Appearance *theme_a_unfocused_pressed_set_shade; -extern Appearance *theme_a_focused_unpressed_iconify; -extern Appearance *theme_a_focused_pressed_iconify; -extern Appearance *theme_a_unfocused_unpressed_iconify; -extern Appearance *theme_a_unfocused_pressed_iconify; -extern Appearance *theme_a_focused_grip; -extern Appearance *theme_a_unfocused_grip; -extern Appearance *theme_a_focused_title; -extern Appearance *theme_a_unfocused_title; -extern Appearance *theme_a_focused_label; -extern Appearance *theme_a_unfocused_label; -extern Appearance *theme_a_icon; -extern Appearance *theme_a_focused_handle; -extern Appearance *theme_a_unfocused_handle; -extern Appearance *theme_a_menu_title; -extern Appearance *theme_a_menu; -extern Appearance *theme_a_menu_item; -extern Appearance *theme_a_menu_disabled; -extern Appearance *theme_a_menu_hilite; +extern RrAppearance *theme_a_focused_unpressed_max; +extern RrAppearance *theme_a_focused_pressed_max; +extern RrAppearance *theme_a_focused_pressed_set_max; +extern RrAppearance *theme_a_unfocused_unpressed_max; +extern RrAppearance *theme_a_unfocused_pressed_max; +extern RrAppearance *theme_a_unfocused_pressed_set_max; +extern RrAppearance *theme_a_focused_unpressed_close; +extern RrAppearance *theme_a_focused_pressed_close; +extern RrAppearance *theme_a_unfocused_unpressed_close; +extern RrAppearance *theme_a_unfocused_pressed_close; +extern RrAppearance *theme_a_focused_unpressed_desk; +extern RrAppearance *theme_a_focused_pressed_desk; +extern RrAppearance *theme_a_focused_pressed_set_desk; +extern RrAppearance *theme_a_unfocused_unpressed_desk; +extern RrAppearance *theme_a_unfocused_pressed_desk; +extern RrAppearance *theme_a_unfocused_pressed_set_desk; +extern RrAppearance *theme_a_focused_unpressed_shade; +extern RrAppearance *theme_a_focused_pressed_shade; +extern RrAppearance *theme_a_focused_pressed_set_shade; +extern RrAppearance *theme_a_unfocused_unpressed_shade; +extern RrAppearance *theme_a_unfocused_pressed_shade; +extern RrAppearance *theme_a_unfocused_pressed_set_shade; +extern RrAppearance *theme_a_focused_unpressed_iconify; +extern RrAppearance *theme_a_focused_pressed_iconify; +extern RrAppearance *theme_a_unfocused_unpressed_iconify; +extern RrAppearance *theme_a_unfocused_pressed_iconify; +extern RrAppearance *theme_a_focused_grip; +extern RrAppearance *theme_a_unfocused_grip; +extern RrAppearance *theme_a_focused_title; +extern RrAppearance *theme_a_unfocused_title; +extern RrAppearance *theme_a_focused_label; +extern RrAppearance *theme_a_unfocused_label; +extern RrAppearance *theme_a_icon; +extern RrAppearance *theme_a_focused_handle; +extern RrAppearance *theme_a_unfocused_handle; +extern RrAppearance *theme_a_menu_title; +extern RrAppearance *theme_a_menu; +extern RrAppearance *theme_a_menu_item; +extern RrAppearance *theme_a_menu_disabled; +extern RrAppearance *theme_a_menu_hilite; -extern Appearance *theme_app_hilite_bg; -extern Appearance *theme_app_unhilite_bg; -extern Appearance *theme_app_hilite_label; -extern Appearance *theme_app_unhilite_label; -extern Appearance *theme_app_icon; +extern RrAppearance *theme_app_hilite_bg; +extern RrAppearance *theme_app_unhilite_bg; +extern RrAppearance *theme_app_hilite_label; +extern RrAppearance *theme_app_unhilite_label; +extern RrAppearance *theme_app_icon; -void theme_startup(); +void theme_startup(const RrInstance *inst); void theme_shutdown(); -char *theme_load(char *theme); +gchar *theme_load(gchar *theme); #endif