diff options
author | John Harper <jsh@eazel.com> | 2001-01-18 04:58:53 +0000 |
---|---|---|
committer | John Harper <jsh@src.gnome.org> | 2001-01-18 04:58:53 +0000 |
commit | 1ffed35feb1c698be9e3414f6d00b38b0564fa2f (patch) | |
tree | db1aadb7d8794bdd93c74d887076680477552447 /libnautilus-private/nautilus-gdk-extensions.c | |
parent | 549f5355a273ffa2e7d8ba02e0d419d8db379825 (diff) | |
download | nautilus-1ffed35feb1c698be9e3414f6d00b38b0564fa2f.tar.gz |
reviewed by: Pavel Cisler <pavel@eazel.com>
2001-01-17 John Harper <jsh@eazel.com>
reviewed by: Pavel Cisler <pavel@eazel.com>
Work to fix bugs 1939 and 4614 -- text in list view is hard to
read when the foreground color specified by the gtk theme
conflicts with the background colors:
* libnautilus-extensions/nautilus-gdk-extensions.h,
libnautilus-extensions/nautilus-gdk-extensions.c
(nautilus_gdk_color_is_dark,
nautilus_gdk_choose_foreground_color,
nautilus_gdk_gc_choose_foreground_color): new functions, used
for testing whether a foreground/background color pair is
suitable for drawing text, and if not, choosing a new
foreground color
* libnautilus-extensions/nautilus-list.c (NautilusListDetails):
added gc fields: text_color, selected_text_color, link_text_color
(unref_gcs, make_gcs_and_colors): handle the new gcs
(nautilus_list_setup_style_colors): use
nautilus_gdk_gc_set_foreground_color () to create the gcs that
will be used for drawing text
(draw_cell): when drawing text cells, don't use the default
foreground gc, use one of the specially chosen gcs
Diffstat (limited to 'libnautilus-private/nautilus-gdk-extensions.c')
-rw-r--r-- | libnautilus-private/nautilus-gdk-extensions.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/libnautilus-private/nautilus-gdk-extensions.c b/libnautilus-private/nautilus-gdk-extensions.c index deca7cea5..5edcd5187 100644 --- a/libnautilus-private/nautilus-gdk-extensions.c +++ b/libnautilus-private/nautilus-gdk-extensions.c @@ -558,6 +558,83 @@ nautilus_rgb_shift_color (guint32 color, float shift_by) } /** + * nautilus_gdk_color_is_dark: + * + * Return true if the given color is `dark' + */ +gboolean +nautilus_gdk_color_is_dark (GdkColor *color) +{ + int intensity; + + intensity = (((color->red >> 8) * 77) + + ((color->green >> 8) * 150) + + ((color->blue >> 8) * 28)) >> 8; + + return intensity < 128; +} + +/** + * nautilus_gdk_choose_foreground_color: + * + * Select a foreground color given that BACKGROUND is the background + * color. If the PREFERRED color has a high enough contrast with + * BACKGROUND, use it, else use one of black or white, depending on + * the darkness of BACKGROUND. + * + * The selected color is stored in PREFERRED. + */ +void +nautilus_gdk_choose_foreground_color (GdkColor *preferred, + GdkColor *background) +{ + gboolean preferred_is_dark, background_is_dark; + + preferred_is_dark = nautilus_gdk_color_is_dark (preferred); + background_is_dark = nautilus_gdk_color_is_dark (background); + + if (preferred_is_dark == background_is_dark) { + /* Colors are too similar, so choose a different fg. + * Currently hardcoded to use either white or black. + */ + if (preferred_is_dark) { + preferred->red = 65535; + preferred->green = 65535; + preferred->blue = 65535; + } else { + preferred->red = 0; + preferred->green = 0; + preferred->blue = 0; + } + } +} + +/** + * nautilus_gdk_gc_choose_foreground_color: + * + * Use nautilus_gdk_color_choose_foreground_color () to set the + * foreground color of GC to something suitable, given that BACKGROUND + * will be the background color and PREFERRED is the preferred color. + * + * Uses GdkRGB to install the color value. + */ +void +nautilus_gdk_gc_choose_foreground_color (GdkGC *gc, + GdkColor *preferred, + GdkColor *background) +{ + GdkColor temp; + guint32 rgb; + + temp = *preferred; + nautilus_gdk_choose_foreground_color (&temp, background); + rgb = nautilus_gdk_color_to_rgb (&temp); + + gdk_rgb_init (); + gdk_rgb_gc_set_foreground (gc, rgb); +} + +/** * nautilus_stipple_bitmap: * * Get pointer to singleton 50% stippled bitmap. |