+float DrawQ_TextWidth_Font_UntilWidth_TrackColors(const char *text, size_t *maxlen, int *outcolor, qboolean ignorecolorcodes, const dp_font_t *fnt, float maxwidth)
+{
+ int num, colorindex = STRING_COLOR_DEFAULT;
+ size_t i;
+ float x = 0;
+ char ch;
+ int current_alpha, tempcolorindex;
+
+ if (*maxlen < 1)
+ *maxlen = 1<<30;
+
+ if (!outcolor || *outcolor == -1)
+ colorindex = STRING_COLOR_DEFAULT;
+ else
+ colorindex = *outcolor;
+
+ maxwidth /= fnt->scale;
+
+ current_alpha = 0xf;
+
+ for (i = 0;i < *maxlen && text[i];i++)
+ {
+ if (text[i] == ' ')
+ {
+ if(x + fnt->width_of[' '] > maxwidth)
+ break; // oops, can't draw this
+ x += fnt->width_of[' '];
+ continue;
+ }
+ if (text[i] == STRING_COLOR_TAG && !ignorecolorcodes && i + 1 < *maxlen)
+ {
+ ch = text[++i];
+ if (ch <= '9' && ch >= '0') // ^[0-9] found
+ {
+ colorindex = ch - '0';
+ continue;
+ }
+ else if (ch == STRING_COLOR_RGB_DEFAULT && i + 3 < *maxlen ) // ^x found
+ {
+ // building colorindex...
+ ch = tolower(text[i+1]);
+ tempcolorindex = 0x10000; // binary: 1,0000,0000,0000,0000
+ if (ch <= '9' && ch >= '0') tempcolorindex |= (ch - '0') << 12;
+ else if (ch >= 'a' && ch <= 'f') tempcolorindex |= (ch - 87) << 12;
+ else tempcolorindex = 0;
+ if (tempcolorindex)
+ {
+ ch = tolower(text[i+2]);
+ if (ch <= '9' && ch >= '0') tempcolorindex |= (ch - '0') << 8;
+ else if (ch >= 'a' && ch <= 'f') tempcolorindex |= (ch - 87) << 8;
+ else tempcolorindex = 0;
+ if (tempcolorindex)
+ {
+ ch = tolower(text[i+3]);
+ if (ch <= '9' && ch >= '0') tempcolorindex |= (ch - '0') << 4;
+ else if (ch >= 'a' && ch <= 'f') tempcolorindex |= (ch - 87) << 4;
+ else tempcolorindex = 0;
+ if (tempcolorindex)
+ {
+ colorindex = tempcolorindex | current_alpha;
+ // ...done! now colorindex has rgba codes (1,rrrr,gggg,bbbb,aaaa)
+ i+=3;
+ continue;
+ }
+ }
+ }
+ }
+ /*else if (ch == 'a' && i + 1 < *maxlen) // ^a found
+ {
+ if (colorindex > 9)
+ {
+ ch = tolower(text[i+1]);
+ if (ch <= '9' && ch >= '0') current_alpha = (ch - '0');
+ else if (ch >= 'a' && ch <= 'f') current_alpha = (ch - 87);
+ else if (ch == '+' && colorindex > 9)
+ {
+ current_alpha = colorindex & 0xf;
+ if (current_alpha < 0xf)
+ current_alpha++;
+ }
+ else if (ch == '-' && colorindex > 9)
+ {
+ current_alpha = colorindex & 0xf;
+ if (current_alpha > 0)
+ current_alpha--;
+ }
+ colorindex = ((colorindex >> 4 ) << 4) + current_alpha;
+ }
+ i++;
+ continue;
+ }*/
+ else if (ch == STRING_COLOR_TAG) // ^^ found, ignore the first ^ and go to print the second
+ i++;
+ i--;
+ }
+ num = (unsigned char) text[i];
+ if(x + fnt->width_of[num] > maxwidth)
+ break; // oops, can't draw this
+ x += fnt->width_of[num];
+ }
+
+ *maxlen = i;
+
+ if (outcolor)
+ *outcolor = colorindex;
+
+ return x * fnt->scale;
+}
+
+float DrawQ_String_Font(float startx, float starty, const char *text, size_t maxlen, float w, float h, float basered, float basegreen, float baseblue, float basealpha, int flags, int *outcolor, qboolean ignorecolorcodes, const dp_font_t *fnt)