3 string Label_toString(entity me)
7 void Label_setText(entity me, string txt)
10 if (txt != me.currentText)
12 strcpy(me.currentText, txt);
16 void Label_recalcPositionWithText(entity me, string t)
19 spaceAvail = 1 - me.keepspaceLeft - me.keepspaceRight;
21 if (me.isBold) draw_beginBoldFont();
24 spaceUsed = draw_TextWidth(t, me.allowColors, me.realFontSize);
26 if (spaceUsed <= spaceAvail)
28 if (!me.overrideRealOrigin_x) me.realOrigin_x = me.align * (spaceAvail - spaceUsed) + me.keepspaceLeft;
29 if (!me.overrideCondenseFactor) me.condenseFactor = 1;
31 else if (me.allowCut || me.allowWrap)
33 if (!me.overrideRealOrigin_x) me.realOrigin_x = me.keepspaceLeft;
34 if (!me.overrideCondenseFactor) me.condenseFactor = 1;
38 if (!me.overrideRealOrigin_x) me.realOrigin_x = me.keepspaceLeft;
39 if (!me.overrideCondenseFactor) me.condenseFactor = spaceAvail / spaceUsed;
40 LOG_TRACEF("NOTE: label text %s too wide for label, condensed by factor %f", t, me.condenseFactor);
43 if (!me.overrideRealOrigin_y)
49 // set up variables to draw in condensed size, but use hinting for original size
51 fs.x *= me.condenseFactor;
54 draw_fontscale.x *= me.condenseFactor;
56 if (me.allowCut) // FIXME allowCut incompatible with align != 0
60 else if (me.allowWrap) // FIXME allowWrap incompatible with align != 0
62 getWrappedLine_remaining = me.text;
64 while (getWrappedLine_remaining)
66 if (me.allowColors) getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), fs, draw_TextWidth_WithColors);
67 else getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), fs, draw_TextWidth_WithoutColors);
78 me.realOrigin_y = 0.5 * (1 - lines * me.realFontSize.y);
81 if (me.isBold) draw_endBoldFont();
85 void Label_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
87 SUPER(Label).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
89 // absSize_y is height of label
90 me.realFontSize_y = absSize.y == 0 ? 0 : (me.fontSize / absSize.y);
91 me.realFontSize_x = absSize.x == 0 ? 0 : (me.fontSize / absSize.x);
92 if (me.marginLeft) me.keepspaceLeft = me.marginLeft * me.realFontSize.x;
93 if (me.marginRight) me.keepspaceRight = me.marginRight * me.realFontSize.x;
97 void Label_configureLabel(entity me, string txt, float sz, float algn)
103 void Label_draw(entity me)
107 if (me.disabled) draw_alpha *= me.disabledAlpha;
111 t = me.textEntity.toString(me.textEntity);
112 if (t != me.currentText)
114 strcpy(me.currentText, t);
123 if (me.recalcPos) me.recalcPositionWithText(me, t);
131 if (me.isBold) draw_beginBoldFont();
133 // set up variables to draw in condensed size, but use hinting for original size
134 fs = me.realFontSize;
135 fs.x *= me.condenseFactor;
137 dfs = draw_fontscale;
138 draw_fontscale.x *= me.condenseFactor;
140 if (me.allowCut) // FIXME allowCut incompatible with align != 0
142 draw_Text(me.realOrigin, draw_TextShortenToWidth(t, (1 - me.keepspaceLeft - me.keepspaceRight), me.allowColors, fs), fs, me.colorL, me.alpha, me.allowColors);
144 else if (me.allowWrap) // FIXME allowWrap incompatible with align != 0
146 getWrappedLine_remaining = t;
148 while (getWrappedLine_remaining)
150 if (me.allowColors) t = getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), fs, draw_TextWidth_WithColors);
151 else t = getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), fs, draw_TextWidth_WithoutColors);
152 draw_Text(o, t, fs, me.colorL, me.alpha, me.allowColors);
153 o.y += me.realFontSize.y;
158 draw_Text(me.realOrigin, t, fs, me.colorL, me.alpha, me.allowColors);
161 draw_fontscale = dfs;
163 if (me.isBold) draw_endBoldFont();
166 SUPER(Label).draw(me);