5 METHOD(Label, configureLabel, void(entity, string, float, float));
6 METHOD(Label, draw, void(entity));
7 METHOD(Label, resizeNotify, void(entity, vector, vector, vector, vector));
8 METHOD(Label, setText, void(entity, string));
9 METHOD(Label, toString, string(entity));
10 METHOD(Label, recalcPositionWithText, void(entity, string));
11 ATTRIB(Label, isBold, float, 0)
12 ATTRIB(Label, text, string, string_null)
13 ATTRIB(Label, currentText, string, string_null)
14 ATTRIB(Label, fontSize, float, 8)
15 ATTRIB(Label, align, float, 0.5)
16 ATTRIB(Label, allowCut, float, 0)
17 ATTRIB(Label, allowColors, float, 0)
18 ATTRIB(Label, keepspaceLeft, float, 0) // for use by subclasses (radiobuttons for example)
19 ATTRIB(Label, keepspaceRight, float, 0)
20 ATTRIB(Label, marginLeft, float, 0) // alternate way to specify keepspace* (in characters from the font)
21 ATTRIB(Label, marginRight, float, 0)
22 ATTRIB(Label, realFontSize, vector, '0 0 0')
23 ATTRIB(Label, realOrigin, vector, '0 0 0')
24 ATTRIB(Label, alpha, float, 0.7)
25 ATTRIB(Label, colorL, vector, SKINCOLOR_TEXT)
26 ATTRIB(Label, disabled, float, 0)
27 ATTRIB(Label, disabledAlpha, float, 0.3)
28 ATTRIB(Label, textEntity, entity, NULL)
29 ATTRIB(Label, allowWrap, float, 0)
30 ATTRIB(Label, recalcPos, float, 0)
31 ATTRIB(Label, condenseFactor, float, 1)
32 ATTRIB(Label, overrideRealOrigin, vector, '0 0 0')
33 ATTRIB(Label, overrideCondenseFactor, float, 0)
38 string Label_toString(entity me)
42 void Label_setText(entity me, string txt)
45 if(txt != me.currentText)
48 strunzone(me.currentText);
49 me.currentText = strzone(txt);
53 void Label_recalcPositionWithText(entity me, string t)
56 spaceAvail = 1 - me.keepspaceLeft - me.keepspaceRight;
62 spaceUsed = draw_TextWidth(t, me.allowColors, me.realFontSize);
64 if(spaceUsed <= spaceAvail)
66 if(!me.overrideRealOrigin_x)
67 me.realOrigin_x = me.align * (spaceAvail - spaceUsed) + me.keepspaceLeft;
68 if(!me.overrideCondenseFactor)
69 me.condenseFactor = 1;
71 else if(me.allowCut || me.allowWrap)
73 if(!me.overrideRealOrigin_x)
74 me.realOrigin_x = me.keepspaceLeft;
75 if(!me.overrideCondenseFactor)
76 me.condenseFactor = 1;
80 if(!me.overrideRealOrigin_x)
81 me.realOrigin_x = me.keepspaceLeft;
82 if(!me.overrideCondenseFactor)
83 me.condenseFactor = spaceAvail / spaceUsed;
84 dprintf("NOTE: label text %s too wide for label, condensed by factor %f\n", t, me.condenseFactor);
87 if(!me.overrideRealOrigin_y)
93 // set up variables to draw in condensed size, but use hinting for original size
95 fs.x *= me.condenseFactor;
98 draw_fontscale.x *= me.condenseFactor;
100 if(me.allowCut) // FIXME allowCut incompatible with align != 0
102 else if(me.allowWrap) // FIXME allowWrap incompatible with align != 0
104 getWrappedLine_remaining = me.text;
106 while(getWrappedLine_remaining)
109 getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), fs, draw_TextWidth_WithColors);
111 getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), fs, draw_TextWidth_WithoutColors);
118 draw_fontscale = dfs;
120 me.realOrigin_y = 0.5 * (1 - lines * me.realFontSize.y);
128 void Label_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
130 SUPER(Label).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
132 // absSize_y is height of label
133 me.realFontSize_y = me.fontSize / absSize.y;
134 me.realFontSize_x = me.fontSize / absSize.x;
136 me.keepspaceLeft = me.marginLeft * me.realFontSize.x;
138 me.keepspaceRight = me.marginRight * me.realFontSize.x;
142 void Label_configureLabel(entity me, string txt, float sz, float algn)
148 void Label_draw(entity me)
153 draw_alpha *= me.disabledAlpha;
157 t = me.textEntity.toString(me.textEntity);
158 if(t != me.currentText)
161 strunzone(me.currentText);
162 me.currentText = strzone(t);
170 me.recalcPositionWithText(me, t);
179 draw_beginBoldFont();
181 // set up variables to draw in condensed size, but use hinting for original size
182 fs = me.realFontSize;
183 fs.x *= me.condenseFactor;
185 dfs = draw_fontscale;
186 draw_fontscale.x *= me.condenseFactor;
188 if(me.allowCut) // FIXME allowCut incompatible with align != 0
189 draw_Text(me.realOrigin, draw_TextShortenToWidth(t, (1 - me.keepspaceLeft - me.keepspaceRight), me.allowColors, fs), fs, me.colorL, me.alpha, me.allowColors);
190 else if(me.allowWrap) // FIXME allowWrap incompatible with align != 0
192 getWrappedLine_remaining = t;
194 while(getWrappedLine_remaining)
197 t = getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), fs, draw_TextWidth_WithColors);
199 t = getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), fs, draw_TextWidth_WithoutColors);
200 draw_Text(o, t, fs, me.colorL, me.alpha, me.allowColors);
201 o.y += me.realFontSize.y;
205 draw_Text(me.realOrigin, t, fs, me.colorL, me.alpha, me.allowColors);
207 draw_fontscale = dfs;
213 SUPER(Label).draw(me);