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