Exemplo n.º 1
0
qboolean CL_InternalConsolePrint( const char *text )
{
	int      y;
	int      c, i, l;
	int      color;

	// for some demos we don't want to ever show anything on the console
	if ( cl_noprint && cl_noprint->integer )
	{
		return qtrue;
	}

	if ( !consoleState.initialized )
	{
		consoleState.textWidthInChars = -1;
		consoleState.initialized = Con_CheckResize();
	}

	//Video hasn't been initialized
	if ( ! cls.glconfig.vidWidth ) {
		return qfalse;
	}

	// NERVE - SMF - work around for text that shows up in console but not in notify
	if ( !Q_strncmp( text, S_SKIPNOTIFY, 12 ) )
	{
		text += 12;
	}
	else if ( !consoleState.isOpened && strncmp( text, "EXCL: ", 6 ) )
	{
		// feed the text to cgame
		Cmd_SaveCmdContext();
		Cmd_TokenizeString( Cmd::Escape(text).c_str() );
		CL_GameConsoleText();
		Cmd_RestoreCmdContext();
	}

	color = ColorIndex( CONSOLE_COLOR );

	while ( ( c = *text & 0xFF ) != 0 )
	{
		if ( Q_IsColorString( text ) )
		{
			color = ( text[ 1 ] == COLOR_NULL ) ? ColorIndex( CONSOLE_COLOR ) : ColorIndex( text[ 1 ] );
			text += 2;
			continue;
		}

		// count word length
		for ( i = l = 0; l < consoleState.textWidthInChars; ++l )
		{
			if ( text[ i ] <= ' ' && text[ i ] >= 0 )
			{
				break;
			}

			if ( text[ i ] == Q_COLOR_ESCAPE && text[ i + 1 ] == Q_COLOR_ESCAPE )
			{
				++i;
			}

			i += Q_UTF8_Width( text + i );
		}

		// word wrap
		if ( l != consoleState.textWidthInChars && ( consoleState.horizontalCharOffset + l >= consoleState.textWidthInChars ) )
		{
			Con_Linefeed( );
		}

		switch ( c )
		{
			case '\n':
				Con_Linefeed( );
				break;

			case '\r':
				consoleState.horizontalCharOffset = 0;
				break;

			case Q_COLOR_ESCAPE:
				if ( text[ 1 ] == Q_COLOR_ESCAPE )
				{
					++text;
				}
				/* no break */

			default: // display character and advance
				y = consoleState.currentLine % consoleState.maxScrollbackLengthInLines;
				// rain - sign extension caused the character to carry over
				// into the color info for high ascii chars; casting c to unsigned
				consoleState.text[ y * consoleState.textWidthInChars + consoleState.horizontalCharOffset ].ch = Q_UTF8_CodePoint( text );
				consoleState.text[ y * consoleState.textWidthInChars + consoleState.horizontalCharOffset ].ink = color;
				++consoleState.horizontalCharOffset;

				if ( consoleState.horizontalCharOffset >= consoleState.textWidthInChars )
				{
					Con_Linefeed( );
					consoleState.horizontalCharOffset = 0;
				}

				break;
		}

		text += Q_UTF8_Width( text );
	}

	return qtrue;
}
Exemplo n.º 2
0
void CL_ConsolePrint( char *txt )
{
	int      y;
	int      c, i, l;
	int      color;
	qboolean skipnotify = qfalse; // NERVE - SMF
	int      prev; // NERVE - SMF

	// NERVE - SMF - work around for text that shows up in console but not in notify
	if ( !Q_strncmp( txt, "[skipnotify]", 12 ) )
	{
		skipnotify = qtrue;
		txt += 12;
	}

	// for some demos we don't want to ever show anything on the console
	if ( cl_noprint && cl_noprint->integer )
	{
		return;
	}

	if ( !con.initialized )
	{
		con.color[ 0 ] = con.color[ 1 ] = con.color[ 2 ] = con.color[ 3 ] = 1.0f;
		con.linewidth = -1;
		Con_CheckResize();
		con.initialized = qtrue;
	}

	if ( !skipnotify && !( cls.keyCatchers & KEYCATCH_CONSOLE ) && strncmp( txt, "EXCL: ", 6 ) )
	{
		// feed the text to cgame
		Cmd_SaveCmdContext();
		Cmd_TokenizeString( txt );
		CL_GameConsoleText();
		Cmd_RestoreCmdContext();
	}

	color = ColorIndex( CONSOLE_COLOR );

	while ( ( c = *txt & 0xFF ) != 0 )
	{
		if ( Q_IsColorString( txt ) )
		{
			color = ( txt[ 1 ] == COLOR_NULL ) ? ColorIndex( CONSOLE_COLOR ) : ColorIndex( txt[ 1 ] );
			txt += 2;
			continue;
		}

		// count word length
		for ( i = l = 0; l < con.linewidth; ++l )
		{
			if ( txt[ i ] <= ' ' && txt[ i ] >= 0 )
			{
				break;
			}

			if ( txt[ i ] == Q_COLOR_ESCAPE && txt[ i + 1 ] == Q_COLOR_ESCAPE )
			{
				++i;
			}

			i += Q_UTF8Width( txt + i );
		}

		// word wrap
		if ( l != con.linewidth && ( con.x + l >= con.linewidth ) )
		{
			Con_Linefeed( skipnotify );
		}

		switch ( c )
		{
			case '\n':
				Con_Linefeed( skipnotify );
				break;

			case '\r':
				con.x = 0;
				break;

			case Q_COLOR_ESCAPE:
				if ( txt[ 1 ] == Q_COLOR_ESCAPE )
				{
					++txt;
				}

			default: // display character and advance
				y = con.current % con.totallines;
				// rain - sign extension caused the character to carry over
				// into the color info for high ascii chars; casting c to unsigned
				con.text[ y * con.linewidth + con.x ].ch = Q_UTF8CodePoint( txt );
				con.text[ y * con.linewidth + con.x ].ink = color;
				++con.x;

				if ( con.x >= con.linewidth )
				{
					Con_Linefeed( skipnotify );
					con.x = 0;
				}

				break;
		}

		txt += Q_UTF8Width( txt );
	}

	// mark time for transparent overlay
	if ( con.current >= 0 )
	{
		// NERVE - SMF
		if ( skipnotify )
		{
			prev = con.current % NUM_CON_TIMES - 1;

			if ( prev < 0 )
			{
				prev = NUM_CON_TIMES - 1;
			}

			con.times[ prev ] = 0;
		}
		else
		{
			// -NERVE - SMF
			con.times[ con.current % NUM_CON_TIMES ] = cls.realtime;
		}
	}
}