From 17a8c4a4c45ee35a974c860510745495495a94d5 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sat, 12 Jan 2008 23:47:03 +0100 Subject: [PATCH] draw_text takes a Area as arg --- draw.c | 23 +++++++++-------------- draw.h | 2 +- widgets/focustitle.c | 18 +++++------------- widgets/taglist.c | 9 ++++++--- widgets/tasklist.c | 19 +++++++------------ widgets/textbox.c | 4 +--- 6 files changed, 29 insertions(+), 46 deletions(-) diff --git a/draw.c b/draw.c index ecfe14ad0..7d467d195 100644 --- a/draw.c +++ b/draw.c @@ -75,8 +75,7 @@ draw_free_context(DrawCtx *ctx) */ void draw_text(DrawCtx *ctx, - int x, int y, - int w, int h, + Area area, int align, int padding, XftFont *font, const char *text, @@ -88,14 +87,8 @@ draw_text(DrawCtx *ctx, cairo_font_face_t *font_face; cairo_surface_t *surface; cairo_t *cr; - Area rectangle; - rectangle.x = x; - rectangle.y = y; - rectangle.width = w; - rectangle.height = h; - - draw_rectangle(ctx, rectangle, True, bg); + draw_rectangle(ctx, area, True, bg); olen = len = a_strlen(text); @@ -113,9 +106,9 @@ draw_text(DrawCtx *ctx, len = sizeof(buf) - 1; memcpy(buf, text, len); buf[len] = 0; - while(len && (nw = (draw_textwidth(font, buf)) + padding * 2) > w) + while(len && (nw = (draw_textwidth(font, buf)) + padding * 2) > area.width) buf[--len] = 0; - if(nw > w) + if(nw > area.width) return; /* too long */ if(len < olen) { @@ -130,13 +123,15 @@ draw_text(DrawCtx *ctx, switch(align) { case AlignLeft: - cairo_move_to(cr, x + padding, y + font->ascent + (ctx->height - font->height) / 2); + cairo_move_to(cr, area.x + padding, area.y + font->ascent + (ctx->height - font->height) / 2); break; case AlignRight: - cairo_move_to(cr, x + (w - nw) + padding, y + font->ascent + (ctx->height - font->height) / 2); + cairo_move_to(cr, area.x + (area.width - nw) + padding, + area.y + font->ascent + (ctx->height - font->height) / 2); break; default: - cairo_move_to(cr, x + ((w - nw) / 2) + padding, y + font->ascent + (ctx->height - font->height) / 2); + cairo_move_to(cr, area.x + ((area.width - nw) / 2) + padding, + area.y + font->ascent + (ctx->height - font->height) / 2); break; } cairo_show_text(cr, buf); diff --git a/draw.h b/draw.h index e44a43b4f..f120f08b1 100644 --- a/draw.h +++ b/draw.h @@ -54,7 +54,7 @@ typedef struct DrawCtx *draw_get_context(int, int, int); void draw_free_context(DrawCtx *); -void draw_text(DrawCtx *, int, int, int, int, int, int, XftFont *, const char *, XColor fg, XColor bg); +void draw_text(DrawCtx *, Area, int, int, XftFont *, const char *, XColor fg, XColor bg); void draw_rectangle(DrawCtx *, Area, Bool, XColor); void draw_graph(DrawCtx *, int, int, int, int *, int, XColor); void draw_circle(DrawCtx *, int, int, int, Bool, XColor); diff --git a/widgets/focustitle.c b/widgets/focustitle.c index 7992c9686..73e4b50b3 100644 --- a/widgets/focustitle.c +++ b/widgets/focustitle.c @@ -53,11 +53,12 @@ focustitle_draw(Widget *widget, DrawCtx *ctx, int offset, int used) if(!widget->user_supplied_y) widget->area.y = 0; + widget->area.width = widget->statusbar->width - used; + widget->area.height = widget->statusbar->height; + if(sel) { - draw_text(ctx, widget->area.x, widget->area.y, - widget->statusbar->width - used, - widget->statusbar->height, + draw_text(ctx, widget->area, d->align, widget->font->height / 2, widget->font, sel->name, d->fg, d->bg); @@ -67,16 +68,7 @@ focustitle_draw(Widget *widget, DrawCtx *ctx, int offset, int used) sel->ismax, d->fg); } else - { - Area rectangle = { widget->area.x, - widget->area.y, - widget->statusbar->width - used, - widget->statusbar->height }; - draw_rectangle(ctx, rectangle, True, d->bg); - } - - widget->area.width = widget->statusbar->width - used; - widget->area.height = widget->statusbar->height; + draw_rectangle(ctx, widget->area, True, d->bg); return widget->area.width; } diff --git a/widgets/taglist.c b/widgets/taglist.c index fd072094e..6d9b57c46 100644 --- a/widgets/taglist.c +++ b/widgets/taglist.c @@ -68,6 +68,7 @@ taglist_draw(Widget *widget, VirtScreen vscreen = globalconf.screens[widget->statusbar->screen]; int w = 0, flagsize; XColor *colors; + Area area; flagsize = (vscreen.font->height + 2) / 3; @@ -95,9 +96,11 @@ taglist_draw(Widget *widget, colors = vscreen.colors_urgent; else colors = vscreen.colors_normal; - draw_text(ctx, - widget->area.x + widget->area.width, widget->area.y, - w, widget->statusbar->height, + area.x = widget->area.x + widget->area.width; + area.y = widget->area.y; + area.width = w; + area.height = widget->statusbar->height; + draw_text(ctx, area, AlignCenter, vscreen.font->height / 2, vscreen.font, diff --git a/widgets/tasklist.c b/widgets/tasklist.c index 3fc349223..553eda01e 100644 --- a/widgets/tasklist.c +++ b/widgets/tasklist.c @@ -111,24 +111,19 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used) } } + area.x = widget->area.x + icon_width + box_width * i; + area.y = widget->area.y; + area.width = box_width - icon_width; + area.height = widget->statusbar->height; if(sel == c) - { - draw_text(ctx, widget->area.x + icon_width + box_width * i, - widget->area.y, - box_width - icon_width, - widget->statusbar->height, - d->align, + draw_text(ctx, area, d->align, widget->font->height / 2, widget->font, c->name, d->fg_sel, d->bg_sel); - } else - draw_text(ctx, widget->area.x + icon_width + box_width * i, - widget->area.y, - box_width - icon_width, - widget->statusbar->height, - d->align, + draw_text(ctx, area, d->align, widget->font->height / 2, widget->font, c->name, d->fg, d->bg); + if(c->isfloating || c->ismax) draw_circle(ctx, widget->area.x + icon_width + box_width * i, widget->area.y, diff --git a/widgets/textbox.c b/widgets/textbox.c index d9af8ef26..16204f0d4 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -56,9 +56,7 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset, if(!widget->user_supplied_y) widget->area.y = 0; - draw_text(ctx, widget->area.x, widget->area.y, widget->area.width, - widget->statusbar->height, d->align, 0, widget->font, - d->text, d->fg, d->bg); + draw_text(ctx, widget->area, d->align, 0, widget->font, d->text, d->fg, d->bg); return widget->area.width; }