Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
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 100 of file label.qc.

101 {
102 me.fontSize = sz;
103 me.align = algn;
104 me.setText(me, txt);
105 }

References entity().

◆ Label_draw()

void Label_draw ( entity me)

Definition at line 106 of file label.qc.

107 {
108 string t;
109 vector o;
110 if (me.disabled) draw_alpha *= me.disabledAlpha;
111
112 if (me.textEntity)
113 {
114 t = me.textEntity.toString(me.textEntity);
115 if (t != me.currentText)
116 {
117 strcpy(me.currentText, t);
118 me.recalcPos = true;
119 }
120 }
121 else
122 {
123 t = me.text;
124 }
125
126 if (me.recalcPos) me.recalcPositionWithText(me, t);
127
128 if (me.fontSize)
129 if (t)
130 {
131 vector dfs;
132 vector fs;
133
134 if (me.isBold) draw_beginBoldFont();
135
136 // set up variables to draw in condensed size, but use hinting for original size
137 fs = me.realFontSize;
138 fs.x *= me.condenseFactor;
139
140 dfs = draw_fontscale;
141 draw_fontscale.x *= me.condenseFactor;
142
143 if (me.allowCut) // FIXME allowCut incompatible with align != 0
144 {
145 draw_Text(me.realOrigin, draw_TextShortenToWidth(t, (1 - me.keepspaceLeft - me.keepspaceRight), me.allowColors, fs), fs, me.colorL, me.alpha, me.allowColors);
146 }
147 else if (me.allowWrap) // FIXME allowWrap incompatible with align != 0
148 {
150 o = me.realOrigin;
152 {
153 if (me.allowColors) t = getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), fs, draw_TextWidth_WithColors);
154 else t = getWrappedLine((1 - me.keepspaceLeft - me.keepspaceRight), fs, draw_TextWidth_WithoutColors);
155 draw_Text(o, t, fs, me.colorL, me.alpha, me.allowColors);
156 o.y += me.realFontSize.y * (1 + me.allowWrap_spacing);
157 }
158 }
159 else
160 {
161 draw_Text(me.realOrigin, t, fs, me.colorL, me.alpha, me.allowColors);
162 }
163
164 draw_fontscale = dfs;
165
166 if (me.isBold) draw_endBoldFont();
167 }
168
169 SUPER(Label).draw(me);
170 }
Definition label.qh:4
#define draw_beginBoldFont()
Definition draw.qh:4
#define draw_endBoldFont()
Definition draw.qh:5
string getWrappedLine(float maxWidth, vector theFontSize, textLengthUpToWidth_widthFunction_t tw)
Definition util.qc:995
string getWrappedLine_remaining
Definition util.qh:147
string draw_TextShortenToWidth(string theText, float maxWidth, float ICanHasKallerz, vector SizeThxBye)
Definition draw.qc:377
float draw_TextWidth_WithoutColors(string s, vector theFontSize)
Definition draw.qc:396
void draw_Text(vector theOrigin, string theText, vector theSize, vector theColor, float theAlpha, float ICanHasKallerz)
Definition draw.qc:282
float draw_TextWidth_WithColors(string s, vector theFontSize)
Definition draw.qc:391
#define draw_fontscale
Definition draw.qh:5
float draw_alpha
Definition draw.qh:9
#define SUPER(cname)
Definition oo.qh:231
vector
Definition self.qh:92
#define strcpy(this, s)
Definition string.qh:52

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

◆ Label_recalcPositionWithText()

void Label_recalcPositionWithText ( entity me,
string t )

Definition at line 16 of file label.qc.

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 {
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 float text_height = lines * me.realFontSize.y;
79 if (lines > 1)
80 text_height += (lines - 1) * me.realFontSize.y * me.allowWrap_spacing;
81 me.realOrigin_y = 0.5 * (1 - text_height);
82 }
83
84 if (me.isBold) draw_endBoldFont();
85
86 me.recalcPos = false;
87 }
#define LOG_TRACEF(...)
Definition log.qh:77
float draw_TextWidth(string theText, float ICanHasKallerz, vector SizeThxBye)
Definition draw.qc:304

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

◆ Label_resizeNotify()

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

Definition at line 88 of file label.qc.

89 {
90 SUPER(Label).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
91
92 // absSize_y is height of label
93 me.realFontSize_y = absSize.y == 0 ? 0 : (me.fontSize / absSize.y);
94 me.realFontSize_x = absSize.x == 0 ? 0 : (me.fontSize / absSize.x);
95 if (me.marginLeft) me.keepspaceLeft = me.marginLeft * me.realFontSize.x;
96 if (me.marginRight) me.keepspaceRight = me.marginRight * me.realFontSize.x;
97
98 me.recalcPos = true;
99 }

References entity(), SUPER, and vector.

◆ Label_setText()

void Label_setText ( entity me,
string txt )

Definition at line 7 of file label.qc.

8 {
9 me.text = txt;
10 if (txt != me.currentText)
11 {
12 strcpy(me.currentText, txt);
13 me.recalcPos = true;
14 }
15 }

References entity(), and strcpy.

◆ Label_toString()

string Label_toString ( entity me)

Definition at line 3 of file label.qc.

4 {
5 return me.text;
6 }

References entity().