improve cutcolorstring

now takes the width of characters into account

also: fix wraparound for docrefs
This commit is contained in:
ac-stef
2017-04-24 21:48:57 +02:00
parent 9739464381
commit 8e08cddaa7
5 changed files with 20 additions and 16 deletions
+1 -1
View File
@@ -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();
-11
View File
@@ -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",
+1 -1
View File
@@ -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<entity> &ents);
extern string mastername;
+15
View File
@@ -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++;
}
}
+3 -3
View File
@@ -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);