]> 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 684224c710100cc64101425a1b3de9c6df0bcc41..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>
 
@@ -214,6 +214,28 @@ vector expandingbox_resize_centered_box_offset(float sz, vector boxsize, float b
        return boxsize * (0.5 * (1 - sz));
 }
 
+// NOTE base is the central value
+// freq: circle frequency, = 2*pi*frequency in hertz
+// start_pos:
+//  -1 start from the lower value
+//   0 start from the base value
+//   1 start from the higher value
+float blink_synced(float base, float range, float freq, float start_time, int start_pos)
+{
+       // note:
+       //   RMS = sqrt(base^2 + 0.5 * range^2)
+       // thus
+       //   base = sqrt(RMS^2 - 0.5 * range^2)
+       // ensure RMS == 1
+
+       return base + range * sin((time - start_time - (M_PI / 2) * start_pos) * freq);
+}
+
+float blink(float base, float range, float freq)
+{
+       return blink_synced(base, range, freq, 0, 0);
+}
+
 void drawborderlines(float thickness, vector pos, vector dim, vector color, float theAlpha, float drawflag)
 {
        vector line_dim = '0 0 0';
@@ -310,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);
@@ -405,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
@@ -433,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);