thirtyflightsofloving/client/cl_string.c

200 lines
4.7 KiB
C
Raw Normal View History

2019-03-13 19:20:07 +00:00
/*
===========================================================================
2019-03-13 19:20:07 +00:00
Copyright (C) 1997-2001 Id Software, Inc.
This file is part of Quake 2 source code.
2019-03-13 19:20:07 +00:00
Quake 2 source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
2019-03-13 19:20:07 +00:00
Quake 2 source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
2019-03-13 19:20:07 +00:00
You should have received a copy of the GNU General Public License
along with Quake 2 source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
2019-03-13 19:20:07 +00:00
*/
// cl_string.c
// string drawing and formatting functions
#include "client.h"
/*
================
CL_StringSetParams
2019-03-13 19:20:07 +00:00
================
*/
qboolean CL_StringSetParams (char modifier, int *red, int *green, int *blue, int *bold, int *shadow, int *italic, int *reset)
2019-03-13 19:20:07 +00:00
{
// sanity check
if (!red || !green || !blue || !bold || !shadow || !italic || !reset)
return false;
2019-03-13 19:20:07 +00:00
if (!alt_text_color)
alt_text_color = Cvar_Get ("alt_text_color", "2", CVAR_ARCHIVE);
switch (modifier)
{
case 'R':
case 'r':
*reset = true;
return true;
case 'B':
case 'b':
if (*bold)
*bold = false;
else
*bold = true;
2019-03-13 19:20:07 +00:00
return true;
case 'S':
case 's':
if (*shadow)
*shadow = false;
2019-03-13 19:20:07 +00:00
else
*shadow = true;
2019-03-13 19:20:07 +00:00
return true;
case 'I':
case 'i':
if (*italic)
*italic = false;
2019-03-13 19:20:07 +00:00
else
*italic = true;
2019-03-13 19:20:07 +00:00
return true;
case COLOR_RED:
case COLOR_GREEN:
case COLOR_YELLOW:
case COLOR_BLUE:
case COLOR_CYAN:
case COLOR_MAGENTA:
case COLOR_WHITE:
case COLOR_BLACK:
case COLOR_ORANGE:
case COLOR_GRAY:
CL_TextColor (atoi(&modifier), red, green, blue);
2019-03-13 19:20:07 +00:00
return true;
case 'A': // alt text color
2019-03-13 19:20:07 +00:00
case 'a':
// CL_TextColor ((int)alt_text_color->value, red, green, blue);
CL_TextColor (alt_text_color->integer, red, green, blue);
2019-03-13 19:20:07 +00:00
return true;
}
return false;
}
/*
================
CL_DrawStringGeneric
2019-03-13 19:20:07 +00:00
================
*/
void CL_DrawStringGeneric (int x, int y, const char *string, int alpha, int fontSize, textscaletype_t scaleType, qboolean altBit)
2019-03-13 19:20:07 +00:00
{
unsigned i, j;
int len, red, green, blue, italic, shadow, bold, reset;
float textSize, textScale;
byte modifier, character;
qboolean modified=false, flushChar;
2019-03-13 19:20:07 +00:00
// defaults
red = 255;
green = 255;
blue = 255;
italic = false;
shadow = false;
bold = false;
2020-07-29 10:05:09 +00:00
len = (int)strlen( string );
2019-03-13 19:20:07 +00:00
for ( i = 0, j = 0; i < len; i++ )
{
modifier = (byte)string[i];
if (modifier & 128) modifier &= ~128;
2019-03-13 19:20:07 +00:00
if (modifier == '^' && i < len)
{
i++;
reset = false;
modifier = (byte)string[i];
if (modifier & 128) modifier &= ~128;
2019-03-13 19:20:07 +00:00
if (modifier != '^')
2019-03-13 19:20:07 +00:00
{
modified = CL_StringSetParams (modifier, &red, &green, &blue, &bold, &shadow, &italic, &reset);
if ( (modifier != 'r') && (modifier != 'R') ) // fix false reset flag
reset = false;
2019-03-13 19:20:07 +00:00
if (reset)
{
red = 255;
green = 255;
blue = 255;
italic = false;
shadow = false;
bold = false;
}
if (modified)
continue;
else
i--;
}
}
j++;
character = (byte)string[i];
// if (bold && character < 128)
// character += 128;
// else if (bold && character > 128)
// character -= 128;
if ( (bold) || (!modified && altBit) ) {
character ^= 128;
}
// hack for alternate text color
if (!modified)
{
if (character & 128) {
// CL_TextColor ((int)alt_text_color->value, &red, &green, &blue);
CL_TextColor (alt_text_color->integer, &red, &green, &blue);
if ( (red != 255) || (green != 255) || (blue != 255) )
character &= ~128;
}
else
red = green = blue = 255;
}
2019-03-13 19:20:07 +00:00
switch (scaleType)
{
case SCALETYPE_MENU:
textSize = SCR_ScaledScreen(fontSize); // MENU_FONT_SIZE
textScale = SCR_GetScreenScale()*((float)fontSize/(float)MENU_FONT_SIZE);
2019-03-13 19:20:07 +00:00
break;
case SCALETYPE_HUD:
textSize = SCR_ScaledHud(fontSize); // HUD_FONT_SIZE
textScale = SCR_GetHudScale()*((float)fontSize/(float)HUD_FONT_SIZE);
2019-03-13 19:20:07 +00:00
break;
case SCALETYPE_CONSOLE:
default:
textSize = fontSize; // FONT_SIZE;
textScale = (float)fontSize/8.0f; // FONT_SIZE/8.0f
2019-03-13 19:20:07 +00:00
break;
}
flushChar = (i==(len-1));
2019-03-13 19:20:07 +00:00
if (shadow)
R_DrawChar( ( x + (j-1)*textSize+textSize/4 ), y+(textSize/8),
character, textScale, 0, 0, 0, alpha, italic, false );
R_DrawChar( ( x + (j-1)*textSize ), y,
character, textScale, red, green, blue, alpha, italic, flushChar );
2019-03-13 19:20:07 +00:00
}
}