Fix negative glyph index in Team Arena text functions

Team Arena's text functions cast signed char values to int and use as an array index.
This works fine for values 0 to 127, but not for -128 to -1 which are a negative array index.
Instead use "character & 255" like client and original Q3 ui/cgame string drawing code.
This commit is contained in:
Zack Middleton 2014-12-01 21:53:06 -06:00
parent 08ddb99732
commit b21a59af8c
3 changed files with 10 additions and 16 deletions

View file

@ -284,7 +284,7 @@ int Text_Width(const char *text, float scale, int limit) {
s += 2;
continue;
} else {
glyph = &font->glyphs[(int)*s];
glyph = &font->glyphs[*s & 255];
out += glyph->xSkip;
s++;
count++;
@ -319,7 +319,7 @@ int Text_Height(const char *text, float scale, int limit) {
s += 2;
continue;
} else {
glyph = &font->glyphs[(int)*s]; // TTimo: FIXME: getting nasty warnings without the cast, hopefully this doesn't break the VM build
glyph = &font->glyphs[*s & 255];
if (max < glyph->height) {
max = glyph->height;
}
@ -361,7 +361,7 @@ void Text_Paint(float x, float y, float scale, vec4_t color, const char *text, f
}
count = 0;
while (s && *s && count < len) {
glyph = &font->glyphs[(int)*s]; // TTimo: FIXME: getting nasty warnings without the cast, hopefully this doesn't break the VM build
glyph = &font->glyphs[*s & 255];
//int yadj = Assets.textFont.glyphs[text[i]].bottom + Assets.textFont.glyphs[text[i]].top;
//float yadj = scale * (Assets.textFont.glyphs[text[i]].imageHeight - Assets.textFont.glyphs[text[i]].height);
if ( Q_IsColorString( s ) ) {
@ -429,9 +429,9 @@ void Text_PaintWithCursor(float x, float y, float scale, vec4_t color, const cha
len = limit;
}
count = 0;
glyph2 = &font->glyphs[ (int) cursor];
glyph2 = &font->glyphs[cursor & 255];
while (s && *s && count < len) {
glyph = &font->glyphs[(int)*s]; // TTimo: FIXME: getting nasty warnings without the cast, hopefully this doesn't break the VM build
glyph = &font->glyphs[*s & 255];
//int yadj = Assets.textFont.glyphs[text[i]].bottom + Assets.textFont.glyphs[text[i]].top;
//float yadj = scale * (Assets.textFont.glyphs[text[i]].imageHeight - Assets.textFont.glyphs[text[i]].height);
if ( Q_IsColorString( s ) ) {
@ -528,7 +528,7 @@ static void Text_Paint_Limit(float *maxX, float x, float y, float scale, vec4_t
}
count = 0;
while (s && *s && count < len) {
glyph = &font->glyphs[(int)*s]; // TTimo: FIXME: getting nasty warnings without the cast, hopefully this doesn't break the VM build
glyph = &font->glyphs[*s & 255];
if ( Q_IsColorString( s ) ) {
memcpy( newColor, g_color_table[ColorIndex(*(s+1))], sizeof( newColor ) );
newColor[3] = color[3];