]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
drawcolorcodedstring: support full 6 parms (added starting rgb) and returns color...
authorvortex <vortex@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 7 Jan 2011 21:51:34 +0000 (21:51 +0000)
committervortex <vortex@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 7 Jan 2011 21:51:34 +0000 (21:51 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10694 d7cf8633-e32d-0410-b094-e92efae38249

dpdefs/csprogsdefs.qc
dpdefs/menudefs.qc
draw.h
gl_draw.c
prvm_cmds.c

index 60e15bec2d2574062dd51c738e6788cde37470d7..7ff4fcaddc85db1ac6c3daf82c2cc19e71b60522 100644 (file)
@@ -467,6 +467,7 @@ float(vector position, vector size, vector rgb, float alpha, float flag) drawfil
 void(float x, float y, float width, float height) drawsetcliparea = #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(float stnum) getstatf = #330;
 float(float stnum) getstati = #331;
index 4ae9ad3f3ae13c2d02d3573bddcf0ca47f97f3a6..5520844f473449e3cae9b4d579d3d3d3ce87877c 100644 (file)
@@ -406,6 +406,10 @@ float      drawcharacter(vector position, float character, vector scale, vector rgb,
 
 float  drawstring(vector position, string text, vector scale, vector rgb, float alpha, float flag) = #455;
 
+float  drawcolorcodedstring(vector position, string text, vector scale, float alpha, float flag) = #467;
+
+vector drawcolorcodedstring2(vector position, string text, vector scale, vector rgb, float alpha, float flag) = #467;
 float  drawpic(vector position, string pic, vector size, vector rgb, float alpha, float flag) = #456;
 
 float  drawfill(vector position, vector size, vector rgb, float alpha, float flag) = #457;
diff --git a/draw.h b/draw.h
index d2ea5daf40a79082d892ece761328abdcbdb72ae..7c3b6543766a46ad26c9d40a84b11f087587312f 100644 (file)
--- a/draw.h
+++ b/draw.h
@@ -162,6 +162,7 @@ void DrawQ_Fill(float x, float y, float width, float height, float red, float gr
 // if outcolor is provided the initial color is read from it, and it is updated at the end with the new value at the end of the text (not at the end of the clipped part)
 // the color is tinted by the provided base color
 // if r_textshadow is not zero, an additional instance of the text is drawn first at an offset with an inverted shade of gray (black text produces a white shadow, brightly colored text produces a black shadow)
+extern float DrawQ_Color[4];
 float DrawQ_String(float x, float y, const char *text, size_t maxlen, float scalex, float scaley, float basered, float basegreen, float baseblue, float basealpha, int flags, int *outcolor, qboolean ignorecolorcodes, const dp_font_t *fnt);
 float DrawQ_String_Scale(float x, float y, const char *text, size_t maxlen, float sizex, float sizey, float scalex, float scaley, float basered, float basegreen, float baseblue, float basealpha, int flags, int *outcolor, qboolean ignorecolorcodes, const dp_font_t *fnt);
 float DrawQ_TextWidth(const char *text, size_t maxlen, float w, float h, qboolean ignorecolorcodes, const dp_font_t *fnt);
index 32d736fa84c7bf4f06352647a7ff4d0b1acaed84..04d3eb8d92057d44658cc2268af35553425b1350 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -1448,13 +1448,13 @@ float DrawQ_TextWidth_UntilWidth_TrackColors_Scale(const char *text, size_t *max
        return x;
 }
 
+float DrawQ_Color[4];
 float DrawQ_String_Scale(float startx, float starty, const char *text, size_t maxlen, float w, float h, float sw, float sh, float basered, float basegreen, float baseblue, float basealpha, int flags, int *outcolor, qboolean ignorecolorcodes, const dp_font_t *fnt)
 {
        int shadow, colorindex = STRING_COLOR_DEFAULT;
        size_t i;
        float x = startx, y, s, t, u, v, thisw;
        float *av, *at, *ac;
-       float color[4];
        int batchcount;
        static float vertex3f[QUADELEMENTS_MAXQUADS*4*3];
        static float texcoord2f[QUADELEMENTS_MAXQUADS*4*2];
@@ -1549,7 +1549,7 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
                else
                        colorindex = *outcolor;
 
-               DrawQ_GetTextColor(color, colorindex, basered, basegreen, baseblue, basealpha, shadow != 0);
+               DrawQ_GetTextColor(DrawQ_Color, colorindex, basered, basegreen, baseblue, basealpha, shadow != 0);
 
                x = startx;
                y = starty;
@@ -1577,7 +1577,7 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
                                if (ch <= '9' && ch >= '0') // ^[0-9] found
                                {
                                        colorindex = ch - '0';
-                                       DrawQ_GetTextColor(color, colorindex, basered, basegreen, baseblue, basealpha, shadow != 0);
+                                       DrawQ_GetTextColor(DrawQ_Color, colorindex, basered, basegreen, baseblue, basealpha, shadow != 0);
                                        ++text;
                                        ++i;
                                        continue;
@@ -1607,7 +1607,7 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
                                                                colorindex = tempcolorindex | 0xf;
                                                                // ...done! now colorindex has rgba codes (1,rrrr,gggg,bbbb,aaaa)
                                                                //Con_Printf("^1colorindex:^7 %x\n", colorindex);
-                                                               DrawQ_GetTextColor(color, colorindex, basered, basegreen, baseblue, basealpha, shadow != 0);
+                                                               DrawQ_GetTextColor(DrawQ_Color, colorindex, basered, basegreen, baseblue, basealpha, shadow != 0);
                                                                i+=4;
                                                                text+=4;
                                                                continue;
@@ -1665,10 +1665,10 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
                                t = (ch >> 4)*0.0625f + (0.5f / th);
                                u = 0.0625f * thisw - (1.0f / tw);
                                v = 0.0625f - (1.0f / th);
-                               ac[ 0] = color[0];ac[ 1] = color[1];ac[ 2] = color[2];ac[ 3] = color[3];
-                               ac[ 4] = color[0];ac[ 5] = color[1];ac[ 6] = color[2];ac[ 7] = color[3];
-                               ac[ 8] = color[0];ac[ 9] = color[1];ac[10] = color[2];ac[11] = color[3];
-                               ac[12] = color[0];ac[13] = color[1];ac[14] = color[2];ac[15] = color[3];
+                               ac[ 0] = DrawQ_Color[0];ac[ 1] = DrawQ_Color[1];ac[ 2] = DrawQ_Color[2];ac[ 3] = DrawQ_Color[3];
+                               ac[ 4] = DrawQ_Color[0];ac[ 5] = DrawQ_Color[1];ac[ 6] = DrawQ_Color[2];ac[ 7] = DrawQ_Color[3];
+                               ac[ 8] = DrawQ_Color[0];ac[ 9] = DrawQ_Color[1];ac[10] = DrawQ_Color[2];ac[11] = DrawQ_Color[3];
+                               ac[12] = DrawQ_Color[0];ac[13] = DrawQ_Color[1];ac[14] = DrawQ_Color[2];ac[15] = DrawQ_Color[3];
                                at[ 0] = s              ; at[ 1] = t    ;
                                at[ 2] = s+u    ; at[ 3] = t    ;
                                at[ 4] = s+u    ; at[ 5] = t+v  ;
@@ -1736,10 +1736,10 @@ float DrawQ_String_Scale(float startx, float starty, const char *text, size_t ma
                                }
                                else
                                        kx = ky = 0;
-                               ac[ 0] = color[0]; ac[ 1] = color[1]; ac[ 2] = color[2]; ac[ 3] = color[3];
-                               ac[ 4] = color[0]; ac[ 5] = color[1]; ac[ 6] = color[2]; ac[ 7] = color[3];
-                               ac[ 8] = color[0]; ac[ 9] = color[1]; ac[10] = color[2]; ac[11] = color[3];
-                               ac[12] = color[0]; ac[13] = color[1]; ac[14] = color[2]; ac[15] = color[3];
+                               ac[ 0] = DrawQ_Color[0]; ac[ 1] = DrawQ_Color[1]; ac[ 2] = DrawQ_Color[2]; ac[ 3] = DrawQ_Color[3];
+                               ac[ 4] = DrawQ_Color[0]; ac[ 5] = DrawQ_Color[1]; ac[ 6] = DrawQ_Color[2]; ac[ 7] = DrawQ_Color[3];
+                               ac[ 8] = DrawQ_Color[0]; ac[ 9] = DrawQ_Color[1]; ac[10] = DrawQ_Color[2]; ac[11] = DrawQ_Color[3];
+                               ac[12] = DrawQ_Color[0]; ac[13] = DrawQ_Color[1]; ac[14] = DrawQ_Color[2]; ac[15] = DrawQ_Color[3];
                                at[0] = map->glyphs[mapch].txmin; at[1] = map->glyphs[mapch].tymin;
                                at[2] = map->glyphs[mapch].txmax; at[3] = map->glyphs[mapch].tymin;
                                at[4] = map->glyphs[mapch].txmax; at[5] = map->glyphs[mapch].tymax;
@@ -1785,7 +1785,7 @@ out:
 
        if (outcolor)
                *outcolor = colorindex;
-
+       
        // note: this relies on the proper text (not shadow) being drawn last
        return x;
 }
index 2630a9db30ee0d462f1ba409346d36517a8f94de..f4a10b6741e0f4a9a08a4080780b93cdb25c0532 100644 (file)
@@ -3385,22 +3385,42 @@ void VM_drawstring(void)
 VM_drawcolorcodedstring
 
 float  drawcolorcodedstring(vector position, string text, vector scale, float alpha, float flag)
+/
+float  drawcolorcodedstring(vector position, string text, vector scale, vector rgb, float alpha, float flag)
 =========
 */
 void VM_drawcolorcodedstring(void)
 {
-       float *pos,*scale;
+       float *pos, *scale;
        const char  *string;
        int flag;
-       float sx, sy;
-       VM_SAFEPARMCOUNT(5,VM_drawstring);
+       vec3_t rgb;
+       float sx, sy, alpha;
 
-       string = PRVM_G_STRING(OFS_PARM1);
-       pos = PRVM_G_VECTOR(OFS_PARM0);
-       scale = PRVM_G_VECTOR(OFS_PARM2);
-       flag = (int)PRVM_G_FLOAT(OFS_PARM4);
+       VM_SAFEPARMCOUNTRANGE(5,6,VM_drawcolorcodedstring);
 
-       if(flag < DRAWFLAG_NORMAL || flag >=DRAWFLAG_NUMFLAGS)
+       if (prog->argc == 6) // full 6 parms, like normal drawstring
+       {
+               pos = PRVM_G_VECTOR(OFS_PARM0);
+               string = PRVM_G_STRING(OFS_PARM1);
+               scale = PRVM_G_VECTOR(OFS_PARM2);
+               VectorCopy(PRVM_G_VECTOR(OFS_PARM3), rgb); 
+               alpha = PRVM_G_FLOAT(OFS_PARM4);
+               flag = (int)PRVM_G_FLOAT(OFS_PARM5);
+       }
+       else
+       {
+               pos = PRVM_G_VECTOR(OFS_PARM0);
+               string = PRVM_G_STRING(OFS_PARM1);
+               scale = PRVM_G_VECTOR(OFS_PARM2);
+               rgb[0] = 1.0;
+               rgb[1] = 1.0;
+               rgb[2] = 1.0;
+               alpha = PRVM_G_FLOAT(OFS_PARM3);
+               flag = (int)PRVM_G_FLOAT(OFS_PARM4);
+       }
+
+       if(flag < DRAWFLAG_NORMAL || flag >= DRAWFLAG_NUMFLAGS)
        {
                PRVM_G_FLOAT(OFS_RETURN) = -2;
                VM_Warning("VM_drawcolorcodedstring: %s: wrong DRAWFLAG %i !\n",PRVM_NAME,flag);
@@ -3418,8 +3438,11 @@ void VM_drawcolorcodedstring(void)
                Con_Printf("VM_drawcolorcodedstring: z value%s from %s discarded\n",(pos[2] && scale[2]) ? "s" : " ",((pos[2] && scale[2]) ? "pos and scale" : (pos[2] ? "pos" : "scale")));
 
        getdrawfontscale(&sx, &sy);
-       DrawQ_String_Scale(pos[0], pos[1], string, 0, scale[0], scale[1], sx, sy, 1, 1, 1, PRVM_G_FLOAT(OFS_PARM3), flag, NULL, false, getdrawfont());
-       PRVM_G_FLOAT(OFS_RETURN) = 1;
+       DrawQ_String_Scale(pos[0], pos[1], string, 0, scale[0], scale[1], sx, sy, rgb[0], rgb[1], rgb[2], alpha, flag, NULL, false, getdrawfont());
+       if (prog->argc == 6) // also return vector of last color
+               VectorCopy(DrawQ_Color, PRVM_G_VECTOR(OFS_RETURN));
+       else
+               PRVM_G_FLOAT(OFS_RETURN) = 1;
 }
 /*
 =========