]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/miscfunctions.qc
remove a useless arg of drawstring_aspect, also implement drawcolorcodedstring_aspect
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / miscfunctions.qc
index 73419b9015ddff87eb7711bf8dd1abb2153cb0de..23f88868bcb5600a7decd1eaf03ae89b3efd57ef 100644 (file)
@@ -482,24 +482,63 @@ 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 = eX * stringwidth(text, FALSE, '1 1 1' * sz_y) + eY * 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 + eX * (oldsz_x - sz_x) * 0.5, text, '1 1 0' * sz_y, color, alpha, drawflag);
+       } else {
+               sz_y = sz_x / textaspect; 
+               drawstring(pos + eY * (oldsz_y - sz_y) * 0.5, text, '1 1 0' * sz_y, color, alpha, drawflag);
+       }
+}
+
+// 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 alpha, float drawflag) {
+       vector textsize;
+       textsize = eX * stringwidth(text, TRUE, '1 1 1' * sz_y) + eY * 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;
+               drawcolorcodedstring(pos + eX * (oldsz_x - sz_x) * 0.5, text, '1 1 0' * sz_y, alpha, drawflag);
+       } else {
+               sz_y = sz_x / textaspect; 
+               drawcolorcodedstring(pos + eY * (oldsz_y - sz_y) * 0.5, text, '1 1 0' * sz_y, alpha, drawflag);
+       }
+}
+
 vector drawfontscale;
 void drawstring_expanding(vector position, string text, vector scale, vector rgb, float alpha, float flag, float fadelerp)
 {
        float sz;
        sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
 
-       if(cvar("menu_font_size_snapping_fix"))
-               drawfontscale = sz * '1 1 0';
-       else
-               drawfontscale = '1 1 0';
+       drawfontscale = sz * '1 1 0';
        dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
         drawstring(position + expandingbox_resize_centered_box_offset(sz, scale, stringwidth(text, FALSE, scale * (sz / drawfontscale_x)) / (scale_x * sz)), text, scale * (sz / drawfontscale_x), rgb, alpha * (1 - fadelerp), flag);
        // width parameter:
        //    (scale_x * sz / drawfontscale_x) * drawfontscale_x * SIZE1 / (scale_x * sz)
        //    SIZE1
-
-       if(cvar("menu_font_size_snapping_fix"))
-               drawfontscale = '1 1 0';
+       drawfontscale = '1 1 0';
 }
 
 void drawcolorcodedstring_expanding(vector position, string text, vector scale, float alpha, float flag, float fadelerp)
@@ -507,15 +546,10 @@ void drawcolorcodedstring_expanding(vector position, string text, vector scale,
        float sz;
        sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
 
-       if(cvar("menu_font_size_snapping_fix"))
-               drawfontscale = sz * '1 1 0';
-       else
-               drawfontscale = '1 1 0';
+       drawfontscale = sz * '1 1 0';
        dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
        drawcolorcodedstring(position + expandingbox_resize_centered_box_offset(sz, scale, stringwidth(text, TRUE, scale * (sz / drawfontscale_x)) / (scale_x * sz)), text, scale * (sz / drawfontscale_x), alpha * (1 - fadelerp), flag);
-
-       if(cvar("menu_font_size_snapping_fix"))
-               drawfontscale = '1 1 0';
+       drawfontscale = '1 1 0';
 }
 
 // this draws the triangles of a model DIRECTLY. Don't expect high performance, really...