Working Insensitive Stock Icon Patch



Here's a proper version of the nicer-looking insensitive stock icons
patch.

Examples ("The Internet" icon):
With: http://jimbob.myip.org/sshots/2002_01_03_165125_shot.jpg
Without: http://jimbob.myip.org/sshots/2002_01_03_110121_shot.jpg

    Jim Cape
    http://www.ignore-your.tv

    "No cause, no God, no abstract idea can justify the mass
     slaughter of innocents."
        -- Edward Said

--- gtk/gtkstyle.c	Thu Jan  3 14:59:04 2002
+++ gtk/gtkstyle.c	Thu Jan  3 16:34:12 2002
@@ -1622,6 +1622,43 @@
     }
 }
 
+static GdkPixbuf *
+set_transparency (const GdkPixbuf *pixbuf, gdouble alpha_percent)
+{
+	GdkPixbuf *target;
+	guchar *data, *current;
+	guint x, y, rowstride, height, width;
+
+	g_return_val_if_fail (pixbuf != NULL, NULL);
+	g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
+
+	/* Returns a copy of pixbuf with it's non-completely-transparent pixels to
+	   have an alpha level "alpha_percent" of their original value. */
+
+	target = gdk_pixbuf_add_alpha (pixbuf, FALSE, 0, 0, 0);
+
+	if (alpha_percent == 1.0)
+		return target;
+
+	width = gdk_pixbuf_get_width (target);
+	height = gdk_pixbuf_get_height (target);
+	rowstride = gdk_pixbuf_get_rowstride (target);
+	data = gdk_pixbuf_get_pixels (target);
+
+	for (y = 0; y < height; y++)
+	{
+		for (x = 0; x < width; x++)
+		{
+			/* The "4" is the number of chars per pixel, in this case, RGBA,
+               the 3 means "skip to the alpha" */
+			current = data + (y * rowstride) + (x * 4) + 3; 
+			*(current) = (guchar) (*(current) * alpha_percent);
+		}
+	}
+
+	return target;
+}
+
 static GdkPixbuf*
 scale_or_ref (GdkPixbuf *src,
               gint width,
@@ -1684,11 +1721,11 @@
     {
       if (state == GTK_STATE_INSENSITIVE)
         {
-          stated = gdk_pixbuf_copy (scaled);      
-          
-          gdk_pixbuf_saturate_and_pixelate (scaled, stated,
-                                            0.8, TRUE);
-          
+          stated = set_transparency (scaled, 0.5);
+
+          gdk_pixbuf_saturate_and_pixelate (stated, stated,
+                                            0.8, FALSE);
+
           gdk_pixbuf_unref (scaled);
         }
       else if (state == GTK_STATE_PRELIGHT)


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