[gtk+/wip/blur-2: 4/5] WIP for icon shadow, add blur to _gtk_icon_shadow_paint ()



commit 4e63b6e7d946ae05e2b7ad178eb16e46b90a6907
Author: Andrea Cimitan <andrea cimitan canonical com>
Date:   Mon Apr 16 13:02:59 2012 +0100

    WIP for icon shadow, add blur to _gtk_icon_shadow_paint ()

 gtk/gtkshadow.c        |   64 +++++++++++++++++++++++++++++++++++++++++------
 gtk/gtkshadowprivate.h |   15 ++++++----
 gtk/gtkthemingengine.c |   19 ++++++++++++-
 3 files changed, 81 insertions(+), 17 deletions(-)
---
diff --git a/gtk/gtkshadow.c b/gtk/gtkshadow.c
index dc3ffe2..cac4b59 100644
--- a/gtk/gtkshadow.c
+++ b/gtk/gtkshadow.c
@@ -322,8 +322,9 @@ _gtk_text_shadow_paint_layout (GtkShadow       *shadow,
 }
 
 void
-_gtk_icon_shadow_paint (GtkShadow *shadow,
-			cairo_t *cr)
+_gtk_icon_shadow_paint (GtkShadow        *shadow,
+                        cairo_t          *cr,
+                        cairo_rectangle_t rect)
 {
   GList *l;
   GtkShadowElement *element;
@@ -335,10 +336,54 @@ _gtk_icon_shadow_paint (GtkShadow *shadow,
 
       cairo_save (cr);
       pattern = cairo_pattern_reference (cairo_get_source (cr));
-      gdk_cairo_set_source_rgba (cr, &element->color);
 
-      cairo_translate (cr, element->hoffset, element->voffset);
-      cairo_mask (cr, pattern);
+      if (element->radius > 0)
+        {
+          cairo_t *cr_surface;
+          cairo_surface_t *surface;
+          gint bradius;
+          gdouble x, y;
+
+          bradius = element->radius;
+
+          /* Calculate coordinates. */
+          x = rect.x + element->hoffset;
+          y = rect.y + element->voffset;
+
+          /* Create a larger surface to center the blur. */
+          surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+                                                rect.width + bradius * 2,
+                                                rect.height + bradius * 2);
+          cr_surface = cairo_create (surface); 
+
+          /* Center the rendering. */
+          cairo_translate (cr_surface,
+                           bradius,
+                           bradius);
+
+          /* Create the path on the surface to blur. */
+          gdk_cairo_set_source_rgba (cr_surface, &element->color);
+          cairo_mask (cr_surface, pattern);
+
+          /* Blur the surface. */
+          _gtk_cairo_blur_surface (surface, bradius);
+
+          /* Paint the blurred surface to cr. */
+          cairo_set_source_surface (cr, surface,
+                                    x - bradius,
+                                    y - bradius); 
+          cairo_paint (cr);
+
+          cairo_destroy (cr_surface);
+          cairo_surface_destroy (surface); 
+        }
+      else
+        {
+          gdk_cairo_set_source_rgba (cr, &element->color);
+
+          cairo_translate (cr, element->hoffset, element->voffset);
+          cairo_mask (cr, pattern);
+        }
 
       cairo_restore (cr);
       cairo_pattern_destroy (pattern);
@@ -346,10 +391,11 @@ _gtk_icon_shadow_paint (GtkShadow *shadow,
 }
 
 void
-_gtk_icon_shadow_paint_spinner (GtkShadow *shadow,
-                                cairo_t   *cr,
-                                gdouble    radius,
-                                gdouble    progress)
+_gtk_icon_shadow_paint_spinner (GtkShadow        *shadow,
+                                cairo_t          *cr,
+                                cairo_rectangle_t rect,
+                                gdouble           radius,
+                                gdouble           progress)
 {
   GtkShadowElement *element;
   GList *l;
diff --git a/gtk/gtkshadowprivate.h b/gtk/gtkshadowprivate.h
index cd479f0..ea3bf0c 100644
--- a/gtk/gtkshadowprivate.h
+++ b/gtk/gtkshadowprivate.h
@@ -59,13 +59,16 @@ void       _gtk_text_shadow_paint_layout (GtkShadow       *shadow,
                                           cairo_t         *cr,
                                           PangoLayout     *layout);
 
-void       _gtk_icon_shadow_paint        (GtkShadow *shadow,
-					  cairo_t *cr);
+void       _gtk_icon_shadow_paint        (GtkShadow        *shadow,
+                                          cairo_t          *cr,
+                                          cairo_rectangle_t rect);
+
+void       _gtk_icon_shadow_paint_spinner (GtkShadow        *shadow,
+                                           cairo_t          *cr,
+                                           cairo_rectangle_t rect,
+                                           gdouble           radius,
+                                           gdouble           progress);
 
-void       _gtk_icon_shadow_paint_spinner (GtkShadow *shadow,
-                                           cairo_t   *cr,
-                                           gdouble    radius,
-                                           gdouble    progress);
 void       _gtk_box_shadow_render         (GtkShadow           *shadow,
                                            cairo_t             *cr,
                                            const GtkRoundedBox *padding_box);
diff --git a/gtk/gtkthemingengine.c b/gtk/gtkthemingengine.c
index d5eb10b..0ca4e6d 100644
--- a/gtk/gtkthemingengine.c
+++ b/gtk/gtkthemingengine.c
@@ -2778,7 +2778,15 @@ render_spinner (GtkThemingEngine *engine,
 
   if (shadow != NULL)
     {
+      cairo_rectangle_t rect;
+
+      rect.x = x;
+      rect.y = y;
+      rect.width = radius;
+      rect.height = radius;
+      
       _gtk_icon_shadow_paint_spinner (shadow, cr,
+                                      rect,
                                       radius,
                                       progress);
       _gtk_shadow_unref (shadow);
@@ -2945,7 +2953,7 @@ gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine    *engine,
 static void
 gtk_theming_engine_render_icon (GtkThemingEngine *engine,
                                 cairo_t *cr,
-				GdkPixbuf *pixbuf,
+                                GdkPixbuf *pixbuf,
                                 gdouble x,
                                 gdouble y)
 {
@@ -2964,7 +2972,14 @@ gtk_theming_engine_render_icon (GtkThemingEngine *engine,
 
   if (icon_shadow != NULL)
     {
-      _gtk_icon_shadow_paint (icon_shadow, cr);
+      cairo_rectangle_t rect;
+
+      rect.x = x;
+      rect.y = y;
+      rect.width = gdk_pixbuf_get_width (pixbuf);
+      rect.height = gdk_pixbuf_get_height (pixbuf);
+
+      _gtk_icon_shadow_paint (icon_shadow, cr, rect);
       _gtk_shadow_unref (icon_shadow);
     }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]