]> icculus.org git repositories - divverent/nexuiz.git/blob - data/menuqc/util/text.qc
Commit flush my old working copy.
[divverent/nexuiz.git] / data / menuqc / util / text.qc
1 // NG Menu
2 // util/text.qc
3
4 //INFO: I only care about \n and \0 and the col if in wrapped mode
5 vector( string pText, vector pLast ) Util_GetEndOfLine =
6 {
7         local string lChar;
8
9         pLast_x = pLast_y;
10         pLast_z = 0;
11         while( 1 ) {
12                 lChar = substring( pText, pLast_x, 1 );
13
14                 // newline -> the current char isnt valid
15                 if( lChar == "\n" ) {
16                         // the next valid is char can only be after the \n
17                         pLast_y = pLast_x + 1;
18                         --pLast_x;
19                         return pLast;
20                 } else if( lChar == "" ) {
21                         pLast_y = --pLast_x;
22                         return pLast;
23                 } else {
24                         ++pLast_x;
25                         ++pLast_z;
26                 }
27         }
28 };
29
30 vector( string pText, vector pLast, float pWrapLength ) Util_GetEndOfWrappedLine =
31 {
32         pLast_x = pLast_y;
33         pLast_z = 0;
34         while( 1 ) {
35                 local string lChar;
36                 lChar = substring( pText, pLast_x, 1 );
37
38                 // newline -> the current char isnt valid
39                 if( lChar == "\n" ) {
40                         --pLast_x;
41                         // the next valid char can only be after the \n
42                         pLast_y = pLast_x + 2;
43                         return pLast;
44                 } else if( lChar == "" ) {
45                         pLast_y = --pLast_x;
46                         return pLast;
47                 } else {
48                         ++pLast_x;
49                         ++pLast_z;
50                         if( !--pWrapLength ) {
51                                 // the current char is one too much
52                                 pLast_y = pLast_x;
53                                 --pLast_x;
54                                 return pLast;
55                         }
56                 }
57         }
58 };
59
60 string( float pValue, float pStep ) Util_FloatToClampedText =
61 {
62         local float lLen;
63         local float lClampedStep;
64         local float lInverseClamped;
65         lClampedStep = pStep - floor( pStep );
66         if( lClampedStep == 0.0 )
67                 return ftos( pValue );
68         // get the integer length
69         lLen = strlen( ftos( floor( pValue ) ) );
70         // Example data: 0.1 -> 10 - 1 = 9; 0.9 -> 1.^1 - 0.1 = 1.0^1 ; 0.01 -> 100 - 1 = 99 ; 0.09 -> 11.^1 - 0.1 = 10.0^1
71         lInverseClamped = 1.0 / lClampedStep - 0.1;
72         // add the fraction length and 1 for the .
73         lLen += strlen( ftos( floor( lInverseClamped ) ) ) + 1;
74         return substring( ftos( pValue + 0.0001 ), 0, lLen );
75 }