]> icculus.org git repositories - divverent/nexuiz.git/blob - data/oldmenuqc/control/visual/label.qc
Merge first change into the branch.
[divverent/nexuiz.git] / data / oldmenuqc / control / visual / label.qc
1 // DP/Nex Menu
2 // control/visual/label.qc
3
4 //////////////
5 // Item_Label
6 ///
7
8 void() _IL_Calc =
9 {
10         // calculate the size if necessary
11         if( self.size == '0 0 0' ) {
12                 self.size_x = self.fontSize_x * strlen( self.text );
13                 self.size_y = self.fontSize_y;
14         } else if( self.fontSize == '0 0 0' ) {
15                 self.fontSize_x = self.size_x / strlen( self.text );
16                 self.fontSize_y = self.size_y;
17         }
18 };
19
20 void() Item_Label_Update =
21 {
22         _IL_Calc();
23 };
24
25 void() Item_Label_Draw =
26 {
27         local vector lAligned;
28         // do we need to align the text?
29         if( self.alignment == ITEM_ALIGN_LEFT )
30                 lAligned_x = self.pos_x;
31         else if( self.alignment & ITEM_ALIGN_CENTER )
32                 lAligned_x = self.pos_x + (self.size_x - strlen( self.text ) * self.fontSize_x) / 2;
33         else if( self.alignment & ITEM_ALIGN_RIGHT )
34                 lAligned_x = self.pos_x + self.size_x - strlen( self.text ) * self.fontSize_x;
35         else
36                 lAligned_x = self.pos_x;
37         lAligned_y = self.pos_y;
38
39         Menu_DrawString( lAligned, self.text, self.fontSize, self.color, self.alpha, self.drawFlag );
40 };
41
42 void() Item_Label_Destroy =
43 {
44         String_EntityFree( self, text );
45 };
46
47 void() Item_Label_Spawn =
48 {
49         if( self.flag == 0 )
50                 self.flag = self.flag | FLAG_DRAWUPDATEONLY;
51
52         String_EntityZone( self, text );
53
54         _IL_Calc();
55
56         if( self.alignment & ITEM_ALIGN_FIX_CENTER )
57                 self.pos_x = self.pos_x - self.size_x / 2;
58         else if( self.alignment & ITEM_ALIGN_FIX_LEFT )
59                 self.pos_x = self.pos_x - self.size_x;
60
61         self._destroy = Item_Label_Destroy;
62         self._draw = Item_Label_Draw;
63         self._update = Item_Label_Update;
64 };