]> de.git.xonotic.org Git - voretournament/voretournament.git/commitdiff
Re-write the centering code for health. The previous was a failure, and most HUD...
authorMirceaKitsune <sonichedgehog_hyperblast00@yahoo.com>
Thu, 14 Apr 2011 23:42:28 +0000 (02:42 +0300)
committerMirceaKitsune <sonichedgehog_hyperblast00@yahoo.com>
Thu, 14 Apr 2011 23:42:28 +0000 (02:42 +0300)
data/qcsrc/client/miscfunctions.qc
data/qcsrc/client/sbar.qc

index 0d72bfec0ec4d9be8e9326f88c87a083170455fb..885d1eda408a5d9e8cc89d6193175ef05e916059 100644 (file)
@@ -481,6 +481,28 @@ void drawpic_expanding_two(vector position, string pic, vector scale, vector rgb
        drawpic(position, pic, scale, rgb, alpha * fadelerp, flag);\r
 }\r
 \r
+// drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box\r
+void drawstring_aspect(vector pos, string text, vector sz, vector color, float alpha, float drawflag) {\r
+       vector textsize;\r
+       textsize = '1 0 0' * stringwidth(text, FALSE, '1 1 1' * sz_y) + '1 0 0' * sz_y;\r
+\r
+       float textaspect;\r
+       textaspect = textsize_x/textsize_y;\r
+\r
+       vector oldsz;\r
+       oldsz = sz;\r
+       float aspect;\r
+       aspect = sz_x/sz_y;\r
+\r
+       if(aspect > textaspect) {\r
+               sz_x = sz_y * textaspect;\r
+               drawstring(pos + '1 0 0' * (oldsz_x - sz_x) * 0.5, text, '1 1 0' * sz_y, color, alpha, drawflag);\r
+       } else {\r
+               sz_y = sz_x / textaspect; \r
+               drawstring(pos + '0 1 0' * (oldsz_y - sz_y) * 0.5, text, '1 1 0' * sz_y, color, alpha, drawflag);\r
+       }\r
+}\r
+\r
 vector drawfontscale;\r
 void drawstring_expanding(vector position, string text, vector scale, vector rgb, float alpha, float flag, float fadelerp)\r
 {\r
index d6a40728d6cad6526714ea38ecbe7bf7db5b4c7c..aff0939d31fb1e50b9cbded89c3597a5b8d7db88 100644 (file)
@@ -123,7 +123,7 @@ void Sbar_DrawXNum (vector pos, float num, float digits, float showminusplus, fl
                pos_x += lettersize / 2;\r
        }\r
 \r
-       drawstring(pos, str, vsize, rgb, alpha, dflags);\r
+       drawstring_aspect(pos, str, vsize, rgb, alpha, dflags);\r
 }\r
 \r
 void Sbar_DrawXNum_Colored (vector pos, float x, float lettersize, float alpha)\r
@@ -2985,7 +2985,7 @@ void Sbar_Draw (void)
                }\r
 \r
                vector health_pos, armor_pos;\r
-               health_pos = bottom - '60 58 0';\r
+               health_pos = bottom - '55 58 0';\r
                armor_pos = bottom - '52.5 68 0';\r
 \r
                // armor\r
@@ -3000,9 +3000,8 @@ void Sbar_Draw (void)
 \r
                // health\r
                x = health;\r
-               drawpic(health_pos + '4.5 16 0', "gfx/hud/sb_health", '32 32 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
-               if(x < 100) health_pos_x += 5; // always center\r
-               if(x < 10) health_pos_x += 5; // always center\r
+               drawpic(health_pos + '0 16 0', "gfx/hud/sb_health", '32 32 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);\r
+               health_pos -= '1 0 0' * stringwidth(ftos(x), FALSE, '22 22 0') * 0.5;\r
                Sbar_DrawXNum_Colored(health_pos, x, 22, sbar_alpha_fg);\r
 \r
                // ammo\r