From 21fe1add9e947eb7268834fc2084ea3cf049115d Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Tue, 18 Dec 2007 14:19:41 +1100 Subject: [PATCH] Make drawtext interface more general. --- draw.c | 7 +++---- draw.h | 2 +- widgets/focustitle.c | 6 ++++-- widgets/layoutinfo.c | 3 ++- widgets/taglist.c | 6 +++++- widgets/textbox.c | 4 +++- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/draw.c b/draw.c index 73b71745..5b7bac24 100644 --- a/draw.c +++ b/draw.c @@ -52,7 +52,7 @@ draw_free_context(DrawCtx *ctx) } void -drawtext(DrawCtx *ctx, int x, int y, int w, int h, XftFont *font, const char *text, XColor color[ColLast]) +drawtext(DrawCtx *ctx, int x, int y, int w, int h, XftFont *font, const char *text, XColor fg, XColor bg) { int nw = 0; static char buf[256]; @@ -61,7 +61,7 @@ drawtext(DrawCtx *ctx, int x, int y, int w, int h, XftFont *font, const char *te cairo_surface_t *surface; cairo_t *cr; - drawrectangle(ctx, x, y, w, h, True, color[ColBG]); + drawrectangle(ctx, x, y, w, h, True, bg); if(!a_strlen(text)) return; @@ -70,7 +70,7 @@ drawtext(DrawCtx *ctx, int x, int y, int w, int h, XftFont *font, const char *te font_face = cairo_ft_font_face_create_for_pattern(font->pattern); cairo_set_font_face(cr, font_face); cairo_set_font_size(cr, font->height); - cairo_set_source_rgb(cr, color[ColFG].red / 65535.0, color[ColFG].green / 65535.0, color[ColFG].blue / 65535.0); + cairo_set_source_rgb(cr, fg.red / 65535.0, fg.green / 65535.0, fg.blue / 65535.0); olen = len = a_strlen(text); if(len >= sizeof(buf)) @@ -177,7 +177,6 @@ draw_rotate(DrawCtx *ctx, int screen, double angle, int tx, int ty) return newdrawable; } - unsigned short textwidth_primitive(Display *display, XftFont *font, char *text) { diff --git a/draw.h b/draw.h index 60e21bb6..01c8513a 100644 --- a/draw.h +++ b/draw.h @@ -38,7 +38,7 @@ struct DrawCtx DrawCtx *draw_get_context(Display*, int, int, int); void draw_free_context(DrawCtx*); -void drawtext(DrawCtx *, int, int, int, int, XftFont *, const char *, XColor []); +void drawtext(DrawCtx *, int, int, int, int, XftFont *, const char *, XColor fg, XColor bg); void drawrectangle(DrawCtx *, int, int, int, int, Bool, XColor); void drawcircle(DrawCtx *, int, int, int, Bool, XColor); Drawable draw_rotate(DrawCtx *, int, double, int, int); diff --git a/widgets/focustitle.c b/widgets/focustitle.c index 7bed7497..e05e50d1 100644 --- a/widgets/focustitle.c +++ b/widgets/focustitle.c @@ -22,7 +22,8 @@ focustitle_draw(Widget *widget, DrawCtx *ctx, int offset, int used) { drawtext(ctx, location, 0, vscreen.statusbar.width - used, vscreen.statusbar.height, vscreen.font, sel->name, - vscreen.colors_selected); + vscreen.colors_selected[ColFG], + vscreen.colors_selected[ColBG]); if(sel->isfloating) drawcircle(ctx, location, 0, (vscreen.font->height + 2) / 4, @@ -32,7 +33,8 @@ focustitle_draw(Widget *widget, DrawCtx *ctx, int offset, int used) else drawtext(ctx, location, 0, vscreen.statusbar.width - used, vscreen.statusbar.height, vscreen.font, NULL, - vscreen.colors_normal); + vscreen.colors_normal[ColFG], + vscreen.colors_normal[ColBG]); return vscreen.statusbar.width - used; } diff --git a/widgets/layoutinfo.c b/widgets/layoutinfo.c index 14db8475..405c55bc 100644 --- a/widgets/layoutinfo.c +++ b/widgets/layoutinfo.c @@ -25,7 +25,8 @@ layoutinfo_draw(Widget *widget, vscreen.statusbar.height, vscreen.font, get_current_layout(widget->statusbar->screen)->symbol, - vscreen.colors_normal); + vscreen.colors_normal[ColFG], + vscreen.colors_normal[ColBG]); return width; } diff --git a/widgets/taglist.c b/widgets/taglist.c index bea66f60..f5e49c07 100644 --- a/widgets/taglist.c +++ b/widgets/taglist.c @@ -56,7 +56,11 @@ taglist_draw(Widget *widget, else colors = vscreen.colors_normal; drawtext(ctx, location + width, 0, w, - vscreen.statusbar.height, vscreen.font, tag->name, colors); + vscreen.statusbar.height, + vscreen.font, + tag->name, + colors[ColFG], + colors[ColBG]); if(isoccupied(widget->statusbar->screen, tag)) drawrectangle(ctx, location + width, 0, flagsize, flagsize, sel && is_client_tagged(sel, diff --git a/widgets/textbox.c b/widgets/textbox.c index dac6f308..593cad1e 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -36,7 +36,9 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset, offset, widget->alignment); drawtext(ctx, location, 0, width, vscreen.statusbar.height, - vscreen.font, d->text, vscreen.colors_normal); + vscreen.font, d->text, + vscreen.colors_normal[ColFG], + vscreen.colors_normal[ColBG]); return width; }