From b814e760c2e00d2de46e9846f10d176b47cf514a Mon Sep 17 00:00:00 2001 From: FruitieX Date: Thu, 17 Jun 2010 19:10:09 +0300 Subject: [PATCH] drawpic_aspect wrapper for drawpic --- qcsrc/client/hud.qc | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/qcsrc/client/hud.qc b/qcsrc/client/hud.qc index da19f03e3..f8c01ec98 100644 --- a/qcsrc/client/hud.qc +++ b/qcsrc/client/hud.qc @@ -75,9 +75,30 @@ void draw_BorderPicture(vector theOrigin, string pic, vector theSize, vector the } } +// drawpic wrapper to draw an image as large as possible with preserved aspect ratio into a box +void drawpic_aspect(vector pos, string pic, vector sz, vector color, float alpha, float drawflag) { + vector imgsize; + imgsize = drawgetimagesize(pic); + float imgaspect; + imgaspect = imgsize_x/imgsize_y; + + vector oldsz; + oldsz = sz; + float aspect; + aspect = sz_x/sz_y; + + if(aspect > imgaspect) { + sz_x = sz_y * imgaspect; + drawpic(pos + eX * (oldsz_x - sz_x) * 0.5, pic, sz, color, alpha, drawflag); + } else { + sz_y = sz_x / imgaspect; + drawpic(pos + eY * (oldsz_y - sz_y) * 0.5, pic, sz, color, alpha, drawflag); + } +} + // draw HUD element with image from gfx/hud/hud_skin/foo.tga if it exists, otherwise gfx/hud/default/foo.tga void drawpic_skin(vector pos, string pic, vector sz, vector color, float alpha, float drawflag) { - drawpic(pos, strcat("gfx/hud/", cvar_string("hud_skin"), "/", pic), sz, color, alpha, drawflag); + drawpic_aspect(pos, strcat("gfx/hud/", cvar_string("hud_skin"), "/", pic), sz, color, alpha, drawflag); } void drawpic_skin_expanding(vector pos, string pic, vector sz, vector rgb, float alpha, float flag, float fadelerp) { -- 2.39.2