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/draw.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.

Functions

void StrafeHUD_DrawGradient (vector color1, vector color2, vector size, float original_width, float offset, float alpha, float gradient_offset, int gradient_type, float range)
void StrafeHUD_DrawSoftGradient (vector color1, vector color2, vector size, float original_width, float offset, float original_offset, float alpha, float gradient_offset, int gradient_type, float range)
void StrafeHUD_DrawStrafeArrow (vector origin, float size, vector color, float alpha, bool flipped, float connection_width)
void StrafeHUD_DrawStrafeHUD (float startangle, float offsetangle, vector color, float alpha, int type, int gradient_type, float range)
void StrafeHUD_DrawTextIndicator (string text, float height, vector color, float fadetime, float lasttime, vector pos, float offset_top, float offset_bottom)
bool StrafeHUD_IsGradient (int style)

Function Documentation

◆ StrafeHUD_DrawGradient()

void StrafeHUD_DrawGradient ( vector color1,
vector color2,
vector size,
float original_width,
float offset,
float alpha,
float gradient_offset,
int gradient_type,
float range )

Definition at line 183 of file draw.qc.

186{
187 if (gradient_type == STRAFEHUD_GRADIENT_BOTH)
188 {
189 original_width *= 0.5;
190
191 vector size1 = size;
192 size1.x = bound(0, original_width - gradient_offset, size.x);
193
194 vector size2 = size;
195 size2.x = size.x - size1.x;
196
197 if (size1.x > 0)
198 StrafeHUD_DrawGradient(color1, color2, size1, original_width, offset, alpha, gradient_offset, STRAFEHUD_GRADIENT_LEFT, range);
199 if (size2.x > 0)
200 StrafeHUD_DrawGradient(color1, color2, size2, original_width, offset + size1.x, alpha, max(0, gradient_offset - original_width), STRAFEHUD_GRADIENT_RIGHT, range);
201
202 return;
203 }
204
205 vector gradient_start = eX * offset;
206 float gradient_width = StrafeHUD_ProjectWidth(gradient_start.x, size.x, range);
207 gradient_start.x = StrafeHUD_ProjectOffset(gradient_start.x, range, false);
208 vector gradient_end = gradient_start + eX * gradient_width;
209 vector gradient_height = eY * size.y;
210
211 float alpha1 = bound(0, alpha, 1);
213 if (alpha1 + alpha2 == 0)
214 return;
215
216 float ratio1 = gradient_offset / original_width;
217 float ratio2 = (gradient_offset + size.x) / original_width;
218 if (gradient_type == STRAFEHUD_GRADIENT_LEFT)
219 {
220 ratio1 = 1 - ratio1;
221 ratio2 = 1 - ratio2;
222 }
223
225 gradient_start.x = HUD_ScaleX(gradient_start.x);
226 gradient_end.x = HUD_ScaleX(gradient_end.x);
227 gradient_height.y = HUD_ScaleY(gradient_height.y);
228
229 R_BeginPolygon("", DRAWFLAG_NORMAL, true);
230 R_PolygonVertex(origin + gradient_start, '0 0 0', color1, alpha1 * (1 - ratio1));
231 R_PolygonVertex(origin + gradient_start + gradient_height, '0 0 0', color1, alpha1 * (1 - ratio1));
232 R_PolygonVertex(origin + gradient_end + gradient_height, '0 0 0', color1, alpha1 * (1 - ratio2));
233 R_PolygonVertex(origin + gradient_end, '0 0 0', color1, alpha1 * (1 - ratio2));
234 R_EndPolygon();
235
236 R_BeginPolygon("", DRAWFLAG_NORMAL, true);
237 R_PolygonVertex(origin + gradient_start, '0 0 0', color2, alpha2 * ratio1);
238 R_PolygonVertex(origin + gradient_start + gradient_height, '0 0 0', color2, alpha2 * ratio1);
239 R_PolygonVertex(origin + gradient_end + gradient_height, '0 0 0', color2, alpha2 * ratio2);
240 R_PolygonVertex(origin + gradient_end, '0 0 0', color2, alpha2 * ratio2);
241 R_EndPolygon();
242}
void StrafeHUD_DrawGradient(vector color1, vector color2, vector size, float original_width, float offset, float alpha, float gradient_offset, int gradient_type, float range)
Definition draw.qc:183
float StrafeHUD_ProjectWidth(float offset, float width, float range)
Definition util.qc:73
float StrafeHUD_ProjectOffset(float offset, float range, bool reverse)
Definition util.qc:61
float alpha
Definition items.qc:13
const float DRAWFLAG_NORMAL
vector size
vector origin
vector HUD_Shift(vector v)
Definition hud.qc:105
#define HUD_ScaleX(f)
Definition hud.qh:15
float panel_fg_alpha
Definition hud.qh:169
#define HUD_ScaleY(f)
Definition hud.qh:16
vector panel_pos
Definition hud.qh:162
float bound(float min, float value, float max)
float max(float f,...)
vector
Definition self.qh:92
const int STRAFEHUD_GRADIENT_RIGHT
Definition strafehud.qh:147
float autocvar_hud_panel_strafehud_bar_neutral_alpha
Definition strafehud.qh:25
const int STRAFEHUD_GRADIENT_BOTH
Definition strafehud.qh:148
const int STRAFEHUD_GRADIENT_LEFT
Definition strafehud.qh:146
const vector eY
Definition vector.qh:45
const vector eX
Definition vector.qh:44

References alpha, autocvar_hud_panel_strafehud_bar_neutral_alpha, bound(), DRAWFLAG_NORMAL, eX, eY, HUD_ScaleX, HUD_ScaleY, HUD_Shift(), max(), origin, panel_fg_alpha, panel_pos, size, StrafeHUD_DrawGradient(), STRAFEHUD_GRADIENT_BOTH, STRAFEHUD_GRADIENT_LEFT, STRAFEHUD_GRADIENT_RIGHT, StrafeHUD_ProjectOffset(), StrafeHUD_ProjectWidth(), and vector.

Referenced by StrafeHUD_DrawGradient(), and StrafeHUD_DrawStrafeHUD().

◆ StrafeHUD_DrawSoftGradient()

void StrafeHUD_DrawSoftGradient ( vector color1,
vector color2,
vector size,
float original_width,
float offset,
float original_offset,
float alpha,
float gradient_offset,
int gradient_type,
float range )

Definition at line 245 of file draw.qc.

248{
249 float alpha1 = bound(0, alpha, 1);
251 if (alpha1 == 0 && alpha2 == 0)
252 return;
253
254 float color_ratio = alpha1 / (alpha1 + alpha2);
255 vector segment_size = size;
256 for (int i = 0; i < size.x; ++i)
257 {
258 segment_size.x = min(size.x - i, 1); // each gradient segment is 1 unit wide except if there is less than 1 unit of gradient remaining
259 float segment_offset = offset + i;
260 float ratio_offset = segment_offset + segment_size.x / 2;
261 ratio_offset = StrafeHUD_ProjectOffset(ratio_offset, range, true);
262 ratio_offset += gradient_offset;
263 float ratio = (ratio_offset - original_offset) / original_width * (gradient_type == STRAFEHUD_GRADIENT_BOTH ? 2 : 1);
264 if (ratio > 1)
265 ratio = 2 - ratio;
266 if (gradient_type != STRAFEHUD_GRADIENT_RIGHT)
267 ratio = 1 - ratio;
268 float alpha_ratio = alpha1 - (alpha1 - alpha2) * ratio;
269 float combine_ratio1 = ratio * (1 - color_ratio);
270 float combine_ratio2 = (1 - ratio) * color_ratio;
271 ratio = (combine_ratio1 + combine_ratio2) == 0 ? 1 : combine_ratio1 / (combine_ratio1 + combine_ratio2);
272
273 if (alpha_ratio > 0)
274 drawfill(
275 panel_pos + eX * segment_offset,
276 segment_size,
277 StrafeHUD_MixColors(color1, color2, ratio),
278 alpha_ratio,
280 }
281}
#define drawfill(position, size, rgb, alpha, flag)
Definition draw.qh:36
vector StrafeHUD_MixColors(vector color1, vector color2, float ratio)
Definition util.qc:351
float min(float f,...)

References alpha, autocvar_hud_panel_strafehud_bar_neutral_alpha, bound(), drawfill, DRAWFLAG_NORMAL, eX, min(), panel_fg_alpha, panel_pos, size, STRAFEHUD_GRADIENT_BOTH, STRAFEHUD_GRADIENT_RIGHT, StrafeHUD_MixColors(), StrafeHUD_ProjectOffset(), and vector.

Referenced by StrafeHUD_DrawStrafeHUD().

◆ StrafeHUD_DrawStrafeArrow()

void StrafeHUD_DrawStrafeArrow ( vector origin,
float size,
vector color,
float alpha,
bool flipped,
float connection_width )

Definition at line 284 of file draw.qc.

285{
286 // alpha and size already checked
287
289 float width = HUD_ScaleX(size * 2 + connection_width);
290 float height = HUD_ScaleY(size);
291 if (flipped)
292 origin.y -= size;
293 R_BeginPolygon("", DRAWFLAG_NORMAL, true);
294 if (connection_width > 0)
295 {
296 R_PolygonVertex(origin + (connection_width / 2 * eX) + (flipped ? height * eY : '0 0 0'), '0 0 0', color, alpha);
297 R_PolygonVertex(origin - (connection_width / 2 * eX) + (flipped ? height * eY : '0 0 0'), '0 0 0', color, alpha);
298 }
299 else
300 R_PolygonVertex(origin + (flipped ? height * eY : '0 0 0'), '0 0 0', color, alpha);
301
302 R_PolygonVertex(origin + (flipped ? '0 0 0' : height * eY) - (width / 2) * eX, '0 0 0', color, alpha);
303 R_PolygonVertex(origin + (flipped ? '0 0 0' : height * eY) + (width / 2) * eX, '0 0 0', color, alpha);
304 R_EndPolygon();
305}
float height
Definition bobbing.qc:3
vector color
Definition dynlight.qc:15

References alpha, color, DRAWFLAG_NORMAL, eX, eY, height, HUD_ScaleX, HUD_ScaleY, HUD_Shift(), origin, size, and vector.

Referenced by StrafeHUD_DrawAngleIndicatorArrow().

◆ StrafeHUD_DrawStrafeHUD()

void StrafeHUD_DrawStrafeHUD ( float startangle,
float offsetangle,
vector color,
float alpha,
int type,
int gradient_type,
float range )

Definition at line 8 of file draw.qc.

9{
10 float offset = StrafeHUD_AngleToOffset(startangle % 360, range);
11 float width = StrafeHUD_AngleToWidth(offsetangle, range);
12 float mirror_offset;
13 float mirror_width;
14
15 if (width <= 0)
16 return;
17
18 if (StrafeHUD_IsGradient(type))
19 {
20 if (gradient_type == STRAFEHUD_GRADIENT_NONE)
21 {
23 if (alpha <= 0)
24 return;
25 }
26 }
27 else if (alpha <= 0)
28 return;
29
30 // how much is hidden by the current hud angle
31 float hidden_width = (360 - range) / range * panel_size.x;
32 float total_width = panel_size.x + hidden_width;
33 float original_width = width; // required for gradient
34
35 if (offset < 0)
36 {
37 mirror_width = min(fabs(offset), width);
38 mirror_offset = offset + total_width;
39 width += offset;
40 offset = 0;
41 }
42 else
43 {
44 mirror_offset = offset - total_width;
45 mirror_width = min(mirror_offset + width, width);
46 if (mirror_offset < 0)
47 mirror_offset = 0;
48 }
49
50 float overflow_width = offset + width - panel_size.x;
51 width = max(width, 0);
52 if (overflow_width > 0)
53 width = panel_size.x - offset;
54 else
55 overflow_width = 0;
56
58 size.x = width;
59
60 float original_offset = offset;
61
62 // the accelerated gradient does the projection later
63 if (type != STRAFEHUD_STYLE_GRADIENT)
64 {
65 if (size.x > 0)
66 size.x = StrafeHUD_ProjectWidth(offset, size.x, range);
67
68 offset = StrafeHUD_ProjectOffset(offset, range, false);
69 }
70
71 if (mirror_offset < 0)
72 {
73 mirror_width += mirror_offset;
74 mirror_offset = 0;
75 }
76
77 float overflow_mirror_width = mirror_offset + mirror_width - panel_size.x;
78 mirror_width = max(mirror_width, 0);
79 if (overflow_mirror_width > 0)
80 mirror_width = panel_size.x - mirror_offset;
81 else
82 overflow_mirror_width = 0;
83
84 vector mirror_size = panel_size;
85 mirror_size.x = mirror_width;
86
87 float original_mirror_offset = mirror_offset;
88
89 // the accelerated gradient does the projection later
90 if (type != STRAFEHUD_STYLE_GRADIENT)
91 {
92 if (mirror_size.x > 0)
93 mirror_size.x = StrafeHUD_ProjectWidth(mirror_offset, mirror_size.x, range);
94
95 mirror_offset = StrafeHUD_ProjectOffset(mirror_offset, range, false);
96 }
97
98 switch (type)
99 {
100 default:
101 case STRAFEHUD_STYLE_DRAWFILL: // no styling (drawfill)
102 if (mirror_size.x > 0 && mirror_size.y > 0)
103 drawfill(panel_pos + eX * mirror_offset, mirror_size, color, alpha, DRAWFLAG_NORMAL);
104 if (size.x > 0 && size.y > 0)
106 break;
107
108 case STRAFEHUD_STYLE_PROGRESSBAR: // progress bar style
109 if (mirror_size.x > 0 && mirror_size.y > 0)
111 panel_pos + eX * mirror_offset,
112 mirror_size, "progressbar",
113 1, 0, 0, color, alpha, DRAWFLAG_NORMAL);
114 if (size.x > 0 && size.y > 0)
116 panel_pos + eX * offset,
117 size, "progressbar",
118 1, 0, 0, color, alpha, DRAWFLAG_NORMAL);
119 break;
120
121 case STRAFEHUD_STYLE_GRADIENT: // gradient style (types: 1 = left, 2 = right, 3 = both)
123 {
124 // determine whether the gradient starts in the mirrored or the non-mirrored area
125 int gradient_start;
126 float gradient_offset, gradient_mirror_offset;
127
128 if (offset == 0 && mirror_offset == 0)
129 gradient_start = width > mirror_width ? 2 : 1;
130 else if (offset == 0)
131 gradient_start = 2;
132 else if (mirror_offset == 0)
133 gradient_start = 1;
134 else
135 gradient_start = 0;
136
137 switch (gradient_start)
138 {
139 default:
140 case 0: // no offset required
141 gradient_offset = gradient_mirror_offset = 0;
142 break;
143 case 1: // offset starts in non-mirrored area, mirrored area requires offset
144 gradient_offset = 0;
145 gradient_mirror_offset = original_width - (mirror_width + overflow_mirror_width);
146 break;
147 case 2: // offset starts in mirrored area, non-mirrored area requires offset
148 gradient_offset = original_width - (width + overflow_width);
149 gradient_mirror_offset = 0;
150 }
151
152 if (type == STRAFEHUD_STYLE_GRADIENT)
153 {
154 if (mirror_size.x > 0)
157 mirror_size, original_width, mirror_offset, alpha,
158 gradient_mirror_offset, gradient_type, range);
159 if (size.x > 0)
162 size, original_width, offset, alpha,
163 gradient_offset, gradient_type, range);
164 }
165 else
166 {
167 if (mirror_size.x > 0)
170 mirror_size, original_width, mirror_offset, original_mirror_offset,
171 alpha, gradient_mirror_offset, gradient_type, range);
172 if (size.x > 0)
175 size, original_width, offset, original_offset,
176 alpha, gradient_offset, gradient_type, range);
177 }
178 }
179 }
180}
void StrafeHUD_DrawSoftGradient(vector color1, vector color2, vector size, float original_width, float offset, float original_offset, float alpha, float gradient_offset, int gradient_type, float range)
Definition draw.qc:245
bool StrafeHUD_IsGradient(int style)
Definition draw.qc:341
float StrafeHUD_AngleToWidth(float angle, float range)
Definition util.qc:12
float StrafeHUD_AngleToOffset(float angle, float range)
Definition util.qc:18
void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, bool vertical, float baralign, vector theColor, float theAlpha, int drawflag)
Definition hud.qc:269
vector panel_size
Definition hud.qh:163
float fabs(float f)
const int STRAFEHUD_STYLE_GRADIENT
Definition strafehud.qh:142
const int STRAFEHUD_GRADIENT_NONE
Definition strafehud.qh:145
const int STRAFEHUD_STYLE_SOFT_GRADIENT
Definition strafehud.qh:143
const int STRAFEHUD_STYLE_DRAWFILL
Definition strafehud.qh:140
vector autocvar_hud_panel_strafehud_bar_neutral_color
Definition strafehud.qh:24
const int STRAFEHUD_STYLE_PROGRESSBAR
Definition strafehud.qh:141

References alpha, autocvar_hud_panel_strafehud_bar_neutral_color, color, drawfill, DRAWFLAG_NORMAL, eX, fabs(), HUD_Panel_DrawProgressBar(), max(), min(), panel_pos, panel_size, size, StrafeHUD_AngleToOffset(), StrafeHUD_AngleToWidth(), StrafeHUD_DrawGradient(), StrafeHUD_DrawSoftGradient(), STRAFEHUD_GRADIENT_NONE, StrafeHUD_IsGradient(), StrafeHUD_ProjectOffset(), StrafeHUD_ProjectWidth(), STRAFEHUD_STYLE_DRAWFILL, STRAFEHUD_STYLE_GRADIENT, STRAFEHUD_STYLE_PROGRESSBAR, STRAFEHUD_STYLE_SOFT_GRADIENT, and vector.

Referenced by StrafeHUD_DrawStrafeMeter().

◆ StrafeHUD_DrawTextIndicator()

void StrafeHUD_DrawTextIndicator ( string text,
float height,
vector color,
float fadetime,
float lasttime,
vector pos,
float offset_top,
float offset_bottom )

Definition at line 308 of file draw.qc.

311{
312 float time_frac = (time - lasttime) / fadetime;
313 if (height <= 0 || lasttime <= 0 || fadetime <= 0 || time_frac > 1)
314 return;
315
316 float alpha = cos(time_frac * M_PI_2); // fade non-linear like the physics panel does
318 size.y = height;
319
320 if (pos.y >= 1)
321 {
322 --pos.y; // for calculations the position should not start at +1
324 pos.y += size.y + offset_top;
325 pos.y *= -1; // it's more intuitive for up to be positive
326 }
327 else if (pos.y <= -1)
328 {
329 ++pos.y; // for calculations the position should not start at -1
331 pos.y *= -1; // it's more intuitive for down to be negative
332 pos.y += panel_size.y + offset_bottom;
333 }
334 else
335 return;
336
338}
void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag)
Definition draw.qc:110
vector StrafeHUD_CalculateTextIndicatorPosition(vector pos)
Definition util.qc:360
float time
const float M_PI_2
Definition mathlib.qh:109
float cos(float f)
fadetime

References alpha, color, cos(), DRAWFLAG_NORMAL, drawstring_aspect(), fadetime, height, M_PI_2, panel_fg_alpha, panel_pos, panel_size, size, StrafeHUD_CalculateTextIndicatorPosition(), time, and vector.

Referenced by StrafeHUD_DrawJumpHeight(), StrafeHUD_DrawStartSpeed(), StrafeHUD_DrawStrafeEfficiency(), and StrafeHUD_DrawVerticalAngle().

◆ StrafeHUD_IsGradient()

bool StrafeHUD_IsGradient ( int style)

Definition at line 341 of file draw.qc.

342{
344}
float style

References STRAFEHUD_STYLE_GRADIENT, STRAFEHUD_STYLE_SOFT_GRADIENT, and style.

Referenced by HUD_StrafeHUD(), and StrafeHUD_DrawStrafeHUD().