r5309 - in trunk/data/qcsrc: client menu menu/item

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Thu Dec 25 13:03:28 EST 2008


Author: div0
Date: 2008-12-25 13:03:28 -0500 (Thu, 25 Dec 2008)
New Revision: 5309

Modified:
   trunk/data/qcsrc/client/miscfunctions.qc
   trunk/data/qcsrc/menu/draw.qc
   trunk/data/qcsrc/menu/item/inputbox.c
Log:
terrencehill's color codes patch. Please test thoroughly!


Modified: trunk/data/qcsrc/client/miscfunctions.qc
===================================================================
--- trunk/data/qcsrc/client/miscfunctions.qc	2008-12-25 17:43:41 UTC (rev 5308)
+++ trunk/data/qcsrc/client/miscfunctions.qc	2008-12-25 18:03:28 UTC (rev 5309)
@@ -136,11 +136,22 @@
 			ch = str2chr(text, i+1);
 			if(ch >= '0' && ch <= '9')
 				++i;
-			else
-				++width;
-		}
-		else
-			++width;
+			else if(i+4 < len && ch == 'x')
+			{
+				ch = str2chr(text, i+2);
+				if ( (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F') )
+				{
+					ch = str2chr(text, i+3);
+					if ( (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F') )
+					{
+						ch = str2chr(text, i+4);
+						if ( (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F') )
+							i+=4;
+						else ++width;
+					} else ++width;
+				} else ++width;
+			} else ++width;
+		} else ++width;
 	}
 	return width;
 }

Modified: trunk/data/qcsrc/menu/draw.qc
===================================================================
--- trunk/data/qcsrc/menu/draw.qc	2008-12-25 17:43:41 UTC (rev 5308)
+++ trunk/data/qcsrc/menu/draw.qc	2008-12-25 18:03:28 UTC (rev 5309)
@@ -295,6 +295,7 @@
 		return strlen(theText); // yeah!
 
 	// binary search for right place to cut string
+	float ch;
 	float left, right, middle; // this always works
 	left = 0;
 	right = strlen(theText); // this always fails
@@ -313,6 +314,32 @@
 	// terminate, as the range still halves each time - but nevertheless, it is
 	// guaranteed that it finds ONE valid cutoff place (where "left" is in
 	// range, and "right" is outside).
-
+	
+	// terencehill: the following code detects truncated ^xrgb tags (e.g. ^x or ^x4)
+	// and decrease left on the basis of the chars detected of the truncated tag
+	// Even if the ^xrgb tag is not complete/correct, left is decreased
+	// (sometimes too much but with a correct result)
+	// it fixes also ^[0-9]
+	if (left >= 1 && substring(theText, left-1, 1) == "^") // * it doesn't consider one or more ^ before the current ^
+		left-=1;
+	else if (left >= 2 && substring(theText, left-2, 2) == "^x") // ^x/
+		left-=2;
+	else if (left >= 3 && substring(theText, left-3, 2) == "^x")
+		{
+			ch = str2chr(theText, left-1);
+			if( (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F') ) // ^xr/
+				left-=3;
+		}
+	else if (left >= 4 && substring(theText, left-4, 2) == "^x")
+		{
+			ch = str2chr(theText, left-2);
+			if ( (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F') )
+			{
+				ch = str2chr(theText, left-1);
+				if ( (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F') ) // ^xrg/
+					left-=4;
+			}
+		}
+	
 	return left;
 }

Modified: trunk/data/qcsrc/menu/item/inputbox.c
===================================================================
--- trunk/data/qcsrc/menu/item/inputbox.c	2008-12-25 17:43:41 UTC (rev 5308)
+++ trunk/data/qcsrc/menu/item/inputbox.c	2008-12-25 18:03:28 UTC (rev 5309)
@@ -163,13 +163,17 @@
 		string ch, ch2;
 		float i;
 		vector theColor;
-		float theAlpha;
+		float theAlpha;    //float theVariableAlpha;
 		vector p;
 		float brightness;
+		vector theTempColor;
+		float component;
+		
 		brightness = cvar("r_textbrightness");
 		p = me.realOrigin - eX * me.scrollPos;
 		theColor = '1 1 1';
-		theAlpha = 1;
+		theAlpha = 1;    //theVariableAlpha = 1; // changes when ^ax found
+		
 		for(i = 0; i < strlen(me.text); ++i)
 		{
 			ch = substring(me.text, i, 1);
@@ -180,7 +184,7 @@
 				w = draw_TextWidth(strcat(ch, ch2), 0) * me.realFontSize_x;
 				if(ch2 == "^")
 				{
-					draw_Fill(p, eX * w + eY * me.realFontSize_y, '0 0 1', 0.5);
+					draw_Fill(p, eX * w + eY * me.realFontSize_y, '1 1 1', 0.5);
 					draw_Text(p + eX * 0.25 * w, "^", me.realFontSize, theColor, theAlpha, 0);
 				}
 				else if(ch2 == "0" || stof(ch2)) // digit?
@@ -201,19 +205,126 @@
 					theColor = theColor * (1 - brightness) + brightness * '1 1 1';
 					draw_Fill(p, eX * w + eY * me.realFontSize_y, '1 1 1', 0.5);
 					draw_Text(p, strcat(ch, ch2), me.realFontSize, theColor, theAlpha, 0);
-					draw_Text(p, strcat(ch, ch2), me.realFontSize, theColor, theAlpha, 0);
 				}
+				else if(ch2 == "x") // ^x found
+				{
+					theColor = '1 1 1' * (1 - brightness) + brightness * '1 1 1';
+					theTempColor = '0 0 0';
+					
+					component = str2chr(me.text, i+2);
+					if (component >= '0' && component <= '9')
+						component = component - '0';
+					else if (component >= 'a' && component <= 'f')
+						component = component - 87;
+					else if (component >= 'A' && component <= 'F')
+						component = component - 55;
+					else
+						component = -1;
+					
+					if (component >= 0) // ^xr found
+					{
+						theTempColor_x = component/15;
+						
+						component = str2chr(me.text, i+3);
+						if (component >= '0' && component <= '9')
+							component = component - '0';
+						else if (component >= 'a' && component <= 'f')
+							component = component - 87;
+						else if (component >= 'A' && component <= 'F')
+							component = component - 55;
+						else
+							component = -1;
+						
+						if (component >= 0) // ^xrg found
+						{
+							theTempColor_y = component/15;
+							
+							component = str2chr(me.text, i+4);
+							if (component >= '0' && component <= '9')
+								component = component - '0';
+							else if (component >= 'a' && component <= 'f')
+								component = component - 87;
+							else if (component >= 'A' && component <= 'F')
+								component = component - 55;
+							else
+								component = -1;
+							
+							if (component >= 0) // ^xrgb found
+							{
+								theTempColor_z = component/15;
+								theColor = '0 0 0' + theTempColor;
+								w = draw_TextWidth(substring(me.text, i, 5), 0) * me.realFontSize_x;
+								
+								draw_Fill(p, eX * w + eY * me.realFontSize_y, '1 1 1', 0.5);
+								draw_Text(p, substring(me.text, i, 5), me.realFontSize, theColor, 1, 0);    // theVariableAlpha instead of 1 using alpha tags ^ax
+								i += 3;
+							}
+							else
+							{
+								// blue missing
+								w = draw_TextWidth(substring(me.text, i, 4), 0) * me.realFontSize_x;
+								draw_Fill(p, eX * w + eY * me.realFontSize_y, eZ, 0.5);
+								draw_Text(p, substring(me.text, i, 4), me.realFontSize, '1 1 1', theAlpha, 0);
+								i += 2;
+							}
+						}
+						else
+						{
+							// green missing
+							w = draw_TextWidth(substring(me.text, i, 3), 0) * me.realFontSize_x;
+							draw_Fill(p, eX * w + eY * me.realFontSize_y, eY, 0.5);
+							draw_Text(p, substring(me.text, i, 3), me.realFontSize, '1 1 1', theAlpha, 0);
+							i += 1;
+						}
+					}
+					else
+					{
+						// red missing
+						//w = draw_TextWidth(substring(me.text, i, 2), 0) * me.realFontSize_x;
+						draw_Fill(p, eX * w + eY * me.realFontSize_y, eX, 0.5);
+						draw_Text(p, substring(me.text, i, 2), me.realFontSize, '1 1 1', theAlpha, 0);
+					}
+				}
+				/*else if(ch2 == "a") // ^a found
+				{
+					draw_Fill(p, eX * w + eY * me.realFontSize_y, '1 1 1', 0.5);
+					draw_Text(p, substring(me.text, i, 2), me.realFontSize, theColor, 0.8, 0);
+					
+					component = str2chr(me.text, i+2);
+					if (component >= '0' && component <= '9')
+						component = component - '0';
+					else if (component >= 'a' && component <= 'f')
+						component = component - 87;
+					else if (component >= 'A' && component <= 'F')
+						component = component - 55;
+					else
+						component = -1;
+					
+					if (component >= 0) // ^ah found
+					{
+						// FIX ME: overflow here
+						if (component == 20 && theVariableAlpha <= 0.97)
+							theVariableAlpha = theVariableAlpha + 0.0625;
+						else if (component == 30 && theVariableAlpha >= 0.03)
+							theVariableAlpha = theVariableAlpha - 0.0625;
+						else
+							theVariableAlpha = component*0.0625;
+						
+						draw_Fill(p, eX * draw_TextWidth(substring(me.text, i, 3), 0) * me.realFontSize_x + eY * me.realFontSize_y, '0.8 0.8 0.8', 0.5);
+						draw_Text(p, strcat(ch, ch2), me.realFontSize, theColor, 0.8, 0);
+					}
+				}*/
 				else
 				{
-					draw_Fill(p, eX * w + eY * me.realFontSize_y, '1 0 0', 0.5);
+					draw_Fill(p, eX * w + eY * me.realFontSize_y, '1 1 1', 0.5);
 					draw_Text(p, strcat(ch, ch2), me.realFontSize, theColor, theAlpha, 0);
-					draw_Text(p, strcat(ch, ch2), me.realFontSize, theColor, theAlpha, 0);
 				}
 				p += w * eX;
 				++i;
 				continue;
 			}
-			draw_Text(p, ch, me.realFontSize, theColor, theAlpha, 0); p += eX * draw_TextWidth(ch, 0) * me.realFontSize_x;
+			draw_Text(p, ch, me.realFontSize, theColor, theAlpha, 0); // TODO theVariableAlpha
+			p += eX * draw_TextWidth(ch, 0) * me.realFontSize_x;
 		}
 	}
 	else




More information about the nexuiz-commits mailing list