]> git.sur5r.net Git - glabels/commitdiff
Cleanup of shadows for boxes and ellipses.
authorJim Evins <evins@snaught.com>
Sat, 12 Jun 2010 16:20:29 +0000 (12:20 -0400)
committerJim Evins <evins@snaught.com>
Sat, 12 Jun 2010 16:35:02 +0000 (12:35 -0400)
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.

data/ui/object-editor.ui
src/label-box.c
src/label-ellipse.c

index 395882f9494c11a1e42990c64d4ea334c697f361..43ac7f79fcdcf1f93d1e24228b00cd1bd53ba455 100644 (file)
   <object class="GtkAdjustment" id="adjustment3">
     <property name="value">1</property>
     <property name="lower">0.25</property>
-    <property name="upper">4</property>
+    <property name="upper">10</property>
     <property name="step_increment">0.25</property>
     <property name="page_increment">1</property>
   </object>
index 3088ef109da516c1eb043683fc296b62ef1e4491..c84b0aa8570a5f9c6050f1f4670354c476467fff 100644 (file)
@@ -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");
 }
 
index 5de25a7252d1dd818ff16beba8027a1fff6ede64..0d38e3e25a25aeba8c50105a9af8c725798fdc17 100644 (file)
@@ -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");
 }