draw_text takes a Area as arg

This commit is contained in:
Julien Danjou 2008-01-12 23:47:03 +01:00
parent d59fc62739
commit 17a8c4a4c4
6 changed files with 29 additions and 46 deletions

23
draw.c
View File

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

2
draw.h
View File

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

View File

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

View File

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

View File

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

View File

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