6 METHOD(Label, configureLabel, void(entity, string, float, float));
7 METHOD(Label, draw, void(entity));
8 METHOD(Label, resizeNotify, void(entity, vector, vector, vector, vector));
9 METHOD(Label, setText, void(entity, string));
10 METHOD(Label, toString, string(entity));
11 METHOD(Label, recalcPositionWithText, void(entity, string));
12 ATTRIB(Label, isBold, float, 0)
13 ATTRIB(Label, text, string, string_null)
14 ATTRIB(Label, currentText, string, string_null)
15 ATTRIB(Label, fontSize, float, 8)
16 ATTRIB(Label, align, float, 0.5)
17 ATTRIB(Label, allowCut, float, 0)
18 ATTRIB(Label, allowColors, float, 0)
19 ATTRIB(Label, keepspaceLeft, float, 0) // for use by subclasses (radiobuttons for example)
20 ATTRIB(Label, keepspaceRight, float, 0)
21 ATTRIB(Label, marginLeft, float, 0) // alternate way to specify keepspace* (in characters from the font)
22 ATTRIB(Label, marginRight, float, 0)
23 ATTRIB(Label, realFontSize, vector, '0 0 0')
24 ATTRIB(Label, realOrigin, vector, '0 0 0')
25 ATTRIB(Label, alpha, float, 0.7)
26 ATTRIB(Label, colorL, vector, SKINCOLOR_TEXT)
27 ATTRIB(Label, disabled, float, 0)
28 ATTRIB(Label, disabledAlpha, float, 0.3)
29 ATTRIB(Label, textEntity, entity, NULL)
30 ATTRIB(Label, allowWrap, float, 0)
31 ATTRIB(Label, recalcPos, float, 0)
32 ATTRIB(Label, condenseFactor, float, 1)
33 ATTRIB(Label, overrideRealOrigin, vector, '0 0 0')
34 ATTRIB(Label, overrideCondenseFactor, float, 0)
39 string Label_toString(entity me)
43 void Label_setText(entity me, string txt)
46 if (txt != me.currentText)
48 if (me.currentText) strunzone(me.currentText);
49 me.currentText = strzone(txt);
53 void Label_recalcPositionWithText(entity me, string t)
56 spaceAvail = 1 - me.keepspaceLeft - me.keepspaceRight;
58 if (me.isBold) draw_beginBoldFont();
61 spaceUsed = draw_TextWidth(t, me.allowColors, me.realFontSize);
63 if (spaceUsed <= spaceAvail)
65 if (!me.overrideRealOrigin_x) me.realOrigin_x = me.align * (spaceAvail - spaceUsed) + me.keepspaceLeft;
66 if (!me.overrideCondenseFactor) me.condenseFactor = 1;
68 else if (me.allowCut || me.allowWrap)
70 if (!me.overrideRealOrigin_x) me.realOrigin_x = me.keepspaceLeft;
71 if (!me.overrideCondenseFactor) me.condenseFactor = 1;
75 if (!me.overrideRealOrigin_x) me.realOrigin_x = me.keepspaceLeft;
76 if (!me.overrideCondenseFactor) me.condenseFactor = spaceAvail / spaceUsed;
77 LOG_TRACEF("NOTE: label text %s too wide for label, condensed by factor %f\n", t, me.condenseFactor);
80 if (!me.overrideRealOrigin_y)
86 // set up variables to draw in condensed size, but use hinting for original size
88 fs.x *= me.condenseFactor;
91 draw_fontscale.x *= me.condenseFactor;
93 if (me.allowCut) // FIXME allowCut incompatible with align != 0
97 else if (me.allowWrap) // FIXME allowWrap incompatible with align != 0
99 getWrappedLine_remaining = me.text;
101 while (getWrappedLine_remaining)
103 if (me.allowColors) getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), fs, draw_TextWidth_WithColors);
104 else getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), fs, draw_TextWidth_WithoutColors);
113 draw_fontscale = dfs;
115 me.realOrigin_y = 0.5 * (1 - lines * me.realFontSize.y);
118 if (me.isBold) draw_endBoldFont();
122 void Label_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
124 SUPER(Label).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
126 // absSize_y is height of label
127 me.realFontSize_y = absSize.y == 0 ? 0 : (me.fontSize / absSize.y);
128 me.realFontSize_x = absSize.x == 0 ? 0 : (me.fontSize / absSize.x);
129 if (me.marginLeft) me.keepspaceLeft = me.marginLeft * me.realFontSize.x;
130 if (me.marginRight) me.keepspaceRight = me.marginRight * me.realFontSize.x;
134 void Label_configureLabel(entity me, string txt, float sz, float algn)
140 void Label_draw(entity me)
144 if (me.disabled) draw_alpha *= me.disabledAlpha;
148 t = me.textEntity.toString(me.textEntity);
149 if (t != me.currentText)
151 if (me.currentText) strunzone(me.currentText);
152 me.currentText = strzone(t);
161 if (me.recalcPos) me.recalcPositionWithText(me, t);
169 if (me.isBold) draw_beginBoldFont();
171 // set up variables to draw in condensed size, but use hinting for original size
172 fs = me.realFontSize;
173 fs.x *= me.condenseFactor;
175 dfs = draw_fontscale;
176 draw_fontscale.x *= me.condenseFactor;
178 if (me.allowCut) // FIXME allowCut incompatible with align != 0
180 draw_Text(me.realOrigin, draw_TextShortenToWidth(t, (1 - me.keepspaceLeft - me.keepspaceRight), me.allowColors, fs), fs, me.colorL, me.alpha, me.allowColors);
182 else if (me.allowWrap) // FIXME allowWrap incompatible with align != 0
184 getWrappedLine_remaining = t;
186 while (getWrappedLine_remaining)
188 if (me.allowColors) t = getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), fs, draw_TextWidth_WithColors);
189 else t = getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), fs, draw_TextWidth_WithoutColors);
190 draw_Text(o, t, fs, me.colorL, me.alpha, me.allowColors);
191 o.y += me.realFontSize.y;
196 draw_Text(me.realOrigin, t, fs, me.colorL, me.alpha, me.allowColors);
199 draw_fontscale = dfs;
201 if (me.isBold) draw_endBoldFont();
204 SUPER(Label).draw(me);