draw: draw_text takes len as arg

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-07-10 15:35:19 +02:00
parent 36fd44d1a0
commit 5fc500a861
6 changed files with 13 additions and 17 deletions

View File

@ -325,20 +325,17 @@ draw_text_markup_expand(draw_parser_data_t *data,
* \param font The font to use. * \param font The font to use.
* \param area Area to draw to. * \param area Area to draw to.
* \param text Text to draw. * \param text Text to draw.
* \param len Text to draw length.
* \param data Optional parser data. * \param data Optional parser data.
*/ */
void void
draw_text(draw_context_t *ctx, font_t *font, draw_text(draw_context_t *ctx, font_t *font,
area_t area, const char *text, draw_parser_data_t *pdata) area_t area, const char *text, ssize_t len, draw_parser_data_t *pdata)
{ {
int x, y; int x, y;
ssize_t len = 0, olen;
PangoRectangle ext; PangoRectangle ext;
draw_parser_data_t parser_data; draw_parser_data_t parser_data;
if(!(len = a_strlen(text)))
return;
if(!pdata) if(!pdata)
{ {
draw_parser_data_init(&parser_data); draw_parser_data_init(&parser_data);
@ -357,8 +354,6 @@ draw_text(draw_context_t *ctx, font_t *font,
len = pdata->text.len; len = pdata->text.len;
} }
olen = len;
if(pdata->has_bg_color) if(pdata->has_bg_color)
draw_rectangle(ctx, area, 1.0, true, &pdata->bg_color); draw_rectangle(ctx, area, 1.0, true, &pdata->bg_color);

View File

@ -199,7 +199,7 @@ typedef struct
void draw_parser_data_init(draw_parser_data_t *); void draw_parser_data_init(draw_parser_data_t *);
void draw_parser_data_wipe(draw_parser_data_t *); void draw_parser_data_wipe(draw_parser_data_t *);
void draw_text(draw_context_t *, font_t *, area_t, const char *, draw_parser_data_t *); void draw_text(draw_context_t *, font_t *, area_t, const char *, ssize_t len, draw_parser_data_t *);
void draw_rectangle(draw_context_t *, area_t, float, bool, const xcolor_t *); void draw_rectangle(draw_context_t *, area_t, float, bool, const xcolor_t *);
void draw_rectangle_gradient(draw_context_t *, area_t, float, bool, vector_t, void draw_rectangle_gradient(draw_context_t *, area_t, float, bool, vector_t,
const xcolor_t *, const xcolor_t *, const xcolor_t *); const xcolor_t *, const xcolor_t *, const xcolor_t *);

View File

@ -241,11 +241,12 @@ mouse_infobox_draw(draw_context_t *ctx,
{ {
area_t draw_geometry = { 0, 0, ctx->width, ctx->height }; area_t draw_geometry = { 0, 0, ctx->width, ctx->height };
char size[64]; char size[64];
size_t len;
snprintf(size, sizeof(size), "<text align=\"center\"/>%dx%d+%d+%d", len = snprintf(size, sizeof(size), "<text align=\"center\"/>%dx%d+%d+%d",
geometry.width, geometry.height, geometry.x, geometry.y); geometry.width, geometry.height, geometry.x, geometry.y);
draw_rectangle(ctx, draw_geometry, 1.0, true, &globalconf.colors.bg); draw_rectangle(ctx, draw_geometry, 1.0, true, &globalconf.colors.bg);
draw_text(ctx, globalconf.font, draw_geometry, size, NULL); draw_text(ctx, globalconf.font, draw_geometry, size, len, NULL);
simplewindow_move(sw, simplewindow_move(sw,
geometry.x + ((2 * border + geometry.width) - sw->geometry.width) / 2, geometry.x + ((2 * border + geometry.width) - sw->geometry.width) / 2,
geometry.y + ((2 * border + geometry.height) - sw->geometry.height) / 2); geometry.y + ((2 * border + geometry.height) - sw->geometry.height) / 2);

View File

@ -93,10 +93,10 @@ taglist_draw(draw_context_t *ctx, int screen, widget_node_t *w,
area_t area; area_t area;
taglist_drawn_area_t *tda; taglist_drawn_area_t *tda;
int prev_width = 0; int prev_width = 0;
size_t len;
tag_array_t *tags = &globalconf.screens[screen].tags; tag_array_t *tags = &globalconf.screens[screen].tags;
const char **text = p_alloca(const char *, tags->len); const char **text = p_alloca(const char *, tags->len);
size_t *len = p_alloca(size_t, tags->len);
draw_parser_data_t *pdata = p_alloca(draw_parser_data_t, tags->len); draw_parser_data_t *pdata = p_alloca(draw_parser_data_t, tags->len);
w->area.width = w->area.y = 0; w->area.width = w->area.y = 0;
@ -125,13 +125,13 @@ taglist_draw(draw_context_t *ctx, int screen, widget_node_t *w,
luaA_dofunction(globalconf.L, data->label, 1, 1); luaA_dofunction(globalconf.L, data->label, 1, 1);
if(lua_isstring(globalconf.L, -1)) if(lua_isstring(globalconf.L, -1))
text[i] = lua_tolstring(globalconf.L, -1, &len); text[i] = lua_tolstring(globalconf.L, -1, &len[i]);
lua_pop(globalconf.L, 1); lua_pop(globalconf.L, 1);
draw_parser_data_init(&pdata[i]); draw_parser_data_init(&pdata[i]);
area = draw_text_extents(ctx->connection, ctx->phys_screen, area = draw_text_extents(ctx->connection, ctx->phys_screen,
globalconf.font, text[i], len, &pdata[i]); globalconf.font, text[i], len[i], &pdata[i]);
if(pdata[i].bg_image) if(pdata[i].bg_image)
area.width = MAX(area.width, pdata[i].bg_resize ? w->area.height : pdata[i].bg_image->width); area.width = MAX(area.width, pdata[i].bg_resize ? w->area.height : pdata[i].bg_image->width);
@ -159,7 +159,7 @@ taglist_draw(draw_context_t *ctx, int screen, widget_node_t *w,
r->x = w->area.x + prev_width; r->x = w->area.x + prev_width;
prev_width += r->width; prev_width += r->width;
draw_text(ctx, globalconf.font, *r, text[i], &pdata[i]); draw_text(ctx, globalconf.font, *r, text[i], len[i], &pdata[i]);
draw_parser_data_wipe(&pdata[i]); draw_parser_data_wipe(&pdata[i]);
} }

View File

@ -214,7 +214,7 @@ tasklist_draw(draw_context_t *ctx, int screen,
if(i == n - 1) if(i == n - 1)
area.width += box_width_rest; area.width += box_width_rest;
draw_text(ctx, globalconf.font, area, text, NULL); draw_text(ctx, globalconf.font, area, text, len, NULL);
i++; i++;
} }

View File

@ -80,7 +80,7 @@ textbox_draw(draw_context_t *ctx, int screen __attribute__ ((unused)),
w->widget->align); w->widget->align);
w->area.y = 0; w->area.y = 0;
draw_text(ctx, globalconf.font, w->area, d->text, pdata_arg); draw_text(ctx, globalconf.font, w->area, d->text, d->len, pdata_arg);
if (pdata_arg) if (pdata_arg)
draw_parser_data_wipe(pdata_arg); draw_parser_data_wipe(pdata_arg);