r2092 - in branches/nexuiz-2.0/data/qcsrc: common menu

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Tue Jan 9 07:10:54 EST 2007


Author: div0
Date: 2007-01-09 07:10:54 -0500 (Tue, 09 Jan 2007)
New Revision: 2092

Modified:
   branches/nexuiz-2.0/data/qcsrc/common/util.qc
   branches/nexuiz-2.0/data/qcsrc/common/util.qh
   branches/nexuiz-2.0/data/qcsrc/menu/msys.qc
Log:
oops... forgot to commit this when merging sv_info_*


Modified: branches/nexuiz-2.0/data/qcsrc/common/util.qc
===================================================================
--- branches/nexuiz-2.0/data/qcsrc/common/util.qc	2007-01-05 13:18:54 UTC (rev 2091)
+++ branches/nexuiz-2.0/data/qcsrc/common/util.qc	2007-01-09 12:10:54 UTC (rev 2092)
@@ -1,17 +1,50 @@
+string wordwrap_buffer;
 
+void wordwrap_buffer_put(string s)
+{
+	wordwrap_buffer = strcat(wordwrap_buffer, s);
+}
+
 string wordwrap(string s, float l)
 {
-	local string t, c;
+	wordwrap_buffer = "";
+	wordwrap_cb(s, l, wordwrap_buffer_put);
+	return wordwrap_buffer;
+}
+
+#ifndef MENUQC
+void wordwrap_buffer_sprint(string s)
+{
+	wordwrap_buffer = strcat(wordwrap_buffer, s);
+	if(s == "\n")
+	{
+		sprint(self, wordwrap_buffer);
+		wordwrap_buffer = "";
+	}
+}
+
+void wordwrap_sprint(string s, float l)
+{
+	wordwrap_buffer = "";
+	wordwrap_cb(s, l, wordwrap_buffer_sprint);
+	if(wordwrap_buffer != "")
+		sprint(self, strcat(wordwrap_buffer, "\n"));
+	return;
+}
+#endif
+
+void wordwrap_cb(string s, float l, void(string) callback)
+{
+	local string c;
 	local float lleft, i, j, wlen;
 
 	s = strzone(s);
-	t = "";
 	lleft = l;
 	for (i = 0;i < strlen(s);i++)
 	{
 		if (substring(s, i, 2) == "\\n")
 		{
-			t = strcat(t, "\n");
+			callback("\n");
 			lleft = l;
 			i++;
 		}
@@ -19,7 +52,7 @@
 		{
 			if (lleft > 0)
 			{
-				t = strcat(t, " ");
+				callback(" ");
 				lleft = lleft - 1;
 			}
 		}
@@ -42,142 +75,20 @@
 				// we need to keep this tempstring alive even if substring is
 				// called repeatedly, so call strcat even though we're not
 				// doing anything
-				t = strcat(t);
+				callback("");
 			}
 			wlen = j - i;
 			if (lleft < wlen)
 			{
-				t = strcat(t, "\n");
+				callback("\n");
 				lleft = l;
 			}
-			t = strcat(t, substring(s, i, wlen));
+			callback(substring(s, i, wlen));
 			lleft = lleft - wlen;
 			i = j - 1;
 		}
 	}
 	strunzone(s);
-	return t;
-
-/*
-	string t;
-	string word;
-
-	float lleft;
-	float i;
-
-	float startidx;
-
-	startidx = 0;
-
-	t = "";
-	word = "";
-	for (i = 0;i < strlen(s);i++)
-	{
-		c = substring(s, i, 1);
-		forceflush = false;
-		if (c == " ")
-			dowhat = 0;
-		else if (c == "\\" && substring(s, i + 1, 1) == "n")
-			dowhat = 1;
-		else
-		{
-			dowhat = 2;
-			word = strcat(word, c);
-		}
-
-		if (dowhat < 2)
-		{
-			// a space may add some whitespace to the output, and flushes the word buffer
-			if (word != "")
-			{
-				if (lleft < strlen(word) + 1)
-				{
-					// add a newline
-					t = strcat(t, "\n");
-					lleft = l;
-				}
-				else
-				{
-					// otherwise just add a space if there's already text in
-					// this line
-					if (lleft != l)
-						t = strcat(t, " ");
-				}
-				t = strcat(t, word);
-				word = "";
-			}
-			if (dowhat == 0)
-			{
-				// if this is a double space, add the space
-				if (lleft)
-					t = strcat(t, " ");
-			}
-			else if (dowhat == 1)
-			{
-				t = strcat(t, "\n");
-				lleft = l;
-			}
-		}
-		// we need to keep these tempstrings alive even if substring is
-		// called repeatedly, so call strcat even though we're not doing
-		// anything
-		t = strcat(t);
-		word = strcat(word);
-	}
-	return t;
-*/
-
-/*
-	string t;
-	string word;
-
-	float lleft;
-	float i;
-
-	float startidx;
-
-	startidx = 0;
-
-	t = "";
-
-	lleft = l;
-	for(i = 0; i <= strlen(s); ++i)
-	{
-		if(i != strlen(s) && substring(s, i, 1) != " ")
-		{
-			// we need to keep this tempstring alive even if substring is
-			// called repeatedly, so call strcat even though we're not doing
-			// anything
-			t = strcat(t);
-			continue;
-		}
-
-		word = substring(s, startidx, i - startidx);
-		startidx = i + 1;
-
-		if(word == "+++")
-		{
-			t = strcat(t, "\n\n");
-			lleft = l;
-		}
-		else if(!l || (strlen(word) < lleft))
-		{
-			if(lleft != l)
-			{
-				t = strcat(t, " ");
-				lleft = lleft - 1;
-			}
-			t = strcat(t, word);
-			lleft = lleft - strlen(word);
-		}
-		else
-		{
-			t = strcat(t, "\n", word);
-			lleft = l - strlen(word);
-		}
-	}
-	return t;
-*/
 }
 
 float dist_point_line(vector p, vector l0, vector ldir)

Modified: branches/nexuiz-2.0/data/qcsrc/common/util.qh
===================================================================
--- branches/nexuiz-2.0/data/qcsrc/common/util.qh	2007-01-05 13:18:54 UTC (rev 2091)
+++ branches/nexuiz-2.0/data/qcsrc/common/util.qh	2007-01-09 12:10:54 UTC (rev 2092)
@@ -2,3 +2,7 @@
 // this returns a tempstring containing a copy of s with additional \n newlines added, it also replaces \n in the text with a real newline
 // NOTE: s IS allowed to be a tempstring
 string wordwrap(string s, float l);
+#ifndef MENUQC
+void wordwrap_sprint(string s, float l);
+#endif
+void wordwrap_cb(string s, float l, void(string) callback)

Modified: branches/nexuiz-2.0/data/qcsrc/menu/msys.qc
===================================================================
--- branches/nexuiz-2.0/data/qcsrc/menu/msys.qc	2007-01-05 13:18:54 UTC (rev 2091)
+++ branches/nexuiz-2.0/data/qcsrc/menu/msys.qc	2007-01-09 12:10:54 UTC (rev 2092)
@@ -1,4 +1,5 @@
 #pragma flag off fastarrays // make dp behave with new fteqcc versions. remove when dp bug with fteqcc fastarrays is fixed
+#define MENUQC // so common/*.qc can check for menu QC or game QC
 
 //////////////////////////////////////////////////////////
 // sys globals




More information about the nexuiz-commits mailing list