From 8af24939bd9f54bfe785089abcb3f29a9a716d97 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Mon, 28 Apr 2008 16:16:02 +0200 Subject: [PATCH] [draw] Rework shadow Signed-off-by: Julien Danjou --- common/configopts.c | 2 +- common/draw.c | 38 +++++++++++++++++++++++++------------- common/draw.h | 11 ++++++++--- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/common/configopts.c b/common/configopts.c index c659c6ca6..40bcde31a 100644 --- a/common/configopts.c +++ b/common/configopts.c @@ -165,7 +165,7 @@ cfg_opt_t style_opts[] = /** Foreground color. */ CFG_STR((char *) "fg", NULL, CFGF_NONE), /** Shadow color. */ - CFG_STR((char *) "shadow", NULL, CFGF_NONE), + CFG_STR((char *) "shadow_color", NULL, CFGF_NONE), /** Shadow offset in pixels. */ CFG_INT((char *) "shadow_offset", 0xffffffff, CFGF_NONE), /** Font to use. */ diff --git a/common/draw.c b/common/draw.c index fab41c4dd..da398207d 100644 --- a/common/draw.c +++ b/common/draw.c @@ -227,6 +227,7 @@ typedef struct } margin; bool has_bg_color; xcolor_t bg_color; + shadow_t shadow; } draw_parser_data_t; static bool @@ -252,8 +253,15 @@ draw_text_markup_expand(draw_parser_data_t *data, /* text */ if(p->attribute_names[1]) for(i = 0; p->attribute_names[1][i]; i++) + { if(!a_strcmp(p->attribute_names[1][i], "align")) data->align = draw_align_get_from_str(p->attribute_values[1][i]); + else if(!a_strcmp(p->attribute_names[1][i], "shadow")) + draw_color_new(data->connection, data->phys_screen, + p->attribute_values[1][i], &data->shadow.color); + else if(!a_strcmp(p->attribute_names[1][i], "shadow_offset")) + data->shadow.offset = atoi(p->attribute_values[1][i]); + } /* margin */ if(p->attribute_names[2]) @@ -286,8 +294,8 @@ draw_text(draw_context_t *ctx, area_t area, const char *text, style_t style) int x, y; ssize_t len, olen; char *buf = NULL, *utf8 = NULL; - xcolor_t *bg_color = NULL; PangoRectangle ext; + shadow_t shadow; draw_parser_data_t parser_data; if(!(len = a_strlen(text))) @@ -313,10 +321,7 @@ draw_text(draw_context_t *ctx, area_t area, const char *text, style_t style) len = olen = a_strlen(buf); if(parser_data.has_bg_color) - { draw_rectangle(ctx, area, 1.0, true, parser_data.bg_color); - p_delete(&bg_color); - } else draw_rectangle(ctx, area, 1.0, true, style.bg); @@ -347,19 +352,26 @@ draw_text(draw_context_t *ctx, area_t area, const char *text, style_t style) break; } - cairo_move_to(ctx->cr, x, y); - if(style.shadow_offset > 0) + p_clear(&shadow, 1); + if(parser_data.shadow.offset) + shadow = parser_data.shadow; + else if(style.shadow.offset) + shadow = style.shadow; + + if(shadow.offset) { cairo_set_source_rgb(ctx->cr, - style.shadow.red / 65535.0, - style.shadow.green / 65535.0, - style.shadow.blue / 65535.0); - cairo_move_to(ctx->cr, x + style.shadow_offset, y + style.shadow_offset); + shadow.color.red / 65535.0, + shadow.color.green / 65535.0, + shadow.color.blue / 65535.0); + cairo_move_to(ctx->cr, x + shadow.offset, y + shadow.offset); pango_cairo_update_layout(ctx->cr, ctx->layout); pango_cairo_show_layout(ctx->cr, ctx->layout); } + cairo_move_to(ctx->cr, x, y); + cairo_set_source_rgb(ctx->cr, style.fg.red / 65535.0, style.fg.green / 65535.0, @@ -1111,12 +1123,12 @@ draw_style_init(xcb_connection_t *conn, int phys_screen, cfg_t *cfg, cfg_getstr(cfg, "border"), &c->border); draw_color_new(conn, phys_screen, - cfg_getstr(cfg, "shadow"), &c->shadow); + cfg_getstr(cfg, "shadow_color"), &c->shadow.color); if((shadow = cfg_getint(cfg, "shadow_offset")) != (int) 0xffffffff) - c->shadow_offset = shadow; + c->shadow.offset = shadow; else if(!m) - c->shadow_offset = 0; + c->shadow.offset = 0; } /** Remove a area from a list of them, diff --git a/common/draw.h b/common/draw.h index 1b1ddca66..e907ae861 100644 --- a/common/draw.h +++ b/common/draw.h @@ -88,6 +88,13 @@ typedef struct int height; } font_t; +typedef struct +{ + int offset; + xcolor_t color; +} shadow_t; + +/** Style structure */ typedef struct { /** Foreground color */ @@ -95,11 +102,9 @@ typedef struct /** Background color */ xcolor_t bg; /** Shadow color */ - xcolor_t shadow; + shadow_t shadow; /** Border color */ xcolor_t border; - /** Shadow offset */ - int shadow_offset; /** Font */ font_t *font; } style_t;