]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/miscfunctions.qc
Merge branch 'terencehill/cl_forceplayercolors_3' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / miscfunctions.qc
index 1af1b971ffe91272af6cfcb915c1de041cbf49a8..a653f4bf1e5ca0af486b06dd58d6f61aafd143a1 100644 (file)
@@ -1,8 +1,8 @@
 #include "miscfunctions.qh"
 
 #include "autocvars.qh"
-#include "defs.qh"
 #include "hud/_mod.qh"
+#include "main.qh"
 
 #include <common/command/_mod.qh>
 
@@ -332,6 +332,23 @@ float stringwidth(string text, float handleColors, vector sz)
        return r;
 }
 
+#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; \
+               pos.x += (oldsz - sz.x) * 0.5; \
+       } else { \
+               oldsz = sz.y; \
+               sz.y = sz.x / textaspect; \
+               pos.y += (oldsz - sz.y) * 0.5; \
+       } \
+MACRO_END
+
 // 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);