draw: add support for border around text

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-07-09 10:25:29 +02:00
parent 9c495c0dee
commit ddae6f76b2
2 changed files with 42 additions and 20 deletions

View File

@ -216,25 +216,39 @@ 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': /* bg */
for(; *names; names++, values++)
switch(a_tokenize(*names, -1))
{
case A_TK_COLOR:
data->has_bg_color = xcolor_init(&data->bg_color, data->connection, data->phys_screen, *values);
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);
case A_TK_RESIZE:
data->bg_resize = a_strtobool(*values, -1);
default:
break;
}
case 'b':
if(elem[1] == 'g') /* bg */
for(; *names; names++, values++)
switch(a_tokenize(*names, -1))
{
case A_TK_COLOR:
data->has_bg_color = xcolor_init(&data->bg_color, data->connection, data->phys_screen, *values);
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);
case A_TK_RESIZE:
data->bg_resize = a_strtobool(*values, -1);
default:
break;
}
else /* border */
for(; *names; names++, values++)
switch(a_tokenize(*names, -1))
{
case A_TK_COLOR:
xcolor_init(&data->border.color, data->connection, data->phys_screen, *values);
break;
case A_TK_WIDTH:
data->border.width = atoi(*values);
break;
default:
break;
}
break;
case 't': /* text */
for(; *names; names++, values++)
@ -275,7 +289,7 @@ static bool
draw_text_markup_expand(draw_parser_data_t *data,
const char *str, ssize_t slen)
{
static char const * const elements[] = { "bg", "text", "margin", NULL };
static char const * const elements[] = { "bg", "text", "margin", "border", NULL };
markup_parser_data_t p =
{
.elements = elements,
@ -342,6 +356,9 @@ draw_text(draw_context_t *ctx, font_t *font,
if(pdata->has_bg_color)
draw_rectangle(ctx, area, 1.0, true, &pdata->bg_color);
if(pdata->border.width > 0)
draw_rectangle(ctx, area, pdata->border.width, false, &pdata->border.color);
if(pdata->bg_image)
{
x = area.x;

View File

@ -189,6 +189,11 @@ typedef struct
int offset;
xcolor_t color;
} shadow;
struct
{
int width;
xcolor_t color;
} border;
} draw_parser_data_t;
void draw_parser_data_init(draw_parser_data_t *);