From: Jim Evins Date: Sat, 12 Jun 2010 16:20:29 +0000 (-0400) Subject: Cleanup of shadows for boxes and ellipses. X-Git-Tag: glabels-2_3_1~231 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=3f4bd5d778015e524870eeb8bf89ad5bd615eabe;p=glabels Cleanup of shadows for boxes and ellipses. Do a more intelligent job of drawing shadows for boxes and ellipses. Instead of just blindly drawing a fill shadow and an outline shadow, choose to draw one or the other and adjust size of shadow appropriately. --- diff --git a/data/ui/object-editor.ui b/data/ui/object-editor.ui index 395882f9..43ac7f79 100644 --- a/data/ui/object-editor.ui +++ b/data/ui/object-editor.ui @@ -2176,7 +2176,7 @@ 1 0.25 - 4 + 10 0.25 1 diff --git a/src/label-box.c b/src/label-box.c index 3088ef10..c84b0aa8 100644 --- a/src/label-box.c +++ b/src/label-box.c @@ -409,11 +409,11 @@ draw_shadow (glLabelObject *object, glColorNode *shadow_color_node; guint shadow_color; gdouble shadow_opacity; - guint shadow_line_color; - guint shadow_fill_color; gl_debug (DEBUG_LABEL, "START"); + cairo_save (cr); + gl_label_object_get_size (object, &w, &h); line_width = gl_label_object_get_line_width (object); @@ -438,27 +438,50 @@ draw_shadow (glLabelObject *object, shadow_color = GL_COLOR_SHADOW_MERGE_DEFAULT; } shadow_opacity = gl_label_object_get_shadow_opacity (object); - shadow_line_color = gl_color_shadow (shadow_color, shadow_opacity, line_color_node->color); - shadow_fill_color = gl_color_shadow (shadow_color, shadow_opacity, fill_color_node->color); + shadow_color = gl_color_set_opacity (shadow_color, shadow_opacity); - cairo_rectangle (cr, 0.0, 0.0, w, h); + cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (shadow_color)); + if ( GL_COLOR_F_ALPHA (fill_color) ) + { + if ( GL_COLOR_F_ALPHA (line_color) ) + { + /* Has FILL and OUTLINE: adjust size to account for line width. */ + cairo_rectangle (cr, + -line_width/2, -line_width/2, + w+line_width, h+line_width); - /* Draw fill shadow */ - cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (shadow_fill_color)); - cairo_fill_preserve (cr); + } + else + { + /* Has FILL but no OUTLINE. */ + cairo_rectangle (cr, 0.0, 0.0, w, h); + } - /* Draw outline shadow */ - cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (shadow_line_color)); - cairo_set_line_width (cr, line_width); - cairo_stroke (cr); + /* Draw shadow */ + cairo_fill (cr); + } + else + { + if ( GL_COLOR_F_ALPHA (line_color) ) + { + /* Has only OUTLINE. */ + cairo_rectangle (cr, 0.0, 0.0, w, h); + + /* Draw shadow of outline */ + cairo_set_line_width (cr, line_width); + cairo_stroke (cr); + } + } gl_color_node_free (&line_color_node); gl_color_node_free (&fill_color_node); gl_color_node_free (&shadow_color_node); + cairo_restore (cr); + gl_debug (DEBUG_LABEL, "END"); } diff --git a/src/label-ellipse.c b/src/label-ellipse.c index 5de25a72..0d38e3e2 100644 --- a/src/label-ellipse.c +++ b/src/label-ellipse.c @@ -410,11 +410,11 @@ draw_shadow (glLabelObject *object, glColorNode *shadow_color_node; guint shadow_color; gdouble shadow_opacity; - guint shadow_line_color; - guint shadow_fill_color; gl_debug (DEBUG_LABEL, "START"); + cairo_save (cr); + gl_label_object_get_size (object, &w, &h); line_width = gl_label_object_get_line_width (object); @@ -439,27 +439,49 @@ draw_shadow (glLabelObject *object, shadow_color = GL_COLOR_SHADOW_MERGE_DEFAULT; } shadow_opacity = gl_label_object_get_shadow_opacity (object); - shadow_line_color = gl_color_shadow (shadow_color_node->color, shadow_opacity, line_color_node->color); - shadow_fill_color = gl_color_shadow (shadow_color_node->color, shadow_opacity, fill_color_node->color); + shadow_color = gl_color_set_opacity (shadow_color, shadow_opacity); - gl_cairo_ellipse_path (cr, w/2, h/2); + cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (shadow_color)); + if ( GL_COLOR_F_ALPHA (fill_color) ) + { + if ( GL_COLOR_F_ALPHA (line_color) ) + { + /* Has FILL and OUTLINE: adjust size to account for line width. */ + cairo_translate (cr, -line_width/2, -line_width/2); + gl_cairo_ellipse_path (cr, (w+line_width)/2, (h+line_width)/2); - /* Draw fill shadow */ - cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (shadow_fill_color)); - cairo_fill_preserve (cr); + } + else + { + /* Has FILL but no OUTLINE. */ + gl_cairo_ellipse_path (cr, w/2, h/2); + } - /* Draw outline shadow */ - cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (shadow_line_color)); - cairo_set_line_width (cr, line_width); - cairo_stroke (cr); + /* Draw shadow */ + cairo_fill (cr); + } + else + { + if ( GL_COLOR_F_ALPHA (line_color) ) + { + /* Has only OUTLINE. */ + gl_cairo_ellipse_path (cr, w/2, h/2); + + /* Draw shadow of outline */ + cairo_set_line_width (cr, line_width); + cairo_stroke (cr); + } + } gl_color_node_free (&line_color_node); gl_color_node_free (&fill_color_node); gl_color_node_free (&shadow_color_node); + cairo_restore (cr); + gl_debug (DEBUG_LABEL, "END"); }