]> 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 a7af09c7c82a146fcc259558ae8c46e9bd789a2c..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);
@@ -427,12 +444,6 @@ void DrawCircleClippedPic(vector centre, float radi, string pic, float f, vector
        centre = HUD_Shift(centre);
        ringsize = HUD_Scale(ringsize);
 
-       float co = cos(f * 2 * M_PI);
-       float si = sin(f * 2 * M_PI);
-       float q = fabs(co) + fabs(si);
-       co /= q;
-       si /= q;
-
        if(f >= 1)
        {
                // draw full rectangle
@@ -455,7 +466,14 @@ void DrawCircleClippedPic(vector centre, float radi, string pic, float f, vector
                R_EndPolygon();
                return;  // Complete rectangle, nothing more needed.
        }
-       else if(f > 0.75)
+
+       float co = cos(f * 2 * M_PI);
+       float si = sin(f * 2 * M_PI);
+       float q = fabs(co) + fabs(si);
+       co /= q;
+       si /= q;
+
+       if(f > 0.75)
        {
                // draw upper half in full
                R_BeginPolygon(pic, drawflag, true);