From 1520e421e54adcec3500c1338d3443a7066c56db Mon Sep 17 00:00:00 2001 From: driAn Date: Thu, 9 Oct 2008 21:59:19 +0000 Subject: [PATCH] keep colors when splitting strings git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@2871 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/rendertext.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/source/src/rendertext.cpp b/source/src/rendertext.cpp index 642e6e17..439fea8c 100644 --- a/source/src/rendertext.cpp +++ b/source/src/rendertext.cpp @@ -135,6 +135,7 @@ void text_block(const char *str, int max, vector &lines) { if(!str) return; int visible; + cvector colordata; while((visible = max ? text_visible(str, max) : (int)strlen(str))) { const char *newline = (const char *)memchr(str, '\n', visible); @@ -145,8 +146,17 @@ void text_block(const char *str, int max, vector &lines) while(v > 0 && str[v] != ' ') v--; if(v) visible = v+1; } - char *t = lines.add(newstring((size_t)visible)); - s_strncpy(t, str, visible+1); + size_t colorsize = colordata.length()*2; + char *t = lines.add(newstring((size_t)visible+colorsize)); + char *color = t; + loopv(colordata) // add colors from previous line + { + s_strncpy(color, colordata[i], 3); + color += 2; + } + s_strncpy(color, str, visible+1); + colordata.setsize(0); + for(char *c = strchr(t, '\f'); c && c[1]; c = strchr(c+1, '\f')) colordata.add(c); // store colors of this line str += visible; } }