[gtk+/wip/hires-icons: 8/11] iconhelper: Use GtkIconSet and gtk_cairo_set_source_icon_set() to render high-res icons



commit f90b8404c5405efa29556523b9aa25a742eca9ed
Author: Carlos Garnacho <carlos lanedo com>
Date:   Fri May 10 18:31:54 2013 +0200

    iconhelper: Use GtkIconSet and gtk_cairo_set_source_icon_set() to render high-res icons
    
    Now GtkIconSets are preferred over GdkPixbufs if the storage type goes through
    these.
    
    An scale argument has been added to _gtk_icon_helper_draw() to let callers tell
    the output scale factor, as those typically have a GdkWindow around to fetch it
    from, all callers were updated too.

 gtk/gtkcellrendererpixbuf.c |    1 +
 gtk/gtkentry.c              |    1 +
 gtk/gtkiconhelper.c         |   65 +++++++++++++++++++++++--------------------
 gtk/gtkiconhelperprivate.h  |    1 +
 gtk/gtkimage.c              |    3 +-
 gtk/gtkspinbutton.c         |    1 +
 6 files changed, 41 insertions(+), 31 deletions(-)
---
diff --git a/gtk/gtkcellrendererpixbuf.c b/gtk/gtkcellrendererpixbuf.c
index 90fc9fe..62f6f65 100644
--- a/gtk/gtkcellrendererpixbuf.c
+++ b/gtk/gtkcellrendererpixbuf.c
@@ -549,6 +549,7 @@ gtk_cell_renderer_pixbuf_render (GtkCellRenderer      *cell,
 
   _gtk_icon_helper_draw (icon_helper,
                          context, cr,
+                         gtk_widget_get_scale_factor (widget),
                          pix_rect.x, pix_rect.y);
   g_object_unref (icon_helper);
 
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index 3fefc24..c139184 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -3641,6 +3641,7 @@ draw_icon (GtkWidget            *widget,
 
   _gtk_icon_helper_draw (icon_info->icon_helper,
                          context, cr,
+                         gtk_widget_get_scale_factor (widget),
                          x, y);
 
   gtk_style_context_restore (context);
diff --git a/gtk/gtkiconhelper.c b/gtk/gtkiconhelper.c
index 58ae8a1..29e9de0 100644
--- a/gtk/gtkiconhelper.c
+++ b/gtk/gtkiconhelper.c
@@ -267,18 +267,6 @@ ensure_pixbuf_for_icon_name_or_gicon (GtkIconHelper *self,
 }
 
 static void
-ensure_pixbuf_for_icon_set (GtkIconHelper *self,
-                            GtkStyleContext *context,
-                            GtkIconSet *icon_set)
-{
-  if (!check_invalidate_pixbuf (self, context))
-    return;
-
-  self->priv->rendered_pixbuf = 
-    gtk_icon_set_render_icon_pixbuf (icon_set, context, self->priv->icon_size);
-}
-
-static void
 ensure_pixbuf_at_size (GtkIconHelper   *self,
                        GtkStyleContext *context)
 {
@@ -307,12 +295,26 @@ ensure_pixbuf_at_size (GtkIconHelper   *self,
     self->priv->rendered_pixbuf = g_object_ref (self->priv->orig_pixbuf);
 }
 
+GtkIconSet *
+_gtk_icon_helper_ensure_icon_set (GtkIconHelper *self,
+                                  GtkStyleContext *context)
+{
+  switch (self->priv->storage_type)
+    {
+    case GTK_IMAGE_ICON_SET:
+      return self->priv->icon_set;
+    case GTK_IMAGE_STOCK:
+      return gtk_style_context_lookup_icon_set (context, self->priv->stock_id);
+    default:
+      return NULL;
+    }
+}
+
 GdkPixbuf *
 _gtk_icon_helper_ensure_pixbuf (GtkIconHelper *self,
                                 GtkStyleContext *context)
 {
   GdkPixbuf *pixbuf = NULL;
-  GtkIconSet *icon_set;
 
   switch (self->priv->storage_type)
     {
@@ -323,19 +325,6 @@ _gtk_icon_helper_ensure_pixbuf (GtkIconHelper *self,
         pixbuf = g_object_ref (self->priv->orig_pixbuf);
       break;
 
-    case GTK_IMAGE_STOCK:
-      icon_set = gtk_style_context_lookup_icon_set (context, self->priv->stock_id);
-      if (icon_set != NULL)
-       ensure_pixbuf_for_icon_set (self, context, icon_set);
-      else
-       pixbuf = NULL;
-      break;
-
-    case GTK_IMAGE_ICON_SET:
-      icon_set = self->priv->icon_set;
-      ensure_pixbuf_for_icon_set (self, context, icon_set);
-      break;
-
     case GTK_IMAGE_ICON_NAME:
     case GTK_IMAGE_GICON:
       ensure_pixbuf_for_icon_name_or_gicon (self, context);
@@ -581,17 +570,33 @@ void
 _gtk_icon_helper_draw (GtkIconHelper *self,
                        GtkStyleContext *context,
                        cairo_t *cr,
+                       gdouble scale,
                        gdouble x,
                        gdouble y)
 {
+  GtkIconSet *icon_set;
   GdkPixbuf *pixbuf;
 
-  pixbuf = _gtk_icon_helper_ensure_pixbuf (self, context);
+  icon_set = _gtk_icon_helper_ensure_icon_set (self, context);
 
-  if (pixbuf != NULL)
+  if (icon_set)
+    {
+      cairo_save (cr);
+      gtk_cairo_set_source_icon_set (cr, context,
+                                     icon_set, self->priv->icon_size,
+                                     scale, x, y);
+      cairo_paint (cr);
+      cairo_restore (cr);
+    }
+  else
     {
-      gtk_render_icon (context, cr, pixbuf, x, y);
-      g_object_unref (pixbuf);
+      pixbuf = _gtk_icon_helper_ensure_pixbuf (self, context);
+
+      if (pixbuf != NULL)
+        {
+          gtk_render_icon (context, cr, pixbuf, x, y);
+          g_object_unref (pixbuf);
+        }
     }
 }
 
diff --git a/gtk/gtkiconhelperprivate.h b/gtk/gtkiconhelperprivate.h
index c2b9f08..9a63bc3 100644
--- a/gtk/gtkiconhelperprivate.h
+++ b/gtk/gtkiconhelperprivate.h
@@ -121,6 +121,7 @@ void _gtk_icon_helper_get_size (GtkIconHelper *self,
 void _gtk_icon_helper_draw (GtkIconHelper *self,
                             GtkStyleContext *context,
                             cairo_t *cr,
+                            gdouble scale,
                             gdouble x,
                             gdouble y);
 
diff --git a/gtk/gtkimage.c b/gtk/gtkimage.c
index 61c41b9..677500f 100644
--- a/gtk/gtkimage.c
+++ b/gtk/gtkimage.c
@@ -1477,8 +1477,9 @@ gtk_image_draw (GtkWidget *widget,
     }
   else
     {
-      _gtk_icon_helper_draw (priv->icon_helper, 
+      _gtk_icon_helper_draw (priv->icon_helper,
                              context, cr,
+                             gtk_widget_get_scale_factor (widget),
                              x, y);
     }
 
diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c
index 0f97078..b675dae 100644
--- a/gtk/gtkspinbutton.c
+++ b/gtk/gtkspinbutton.c
@@ -1020,6 +1020,7 @@ gtk_spin_button_panel_draw (GtkSpinButton   *spin_button,
   y = floor ((height - icon_height) / 2.0);
 
   _gtk_icon_helper_draw (icon_helper, context, cr,
+                         gtk_widget_get_scale_factor (widget),
                          x, y);
   cairo_restore (cr);
 


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