Re: patch: new themable render modes for icons
- From: JackTheDipper <gnome-color-chooser punk-ass-bitch org>
- To: nautilus-list gnome org
- Subject: Re: patch: new themable render modes for icons
- Date: Fri, 24 Nov 2006 22:06:59 +0100
That's right. Here's the latest patch. ;-)
Alexander Larsson wrote:
I remember you saying that you had further work on this. Do you have the
latest version of the patch?
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Alexander Larsson Red Hat, Inc
alexl redhat com alla lysator liu se
He's a maverick white trash assassin haunted by memories of 'Nam. She's a
disco-crazy impetuous angel with the power to see death. They fight crime!
--- 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-24 21:46:20.000000000 +0100
@@ -115,9 +115,19 @@
#define DEFAULT_SELECTION_BOX_ALPHA 0x40
#define DEFAULT_HIGHLIGHT_ALPHA 0xff
#define DEFAULT_NORMAL_ALPHA 0xff
+#define DEFAULT_PRELIGHT_ALPHA 0xff
#define DEFAULT_LIGHT_INFO_COLOR 0xAAAAFD
#define DEFAULT_DARK_INFO_COLOR 0x33337F
+#define DEFAULT_NORMAL_ICON_RENDER_MODE 0
+#define DEFAULT_PRELIGHT_ICON_RENDER_MODE 1
+#define DEFAULT_NORMAL_ICON_SATURATION 255
+#define DEFAULT_PRELIGHT_ICON_SATURATION 255
+#define DEFAULT_NORMAL_ICON_BRIGHTNESS 255
+#define DEFAULT_PRELIGHT_ICON_BRIGHTNESS 255
+#define DEFAULT_NORMAL_ICON_LIGHTEN 0
+#define DEFAULT_PRELIGHT_ICON_LIGHTEN 0
+
#define MINIMUM_EMBEDDED_TEXT_RECT_WIDTH 20
#define MINIMUM_EMBEDDED_TEXT_RECT_HEIGHT 20
@@ -4799,6 +4809,13 @@
DEFAULT_NORMAL_ALPHA,
G_PARAM_READABLE));
gtk_widget_class_install_style_property (widget_class,
+ g_param_spec_uchar ("prelight_alpha",
+ _("Prelight Alpha"),
+ _("Opacity of the prelight icons if frame_text is set"),
+ 0, 0xff,
+ DEFAULT_PRELIGHT_ALPHA,
+ G_PARAM_READABLE));
+ gtk_widget_class_install_style_property (widget_class,
g_param_spec_boxed ("light_info_color",
"Light Info Color",
"Color used for information text against a dark background",
@@ -4811,6 +4828,82 @@
GDK_TYPE_COLOR,
G_PARAM_READABLE));
+ gtk_widget_class_install_style_property (widget_class,
+ g_param_spec_uint ("normal_icon_render_mode",
+ "Normal Icon Render Mode",
+ "Mode of normal icons being rendered (0=normal, 1=spotlight, 2=colorize, 3=colorize-monochromely)",
+ 0, 3,
+ DEFAULT_NORMAL_ICON_RENDER_MODE,
+ G_PARAM_READABLE));
+ gtk_widget_class_install_style_property (widget_class,
+ g_param_spec_uint ("prelight_icon_render_mode",
+ "Prelight Icon Render Mode",
+ "Mode of prelight icons being rendered (0=normal, 1=spotlight, 2=colorize, 3=colorize-monochromely)",
+ 0, 3,
+ DEFAULT_PRELIGHT_ICON_RENDER_MODE,
+ G_PARAM_READABLE));
+ gtk_widget_class_install_style_property (widget_class,
+ g_param_spec_boxed ("normal_icon_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_icon_color",
+ "Icon Prelight Color",
+ "Color used for colorizing prelighted icons (default base[PRELIGHT])",
+ GDK_TYPE_COLOR,
+ G_PARAM_READABLE));
+ gtk_widget_class_install_style_property (widget_class,
+ g_param_spec_uint ("normal_icon_saturation",
+ "Normal Icon Saturation",
+ "Saturation of icons in normal state",
+ 0, 255,
+ DEFAULT_NORMAL_ICON_SATURATION,
+ G_PARAM_READABLE));
+ gtk_widget_class_install_style_property (widget_class,
+ g_param_spec_uint ("prelight_icon_saturation",
+ "Prelight Icon Saturation",
+ "Saturation of icons in prelight state",
+ 0, 255,
+ DEFAULT_PRELIGHT_ICON_SATURATION,
+ G_PARAM_READABLE));
+ gtk_widget_class_install_style_property (widget_class,
+ g_param_spec_uint ("normal_icon_brightness",
+ "Normal Icon Brightness",
+ "Brightness of icons in normal state",
+ 0, 255,
+ DEFAULT_NORMAL_ICON_BRIGHTNESS,
+ G_PARAM_READABLE));
+ gtk_widget_class_install_style_property (widget_class,
+ g_param_spec_uint ("prelight_icon_brightness",
+ "Prelight Icon Brightness",
+ "Brightness of icons in prelight state",
+ 0, 255,
+ DEFAULT_PRELIGHT_ICON_BRIGHTNESS,
+ G_PARAM_READABLE));
+ gtk_widget_class_install_style_property (widget_class,
+ g_param_spec_uint ("normal_icon_lighten",
+ "Normal Icon Lighten",
+ "Lighten icons in normal state",
+ 0, 255,
+ DEFAULT_NORMAL_ICON_LIGHTEN,
+ G_PARAM_READABLE));
+ gtk_widget_class_install_style_property (widget_class,
+ g_param_spec_uint ("prelight_icon_lighten",
+ "Prelight Icon Lighten",
+ "Lighten icons in prelight state",
+ 0, 255,
+ DEFAULT_PRELIGHT_ICON_LIGHTEN,
+ G_PARAM_READABLE));
+ gtk_widget_class_install_style_property (widget_class,
+ g_param_spec_boolean ("activate_prelight_icon_label",
+ "Activate Prelight Icon Label",
+ "Whether icon labels should make use of its prelight color in prelight state",
+ FALSE,
+ 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);
@@ -4844,7 +4937,6 @@
{
/* End renaming and commit change. */
end_renaming_mode (NAUTILUS_ICON_CONTAINER (widget), TRUE);
-
update_selected (NAUTILUS_ICON_CONTAINER (widget));
return FALSE;
@@ -6938,10 +7030,11 @@
nautilus_icon_container_get_label_color_and_gc (NautilusIconContainer *container,
GdkColor **color,
gboolean is_name,
- gboolean is_highlight)
+ gboolean is_highlight,
+ gboolean is_prelit)
{
int idx;
-
+
if (is_name) {
if (is_highlight) {
if (GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (container))) {
@@ -6950,7 +7043,11 @@
idx = LABEL_COLOR_ACTIVE;
}
} else {
- idx = LABEL_COLOR;
+ if (is_prelit) {
+ idx = LABEL_COLOR_PRELIGHT;
+ } else {
+ idx = LABEL_COLOR;
+ }
}
} else {
if (is_highlight) {
@@ -7030,6 +7127,7 @@
setup_gc_with_fg (container, LABEL_COLOR_HIGHLIGHT, eel_gdk_color_to_rgb (&widget->style->text[GTK_STATE_SELECTED]));
setup_gc_with_fg (container, LABEL_COLOR_ACTIVE, eel_gdk_color_to_rgb (&widget->style->text[GTK_STATE_ACTIVE]));
+ setup_gc_with_fg (container, LABEL_COLOR_PRELIGHT, eel_gdk_color_to_rgb (&widget->style->text[GTK_STATE_PRELIGHT]));
setup_gc_with_fg (container,
LABEL_INFO_COLOR_HIGHLIGHT,
eel_gdk_color_is_dark (>K_WIDGET (container)->style->base[GTK_STATE_SELECTED]) ? light_info_value : dark_info_value);
@@ -7155,7 +7253,8 @@
{
NautilusIconContainer *container;
GtkStyle *style;
- guchar highlight_alpha, normal_alpha;
+ GdkColor *prelight_icon_color, *normal_icon_color;
+ guchar highlight_alpha, normal_alpha, prelight_alpha;
container = NAUTILUS_ICON_CONTAINER (user_data);
@@ -7183,18 +7282,71 @@
style->base[GTK_STATE_ACTIVE].green >> 8,
style->base[GTK_STATE_ACTIVE].blue >> 8,
highlight_alpha);
-
+
+ /* load the prelight icon color */
+ gtk_widget_style_get (GTK_WIDGET (container),
+ "prelight_icon_color", &prelight_icon_color,
+ NULL);
+
+ if (prelight_icon_color) {
+ container->details->prelight_icon_color_rgba =
+ EEL_RGBA_COLOR_PACK (prelight_icon_color->red >> 8,
+ prelight_icon_color->green >> 8,
+ prelight_icon_color->blue >> 8,
+ 255);
+ } else { /* if not defined by rc, set to default value */
+ container->details->prelight_icon_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 icon color */
+ gtk_widget_style_get (GTK_WIDGET (container),
+ "normal_icon_color", &normal_icon_color,
+ NULL);
+
+ if (normal_icon_color) {
+ container->details->normal_icon_color_rgba =
+ EEL_RGBA_COLOR_PACK (normal_icon_color->red >> 8,
+ normal_icon_color->green >> 8,
+ normal_icon_color->blue >> 8,
+ 255);
+ } else { /* if not defined by rc, set to default value */
+ container->details->normal_icon_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,
+ 255);
+ }
+
+
/* load the normal color */
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);
+
+ /* load the prelight color */
+ gtk_widget_style_get (GTK_WIDGET (container),
+ "prelight_alpha", &prelight_alpha,
+ NULL);
+
+ 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,
+ prelight_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-24 21:55:34.000000000 +0100
@@ -955,7 +955,7 @@
PangoLayout *additional_layout;
GdkColor *label_color;
int icon_width;
- gboolean have_editable, have_additional, needs_highlight, needs_frame;
+ gboolean have_editable, have_additional, needs_highlight, needs_frame, prelight_label;
int max_text_width;
int x;
GdkGC *gc;
@@ -1093,21 +1093,34 @@
if (have_editable) {
gtk_widget_style_get (GTK_WIDGET (container),
"frame_text", &needs_frame,
+ "activate_prelight_icon_label", &prelight_label,
NULL);
if (needs_frame && !needs_highlight && details->text_width > 0 && details->text_height > 0) {
- draw_frame (item,
- drawable,
- container->details->normal_color_rgba,
- create_mask,
- text_rect.x0,
- text_rect.y0,
- text_rect.x1 - text_rect.x0,
- text_rect.y1 - text_rect.y0);
+ if (!(prelight_label && item->details->is_prelit)) {
+ draw_frame (item,
+ drawable,
+ container->details->normal_color_rgba,
+ create_mask,
+ text_rect.x0,
+ text_rect.y0,
+ text_rect.x1 - text_rect.x0,
+ text_rect.y1 - text_rect.y0);
+ } else {
+ draw_frame (item,
+ drawable,
+ container->details->prelight_color_rgba,
+ create_mask,
+ text_rect.x0,
+ text_rect.y0,
+ text_rect.x1 - text_rect.x0,
+ text_rect.y1 - text_rect.y0);
+ }
}
gc = nautilus_icon_container_get_label_color_and_gc
(NAUTILUS_ICON_CONTAINER (canvas_item->canvas),
- &label_color, TRUE, needs_highlight);
+ &label_color, TRUE, needs_highlight,
+ item->details->is_prelit);
draw_label_layout (item, drawable,
editable_layout, needs_highlight,
@@ -1119,7 +1132,8 @@
if (have_additional) {
gc = nautilus_icon_container_get_label_color_and_gc
(NAUTILUS_ICON_CONTAINER (canvas_item->canvas),
- &label_color, FALSE, needs_highlight);
+ &label_color, FALSE, needs_highlight,
+ item->details->is_prelit);
draw_label_layout (item, drawable,
additional_layout, needs_highlight,
@@ -1439,24 +1453,157 @@
128);
}
+/* should be moved to libeel! */
+static guchar
+nautilus_icon_canvas_lighten_pixbuf_component (guchar cur_value, guint lighten_value) {
+ int new_value = cur_value;
+ if (lighten_value > 0) {
+ new_value += lighten_value + (new_value >> 3);
+ if (new_value > 255) {
+ new_value = 255;
+ }
+ }
+ return (guchar) new_value;
+}
+
+/* should be moved to libeel! */
+GdkPixbuf *
+nautilus_icon_canvas_lighten_pixbuf (GdkPixbuf* src, guint lighten_value) {
+ GdkPixbuf *dest;
+ int i, j;
+ int width, height, has_alpha, src_row_stride, dst_row_stride;
+ guchar *target_pixels, *original_pixels;
+ guchar *pixsrc, *pixdest;
+
+ g_return_val_if_fail (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB, NULL);
+ g_return_val_if_fail ((!gdk_pixbuf_get_has_alpha (src)
+ && gdk_pixbuf_get_n_channels (src) == 3)
+ || (gdk_pixbuf_get_has_alpha (src)
+ && gdk_pixbuf_get_n_channels (src) == 4), NULL);
+ g_return_val_if_fail (gdk_pixbuf_get_bits_per_sample (src) == 8, NULL);
+
+ 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);
+ dst_row_stride = gdk_pixbuf_get_rowstride (dest);
+ src_row_stride = gdk_pixbuf_get_rowstride (src);
+ 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++ = nautilus_icon_canvas_lighten_pixbuf_component (*pixsrc++, lighten_value);
+ *pixdest++ = nautilus_icon_canvas_lighten_pixbuf_component (*pixsrc++, lighten_value);
+ *pixdest++ = nautilus_icon_canvas_lighten_pixbuf_component (*pixsrc++, lighten_value);
+ if (has_alpha) {
+ *pixdest++ = *pixsrc++;
+ }
+ }
+ }
+ return dest;
+}
+
+
+
+static GdkPixbuf *
+render_icon (GdkPixbuf *pixbuf, guint render_mode, guint saturation, guint brightness, guint lighten_value, guint color)
+{
+ GdkPixbuf *temp_pixbuf, *old_pixbuf;
+ gboolean unref_icon = TRUE;
+
+ if (render_mode == 1) {
+ /* lighten icon */
+ temp_pixbuf = eel_create_spotlight_pixbuf (pixbuf);
+ }
+ else if (render_mode == 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_mode == 3) {
+ /* monochromely colorize icon */
+ old_pixbuf = eel_create_darkened_pixbuf (pixbuf, 0, 255);
+ temp_pixbuf = eel_create_colorized_pixbuf (old_pixbuf,
+ EEL_RGBA_COLOR_GET_R (color),
+ EEL_RGBA_COLOR_GET_G (color),
+ EEL_RGBA_COLOR_GET_B (color));
+ g_object_unref(old_pixbuf);
+ } else {
+
+ unref_icon = FALSE;
+ }
+
+ if (saturation < 255 || brightness < 255 || !unref_icon) { // !unref_icon just for safer code (return copy)
+ if (unref_icon) {
+ old_pixbuf = temp_pixbuf;
+ }
+ temp_pixbuf = eel_create_darkened_pixbuf (unref_icon ? temp_pixbuf : pixbuf, saturation, brightness);
+ if (unref_icon) {
+ g_object_unref(old_pixbuf);
+ }
+ unref_icon = TRUE;
+ }
+
+ if (lighten_value > 0) {
+ if (unref_icon) {
+ old_pixbuf = temp_pixbuf;
+ }
+ temp_pixbuf = nautilus_icon_canvas_lighten_pixbuf (unref_icon ? temp_pixbuf : pixbuf, lighten_value);
+ if (unref_icon) {
+ g_object_unref(old_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_mode, saturation, brightness, lighten;
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);
- g_object_unref (old_pixbuf);
+
+ gtk_widget_style_get (GTK_WIDGET (container),
+ "prelight_icon_render_mode", &render_mode,
+ "prelight_icon_saturation", &saturation,
+ "prelight_icon_brightness", &brightness,
+ "prelight_icon_lighten", &lighten,
+ NULL);
+
+ if (render_mode > 0 || saturation < 255 || brightness < 255) {
+ temp_pixbuf = render_icon (temp_pixbuf,
+ render_mode,
+ saturation,
+ brightness,
+ lighten,
+ container->details->prelight_icon_color_rgba);
+ g_object_unref (old_pixbuf);
+ }
+
+
/* FIXME bugzilla.gnome.org 42471: This hard-wired image is inappropriate to
* this level of code, which shouldn't know that the
@@ -1508,12 +1655,42 @@
temp_pixbuf = eel_create_colorized_pixbuf (temp_pixbuf,
EEL_RGBA_COLOR_GET_R (color),
- EEL_RGBA_COLOR_GET_G(color),
+ EEL_RGBA_COLOR_GET_G (color),
EEL_RGBA_COLOR_GET_B (color));
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_icon_render_mode", &render_mode,
+ "normal_icon_saturation", &saturation,
+ "normal_icon_brightness", &brightness,
+ "normal_icon_lighten", &lighten,
+ NULL);
+ if (render_mode > 0 || saturation < 255 || brightness < 255) {
+ /* if theme requests colorization */
+ temp_pixbuf = render_icon (temp_pixbuf,
+ render_mode,
+ saturation,
+ brightness,
+ lighten,
+ container->details->normal_icon_color_rgba);
+ g_object_unref (old_pixbuf);
+ }
+
+
+
+ }
+
+
+
return temp_pixbuf;
}
@@ -1616,6 +1793,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-11-11 00:18:55.000000000 +0100
@@ -104,6 +104,7 @@
LABEL_COLOR,
LABEL_COLOR_HIGHLIGHT,
LABEL_COLOR_ACTIVE,
+ LABEL_COLOR_PRELIGHT,
LABEL_INFO_COLOR,
LABEL_INFO_COLOR_HIGHLIGHT,
LABEL_INFO_COLOR_ACTIVE,
@@ -196,7 +197,10 @@
guint32 highlight_color_rgba;
guint32 active_color_rgba;
guint32 normal_color_rgba;
-
+ guint32 prelight_color_rgba;
+ guint32 prelight_icon_color_rgba;
+ guint32 normal_icon_color_rgba;
+
/* colors for text labels */
GdkGC *label_gcs [LAST_LABEL_COLOR];
GdkColor label_colors [LAST_LABEL_COLOR];
@@ -297,6 +301,7 @@
GdkGC *nautilus_icon_container_get_label_color_and_gc (NautilusIconContainer *container,
GdkColor **color,
gboolean first_line,
- gboolean needs_highlight);
+ gboolean needs_highlight,
+ gboolean is_prelit);
#endif /* NAUTILUS_ICON_CONTAINER_PRIVATE_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]