From 8e08cddaa7a912d119f6eaecc5e506cbef719538 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Mon, 24 Apr 2017 21:48:57 +0200 Subject: [PATCH] improve cutcolorstring now takes the width of characters into account also: fix wraparound for docrefs --- source/src/docs.cpp | 2 +- source/src/protocol.cpp | 11 ----------- source/src/protos.h | 2 +- source/src/rendertext.cpp | 15 +++++++++++++++ source/src/serverbrowser.cpp | 6 +++--- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/source/src/docs.cpp b/source/src/docs.cpp index 1afe81a0..0a3dedea 100644 --- a/source/src/docs.cpp +++ b/source/src/docs.cpp @@ -589,7 +589,7 @@ void renderdoc(int x, int y, int doch) { string refs = ""; loopvj(curident->references) concatformatstring(refs, ", %s", curident->references[j]); - formatstring(doclines.add(newstringbuf()))("~related identifiers:%s", refs + 1); + formatstring(doclines.add(newstringbuf()))("Related identifiers:%s", refs + 1); } while(doclines.length() && !doclines.last()) doclines.pop(); diff --git a/source/src/protocol.cpp b/source/src/protocol.cpp index 9c7c0a9b..9f9ed849 100644 --- a/source/src/protocol.cpp +++ b/source/src/protocol.cpp @@ -377,17 +377,6 @@ void trimtrailingwhitespace(char *s) s[n] = '\0'; } -void cutcolorstring(char *text, int len) -{ // limit string length, ignore color codes - while(*text) - { - if(*text == '\f' && text[1]) text++; - else len--; - if(len < 0) { *text = '\0'; break; } - text++; - } -} - const char *modefullnames[] = { "demo playback", diff --git a/source/src/protos.h b/source/src/protos.h index a12cec80..da37df22 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -719,6 +719,7 @@ extern int text_visible(const char *str, int hitx, int hity, int maxwidth); extern void text_pos(const char *str, int cursor, int &cx, int &cy, int maxwidth); extern void text_startcolumns(); extern void text_endcolumns(); +extern void cutcolorstring(char *text, int len); // editing #define EDITSEL(x) if(noteditmode(x) || noselection()) return @@ -1071,7 +1072,6 @@ extern char *filtertext(char *dst, const char *src, int flags = 1, int len = siz extern void filterrichtext(char *dst, const char *src, int len = sizeof(string)-1); extern void filterlang(char *d, const char *s); extern void trimtrailingwhitespace(char *s); -extern void cutcolorstring(char *text, int len); extern void startintermission(); extern void restoreserverstate(vector &ents); extern string mastername; diff --git a/source/src/rendertext.cpp b/source/src/rendertext.cpp index e84aad76..c487a7e6 100644 --- a/source/src/rendertext.cpp +++ b/source/src/rendertext.cpp @@ -384,3 +384,18 @@ void reloadfonts() if(!reloadtexture(*f.tex)) fatal("failed to reload font texture"); ); } + +void cutcolorstring(char *text, int maxlen) +{ // limit string length, ignore color codes + if(!curfont) return; + int len = 0; + maxlen *= curfont->defaultw; + while(*text) + { + if(*text == '\f' && text[1]) text++; + else if(*text == '\t') len = TABALIGN(len); + else len += curfont->chars.inrange(*text - curfont->skip) ? curfont->chars[*text - curfont->skip].w : curfont->defaultw; + if(len > maxlen) { *text = '\0'; break; } + text++; + } +} diff --git a/source/src/serverbrowser.cpp b/source/src/serverbrowser.cpp index ef834845..f8d0f97f 100644 --- a/source/src/serverbrowser.cpp +++ b/source/src/serverbrowser.cpp @@ -536,7 +536,7 @@ void checkpings() if(*text && !p.overread()) { text[MAXINFOLINELEN] = '\0'; - cutcolorstring(text, 80); + cutcolorstring(text, 100); ADDINFOLINE(strcmp(text, ".") ? text : ""); } else break; @@ -1094,8 +1094,8 @@ void refreshservers(void *menu, bool init) } if(showthisone) { - cutcolorstring(si.full, 76); // cut off too long server descriptions - cutcolorstring(si.description, 76); + cutcolorstring(si.full, 105); // cut off too long server descriptions + cutcolorstring(si.description, 100); if(sbconnectexists) { filtertext(text, si.sdesc, FTXT_NOCOLOR|FTXT_NOWHITE|FTXT_ALLOWBLANKS);