Make drawtext interface more general.

This commit is contained in:
Aldo Cortesi 2007-12-18 14:19:41 +11:00 committed by Julien Danjou
parent 4723ab3627
commit 21fe1add9e
6 changed files with 18 additions and 10 deletions

7
draw.c
View File

@ -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)
{

2
draw.h
View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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,

View File

@ -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;
}