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 */ /* hack: markup.c validates tags so we can avoid strcmps here */
switch (*elem) { switch (*elem) {
case 'b': /* bg */ case 'b':
for(; *names; names++, values++) if(elem[1] == 'g') /* bg */
switch(a_tokenize(*names, -1)) 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); case A_TK_COLOR:
break; data->has_bg_color = xcolor_init(&data->bg_color, data->connection, data->phys_screen, *values);
case A_TK_IMAGE: break;
if(data->bg_image) case A_TK_IMAGE:
draw_image_delete(&data->bg_image); if(data->bg_image)
data->bg_image = draw_image_new(*values); draw_image_delete(&data->bg_image);
break; data->bg_image = draw_image_new(*values);
case A_TK_ALIGN: break;
data->bg_align = draw_align_fromstr(*values, -1); case A_TK_ALIGN:
case A_TK_RESIZE: data->bg_align = draw_align_fromstr(*values, -1);
data->bg_resize = a_strtobool(*values, -1); case A_TK_RESIZE:
default: data->bg_resize = a_strtobool(*values, -1);
break; 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; break;
case 't': /* text */ case 't': /* text */
for(; *names; names++, values++) for(; *names; names++, values++)
@ -275,7 +289,7 @@ static 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", NULL }; static char const * const elements[] = { "bg", "text", "margin", "border", NULL };
markup_parser_data_t p = markup_parser_data_t p =
{ {
.elements = elements, .elements = elements,
@ -342,6 +356,9 @@ draw_text(draw_context_t *ctx, font_t *font,
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);
if(pdata->border.width > 0)
draw_rectangle(ctx, area, pdata->border.width, false, &pdata->border.color);
if(pdata->bg_image) if(pdata->bg_image)
{ {
x = area.x; x = area.x;

View File

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