Пример #1
0
static int GLua_Sys_StripColorcodes(lua_State *L) {
	const char *input;
	char *output;

	const char *i;
	char *o;

	input = luaL_checkstring(L, 1);
	// alloc the output buffer to be big enough to fit the entire input
	output = malloc(strlen(input) + 1);
	
	i = input;
	o = output;
	while (*i) {
		if (*i == '^') {
			if (*(i+1) >= '0' && *(i+1) <= '9') {
				i+=2;
				continue;
			}
			if (*(i+1) == 'x') {
				if (Text_IsExtColorCode(i+1)) {
					i+=5;
					continue;
				}
			}
		}
		*o = *i;
		i++; o++;
	}

	*o = *i;
	lua_pushstring(L, output);
	free(output);
	return 1;
}
Пример #2
0
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 );
	}
}