changeset 12363:f758af0373cb

[gaim-migrate @ 14667] this gets rid of the warnings and should express my intent more clearly committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Mon, 05 Dec 2005 23:41:29 +0000
parents e7e3144760b0
children 6fd82071a7b8
files src/gtkconv.c
diffstat 1 files changed, 22 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkconv.c	Mon Dec 05 22:50:03 2005 +0000
+++ b/src/gtkconv.c	Mon Dec 05 23:41:29 2005 +0000
@@ -7563,7 +7563,7 @@
 static GdkColor*
 generate_nick_colors(guint numcolors, GdkColor background)
 {
-	guint i = 0;
+	guint i = 0, j = 0;
 	GdkColor *colors = g_new(GdkColor, numcolors);
 	GdkColor nick_highlight;
 	GdkColor send_color;
@@ -7573,9 +7573,16 @@
 
 	srand(background.red + background.green + background.blue + 1);
 
-	for (i ; i < numcolors; )
+	/* first we look through the list of "good" colors: colors that differ from every other color in the
+	 * list.  only some of them will differ from the background color though. lets see if we can find
+	 * numcolors of them that do
+	 */
+	while (i < numcolors && j < NUM_NICK_SEED_COLORS )
 	{
-		GdkColor color = nick_seed_colors[i];
+		GdkColor color = nick_seed_colors[j];
+
+		gaim_debug(GAIM_DEBUG_INFO, NULL,
+				   "Looking for colors from safe list, I have found %i so far.\n",i);
 
 		if (color_is_visible(color, background,     MIN_COLOR_CONTRAST,     MIN_BRIGHTNESS_CONTRAST) &&
 			color_is_visible(color, nick_highlight, MIN_COLOR_CONTRAST / 2, 0) &&
@@ -7584,12 +7591,21 @@
 			colors[i] = color;
 			i++;
 		}
-	}
-
-	for (i ; i < numcolors; )
+		j++;
+	}
+
+	/* we might not have found numcolors in the last loop.  if we did, we'll never enter this one.
+	 * if we did not, lets just find some colors that don't conflict with the background.  its
+	 * expensive to find colors that not only don't conflict with the background, but also do not
+	 * conflict with each other.
+	 */
+	while(i < numcolors )
 	{
 		GdkColor color = { 0, rand() % 65536, rand() % 65536, rand() % 65536 };
 
+		gaim_debug(GAIM_DEBUG_WARNING, NULL,
+				   "Looking for random colors to fill the list, I have found %i so far.\n",i);
+
 		if (color_is_visible(color, background,     MIN_COLOR_CONTRAST,     MIN_BRIGHTNESS_CONTRAST) &&
 			color_is_visible(color, nick_highlight, MIN_COLOR_CONTRAST / 2, 0) &&
 			color_is_visible(color, send_color,     MIN_COLOR_CONTRAST / 4, 0))