Xonotic
label.qc File Reference
#include "label.qh"
+ Include dependency graph for label.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void Label_configureLabel (entity me, string txt, float sz, float algn)
 
void Label_draw (entity me)
 
void Label_recalcPositionWithText (entity me, string t)
 
void Label_resizeNotify (entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
 
void Label_setText (entity me, string txt)
 
string Label_toString (entity me)
 

Function Documentation

◆ Label_configureLabel()

void Label_configureLabel ( entity  me,
string  txt,
float  sz,
float  algn 
)

Definition at line 97 of file label.qc.

98  {
99  me.fontSize = sz;
100  me.align = algn;
101  me.setText(me, txt);
102  }

◆ Label_draw()

void Label_draw ( entity  me)

Definition at line 103 of file label.qc.

References draw_alpha, draw_beginBoldFont, draw_endBoldFont, draw_fontscale, draw_Text(), draw_TextShortenToWidth(), draw_TextWidth_WithColors(), draw_TextWidth_WithoutColors(), getWrappedLine(), getWrappedLine_remaining, strcpy, SUPER, and vector().

104  {
105  string t;
106  vector o;
107  if (me.disabled) draw_alpha *= me.disabledAlpha;
108 
109  if (me.textEntity)
110  {
111  t = me.textEntity.toString(me.textEntity);
112  if (t != me.currentText)
113  {
114  strcpy(me.currentText, t);
115  me.recalcPos = 1;
116  }
117  }
118  else
119  {
120  t = me.text;
121  }
122 
123  if (me.recalcPos) me.recalcPositionWithText(me, t);
124 
125  if (me.fontSize)
126  if (t)
127  {
128  vector dfs;
129  vector fs;
130 
131  if (me.isBold) draw_beginBoldFont();
132 
133  // set up variables to draw in condensed size, but use hinting for original size
134  fs = me.realFontSize;
135  fs.x *= me.condenseFactor;
136 
137  dfs = draw_fontscale;
138  draw_fontscale.x *= me.condenseFactor;
139 
140  if (me.allowCut) // FIXME allowCut incompatible with align != 0
141  {
142  draw_Text(me.realOrigin, draw_TextShortenToWidth(t, (1 - me.keepspaceLeft - me.keepspaceRight), me.allowColors, fs), fs, me.colorL, me.alpha, me.allowColors);
143  }
144  else if (me.allowWrap) // FIXME allowWrap incompatible with align != 0
145  {
147  o = me.realOrigin;
149  {
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;
154  }
155  }
156  else
157  {
158  draw_Text(me.realOrigin, t, fs, me.colorL, me.alpha, me.allowColors);
159  }
160 
161  draw_fontscale = dfs;
162 
163  if (me.isBold) draw_endBoldFont();
164  }
165 
166  SUPER(Label).draw(me);
167  }
#define draw_endBoldFont()
Definition: draw.qh:5
string getWrappedLine_remaining
Definition: util.qh:108
#define draw_beginBoldFont()
Definition: draw.qh:4
#define strcpy(this, s)
Definition: string.qh:49
#define SUPER(cname)
Definition: oo.qh:219
Definition: label.qh:4
vector(float skel, float bonenum) _skel_get_boneabs_hidden
string getWrappedLine(float w, vector theFontSize, textLengthUpToWidth_widthFunction_t tw)
Definition: util.qc:880
+ Here is the call graph for this function:

◆ Label_recalcPositionWithText()

void Label_recalcPositionWithText ( entity  me,
string  t 
)

Definition at line 16 of file label.qc.

References draw_beginBoldFont, draw_endBoldFont, draw_fontscale, draw_TextWidth(), draw_TextWidth_WithColors(), draw_TextWidth_WithoutColors(), getWrappedLine(), getWrappedLine_remaining, if(), LOG_TRACEF, and vector().

17  {
18  float spaceAvail;
19  spaceAvail = 1 - me.keepspaceLeft - me.keepspaceRight;
20 
21  if (me.isBold) draw_beginBoldFont();
22 
23  float spaceUsed;
24  spaceUsed = draw_TextWidth(t, me.allowColors, me.realFontSize);
25 
26  if (spaceUsed <= spaceAvail)
27  {
28  if (!me.overrideRealOrigin_x) me.realOrigin_x = me.align * (spaceAvail - spaceUsed) + me.keepspaceLeft;
29  if (!me.overrideCondenseFactor) me.condenseFactor = 1;
30  }
31  else if (me.allowCut || me.allowWrap)
32  {
33  if (!me.overrideRealOrigin_x) me.realOrigin_x = me.keepspaceLeft;
34  if (!me.overrideCondenseFactor) me.condenseFactor = 1;
35  }
36  else
37  {
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);
41  }
42 
43  if (!me.overrideRealOrigin_y)
44  {
45  float lines;
46  vector dfs;
47  vector fs;
48 
49  // set up variables to draw in condensed size, but use hinting for original size
50  fs = me.realFontSize;
51  fs.x *= me.condenseFactor;
52 
53  dfs = draw_fontscale;
54  draw_fontscale.x *= me.condenseFactor;
55 
56  if (me.allowCut) // FIXME allowCut incompatible with align != 0
57  {
58  lines = 1;
59  }
60  else if (me.allowWrap) // FIXME allowWrap incompatible with align != 0
61  {
62  getWrappedLine_remaining = me.text;
63  lines = 0;
65  {
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);
68  ++lines;
69  }
70  }
71  else
72  {
73  lines = 1;
74  }
75 
76  draw_fontscale = dfs;
77 
78  me.realOrigin_y = 0.5 * (1 - lines * me.realFontSize.y);
79  }
80 
81  if (me.isBold) draw_endBoldFont();
82 
83  me.recalcPos = 0;
84  }
#define draw_endBoldFont()
Definition: draw.qh:5
string getWrappedLine_remaining
Definition: util.qh:108
#define draw_beginBoldFont()
Definition: draw.qh:4
#define LOG_TRACEF(...)
Definition: log.qh:82
vector(float skel, float bonenum) _skel_get_boneabs_hidden
if(IS_DEAD(this))
Definition: impulse.qc:92
string getWrappedLine(float w, vector theFontSize, textLengthUpToWidth_widthFunction_t tw)
Definition: util.qc:880
+ Here is the call graph for this function:

◆ Label_resizeNotify()

void Label_resizeNotify ( entity  me,
vector  relOrigin,
vector  relSize,
vector  absOrigin,
vector  absSize 
)

Definition at line 85 of file label.qc.

References SUPER.

86  {
87  SUPER(Label).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
88 
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;
94 
95  me.recalcPos = 1;
96  }
#define SUPER(cname)
Definition: oo.qh:219
Definition: label.qh:4

◆ Label_setText()

void Label_setText ( entity  me,
string  txt 
)

Definition at line 7 of file label.qc.

References strcpy.

8  {
9  me.text = txt;
10  if (txt != me.currentText)
11  {
12  strcpy(me.currentText, txt);
13  me.recalcPos = 1;
14  }
15  }
#define strcpy(this, s)
Definition: string.qh:49

◆ Label_toString()

string Label_toString ( entity  me)

Definition at line 3 of file label.qc.

4  {
5  return me.text;
6  }