From 1950409af844e107d22d8f396e89213ec2f32ff2 Mon Sep 17 00:00:00 2001 From: dresk Date: Wed, 5 Sep 2007 22:15:04 +0000 Subject: [PATCH] Added QC function drawcolorcodedstring (#326 CSQC, #467 MQC) which is similar to drawstring, instead it does not take in an RGB vector and instead colors the string based on the engine's coloring rules. Useful for drawing colorized player names, centerprints, etc. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7561 d7cf8633-e32d-0410-b094-e92efae38249 --- clvm_cmds.c | 2 +- mvm_cmds.c | 2 +- prvm_cmds.c | 41 +++++++++++++++++++++++++++++++++++++++++ prvm_cmds.h | 1 + 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/clvm_cmds.c b/clvm_cmds.c index 27ba2521..9afd7812 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -3075,7 +3075,7 @@ VM_drawpic, // #322 float(vector position, string pic, vector size, vector VM_drawfill, // #323 float(vector position, vector size, vector rgb, float alpha, float flag) drawfill (EXT_CSQC) VM_drawsetcliparea, // #324 void(float x, float y, float width, float height) drawsetcliparea VM_drawresetcliparea, // #325 void(void) drawresetcliparea -NULL, // #326 +VM_drawcolorcodedstring, // #326 float drawcolorcodedstring(vector position, string text, vector scale, vector rgb, float alpha, float flag) (EXT_CSQC) NULL, // #327 NULL, // #328 NULL, // #329 diff --git a/mvm_cmds.c b/mvm_cmds.c index 7ed9c135..cef5830c 100644 --- a/mvm_cmds.c +++ b/mvm_cmds.c @@ -1226,7 +1226,7 @@ VM_cin_setstate, // #463 VM_cin_getstate, // #464 VM_cin_restart, // #465 VM_drawline, // #466 -NULL, // #467 +VM_drawcolorcodedstring, // #467 NULL, // #468 NULL, // #469 NULL, // #470 diff --git a/prvm_cmds.c b/prvm_cmds.c index fcf3d8ba..7710cf78 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -2586,6 +2586,47 @@ void VM_drawstring(void) DrawQ_String (pos[0], pos[1], string, 0, scale[0], scale[1], rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM4), flag, NULL, true); PRVM_G_FLOAT(OFS_RETURN) = 1; } + +/* +========= +VM_drawcolorcodedstring + +float drawcolorcodedstring(vector position, string text, vector scale, float alpha, float flag) +========= +*/ +void VM_drawcolorcodedstring(void) +{ + float *pos,*scale; + const char *string; + int flag,color; + VM_SAFEPARMCOUNT(5,VM_drawstring); + + string = PRVM_G_STRING(OFS_PARM1); + pos = PRVM_G_VECTOR(OFS_PARM0); + scale = PRVM_G_VECTOR(OFS_PARM2); + flag = (int)PRVM_G_FLOAT(OFS_PARM5); + + 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); + return; + } + + if(!scale[0] || !scale[1]) + { + PRVM_G_FLOAT(OFS_RETURN) = -3; + VM_Warning("VM_drawcolorcodedstring: scale %s is null !\n", (scale[0] == 0) ? ((scale[1] == 0) ? "x and y" : "x") : "y"); + return; + } + + if(pos[2] || scale[2]) + 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"))); + + color = -1; + DrawQ_String (pos[0], pos[1], string, 0, scale[0], scale[1], 1, 1, 1, PRVM_G_FLOAT(OFS_PARM3), flag, NULL, false); + PRVM_G_FLOAT(OFS_RETURN) = 1; +} /* ========= VM_drawpic diff --git a/prvm_cmds.h b/prvm_cmds.h index 61393b16..20c4927b 100644 --- a/prvm_cmds.h +++ b/prvm_cmds.h @@ -323,6 +323,7 @@ void VM_precache_pic(void); void VM_freepic(void); void VM_drawcharacter(void); void VM_drawstring(void); +void VM_drawcolorcodedstring(void); void VM_drawpic(void); void VM_drawfill(void); void VM_drawsetcliparea(void); -- 2.39.2