]> icculus.org git repositories - divverent/nexuiz.git/blob - data/source/control/visual/multilabel.qc
restructure
[divverent/nexuiz.git] / data / source / control / visual / multilabel.qc
1 // DP/Nex Menu
2 // control/visual/multilabel.qc
3
4 /*
5 ===================
6 _IML_Calc
7 ===================
8 */
9 void() _IML_Calc =
10 {
11         local float lMaxWidth;
12         local float lLineNumber;
13         local vector lLine;
14
15         lMaxWidth = 0;
16         lLineNumber = 0;
17         lLine = '0 0 0';
18         do {
19                 if( self.wrap )
20                         lLine = Util_GetEndOfWrappedLine( self.text, lLine, self.wrap );
21                 else
22                         lLine = Util_GetEndOfLine( self.text, lLine );
23
24                 ++lLineNumber;
25                 lMaxWidth = max( lMaxWidth, lLine_z );
26         } while( lLine_x != lLine_y );
27
28         self.size_x = lMaxWidth * self.fontSize_x;
29         self.size_y = lLineNumber * self.fontSize_y;
30 };
31
32 /*
33 ===================
34 _IML_DrawLine
35 ===================
36 */
37 void( vector pPosition, string pText ) _IML_DrawLine =
38 {
39         if( self.alignment == ITEM_ALIGN_CENTER )
40                 pPosition_x = self.pos_x + (self.size_x - strlen( pText ) * self.fontSize_x) / 2;
41         else if( self.alignment == ITEM_ALIGN_RIGHT )
42                 pPosition_x = self.pos_x + self.size_x - strlen( pText ) * self.fontSize_x;
43         else
44                 pPosition_x = self.pos_x;
45
46         Menu_DrawString( pPosition, pText, self.fontSize, self.color, self.alpha, self.drawFlag );
47 };
48
49 /*
50 ===================
51 Item_MultiLable_Draw
52 ===================
53 */
54 void() Item_MultiLabel_Draw =
55 {
56         local vector lPosition;
57         local vector lLine;
58
59         lPosition_y = self.pos_y;
60         lLine = '0 0 0';
61         do  {
62                 if( self.wrap )
63                         lLine = Util_GetEndOfWrappedLine( self.text, lLine, self.wrap );
64                 else
65                         lLine = Util_GetEndOfLine( self.text, lLine );
66
67                 _IML_DrawLine( lPosition, substring( self.text, lLine_x - lLine_z + 1, lLine_z ) );
68                 lPosition_y = lPosition_y + self.fontSize_y;
69         } while( lLine_x != lLine_y );
70 };
71
72 /*
73 ===================
74 Item_MultiLabel_Update
75 ===================
76 */
77 void() Item_MultiLabel_Update =
78 {
79         if( self.size == '0 0 0' )
80                 _IML_Calc();
81 };
82
83 /*
84 ===================
85 Item_MultiLabel_Destroy
86 ===================
87 */
88 void() Item_MultiLabel_Destroy =
89 {
90         String_EntityFree( self, text );
91 };
92
93 /*
94 ===================
95 Item_MultiLabel_Spawn
96 ===================
97 */
98 void() Item_MultiLabel_Spawn =
99 {
100         if( self.flag == 0 )
101                 self.flag = self.flag | FLAG_DRAWUPDATEONLY;
102
103         String_EntityZone( self, text );
104
105         Item_MultiLabel_Update();
106
107         self._destroy = Item_MultiLabel_Destroy;
108         self._draw = Item_MultiLabel_Draw;
109         self._update = Item_MultiLabel_Update;
110 };