patch: new themable render modes for icons



Dear nautilus maintainers,

here is a patch (against 2.14.3) that enables nautilus to have themable render modes for its icons.
With it, there are 4 render modes:
0: normal rendering (as before)
1: spotlight rendering (as prelighted icons got rendered before)
2: colorized rendering (icons are colorized by a specified color)
3: cartoonish grayscale rendering (icon is rendered gray and without most details)


Themes have these new style settings (here with example values):

NautilusIconContainer::normal_render_type = 3
NautilusIconContainer::normal_color = "#00FF00"
NautilusIconContainer::prelight_render_type = 2
NautilusIconContainer::prelight_color = "#00FF00"

If no render type is given by the theme, nautilus keeps it current rendering (0 for normal icons, 1 for prelight icons). If no color is explicitly specified, it uses base[NORMAL] and base[PRELIGHT] as default values.

The patch is really small and doesn't affect current themes. In fact, noone will notice the changes unless he uses an adapted theme or adds some of these new commands to his gtkrc. It uses only standard libeel/GdkPixbuf methods for image manipulation. So i hope, you apply this patch to the official nautilus repository and i would be really, really glad if these small additions can even be shipped with the next gnome 2.16 update, cause otherwise i would have to package my "gnome-color-chooser" with a nautilus patch, and i'm sure that most of its users aren't capable to patch nautilus on their own. Well... most important is that you find this not useless and never apply it *g*


Best regards,
 JackTheDipper ;o)


P.S.: I tried to follow your coding conventions consequently, hope successfully. ;-) P.P.S.: Feel free to demand changes in the code if you don't like some parts of it! Per mail or in #nautilus.

--- nautilus-2.14.3/libnautilus-private/nautilus-icon-container.c	2006-04-18 18:54:31.000000000 +0200
+++ nautilus-2.14.3_patched/libnautilus-private/nautilus-icon-container.c	2006-11-01 14:29:04.000000000 +0100
@@ -118,6 +118,9 @@
 #define DEFAULT_LIGHT_INFO_COLOR 0xAAAAFD
 #define DEFAULT_DARK_INFO_COLOR  0x33337F
 
+#define DEFAULT_NORMAL_RENDER_TYPE 0
+#define DEFAULT_PRELIGHT_RENDER_TYPE 1
+
 #define MINIMUM_EMBEDDED_TEXT_RECT_WIDTH       20
 #define MINIMUM_EMBEDDED_TEXT_RECT_HEIGHT      20
 
@@ -4811,6 +4814,33 @@
 								     GDK_TYPE_COLOR,
 								     G_PARAM_READABLE));
 
+	gtk_widget_class_install_style_property (widget_class,
+						 g_param_spec_uint ("normal_render_type",
+								     "Normal Icon Render Type",
+								     "Type of normal icons being rendered (0=normal, 1=spotlight, 2=colorize, 3=black/white)",
+								     0, 3,
+								     DEFAULT_NORMAL_RENDER_TYPE,
+								     G_PARAM_READABLE));
+	gtk_widget_class_install_style_property (widget_class,
+						 g_param_spec_uint ("prelight_render_type",
+								     "Prelight Icon Render Type",
+								     "Type of prelight icons being rendered (0=normal, 1=spotlight, 2=colorize, 3=black/white)",
+								     0, 3,
+								     DEFAULT_PRELIGHT_RENDER_TYPE,
+								     G_PARAM_READABLE));
+	gtk_widget_class_install_style_property (widget_class,
+						 g_param_spec_boxed ("normal_color",
+								     "Icon Normal Color",
+								     "Color used for colorizing icons in normal state (default base[NORMAL])",
+								     GDK_TYPE_COLOR,
+								     G_PARAM_READABLE));
+	gtk_widget_class_install_style_property (widget_class,
+						 g_param_spec_boxed ("prelight_color",
+								     "Icon Prelight Color",
+								     "Color used for colorizing prelighted icons (default base[PRELIGHT]",
+								     GDK_TYPE_COLOR,
+								     G_PARAM_READABLE));
+
 	binding_set = gtk_binding_set_by_class (class);
 
 	gtk_binding_entry_add_signal (binding_set, GDK_f, GDK_CONTROL_MASK, "start_interactive_search", 0);
@@ -7155,6 +7185,7 @@
 {
 	NautilusIconContainer *container;
 	GtkStyle *style;
+	GdkColor *prelight_color, *normal_color;
 	guchar highlight_alpha, normal_alpha;
 
 	container = NAUTILUS_ICON_CONTAINER (user_data);
@@ -7183,18 +7214,49 @@
 				     style->base[GTK_STATE_ACTIVE].green >> 8, 
 				     style->base[GTK_STATE_ACTIVE].blue >> 8,
 				     highlight_alpha);
-	
+
+  /* load the prelight color */
+	gtk_widget_style_get (GTK_WIDGET (container),
+			      "prelight_color", &prelight_color,
+			      NULL);
+
+	if (prelight_color) {
+		container->details->prelight_color_rgba = 
+			EEL_RGBA_COLOR_PACK (prelight_color->red >> 8, 
+					     prelight_color->green >> 8, 
+					     prelight_color->blue >> 8,
+					     255);
+	} else { /* if not defined by rc, set to default value */
+		container->details->prelight_color_rgba = 
+			EEL_RGBA_COLOR_PACK ( style->base[GTK_STATE_PRELIGHT].red >> 8,
+					     style->base[GTK_STATE_PRELIGHT].green >> 8,
+					     style->base[GTK_STATE_PRELIGHT].blue >> 8,
+					     255);
+  }
+  
+  
 	/* load the normal color */
 	gtk_widget_style_get (GTK_WIDGET (container),
+			      "normal_color", &normal_color,
+			      NULL);
+	gtk_widget_style_get (GTK_WIDGET (container),
 			      "normal_alpha", &normal_alpha,
 			      NULL);
-	
-	container->details->normal_color_rgba = 
-		EEL_RGBA_COLOR_PACK (style->base[GTK_STATE_NORMAL].red >> 8, 
-				     style->base[GTK_STATE_NORMAL].green >> 8, 
-				     style->base[GTK_STATE_NORMAL].blue >> 8,
-				     normal_alpha);
 
+  if (normal_color) {
+		container->details->normal_color_rgba = 
+			EEL_RGBA_COLOR_PACK (normal_color->red >> 8, 
+					     normal_color->green >> 8, 
+					     normal_color->blue >> 8,
+					     normal_alpha);
+	} else { /* if not defined by rc, set to default value */
+		container->details->normal_color_rgba = 
+			EEL_RGBA_COLOR_PACK (style->base[GTK_STATE_NORMAL].red >> 8, 
+					     style->base[GTK_STATE_NORMAL].green >> 8, 
+					     style->base[GTK_STATE_NORMAL].blue >> 8,
+					     normal_alpha);
+	}
+	
 	setup_label_gcs (container);
 }
 
--- nautilus-2.14.3/libnautilus-private/nautilus-icon-canvas-item.c	2006-04-26 17:00:23.000000000 +0200
+++ nautilus-2.14.3_patched/libnautilus-private/nautilus-icon-canvas-item.c	2006-11-01 16:46:55.000000000 +0100
@@ -1439,23 +1439,71 @@
 					   128);
 }
 
+static GdkPixbuf *
+render_icon (GdkPixbuf *pixbuf, guint render_type, guint color)
+{
+ 	GdkPixbuf *temp_pixbuf;
+
+	if (render_type == 2) {
+	/* colorize icon */
+		temp_pixbuf = eel_create_colorized_pixbuf (pixbuf,
+				   EEL_RGBA_COLOR_GET_R (color),
+				   EEL_RGBA_COLOR_GET_G (color),
+				   EEL_RGBA_COLOR_GET_B (color));
+	} else if (render_type == 3) {
+	/* gray out icon (black/white) */
+	
+		/* broken convert to ntsc color space and set hue and saturation to zero */
+		temp_pixbuf = eel_create_colorized_pixbuf (pixbuf, 76, 150, 29);
+		temp_pixbuf = eel_create_colorized_pixbuf (temp_pixbuf, 152, -70, -82);
+		temp_pixbuf = eel_create_colorized_pixbuf (temp_pixbuf, 54, -134, 80);
+		temp_pixbuf = eel_create_colorized_pixbuf (temp_pixbuf, 255, 0, 0);
+		/* convert back to rgb colorspace */
+		temp_pixbuf = eel_create_colorized_pixbuf (temp_pixbuf, 256, 244, 158);
+		temp_pixbuf = eel_create_colorized_pixbuf (temp_pixbuf, 256, -69, -165);
+		temp_pixbuf = eel_create_colorized_pixbuf (temp_pixbuf, 256, -283, 436);
+		/* lighten up */
+ 		temp_pixbuf = eel_create_spotlight_pixbuf (temp_pixbuf);
+ 		temp_pixbuf = eel_create_spotlight_pixbuf (temp_pixbuf);
+ 		temp_pixbuf = eel_create_spotlight_pixbuf (temp_pixbuf);
+ 		temp_pixbuf = eel_create_spotlight_pixbuf (temp_pixbuf);
+ 		temp_pixbuf = eel_create_spotlight_pixbuf (temp_pixbuf);
+ 		/* now the picture is gray and additionally most details have gone away */
+	} else {
+		/* lighten up icon (default colorize behavior) */
+		temp_pixbuf = eel_create_spotlight_pixbuf (pixbuf);
+	}
+  
+	return temp_pixbuf;
+}
+
 /* shared code to highlight or dim the passed-in pixbuf */
 static GdkPixbuf *
 real_map_pixbuf (NautilusIconCanvasItem *icon_item)
 {
 	EelCanvas *canvas;
 	char *audio_filename;
+	NautilusIconContainer *container;
 	GdkPixbuf *temp_pixbuf, *old_pixbuf, *audio_pixbuf;
 	double zoom;
+	guint render_type;
 	
 	temp_pixbuf = icon_item->details->pixbuf;
 	canvas = EEL_CANVAS_ITEM(icon_item)->canvas;
+	container = NAUTILUS_ICON_CONTAINER (canvas);
 
 	g_object_ref (temp_pixbuf);
 
 	if (icon_item->details->is_prelit) {
 		old_pixbuf = temp_pixbuf;
-		temp_pixbuf = eel_create_spotlight_pixbuf (temp_pixbuf);
+
+		gtk_widget_style_get (GTK_WIDGET (container),
+			      "prelight_render_type", &render_type,
+			      NULL);
+		temp_pixbuf = render_icon (temp_pixbuf,
+                	render_type,
+                	container->details->prelight_color_rgba);
+
 		g_object_unref (old_pixbuf);
 
 		/* FIXME bugzilla.gnome.org 42471: This hard-wired image is inappropriate to
@@ -1514,6 +1562,29 @@
 		g_object_unref (old_pixbuf);
 	} 
 
+	if (!icon_item->details->is_active
+			&& !icon_item->details->is_prelit
+			&& !icon_item->details->is_highlighted_for_selection
+			&& !icon_item->details->is_highlighted_for_drop) {
+
+		old_pixbuf = temp_pixbuf;
+
+		gtk_widget_style_get (GTK_WIDGET (container),
+			      "normal_render_type", &render_type,
+			      NULL);
+		if (render_type > 0) {
+			/* if theme requests colorization */
+			temp_pixbuf = render_icon (temp_pixbuf,
+					    render_type,
+					    container->details->normal_color_rgba);
+		}
+
+		g_object_unref (old_pixbuf);
+
+      }
+
+
+
 	return temp_pixbuf;
 }
 
@@ -1616,6 +1687,7 @@
 	icon_rect = icon_item->details->canvas_rect;
 	
 	/* if the pre-lit or selection flag is set, make a pre-lit or darkened pixbuf and draw that instead */
+	/* and colorize normal pixbuf if rc wants that */
 	temp_pixbuf = map_pixbuf (icon_item);
 	pixbuf_rect.x = icon_rect.x0;
 	pixbuf_rect.y = icon_rect.y0;
--- nautilus-2.14.3/libnautilus-private/nautilus-icon-private.h	2006-04-18 18:54:31.000000000 +0200
+++ nautilus-2.14.3_patched/libnautilus-private/nautilus-icon-private.h	2006-10-31 18:07:04.000000000 +0100
@@ -196,6 +196,7 @@
 	guint32    highlight_color_rgba;
 	guint32    active_color_rgba;
 	guint32    normal_color_rgba;
+	guint32    prelight_color_rgba;
 	
 	/* colors for text labels */
 	GdkGC   *label_gcs    [LAST_LABEL_COLOR];


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