]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/strafehud.qc
update strafehud minspeed description and cvar name to be more accurate
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / strafehud.qc
1 // Author: Juhu
2
3 #include "strafehud.qh"
4
5 #include <client/autocvars.qh>
6 #include <client/miscfunctions.qh>
7 #include <common/animdecide.qh>
8 #include <common/ent_cs.qh>
9 #include <common/mapinfo.qh>
10 #include <common/physics/movetypes/movetypes.qh>
11 #include <common/physics/player.qh>
12 #include <lib/csqcmodel/cl_player.qh>
13
14 // StrafeHUD (#25)
15
16 void HUD_StrafeHUD_Export(int fh)
17 {
18     // allow saving cvars that aesthetically change the panel into hud skin files
19 }
20
21 bool fwd = true;
22 bool state_fwd = true;
23 bool state_fwd_prev = true;
24 float demo_angle = -37;
25 float demo_direction = 1;
26 float demo_time = 0;
27 float state_onground_time = 0;
28 float state_strafekeys_time = 0;
29 float state_direction_time = 0;
30 bool state_onground = false;
31 bool state_strafekeys = false;
32 bool turn = false;
33 float turnangle;
34
35 // provide basic panel cvars to old clients
36 // TODO remove them after a future release (0.8.2+)
37 noref string autocvar_hud_panel_strafehud_pos = "0.320000 0.570000";
38 noref string autocvar_hud_panel_strafehud_size = "0.360000 0.020000";
39 noref string autocvar_hud_panel_strafehud_bg = "0";
40 noref string autocvar_hud_panel_strafehud_bg_color = "";
41 noref string autocvar_hud_panel_strafehud_bg_color_team = "";
42 noref string autocvar_hud_panel_strafehud_bg_alpha = "0.7";
43 noref string autocvar_hud_panel_strafehud_bg_border = "";
44 noref string autocvar_hud_panel_strafehud_bg_padding = "";
45
46 void HUD_StrafeHUD()
47 {
48     entity strafeplayer;
49     bool islocal;
50
51     if(!autocvar__hud_configure)
52     {
53         if(!autocvar_hud_panel_strafehud) return;
54         if(spectatee_status == -1 && (autocvar_hud_panel_strafehud == 1 || autocvar_hud_panel_strafehud == 3)) return;
55         if(autocvar_hud_panel_strafehud == 3 && !(ISGAMETYPE(RACE) || ISGAMETYPE(CTS))) return;
56     }
57
58     HUD_Panel_LoadCvars();
59
60     if(autocvar_hud_panel_strafehud_dynamichud)
61         HUD_Scale_Enable();
62     else
63         HUD_Scale_Disable();
64     HUD_Panel_DrawBg();
65     if(panel_bg_padding)
66     {
67         panel_pos  += '1 1 0' * panel_bg_padding;
68         panel_size -= '2 2 0' * panel_bg_padding;
69     }
70
71     if(spectatee_status > 0 || isdemo())
72     {
73         islocal = false;
74         strafeplayer = CSQCModel_server2csqc(player_localentnum - 1);
75     }
76     else
77     {
78         islocal = true;
79         strafeplayer = csqcplayer;
80     }
81
82     // draw strafehud
83     if(csqcplayer && strafeplayer)
84     {
85         // physics
86         bool   onground                      = islocal ? IS_ONGROUND(strafeplayer) : !(strafeplayer.anim_implicit_state & ANIMIMPLICITSTATE_INAIR);
87         bool   strafekeys;
88         bool   is_swimming                   = strafeplayer.waterlevel >= WATERLEVEL_SWIMMING;
89         float  speed                         = !autocvar__hud_configure ? vlen(vec2(csqcplayer.velocity)) : 1337; // use local csqcmodel entity for this even when spectating, flickers too much otherwise
90         float  maxspeed_crouch_mod           = IS_DUCKED(strafeplayer) && (!is_swimming || IS_ONGROUND(strafeplayer)) ? .5 : 1;
91         float  maxspeed_water_mod            = is_swimming ? .7 : 1; // very simplified water physics, the hud will not work well (and is not supposed to) while swimming
92         float  maxspeed_phys                 = onground ? PHYS_MAXSPEED(strafeplayer) : PHYS_MAXAIRSPEED(strafeplayer);
93         float  maxspeed                      = !autocvar__hud_configure ? maxspeed_phys * maxspeed_crouch_mod * maxspeed_water_mod : 320;
94         float  vel_angle                     = vectoangles(strafeplayer.velocity).y;
95         float  view_angle                    = view_angles.y + 180;
96         float  angle;
97         float  direction;
98         vector movement                      = PHYS_INPUT_MOVEVALUES(strafeplayer);
99         int    keys                          = STAT(PRESSED_KEYS);
100         int    keys_fwd;
101         float  wishangle                     = 0;
102         float  moveangle;
103
104         // HUD
105         int    mode                          = autocvar_hud_panel_strafehud_mode >= 0 && autocvar_hud_panel_strafehud_mode <= 1 ? autocvar_hud_panel_strafehud_mode : 0;
106         float  hudangle;
107         float  bar_offset;
108         float  bar_width;
109         vector currentangle_color            = autocvar_hud_panel_strafehud_warning_color;
110         float  currentangle_offset;
111         vector currentangle_size             = '0 0 0';
112         float  bestangle;
113         bool   bestangle_anywhere            = false;
114         float  bestangle_offset;
115         float  bestangle_width;
116         float  switch_bestangle_offset;
117         float  accelzone_offset;
118         float  accelzone_width;
119         float  odd_accelzone_offset;
120         float  odd_accelzone_width;
121         float  overturn_offset;
122         float  overturn_width;
123         float  overturn_width_visible;
124         float  hidden_angle;
125         float  hidden_size;
126         vector direction_size_vertical       = '0 0 0';
127         vector direction_size_horizontal     = '0 0 0';
128         float  maxangle;
129         float  range_minangle;
130
131         // determine whether the player is pressing forwards or backwards keys
132         if(islocal) // if entity is local player
133         {
134             if(movement_x > 0)
135             {
136                 keys_fwd = 1;
137             }
138             else if(movement_x < 0)
139             {
140                 keys_fwd = -1;
141             }
142             else
143             {
144                 keys_fwd = 0;
145             }
146         }
147         else // alternatively determine direction by querying pressed keys
148         {
149             if((keys & KEY_FORWARD) && !(keys & KEY_BACKWARD))
150             {
151                 keys_fwd = 1;
152             }
153             else if(!(keys & KEY_FORWARD) && (keys & KEY_BACKWARD))
154             {
155                 keys_fwd = -1;
156             }
157             else
158             {
159                 keys_fwd = 0;
160             }
161         }
162
163         // determine player wishdir
164         if(islocal) // if entity is local player
165         {
166             if(movement_x == 0)
167             {
168                 if(movement_y < 0)
169                 {
170                     wishangle = -90;
171                 }
172                 else if(movement_y > 0)
173                 {
174                     wishangle = 90;
175                 }
176                 else
177                 {
178                     wishangle = 0;
179                 }
180             }
181             else
182             {
183                 if(movement_y == 0)
184                 {
185                     wishangle = 0;
186                 }
187                 else
188                 {
189                     wishangle = RAD2DEG * atan2(movement_y, movement_x);
190                     // wrap the wish angle if it exceeds ±90°
191                     if(fabs(wishangle) > 90)
192                     {
193                         if(wishangle < 0) wishangle += 180;
194                         else wishangle -= 180;
195                         wishangle = -wishangle;
196                     }
197                 }
198             }
199         }
200         else // alternatively calculate wishdir by querying pressed keys
201         {
202             if(keys & KEY_FORWARD || keys & KEY_BACKWARD)
203             {
204                 wishangle = 45;
205             }
206             else
207             {
208                 wishangle = 90;
209             }
210             if(keys & KEY_LEFT)
211             {
212                 wishangle *= -1;
213             }
214             else if(!(keys & KEY_RIGHT))
215             {
216                 wishangle = 0; // wraps at 180°
217             }
218         }
219
220         strafekeys = fabs(wishangle) == 90;
221
222         // determine minimum required angle to display full strafe range
223         range_minangle = fabs(wishangle) % 90; // maximum range is 90 degree
224         if(range_minangle > 45) // minimum angle range is 45
225         {
226             range_minangle = 45 - fabs(wishangle) % 45;
227         }
228         range_minangle = 90 - range_minangle; // calculate value which is never >90 or <45
229         range_minangle *= 2; // multiply to accommodate for both sides of the hud
230
231         if(autocvar_hud_panel_strafehud_angle == 0)
232         {
233             if(autocvar__hud_configure)
234             {
235                 hudangle = 90;
236             }
237             else
238             {
239                 hudangle = range_minangle; // use minimum angle required if dynamically setting hud angle
240             }
241         }
242         else
243         {
244             hudangle = bound(0, fabs(autocvar_hud_panel_strafehud_angle), 360); // limit HUD range to 360 degrees, higher values don't make sense
245         }
246
247         // detect air strafe turning
248         if(onground != state_onground)
249         {
250             state_onground_time = time;
251         }
252         state_onground = onground;
253         if(strafekeys != state_strafekeys)
254         {
255             state_strafekeys_time = time;
256         }
257         state_strafekeys = strafekeys;
258         if((keys & KEY_FORWARD) || (keys & KEY_BACKWARD) || is_swimming || autocvar__hud_configure)
259         {
260             turn = false;
261         }
262         else if(onground)
263         {
264             if((time - state_onground_time) >= autocvar_hud_panel_strafehud_timeout_ground) // timeout for strafe jumping in general
265             {
266                 turn = false;
267             }
268         }
269         else // air strafe only
270         {
271             if(strafekeys)
272             {
273                 if(((time - state_onground_time) >= autocvar_hud_panel_strafehud_timeout_air) || (keys & KEY_JUMP)) // timeout for slick ramps
274                 {
275                     turn = true; // CPMA turning
276                     turnangle = wishangle;
277                 }
278             }
279             else if((time - state_strafekeys_time) >= autocvar_hud_panel_strafehud_timeout_strafe) // timeout for jumping with strafe keys only
280             {
281                 turn = false;
282             }
283         }
284         if(turn)
285         {
286             maxspeed = PHYS_MAXAIRSTRAFESPEED(strafeplayer); // no crouching here because it doesn't affect air strafing
287             wishangle = turnangle;
288         }
289
290         autocvar_hud_panel_strafehud_minspeed = autocvar_hud_panel_strafehud_minspeed < 0 ? maxspeed + .1 : autocvar_hud_panel_strafehud_minspeed;
291
292         // get current strafing angle ranging from -180° to +180°
293         if(!autocvar__hud_configure)
294         {
295             if(speed > 0)
296             {
297                 // calculate view angle relative to the players current velocity direction
298                 angle = vel_angle - view_angle;
299
300                 // if the angle goes above 180° or below -180° wrap it to the opposite side
301                 if (angle > 180) angle -= 360;
302                 else if(angle < -180) angle += 360;
303
304                 // shift the strafe angle by 180° for hud calculations
305                 if(angle < 0) angle += 180;
306                 else angle -= 180;
307
308                 // determine whether the player is strafing forwards or backwards
309                 // if the player isn't strafe turning use forwards/backwards keys to determine direction
310                 if(!strafekeys)
311                 {
312                     if(keys_fwd > 0)
313                     {
314                     state_fwd = true;
315                     }
316                     else if(keys_fwd < 0)
317                     {
318                         state_fwd = false;
319                     }
320                     else
321                     {
322                         state_fwd = fabs(angle) <= 90;
323                     }
324                 }
325                 // otherwise determine by examining the strafe angle
326                 else
327                 {
328                     if(wishangle < 0) // detect direction since the direction is not yet set
329                     {
330                         state_fwd = angle <= -wishangle;
331                     }
332                     else
333                     {
334                         state_fwd = angle >= -wishangle;
335                     }
336                 }
337
338                 if(state_fwd_prev != state_fwd)
339                 {
340                     state_direction_time = time;
341                 }
342                 state_fwd_prev = state_fwd;
343
344                 if((time - state_direction_time) >= autocvar_hud_panel_strafehud_timeout_direction) // timeout when changing between forwards and backwards strafe
345                 {
346                     fwd = state_fwd;
347                 }
348
349                 // shift the strafe angle by 180° when strafing backwards
350                 if(!fwd)
351                 {
352                     if(angle < 0) angle += 180;
353                     else angle -= 180;
354                 }
355
356                 // making the hud less flickery in case of rounding errors
357                 if(angle > 179.9 || angle < -179.9)
358                 {
359                     currentangle_color = autocvar_hud_panel_strafehud_alert_color;
360                     angle = 0;
361                 }
362                 if(angle < .1 && angle > -.1)
363                 {
364                     angle = 0;
365                 }
366             }
367             else
368             {
369                 angle = 0;
370             }
371         }
372         else // simulate turning for HUD setup
373         {
374             if(autocvar__hud_panel_strafehud_center)
375             {
376                 angle = demo_angle = 0;
377                 demo_time = 0;
378                 wishangle = 0;
379             }
380             else
381             {
382                 if(autocvar__hud_panel_strafehud_demo && ((time - demo_time) >= .025))
383                 {
384                     demo_time = time;
385                     demo_angle += demo_direction;
386                     if(fabs(demo_angle) >= 55)
387                     {
388                         demo_direction = -demo_direction;
389                     }
390                 }
391                 angle = demo_angle;
392                 wishangle = 45 * (demo_angle > 0 ? 1 : -1);
393             }
394         }
395
396         // invert the wish angle when strafing backwards
397         if(!fwd)
398         {
399             wishangle = -wishangle;
400         }
401
402         // flip angles if v_flipped is enabled
403         if(autocvar_v_flipped)
404         {
405             angle = -angle;
406             wishangle = -wishangle;
407         }
408
409         moveangle = angle + wishangle;
410
411         if(wishangle != 0)
412         {
413             direction = wishangle > 0 ? 1 : -1;
414         }
415         else
416         {
417             direction = moveangle > 0 ? 1 : moveangle < 0 ? -1 : 0;
418         }
419
420         // how much is hidden by the current hud angle
421         hidden_angle = 360 - hudangle;
422         hidden_size = hidden_angle / hudangle * panel_size.x;
423         // decelerating at this angle
424         maxangle = 90 - fabs(wishangle);
425         // best angle to strafe at
426         bestangle = (speed > maxspeed ? acos(maxspeed / speed) : 0) * RAD2DEG * (direction < 0 ? -1 : 1) - wishangle;
427         // various offsets and size calculations of hud indicator elements
428         // current angle
429         currentangle_size.x = panel_size.x * .005;
430         if(currentangle_size.x < 1) currentangle_size.x = 1;
431         if(mode == 0)
432         {
433             currentangle_offset = angle/hudangle * panel_size.x;
434         }
435         else
436         {
437             currentangle_offset = bound(-hudangle/2, angle, hudangle/2)/hudangle * panel_size.x + panel_size.x/2;
438         }
439         currentangle_size.y = panel_size.y * 1.5;
440         // best strafe acceleration angle
441         bestangle_offset        =  bestangle/hudangle * panel_size.x + panel_size.x/2;
442         switch_bestangle_offset = -bestangle/hudangle * panel_size.x + panel_size.x/2;
443         if(autocvar_hud_panel_strafehud_indicators)
444         {
445             bestangle_width = panel_size.x * .01;
446             if(bestangle_width < 1) bestangle_width = 1;
447         }
448         else
449         {
450             bestangle_width = 0;
451         }
452         // remove indicator width from offset
453         if(direction < 0)
454         {
455             bestangle_offset -= bestangle_width;
456         }
457         else
458         {
459             switch_bestangle_offset -= bestangle_width;
460         }
461         // direction indicator
462         direction_size_vertical.x = panel_size.x * .0075;
463         if(direction_size_vertical.x < 1) direction_size_vertical.x = 1;
464         direction_size_vertical.y = panel_size.y;
465         direction_size_horizontal.x = direction_size_vertical.x * 3;
466         direction_size_horizontal.y = direction_size_vertical.x;
467         // overturn
468         overturn_width = 180/hudangle * panel_size.x;
469         overturn_width_visible = (hudangle/2 - maxangle) / hudangle * panel_size.x;
470
471         // if the strafe bar fills the whole hud panel
472         if(!(speed >= autocvar_hud_panel_strafehud_minspeed) || !(direction != 0))
473         {
474             // add a background to the strafe-o-meter
475             if(panel_size.x > 0 && panel_size.y > 0)
476             {
477                 if(!autocvar_hud_panel_strafehud_unstyled)
478                 {
479                     HUD_Panel_DrawProgressBar(panel_pos, panel_size, "progressbar", 1, 0, 0, autocvar_hud_panel_strafehud_bar_color, autocvar_hud_panel_strafehud_bar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
480                 }
481                 else
482                 {
483                     drawfill(panel_pos, panel_size, autocvar_hud_panel_strafehud_bar_color, autocvar_hud_panel_strafehud_bar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
484                 }
485             }
486         }
487
488         // mark the ideal strafe angle
489         if(speed >= autocvar_hud_panel_strafehud_minspeed) // only draw indicators if strafing is required to gain speed (or when whatever configured speed is reached)
490         {
491             if(direction != 0) // only draw acceleration zones if strafe direction can be determined
492             {
493                 if(direction < 0) // turning left
494                 {
495                     // calculate zone in which strafe acceleration happens
496                     accelzone_width = bestangle_offset;
497                     // calculate offset of overturn area
498                     overturn_offset = overturn_width_visible - overturn_width;
499                     // move/adjust acceleration zone
500                     accelzone_offset = overturn_width_visible;
501                     accelzone_width -= overturn_width_visible;
502                     // calculate zone in which strafe acceleration could also happen without changing wishdir
503                     odd_accelzone_width = accelzone_width + bestangle_width;
504                     odd_accelzone_offset = overturn_offset - odd_accelzone_width;
505                     // calculate the background of the strafe-o-meter
506                     bar_offset = bestangle_offset + bestangle_width;
507                     bar_width = 360/hudangle * panel_size.x - bestangle_width - accelzone_width - odd_accelzone_width - overturn_width;
508                 }
509                 else // turning right
510                 {
511                     // calculate zone in which strafe acceleration happens
512                     accelzone_offset = bestangle_offset + bestangle_width;
513                     accelzone_width = panel_size.x - accelzone_offset;
514                     // calculate offset of overturn area
515                     overturn_offset = panel_size.x - overturn_width_visible;
516                     // adjust acceleration zone
517                     accelzone_width -= overturn_width_visible;
518                     // calculate zone in which strafe acceleration could also happen without changing wishdir
519                     odd_accelzone_width = accelzone_width + bestangle_width;
520                     odd_accelzone_offset = overturn_offset + overturn_width;
521                     // calculate the background of the strafe-o-meter
522                     bar_offset = odd_accelzone_offset + odd_accelzone_width;
523                     bar_width = 360/hudangle * panel_size.x - bestangle_width - accelzone_width - odd_accelzone_width - overturn_width;
524                 }
525
526                 if(mode == 0)
527                 {
528                     bar_offset -= currentangle_offset;
529                     accelzone_offset -= currentangle_offset;
530                     odd_accelzone_offset -= currentangle_offset;
531                     overturn_offset -= currentangle_offset;
532                     bestangle_offset -= currentangle_offset;
533                     switch_bestangle_offset -= currentangle_offset;
534                 }
535
536                 if(!autocvar_hud_panel_strafehud_unstyled)
537                 {
538                     // draw acceleration zone
539                     HUD_Panel_DrawStrafeHUD_ProgressBar(accelzone_offset, accelzone_width, autocvar_hud_panel_strafehud_indicator_color, autocvar_hud_panel_strafehud_bar_alpha, hidden_size);
540
541                     // draw odd acceleration zone
542                     HUD_Panel_DrawStrafeHUD_ProgressBar(odd_accelzone_offset, odd_accelzone_width, autocvar_hud_panel_strafehud_indicator_color, autocvar_hud_panel_strafehud_bar_alpha, hidden_size);
543
544                     // draw overturn area
545                     HUD_Panel_DrawStrafeHUD_ProgressBar(overturn_offset, overturn_width, autocvar_hud_panel_strafehud_alert_color, autocvar_hud_panel_strafehud_bar_alpha, hidden_size);
546
547                     // draw the strafe bar background
548                     HUD_Panel_DrawStrafeHUD_ProgressBar(bar_offset, bar_width, autocvar_hud_panel_strafehud_bar_color, autocvar_hud_panel_strafehud_bar_alpha, hidden_size);
549                 }
550                 else
551                 {
552                     // draw acceleration zone
553                     HUD_Panel_DrawStrafeHUD_drawfill(accelzone_offset, accelzone_width, autocvar_hud_panel_strafehud_indicator_color, autocvar_hud_panel_strafehud_bar_alpha, hidden_size);
554
555                     // draw odd acceleration zone
556                     HUD_Panel_DrawStrafeHUD_drawfill(odd_accelzone_offset, odd_accelzone_width, autocvar_hud_panel_strafehud_indicator_color, autocvar_hud_panel_strafehud_bar_alpha, hidden_size);
557
558                     // draw overturn area
559                     HUD_Panel_DrawStrafeHUD_drawfill(overturn_offset, overturn_width, autocvar_hud_panel_strafehud_alert_color, autocvar_hud_panel_strafehud_bar_alpha, hidden_size);
560
561                     // draw the strafe bar background
562                     HUD_Panel_DrawStrafeHUD_drawfill(bar_offset, bar_width, autocvar_hud_panel_strafehud_bar_color, autocvar_hud_panel_strafehud_bar_alpha, hidden_size);
563                 }
564
565                 // draw the direction indicator caps at the sides of the hud
566                 // vertical line
567                 drawfill(panel_pos + eX * (direction < 0 ? -direction_size_vertical.x : panel_size.x), direction_size_vertical, autocvar_hud_panel_strafehud_direction_color, panel_fg_alpha, DRAWFLAG_NORMAL);
568                 // top horizontal line
569                 drawfill(panel_pos + eX * (direction < 0 ? -direction_size_vertical.x : panel_size.x - direction_size_horizontal.x + direction_size_vertical.x) - eY * direction_size_horizontal.y, direction_size_horizontal, autocvar_hud_panel_strafehud_direction_color, panel_fg_alpha, DRAWFLAG_NORMAL);
570                 // bottom horizontal line
571                 drawfill(panel_pos + eX * (direction < 0 ? -direction_size_vertical.x : panel_size.x - direction_size_horizontal.x + direction_size_vertical.x) + eY * panel_size.y, direction_size_horizontal, autocvar_hud_panel_strafehud_direction_color, panel_fg_alpha, DRAWFLAG_NORMAL);
572
573                 if(autocvar_hud_panel_strafehud_indicators)
574                 {
575                     // draw best angles for acceleration
576                     HUD_Panel_DrawStrafeHUD_drawfill(switch_bestangle_offset, bestangle_width, autocvar_hud_panel_strafehud_indicator_switch_color, 1, hidden_size);
577                     HUD_Panel_DrawStrafeHUD_drawfill(bestangle_offset, bestangle_width, autocvar_hud_panel_strafehud_indicator_color, 1, hidden_size);
578                 }
579             }
580             else
581             {
582                 if(autocvar_hud_panel_strafehud_indicators)
583                 {
584                     // draw best angles for acceleration
585                     HUD_Panel_DrawStrafeHUD_drawfill(switch_bestangle_offset, bestangle_width, autocvar_hud_panel_strafehud_indicator_switch_color, 1, hidden_size);
586                     HUD_Panel_DrawStrafeHUD_drawfill(bestangle_offset, bestangle_width, autocvar_hud_panel_strafehud_indicator_switch_color, 1, hidden_size);
587                 }
588             }
589         }
590         else
591         {
592             bestangle_anywhere = true; // no indicators, moving forward should suffice to gain speed
593         }
594
595         // draw the actual strafe angle
596         if(!bestangle_anywhere) // player gains speed with strafing
597         {
598             if((direction > 0 && (angle >= bestangle || angle <= -(bestangle + wishangle*2))) ||
599                 (direction < 0 && (angle <= bestangle || angle >= -(bestangle + wishangle*2))))
600             currentangle_color = autocvar_hud_panel_strafehud_good_color;
601         }
602
603         if(fabs(moveangle) > 90) // player is overturning
604         {
605             currentangle_color = autocvar_hud_panel_strafehud_alert_color;
606         }
607
608         if(speed <= (maxspeed + .1) && currentangle_color != autocvar_hud_panel_strafehud_alert_color) // player gains speed without strafing
609         {
610             currentangle_color = autocvar_hud_panel_strafehud_good_color;
611         }
612
613         if(mode == 0)
614         {
615             drawfill(panel_pos - eY * ((currentangle_size.y - panel_size.y) / 2) + eX * (panel_size.x/2 - currentangle_size.x/2), currentangle_size, currentangle_color, autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
616         }
617         else
618         {
619             drawfill(panel_pos - eY * ((currentangle_size.y - panel_size.y) / 2) + eX * (currentangle_offset - currentangle_size.x/2), currentangle_size, currentangle_color, autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
620         }
621     }
622 }
623
624 // functions to make hud elements align perfectly in the hud area
625 void HUD_Panel_DrawStrafeHUD_ProgressBar(float offset, float width, vector color, float alpha, float hidden)
626 {
627     float mirror_offset, mirror_width;
628     vector size = panel_size;
629     vector mirror_size = panel_size;
630
631     if(offset < 0)
632     {
633         mirror_width = min(fabs(offset), width);
634         mirror_offset = panel_size.x + hidden - fabs(offset);
635         width += offset;
636         offset = 0;
637     }
638     else
639     {
640         mirror_width = min(offset + width - panel_size.x - hidden, width);
641         mirror_offset = max(offset - panel_size.x - hidden, 0);
642     }
643     if((offset + width) > panel_size.x)
644     {
645         width = panel_size.x - offset;
646     }
647     if(mirror_offset < 0)
648     {
649         mirror_width += mirror_offset;
650         mirror_offset = 0;
651     }
652     if((mirror_offset + mirror_width) > panel_size.x)
653     {
654         mirror_width = panel_size.x - mirror_offset;
655     }
656
657     size.x = width;
658     mirror_size.x = mirror_width;
659     if(mirror_size.x > 0 && mirror_size.y > 0) HUD_Panel_DrawProgressBar(panel_pos + eX * mirror_offset, mirror_size, "progressbar", 1, 0, 0, color, alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
660     if(size.x > 0 && size.y > 0) HUD_Panel_DrawProgressBar(panel_pos + eX * offset, size, "progressbar", 1, 0, 0, color, alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
661 }
662
663 void HUD_Panel_DrawStrafeHUD_drawfill(float offset, float width, vector color, float alpha, float hidden)
664 {
665     float mirror_offset, mirror_width;
666     vector size = panel_size;
667     vector mirror_size = panel_size;
668
669     if(offset < 0)
670     {
671         mirror_width = min(fabs(offset), width);
672         mirror_offset = panel_size.x + hidden - fabs(offset);
673         width += offset;
674         offset = 0;
675     }
676     else
677     {
678         mirror_width = min(offset + width - panel_size.x - hidden, width);
679         mirror_offset = max(offset - panel_size.x - hidden, 0);
680     }
681     if((offset + width) > panel_size.x)
682     {
683         width = panel_size.x - offset;
684     }
685     if(mirror_offset < 0)
686     {
687         mirror_width += mirror_offset;
688         mirror_offset = 0;
689     }
690     if((mirror_offset + mirror_width) > panel_size.x)
691     {
692         mirror_width = panel_size.x - mirror_offset;
693     }
694
695     size.x = width;
696     mirror_size.x = mirror_width;
697     if(mirror_width > 0) drawfill(panel_pos + eX * mirror_offset, mirror_size, color, alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
698     if(width > 0) drawfill(panel_pos + eX * offset, size, color, alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
699 }