[gtk+/wip/window-scales: 68/84] stylecontext: add gtk_render_icon_pattern



commit 48cb4d24328710804c105ae0442c70713460c4d0
Author: Alexander Larsson <alexl redhat com>
Date:   Mon Jun 24 12:35:39 2013 +0200

    stylecontext: add gtk_render_icon_pattern
    
    This draws an icon from a cairo_pattern. We want to use this more rather
    than render_icon as this means we can skip the pixbuf to surface
    conversion (including allocation and alpha premultiplication) at
    render time, plus we can use create_similar_image which may allow
    faster rendering.

 gtk/gtkstylecontext.c  |   36 ++++++++++++++++++++++++++++++++++++
 gtk/gtkstylecontext.h  |    6 ++++++
 gtk/gtkthemingengine.c |   26 ++++++++++++++++++++++++++
 gtk/gtkthemingengine.h |    8 +++++++-
 4 files changed, 75 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 36ab00d..1f26ce6 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -4457,6 +4457,42 @@ gtk_render_icon (GtkStyleContext *context,
   cairo_restore (cr);
 }
 
+/**
+ * gtk_render_icon_pattern:
+ * @context: a #GtkStyleContext
+ * @cr: a #cairo_t
+ * @pattern: a #cairo_pattern_t containing the icon to draw
+ * @x: X position for the @pixbuf
+ * @y: Y position for the @pixbuf
+ *
+ * Renders the icon in @pixbuf at the specified @x and @y coordinates.
+ *
+ * Since: 3.10
+ **/
+void
+gtk_render_icon_pattern (GtkStyleContext *context,
+                        cairo_t         *cr,
+                        cairo_pattern_t *pattern,
+                        gdouble          x,
+                        gdouble          y)
+{
+  GtkThemingEngineClass *engine_class;
+  GtkThemingEngine *engine;
+
+  g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
+  g_return_if_fail (cr != NULL);
+
+  engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, 
GTK_CSS_PROPERTY_ENGINE));
+  engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
+
+  cairo_save (cr);
+
+  _gtk_theming_engine_set_context (engine, context);
+  engine_class->render_icon_pattern (engine, cr, pattern, x, y);
+
+  cairo_restore (cr);
+}
+
 static void
 draw_insertion_cursor (GtkStyleContext *context,
                        cairo_t         *cr,
diff --git a/gtk/gtkstylecontext.h b/gtk/gtkstylecontext.h
index 85ebf20..a7719f0 100644
--- a/gtk/gtkstylecontext.h
+++ b/gtk/gtkstylecontext.h
@@ -1084,6 +1084,12 @@ void        gtk_render_icon        (GtkStyleContext     *context,
                                     GdkPixbuf           *pixbuf,
                                     gdouble              x,
                                     gdouble              y);
+GDK_AVAILABLE_IN_3_10
+void        gtk_render_icon_pattern (GtkStyleContext    *context,
+                                    cairo_t            *cr,
+                                    cairo_pattern_t    *pattern,
+                                    gdouble             x,
+                                    gdouble             y);
 GDK_AVAILABLE_IN_3_4
 void        gtk_render_insertion_cursor
                                    (GtkStyleContext     *context,
diff --git a/gtk/gtkthemingengine.c b/gtk/gtkthemingengine.c
index 8e71adb..2ce3e10 100644
--- a/gtk/gtkthemingengine.c
+++ b/gtk/gtkthemingengine.c
@@ -182,6 +182,11 @@ static void gtk_theming_engine_render_icon (GtkThemingEngine *engine,
                                            GdkPixbuf *pixbuf,
                                             gdouble x,
                                             gdouble y);
+static void gtk_theming_engine_render_icon_pattern (GtkThemingEngine *engine,
+                                                   cairo_t *cr,
+                                                   cairo_pattern_t *pattern,
+                                                   gdouble x,
+                                                   gdouble y);
 
 G_DEFINE_TYPE (GtkThemingEngine, gtk_theming_engine, G_TYPE_OBJECT)
 
@@ -239,6 +244,7 @@ gtk_theming_engine_class_init (GtkThemingEngineClass *klass)
   klass->render_handle = gtk_theming_engine_render_handle;
   klass->render_activity = gtk_theming_engine_render_activity;
   klass->render_icon_pixbuf = gtk_theming_engine_render_icon_pixbuf;
+  klass->render_icon_pattern = gtk_theming_engine_render_icon_pattern;
 
   /**
    * GtkThemingEngine:name:
@@ -2791,3 +2797,23 @@ gtk_theming_engine_render_icon (GtkThemingEngine *engine,
   cairo_restore (cr);
 }
 
+static void
+gtk_theming_engine_render_icon_pattern (GtkThemingEngine *engine,
+                                       cairo_t *cr,
+                                       cairo_pattern_t *pattern,
+                                       gdouble x,
+                                       gdouble y)
+{
+  cairo_save (cr);
+
+  cairo_translate (cr, x, y);
+  cairo_set_source (cr, pattern);
+
+
+  _gtk_css_shadows_value_paint_icon (_gtk_theming_engine_peek_property (engine, 
GTK_CSS_PROPERTY_ICON_SHADOW), cr);
+
+  cairo_paint (cr);
+
+  cairo_restore (cr);
+}
+
diff --git a/gtk/gtkthemingengine.h b/gtk/gtkthemingengine.h
index a3c48f2..3e05f16 100644
--- a/gtk/gtkthemingengine.h
+++ b/gtk/gtkthemingengine.h
@@ -70,6 +70,7 @@ struct _GtkThemingEngine
  *                   or #GtkProgressBar.
  * @render_icon_pixbuf: Renders an icon as a #GdkPixbuf.
  * @render_icon: Renders an icon given as a #GdkPixbuf.
+ * @render_icon_pattern: Renders an icon given as a #cairo_pattern_t.
  *
  * Base class for theming engines.
  */
@@ -174,9 +175,14 @@ struct _GtkThemingEngineClass
                        GdkPixbuf        *pixbuf,
                         gdouble           x,
                         gdouble           y);
+  void (* render_icon_pattern) (GtkThemingEngine *engine,
+                               cairo_t          *cr,
+                               cairo_pattern_t  *pattern,
+                               gdouble           x,
+                               gdouble           y);
 
   /*< private >*/
-  gpointer padding[15];
+  gpointer padding[14];
 };
 
 GDK_AVAILABLE_IN_ALL


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