From: MirceaKitsune Date: Thu, 14 Apr 2011 23:42:28 +0000 (+0300) Subject: Re-write the centering code for health. The previous was a failure, and most HUD... X-Git-Url: http://de.git.xonotic.org/?p=voretournament%2Fvoretournament.git;a=commitdiff_plain;h=a8824a36e07c64554f9371c870b799a13bf2523c Re-write the centering code for health. The previous was a failure, and most HUD items need to be fixed again (to keep their position with different fonts). --- diff --git a/data/qcsrc/client/miscfunctions.qc b/data/qcsrc/client/miscfunctions.qc index 0d72bfec..885d1eda 100644 --- a/data/qcsrc/client/miscfunctions.qc +++ b/data/qcsrc/client/miscfunctions.qc @@ -481,6 +481,28 @@ void drawpic_expanding_two(vector position, string pic, vector scale, vector rgb drawpic(position, pic, scale, rgb, alpha * fadelerp, flag); } +// drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box +void drawstring_aspect(vector pos, string text, vector sz, vector color, float alpha, float drawflag) { + vector textsize; + textsize = '1 0 0' * stringwidth(text, FALSE, '1 1 1' * sz_y) + '1 0 0' * sz_y; + + float textaspect; + textaspect = textsize_x/textsize_y; + + vector oldsz; + oldsz = sz; + float aspect; + aspect = sz_x/sz_y; + + if(aspect > textaspect) { + sz_x = sz_y * textaspect; + drawstring(pos + '1 0 0' * (oldsz_x - sz_x) * 0.5, text, '1 1 0' * sz_y, color, alpha, drawflag); + } else { + sz_y = sz_x / textaspect; + drawstring(pos + '0 1 0' * (oldsz_y - sz_y) * 0.5, text, '1 1 0' * sz_y, color, alpha, drawflag); + } +} + vector drawfontscale; void drawstring_expanding(vector position, string text, vector scale, vector rgb, float alpha, float flag, float fadelerp) { diff --git a/data/qcsrc/client/sbar.qc b/data/qcsrc/client/sbar.qc index d6a40728..aff0939d 100644 --- a/data/qcsrc/client/sbar.qc +++ b/data/qcsrc/client/sbar.qc @@ -123,7 +123,7 @@ void Sbar_DrawXNum (vector pos, float num, float digits, float showminusplus, fl pos_x += lettersize / 2; } - drawstring(pos, str, vsize, rgb, alpha, dflags); + drawstring_aspect(pos, str, vsize, rgb, alpha, dflags); } void Sbar_DrawXNum_Colored (vector pos, float x, float lettersize, float alpha) @@ -2985,7 +2985,7 @@ void Sbar_Draw (void) } vector health_pos, armor_pos; - health_pos = bottom - '60 58 0'; + health_pos = bottom - '55 58 0'; armor_pos = bottom - '52.5 68 0'; // armor @@ -3000,9 +3000,8 @@ void Sbar_Draw (void) // health x = health; - drawpic(health_pos + '4.5 16 0', "gfx/hud/sb_health", '32 32 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); - if(x < 100) health_pos_x += 5; // always center - if(x < 10) health_pos_x += 5; // always center + drawpic(health_pos + '0 16 0', "gfx/hud/sb_health", '32 32 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); + health_pos -= '1 0 0' * stringwidth(ftos(x), FALSE, '22 22 0') * 0.5; Sbar_DrawXNum_Colored(health_pos, x, 22, sbar_alpha_fg); // ammo