Mercurial > pidgin
comparison src/gtkconv.c @ 12356:4b8c20fcecd6
[gaim-migrate @ 14660]
Bias the color selection away from the nick highlight and send colors.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Mon, 05 Dec 2005 19:10:04 +0000 |
parents | 709548d845a1 |
children | d1af58b4a463 |
comparison
equal
deleted
inserted
replaced
12355:9afd83a7eeeb | 12356:4b8c20fcecd6 |
---|---|
66 #include "gtkutils.h" | 66 #include "gtkutils.h" |
67 #include "gtkstock.h" | 67 #include "gtkstock.h" |
68 | 68 |
69 #define AUTO_RESPONSE "<AUTO-REPLY> : " | 69 #define AUTO_RESPONSE "<AUTO-REPLY> : " |
70 | 70 |
71 #define SEND_COLOR "#204a87" | 71 #define SEND_COLOR "#16569E" |
72 #define RECV_COLOR "#cc0000" | 72 #define RECV_COLOR "#A82F2F" |
73 #define HIGHLIGHT_COLOR "#AF7F00" | |
73 | 74 |
74 /* Undef this to turn off "custom-smiley" debug messages */ | 75 /* Undef this to turn off "custom-smiley" debug messages */ |
75 #define DEBUG_CUSTOM_SMILEY | 76 #define DEBUG_CUSTOM_SMILEY |
76 | 77 |
77 #define LUMINANCE(c) (float)((0.3*(c.red))+(0.59*(c.green))+(0.11*(c.blue))) | 78 #define LUMINANCE(c) (float)((0.3*(c.red))+(0.59*(c.green))+(0.11*(c.blue))) |
146 static char *item_factory_translate_func (const char *path, gpointer func_data); | 147 static char *item_factory_translate_func (const char *path, gpointer func_data); |
147 gboolean gaim_gtkconv_has_focus(GaimConversation *conv); | 148 gboolean gaim_gtkconv_has_focus(GaimConversation *conv); |
148 static void gaim_gtkconv_custom_smiley_allocated(GdkPixbufLoader *loader, gpointer user_data); | 149 static void gaim_gtkconv_custom_smiley_allocated(GdkPixbufLoader *loader, gpointer user_data); |
149 static void gaim_gtkconv_custom_smiley_closed(GdkPixbufLoader *loader, gpointer user_data); | 150 static void gaim_gtkconv_custom_smiley_closed(GdkPixbufLoader *loader, gpointer user_data); |
150 static GdkColor* generate_nick_colors(guint numcolors, GdkColor background); | 151 static GdkColor* generate_nick_colors(guint numcolors, GdkColor background); |
151 static gboolean color_is_visible(GdkColor foreground, GdkColor background); | 152 static gboolean color_is_visible(GdkColor foreground, GdkColor background, int color_contrast, int brightness_contrast); |
152 | 153 |
153 static GdkColor *get_nick_color(GaimGtkConversation *gtkconv, const char *name) { | 154 static GdkColor *get_nick_color(GaimGtkConversation *gtkconv, const char *name) { |
154 static GdkColor col; | 155 static GdkColor col; |
155 GtkStyle *style = gtk_widget_get_style(gtkconv->imhtml); | 156 GtkStyle *style = gtk_widget_get_style(gtkconv->imhtml); |
156 float scale; | 157 float scale; |
4390 g_snprintf(str, 1024, "***%s", alias_escaped); | 4391 g_snprintf(str, 1024, "***%s", alias_escaped); |
4391 tag_start_offset += 3; | 4392 tag_start_offset += 3; |
4392 } | 4393 } |
4393 | 4394 |
4394 if (flags & GAIM_MESSAGE_NICK) | 4395 if (flags & GAIM_MESSAGE_NICK) |
4395 strcpy(color, "#AF7F00"); | 4396 strcpy(color, HIGHLIGHT_COLOR); |
4396 else | 4397 else |
4397 strcpy(color, "#062585"); | 4398 strcpy(color, "#062585"); |
4398 } | 4399 } |
4399 else { | 4400 else { |
4400 str = g_malloc(1024); | 4401 str = g_malloc(1024); |
4405 } else { | 4406 } else { |
4406 g_snprintf(str, 1024, "%s:", alias_escaped); | 4407 g_snprintf(str, 1024, "%s:", alias_escaped); |
4407 tag_end_offset = 1; | 4408 tag_end_offset = 1; |
4408 } | 4409 } |
4409 if (flags & GAIM_MESSAGE_NICK) | 4410 if (flags & GAIM_MESSAGE_NICK) |
4410 strcpy(color, "#AF7F00"); | 4411 strcpy(color, HIGHLIGHT_COLOR); |
4411 else if (flags & GAIM_MESSAGE_RECV) { | 4412 else if (flags & GAIM_MESSAGE_RECV) { |
4412 if (flags & GAIM_MESSAGE_COLORIZE) { | 4413 if (flags & GAIM_MESSAGE_COLORIZE) { |
4413 GdkColor *col = get_nick_color(gtkconv, alias); | 4414 GdkColor *col = get_nick_color(gtkconv, alias); |
4414 | 4415 |
4415 g_snprintf(color, sizeof(color), "#%02X%02X%02X", | 4416 g_snprintf(color, sizeof(color), "#%02X%02X%02X", |
7508 } | 7509 } |
7509 | 7510 |
7510 | 7511 |
7511 /* Algorithm from http://www.w3.org/TR/AERT#color-contrast */ | 7512 /* Algorithm from http://www.w3.org/TR/AERT#color-contrast */ |
7512 static gboolean | 7513 static gboolean |
7513 color_is_visible(GdkColor foreground, GdkColor background) | 7514 color_is_visible(GdkColor foreground, GdkColor background, int color_contrast, int brightness_contrast) |
7514 { | 7515 { |
7515 gulong fg_brightness; | 7516 gulong fg_brightness; |
7516 gulong bg_brightness; | 7517 gulong bg_brightness; |
7517 gulong br_diff; | 7518 gulong br_diff; |
7518 gulong col_diff; | 7519 gulong col_diff; |
7536 bg_brightness = (bred * 299 + bgreen * 587 + bblue * 114) / 1000; | 7537 bg_brightness = (bred * 299 + bgreen * 587 + bblue * 114) / 1000; |
7537 br_diff = abs(fg_brightness - bg_brightness); | 7538 br_diff = abs(fg_brightness - bg_brightness); |
7538 | 7539 |
7539 col_diff = abs(fred - bred) + abs(fgreen - bgreen) + abs(fblue - bblue); | 7540 col_diff = abs(fred - bred) + abs(fgreen - bgreen) + abs(fblue - bblue); |
7540 | 7541 |
7541 return ((col_diff > MIN_COLOR_CONTRAST) && (br_diff > MIN_BRIGHTNESS_CONTRAST)); | 7542 return ((col_diff > color_contrast) && (br_diff > brightness_contrast)); |
7542 } | 7543 } |
7543 | 7544 |
7544 | 7545 |
7545 static GdkColor* | 7546 static GdkColor* |
7546 generate_nick_colors(guint numcolors, GdkColor background) | 7547 generate_nick_colors(guint numcolors, GdkColor background) |
7547 { | 7548 { |
7548 guint i; | 7549 guint i; |
7549 GdkColor *colors = g_new(GdkColor, numcolors); | 7550 GdkColor *colors = g_new(GdkColor, numcolors); |
7551 GdkColor nick_highlight; | |
7552 GdkColor send_color; | |
7553 | |
7554 gdk_color_parse(HIGHLIGHT_COLOR, &nick_highlight); | |
7555 gdk_color_parse(SEND_COLOR, &send_color); | |
7550 | 7556 |
7551 srand(background.red + background.green + background.blue + 1); | 7557 srand(background.red + background.green + background.blue + 1); |
7552 | 7558 |
7553 for (i = 0; i < numcolors; ) | 7559 for (i = 0; i < numcolors; ) |
7554 { | 7560 { |
7555 GdkColor color = { 0, rand() % 65536, rand() % 65536, rand() % 65536 }; | 7561 GdkColor color = { 0, rand() % 65536, rand() % 65536, rand() % 65536 }; |
7556 if (color_is_visible(color, background)){ | 7562 if (color_is_visible(color, background, MIN_COLOR_CONTRAST, MIN_BRIGHTNESS_CONTRAST) && |
7563 color_is_visible(color, nick_highlight, MIN_COLOR_CONTRAST / 2, 0) && | |
7564 color_is_visible(color, send_color, MIN_COLOR_CONTRAST / 4, 0)) | |
7565 { | |
7557 colors[i] = color; | 7566 colors[i] = color; |
7558 i++; | 7567 i++; |
7559 } | 7568 } |
7560 } | 7569 } |
7561 | 7570 |