draw: add background alignment

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-06-23 18:01:15 +02:00
parent 9ad5f651fe
commit 9caa9fc96f
2 changed files with 17 additions and 1 deletions

View File

@ -226,6 +226,8 @@ draw_markup_on_element(markup_parser_data_t *p, const char *elem,
case A_TK_IMAGE: case A_TK_IMAGE:
data->bg_image = draw_image_new(*values); data->bg_image = draw_image_new(*values);
break; break;
case A_TK_ALIGN:
data->bg_align = draw_align_fromstr(*values, -1);
default: default:
break; break;
} }
@ -338,7 +340,20 @@ draw_text(draw_context_t *ctx, font_t *font,
if(pdata->bg_image) if(pdata->bg_image)
{ {
draw_image(ctx, area.x, area.y, 0, pdata->bg_image); x = area.x;
y = area.y;
switch(pdata->bg_align)
{
case AlignCenter:
x += (area.width - pdata->bg_image->width) / 2;
break;
case AlignRight:
x += area.width- pdata->bg_image->width;
break;
default:
break;
}
draw_image(ctx, x, y, 0, pdata->bg_image);
draw_image_delete(&pdata->bg_image); draw_image_delete(&pdata->bg_image);
} }

View File

@ -167,6 +167,7 @@ typedef struct
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;
alignment_t bg_align;
struct struct
{ {
int offset; int offset;