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 void
draw_text(DrawCtx *ctx, draw_text(DrawCtx *ctx,
int x, int y, Area area,
int w, int h,
int align, int align,
int padding, int padding,
XftFont *font, const char *text, XftFont *font, const char *text,
@ -88,14 +87,8 @@ draw_text(DrawCtx *ctx,
cairo_font_face_t *font_face; cairo_font_face_t *font_face;
cairo_surface_t *surface; cairo_surface_t *surface;
cairo_t *cr; cairo_t *cr;
Area rectangle;
rectangle.x = x; draw_rectangle(ctx, area, True, bg);
rectangle.y = y;
rectangle.width = w;
rectangle.height = h;
draw_rectangle(ctx, rectangle, True, bg);
olen = len = a_strlen(text); olen = len = a_strlen(text);
@ -113,9 +106,9 @@ draw_text(DrawCtx *ctx,
len = sizeof(buf) - 1; len = sizeof(buf) - 1;
memcpy(buf, text, len); memcpy(buf, text, len);
buf[len] = 0; 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; buf[--len] = 0;
if(nw > w) if(nw > area.width)
return; /* too long */ return; /* too long */
if(len < olen) if(len < olen)
{ {
@ -130,13 +123,15 @@ draw_text(DrawCtx *ctx,
switch(align) switch(align)
{ {
case AlignLeft: 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; break;
case AlignRight: 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; break;
default: 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; break;
} }
cairo_show_text(cr, buf); cairo_show_text(cr, buf);

2
draw.h
View File

@ -54,7 +54,7 @@ typedef struct
DrawCtx *draw_get_context(int, int, int); DrawCtx *draw_get_context(int, int, int);
void draw_free_context(DrawCtx *); 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_rectangle(DrawCtx *, Area, Bool, XColor);
void draw_graph(DrawCtx *, int, int, int, int *, int, XColor); void draw_graph(DrawCtx *, int, int, int, int *, int, XColor);
void draw_circle(DrawCtx *, int, int, int, Bool, 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) if(!widget->user_supplied_y)
widget->area.y = 0; widget->area.y = 0;
widget->area.width = widget->statusbar->width - used;
widget->area.height = widget->statusbar->height;
if(sel) if(sel)
{ {
draw_text(ctx, widget->area.x, widget->area.y, draw_text(ctx, widget->area,
widget->statusbar->width - used,
widget->statusbar->height,
d->align, d->align,
widget->font->height / 2, widget->font, sel->name, widget->font->height / 2, widget->font, sel->name,
d->fg, d->bg); d->fg, d->bg);
@ -67,16 +68,7 @@ focustitle_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
sel->ismax, d->fg); sel->ismax, d->fg);
} }
else else
{ draw_rectangle(ctx, widget->area, True, d->bg);
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;
return widget->area.width; return widget->area.width;
} }

View File

@ -68,6 +68,7 @@ taglist_draw(Widget *widget,
VirtScreen vscreen = globalconf.screens[widget->statusbar->screen]; VirtScreen vscreen = globalconf.screens[widget->statusbar->screen];
int w = 0, flagsize; int w = 0, flagsize;
XColor *colors; XColor *colors;
Area area;
flagsize = (vscreen.font->height + 2) / 3; flagsize = (vscreen.font->height + 2) / 3;
@ -95,9 +96,11 @@ taglist_draw(Widget *widget,
colors = vscreen.colors_urgent; colors = vscreen.colors_urgent;
else else
colors = vscreen.colors_normal; colors = vscreen.colors_normal;
draw_text(ctx, area.x = widget->area.x + widget->area.width;
widget->area.x + widget->area.width, widget->area.y, area.y = widget->area.y;
w, widget->statusbar->height, area.width = w;
area.height = widget->statusbar->height;
draw_text(ctx, area,
AlignCenter, AlignCenter,
vscreen.font->height / 2, vscreen.font->height / 2,
vscreen.font, 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) if(sel == c)
{ draw_text(ctx, area, d->align,
draw_text(ctx, widget->area.x + icon_width + box_width * i,
widget->area.y,
box_width - icon_width,
widget->statusbar->height,
d->align,
widget->font->height / 2, widget->font, c->name, widget->font->height / 2, widget->font, c->name,
d->fg_sel, d->bg_sel); d->fg_sel, d->bg_sel);
}
else else
draw_text(ctx, widget->area.x + icon_width + box_width * i, draw_text(ctx, area, d->align,
widget->area.y,
box_width - icon_width,
widget->statusbar->height,
d->align,
widget->font->height / 2, widget->font, c->name, widget->font->height / 2, widget->font, c->name,
d->fg, d->bg); d->fg, d->bg);
if(c->isfloating || c->ismax) if(c->isfloating || c->ismax)
draw_circle(ctx, widget->area.x + icon_width + box_width * i, draw_circle(ctx, widget->area.x + icon_width + box_width * i,
widget->area.y, widget->area.y,

View File

@ -56,9 +56,7 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset,
if(!widget->user_supplied_y) if(!widget->user_supplied_y)
widget->area.y = 0; widget->area.y = 0;
draw_text(ctx, widget->area.x, widget->area.y, widget->area.width, draw_text(ctx, widget->area, d->align, 0, widget->font, d->text, d->fg, d->bg);
widget->statusbar->height, d->align, 0, widget->font,
d->text, d->fg, d->bg);
return widget->area.width; return widget->area.width;
} }