1 string wordwrap_buffer;
3 void wordwrap_buffer_put(string s)
5 wordwrap_buffer = strcat(wordwrap_buffer, s);
8 string wordwrap(string s, float l)
11 wordwrap_cb(s, l, wordwrap_buffer_put);
12 return wordwrap_buffer;
16 void wordwrap_buffer_sprint(string s)
18 wordwrap_buffer = strcat(wordwrap_buffer, s);
21 sprint(self, wordwrap_buffer);
26 void wordwrap_sprint(string s, float l)
29 wordwrap_cb(s, l, wordwrap_buffer_sprint);
30 if(wordwrap_buffer != "")
31 sprint(self, strcat(wordwrap_buffer, "\n"));
36 void wordwrap_cb(string s, float l, void(string) callback)
39 local float lleft, i, j, wlen;
43 for (i = 0;i < strlen(s);i++)
45 if (substring(s, i, 2) == "\\n")
51 else if (substring(s, i, 1) == " ")
61 for (j = i+1;j < strlen(s);j++)
62 // ^^ this skips over the first character of a word, which
63 // is ALWAYS part of the word
64 // this is safe since if i+1 == strlen(s), i will become
65 // strlen(s)-1 at the end of this block and the function
66 // will terminate. A space can't be the first character we
67 // read here, and neither can a \n be the start, since these
68 // two cases have been handled above.
70 c = substring(s, j, 1);
75 // we need to keep this tempstring alive even if substring is
76 // called repeatedly, so call strcat even though we're not
86 callback(substring(s, i, wlen));
94 float dist_point_line(vector p, vector l0, vector ldir)
96 ldir = normalize(ldir);
98 // remove the component in line direction
99 p = p - (p * ldir) * ldir;
101 // vlen of the remaining vector