Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
draw.qc File Reference
#include "draw.qh"
#include <client/hud/hud.qh>
Include dependency graph for draw.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DRAWSTRING_ASPECT_SCALE(pos, text, sz, allow_colors)

Functions

void drawborderlines (float thickness, vector pos, vector dim, vector color, float theAlpha, float drawflag)
void DrawCircleClippedPic (vector centre, float radi, string pic, float f, vector rgb, float a, float drawflag)
void drawcolorcodedstring_aspect (vector pos, string text, vector sz, float theAlpha, float drawflag)
void drawcolorcodedstring_aspect_expanding (vector pos, string text, vector sz, float theAlpha, float drawflag, float fadelerp)
void drawcolorcodedstring_expanding (vector position, string text, vector theScale, float theAlpha, float flag, float fadelerp)
void drawpic_aspect_skin_expanding (vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
void drawpic_aspect_skin_expanding_two (vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
void drawpic_tiled (vector pos, string pic, vector sz, vector area, vector color, float theAlpha, float drawflag)
void drawstring_aspect (vector pos, string text, vector sz, vector color, float theAlpha, float drawflag)
void drawstring_aspect_expanding (vector pos, string text, vector sz, vector color, float theAlpha, float drawflag, float fadelerp)
void drawstring_expanding (vector position, string text, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
vector expandingbox_resize_centered_box_offset (float sz, vector boxsize, float boxxsizefactor)
float expandingbox_sizefactor_from_fadelerp (float fadelerp)
void PolyDrawModel (entity e)
float PolyDrawModelSurface (entity e, float i_s)
float stringwidth (string text, float handleColors, vector sz)

Macro Definition Documentation

◆ DRAWSTRING_ASPECT_SCALE

#define DRAWSTRING_ASPECT_SCALE ( pos,
text,
sz,
allow_colors )
Value:
MACRO_BEGIN \
float textaspect, oldsz; \
drawfontscale = '1 1 0'; \
textaspect = stringwidth(text, allow_colors, '1 1 1' * sz.y) / sz.y; \
if(sz.x/sz.y > textaspect) { \
oldsz = sz.x; \
sz.x = sz.y * textaspect; \
pos.x += (oldsz - sz.x) * 0.5; \
} else { \
oldsz = sz.y; \
sz.y = sz.x / textaspect; \
pos.y += (oldsz - sz.y) * 0.5; \
/* in case text is rendered with a different size, at least recenter it horizontally */ \
/* unfortunately there is no way to correctly recenter it vertically */ \
float new_textwidth = stringwidth(text, allow_colors, '1 1 1' * sz.y); \
pos.x += (sz.x - new_textwidth) * 0.5; \
} \
drawfontscale = dfs; \
vector drawfontscale
Definition draw.qh:3
#define stringwidth
#define MACRO_END
Definition macro.qh:7
vector
Definition self.qh:92

Definition at line 88 of file draw.qc.

88#define DRAWSTRING_ASPECT_SCALE(pos, text, sz, allow_colors) MACRO_BEGIN \
89 float textaspect, oldsz; \
90 vector dfs = drawfontscale; \
91 drawfontscale = '1 1 0'; \
92 textaspect = stringwidth(text, allow_colors, '1 1 1' * sz.y) / sz.y; \
93 if(sz.x/sz.y > textaspect) { \
94 oldsz = sz.x; \
95 sz.x = sz.y * textaspect; \
96 pos.x += (oldsz - sz.x) * 0.5; \
97 } else { \
98 oldsz = sz.y; \
99 sz.y = sz.x / textaspect; \
100 pos.y += (oldsz - sz.y) * 0.5; \
101 /* in case text is rendered with a different size, at least recenter it horizontally */ \
102 /* unfortunately there is no way to correctly recenter it vertically */ \
103 float new_textwidth = stringwidth(text, allow_colors, '1 1 1' * sz.y); \
104 pos.x += (sz.x - new_textwidth) * 0.5; \
105 } \
106 drawfontscale = dfs; \
107MACRO_END

Referenced by drawcolorcodedstring_aspect(), drawcolorcodedstring_aspect_expanding(), drawstring_aspect(), and drawstring_aspect_expanding().

Function Documentation

◆ drawborderlines()

void drawborderlines ( float thickness,
vector pos,
vector dim,
vector color,
float theAlpha,
float drawflag )

Definition at line 5 of file draw.qc.

6{
7 vector line_dim = '0 0 0';
8
9 // left and right lines
10 pos.x -= thickness;
11 line_dim.x = thickness;
12 line_dim.y = dim.y;
13 drawfill(pos, line_dim, color, theAlpha, drawflag);
14 drawfill(pos + (dim.x + thickness) * '1 0 0', line_dim, color, theAlpha, drawflag);
15
16 // upper and lower lines
17 pos.y -= thickness;
18 line_dim.x = dim.x + thickness * 2; // make upper and lower lines longer
19 line_dim.y = thickness;
20 drawfill(pos, line_dim, color, theAlpha, drawflag);
21 drawfill(pos + (dim.y + thickness) * '0 1 0', line_dim, color, theAlpha, drawflag);
22}
#define drawfill(position, size, rgb, alpha, flag)
Definition draw.qh:36
vector color
Definition dynlight.qc:15

References color, drawfill, and vector.

Referenced by GameTypeVote_DrawGameTypeItem(), and MapVote_DrawMapItem().

◆ DrawCircleClippedPic()

void DrawCircleClippedPic ( vector centre,
float radi,
string pic,
float f,
vector rgb,
float a,
float drawflag )

Definition at line 190 of file draw.qc.

191{
192 vector ringsize, v, t;
193 ringsize = radi * '1 1 0';
194 centre = HUD_Shift(centre);
195 ringsize = HUD_Scale(ringsize);
196
197 if(f >= 1)
198 {
199 // draw full rectangle
200 R_BeginPolygon(pic, drawflag, true);
201 v = centre; t = '0.5 0.5 0';
202 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
203 R_PolygonVertex(v, t, rgb, a);
204
205 v = centre; t = '0.5 0.5 0';
206 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
207 R_PolygonVertex(v, t, rgb, a);
208
209 v = centre; t = '0.5 0.5 0';
210 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
211 R_PolygonVertex(v, t, rgb, a);
212
213 v = centre; t = '0.5 0.5 0';
214 v.y -= 0.5 * ringsize.y; t -= '0.5 -0.5 0';
215 R_PolygonVertex(v, t, rgb, a);
216 R_EndPolygon();
217 return; // Complete rectangle, nothing more needed.
218 }
219
220 float co = cos(f * (2 * M_PI));
221 float si = sin(f * (2 * M_PI));
222 float q = fabs(co) + fabs(si);
223 co /= q;
224 si /= q;
225
226 if(f > 0.75)
227 {
228 // draw upper half in full
229 R_BeginPolygon(pic, drawflag, true);
230 v = centre; t = '0.5 0.5 0';
231 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
232 R_PolygonVertex(v, t, rgb, a);
233
234 v = centre; t = '0.5 0.5 0';
235 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
236 R_PolygonVertex(v, t, rgb, a);
237
238 v = centre; t = '0.5 0.5 0';
239 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
240 R_PolygonVertex(v, t, rgb, a);
241 R_EndPolygon();
242 // draw clipped lower half as a quad
243 R_BeginPolygon(pic, drawflag, true);
244 v = centre; t = '0.5 0.5 0';
245 R_PolygonVertex(v, t, rgb, a);
246
247 v = centre; t = '0.5 0.5 0';
248 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
249 R_PolygonVertex(v, t, rgb, a);
250
251 v = centre; t = '0.5 0.5 0';
252 v.y -= 0.5 * ringsize.y; t -= '0.5 -0.5 0';
253 R_PolygonVertex(v, t, rgb, a);
254 }
255 else if(f > 0.5)
256 {
257 // draw upper half in full
258 R_BeginPolygon(pic, drawflag, true);
259 v = centre; t = '0.5 0.5 0';
260 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
261 R_PolygonVertex(v, t, rgb, a);
262
263 v = centre; t = '0.5 0.5 0';
264 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
265 R_PolygonVertex(v, t, rgb, a);
266
267 v = centre; t = '0.5 0.5 0';
268 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
269 R_PolygonVertex(v, t, rgb, a);
270 R_EndPolygon();
271 // draw clipped lower half as a triangle
272 R_BeginPolygon(pic, drawflag, true);
273 v = centre; t = '0.5 0.5 0';
274 R_PolygonVertex(v, t, rgb, a);
275
276 v = centre; t = '0.5 0.5 0';
277 v.x -= 0.5 * ringsize.x; t -= '0.5 0.5 0';
278 R_PolygonVertex(v, t, rgb, a);
279 }
280 else if(f > 0.25)
281 {
282 // draw clipped lower half as a quad
283 R_BeginPolygon(pic, drawflag, true);
284 v = centre; t = '0.5 0.5 0';
285 R_PolygonVertex(v, t, rgb, a);
286
287 v = centre; t = '0.5 0.5 0';
288 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
289 R_PolygonVertex(v, t, rgb, a);
290
291 v = centre; t = '0.5 0.5 0';
292 v.y += 0.5 * ringsize.y; t += '0.5 -0.5 0';
293 R_PolygonVertex(v, t, rgb, a);
294 }
295 else if (f > 0)
296 {
297 // draw clipped lower half as a triangle
298 R_BeginPolygon(pic, drawflag, true);
299 v = centre; t = '0.5 0.5 0';
300 R_PolygonVertex(v, t, rgb, a);
301
302 v = centre; t = '0.5 0.5 0';
303 v.x += 0.5 * ringsize.x; t += '0.5 0.5 0';
304 R_PolygonVertex(v, t, rgb, a);
305 }
306 else
307 {
308 // Nothing to draw.
309 return;
310 }
311
312 // The last, moving vertex.
313 v = centre; t = '0.5 0.5 0';
314 v.x += co * 0.5 * ringsize.x; t += co * '0.5 0.5 0';
315 v.y += si * 0.5 * ringsize.y; t += si * '0.5 -0.5 0';
316 R_PolygonVertex(v, t, rgb, a);
317 R_EndPolygon();
318}
vector HUD_Shift(vector v)
Definition hud.qc:105
vector HUD_Scale(vector v)
Definition hud.qc:98
#define M_PI
Definition mathlib.qh:108
float cos(float f)
float sin(float f)
float fabs(float f)

References cos(), fabs(), HUD_Scale(), HUD_Shift(), M_PI, sin(), and vector.

Referenced by HUD_Crosshair(), and HUD_Draw().

◆ drawcolorcodedstring_aspect()

void drawcolorcodedstring_aspect ( vector pos,
string text,
vector sz,
float theAlpha,
float drawflag )

Definition at line 116 of file draw.qc.

116 {
117 DRAWSTRING_ASPECT_SCALE(pos, text, sz, true);
118 drawcolorcodedstring(pos, text, '1 1 0' * sz.y, theAlpha, drawflag);
119}
#define DRAWSTRING_ASPECT_SCALE(pos, text, sz, allow_colors)
Definition draw.qc:88
#define drawcolorcodedstring(position, text, scale, alpha, flag)
Definition draw.qh:30

References drawcolorcodedstring, DRAWSTRING_ASPECT_SCALE, and vector.

Referenced by HUD_Mod_Race(), and HUD_Vote().

◆ drawcolorcodedstring_aspect_expanding()

void drawcolorcodedstring_aspect_expanding ( vector pos,
string text,
vector sz,
float theAlpha,
float drawflag,
float fadelerp )

Definition at line 155 of file draw.qc.

155 {
156 DRAWSTRING_ASPECT_SCALE(pos, text, sz, true);
157 drawcolorcodedstring_expanding(pos, text, '1 1 0' * sz.y, theAlpha, drawflag, fadelerp);
158}
void drawcolorcodedstring_expanding(vector position, string text, vector theScale, float theAlpha, float flag, float fadelerp)
Definition draw.qc:144

References drawcolorcodedstring_expanding(), DRAWSTRING_ASPECT_SCALE, and vector.

◆ drawcolorcodedstring_expanding()

void drawcolorcodedstring_expanding ( vector position,
string text,
vector theScale,
float theAlpha,
float flag,
float fadelerp )

Definition at line 144 of file draw.qc.

145{
146 float sz;
148
150 // eventually replace with drawcolorcodedstring
151 drawcolorcodedstring(position + expandingbox_resize_centered_box_offset(sz, theScale, stringwidth_builtin(text, true, theScale * (sz / drawfontscale.x)) / (theScale.x * sz)), text, theScale * (sz / drawfontscale.x), theAlpha * (1 - fadelerp), flag);
153}
float expandingbox_sizefactor_from_fadelerp(float fadelerp)
Definition draw.qc:50
vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float boxxsizefactor)
Definition draw.qc:55
vector hud_scale
Definition hud.qh:221

References drawcolorcodedstring, drawfontscale, expandingbox_resize_centered_box_offset(), expandingbox_sizefactor_from_fadelerp(), hud_scale, and vector.

Referenced by drawcolorcodedstring_aspect_expanding().

◆ drawpic_aspect_skin_expanding()

void drawpic_aspect_skin_expanding ( vector position,
string pic,
vector theScale,
vector rgb,
float theAlpha,
float flag,
float fadelerp )

Definition at line 61 of file draw.qc.

62{
63 float sz;
65
66 drawpic_aspect_skin(position + expandingbox_resize_centered_box_offset(sz, theScale, 1), pic, theScale * sz, rgb, theAlpha * (1 - fadelerp), flag);
67}
#define drawpic_aspect_skin(pos, pic, sz, color, theAlpha, drawflag)
Definition draw.qh:78

References drawpic_aspect_skin, expandingbox_resize_centered_box_offset(), expandingbox_sizefactor_from_fadelerp(), and vector.

Referenced by DrawAmmoNades(), DrawItemsTimeItem(), DrawNumIcon_expanding(), drawpic_aspect_skin_expanding_two(), HUD_Mod_Keepaway(), and HUD_Mod_TeamKeepaway().

◆ drawpic_aspect_skin_expanding_two()

void drawpic_aspect_skin_expanding_two ( vector position,
string pic,
vector theScale,
vector rgb,
float theAlpha,
float flag,
float fadelerp )

Definition at line 69 of file draw.qc.

70{
71 drawpic_aspect_skin_expanding(position, pic, theScale, rgb, theAlpha, flag, fadelerp);
72 drawpic_skin(position, pic, theScale, rgb, theAlpha * fadelerp, flag);
73}
void drawpic_aspect_skin_expanding(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
Definition draw.qc:61
#define drawpic_skin(pos, pic, sz, color, theAlpha, drawflag)
Definition draw.qh:88

References drawpic_aspect_skin_expanding(), drawpic_skin, and vector.

◆ drawpic_tiled()

void drawpic_tiled ( vector pos,
string pic,
vector sz,
vector area,
vector color,
float theAlpha,
float drawflag )

Definition at line 24 of file draw.qc.

25{
26 pos = HUD_Shift(pos);
27 sz = HUD_Scale(sz);
28 area = HUD_Scale(area);
29
30 vector current_pos = '0 0 0', end_pos, new_size = '0 0 0', ratio = '0 0 0';
31 end_pos = pos + area;
32
33 current_pos.y = pos.y;
34 while (current_pos.y < end_pos.y)
35 {
36 current_pos.x = pos.x;
37 while (current_pos.x < end_pos.x)
38 {
39 new_size.x = min(sz.x, end_pos.x - current_pos.x);
40 new_size.y = min(sz.y, end_pos.y - current_pos.y);
41 ratio.x = new_size.x / sz.x;
42 ratio.y = new_size.y / sz.y;
43 drawsubpic(current_pos, new_size, pic, '0 0 0', ratio, color, theAlpha, drawflag);
44 current_pos.x += sz.x;
45 }
46 current_pos.y += sz.y;
47 }
48}
float drawsubpic(vector position, vector size, string pic, vector srcPosition, vector srcSize, vector rgb, float alpha, float flag)
float min(float f,...)

References color, drawsubpic(), HUD_Scale(), HUD_Shift(), min(), and vector.

Referenced by HUD_Panel_HlBorder(), Scoreboard_AccuracyStats_Draw(), Scoreboard_ItemStats_Draw(), Scoreboard_MakeTable(), Scoreboard_MapStats_Draw(), and Scoreboard_Rankings_Draw().

◆ drawstring_aspect()

void drawstring_aspect ( vector pos,
string text,
vector sz,
vector color,
float theAlpha,
float drawflag )

Definition at line 110 of file draw.qc.

110 {
111 DRAWSTRING_ASPECT_SCALE(pos, text, sz, false);
112 drawstring(pos, text, '1 1 0' * sz.y, color, theAlpha, drawflag);
113}
#define drawstring(position, text, scale, rgb, alpha, flag)
Definition draw.qh:27

References color, drawstring, DRAWSTRING_ASPECT_SCALE, and vector.

Referenced by DrawAmmoItem(), DrawAmmoNades(), DrawCAItem(), DrawDomItem(), DrawItemsTimeItem(), DrawNumIcon_expanding(), HUD_Draw(), HUD_EngineInfo(), HUD_Mod_LMS_Draw(), HUD_Mod_Race(), HUD_Mod_Survival(), HUD_Physics(), HUD_Score(), HUD_Score_Rankings(), HUD_Timer(), HUD_Vote(), race_showTime(), StrafeHUD_DrawTextIndicator(), and Weapons_Draw().

◆ drawstring_aspect_expanding()

void drawstring_aspect_expanding ( vector pos,
string text,
vector sz,
vector color,
float theAlpha,
float drawflag,
float fadelerp )

Definition at line 139 of file draw.qc.

139 {
140 DRAWSTRING_ASPECT_SCALE(pos, text, sz, false);
141 drawstring_expanding(pos, text, '1 1 0' * sz.y, color, theAlpha, drawflag, fadelerp);
142}
void drawstring_expanding(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
Definition draw.qc:121

References color, DRAWSTRING_ASPECT_SCALE, drawstring_expanding(), and vector.

Referenced by DrawNumIcon_expanding(), and race_showTime().

◆ drawstring_expanding()

void drawstring_expanding ( vector position,
string text,
vector theScale,
vector rgb,
float theAlpha,
float flag,
float fadelerp )

Definition at line 121 of file draw.qc.

122{
123 float sz;
125
127 vector dfs = drawfontscale;
128 drawfontscale = sz * '1 1 0';
129 float textaspect = stringwidth_builtin(text, false, theScale * (sz / drawfontscale.x)) / (theScale.x * sz);
130 drawfontscale = dfs;
131 drawstring(position + expandingbox_resize_centered_box_offset(sz, theScale, textaspect), text, HUD_Scale(theScale * (sz / drawfontscale.x)), rgb, theAlpha * (1 - fadelerp), flag);
132 // width parameter:
133 // (scale_x * sz / drawfontscale.x) * drawfontscale.x * SIZE1 / (scale_x * sz)
134 // SIZE1
136}

References drawfontscale, drawstring, expandingbox_resize_centered_box_offset(), expandingbox_sizefactor_from_fadelerp(), HUD_Scale(), hud_scale, and vector.

Referenced by drawstring_aspect_expanding(), and HUD_RaceTimer().

◆ expandingbox_resize_centered_box_offset()

vector expandingbox_resize_centered_box_offset ( float sz,
vector boxsize,
float boxxsizefactor )

Definition at line 55 of file draw.qc.

56{
57 boxsize.x *= boxxsizefactor; // easier interface for text
58 return boxsize * (0.5 * (1 - sz));
59}

References vector.

Referenced by drawcolorcodedstring_expanding(), drawpic_aspect_skin_expanding(), and drawstring_expanding().

◆ expandingbox_sizefactor_from_fadelerp()

float expandingbox_sizefactor_from_fadelerp ( float fadelerp)

Definition at line 50 of file draw.qc.

51{
52 return 1.2 / (1.2 - fadelerp);
53}

Referenced by drawcolorcodedstring_expanding(), drawpic_aspect_skin_expanding(), and drawstring_expanding().

◆ PolyDrawModel()

void PolyDrawModel ( entity e)

Definition at line 182 of file draw.qc.

183{
184 float i_s;
185 for(i_s = 0; ; ++i_s)
186 if(!PolyDrawModelSurface(e, i_s))
187 break;
188}
float PolyDrawModelSurface(entity e, float i_s)
Definition draw.qc:161

References entity(), and PolyDrawModelSurface().

Referenced by DrawDebugModel().

◆ PolyDrawModelSurface()

float PolyDrawModelSurface ( entity e,
float i_s )

Definition at line 161 of file draw.qc.

162{
163 float i_t;
164 float n_t;
165 vector tri;
166 string tex;
167 tex = getsurfacetexture(e, i_s);
168 if (!tex)
169 return 0; // this is beyond the last one
170 n_t = getsurfacenumtriangles(e, i_s);
171 for(i_t = 0; i_t < n_t; ++i_t)
172 {
173 tri = getsurfacetriangle(e, i_s, i_t);
174 R_BeginPolygon(tex, 0, false);
175 R_PolygonVertex(getsurfacepoint(e, i_s, tri.x), getsurfacepointattribute(e, i_s, tri.x, SPA_TEXCOORDS0), '1 1 1', 1);
176 R_PolygonVertex(getsurfacepoint(e, i_s, tri.y), getsurfacepointattribute(e, i_s, tri.y, SPA_TEXCOORDS0), '1 1 1', 1);
177 R_PolygonVertex(getsurfacepoint(e, i_s, tri.z), getsurfacepointattribute(e, i_s, tri.z, SPA_TEXCOORDS0), '1 1 1', 1);
178 R_EndPolygon();
179 }
180 return 1;
181}
#define SPA_TEXCOORDS0

References entity(), SPA_TEXCOORDS0, and vector.

Referenced by PolyDrawModel().

◆ stringwidth()

float stringwidth ( string text,
float handleColors,
vector sz )

Definition at line 75 of file draw.qc.

76{
78 drawfontscale = '1 1 0';
79 float r = stringwidth_builtin(text, handleColors, sz);
80 drawfontscale = dfs;
81 return r;
82}

References drawfontscale, and vector.