[gtk+/icon-shadow: 3/11] themingengine: add gtk_theming_engine_render_icon()



commit 8a75e562f3609614096a878e194cdc9448c9d64e
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Fri May 20 23:50:47 2011 -0400

    themingengine: add gtk_theming_engine_render_icon()

 gtk/gtkthemingengine.c |   71 ++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkthemingengine.h |   10 ++++++-
 2 files changed, 80 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkthemingengine.c b/gtk/gtkthemingengine.c
index 47833a3..69ad087 100644
--- a/gtk/gtkthemingengine.c
+++ b/gtk/gtkthemingengine.c
@@ -176,6 +176,14 @@ static void gtk_theming_engine_render_activity  (GtkThemingEngine *engine,
 static GdkPixbuf * gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine    *engine,
                                                           const GtkIconSource *source,
                                                           GtkIconSize          size);
+static void gtk_theming_engine_render_icon (GtkThemingEngine *engine,
+                                            cairo_t *cr,
+                                            gdouble x,
+                                            gdouble y,
+                                            gdouble width,
+                                            gdouble height,
+                                            cairo_surface_t *surface,
+                                            gboolean symbolic);
 
 G_DEFINE_TYPE (GtkThemingEngine, gtk_theming_engine, G_TYPE_OBJECT)
 
@@ -214,6 +222,7 @@ gtk_theming_engine_class_init (GtkThemingEngineClass *klass)
   object_class->set_property = gtk_theming_engine_impl_set_property;
   object_class->get_property = gtk_theming_engine_impl_get_property;
 
+  klass->render_icon = gtk_theming_engine_render_icon;
   klass->render_check = gtk_theming_engine_render_check;
   klass->render_option = gtk_theming_engine_render_option;
   klass->render_arrow = gtk_theming_engine_render_arrow;
@@ -3175,3 +3184,65 @@ gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine    *engine,
 
   return stated;
 }
+
+static void
+colorshift_surface (cairo_surface_t *surface,
+                    gdouble shift)
+{
+  cairo_t *cr;
+
+  cr = cairo_create (surface);
+  cairo_set_source_rgb (cr, shift, shift, shift);
+  cairo_set_operator (cr, CAIRO_OPERATOR_COLOR_DODGE);
+
+  cairo_mask_surface (cr, surface, 0, 0);
+
+  cairo_destroy (cr);
+}
+
+static void
+gtk_theming_engine_render_icon (GtkThemingEngine *engine,
+                                cairo_t *cr,
+                                gdouble x,
+                                gdouble y,
+                                gdouble width,
+                                gdouble height,
+                                cairo_surface_t *surface,
+                                gboolean symbolic)
+{
+  GtkStateFlags state;
+  GtkShadow *icon_shadow;
+
+  state = gtk_theming_engine_get_state (engine);
+
+  gtk_theming_engine_get (engine, state,
+                          "icon-shadow", &icon_shadow,
+                          NULL);
+
+  if (icon_shadow != NULL)
+    {
+      _gtk_icon_shadow_paint_surface (icon_shadow, cr,
+                                      x, y, width, height,
+                                      surface);
+      _gtk_shadow_unref (icon_shadow);
+    }
+
+  cairo_save (cr);
+
+  if (!symbolic &&
+      (state & GTK_STATE_FLAG_PRELIGHT))
+    colorshift_surface (surface, 0.12);
+
+  cairo_set_source_surface (cr, surface, x, y);
+  cairo_rectangle (cr, x, y, width, height);
+  cairo_clip (cr);
+
+  if (!symbolic &&
+      (state & GTK_STATE_FLAG_INSENSITIVE))
+    cairo_paint_with_alpha (cr, 0.50);
+  else
+    cairo_paint (cr);
+
+  cairo_restore (cr);
+}
+
diff --git a/gtk/gtkthemingengine.h b/gtk/gtkthemingengine.h
index b1d4b95..88cb74a 100644
--- a/gtk/gtkthemingengine.h
+++ b/gtk/gtkthemingengine.h
@@ -168,9 +168,17 @@ struct _GtkThemingEngineClass
   GdkPixbuf * (* render_icon_pixbuf) (GtkThemingEngine    *engine,
                                       const GtkIconSource *source,
                                       GtkIconSize          size);
+  void (* render_icon) (GtkThemingEngine *engine,
+                        cairo_t          *cr,
+                        gdouble           x,
+                        gdouble           y,
+                        gdouble           width,
+                        gdouble           height,
+                        cairo_surface_t  *surface,
+                        gboolean          symbolic);
 
   /*< private >*/
-  gpointer padding[16];
+  gpointer padding[15];
 };
 
 GType gtk_theming_engine_get_type (void) G_GNUC_CONST;



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