From 4c76b5a1d542183bff42bfe9039c0bfab96ee2ba Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 19 Aug 2008 11:43:45 +0200 Subject: [PATCH] draw: add support for top and left bg_margin Signed-off-by: Julien Danjou --- common/draw.c | 73 ++++++++++++++++++++++++++++++++------------------- common/draw.h | 4 +++ 2 files changed, 50 insertions(+), 27 deletions(-) diff --git a/common/draw.c b/common/draw.c index e9f64e614..205d6118c 100644 --- a/common/draw.c +++ b/common/draw.c @@ -207,32 +207,48 @@ draw_markup_on_element(markup_parser_data_t *p, const char *elem, /* hack: markup.c validates tags so we can avoid strcmps here */ switch (*elem) { case 'b': - if(elem[1] == 'g') /* bg */ - for(; *names; names++, values++) - switch(a_tokenize(*names, -1)) - { - case A_TK_COLOR: - reqs[++reqs_nbr] = xcolor_init_unchecked(data->connection, - &data->bg_color, - data->phys_screen, - *values, - a_strlen(*values)); + if(elem[1] == 'g') /* bg? */ + { + if(elem[2] == '_') /* bg_margin */ + for(; *names; names++, values++) + switch(a_tokenize(*names, -1)) + { + case A_TK_LEFT: + data->bg_margin.left = atoi(*values); + break; + case A_TK_TOP: + data->bg_margin.top = atoi(*values); + default: + break; + } + else /* bg */ + for(; *names; names++, values++) + switch(a_tokenize(*names, -1)) + { + case A_TK_COLOR: + reqs[++reqs_nbr] = xcolor_init_unchecked(data->connection, + &data->bg_color, + data->phys_screen, + *values, + a_strlen(*values)); - bg_color_nbr = reqs_nbr; - break; - case A_TK_IMAGE: - if(data->bg_image) - draw_image_delete(&data->bg_image); - data->bg_image = draw_image_new(*values); - break; - case A_TK_ALIGN: - data->bg_align = draw_align_fromstr(*values, -1); - break; - case A_TK_RESIZE: - data->bg_resize = a_strtobool(*values, -1); - default: - break; - } + bg_color_nbr = reqs_nbr; + break; + case A_TK_IMAGE: + if(data->bg_image) + draw_image_delete(&data->bg_image); + data->bg_image = draw_image_new(*values); + break; + case A_TK_ALIGN: + data->bg_align = draw_align_fromstr(*values, -1); + break; + case A_TK_RESIZE: + data->bg_resize = a_strtobool(*values, -1); + default: + break; + } + + } else /* border */ for(; *names; names++, values++) switch(a_tokenize(*names, -1)) @@ -301,7 +317,7 @@ bool draw_text_markup_expand(draw_parser_data_t *data, const char *str, ssize_t slen) { - static char const * const elements[] = { "bg", "text", "margin", "border", NULL }; + static char const * const elements[] = { "bg", "bg_margin", "text", "margin", "border", NULL }; markup_parser_data_t p = { .elements = elements, @@ -387,7 +403,10 @@ draw_text(draw_context_t *ctx, font_t *font, default: break; } - draw_image(ctx, x, y, pdata->bg_resize ? area.height : 0, pdata->bg_image); + draw_image(ctx, + x + pdata->bg_margin.left, + y + pdata->bg_margin.top, + pdata->bg_resize ? area.height : 0, pdata->bg_image); } pango_layout_set_text(ctx->layout, pdata->text, pdata->len); diff --git a/common/draw.h b/common/draw.h index 396d9ee31..39f7eebb5 100644 --- a/common/draw.h +++ b/common/draw.h @@ -181,6 +181,10 @@ typedef struct { int left, right, top; } margin; + struct + { + int top, left; + } bg_margin; bool has_bg_color; xcolor_t bg_color; draw_image_t *bg_image;