draw: add support for top and left bg_margin

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-08-19 11:43:45 +02:00
parent 3b895d84ed
commit 4c76b5a1d5
2 changed files with 50 additions and 27 deletions

View File

@ -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 */ /* hack: markup.c validates tags so we can avoid strcmps here */
switch (*elem) { switch (*elem) {
case 'b': case 'b':
if(elem[1] == 'g') /* bg */ if(elem[1] == 'g') /* bg? */
for(; *names; names++, values++) {
switch(a_tokenize(*names, -1)) if(elem[2] == '_') /* bg_margin */
{ for(; *names; names++, values++)
case A_TK_COLOR: switch(a_tokenize(*names, -1))
reqs[++reqs_nbr] = xcolor_init_unchecked(data->connection, {
&data->bg_color, case A_TK_LEFT:
data->phys_screen, data->bg_margin.left = atoi(*values);
*values, break;
a_strlen(*values)); 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; bg_color_nbr = reqs_nbr;
break; break;
case A_TK_IMAGE: case A_TK_IMAGE:
if(data->bg_image) if(data->bg_image)
draw_image_delete(&data->bg_image); draw_image_delete(&data->bg_image);
data->bg_image = draw_image_new(*values); data->bg_image = draw_image_new(*values);
break; break;
case A_TK_ALIGN: case A_TK_ALIGN:
data->bg_align = draw_align_fromstr(*values, -1); data->bg_align = draw_align_fromstr(*values, -1);
break; break;
case A_TK_RESIZE: case A_TK_RESIZE:
data->bg_resize = a_strtobool(*values, -1); data->bg_resize = a_strtobool(*values, -1);
default: default:
break; break;
} }
}
else /* border */ else /* border */
for(; *names; names++, values++) for(; *names; names++, values++)
switch(a_tokenize(*names, -1)) switch(a_tokenize(*names, -1))
@ -301,7 +317,7 @@ bool
draw_text_markup_expand(draw_parser_data_t *data, draw_text_markup_expand(draw_parser_data_t *data,
const char *str, ssize_t slen) 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 = markup_parser_data_t p =
{ {
.elements = elements, .elements = elements,
@ -387,7 +403,10 @@ draw_text(draw_context_t *ctx, font_t *font,
default: default:
break; 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); pango_layout_set_text(ctx->layout, pdata->text, pdata->len);

View File

@ -181,6 +181,10 @@ typedef struct
{ {
int left, right, top; int left, right, top;
} margin; } margin;
struct
{
int top, left;
} bg_margin;
bool has_bg_color; bool has_bg_color;
xcolor_t bg_color; xcolor_t bg_color;
draw_image_t *bg_image; draw_image_t *bg_image;