From e84f4d7df48aafab8cc2aba84b1f522a24deb17a Mon Sep 17 00:00:00 2001 From: havoc Date: Sun, 14 Jan 2007 09:53:31 +0000 Subject: [PATCH] patch from div0 to make DrawQ_ColoredString return the length of the printed text git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6688 d7cf8633-e32d-0410-b094-e92efae38249 --- draw.h | 2 +- gl_draw.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/draw.h b/draw.h index 62e9d585..6d6f4e3f 100644 --- a/draw.h +++ b/draw.h @@ -81,7 +81,7 @@ void DrawQ_Pic(float x, float y, cachepic_t *pic, float width, float height, flo // draw a text string void DrawQ_String(float x, float y, const char *string, int maxlen, float scalex, float scaley, float red, float green, float blue, float alpha, int flags); // draw a text string that supports color tags (colorindex can either be NULL, -1 to make it choose the default color or valid index to start with) -void DrawQ_ColoredString( float x, float y, const char *text, int maxlen, float scalex, float scaley, float basered, float basegreen, float baseblue, float basealpha, int flags, int *outcolor ); +float DrawQ_ColoredString( float x, float y, const char *text, int maxlen, float scalex, float scaley, float basered, float basegreen, float baseblue, float basealpha, int flags, int *outcolor ); // draw a very fancy pic (per corner texcoord/color control), the order is tl, tr, bl, br void DrawQ_SuperPic(float x, float y, cachepic_t *pic, float width, float height, float s1, float t1, float r1, float g1, float b1, float a1, float s2, float t2, float r2, float g2, float b2, float a2, float s3, float t3, float r3, float g3, float b3, float a3, float s4, float t4, float r4, float g4, float b4, float a4, int flags); // draw a triangle mesh diff --git a/gl_draw.c b/gl_draw.c index 9184ace7..217bf22d 100644 --- a/gl_draw.c +++ b/gl_draw.c @@ -683,7 +683,7 @@ static vec4_t string_colors[] = #define STRING_COLORS_COUNT (sizeof(string_colors) / sizeof(vec4_t)) // color is read and changed in the end -void DrawQ_ColoredString( float x, float y, const char *text, int maxlen, float scalex, float scaley, float basered, float basegreen, float baseblue, float basealpha, int flags, int *outcolor ) +float DrawQ_ColoredString( float x, float y, const char *text, int maxlen, float scalex, float scaley, float basered, float basegreen, float baseblue, float basealpha, int flags, int *outcolor ) { vec_t *color; int len; @@ -754,10 +754,22 @@ void DrawQ_ColoredString( float x, float y, const char *text, int maxlen, float } } + if( start != current ) { + // draw the string + DrawQ_String( x, y, start, current - start, scalex, scaley, basered * color[0], basegreen * color[1], baseblue * color[2], basealpha * color[3], flags ); + // update x to be at the new start position + x += (current - start) * scalex; + // set start accordingly + start = current; + } + // return the last colorindex if( outcolor ) { *outcolor = colorindex; } + + // return the new x position + return x; } void DrawQ_SuperPic(float x, float y, cachepic_t *pic, float width, float height, float s1, float t1, float r1, float g1, float b1, float a1, float s2, float t2, float r2, float g2, float b2, float a2, float s3, float t3, float r3, float g3, float b3, float a3, float s4, float t4, float r4, float g4, float b4, float a4, int flags) -- 2.39.2