summaryrefslogtreecommitdiff
path: root/render
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2003-06-20 02:17:23 +0000
committerDana Jansens <danakj@orodu.net>2003-06-20 02:17:23 +0000
commitcd12a2eae5b5b72df08d588ac71d1f6cf6725dfb (patch)
tree56413723ec877b3da05e2ece758b45b98d5b589c /render
parent349d0167dbee10ccb1c6200709286a5134ac7121 (diff)
simply the render interface by not requiring the setting of all the areas. only take a w and h in paint(). best font layout ever.
Diffstat (limited to 'render')
-rw-r--r--render/font.c24
-rw-r--r--render/gradient.c6
-rw-r--r--render/image.c18
-rw-r--r--render/image.h3
-rw-r--r--render/render.c310
-rw-r--r--render/render.h11
-rw-r--r--render/test.c24
-rw-r--r--render/theme.c2
-rw-r--r--render/theme.h2
9 files changed, 121 insertions, 279 deletions
diff --git a/render/font.c b/render/font.c
index 22722245..27474304 100644
--- a/render/font.c
+++ b/render/font.c
@@ -1,4 +1,5 @@
#include "font.h"
+#include "theme.h"
#include "kernel/openbox.h"
#include "kernel/geom.h"
#include "kernel/gettext.h"
@@ -102,7 +103,7 @@ int font_max_char_width(ObFont *f)
return (signed) f->xftfont->max_advance_width;
}
-void font_draw(XftDraw *d, TextureText *t, Rect *position)
+void font_draw(XftDraw *d, TextureText *t, Rect *area)
{
int x,y,w,h;
XftColor c;
@@ -111,20 +112,22 @@ void font_draw(XftDraw *d, TextureText *t, Rect *position)
size_t l;
gboolean shortened = FALSE;
- y = position->y;
- w = position->width;
- h = position->height;
+ /* center vertically */
+ y = area->y +
+ (area->height - font_height(t->font, t->shadow, t->offset)) / 2;
+ w = area->width;
+ h = area->height;
text = g_string_new(t->string);
l = g_utf8_strlen(text->str, -1);
font_measure_full(t->font, text->str, t->shadow, t->offset, &mw, &mh);
- while (l && mw > position->width) {
+ while (l && mw > area->width) {
shortened = TRUE;
/* remove a character from the middle */
text = g_string_erase(text, l-- / 2, 1);
em = ELIPSES_LENGTH(t->font, t->shadow, t->offset);
/* if the elipses are too large, don't show them at all */
- if (em > position->width)
+ if (em > area->width)
shortened = FALSE;
font_measure_full(t->font, text->str, t->shadow, t->offset, &mw, &mh);
mw += em;
@@ -135,18 +138,15 @@ void font_draw(XftDraw *d, TextureText *t, Rect *position)
}
if (!l) return;
- /* center vertically */
- y -= ((t->font->xftfont->ascent + t->font->xftfont->descent) - mh) / 2;
-
switch (t->justify) {
case Justify_Left:
- x = position->x;
+ x = area->x + theme_bevel;
break;
case Justify_Right:
- x = position->x + (w - mw);
+ x = area->x + (w - mw) - theme_bevel;
break;
case Justify_Center:
- x = position->x + (w - mw) / 2;
+ x = area->x + (w - mw) / 2;
break;
}
diff --git a/render/gradient.c b/render/gradient.c
index b6661bbc..ebfdb3bb 100644
--- a/render/gradient.c
+++ b/render/gradient.c
@@ -295,9 +295,9 @@ void gradient_solid(Appearance *l, int x, int y, int w, int h)
+ (sp->primary->g << default_green_offset)
+ (sp->primary->b << default_blue_offset);
- for (a = 0; a < l->area.width; a++)
- for (b = 0; b < l->area.height; b++)
- sp->pixel_data[a + b*l->area.width] = pix;
+ for (a = 0; a < w; a++)
+ for (b = 0; b < h; b++)
+ sp->pixel_data[a + b * w] = pix;
XFillRectangle(ob_display, l->pixmap, sp->primary->gc,
x, y, w, h);
diff --git a/render/image.c b/render/image.c
index feb25970..351a831d 100644
--- a/render/image.c
+++ b/render/image.c
@@ -2,18 +2,12 @@
#include "../kernel/geom.h"
#include "image.h"
-void image_draw(pixel32 *target, TextureRGBA *rgba, Rect *position,
- Rect *surarea)
+void image_draw(pixel32 *target, TextureRGBA *rgba, Rect *area)
{
pixel32 *draw = rgba->data;
guint c, i, e, t, sfw, sfh;
- sfw = position->width;
- sfh = position->height;
-
- /* it would be nice if this worked, but this function is well broken in
- these circumstances. */
- g_assert(position->width == surarea->width &&
- position->height == surarea->height);
+ sfw = area->width;
+ sfh = area->height;
g_assert(rgba->data != NULL);
@@ -28,7 +22,7 @@ void image_draw(pixel32 *target, TextureRGBA *rgba, Rect *position,
/* scale it and cache it */
if (rgba->cache != NULL)
g_free(rgba->cache);
- rgba->cache = g_new(unsigned long, sfw * sfh);
+ rgba->cache = g_new(pixel32, sfw * sfh);
rgba->cwidth = sfw;
rgba->cheight = sfh;
for (i = 0, c = 0, e = sfw*sfh; i < e; ++i) {
@@ -47,7 +41,7 @@ void image_draw(pixel32 *target, TextureRGBA *rgba, Rect *position,
draw = rgba->cache;
/* apply the alpha channel */
- for (i = 0, c = 0, t = position->x, e = sfw*sfh; i < e; ++i, ++t) {
+ for (i = 0, c = 0, t = area->x, e = sfw*sfh; i < e; ++i, ++t) {
guchar alpha, r, g, b, bgr, bgg, bgb;
alpha = draw[i] >> default_alpha_offset;
@@ -57,7 +51,7 @@ void image_draw(pixel32 *target, TextureRGBA *rgba, Rect *position,
if (c >= sfw) {
c = 0;
- t += surarea->width - sfw;
+ t += area->width - sfw;
}
/* background color */
diff --git a/render/image.h b/render/image.h
index 84f61d77..7dd48e7d 100644
--- a/render/image.h
+++ b/render/image.h
@@ -4,7 +4,6 @@
#include "render.h"
#include "../kernel/geom.h"
-void image_draw(pixel32 *target, TextureRGBA *rgba, Rect *position,
- Rect *surarea);
+void image_draw(pixel32 *target, TextureRGBA *rgba, Rect *area);
#endif
diff --git a/render/render.c b/render/render.c
index 3a129012..b2575c63 100644
--- a/render/render.c
+++ b/render/render.c
@@ -1,10 +1,6 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
-#ifdef USE_GL
-# include <GL/glx.h>
-#endif
-
#include <glib.h>
#include "render.h"
#include "gradient.h"
@@ -30,122 +26,26 @@ int render_red_shift, render_green_shift, render_blue_shift;
int render_red_mask, render_green_mask, render_blue_mask;
-#ifdef USE_GL
-
-GLXContext render_glx_context;
-
-int render_glx_rating(XVisualInfo *v)
-{
- int er;
- int rating = 0;
- int val;
- printf("evaluating visual %d\n", v->visualid);
- glXGetConfig(ob_display, v, GLX_BUFFER_SIZE, &val);
- printf("buffer size %d\n", val);
-
- switch (val) {
- case 32:
- rating += 300;
- break;
- case 24:
- rating += 200;
- break;
- case 16:
- rating += 100;
- break;
- }
-
- glXGetConfig(ob_display, v, GLX_LEVEL, &val);
- printf("level %d\n", val);
- if (val != 0)
- rating = -10000;
-
- glXGetConfig(ob_display, v, GLX_DEPTH_SIZE, &val);
- printf("depth size %d\n", val);
- switch (val) {
- case 32:
- rating += 30;
- break;
- case 24:
- rating += 20;
- break;
- case 16:
- rating += 10;
- break;
- case 0:
- rating -= 10000;
- }
-
- glXGetConfig(ob_display, v, GLX_DOUBLEBUFFER, &val);
- printf("double buffer %d\n", val);
- if (val)
- rating++;
- return rating;
-}
-#endif /* USE_GL */
-
void render_startup(void)
{
- int count, i = 0, val, best = 0, rate = 0, temp;
- XVisualInfo vimatch, *vilist;
- paint = x_paint;
-
render_depth = DefaultDepth(ob_display, ob_screen);
render_visual = DefaultVisual(ob_display, ob_screen);
render_colormap = DefaultColormap(ob_display, ob_screen);
-#ifdef USE_GL
- vimatch.screen = ob_screen;
- vimatch.class = TrueColor;
- vilist = XGetVisualInfo(ob_display, VisualScreenMask | VisualClassMask,
- &vimatch, &count);
-
- if (vilist) {
- printf("looking for a GL visualin %d visuals\n", count);
- for (i = 0; i < count; i++) {
- glXGetConfig(ob_display, &vilist[i], GLX_USE_GL, &val);
- if (val) {
- temp = render_glx_rating(&vilist[i]);
- if (temp > rate) {
- best = i;
- rate = temp;
- }
- }
- }
- }
- if (rate > 0) {
- printf("picked visual %d with rating %d\n", best, rate);
- render_depth = vilist[best].depth;
- render_visual = vilist[best].visual;
- render_colormap = XCreateColormap(ob_display, ob_root,
- render_visual, AllocNone);
- render_visual_info = vilist[best];
- render_glx_context = glXCreateContext(ob_display, &render_visual_info,
- NULL, True);
- if (render_glx_context == NULL)
- printf("sadness\n");
- else {
- paint = gl_paint;
- }
+ 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);
}
-#endif /*USE_GL*/
-
-
- 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)
@@ -259,22 +159,27 @@ void pseudocolor_startup(void)
}
}
-void x_paint(Window win, Appearance *l)
+void paint(Window win, Appearance *l, int w, int h)
{
int i, transferred = 0, sw;
pixel32 *source, *dest;
Pixmap oldp;
- int x = l->area.x;
- int y = l->area.y;
- int w = l->area.width;
- int h = l->area.height;
Rect tarea; /* area in which to draw textures */
+ gboolean resized;
- if (w <= 0 || h <= 0 || x+w <= 0 || y+h <= 0) return;
+ if (w <= 0 || h <= 0) return;
+
+ resized = (l->w != w || l->h != 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);
+ } else
+ oldp = None;
- oldp = l->pixmap; /* save to free after changing the visible pixmap */
- l->pixmap = XCreatePixmap(ob_display, ob_root, x+w, y+h, render_depth);
g_assert(l->pixmap != None);
+ l->w = w;
+ l->h = h;
if (l->xftdraw != NULL)
XftDrawDestroy(l->xftdraw);
@@ -285,72 +190,72 @@ void x_paint(Window win, Appearance *l)
g_free(l->surface.pixel_data);
l->surface.pixel_data = g_new(pixel32, w * h);
-
if (l->surface.grad == Background_ParentRelative) {
- sw = l->surface.parent->area.width;
- source = l->surface.parent->surface.pixel_data
- + l->surface.parentx
- + sw * l->surface.parenty;
+ g_assert (l->surface.parent);
+ g_assert (l->surface.parent->w);
+
+ sw = l->surface.parent->w;
+ source = (l->surface.parent->surface.pixel_data + l->surface.parentx +
+ sw * l->surface.parenty);
dest = l->surface.pixel_data;
for (i = 0; i < h; i++, source += sw, dest += w) {
memcpy(dest, source, w * sizeof(pixel32));
}
}
else if (l->surface.grad == Background_Solid)
- gradient_solid(l, x, y, w, h);
+ gradient_solid(l, 0, 0, w, h);
else gradient_render(&l->surface, w, h);
- for (i = 0; i < l->textures; i++) {
- tarea = l->texture[i].position;
- if (l->surface.grad != Background_ParentRelative) {
- if (l->surface.relief != Flat) {
- switch (l->surface.bevel) {
- case Bevel1:
- tarea.x += 1; tarea.y += 1;
- tarea.width -= 2; tarea.height -= 2;
- break;
- case Bevel2:
- tarea.x += 2; tarea.y += 2;
- tarea.width -= 4; tarea.height -= 4;
- break;
- }
- } else if (l->surface.border) {
+ RECT_SET(tarea, 0, 0, w, h);
+ if (l->surface.grad != Background_ParentRelative) {
+ if (l->surface.relief != Flat) {
+ switch (l->surface.bevel) {
+ case Bevel1:
tarea.x += 1; tarea.y += 1;
tarea.width -= 2; tarea.height -= 2;
+ break;
+ case Bevel2:
+ tarea.x += 2; tarea.y += 2;
+ tarea.width -= 4; tarea.height -= 4;
+ break;
}
+ } else if (l->surface.border) {
+ tarea.x += 1; tarea.y += 1;
+ tarea.width -= 2; tarea.height -= 2;
}
+ }
+ for (i = 0; i < l->textures; i++) {
switch (l->texture[i].type) {
+ case NoTexture:
+ break;
case Text:
if (!transferred) {
transferred = 1;
if (l->surface.grad != Background_Solid)
pixel32_to_pixmap(l->surface.pixel_data,
- l->pixmap,x,y,w,h);
+ l->pixmap, 0, 0, w, h);
}
if (l->xftdraw == NULL) {
l->xftdraw = XftDrawCreate(ob_display, l->pixmap,
render_visual, render_colormap);
}
- font_draw(l->xftdraw, &l->texture[i].data.text,
- &tarea);
+ font_draw(l->xftdraw, &l->texture[i].data.text, &tarea);
break;
case Bitmask:
if (!transferred) {
transferred = 1;
if (l->surface.grad != Background_Solid)
pixel32_to_pixmap(l->surface.pixel_data,
- l->pixmap,x,y,w,h);
+ l->pixmap, 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);
+ mask_draw(l->pixmap, &l->texture[i].data.mask, &tarea);
break;
case RGBA:
- image_draw(l->surface.pixel_data,
- &l->texture[i].data.rgba,
- &tarea, &l->area);
+ image_draw(l->surface.pixel_data,
+ &l->texture[i].data.rgba, &tarea);
break;
}
}
@@ -358,14 +263,13 @@ void x_paint(Window win, Appearance *l)
if (!transferred) {
transferred = 1;
if (l->surface.grad != Background_Solid)
- pixel32_to_pixmap(l->surface.pixel_data, l->pixmap
- ,x,y,w,h);
+ pixel32_to_pixmap(l->surface.pixel_data, l->pixmap, 0, 0, w, h);
}
XSetWindowBackgroundPixmap(ob_display, win, l->pixmap);
XClearWindow(ob_display, win);
- if (oldp != None) XFreePixmap(ob_display, oldp);
+ if (oldp) XFreePixmap(ob_display, oldp);
}
void render_shutdown(void)
@@ -383,6 +287,7 @@ Appearance *appearance_new(int numtex)
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;
@@ -442,6 +347,7 @@ Appearance *appearance_copy(Appearance *orig)
copy->texture = g_memdup(orig->texture, orig->textures * sizeof(Texture));
copy->pixmap = None;
copy->xftdraw = NULL;
+ copy->w = copy->h = 0;
return copy;
}
@@ -491,45 +397,52 @@ void appearance_minsize(Appearance *l, int *w, int *h)
{
int i;
int m;
- *w = *h = 1;
-
- if (l->surface.relief != Flat) {
- switch (l->surface.bevel) {
- case Bevel1:
- *w = *h = 2;
- break;
- case Bevel2:
- *w = *h = 4;
- break;
- }
- } else if (l->surface.border)
- *w = *h = 2;
+ *w = *h = 0;
for (i = 0; i < l->textures; ++i) {
switch (l->texture[i].type) {
case Bitmask:
- *w += l->texture[i].data.mask.mask->w;
- *h += l->texture[i].data.mask.mask->h;
+ *w = MAX(*w, l->texture[i].data.mask.mask->w);
+ *h = MAX(*h, l->texture[i].data.mask.mask->h);
break;
case Text:
m = font_measure_string(l->texture[i].data.text.font,
l->texture[i].data.text.string,
l->texture[i].data.text.shadow,
l->texture[i].data.text.offset);
- *w += m;
+ *w = MAX(*w, m);
m = font_height(l->texture[i].data.text.font,
l->texture[i].data.text.shadow,
l->texture[i].data.text.offset);
- *h += m;
+ *h += MAX(*h, m);
break;
case RGBA:
- *w += l->texture[i].data.rgba.width;
- *h += l->texture[i].data.rgba.height;
+ *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) {
+ switch (l->surface.bevel) {
+ case Bevel1:
+ *w += 2;
+ *h += 2;
+ break;
+ case Bevel2:
+ *w += 4;
+ *h += 4;
+ break;
+ }
+ } else if (l->surface.border) {
+ *w += 2;
+ *h += 2;
+ }
+
+ if (*w < 1) *w = 1;
+ if (*h < 1) *h = 1;
}
gboolean render_pixmap_to_rgba(Pixmap pmap, Pixmap mask,
@@ -579,54 +492,3 @@ gboolean render_pixmap_to_rgba(Pixmap pmap, Pixmap mask,
return TRUE;
}
-
-#ifdef USE_GL
-void gl_paint(Window win, Appearance *l)
-{
- int err;
- Window root, child;
- int i, transferred = 0, sw, b, d;
- pixel32 *source, *dest;
- Pixmap oldp;
- int tempx, tempy, absx, absy, absw, absh;
- int x = l->area.x;
- int y = l->area.y;
- int w = l->area.width;
- int h = l->area.height;
- Rect tarea; /* area in which to draw textures */
- if (w <= 0 || h <= 0 || x+w <= 0 || y+h <= 0) return;
-
- g_assert(l->surface.type == Surface_Planar);
-
-printf("making %p, %p, %p current\n", ob_display, win, render_glx_context);
- err = glXMakeCurrent(ob_display, win, render_glx_context);
-g_assert(err != 0);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0, 1376, 1032, 0, 0, 10);
- if (XGetGeometry(ob_display, win, &root, &tempx, &tempy,
- &absw, &absh, &b, &d) &&
- XTranslateCoordinates(ob_display, win, root, tempx, tempy,
- &absx, &absy, &child))
- printf("window at %d, %d (%d,%d)\n", absx, absy, absw, absh);
- else
- return;
-
- glViewport(0, 0, 1376, 1032);
- glMatrixMode(GL_MODELVIEW);
- glTranslatef(-absx, 1032-absh-absy, 0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
-
- if (l->surface.grad == Background_ParentRelative) {
- printf("crap\n");
- } else
- render_gl_gradient(&l->surface, absx+x, absy+y, absw, absh);
-
- glXSwapBuffers(ob_display, win);
-}
-
-#endif /* USE_GL */
diff --git a/render/render.h b/render/render.h
index 1b1cce1d..31e62ee7 100644
--- a/render/render.h
+++ b/render/render.h
@@ -59,7 +59,6 @@ typedef struct Surface {
typedef struct {
XftFont *xftfont;
- int height;
int elipses_length;
} ObFont;
@@ -107,18 +106,19 @@ typedef union {
} TextureData;
typedef struct Texture {
- Rect position;
TextureType type;
TextureData data;
} Texture;
typedef struct Appearance {
Surface surface;
- Rect area;
int textures;
Texture *texture;
Pixmap pixmap;
XftDraw *xftdraw;
+
+ /* cached for internal use */
+ int w, h;
} Appearance;
extern Visual *render_visual;
@@ -126,12 +126,9 @@ extern XVisualInfo render_visual_info;
extern int render_depth;
extern Colormap render_colormap;
-void (*paint)(Window win, Appearance *l);
-
void render_startup(void);
void init_appearance(Appearance *l);
-void x_paint(Window win, Appearance *l);
-void gl_paint(Window win, 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);
diff --git a/render/test.c b/render/test.c
index 4dfed619..9ae7eada 100644
--- a/render/test.c
+++ b/render/test.c
@@ -21,25 +21,19 @@ Window ob_root;
int main()
{
Window win;
- GC gc;
- Pixmap pm;
Appearance *look;
- int grabbed = 0;
Window root;
- XGCValues values;
XEvent report;
- int h = 500, w = 500, tmp;
- XVisualInfo *vi;
- int i;
+ int h = 500, w = 500;
ob_display = XOpenDisplay(NULL);
XSetErrorHandler(x_error_handler);
ob_screen = DefaultScreen(ob_display);
ob_root = RootWindow(ob_display, ob_screen);
win =
- XCreateWindow(ob_display, RootWindow(ob_display, 0)
- , 10, 10, w, h, 10,
+ XCreateWindow(ob_display, RootWindow(ob_display, 0),
+ 10, 10, w, h, 10,
CopyFromParent, /* depth */
CopyFromParent, /* class */
CopyFromParent, /* visual */
@@ -55,25 +49,21 @@ int main()
look->surface.secondary = color_parse("Yellow");
look->surface.primary = color_parse("Blue");
look->surface.interlaced = FALSE;
- look->area.x = 0;
- look->area.y = 0;
- look->area.width = 500;
- look->area.height = 500;
if (ob_display == NULL) {
fprintf(stderr, "couldn't connect to X server :0\n");
return 0;
}
- paint(win, look);
+ paint(win, look, w, h);
while (1) {
XNextEvent(ob_display, &report);
switch (report.type) {
case Expose:
break;
case ConfigureNotify:
- look->area.width = report.xconfigure.width;
- look->area.height = report.xconfigure.height;
- paint(win, look);
+ paint(win, look,
+ report.xconfigure.width,
+ report.xconfigure.height);
break;
}
diff --git a/render/theme.c b/render/theme.c
index 2ebcead3..12e54377 100644
--- a/render/theme.c
+++ b/render/theme.c
@@ -515,7 +515,7 @@ char *theme_load(char *theme)
}
/* load the font stuff */
- font_str = "arial:bold:pixelsize=10:minsize";
+ font_str = "arial:bold:pixelsize=10";
theme_winfont_shadow = FALSE;
if (read_string(db, "window.xft.flags", &str)) {
diff --git a/render/theme.h b/render/theme.h
index 2a93c8df..0f87b808 100644
--- a/render/theme.h
+++ b/render/theme.h
@@ -11,7 +11,7 @@ extern int theme_handle_height;
extern int theme_bwidth;
extern int theme_cbwidth;
-#define theme_label_height (theme_winfont_height + 2)
+#define theme_label_height (theme_winfont_height)
#define theme_title_height (theme_label_height + theme_bevel * 2)
#define theme_button_size (theme_label_height - 2)
#define theme_grip_width (theme_button_size * 2)