[cairo-commit] cairo-gtk-engine/src caligula-draw-shadowed.c, 1.1, 1.2 caligula-draw-shadowed.h, 1.1, 1.2 caligula-style.c, 1.4, 1.5

Carl Worth commit at pdx.freedesktop.org
Fri Feb 11 07:27:28 PST 2005


Committed by: cworth

Update of /cvs/cairo/cairo-gtk-engine/src
In directory gabe:/tmp/cvs-serv30664/src

Modified Files:
	caligula-draw-shadowed.c caligula-draw-shadowed.h 
	caligula-style.c 
Log Message:

        * theme/caligula/gtkrc: Add new caligula-entry style with a bit
        more thickness than default to allow room for soft gradient
        shadow.

        * src/caligula-style.c (caligula_draw_shadow): Add code to draw
        gradient shadows with cairo for GTK_SHADOW_IN, (and defer to
        parent for all other shadows).

        * src/caligula-draw-shadowed.c (caligula_draw_shadowed_inset_box):
        Refine shadow-drawing code to better match Diana's latest
        mockups. Add comments describing what is going on.


Index: caligula-draw-shadowed.c
===================================================================
RCS file: /cvs/cairo/cairo-gtk-engine/src/caligula-draw-shadowed.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- caligula-draw-shadowed.c	9 Feb 2005 22:18:43 -0000	1.1
+++ caligula-draw-shadowed.c	11 Feb 2005 15:27:26 -0000	1.2
@@ -30,35 +30,87 @@
 void
 caligula_draw_shadowed_inset_box (cairo_t *cr,
 				  int x, int y, int width, int height,
-				  int shadow_width, int shadow_height)
+				  double shadow_width, double shadow_height)
 {
     cairo_pattern_t *shadow;
 
     cairo_translate (cr, x, y);
 
+    /* The gradient I'm using here is a piece-wise linear
+     * approximation I made by manually examining Diana's mockup and
+     * progressively adding segments until the visual effect was
+     * pleasing.
+     *
+     * Better would be to write a function to compute the shadow
+     * falloff with some analytic expression.
+     */
+
     /* Left side */
     shadow = cairo_pattern_create_linear (0, 0, shadow_width, 0);
-    cairo_pattern_add_color_stop (shadow, 0.0, 0, 0, 0, 0.45);
-    cairo_pattern_add_color_stop (shadow, 0.5, 0, 0, 0, 0.15);
+    cairo_pattern_add_color_stop (shadow, 0.0, 0, 0, 0, 0.74);
+    cairo_pattern_add_color_stop (shadow, 0.5, 0, 0, 0, 0.25);
+    cairo_pattern_add_color_stop (shadow, 0.75, 0, 0, 0, 0.075);
     cairo_pattern_add_color_stop (shadow, 1.0, 0, 0, 0, 0.0);
     cairo_set_pattern (cr, shadow);
     cairo_rectangle (cr, 0, 0, shadow_width, height);
     cairo_fill (cr);
     cairo_pattern_destroy (shadow);
+
+    /* The left and top shadows are drawn in two separate operations,
+     * one OVER the other. This means we're not really getting the
+     * right effect in the corner. Fixing this probably requires more
+     * general "gradient" support in cairo so we can describe the
+     * whole shadow in a single drawing operation. */
     
     /* Top */
     shadow = cairo_pattern_create_linear (0, 0, 0, shadow_height);
-    cairo_pattern_add_color_stop (shadow, 0.0, 0, 0, 0, 0.45);
-    cairo_pattern_add_color_stop (shadow, 0.5, 0, 0, 0, 0.15);
+    cairo_pattern_add_color_stop (shadow, 0.0, 0, 0, 0, 0.74);
+    cairo_pattern_add_color_stop (shadow, 0.5, 0, 0, 0, 0.25);
+    cairo_pattern_add_color_stop (shadow, 0.75, 0, 0, 0, 0.075);
     cairo_pattern_add_color_stop (shadow, 1.0, 0, 0, 0, 0.0);
     cairo_set_pattern (cr, shadow);
     cairo_rectangle (cr, 0, 0, width, shadow_height);
     cairo_fill (cr);
     cairo_pattern_destroy (shadow);
 
-    /* And just a one-pixel highlight on the right and bottom */
+    /* Put a one-pixel highlight on the right and bottom */
     cairo_set_rgb_color (cr, 1, 1, 1);
     cairo_rectangle (cr, width - 1, 0, 1, height);
     cairo_rectangle (cr, 0, height - 1, width, 1);
     cairo_fill (cr);
+    
+    /* Then a half-sized, half-as-dark shadow just inside the
+     * highlight on the right and bottom.
+     *
+     * Diana's mockup has almost no decoration on the right and bottom
+     * sides, but since GTK+ only gives us symmetric thickness values,
+     * I think we need to at least draw something. What I'm doing here
+     * is modeled something after the default GTK+ theme.
+     */
+    shadow_width /= 2.0;
+    shadow_height /= 2.0;
+    width -= 1;
+    height -= 1;
+
+    /* Right side */
+    shadow = cairo_pattern_create_linear (width, 0, width - shadow_width, 0);
+    cairo_pattern_add_color_stop (shadow, 0.0, 0, 0, 0, 0.37);
+    cairo_pattern_add_color_stop (shadow, 0.5, 0, 0, 0, 0.125);
+    cairo_pattern_add_color_stop (shadow, 0.75, 0, 0, 0, 0.0375);
+    cairo_pattern_add_color_stop (shadow, 1.0, 0, 0, 0, 0.0);
+    cairo_set_pattern (cr, shadow);
+    cairo_rectangle (cr, width - shadow_width, 0, shadow_width, height);
+    cairo_fill (cr);
+    cairo_pattern_destroy (shadow);
+
+    /* Bottom */
+    shadow = cairo_pattern_create_linear (0, height, 0, height - shadow_height);
+    cairo_pattern_add_color_stop (shadow, 0.0, 0, 0, 0, 0.37);
+    cairo_pattern_add_color_stop (shadow, 0.5, 0, 0, 0, 0.125);
+    cairo_pattern_add_color_stop (shadow, 0.75, 0, 0, 0, 0.0375);
+    cairo_pattern_add_color_stop (shadow, 1.0, 0, 0, 0, 0.0);
+    cairo_set_pattern (cr, shadow);
+    cairo_rectangle (cr, 0, height - shadow_height, width, shadow_height);
+    cairo_fill (cr);
+    cairo_pattern_destroy (shadow);
 }

Index: caligula-draw-shadowed.h
===================================================================
RCS file: /cvs/cairo/cairo-gtk-engine/src/caligula-draw-shadowed.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- caligula-draw-shadowed.h	9 Feb 2005 22:18:43 -0000	1.1
+++ caligula-draw-shadowed.h	11 Feb 2005 15:27:26 -0000	1.2
@@ -33,6 +33,6 @@
 void
 caligula_draw_shadowed_inset_box (cairo_t *cr,
 				  int x, int y, int width, int height,
-				  int shadow_width, int shadow_height);
+				  double shadow_width, double shadow_height);
 
 #endif

Index: caligula-style.c
===================================================================
RCS file: /cvs/cairo/cairo-gtk-engine/src/caligula-style.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- caligula-style.c	10 Feb 2005 21:02:07 -0000	1.4
+++ caligula-style.c	11 Feb 2005 15:27:26 -0000	1.5
@@ -70,6 +70,37 @@
 }
 
 static void
+caligula_draw_shadow (GtkStyle      *style,
+		      GdkWindow     *window,
+		      GtkStateType   state_type,
+		      GtkShadowType  shadow_type,
+		      GdkRectangle  *area,
+		      GtkWidget     *widget,
+		      const gchar   *detail,
+		      int            x,
+		      int            y,
+		      int            width,
+		      int            height)
+{
+    cairo_t *cr;
+    int x_offset, y_offset;
+
+    cr = caligula_begin_paint (window, &x_offset, &y_offset);
+
+    if (shadow_type == GTK_SHADOW_IN) {
+	caligula_draw_shadowed_inset_box (cr, x, y, width, height,
+					  style->xthickness, style->ythickness);
+    } else {
+	caligula_style_parent_class->draw_shadow (style, window,
+						  state_type, shadow_type,
+						  area, widget, detail,
+						  x, y, width, height);
+    }
+
+    caligula_end_paint (cr);
+}
+
+static void
 caligula_draw_box (GtkStyle      *style,
 		   GdkWindow     *window,
 		   GtkStateType   state_type,
@@ -168,6 +199,7 @@
 {
     GtkStyleClass *style_class = GTK_STYLE_CLASS (klass);
 
+    style_class->draw_shadow = caligula_draw_shadow;
     style_class->draw_box = caligula_draw_box;
     style_class->draw_flat_box = caligula_draw_flat_box;
     




More information about the cairo-commit mailing list