]> de.git.xonotic.org Git - voretournament/voretournament.git/blob - data/qcsrc/menu/item/label.c
Include gmqcc binaries for Windows and Linux
[voretournament/voretournament.git] / data / qcsrc / menu / item / label.c
1 #ifdef INTERFACE\r
2 CLASS(Label) EXTENDS(Item)\r
3         METHOD(Label, configureLabel, void(entity, string, float, float))\r
4         METHOD(Label, draw, void(entity))\r
5         METHOD(Label, resizeNotify, void(entity, vector, vector, vector, vector))\r
6         METHOD(Label, setText, void(entity, string))\r
7         METHOD(Label, toString, string(entity))\r
8         ATTRIB(Label, text, string, string_null)\r
9         ATTRIB(Label, fontSize, float, 8)\r
10         ATTRIB(Label, align, float, 0.5)\r
11         ATTRIB(Label, allowCut, float, 0)\r
12         ATTRIB(Label, allowColors, float, 1)\r
13         ATTRIB(Label, keepspaceLeft, float, 0) // for use by subclasses (radiobuttons for example)\r
14         ATTRIB(Label, keepspaceRight, float, 0)\r
15         ATTRIB(Label, marginLeft, float, 0) // alternate way to specify keepspace* (in characters from the font)\r
16         ATTRIB(Label, marginRight, float, 0)\r
17         ATTRIB(Label, realFontSize, vector, '0 0 0')\r
18         ATTRIB(Label, realOrigin, vector, '0 0 0')\r
19         ATTRIB(Label, alpha, float, 0.7)\r
20         ATTRIB(Label, colorL, vector, '1 1 1')\r
21         ATTRIB(Label, disabled, float, 0)\r
22         ATTRIB(Label, disabledAlpha, float, 0.3)\r
23         ATTRIB(Label, textEntity, entity, NULL)\r
24         ATTRIB(Label, allowWrap, float, 0)\r
25 ENDCLASS(Label)\r
26 #endif\r
27 \r
28 #ifdef IMPLEMENTATION\r
29 string toStringLabel(entity me)\r
30 {\r
31         return me.text;\r
32 }\r
33 void setTextLabel(entity me, string txt)\r
34 {\r
35         me.text = txt;\r
36         me.realOrigin_x = me.align * (1 - me.keepspaceLeft - me.keepspaceRight - min(draw_TextWidth(me.text, me.allowColors, me.realFontSize), (1 - me.keepspaceLeft - me.keepspaceRight))) + me.keepspaceLeft;\r
37 }\r
38 void resizeNotifyLabel(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)\r
39 {\r
40         resizeNotifyItem(me, relOrigin, relSize, absOrigin, absSize);\r
41         // absSize_y is height of label\r
42         me.realFontSize_y = me.fontSize / absSize_y;\r
43         me.realFontSize_x = me.fontSize / absSize_x;\r
44         if(me.marginLeft)\r
45                 me.keepspaceLeft = me.marginLeft * me.realFontSize_x;\r
46         if(me.marginRight)\r
47                 me.keepspaceRight = me.marginRight * me.realFontSize_x;\r
48         me.realOrigin_x = me.align * (1 - me.keepspaceLeft - me.keepspaceRight - min(draw_TextWidth(me.text, me.allowColors, me.realFontSize), (1 - me.keepspaceLeft - me.keepspaceRight))) + me.keepspaceLeft;\r
49         me.realOrigin_y = 0.5 * (1 - me.realFontSize_y);\r
50 }\r
51 void configureLabelLabel(entity me, string txt, float sz, float algn)\r
52 {\r
53         me.fontSize = sz;\r
54         me.align = algn;\r
55         me.setText(me, txt);\r
56 }\r
57 void drawLabel(entity me)\r
58 {\r
59         string t;\r
60         vector o;\r
61         if(me.disabled)\r
62                 draw_alpha *= me.disabledAlpha;\r
63 \r
64         if(me.textEntity)\r
65         {\r
66                 t = me.textEntity.toString(me.textEntity);\r
67                 me.realOrigin_x = me.align * (1 - me.keepspaceLeft - me.keepspaceRight - min(draw_TextWidth(t, 0, me.realFontSize), (1 - me.keepspaceLeft - me.keepspaceRight))) + me.keepspaceLeft;\r
68         }\r
69         else\r
70                 t = me.text;\r
71         \r
72         if(me.fontSize)\r
73                 if(t)\r
74                 {\r
75                         if(me.allowCut) // FIXME allowCut incompatible with align != 0\r
76                                 draw_Text(me.realOrigin, draw_TextShortenToWidth(t, (1 - me.keepspaceLeft - me.keepspaceRight), me.allowColors, me.realFontSize), me.realFontSize, me.colorL, me.alpha, me.allowColors);\r
77                         else if(me.allowWrap) // FIXME allowWrap incompatible with align != 0\r
78                         {\r
79                                 getWrappedLine_remaining = t;\r
80                                 o = me.realOrigin;\r
81                                 while(getWrappedLine_remaining)\r
82                                 {\r
83                                         if (me.allowColors)\r
84                                                 t = getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), me.realFontSize, draw_TextWidth_WithColors);\r
85                                         else\r
86                                                 t = getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), me.realFontSize, draw_TextWidth_WithoutColors);\r
87                                         draw_Text(o, t, me.realFontSize, me.colorL, me.alpha, me.allowColors);\r
88                                         o_y += me.realFontSize_y;\r
89                                 }\r
90                         }\r
91                         else\r
92                                 draw_Text(me.realOrigin, t, me.realFontSize, me.colorL, me.alpha, me.allowColors);\r
93                 }\r
94 }\r
95 #endif\r