[gtk+/icon-shadow: 6/11] cellrendererpix: use gtk_render_icon()



commit 16e2af62be90bb73976c28dc8c8feddd5296efb6
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Fri May 20 23:51:59 2011 -0400

    cellrendererpix: use gtk_render_icon()

 gtk/gtkcellrendererpixbuf.c |  124 ++++++++++++-------------------------------
 1 files changed, 34 insertions(+), 90 deletions(-)
---
diff --git a/gtk/gtkcellrendererpixbuf.c b/gtk/gtkcellrendererpixbuf.c
index 8c222ff..a8766ef 100644
--- a/gtk/gtkcellrendererpixbuf.c
+++ b/gtk/gtkcellrendererpixbuf.c
@@ -641,53 +641,6 @@ create_symbolic_pixbuf (GtkCellRendererPixbuf *cellpixbuf,
   return NULL;
 }
 
-static GdkPixbuf *
-create_colorized_pixbuf (GdkPixbuf *src,
-                         GdkRGBA   *new_color)
-{
-  gint i, j;
-  gint width, height, has_alpha, src_row_stride, dst_row_stride;
-  gint red_value, green_value, blue_value;
-  guchar *target_pixels;
-  guchar *original_pixels;
-  guchar *pixsrc;
-  guchar *pixdest;
-  GdkPixbuf *dest;
-
-  red_value = (new_color->red * 65535.0) / 255.0;
-  green_value = (new_color->green * 65535.0) / 255.0;
-  blue_value = (new_color->blue * 65535.0) / 255.0;
-
-  dest = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (src),
-			 gdk_pixbuf_get_has_alpha (src),
-			 gdk_pixbuf_get_bits_per_sample (src),
-			 gdk_pixbuf_get_width (src),
-			 gdk_pixbuf_get_height (src));
-  
-  has_alpha = gdk_pixbuf_get_has_alpha (src);
-  width = gdk_pixbuf_get_width (src);
-  height = gdk_pixbuf_get_height (src);
-  src_row_stride = gdk_pixbuf_get_rowstride (src);
-  dst_row_stride = gdk_pixbuf_get_rowstride (dest);
-  target_pixels = gdk_pixbuf_get_pixels (dest);
-  original_pixels = gdk_pixbuf_get_pixels (src);
-  
-  for (i = 0; i < height; i++) {
-    pixdest = target_pixels + i*dst_row_stride;
-    pixsrc = original_pixels + i*src_row_stride;
-    for (j = 0; j < width; j++) {		
-      *pixdest++ = (*pixsrc++ * red_value) >> 8;
-      *pixdest++ = (*pixsrc++ * green_value) >> 8;
-      *pixdest++ = (*pixsrc++ * blue_value) >> 8;
-      if (has_alpha) {
-	*pixdest++ = *pixsrc++;
-      }
-    }
-  }
-  return dest;
-}
-
-
 static void
 gtk_cell_renderer_pixbuf_get_size (GtkCellRenderer    *cell,
 				   GtkWidget          *widget,
@@ -778,13 +731,14 @@ gtk_cell_renderer_pixbuf_render (GtkCellRenderer      *cell,
   GtkCellRendererPixbufPrivate *priv = cellpixbuf->priv;
   GtkStyleContext *context;
   GdkPixbuf *pixbuf;
-  GdkPixbuf *invisible = NULL;
-  GdkPixbuf *colorized = NULL;
-  GdkPixbuf *symbolic = NULL;
   GdkRectangle pix_rect;
   GdkRectangle draw_rect;
   gboolean is_expander;
   gint xpad, ypad;
+  GtkStateFlags state;
+  cairo_surface_t *surface;
+  cairo_t *surface_cr;
+  GdkPixbuf *symbolic = NULL;
 
   gtk_cell_renderer_pixbuf_get_size (cell, widget, (GdkRectangle *) cell_area,
 				     &pix_rect.x,
@@ -818,63 +772,53 @@ gtk_cell_renderer_pixbuf_render (GtkCellRenderer      *cell,
 	pixbuf = priv->pixbuf_expander_closed;
     }
 
-  if (!pixbuf)
+  if (pixbuf == NULL)
     return;
 
-  context = gtk_widget_get_style_context (widget);
+  g_object_ref (pixbuf);
+  state = GTK_STATE_FLAG_NORMAL;
 
   if (!gtk_widget_get_sensitive (widget) ||
       !gtk_cell_renderer_get_sensitive (cell))
     {
-      GtkIconSource *source;
-      
-      source = gtk_icon_source_new ();
-      gtk_icon_source_set_pixbuf (source, pixbuf);
-      /* The size here is arbitrary; since size isn't
-       * wildcarded in the source, it isn't supposed to be
-       * scaled by the engine function
-       */
-      gtk_icon_source_set_size (source, GTK_ICON_SIZE_SMALL_TOOLBAR);
-      gtk_icon_source_set_size_wildcarded (source, FALSE);
-
-      gtk_style_context_save (context);
-      gtk_style_context_set_state (context, GTK_STATE_FLAG_INSENSITIVE);
-
-      pixbuf = invisible = gtk_render_icon_pixbuf (context, source,
-                                                   (GtkIconSize) -1);
-
-      gtk_style_context_restore (context);
-      gtk_icon_source_free (source);
+      state = GTK_STATE_FLAG_INSENSITIVE;
     }
   else if (priv->follow_state && 
-	   (flags & (GTK_CELL_RENDERER_SELECTED|GTK_CELL_RENDERER_PRELIT)) != 0)
+	   (flags &
+            (GTK_CELL_RENDERER_SELECTED |
+             GTK_CELL_RENDERER_PRELIT)) != 0)
     {
-      GtkStateFlags state;
-
       state = gtk_cell_renderer_get_state (cell, widget, flags);
       symbolic = create_symbolic_pixbuf (cellpixbuf, widget, state);
 
-      if (!symbolic)
+      if (symbolic != NULL)
         {
-          GdkRGBA color;
-
-          gtk_style_context_get_background_color (context, state, &color);
-          pixbuf = colorized = create_colorized_pixbuf (pixbuf, &color);
+          g_object_unref (pixbuf);
+          pixbuf = symbolic;
         }
-      else
-        pixbuf = symbolic;
     }
 
-  gdk_cairo_set_source_pixbuf (cr, pixbuf, pix_rect.x, pix_rect.y);
-  gdk_cairo_rectangle (cr, &draw_rect);
-  cairo_fill (cr);
+  context = gtk_widget_get_style_context (widget);
+
+  gtk_style_context_save (context);
+  gtk_style_context_set_state (context, state);
+
+  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+                                        gdk_pixbuf_get_width (pixbuf),
+                                        gdk_pixbuf_get_height (pixbuf));
+  surface_cr = cairo_create (surface);
+  gdk_cairo_set_source_pixbuf (surface_cr, pixbuf, 0, 0);
+  cairo_paint (surface_cr);
+  cairo_destroy (surface_cr);
 
-  if (invisible)
-    g_object_unref (invisible);
+  gtk_render_icon (context, cr,
+                   draw_rect.x, draw_rect.y,
+                   draw_rect.width, draw_rect.height,
+                   surface,
+                   (symbolic != NULL));
 
-  if (colorized)
-    g_object_unref (colorized);
+  gtk_style_context_restore (context);
 
-  if (symbolic)
-    g_object_unref (symbolic);
+  cairo_surface_destroy (surface);
+  g_object_unref (pixbuf);
 }



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