]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu/item/label.c
shortened some names
[divverent/nexuiz.git] / data / qcsrc / menu / item / label.c
1 #ifdef INTERFACE
2 CLASS(Label) EXTENDS(Item)
3         METHOD(Label, configureLabel, void(entity, string, float, float))
4         METHOD(Label, draw, void(entity))
5         METHOD(Label, resizeNotify, void(entity, vector, vector, vector, vector))
6         METHOD(Label, setText, void(entity, string))
7         METHOD(Label, toString, string(entity))
8         ATTRIB(Label, text, string, string_null)
9         ATTRIB(Label, fontSize, float, 8)
10         ATTRIB(Label, align, float, 0.5)
11         ATTRIB(Label, allowCut, float, 0)
12         ATTRIB(Label, keepspaceLeft, float, 0) // for use by subclasses (radiobuttons for example)
13         ATTRIB(Label, keepspaceRight, float, 0)
14         ATTRIB(Label, realFontSize, vector, '0 0 0')
15         ATTRIB(Label, realOrigin, vector, '0 0 0')
16         ATTRIB(Label, alpha, float, 0.7)
17         ATTRIB(Label, colorL, vector, '1 1 1')
18         ATTRIB(Label, disabled, float, 0)
19         ATTRIB(Label, disabledAlpha, float, 0.3)
20         ATTRIB(Label, textEntity, entity, NULL)
21 ENDCLASS(Label)
22 #endif
23
24 #ifdef IMPLEMENTATION
25 string toStringLabel(entity me)
26 {
27         return me.text;
28 }
29 void setTextLabel(entity me, string txt)
30 {
31         me.text = txt;
32         me.realOrigin_x = me.align * (1 - me.keepspaceLeft - me.keepspaceRight - min(me.realFontSize_x * draw_TextWidth(me.text, 0), (1 - me.keepspaceLeft - me.keepspaceRight))) + me.keepspaceLeft;
33 }
34 void resizeNotifyLabel(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
35 {
36         // absSize_y is height of label
37         me.realFontSize_y = me.fontSize / absSize_y;
38         me.realFontSize_x = me.fontSize / absSize_x;
39         me.realOrigin_x = me.align * (1 - me.keepspaceLeft - me.keepspaceRight - min(me.realFontSize_x * draw_TextWidth(me.text, 0), (1 - me.keepspaceLeft - me.keepspaceRight))) + me.keepspaceLeft;
40         me.realOrigin_y = 0.5 * (1 - me.realFontSize_y);
41 }
42 void configureLabelLabel(entity me, string txt, float sz, float algn)
43 {
44         me.fontSize = sz;
45         me.align = algn;
46         me.setText(me, txt);
47 }
48 void drawLabel(entity me)
49 {
50         string t;
51         if(me.disabled)
52                 draw_alpha *= me.disabledAlpha;
53
54         if(me.textEntity)
55         {
56                 t = me.textEntity.toString(me.textEntity);
57                 me.realOrigin_x = me.align * (1 - me.keepspaceLeft - me.keepspaceRight - min(me.realFontSize_x * draw_TextWidth(t, 0), (1 - me.keepspaceLeft - me.keepspaceRight))) + me.keepspaceLeft;
58         }
59         else
60                 t = me.text;
61         
62         if(me.fontSize)
63                 if(t)
64                 {
65                         if(me.allowCut)
66                                 draw_Text(me.realOrigin, draw_TextShortenToWidth(t, (1 - me.keepspaceLeft - me.keepspaceRight) / me.realFontSize_x, 0), me.realFontSize, me.colorL, me.alpha, 0);
67                         else
68                                 draw_Text(me.realOrigin, t, me.realFontSize, me.colorL, me.alpha, 0);
69                 }
70 }
71 #endif