]> icculus.org git repositories - divverent/nexuiz.git/blob - data/menuqc/util/text.qc
Fixed the crosshair selection.
[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         local string lChar;
33
34         pLast_x = pLast_y;
35         pLast_z = 0;
36         while( 1 ) {
37                 lChar = substring( pText, pLast_x, 1 );
38
39                 // newline -> the current char isnt valid
40                 if( lChar == "\n" ) {
41                         --pLast_x;
42                         // the next valid is char can only be after the \n
43                         pLast_y = pLast_x + 2;
44                         return pLast;
45                 } else if( lChar == "" ) {
46                         pLast_y = --pLast_x;
47                         return pLast;
48                 } else {
49                         ++pLast_x;
50                         ++pLast_z;
51                         if( !--pWrapLength ) {
52                                 // the current char is one too much
53                                 pLast_y = pLast_x;
54                                 --pLast_x;
55                                 return pLast;
56                         }
57                 }
58         }
59 };
60
61 string( float pValue, float pStep ) Util_FloatToClampedText =
62 {
63         local float lLen;
64         local float lClampedStep;
65         local float lInverseClamped;
66         lClampedStep = pStep - floor( pStep );
67         if( lClampedStep == 0.0 )
68                 return ftos( pValue );
69         // get the integer length
70         lLen = strlen( ftos( floor( pValue ) ) );
71         // 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
72         lInverseClamped = 1.0 / lClampedStep - 0.1;
73         // add the fraction length and 1 for the .
74         lLen += strlen( ftos( floor( lInverseClamped ) ) ) + 1;
75         return substring( ftos( pValue + 0.0001 ), 0, lLen );
76 }