Commit c18d8721 authored by Alexander Larsson's avatar Alexander Larsson Committed by Alexander Larsson

Add more themeing features for icon view icons. Patch from JackTheDipper

2006-11-30  Alexander Larsson  <alexl@redhat.com>

	* libnautilus-private/nautilus-icon-canvas-item.c:
	* libnautilus-private/nautilus-icon-container.c:
	* libnautilus-private/nautilus-icon-private.h:
	Add more themeing features for icon view icons.
	Patch from JackTheDipper
parent 9e3ea545
2006-11-30 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-icon-canvas-item.c:
* libnautilus-private/nautilus-icon-container.c:
* libnautilus-private/nautilus-icon-private.h:
Add more themeing features for icon view icons.
Patch from JackTheDipper
2006-11-28 Alexander Larsson <alexl@redhat.com>
* src/file-manager/fm-tree-view.c:
......
......@@ -225,6 +225,8 @@ static void draw_embedded_text (NautilusIconCanvasItem
int x,
int y);
static GdkPixbuf *nautilus_icon_canvas_lighten_pixbuf (GdkPixbuf* src, guint lighten_value);
static NautilusIconCanvasItemClass *parent_class = NULL;
static gpointer accessible_parent_class = NULL;
......@@ -959,7 +961,7 @@ draw_or_measure_label_text (NautilusIconCanvasItem *item,
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;
......@@ -1097,8 +1099,10 @@ draw_or_measure_label_text (NautilusIconCanvasItem *item,
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) {
if (!(prelight_label && item->details->is_prelit)) {
draw_frame (item,
drawable,
container->details->normal_color_rgba,
......@@ -1107,11 +1111,22 @@ draw_or_measure_label_text (NautilusIconCanvasItem *item,
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,
prelight_label & item->details->is_prelit);
draw_label_layout (item, drawable,
editable_layout, needs_highlight,
......@@ -1123,7 +1138,8 @@ draw_or_measure_label_text (NautilusIconCanvasItem *item,
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,
FALSE);
draw_label_layout (item, drawable,
additional_layout, needs_highlight,
......@@ -1443,24 +1459,150 @@ draw_mask (GdkPixbuf *pixbuf, GdkDrawable *drawable, int x, int y)
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! */
static 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;
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 {
temp_pixbuf = NULL;
}
if (saturation < 255 || brightness < 255 || temp_pixbuf == NULL) { // temp_pixbuf == NULL just for safer code (return copy)
old_pixbuf = temp_pixbuf;
temp_pixbuf = eel_create_darkened_pixbuf (temp_pixbuf ? temp_pixbuf : pixbuf, saturation, brightness);
if (old_pixbuf) {
g_object_unref (old_pixbuf);
}
}
if (lighten_value > 0) {
old_pixbuf = temp_pixbuf;
temp_pixbuf = nautilus_icon_canvas_lighten_pixbuf (temp_pixbuf ? temp_pixbuf : pixbuf, lighten_value);
if (old_pixbuf) {
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);
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
......@@ -1512,12 +1654,36 @@ real_map_pixbuf (NautilusIconCanvasItem *icon_item)
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;
}
......@@ -1620,6 +1786,7 @@ nautilus_icon_canvas_item_draw (EelCanvasItem *item, GdkDrawable *drawable,
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;
......
......@@ -116,9 +116,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
......@@ -4880,6 +4890,13 @@ nautilus_icon_container_class_init (NautilusIconContainerClass *class)
0, 0xff,
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",
......@@ -4893,6 +4910,82 @@ nautilus_icon_container_class_init (NautilusIconContainerClass *class)
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);
......@@ -4926,7 +5019,6 @@ handle_focus_out_event (GtkWidget *widget, GdkEventFocus *event, gpointer user_d
{
/* End renaming and commit change. */
end_renaming_mode (NAUTILUS_ICON_CONTAINER (widget), TRUE);
update_selected (NAUTILUS_ICON_CONTAINER (widget));
return FALSE;
......@@ -7016,7 +7108,8 @@ GdkGC *
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;
......@@ -7027,9 +7120,13 @@ nautilus_icon_container_get_label_color_and_gc (NautilusIconContainer *container
} else {
idx = LABEL_COLOR_ACTIVE;
}
} else {
if (is_prelit) {
idx = LABEL_COLOR_PRELIGHT;
} else {
idx = LABEL_COLOR;
}
}
} else {
if (is_highlight) {
if (GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (container))) {
......@@ -7108,6 +7205,7 @@ setup_label_gcs (NautilusIconContainer *container)
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 (&GTK_WIDGET (container)->style->base[GTK_STATE_SELECTED]) ? light_info_value : dark_info_value);
......@@ -7233,7 +7331,8 @@ nautilus_icon_container_theme_changed (gpointer user_data)
{
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);
......@@ -7262,6 +7361,46 @@ nautilus_icon_container_theme_changed (gpointer user_data)
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,
......@@ -7273,6 +7412,19 @@ nautilus_icon_container_theme_changed (gpointer user_data)
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);
}
......
......@@ -104,6 +104,7 @@ enum {
LABEL_COLOR,
LABEL_COLOR_HIGHLIGHT,
LABEL_COLOR_ACTIVE,
LABEL_COLOR_PRELIGHT,
LABEL_INFO_COLOR,
LABEL_INFO_COLOR_HIGHLIGHT,
LABEL_INFO_COLOR_ACTIVE,
......@@ -196,6 +197,9 @@ struct NautilusIconContainerDetails {
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];
......@@ -298,6 +302,7 @@ void nautilus_icon_container_update_scroll_region (NautilusIconC
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 */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment