Exemple #1
0
void CG_DrawStringExt( int x, int y, const char *string, const float *setColor, 
		qboolean forceColor, qboolean shadow, int charWidth, int charHeight, int maxChars )
{
	if (trap_Language_IsAsian())
	{
		// hack-a-doodle-do (post-release quick fix code)...
		//
		vec4_t color;
		memcpy(color,setColor, sizeof(color));	// de-const it
		CG_Text_Paint(x, y, 1.0f,	// float scale, 
						color,		// vec4_t color, 
						string,		// const char *text, 
						0.0f,		// float adjust, 
						0,			// int limit, 
						shadow ? ITEM_TEXTSTYLE_SHADOWED : 0,	// int style, 
						FONT_MEDIUM		// iMenuFont
						) ;
	}
	else
	{
		vec4_t		color;
		const char	*s;
		int			xx;

		// draw the drop shadow
		if (shadow) {
			color[0] = color[1] = color[2] = 0;
			color[3] = setColor[3];
			trap_R_SetColor( color );
			s = string;
			xx = x;
			while ( *s ) {
				if ( Q_IsColorString( s ) ) {
					s += 2;
					continue;
				}
				CG_DrawChar( xx + 2, y + 2, charWidth, charHeight, *s );
				xx += charWidth;
				s++;
			}
		}

		// draw the colored text
		s = string;
		xx = x;
		trap_R_SetColor( setColor );
		while ( *s ) {
			if ( Q_IsColorString( s ) ) {
				if ( !forceColor ) {
					memcpy( color, g_color_table[ColorIndex(*(s+1))], sizeof( color ) );
					color[3] = setColor[3];
					trap_R_SetColor( color );
				}
				s += 2;
				continue;
			}
			CG_DrawChar( xx, y, charWidth, charHeight, *s );
			xx += charWidth;
			s++;
		}
		trap_R_SetColor( NULL );
	}
}
void CG_DrawStringExt( int x, int y, const char *string, const float *setColor, 
		qboolean forceColor, qboolean shadow, int charWidth, int charHeight, int maxChars, qhandle_t textShader )
{
	if (trap_Language_IsAsian())
	{
		// hack-a-doodle-do (post-release quick fix code)...
		//
		vec4_t color;
		memcpy(color,setColor, sizeof(color));	// de-const it
		CG_Text_Paint(x, y, 1.0f,	// float scale, 
						color,		// vec4_t color, 
						string,		// const char *text, 
						0.0f,		// float adjust, 
						0,			// int limit, 
						shadow ? ITEM_TEXTSTYLE_SHADOWED : 0,	// int style, 
						FONT_MEDIUM		// iMenuFont
						) ;
	}
	else
	{
		vec4_t		color;
		const char	*s;
		int			xx;
		int			yy;

		// draw the drop shadow
		if (shadow) {
			color[0] = color[1] = color[2] = 0;
			color[3] = setColor[3];
			trap_R_SetColor( color );
			s = string;
			xx = x;
			yy = y;
			while ( *s ) {
				if(*s == '^')
				{
					//Don't include color codes
					if(*(s+1) >= '0' && *(s+1) <= '9')
					{
						s+=2;
						continue;
					}
					else if(*(s+1) == 'x' && Text_IsExtColorCode((s+1)))
					{
						s+=5;
						continue;
					}
				}
				else if(*s == '\n')
				{
					yy += charHeight;
					xx = x;
					s++;
					continue;
				}
				//trap_R_DrawStretchPic( xx + 2, yy+2, charWidth, charHeight, 8, 16, 
				CG_DrawChar( xx + 2, yy + 2, charWidth, charHeight, *s, textShader );
				xx += charWidth;
				s++;
			}
		}

		// draw the colored text
		s = string;
		xx = x;
		yy = y;
		trap_R_SetColor( setColor );
		while ( *s ) {
			if(*s == '\n')
			{	//Handle newlines
				yy += charHeight;
				xx = x;
				s++;
				continue;
			}
			else if(*s == '^')
			{	//Handle color codes
				if(*(s+1) >= '0' && *(s+1) <= '9')
				{
					if(!forceColor)
					{
						memcpy( color, g_color_table[ColorIndex(*(s+1))], sizeof( color ) );
						color[3] = setColor[3];
						trap_R_SetColor( color );
					}
					s+= 2;
					continue;
				}
				else if(*(s+1) == 'x')
				{
					if(strlen(s) > 5)
					{
						if(!forceColor)
						{
							int i;
							for(i=0; i<3; i++)
							{
								if((s+2+i))
								{
									char letter = *(s+2+i);
									if(*(s+2+i) >= '0' && *(s+2+i) <= '9')
									{
										color[i] = (atof(va("%c", letter))/16.0f);
									}
									else if((*(s+2+i) >= 'A' && *(s+2+i) <= 'F') || (*(s+2+i) >= 'a' && *(s+2+i) <= 'f'))
									{
										char *endPtr = NULL;
										long value = strtol(va("0x%c", letter), &endPtr, 16);
										color[i] = (float)value/16.0f;
									}
								}
							}
							color[3] = setColor[3];
							trap_R_SetColor( color );
						}
						s += 5;
						continue;
					}
				}
			}
			CG_DrawChar( xx + 2, yy, charWidth, charHeight, *s, textShader );
			xx += charWidth-1;
			s++;
		}
		trap_R_SetColor( NULL );
	}
}