[gtk+/wip/hires-icons: 8/9] iconfactory: Add gtk_cairo_set_source_icon_set()



commit e16840171778b0fd98baf4a0b670fbe959137dd5
Author: Carlos Garnacho <carlos lanedo com>
Date:   Fri May 10 18:29:05 2013 +0200

    iconfactory: Add gtk_cairo_set_source_icon_set()
    
    As GtkIconSet remains a good candidate to delay pixbuf lookup until
    the moment of rendering, a cairo helper function has been added
    to easy enabling support for high resolution icons.

 gtk/gtkiconfactory.c |   28 ++++++++++++++++++++++++++++
 gtk/gtkiconfactory.h |    9 +++++++++
 2 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkiconfactory.c b/gtk/gtkiconfactory.c
index bf9957d..8b18bbe 100644
--- a/gtk/gtkiconfactory.c
+++ b/gtk/gtkiconfactory.c
@@ -3199,3 +3199,31 @@ gtk_icon_factory_buildable_custom_tag_end (GtkBuildable *buildable,
       gtk_icon_factory_add_default (icon_factory);
     }
 }
+
+void
+gtk_cairo_set_source_icon_set (cairo_t         *cr,
+                               GtkStyleContext *context,
+                               GtkIconSet      *icon_set,
+                               GtkIconSize      size,
+                               gdouble          scale,
+                               gdouble          icon_x,
+                               gdouble          icon_y)
+{
+  cairo_pattern_t *pattern;
+  cairo_matrix_t matrix;
+  GdkPixbuf *pixbuf;
+
+  g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
+  g_return_if_fail (cr != NULL);
+  g_return_if_fail (icon_set != NULL);
+
+  pixbuf = gtk_icon_set_render_icon_pixbuf_scaled (icon_set, context, size, &scale);
+  gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
+
+  pattern = cairo_get_source (cr);
+  cairo_matrix_init_scale (&matrix, scale, scale);
+  cairo_matrix_translate (&matrix, -icon_x, -icon_y);
+  cairo_pattern_set_matrix (pattern, &matrix);
+
+  g_object_unref (pixbuf);
+}
diff --git a/gtk/gtkiconfactory.h b/gtk/gtkiconfactory.h
index 00a5849..46aca3d 100644
--- a/gtk/gtkiconfactory.h
+++ b/gtk/gtkiconfactory.h
@@ -221,6 +221,15 @@ GDK_AVAILABLE_IN_ALL
 GtkIconSize      gtk_icon_source_get_size                 (const GtkIconSource *source);
 gdouble          gtk_icon_source_get_scale                (const GtkIconSource *source);
 
+/* Cairo helper */
+void             gtk_cairo_set_source_icon_set            (cairo_t             *cr,
+                                                           GtkStyleContext     *context,
+                                                           GtkIconSet          *icon_set,
+                                                           GtkIconSize          size,
+                                                           gdouble              scale,
+                                                           gdouble              icon_x,
+                                                           gdouble              icon_y);
+
 /* ignore this */
 void _gtk_icon_set_invalidate_caches (void);
 GList* _gtk_icon_factory_list_ids (void);


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