Dynamic HUD: Rework panel resizing/shifting in a cleaner way and implement proper...
authorterencehill <piuntn@gmail.com>
Thu, 24 Mar 2016 20:57:52 +0000 (21:57 +0100)
committerterencehill <piuntn@gmail.com>
Thu, 24 Mar 2016 21:17:44 +0000 (22:17 +0100)
40 files changed:
qcsrc/client/hud/hud.qc
qcsrc/client/hud/hud.qh
qcsrc/client/hud/panel/ammo.qc
qcsrc/client/hud/panel/centerprint.qc
qcsrc/client/hud/panel/chat.qc
qcsrc/client/hud/panel/engineinfo.qc
qcsrc/client/hud/panel/healtharmor.qc
qcsrc/client/hud/panel/infomessages.qc
qcsrc/client/hud/panel/modicons.qc
qcsrc/client/hud/panel/notify.qc
qcsrc/client/hud/panel/physics.qc
qcsrc/client/hud/panel/powerups.qc
qcsrc/client/hud/panel/pressedkeys.qc
qcsrc/client/hud/panel/racetimer.qc
qcsrc/client/hud/panel/radar.qc
qcsrc/client/hud/panel/score.qc
qcsrc/client/hud/panel/timer.qc
qcsrc/client/hud/panel/vote.qc
qcsrc/client/hud/panel/weapons.qc
qcsrc/client/mapvoting.qc
qcsrc/client/miscfunctions.qc
qcsrc/client/miscfunctions.qh
qcsrc/client/quickmenu.qc
qcsrc/client/teamradar.qc
qcsrc/client/view.qc
qcsrc/common/debug.qh
qcsrc/common/minigames/cl_minigames_hud.qc
qcsrc/common/minigames/minigame/bd.qc
qcsrc/common/minigames/minigame/c4.qc
qcsrc/common/minigames/minigame/nmm.qc
qcsrc/common/minigames/minigame/pong.qc
qcsrc/common/minigames/minigame/pp.qc
qcsrc/common/minigames/minigame/ps.qc
qcsrc/common/minigames/minigame/snake.qc
qcsrc/common/minigames/minigame/ttt.qc
qcsrc/common/mutators/mutator/damagetext/damagetext.qc
qcsrc/common/mutators/mutator/itemstime.qc
qcsrc/dpdefs/upstream/csprogsdefs.qc
qcsrc/lib/draw.qh
qcsrc/lib/string.qh

index 6b6f4d230ab0a7a379272d9e8c527bdbd2ada095..f27870988a6b62470c36f4bd57cb5a2c6901d6ca 100644 (file)
@@ -216,6 +216,9 @@ void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, flo
        else if(length_ratio < 0)
                return;
 
+       theOrigin = HUD_Shift(theOrigin);
+       theSize = HUD_Scale(theSize);
+
        vector square;
        vector width, height;
        if(vertical) {
@@ -311,6 +314,9 @@ void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float theA
        if(!theAlpha)
                return;
 
+       pos = HUD_Shift(pos);
+       mySize = HUD_Scale(mySize);
+
        string pic;
        pic = strcat(hud_skin_path, "/num_leading");
        if(precache_pic(pic) == "") {
@@ -491,20 +497,29 @@ bool Hud_Shake_Update()
 void calc_followmodel_ofs(entity view);
 void Hud_Dynamic_Frame()
 {
-       hud_dynamic_ofs = '0 0 0';
+       vector ofs = '0 0 0';
+       hud_scale = '1 1 0';
+       hud_shift = '0 0 0';
        if (autocvar_hud_dynamic_follow)
        {
                entity view = CSQCModel_server2csqc(player_localentnum - 1);
                calc_followmodel_ofs(view);
-               hud_dynamic_ofs -= cl_followmodel_ofs * autocvar_hud_dynamic_follow_scale;
+               ofs = -cl_followmodel_ofs * autocvar_hud_dynamic_follow_scale;
        }
 
-       if (fabs(hud_dynamic_ofs.x) < 0.001) hud_dynamic_ofs.x = 0;
-       if (fabs(hud_dynamic_ofs.y) < 0.001) hud_dynamic_ofs.y = 0;
-       if (fabs(hud_dynamic_ofs.z) < 0.001) hud_dynamic_ofs.z = 0;
-       hud_dynamic_ofs.x = bound(-0.1, hud_dynamic_ofs.x, 0.1);
-       hud_dynamic_ofs.y = bound(-0.1, hud_dynamic_ofs.y, 0.1);
-       hud_dynamic_ofs.z = bound(-0.1, hud_dynamic_ofs.z, 0.1);
+       if (fabs(ofs.x) < 0.001) ofs.x = 0;
+       if (fabs(ofs.y) < 0.001) ofs.y = 0;
+       if (fabs(ofs.z) < 0.001) ofs.z = 0;
+       ofs.x = bound(-0.1, ofs.x, 0.1);
+       ofs.y = bound(-0.1, ofs.y, 0.1);
+       ofs.z = bound(-0.1, ofs.z, 0.1);
+
+       hud_shift.x = ofs.y * vid_conwidth;
+       hud_shift.y = ofs.z * vid_conheight;
+       hud_shift.z = ofs.x;
+
+       hud_scale.x = (1 + hud_shift.z);
+       hud_scale.y = hud_scale.x;
 
        float health = STAT(HEALTH);
        if(autocvar_hud_dynamic_shake > 0 && !autocvar__hud_configure && health > 0)
@@ -531,6 +546,18 @@ void Hud_Dynamic_Frame()
                                        hud_dynamic_shake_factor = 0;
                }
        }
+
+       if(hud_dynamic_shake_factor > 0)
+       {
+               hud_shift.x += hud_dynamic_shake_realofs.x;
+               hud_shift.y += hud_dynamic_shake_realofs.y;
+       }
+
+       hud_scale_center.x = 0.5 * vid_conwidth;
+       hud_scale_center.y = 0.5 * vid_conheight;
+
+       hud_scale_current = hud_scale;
+       hud_shift_current = hud_shift;
 }
 
 void HUD_Main()
@@ -547,6 +574,8 @@ void HUD_Main()
 
        HUD_Configure_Frame();
 
+       Hud_Dynamic_Frame();
+
        // panels that we want to be active together with the scoreboard
        // they must fade only when the menu does
        if(scoreboard_fade_alpha == 1)
@@ -563,8 +592,6 @@ void HUD_Main()
                return;
        }
 
-       Hud_Dynamic_Frame();
-
        // Drawing stuff
        if (hud_skin_prev != autocvar_hud_skin)
        {
index 3141fa75faf418c89da20b68d7be4d7ce7c4d71f..4b12656895aa38de2d2c42bc612f4ed72b86b3bd 100644 (file)
@@ -22,9 +22,16 @@ REGISTER_REGISTRY(hud_panels)
 #define HUD_PANEL(NAME) HUD_PANEL_##NAME
 
 // draw the background/borders
-#define HUD_Panel_DrawBg(theAlpha) MACRO_BEGIN {                                                                                                                                                               \
-       if(panel.current_panel_bg != "0" && panel.current_panel_bg != "")                                                                                               \
-               draw_BorderPicture(panel_pos - '1 1 0' * panel_bg_border, panel.current_panel_bg, panel_size + '1 1 0' * 2 * panel_bg_border, panel_bg_color, panel_bg_alpha * theAlpha, '1 1 0' * (panel_bg_border/BORDER_MULTIPLIER));\
+#define HUD_Panel_DrawBg(theAlpha) MACRO_BEGIN { \
+       if(panel.current_panel_bg != "0" && panel.current_panel_bg != "") \
+               draw_BorderPicture( \
+                       HUD_Shift(panel_pos - '1 1 0' * panel_bg_border), \
+                       panel.current_panel_bg, \
+                       HUD_Scale(panel_size + '1 1 0' * 2 * panel_bg_border), \
+                       panel_bg_color, \
+                       panel_bg_alpha * theAlpha, \
+                       HUD_Scale('1 1 0' * (panel_bg_border/BORDER_MULTIPLIER)) \
+               ); \
 } MACRO_END
 
 int panel_order[hud_panels_MAX];
@@ -166,7 +173,11 @@ float hud_dynamic_shake_time;
 vector cl_followmodel_ofs;
 float cl_followmodel_time;
 
-vector hud_dynamic_ofs;
+vector hud_scale;
+vector hud_scale_current;
+vector hud_shift;
+vector hud_shift_current;
+vector hud_scale_center;
 
 float stringwidth_colors(string s, vector theSize);
 float stringwidth_nocolors(string s, vector theSize);
@@ -406,15 +417,6 @@ REGISTER_HUD_PANEL(QUICKMENU,       HUD_QuickMenu,      quickmenu,      PANEL_CO
                panel_bg_padding = panel.current_panel_bg_padding;                                                          \
                panel_fg_alpha = panel.current_panel_fg_alpha * hud_fade_alpha;                                             \
        }                                                                                                               \
-       if(hud_dynamic_shake_factor > 0) panel_pos += hud_dynamic_shake_realofs; \
-       if(hud_dynamic_ofs.y) panel_pos.x += hud_dynamic_ofs.y * vid_conwidth; \
-       if(hud_dynamic_ofs.z) panel_pos.y += hud_dynamic_ofs.z * vid_conheight; \
-       if(hud_dynamic_ofs.x) { \
-               panel_size.x += hud_dynamic_ofs.x * panel_size.x; \
-               panel_size.y += hud_dynamic_ofs.x * panel_size.y; \
-               panel_pos.x += hud_dynamic_ofs.x * (panel_pos.x - vid_conwidth * 0.5); \
-               panel_pos.y += hud_dynamic_ofs.x * (panel_pos.y - vid_conheight * 0.5); \
-       } \
 } MACRO_END
 
 #define HUD_Panel_UpdatePosSize() MACRO_BEGIN {                                                                     \
index fda7887b1641d74d55f3b8a2e3c9ded8e36d7874..e8a702d6b34ee80684521e43f072fdcfcd2a7e39 100644 (file)
@@ -110,6 +110,7 @@ void HUD_Ammo()
        pos = panel_pos;
        mySize = panel_size;
 
+       HUD_Scale_Enable();
        HUD_Panel_DrawBg(1);
        if(panel_bg_padding)
        {
index 99e8baaa65807a2a390b85050a1f53a1c70838a7..23c383e45c3e22e856fb4e66f1bca7bda003bd40 100644 (file)
@@ -186,6 +186,7 @@ void HUD_CenterPrint ()
                }
        }
 
+       HUD_Scale_Enable();
        HUD_Panel_DrawBg(1);
 
        if (!centerprint_showing)
@@ -263,7 +264,7 @@ void HUD_CenterPrint ()
 
                // finally set the size based on the new theAlpha from subsequent fading
                sz = sz * (autocvar_hud_panel_centerprint_fade_subsequent_minfontsize + a * (1 - autocvar_hud_panel_centerprint_fade_subsequent_minfontsize));
-               drawfontscale = sz * '1 1 0';
+               drawfontscale = hud_scale * sz;
 
                if (centerprint_countdown_num[j])
                        n = tokenizebyseparator(strreplace("^COUNT", count_seconds(centerprint_countdown_num[j]), centerprint_messages[j]), "\n");
@@ -278,7 +279,7 @@ void HUD_CenterPrint ()
                                getWrappedLine_remaining = argv(k);
                                while(getWrappedLine_remaining)
                                {
-                                       ts = getWrappedLine(panel_size.x * sz, fontsize, stringwidth_colors);
+                                       ts = getWrappedLine(panel_size.x * hud_scale.x * sz, fontsize, stringwidth_colors);
                                        if (ts != "")
                                                pos.y -= fontsize.y;
                                        else
@@ -294,13 +295,13 @@ void HUD_CenterPrint ()
                        getWrappedLine_remaining = argv(k);
                        while(getWrappedLine_remaining)
                        {
-                               ts = getWrappedLine(panel_size.x * sz, fontsize, stringwidth_colors);
+                               ts = getWrappedLine(panel_size.x * hud_scale.x * sz, fontsize, stringwidth_colors);
                                if (ts != "")
                                {
                                        if (align)
-                                               pos.x = panel_pos.x + (panel_size.x - stringwidth(ts, true, fontsize)) * align;
+                                               pos.x = panel_pos.x + (panel_size.x - stringwidth(ts, true, fontsize) * sz) * align;
                                        if (a > 0.5/255.0)  // Otherwise guaranteed invisible - don't show. This is checked a second time after some multiplications with other factors were done so temporary changes of these cannot cause flicker.
-                                               drawcolorcodedstring(pos + eY * 0.5 * (1 - sz) * fontsize.y, ts, fontsize, a, DRAWFLAG_NORMAL);
+                                               drawcolorcodedstring(pos + eY * 0.5 * (1 - sz * hud_scale.x) * fontsize.y, ts, fontsize, a, DRAWFLAG_NORMAL);
                                        pos.y += fontsize.y;
                                }
                                else
@@ -319,7 +320,7 @@ void HUD_CenterPrint ()
 
                        if (pos.y < panel_pos.y) // check if the next message can be shown
                        {
-                               drawfontscale = '1 1 0';
+                               drawfontscale = hud_scale;
                                return;
                        }
                }
@@ -331,12 +332,12 @@ void HUD_CenterPrint ()
 
                        if(pos.y > panel_pos.y + panel_size.y - fontsize.y) // check if the next message can be shown
                        {
-                               drawfontscale = '1 1 0';
+                               drawfontscale = hud_scale;
                                return;
                        }
                }
        }
-       drawfontscale = '1 1 0';
+       drawfontscale = hud_scale;
        if (all_messages_expired)
        {
                centerprint_showing = false;
index dd89b791ce2c2362513a86c03fee66894e68bb12..d8945991ece5c7b28506a178526a11b7965b3a2b 100644 (file)
@@ -54,6 +54,7 @@ void HUD_Chat()
        pos = panel_pos;
        mySize = panel_size;
 
+       HUD_Scale_Disable();
        HUD_Panel_DrawBg(1);
 
        if(panel_bg_padding)
index ea136a21489abd1c111b457ec27855cd23a673fc..ce425a2def193c6b14e86a6ef8e2f8f71ffa057f 100644 (file)
@@ -23,6 +23,7 @@ void HUD_EngineInfo()
        pos = panel_pos;
        mySize = panel_size;
 
+       HUD_Scale_Enable();
        HUD_Panel_DrawBg(1);
        if(panel_bg_padding)
        {
index 3b03979177da96edf15e5c4a3ee0ed35f04b0ee1..ffbd231eec4ecfa4b82bf9083094dd30d2ad9183 100644 (file)
@@ -62,6 +62,7 @@ void HUD_HealthArmor()
        pos = panel_pos;
        mySize = panel_size;
 
+       HUD_Scale_Enable();
        HUD_Panel_DrawBg(1);
        if(panel_bg_padding)
        {
index 8199bd8dd6d82f10dfb9a031f3feea8266e63a02..2f072b2b55489f6c2fe803c825df0628b1ccf483 100644 (file)
@@ -23,6 +23,7 @@ void HUD_InfoMessages()
        pos = panel_pos;
        mySize = panel_size;
 
+       HUD_Scale_Enable();
        HUD_Panel_DrawBg(1);
        if(panel_bg_padding)
        {
index fbc98e0a5a03cd1e0f0eca7dd1b93d22ae60ddca..479c594db56e5ad07b5b9187df84c9568f7f05c7 100644 (file)
@@ -766,6 +766,7 @@ void HUD_ModIcons()
        else
                mod_alpha = bound(0, 1 - (time - mod_change) * 2, 1);
 
+       HUD_Scale_Enable();
        if(mod_alpha)
                HUD_Panel_DrawBg(mod_alpha);
 
index 1f0e26b9a5e7274f8559ab7c402e6d619519e478..720b7aeda561c0488f327daa24a7c9951e1e7694 100644 (file)
@@ -48,6 +48,7 @@ void HUD_Notify()
                        return;
 
        HUD_Panel_UpdateCvars();
+       HUD_Scale_Enable();
        HUD_Panel_DrawBg(1);
 
        if (!autocvar__hud_configure)
index 7a9f664eb233d89a9342d8838fb7f934f6a13299..741c305b41af7552bb6b86caa4e9007b32ea69a8 100644 (file)
@@ -21,6 +21,7 @@ void HUD_Physics()
 
        draw_beginBoldFont();
 
+       HUD_Scale_Enable();
        HUD_Panel_DrawBg(1);
        if(panel_bg_padding)
        {
index 31a00794e3ed7977c2eb4bb04480831a2791191b..8abe1fc5a1b576cadca6222440772092320a0114 100644 (file)
@@ -109,6 +109,7 @@ void HUD_Powerups()
 
        // Draw panel background
        HUD_Panel_UpdateCvars();
+       HUD_Scale_Enable();
        HUD_Panel_DrawBg(1);
 
        // Set drawing area
index 3b512b1c33a622107fe73b558e32f8f425dd3a53..9989c4fc847dfb740281c798eb229dac5aa24b7d 100644 (file)
@@ -13,6 +13,7 @@ void HUD_PressedKeys()
        pos = panel_pos;
        mySize = panel_size;
 
+       HUD_Scale_Enable();
        HUD_Panel_DrawBg(1);
        if(panel_bg_padding)
        {
index 7a9f90f9af51c24fbf6ff3de4f77d6a8184ff43d..449b1682cadd1faa7ea7945cb01be57b31a6e0eb 100644 (file)
@@ -18,6 +18,7 @@ void HUD_RaceTimer ()
        pos = panel_pos;
        mySize = panel_size;
 
+       HUD_Scale_Enable();
        HUD_Panel_DrawBg(1);
        if(panel_bg_padding)
        {
index 4a2e7ee2b345165afc75e18399b9c1de8147ab2f..925050df1cca9c66dc533dd72be5930585979e9b 100644 (file)
@@ -275,6 +275,7 @@ void HUD_Radar()
        pos = panel_pos;
        mySize = panel_size;
 
+       HUD_Scale_Enable();
        HUD_Panel_DrawBg(1);
        if(panel_bg_padding)
        {
@@ -285,7 +286,7 @@ void HUD_Radar()
        int color2;
        float scale2d, normalsize, bigsize;
 
-       teamradar_origin2d = pos + 0.5 * mySize;
+       teamradar_origin2d = HUD_Shift(pos + 0.5 * mySize);
        teamradar_size2d = mySize;
 
        if(minimapname == "")
@@ -294,7 +295,7 @@ void HUD_Radar()
        teamradar_loadcvars();
 
        scale2d = vlen_maxnorm2d(mi_picmax - mi_picmin);
-       teamradar_size2d = mySize;
+       teamradar_size2d = HUD_Scale(mySize);
 
        teamradar_extraclip_mins = teamradar_extraclip_maxs = '0 0 0'; // we always center
 
index 12114b4e356a712d8306439c8df0708da753eb3a..d65b2c2a2205c7372b4aa903f172adc8e3d5b395 100644 (file)
@@ -144,6 +144,7 @@ void HUD_Score()
        pos = panel_pos;
        mySize = panel_size;
 
+       HUD_Scale_Enable();
        HUD_Panel_DrawBg(1);
        if(panel_bg_padding)
        {
index b61f3c4c177ff2b8bafa7d280167dac7b898548d..59702304f8e2e8eccadf5fdc172e447e3b1c9fa6 100644 (file)
@@ -14,6 +14,7 @@ void HUD_Timer()
        pos = panel_pos;
        mySize = panel_size;
 
+       HUD_Scale_Enable();
        HUD_Panel_DrawBg(1);
        if(panel_bg_padding)
        {
index 502b237f7882efdb22662e33398b63890b3037f1..8968a6f349484bcb64c3f7d689e54f4d1958e094 100644 (file)
@@ -69,6 +69,7 @@ void HUD_Vote()
        mySize = panel_size;
 
        a = vote_alpha * (vote_highlighted ? autocvar_hud_panel_vote_alreadyvoted_alpha : 1);
+       HUD_Scale_Enable();
        HUD_Panel_DrawBg(a);
        a = panel_fg_alpha * a;
 
index c465caf4fddc3911ca2e997adaead177a2f6fa40..2caa86463ff342713b31ee8d2f2124b593b053aa 100644 (file)
@@ -282,6 +282,7 @@ void HUD_Weapons()
        }
 
        // draw the background, then change the virtual size of it to better fit other items inside
+       HUD_Scale_Enable();
        HUD_Panel_DrawBg(1);
 
        if(center.x == -1)
index 3223bf120aa7cc012f9143e21bc671f12ee9031b..caa3db8f39cff5f380253810bbecf310bc4d1c62 100644 (file)
@@ -442,6 +442,7 @@ void MapVote_Draw()
        panel_pos.y = pos.y;
        panel_size.x = xmax - xmin;
        panel_size.y = ymax - ymin;
+       HUD_Scale_Disable();
        HUD_Panel_DrawBg(1);
 
        if(panel_bg_padding)
index 970a681e37b202f9bfc2a49c6f2c6377b0a13715..8c0bf14ea432a2c120f9f6bbb80a8ab381875436 100644 (file)
@@ -224,6 +224,10 @@ void drawborderlines(float thickness, vector pos, vector dim, vector color, floa
 
 void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float theAlpha, float drawflag)
 {
+       pos = HUD_Shift(pos);
+       sz = HUD_Scale(sz);
+       area = HUD_Scale(area);
+
        vector current_pos = '0 0 0', end_pos, new_size = '0 0 0', ratio = '0 0 0';
        end_pos = pos + area;
 
@@ -258,6 +262,43 @@ void drawpic_aspect_skin_expanding_two(vector position, string pic, vector theSc
        drawpic_skin(position, pic, theScale, rgb, theAlpha * fadelerp, flag);
 }
 
+void HUD_Scale_Disable()
+{
+       hud_scale = '1 1 0';
+       hud_shift = '0 0 0';
+       drawfontscale = hud_scale;
+}
+
+void HUD_Scale_Enable()
+{
+       hud_scale = hud_scale_current;
+       hud_shift = hud_shift_current;
+       drawfontscale = hud_scale;
+}
+
+vector HUD_Scale(vector v)
+{
+       v.x = HUD_ScaleX(v.x);
+       v.y = HUD_ScaleY(v.y);
+       return v;
+}
+
+vector HUD_Shift(vector v)
+{
+       v.x = HUD_ShiftX(v.x);
+       v.y = HUD_ShiftY(v.y);
+       return v;
+}
+
+float stringwidth(string text, float handleColors, vector sz)
+{
+       vector dfs = drawfontscale;
+       drawfontscale = '1 1 0';
+       float r = stringwidth_builtin(text, handleColors, sz);
+       drawfontscale = dfs;
+       return r;
+}
+
 // 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 theAlpha, float drawflag) {
        SET_POS_AND_SZ_Y_ASPECT(false);
@@ -275,12 +316,16 @@ void drawstring_expanding(vector position, string text, vector theScale, vector
        float sz;
        sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
 
+       drawfontscale = hud_scale * sz;
+       vector dfs = drawfontscale;
        drawfontscale = sz * '1 1 0';
-       drawstring(position + expandingbox_resize_centered_box_offset(sz, theScale, stringwidth(text, false, theScale * (sz / drawfontscale.x)) / (theScale.x * sz)), text, theScale * (sz / drawfontscale.x), rgb, theAlpha * (1 - fadelerp), flag);
+       float textaspect = stringwidth_builtin(text, false, theScale * (sz / drawfontscale.x)) / (theScale.x * sz);
+       drawfontscale = dfs;
+       drawstring(position + expandingbox_resize_centered_box_offset(sz, theScale, textaspect), text, HUD_Scale(theScale * (sz / drawfontscale.x)), rgb, theAlpha * (1 - fadelerp), flag);
        // width parameter:
-       //    (scale_x * sz / drawfontscale_x) * drawfontscale_x * SIZE1 / (scale_x * sz)
+       //    (scale_x * sz / drawfontscale.x) * drawfontscale.x * SIZE1 / (scale_x * sz)
        //    SIZE1
-       drawfontscale = '1 1 0';
+       drawfontscale = hud_scale;
 }
 
 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
@@ -294,9 +339,10 @@ void drawcolorcodedstring_expanding(vector position, string text, vector theScal
        float sz;
        sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
 
-       drawfontscale = sz * '1 1 0';
-       drawcolorcodedstring(position + expandingbox_resize_centered_box_offset(sz, theScale, stringwidth(text, true, theScale * (sz / drawfontscale.x)) / (theScale.x * sz)), text, theScale * (sz / drawfontscale.x), theAlpha * (1 - fadelerp), flag);
-       drawfontscale = '1 1 0';
+       drawfontscale = hud_scale * sz;
+       // eventually replace with drawcolorcodedstring
+       drawcolorcodedstring(position + expandingbox_resize_centered_box_offset(sz, theScale, stringwidth_builtin(text, true, theScale * (sz / drawfontscale.x)) / (theScale.x * sz)), text, theScale * (sz / drawfontscale.x), theAlpha * (1 - fadelerp), flag);
+       drawfontscale = hud_scale;
 }
 
 void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float theAlpha, float drawflag, float fadelerp) {
index 32563598b3f79ad2189aa2f2b48d54c9ea0e3b24..f0a259e0ce696c56fddc1e0de331de7b61dd8a56 100644 (file)
@@ -44,6 +44,7 @@ float cvar_or(string cv, float v);
 
 vector project_3d_to_2d(vector vec);
 
+vector drawfontscale;
 #define draw_beginBoldFont()    MACRO_BEGIN { drawfont = FONT_USER + 2; } MACRO_END
 #define draw_endBoldFont()      MACRO_BEGIN { drawfont = FONT_USER + 1; } MACRO_END
 
@@ -55,6 +56,47 @@ void drawborderlines(float thickness, vector pos, vector dim, vector color, floa
 
 void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float theAlpha, float drawflag);
 
+void HUD_Scale_Disable();
+void HUD_Scale_Enable();
+
+#define HUD_ScaleX(f) (f * hud_scale.x)
+#define HUD_ScaleY(f) (f * hud_scale.y)
+#define HUD_ShiftX(f) (f + hud_shift.x + hud_shift.z * (f - hud_scale_center.x))
+#define HUD_ShiftY(f) (f + hud_shift.y + hud_shift.z * (f - hud_scale_center.y))
+vector HUD_Scale(vector v);
+vector HUD_Shift(vector v);
+
+// call draw*_builtin (and stringwidth_builtin) functions only when
+// pos and size don't have to be scaled by the hud_dynamic code
+// (typically outside the real HUD code)
+
+// NOTE: drawsubpic usually gets called multiple times within an utility function
+// so instead of remapping it, scaling pos and size in every call,
+// we prefer to scale pos and size once for all in the utility function
+
+float stringwidth(string text, float handleColors, vector sz);
+
+#define drawpic(position, pic, size, rgb, alpha, flag) \
+       drawpic_builtin(HUD_Shift(position), pic, HUD_Scale(size), rgb, alpha, flag)
+
+#define drawcharacter(position, character, scale, rgb, alpha, flag) \
+       drawcharacter_builtin(HUD_Shift(position), text, scale, rgb, alpha, flag)
+
+#define drawstring(position, text, scale, rgb, alpha, flag) \
+       drawstring_builtin(HUD_Shift(position), text, scale, rgb, alpha, flag)
+
+#define drawcolorcodedstring(position, text, scale, alpha, flag) \
+       drawcolorcodedstring_builtin(HUD_Shift(position), text, scale, alpha, flag)
+
+#define drawcolorcodedstring2(position, text, scale, rgb, alpha, flag) \
+       drawcolorcodedstring2_builtin(HUD_Shift(position), text, scale, rgb, alpha, flag)
+
+#define drawfill(position, size, rgb, alpha, flag) \
+       drawfill_builtin(HUD_Shift(position), HUD_Scale(size), rgb, alpha, flag)
+
+#define drawsetcliparea(xposition, yposition, w, h) \
+       drawsetcliparea_builtin(HUD_ShiftX(xposition), HUD_ShiftY(yposition), HUD_ScaleX(w), HUD_ScaleY(h))
+
 // drawpic wrapper to draw an image as large as possible with preserved aspect ratio into a box
 float _drawpic_imgaspect;
 vector _drawpic_imgsize;
@@ -109,7 +151,10 @@ void drawpic_aspect_skin_expanding_two(vector position, string pic, vector theSc
 
 #define SET_POS_AND_SZ_Y_ASPECT(allow_colors) MACRO_BEGIN {                                                                                                                    \
        float textaspect, oldsz;                                                                                                                                                                                \
+       vector dfs = drawfontscale; \
+       drawfontscale = '1 1 0'; \
        textaspect = stringwidth(text, allow_colors, '1 1 1' * sz.y) / sz.y;                                                                                    \
+       drawfontscale = dfs; \
        if(sz.x/sz.y > textaspect) {                                                                                                                                                                    \
                oldsz = sz.x;                                                                                                                                                                                           \
                sz.x = sz.y * textaspect;                                                                                                                                                                       \
@@ -127,7 +172,6 @@ void drawstring_aspect(vector pos, string text, vector sz, vector color, float t
 // drawstring wrapper to draw a colorcodedstring as large as possible with preserved aspect ratio into a box
 void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag);
 
-vector drawfontscale;
 void drawstring_expanding(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp);
 
 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
index 6d281aa6b6a578b919efacc0d262534d61f95e99..8f44529e38f794f4f0e8e98f12ded666197e7756 100644 (file)
@@ -620,6 +620,7 @@ void HUD_QuickMenu()
 
        HUD_Panel_UpdateCvars();
 
+       HUD_Scale_Enable();
        HUD_Panel_DrawBg(1);
 
        if(panel_bg_padding)
index 01388fdd2ff7ad69609cc6f00ea671df7df98724..a8708f2460f809a579f96db0428fbc1522432c61 100644 (file)
@@ -128,7 +128,7 @@ void draw_teamradar_player(vector coord3d, vector pangles, vector rgb)
 void draw_teamradar_icon(vector coord, entity icon, entity pingdata, vector rgb, float a)
 {
        coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(coord));
-       drawpic(coord - '4 4 0', strcat("gfx/teamradar_icon_", ftos(icon.m_radaricon)), '8 8 0', rgb, a, 0);
+       drawpic_builtin(coord - '4 4 0', strcat("gfx/teamradar_icon_", ftos(icon.m_radaricon)), '8 8 0', rgb, a, 0);
 
        if(pingdata)
        {
@@ -141,7 +141,7 @@ void draw_teamradar_icon(vector coord, entity icon, entity pingdata, vector rgb,
                        if(dt >= 1 || dt <= 0)
                                continue;
                        vector v = '2 2 0' * teamradar_size * dt;
-                       drawpic(coord - 0.5 * v, "gfx/teamradar_ping", v, '1 1 1', (1 - dt) * a, DRAWFLAG_ADDITIVE);
+                       drawpic_builtin(coord - 0.5 * v, "gfx/teamradar_ping", v, '1 1 1', (1 - dt) * a, DRAWFLAG_ADDITIVE);
                }
        }
 }
index 8aeac192633cdf5a84ef341f308a3dd221f65064..b9730407ddc6339a9eced9fdedc6c6dad5686685 100644 (file)
@@ -1340,6 +1340,7 @@ void HUD_Draw()
 
                        HUD_Main();
                        HUD_DrawScoreboard();
+                       HUD_Scale_Disable();
                }
 
        // crosshair goes VERY LAST
@@ -1382,6 +1383,8 @@ void CSQC_UpdateView(float w, float h)
 
        lasthud = hud;
 
+       HUD_Scale_Disable();
+
        if(autocvar__hud_showbinds_reload) // menu can set this one
        {
                db_close(binddb);
index 40b2b3547ef16116994ef2ce879f0a497fa6125d..9aca8e774c34a669cf3439f6656914c703b7a0a3 100644 (file)
@@ -142,7 +142,7 @@ bool autocvar_debugdraw;
                                if (pos.z < 0) continue;
                                pos.z = 0;
                                pos.y += ofs * sz;
-                               drawcolorcodedstring2(pos,
+                               drawcolorcodedstring2_builtin(pos,
                                        sprintf("%d: '%s'@%s", (it.debug ? it.sv_entnum : etof(it)),
                                        it.classname, it.sourceLoc),
                                        sz * '1 1 0', rgb, 0.5, DRAWFLAG_NORMAL);
index dfe918feca56d97da3c6479b54227ac96eafb5c7..a61d8bfbc6519da43388cb66c9f49fe041de1383 100644 (file)
@@ -476,6 +476,7 @@ void HUD_MinigameMenu ()
 
        HUD_Panel_UpdateCvars();
 
+       HUD_Scale_Disable();
        HUD_Panel_DrawBg(1);
 
        if(panel_bg_padding)
index 84120e1b04ad100bd6d148ed9ee2a810205929b7..4610c306ac62e5a5d9648f2db7d9b77885d4f29e 100644 (file)
@@ -828,6 +828,7 @@ void bd_hud_board(vector pos, vector mySize)
 // Required function, draw the game status panel
 void bd_hud_status(vector pos, vector mySize)
 {
+       HUD_Scale_Disable();
        HUD_Panel_DrawBg(1);
        vector ts;
        ts = minigame_drawstring_wrapped(mySize_x,pos,active_minigame.descriptor.message,
index 9b9d570855b490d8ac01d737cfb2114329656fe7..76770cefe29c1e5fc545698dfd796530c6381c00 100644 (file)
@@ -322,6 +322,7 @@ void c4_hud_board(vector pos, vector mySize)
 // Required function, draw the game status panel
 void c4_hud_status(vector pos, vector mySize)
 {
+       HUD_Scale_Disable();
        HUD_Panel_DrawBg(1);
        vector ts;
        ts = minigame_drawstring_wrapped(mySize_x,pos,active_minigame.descriptor.message,
index e4e0dc6380d9aec56a1b05601a8f5d733fe1b9c5..f7da8f8e74f4577b4cf28c216dc9d5b3f6df8814 100644 (file)
@@ -496,6 +496,7 @@ void nmm_hud_board(vector pos, vector mySize)
 // Required function, draw the game status panel
 void nmm_hud_status(vector pos, vector mySize)
 {
+       HUD_Scale_Disable();
        HUD_Panel_DrawBg(1);
        vector ts;
 
index 87c75f48c59ab05ac3b9ce01d4c628ccb66a3580..053cadc4e00d173f38d8874520ea91a40c1dabbf 100644 (file)
@@ -542,6 +542,7 @@ void pong_hud_board(vector pos, vector mySize)
 // Required function, draw the game status panel
 void pong_hud_status(vector pos, vector mySize)
 {
+       HUD_Scale_Disable();
        HUD_Panel_DrawBg(1);
        vector ts;
        ts = minigame_drawstring_wrapped(mySize_x,pos,active_minigame.descriptor.message,
index a66a839677d9ceed95f9e62bdeaea3d72ddf5c34..24c61c01000e4f93cfa34f269847657d5c295858 100644 (file)
@@ -374,6 +374,7 @@ void pp_hud_board(vector pos, vector mySize)
 // Required function, draw the game status panel
 void pp_hud_status(vector pos, vector mySize)
 {
+       HUD_Scale_Disable();
        HUD_Panel_DrawBg(1);
        vector ts;
        ts = minigame_drawstring_wrapped(mySize_x,pos,active_minigame.descriptor.message,
index 4eb0009b9db2ae5383906e7772270a85cc1258bf..58df41415f83aecba18f2a78ff31b0e921cb284e 100644 (file)
@@ -429,6 +429,7 @@ void ps_hud_board(vector pos, vector mySize)
 // Required function, draw the game status panel
 void ps_hud_status(vector pos, vector mySize)
 {
+       HUD_Scale_Disable();
        HUD_Panel_DrawBg(1);
        vector ts;
        ts = minigame_drawstring_wrapped(mySize_x,pos,active_minigame.descriptor.message,
index d367472d8214f1a4296e4bbf3dcce47802c06e00..dafa14fa3141c56933c34876acee129f94fb3c74 100644 (file)
@@ -674,6 +674,7 @@ void snake_hud_board(vector pos, vector mySize)
 // Required function, draw the game status panel
 void snake_hud_status(vector pos, vector mySize)
 {
+       HUD_Scale_Disable();
        HUD_Panel_DrawBg(1);
        vector ts;
        ts = minigame_drawstring_wrapped(mySize_x,pos,active_minigame.descriptor.message,
index cd9565abd54ce2bf401b9459f33afa4ad4a25dd3..7e2ed7e088172b67624e99349278a1e2ea0ae9db 100644 (file)
@@ -272,6 +272,7 @@ void ttt_hud_board(vector pos, vector mySize)
 // Required function, draw the game status panel
 void ttt_hud_status(vector pos, vector mySize)
 {
+       HUD_Scale_Disable();
        HUD_Panel_DrawBg(1);
        vector ts;
        ts = minigame_drawstring_wrapped(mySize_x,pos,active_minigame.descriptor.message,
index 0b44b7346ea73328d8db3067becf0f7078bb3fe4..8ca049133ddab698698af55c8842ed050f2174a3 100644 (file)
@@ -58,7 +58,7 @@ CLASS(DamageText, Object)
             s = strreplace("{health}", sprintf("%d", this.m_damage), s);
             s = strreplace("{armor}",  sprintf("%d", this.m_armordamage), s);
             s = strreplace("{total}",  sprintf("%d", this.m_damage + this.m_armordamage), s);
-            drawcolorcodedstring2(pos, s, this.m_size * '1 1 0', rgb, this.alpha, DRAWFLAG_NORMAL);
+            drawcolorcodedstring2_builtin(pos, s, this.m_size * '1 1 0', rgb, this.alpha, DRAWFLAG_NORMAL);
         }
     }
     ATTRIB(DamageText, draw2d, void(DamageText), DamageText_draw2d)
index 6c7eb4d76f0f42d01a5dd25fd2c1a264e05c2ada..34e6e3275a69b75a904f94bae1fc7f47b3650ac3 100644 (file)
@@ -357,6 +357,7 @@ void HUD_ItemsTime()
         }
     }
 
+    HUD_Scale_Enable();
     HUD_Panel_DrawBg(1);
 
     float row = 0, column = 0;
index 21b7c5433b15224b67846b6c44ebe20bf997da34..3748b8df79cd47ddf5eb9150d705ff0186f0d3a9 100644 (file)
@@ -476,14 +476,14 @@ string(string name, ...) precache_pic = #317;
 string(string name) precache_cubemap = #317;
 vector(string picname) draw_getimagesize = #318;
 void(string name) freepic = #319;
-float(vector position, float character, vector scale, vector rgb, float alpha, float flag) drawcharacter = #320;
-float(vector position, string text, vector scale, vector rgb, float alpha, float flag) drawstring = #321;
-float(vector position, string pic, vector size, vector rgb, float alpha, float flag) drawpic = #322;
-float(vector position, vector size, vector rgb, float alpha, float flag) drawfill = #323;
-void(float x, float y, float width, float height) drawsetcliparea = #324;
+float(vector position, float character, vector scale, vector rgb, float alpha, float flag) drawcharacter_builtin = #320;
+float(vector position, string text, vector scale, vector rgb, float alpha, float flag) drawstring_builtin = #321;
+float(vector position, string pic, vector size, vector rgb, float alpha, float flag) drawpic_builtin = #322;
+float(vector position, vector size, vector rgb, float alpha, float flag) drawfill_builtin = #323;
+void(float x, float y, float width, float height) drawsetcliparea_builtin = #324;
 void(void) drawresetcliparea = #325;
-float(vector position, string text, vector scale, float alpha, float flag) drawcolorcodedstring = #326;
-vector(vector position, string text, vector scale, vector rgb, float alpha, float flag) drawcolorcodedstring2 = #326;
+float(vector position, string text, vector scale, float alpha, float flag) drawcolorcodedstring_builtin = #326;
+vector(vector position, string text, vector scale, vector rgb, float alpha, float flag) drawcolorcodedstring2_builtin = #326;
 
 float(float stnum) getstatf = #330;
 float(float stnum, ...) getstati = #331; // can optionally take first bit and count
@@ -846,7 +846,7 @@ float loadfont(string fontname, string fontmaps, string sizes, float slot, float
 // fix_* parms let you fix badly made fonts by applying some transformations to them
 // fix_scale : per-character center-oriented scale (doesn't change line height at all)
 // fix_voffset : vertical offset for each character, it's a multiplier to character height
-float stringwidth(string text, float allowColorCodes, vector size) = #327; // get a width of string with given font and char size
+float stringwidth_builtin(string text, float allowColorCodes, vector size) = #327; // get a width of string with given font and char size
 float stringwidth_menu(string text, float allowColorCodes, vector size) = #468; // in menu.dat it has different builtin #
 //description: engine support for custom fonts in console, hud, qc etc.
 // limits:
index c8d9ae8de9b4dedee783b3ac3d4f0e531cef9286..698c9262370974781c1f0585caaba18103d19ff7 100644 (file)
@@ -46,7 +46,7 @@
        {
                if (theBorderSize.x < 0 && theBorderSize.y < 0)  // draw whole image as it is
                {
-                       drawpic(theOrigin, pic, theSize, theColor, theAlpha, 0);
+                       drawpic_builtin(theOrigin, pic, theSize, theColor, theAlpha, 0);
                        return;
                }
                if (theBorderSize.x == 0 && theBorderSize.y == 0)  // no border
        void drawstringright(vector position, string text, vector theScale, vector rgb, float theAlpha, int flag)
        {
                position.x -= 2 / 3 * strlen(text) * theScale.x;
-               drawstring(position, text, theScale, rgb, theAlpha, flag);
+               drawstring_builtin(position, text, theScale, rgb, theAlpha, flag);
        }
 
        void drawstringcenter(vector position, string text, vector theScale, vector rgb, float theAlpha, int flag)
        {
                position.x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * theScale.x);
-               drawstring(position, text, theScale, rgb, theAlpha, flag);
+               drawstring_builtin(position, text, theScale, rgb, theAlpha, flag);
        }
 
 #endif
index 47a8175cac598554b3f2965a7dfc83db5429d2f5..3e12af394f032c587cc310b151f8b977bffb67d2 100644 (file)
@@ -4,7 +4,18 @@
 #include "sort.qh"
 #include "oo.qh"
 
-#ifndef SVQC
+#ifdef CSQC
+       float stringwidth_colors(string s, vector theSize)
+       {
+               return stringwidth_builtin(s, true, theSize);
+       }
+
+       float stringwidth_nocolors(string s, vector theSize)
+       {
+               return stringwidth_builtin(s, false, theSize);
+       }
+#endif
+#ifdef MENUQC
        float stringwidth_colors(string s, vector theSize)
        {
                return stringwidth(s, true, theSize);