[PATCH] Industrial: insensitive icon like Mist



Hi,

I have prepared a (small) patch for Industrial against gtk-engines-2.6.0.
It uses the same code as Mist (that's the one described here by James
Cape http://mail.gnome.org/archives/gtk-devel-list/2002-January/msg00010.html)
to render better looking insensitive icons (obligatory screenshot
here: http://dredoz.altervista.org/industrial.png).

It's my first patch so be patient ;-) should I open a bug and attach it there?

Ciao
Michele
diff -aur gtk-engines-2.6.0-orig/engines/industrial/src/industrial_style.c gtk-engines-2.6.0/engines/industrial/src/industrial_style.c
--- gtk-engines-2.6.0-orig/engines/industrial/src/industrial_style.c	2004-12-17 18:10:21.000000000 +0100
+++ gtk-engines-2.6.0/engines/industrial/src/industrial_style.c	2005-02-08 20:18:45.361254624 +0100
@@ -2720,4 +2720,142 @@
 }
 #endif
 
+#if INDUSTRIAL_GTK_VERSION == 2
+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,
+              int width,
+              int height)
+{
+	if (width == gdk_pixbuf_get_width (src) &&
+	    height == gdk_pixbuf_get_height (src)) {
+		return g_object_ref (src);
+	} else {
+		return gdk_pixbuf_scale_simple (src,
+						width, height,
+						GDK_INTERP_BILINEAR);
+	}
+}
+
+static GdkPixbuf *
+render_icon (GtkStyle            *style,
+	     const GtkIconSource *source,
+	     GtkTextDirection     direction,
+	     GtkStateType         state,
+	     GtkIconSize          size,
+	     GtkWidget           *widget,
+	     const char          *detail)
+{
+	int width = 1;
+	int height = 1;
+	GdkPixbuf *scaled;
+	GdkPixbuf *stated;
+	GdkPixbuf *base_pixbuf;
+	GdkScreen *screen;
+	GtkSettings *settings;
+	
+	/* Oddly, style can be NULL in this function, because
+	 * GtkIconSet can be used without a style and if so
+	 * it uses this function.
+	 */
+	
+	base_pixbuf = gtk_icon_source_get_pixbuf (source);
+	
+	g_return_val_if_fail (base_pixbuf != NULL, NULL);
+	
+	if (widget && gtk_widget_has_screen (widget)) {
+		screen = gtk_widget_get_screen (widget);
+		settings = gtk_settings_get_for_screen (screen);
+	} else if (style->colormap) {
+		screen = gdk_colormap_get_screen (style->colormap);
+		settings = gtk_settings_get_for_screen (screen);
+	} else {
+		settings = gtk_settings_get_default ();
+		GTK_NOTE (MULTIHEAD,
+			  g_warning ("Using the default screen for gtk_default_render_icon()"));
+	}
+	
+  
+	if (size != (GtkIconSize) -1 && !gtk_icon_size_lookup_for_settings (settings, size, &width, &height)) {
+		g_warning (G_STRLOC ": invalid icon size '%d'", size);
+		return NULL;
+	}
+
+	/* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
+	 * leave it alone.
+	 */
+	if (size != (GtkIconSize)-1 && gtk_icon_source_get_size_wildcarded (source))
+		scaled = scale_or_ref (base_pixbuf, width, height);
+	else
+		scaled = g_object_ref (base_pixbuf);
+	
+	/* If the state was wildcarded, then generate a state. */
+	if (gtk_icon_source_get_state_wildcarded (source)) {
+		if (state == GTK_STATE_INSENSITIVE) {
+			stated = set_transparency (scaled, 0.3);
+#if 0
+			stated =
+				gdk_pixbuf_composite_color_simple (scaled,
+								   gdk_pixbuf_get_width (scaled),
+								   gdk_pixbuf_get_height (scaled),
+								   GDK_INTERP_BILINEAR, 128,
+								   gdk_pixbuf_get_width (scaled),
+								   style->bg[state].pixel,
+								   style->bg[state].pixel);
+#endif
+			gdk_pixbuf_saturate_and_pixelate (stated, stated,
+							  0.1, FALSE);
+			
+			g_object_unref (scaled);
+		} else if (state == GTK_STATE_PRELIGHT) {
+			stated = gdk_pixbuf_copy (scaled);      
+			
+			gdk_pixbuf_saturate_and_pixelate (scaled, stated,
+							  1.2, FALSE);
+			
+			g_object_unref (scaled);
+		} else {
+			stated = scaled;
+		}
+	}
+	else
+		stated = scaled;
+  
+  return stated;
+}
+#endif
+
 #include "industrial_style_versioned_code.h"
diff -aur gtk-engines-2.6.0-orig/engines/industrial/src/industrial_style_versioned_code.h gtk-engines-2.6.0/engines/industrial/src/industrial_style_versioned_code.h
--- gtk-engines-2.6.0-orig/engines/industrial/src/industrial_style_versioned_code.h	2004-12-01 13:55:56.000000000 +0100
+++ gtk-engines-2.6.0/engines/industrial/src/industrial_style_versioned_code.h	2005-02-08 19:50:39.501544256 +0100
@@ -78,6 +78,7 @@
   style_class->draw_shadow_gap = draw_shadow_gap;
   style_class->draw_extension = draw_extension;
   style_class->draw_option = draw_option;
+  style_class->render_icon = render_icon;
 }
 
 GType industrial_type_style = 0;



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