Commit 50735a65 authored by Andy Hertzfeld's avatar Andy Hertzfeld

improved selection highlighting by darkening the icon and emboldening the


	improved selection highlighting by darkening the icon and emboldening
	the font
parent 5ef2bdcf
2000-03-25 Andy Hertzfeld <andy@eazel.com>
Improved selection highlighting.
* libnautilus/nautilus-graphic-effects.c,h:
added create_darkened_pixbuf routine based on one in panel
* libnautilus/icon-private.h:
added field for highlight_font
* libnautilus/icon-container.c:
loads and maintain highlight font
* libnautilus/icon-canvas-item:
if item is selected, darken the icon and use the highlight font
2000-03-24 Darin Adler <darin@eazel.com>
Fixed bug 337 (Crash on userlevel change).
......
......@@ -33,7 +33,7 @@
#include "nautilus-graphic-effects.h"
/* graphics routine to lighten a pixbuf */
/* utility routine to bump the level of a color component with pinning */
static guchar
lighten_component (guchar cur_value)
......@@ -45,8 +45,8 @@ lighten_component (guchar cur_value)
return (guchar) new_value;
}
static void
do_lighten (GdkPixbuf *dest, GdkPixbuf *src)
GdkPixbuf *
create_spotlight_pixbuf (GdkPixbuf* src)
{
int i, j;
int width, height, has_alpha, src_rowstride, dst_rowstride;
......@@ -54,6 +54,13 @@ do_lighten (GdkPixbuf *dest, GdkPixbuf *src)
guchar *original_pixels;
guchar *pixsrc;
guchar *pixdest;
GdkPixbuf *dest;
dest = gdk_pixbuf_new (gdk_pixbuf_get_format (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);
......@@ -75,22 +82,64 @@ do_lighten (GdkPixbuf *dest, GdkPixbuf *src)
}
}
}
return dest;
}
/* utility routine to lighten a pixbuf for pre-lighting */
/* the following routine was stolen from the panel to darken a pixbuf, by manipulating the saturation */
#define INTENSITY(r, g, b) (((r)*77 + (g)*150 + (b)*28)>>8)
/* saturation is 0-255, darken is 0-255 */
GdkPixbuf *
create_spotlight_pixbuf (GdkPixbuf* source_pixbuf)
create_darkened_pixbuf (GdkPixbuf *src, int saturation, int darken)
{
GdkPixbuf *new = gdk_pixbuf_new (gdk_pixbuf_get_format (source_pixbuf),
gdk_pixbuf_get_has_alpha (source_pixbuf),
gdk_pixbuf_get_bits_per_sample (source_pixbuf),
gdk_pixbuf_get_width (source_pixbuf),
gdk_pixbuf_get_height (source_pixbuf));
do_lighten (new, source_pixbuf);
return new;
gint i, j;
gint width, height, has_alpha, rowstride;
guchar *target_pixels;
guchar *original_pixels;
guchar *pixsrc;
guchar *pixdest;
guchar intensity;
guchar alpha;
guchar negalpha;
guchar r,g,b;
GdkPixbuf *dest;
dest = gdk_pixbuf_new (gdk_pixbuf_get_format (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);
rowstride = 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*rowstride;
pixsrc = original_pixels + i*rowstride;
for (j = 0; j < width; j++) {
r = *(pixsrc++);
g = *(pixsrc++);
b = *(pixsrc++);
intensity = INTENSITY(r,g,b);
negalpha = ((255 - saturation)*darken)>>8;
alpha = (saturation*darken)>>8;
*(pixdest++) = (negalpha * intensity + alpha * r) >> 8;
*(pixdest++) = (negalpha * intensity + alpha * g) >> 8;
*(pixdest++) = (negalpha * intensity + alpha * b) >> 8;
if (has_alpha)
*(pixdest++) = *(pixsrc++);
}
}
return dest;
}
#undef INTENSITY
/* this routine takes the source pixbuf and returns a new one that's semi-transparent, by
clearing every other pixel's alpha value in a checkerboard grip. We have to do the
......
......@@ -32,6 +32,9 @@
/* return a lightened pixbuf for pre-lighting */
GdkPixbuf* create_spotlight_pixbuf (GdkPixbuf* source_pixbuf);
/* return a darkened pixbuf for selection hiliting */
GdkPixbuf* create_darkened_pixbuf (GdkPixbuf *src, int saturation, int darken);
/* return a semi-transparent pixbuf from the source pixbuf using a checkboard
stipple in the alpha channel (so it can be converted to an alpha-less pixmap) */
GdkPixbuf* make_semi_transparent(GdkPixbuf *source_pixbuf);
......
......@@ -52,6 +52,7 @@ struct NautilusIconCanvasItemDetails {
GList *emblem_pixbufs;
char *text;
GdkFont *font;
GdkFont *highlight_font;
ArtIRect embedded_text_rect;
char *embedded_text_file_URI;
......@@ -72,6 +73,7 @@ enum {
ARG_0,
ARG_TEXT,
ARG_FONT,
ARG_HIGHLIGHT_FONT,
ARG_HIGHLIGHTED_FOR_SELECTION,
ARG_HIGHLIGHTED_AS_KEYBOARD_FOCUS,
ARG_HIGHLIGHTED_FOR_DROP,
......@@ -182,6 +184,9 @@ nautilus_icon_canvas_item_initialize_class (NautilusIconCanvasItemClass *class)
GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_TEXT);
gtk_object_add_arg_type ("NautilusIconCanvasItem::font",
GTK_TYPE_BOXED, GTK_ARG_READWRITE, ARG_FONT);
gtk_object_add_arg_type ("NautilusIconCanvasItem::highlight_font",
GTK_TYPE_BOXED, GTK_ARG_READWRITE, ARG_HIGHLIGHT_FONT);
gtk_object_add_arg_type ("NautilusIconCanvasItem::highlighted_for_selection",
GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_HIGHLIGHTED_FOR_SELECTION);
gtk_object_add_arg_type ("NautilusIconCanvasItem::highlighted_as_keyboard_focus",
......@@ -251,10 +256,11 @@ nautilus_icon_canvas_item_destroy (GtkObject *object)
}
nautilus_gdk_pixbuf_list_free (details->emblem_pixbufs);
g_free (details->text);
if (details->font != NULL) {
if (details->font != NULL)
gdk_font_unref (details->font);
}
if (details->highlight_font != NULL)
gdk_font_unref (details->highlight_font);
g_free (details);
NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
......@@ -308,6 +314,21 @@ nautilus_icon_canvas_item_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
details->font = font;
break;
case ARG_HIGHLIGHT_FONT:
font = GTK_VALUE_BOXED (*arg);
if (nautilus_gdk_font_equal (font, details->highlight_font)) {
return;
}
if (font != NULL) {
gdk_font_ref (font);
}
if (details->highlight_font != NULL) {
gdk_font_unref (details->highlight_font);
}
details->highlight_font = font;
break;
case ARG_HIGHLIGHTED_FOR_SELECTION:
if (!details->is_highlighted_for_selection == !GTK_VALUE_BOOL (*arg)) {
return;
......@@ -364,6 +385,10 @@ nautilus_icon_canvas_item_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
GTK_VALUE_BOXED (*arg) = details->font;
break;
case ARG_HIGHLIGHT_FONT:
GTK_VALUE_BOXED (*arg) = details->highlight_font;
break;
case ARG_HIGHLIGHTED_FOR_SELECTION:
GTK_VALUE_BOOL (*arg) = details->is_highlighted_for_selection;
break;
......@@ -552,6 +577,7 @@ draw_or_measure_label_text (NautilusIconCanvasItem *item,
NautilusIconCanvasItemDetails *details;
int width_so_far, height_so_far;
GdkGC* gc;
GdkFont *font;
int max_text_width;
int icon_width, text_left, box_left;
GnomeIconTextInfo *icon_text_info;
......@@ -561,7 +587,12 @@ draw_or_measure_label_text (NautilusIconCanvasItem *item,
details = item->details;
if (details->font == NULL || details->text == NULL || details->text[0] == '\0') {
if (details->is_highlighted_for_selection)
font = details->highlight_font;
else
font = details->font;
if (font == NULL || details->text == NULL || details->text[0] == '\0') {
details->text_height = 0;
details->text_width = 0;
return;
......@@ -587,9 +618,9 @@ draw_or_measure_label_text (NautilusIconCanvasItem *item,
}
icon_text_info = gnome_icon_layout_text
(details->font, text_piece, " -_,;.?/&", max_text_width, TRUE);
(font, text_piece, " -_,;.?/&", max_text_width, TRUE);
if (drawable != NULL) {
if (drawable != NULL) {
text_left = icon_left + (icon_width - icon_text_info->width) / 2;
gnome_icon_paint_text (icon_text_info, drawable, gc,
text_left, icon_bottom + height_so_far, GTK_JUSTIFY_CENTER);
......@@ -615,15 +646,6 @@ draw_or_measure_label_text (NautilusIconCanvasItem *item,
g_assert (width_so_far == details->text_width);
box_left = icon_left + (icon_width - width_so_far) / 2;
/* invert to indicate selection if necessary */
if (details->is_highlighted_for_selection) {
gdk_gc_set_function (gc, GDK_INVERT);
gdk_draw_rectangle (drawable, gc, TRUE,
box_left, icon_bottom - 2,
width_so_far, 2 + height_so_far);
gdk_gc_set_function (gc, GDK_COPY);
}
/* indicate keyboard selection by framing the text with a gray-stippled rectangle */
if (details->is_highlighted_as_keyboard_focus) {
......@@ -923,7 +945,7 @@ nautilus_icon_canvas_item_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
NautilusIconCanvasItemDetails *details;
ArtIRect icon_rect, emblem_rect;
EmblemLayout emblem_layout;
GdkPixbuf *emblem_pixbuf, *prelit_pixbuf;
GdkPixbuf *emblem_pixbuf, *prelit_pixbuf, *selected_pixbuf;
icon_item = NAUTILUS_ICON_CANVAS_ITEM (item);
details = icon_item->details;
......@@ -940,12 +962,18 @@ nautilus_icon_canvas_item_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
icon_rect.x1 -= x;
icon_rect.y1 -= y;
/* if the pre-lit flag is set, make a pre-lit pixbuf and draw that instead */
/* if the pre-lit or selection flag is set, make a pre-lit or darkened pixbuf and draw that instead */
if (details->is_prelit) {
prelit_pixbuf = create_spotlight_pixbuf (details->pixbuf);
draw_pixbuf (prelit_pixbuf, drawable, icon_rect.x0, icon_rect.y0);
gdk_pixbuf_unref (prelit_pixbuf);
}
else if (details->is_highlighted_for_selection) {
selected_pixbuf = create_darkened_pixbuf (details->pixbuf, (int)(0.6*255), (int)(0.6*255));
draw_pixbuf (selected_pixbuf, drawable, icon_rect.x0, icon_rect.y0);
gdk_pixbuf_unref (selected_pixbuf);
} else {
draw_pixbuf (details->pixbuf, drawable, icon_rect.x0, icon_rect.y0);
}
......@@ -959,7 +987,7 @@ nautilus_icon_canvas_item_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
/* Draw stretching handles (if necessary). */
draw_stretch_handles (icon_item, drawable, &icon_rect);
/* Draw embedded text. */
/* Draw embedded text (if necessary) */
draw_embedded_text (item, drawable, &icon_rect);
/* Draw the label text. */
......
......@@ -1352,9 +1352,10 @@ destroy (GtkObject *object)
gtk_idle_remove (container->details->idle_id);
}
for (i = 0; i < NAUTILUS_N_ELEMENTS (container->details->label_font); i++) {
if (container->details->label_font[i] != NULL) {
gdk_font_unref (container->details->label_font[i]);
}
if (container->details->label_font[i] != NULL)
gdk_font_unref (container->details->label_font[i]);
if (container->details->hilite_font[i] != NULL)
gdk_font_unref (container->details->hilite_font[i]);
}
g_free (container->details);
......@@ -1890,6 +1891,14 @@ nautilus_icon_container_initialize (NautilusIconContainer *container)
details->label_font[NAUTILUS_ZOOM_LEVEL_LARGER] = load_font ("-*-helvetica-medium-r-normal-*-18-*-*-*-*-*-*-*");
details->label_font[NAUTILUS_ZOOM_LEVEL_LARGEST] = load_font ("-*-helvetica-medium-r-normal-*-18-*-*-*-*-*-*-*");
details->hilite_font[NAUTILUS_ZOOM_LEVEL_SMALLEST] = load_font ("-*-helvetica-bold-r-normal-*-8-*-*-*-*-*-*-*");
details->hilite_font[NAUTILUS_ZOOM_LEVEL_SMALLER] = load_font ("-*-helvetica-bold-r-normal-*-8-*-*-*-*-*-*-*");
details->hilite_font[NAUTILUS_ZOOM_LEVEL_SMALL] = load_font ("-*-helvetica-bold-r-normal-*-10-*-*-*-*-*-*-*");
details->hilite_font[NAUTILUS_ZOOM_LEVEL_STANDARD] = load_font ("-*-helvetica-bold-r-normal-*-12-*-*-*-*-*-*-*");
details->hilite_font[NAUTILUS_ZOOM_LEVEL_LARGE] = load_font ("-*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*");
details->hilite_font[NAUTILUS_ZOOM_LEVEL_LARGER] = load_font ("-*-helvetica-bold-r-normal-*-18-*-*-*-*-*-*-*");
details->hilite_font[NAUTILUS_ZOOM_LEVEL_LARGEST] = load_font ("-*-helvetica-bold-r-normal-*-18-*-*-*-*-*-*-*");
/* FIXME: Read this from preferences. */
details->single_click_mode = TRUE;
......@@ -2166,7 +2175,7 @@ update_icon (NautilusIconContainer *container, NautilusIcon *icon)
GList *emblem_icons, *emblem_pixbufs, *p;
char *label;
char *contents_as_text;
GdkFont *font;
GdkFont *font, *item_hilite_font;
details = container->details;
......@@ -2205,6 +2214,7 @@ update_icon (NautilusIconContainer *container, NautilusIcon *icon)
&label);
font = details->label_font[details->zoom_level];
item_hilite_font = details->hilite_font[details->zoom_level];
/* Choose to show mini-text based on this icon's requested size,
* not zoom level, since icon may be stretched big or small.
......@@ -2223,6 +2233,7 @@ update_icon (NautilusIconContainer *container, NautilusIcon *icon)
gnome_canvas_item_set (GNOME_CANVAS_ITEM (icon->item),
"text", label,
"font", font,
"highlight_font", item_hilite_font,
"text_source", contents_as_text,
NULL);
nautilus_icon_canvas_item_set_image (icon->item, pixbuf, &text_rect);
......
......@@ -148,7 +148,8 @@ struct NautilusIconContainerDetails {
/* default fonts used to draw labels */
GdkFont *label_font[NAUTILUS_ZOOM_LEVEL_LARGEST + 1];
GdkFont *hilite_font[NAUTILUS_ZOOM_LEVEL_LARGEST + 1];
/* State used so arrow keys don't wander if icons aren't lined up.
* Keeps track of last axis arrow key was used on.
*/
......
......@@ -33,7 +33,7 @@
#include "nautilus-graphic-effects.h"
/* graphics routine to lighten a pixbuf */
/* utility routine to bump the level of a color component with pinning */
static guchar
lighten_component (guchar cur_value)
......@@ -45,8 +45,8 @@ lighten_component (guchar cur_value)
return (guchar) new_value;
}
static void
do_lighten (GdkPixbuf *dest, GdkPixbuf *src)
GdkPixbuf *
create_spotlight_pixbuf (GdkPixbuf* src)
{
int i, j;
int width, height, has_alpha, src_rowstride, dst_rowstride;
......@@ -54,6 +54,13 @@ do_lighten (GdkPixbuf *dest, GdkPixbuf *src)
guchar *original_pixels;
guchar *pixsrc;
guchar *pixdest;
GdkPixbuf *dest;
dest = gdk_pixbuf_new (gdk_pixbuf_get_format (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);
......@@ -75,22 +82,64 @@ do_lighten (GdkPixbuf *dest, GdkPixbuf *src)
}
}
}
return dest;
}
/* utility routine to lighten a pixbuf for pre-lighting */
/* the following routine was stolen from the panel to darken a pixbuf, by manipulating the saturation */
#define INTENSITY(r, g, b) (((r)*77 + (g)*150 + (b)*28)>>8)
/* saturation is 0-255, darken is 0-255 */
GdkPixbuf *
create_spotlight_pixbuf (GdkPixbuf* source_pixbuf)
create_darkened_pixbuf (GdkPixbuf *src, int saturation, int darken)
{
GdkPixbuf *new = gdk_pixbuf_new (gdk_pixbuf_get_format (source_pixbuf),
gdk_pixbuf_get_has_alpha (source_pixbuf),
gdk_pixbuf_get_bits_per_sample (source_pixbuf),
gdk_pixbuf_get_width (source_pixbuf),
gdk_pixbuf_get_height (source_pixbuf));
do_lighten (new, source_pixbuf);
return new;
gint i, j;
gint width, height, has_alpha, rowstride;
guchar *target_pixels;
guchar *original_pixels;
guchar *pixsrc;
guchar *pixdest;
guchar intensity;
guchar alpha;
guchar negalpha;
guchar r,g,b;
GdkPixbuf *dest;
dest = gdk_pixbuf_new (gdk_pixbuf_get_format (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);
rowstride = 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*rowstride;
pixsrc = original_pixels + i*rowstride;
for (j = 0; j < width; j++) {
r = *(pixsrc++);
g = *(pixsrc++);
b = *(pixsrc++);
intensity = INTENSITY(r,g,b);
negalpha = ((255 - saturation)*darken)>>8;
alpha = (saturation*darken)>>8;
*(pixdest++) = (negalpha * intensity + alpha * r) >> 8;
*(pixdest++) = (negalpha * intensity + alpha * g) >> 8;
*(pixdest++) = (negalpha * intensity + alpha * b) >> 8;
if (has_alpha)
*(pixdest++) = *(pixsrc++);
}
}
return dest;
}
#undef INTENSITY
/* this routine takes the source pixbuf and returns a new one that's semi-transparent, by
clearing every other pixel's alpha value in a checkerboard grip. We have to do the
......
......@@ -32,6 +32,9 @@
/* return a lightened pixbuf for pre-lighting */
GdkPixbuf* create_spotlight_pixbuf (GdkPixbuf* source_pixbuf);
/* return a darkened pixbuf for selection hiliting */
GdkPixbuf* create_darkened_pixbuf (GdkPixbuf *src, int saturation, int darken);
/* return a semi-transparent pixbuf from the source pixbuf using a checkboard
stipple in the alpha channel (so it can be converted to an alpha-less pixmap) */
GdkPixbuf* make_semi_transparent(GdkPixbuf *source_pixbuf);
......
......@@ -52,6 +52,7 @@ struct NautilusIconCanvasItemDetails {
GList *emblem_pixbufs;
char *text;
GdkFont *font;
GdkFont *highlight_font;
ArtIRect embedded_text_rect;
char *embedded_text_file_URI;
......@@ -72,6 +73,7 @@ enum {
ARG_0,
ARG_TEXT,
ARG_FONT,
ARG_HIGHLIGHT_FONT,
ARG_HIGHLIGHTED_FOR_SELECTION,
ARG_HIGHLIGHTED_AS_KEYBOARD_FOCUS,
ARG_HIGHLIGHTED_FOR_DROP,
......@@ -182,6 +184,9 @@ nautilus_icon_canvas_item_initialize_class (NautilusIconCanvasItemClass *class)
GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_TEXT);
gtk_object_add_arg_type ("NautilusIconCanvasItem::font",
GTK_TYPE_BOXED, GTK_ARG_READWRITE, ARG_FONT);
gtk_object_add_arg_type ("NautilusIconCanvasItem::highlight_font",
GTK_TYPE_BOXED, GTK_ARG_READWRITE, ARG_HIGHLIGHT_FONT);
gtk_object_add_arg_type ("NautilusIconCanvasItem::highlighted_for_selection",
GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_HIGHLIGHTED_FOR_SELECTION);
gtk_object_add_arg_type ("NautilusIconCanvasItem::highlighted_as_keyboard_focus",
......@@ -251,10 +256,11 @@ nautilus_icon_canvas_item_destroy (GtkObject *object)
}
nautilus_gdk_pixbuf_list_free (details->emblem_pixbufs);
g_free (details->text);
if (details->font != NULL) {
if (details->font != NULL)
gdk_font_unref (details->font);
}
if (details->highlight_font != NULL)
gdk_font_unref (details->highlight_font);
g_free (details);
NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
......@@ -308,6 +314,21 @@ nautilus_icon_canvas_item_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
details->font = font;
break;
case ARG_HIGHLIGHT_FONT:
font = GTK_VALUE_BOXED (*arg);
if (nautilus_gdk_font_equal (font, details->highlight_font)) {
return;
}
if (font != NULL) {
gdk_font_ref (font);
}
if (details->highlight_font != NULL) {
gdk_font_unref (details->highlight_font);
}
details->highlight_font = font;
break;
case ARG_HIGHLIGHTED_FOR_SELECTION:
if (!details->is_highlighted_for_selection == !GTK_VALUE_BOOL (*arg)) {
return;
......@@ -364,6 +385,10 @@ nautilus_icon_canvas_item_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
GTK_VALUE_BOXED (*arg) = details->font;
break;
case ARG_HIGHLIGHT_FONT:
GTK_VALUE_BOXED (*arg) = details->highlight_font;
break;
case ARG_HIGHLIGHTED_FOR_SELECTION:
GTK_VALUE_BOOL (*arg) = details->is_highlighted_for_selection;
break;
......@@ -552,6 +577,7 @@ draw_or_measure_label_text (NautilusIconCanvasItem *item,
NautilusIconCanvasItemDetails *details;
int width_so_far, height_so_far;
GdkGC* gc;
GdkFont *font;
int max_text_width;
int icon_width, text_left, box_left;
GnomeIconTextInfo *icon_text_info;
......@@ -561,7 +587,12 @@ draw_or_measure_label_text (NautilusIconCanvasItem *item,
details = item->details;
if (details->font == NULL || details->text == NULL || details->text[0] == '\0') {
if (details->is_highlighted_for_selection)
font = details->highlight_font;
else
font = details->font;
if (font == NULL || details->text == NULL || details->text[0] == '\0') {
details->text_height = 0;
details->text_width = 0;
return;
......@@ -587,9 +618,9 @@ draw_or_measure_label_text (NautilusIconCanvasItem *item,
}
icon_text_info = gnome_icon_layout_text
(details->font, text_piece, " -_,;.?/&", max_text_width, TRUE);
(font, text_piece, " -_,;.?/&", max_text_width, TRUE);
if (drawable != NULL) {
if (drawable != NULL) {
text_left = icon_left + (icon_width - icon_text_info->width) / 2;
gnome_icon_paint_text (icon_text_info, drawable, gc,
text_left, icon_bottom + height_so_far, GTK_JUSTIFY_CENTER);
......@@ -615,15 +646,6 @@ draw_or_measure_label_text (NautilusIconCanvasItem *item,
g_assert (width_so_far == details->text_width);
box_left = icon_left + (icon_width - width_so_far) / 2;
/* invert to indicate selection if necessary */
if (details->is_highlighted_for_selection) {
gdk_gc_set_function (gc, GDK_INVERT);
gdk_draw_rectangle (drawable, gc, TRUE,
box_left, icon_bottom - 2,
width_so_far, 2 + height_so_far);
gdk_gc_set_function (gc, GDK_COPY);
}
/* indicate keyboard selection by framing the text with a gray-stippled rectangle */
if (details->is_highlighted_as_keyboard_focus) {
......@@ -923,7 +945,7 @@ nautilus_icon_canvas_item_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
NautilusIconCanvasItemDetails *details;
ArtIRect icon_rect, emblem_rect;
EmblemLayout emblem_layout;
GdkPixbuf *emblem_pixbuf, *prelit_pixbuf;
GdkPixbuf *emblem_pixbuf, *prelit_pixbuf, *selected_pixbuf;
icon_item = NAUTILUS_ICON_CANVAS_ITEM (item);
details = icon_item->details;
......@@ -940,12 +962,18 @@ nautilus_icon_canvas_item_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
icon_rect.x1 -= x;
icon_rect.y1 -= y;
/* if the pre-lit flag is set, make a pre-lit pixbuf and draw that instead */
/* if the pre-lit or selection flag is set, make a pre-lit or darkened pixbuf and draw that instead */
if (details->is_prelit) {
prelit_pixbuf = create_spotlight_pixbuf (details->pixbuf);
draw_pixbuf (prelit_pixbuf, drawable, icon_rect.x0, icon_rect.y0);
gdk_pixbuf_unref (prelit_pixbuf);
}
else if (details->is_highlighted_for_selection) {
selected_pixbuf = create_darkened_pixbuf (details->pixbuf, (int)(0.6*255), (int)(0.6*255));
draw_pixbuf (selected_pixbuf, drawable, icon_rect.x0, icon_rect.y0);
gdk_pixbuf_unref (selected_pixbuf);
} else {
draw_pixbuf (details->pixbuf, drawable, icon_rect.x0, icon_rect.y0);
}
......@@ -959,7 +987,7 @@ nautilus_icon_canvas_item_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
/* Draw stretching handles (if necessary). */
draw_stretch_handles (icon_item, drawable, &icon_rect);
/* Draw embedded text. */
/* Draw embedded text (if necessary) */
draw_embedded_text (item, drawable, &icon_rect);