Exemplo n.º 1
0
void Con_DrawRightFloatingTextLine( const int linePosition, const float *color, const char* text )
{
	int i, x;
	float currentWidthLocation = 0;

	const int charHeight = SCR_ConsoleFontCharHeight();
	const int positionFromTop = consoleState.margin.top
	                          + consoleState.border.top
	                          + consoleState.padding.top
	                          + charHeight;

	i = strlen( text );
	currentWidthLocation = cls.glconfig.vidWidth
	                     - SCR_ConsoleFontStringWidth( text, i )
	                     - consoleState.margin.sides - consoleState.padding.sides;

	re.SetColor( color );

	for ( x = 0; x < i; x++ )
	{
		int ch = Q_UTF8_CodePoint( &text[ x ] );
		SCR_DrawConsoleFontUnichar( currentWidthLocation, positionFromTop + ( linePosition * charHeight ), ch );
		currentWidthLocation += SCR_ConsoleFontUnicharWidth( ch );
	}
}
Exemplo n.º 2
0
/*
================
Con_DrawInput

Draw the editline after a ] prompt
================
*/
void Con_DrawInput( void )
{
	int     y;
	char    prompt[ MAX_STRING_CHARS ];
	vec4_t  color;
	qtime_t realtime;

	if ( cls.state != CA_DISCONNECTED && !( cls.keyCatchers & KEYCATCH_CONSOLE ) )
	{
		return;
	}

	Com_RealTime( &realtime );

	y = con.vislines - ( SCR_ConsoleFontCharHeight() * 2 ) + 2;

	Com_sprintf( prompt,  sizeof( prompt ), "^0[^3%02d%c%02d^0]^7 %s", realtime.tm_hour, ( realtime.tm_sec & 1 ) ? ':' : ' ', realtime.tm_min, cl_consolePrompt->string );

	color[ 0 ] = 1.0f;
	color[ 1 ] = 1.0f;
	color[ 2 ] = 1.0f;
	color[ 3 ] = ( scr_conUseOld->integer ? 1.0f : con.displayFrac * 2.0f );

	SCR_DrawSmallStringExt( con.xadjust + cl_conXOffset->integer, y + 10, prompt, color, qfalse, qfalse );

	Q_CleanStr( prompt );
	Field_Draw( &g_consoleField, con.xadjust + cl_conXOffset->integer + SCR_ConsoleFontStringWidth( prompt, strlen( prompt ) ), y + 10, qtrue, qtrue, color[ 3 ] );
}
Exemplo n.º 3
0
/*
================
Con_DrawConsoleContent
================
*/
void Con_DrawConsoleContent( void )
{
	float  currentWidthLocation = 0;
	int    x;
	float  lineDrawPosition, lineDrawLowestPosition;
	int    row;
	int    currentColor;
	vec4_t color;

	const int charHeight = SCR_ConsoleFontCharHeight();
	const int charPadding = SCR_ConsoleFontCharVPadding();
	const int textDistanceToTop = consoleState.margin.top
	                            + consoleState.padding.top
	                            + consoleState.border.top
	                            - charPadding - 1;

	// draw from the bottom up
	lineDrawPosition = consoleState.height
	                 + consoleState.margin.top
	                 - consoleState.padding.bottom
	                 - consoleState.border.top
	                 - charPadding - 1;

	if (lineDrawPosition <= textDistanceToTop)
	{
		return;
	}

	// draw the input prompt, user text, and cursor if desired
	// moved back here (have observed render issues to do with time taken)
	Con_DrawInput( lineDrawPosition, Con_MarginFadeAlpha( 1, lineDrawPosition, textDistanceToTop, lineDrawPosition, charHeight ) );
	lineDrawPosition -= charHeight;

	if (lineDrawPosition <= textDistanceToTop)
	{
		return;
	}

	if(con_debug->integer) {
		Con_DrawRightFloatingTextLine( 3, NULL, va( "Buffer (lines): ScrollbackLength %d/%d  CurrentIndex %d", consoleState.usedScrollbackLengthInLines, consoleState.maxScrollbackLengthInLines, consoleState.currentLine) );
		Con_DrawRightFloatingTextLine( 4, NULL, va( "Display (lines): From %d to %d (%d a %i px)", consoleState.currentLine-consoleState.maxScrollbackLengthInLines, consoleState.scrollLineIndex, consoleState.visibleAmountOfLines, charHeight ) );
	}

	/*
	 * if we scrolled back, give feedback,
	 * unless it's the last line (which will be rendered partly transparent anyway)
	 * so that we dont indicate scrollback each time a single line gets added
	 */
	if ( floor( consoleState.bottomDisplayedLine ) < consoleState.currentLine - 1 )
	{
		// draw arrows to show the buffer is backscrolled
		Con_DrawConsoleScrollbackIndicator( lineDrawPosition );
	}

	lineDrawPosition -= charHeight;

	row = consoleState.bottomDisplayedLine;

	if ( consoleState.horizontalCharOffset == 0 )
	{
		row--;
	}

	lineDrawLowestPosition = lineDrawPosition;

	if ( consoleState.bottomDisplayedLine - floor( consoleState.bottomDisplayedLine ) != 0.0f )
	{
		lineDrawPosition += charHeight - ( consoleState.bottomDisplayedLine - floor( consoleState.bottomDisplayedLine ) ) * charHeight;
		++row;
	}

	currentColor = 7;
	color[ 0 ] = g_color_table[ currentColor ][ 0 ];
	color[ 1 ] = g_color_table[ currentColor ][ 1 ];
	color[ 2 ] = g_color_table[ currentColor ][ 2 ];

	for ( ; row >= 0 && lineDrawPosition > textDistanceToTop; lineDrawPosition -= charHeight, row-- )
	{
		conChar_t *text;

		if ( consoleState.currentLine - row >= consoleState.maxScrollbackLengthInLines )
		{
			// past scrollback wrap point
			continue;
		}

		if ( row == consoleState.lastReadLineIndex - 1
			&& consoleState.lastReadLineIndex != consoleState.currentLine
			&& consoleState.currentLine - consoleState.lastReadLineIndex < consoleState.usedScrollbackLengthInLines)
		{
			Con_DrawScrollbackMarkerline( lineDrawPosition );
		}

		text = consoleState.text + CON_LINE( row );

		currentWidthLocation = consoleState.margin.sides + consoleState.padding.sides;

		for ( x = 0; x < consoleState.textWidthInChars && text[x].ch; ++x )
		{
			if ( text[ x ].ink != currentColor )
			{
				currentColor = text[ x ].ink;
				color[ 0 ] = g_color_table[ currentColor ][ 0 ];
				color[ 1 ] = g_color_table[ currentColor ][ 1 ];
				color[ 2 ] = g_color_table[ currentColor ][ 2 ];
			}

			color[ 3 ] = Con_MarginFadeAlpha( consoleState.currentAlphaFactor, lineDrawPosition, textDistanceToTop, lineDrawLowestPosition, charHeight );
			re.SetColor( color );

			SCR_DrawConsoleFontUnichar( currentWidthLocation, floor( lineDrawPosition + 0.5 ), text[ x ].ch );
			currentWidthLocation += SCR_ConsoleFontUnicharWidth( text[ x ].ch );
		}
	}

	Con_DrawConsoleScrollbar( );

	re.SetColor( NULL ); //set back to white
}
Exemplo n.º 4
0
/*
==================
Con_UpdateConsoleState
updates the consoleState
==================
*/
void Con_UpdateConsoleState( void )
{
	float  horizontalMargin, verticalMargin;
	int    totalVerticalPadding;

	const int charHeight = SCR_ConsoleFontCharHeight();
	const int charPadding = SCR_ConsoleFontCharVPadding();

	/*
	 * calculate margin and border
	 * we will treat the border in pixel (as opposed to margins and paddings)
	 * to allow for nice looking 1px borders, as well as to prevent
	 * different widths for horizontal and vertical borders due to different resolution-ratios
	 * since that isn't as nice looking as with areas
	 */
	consoleState.border.bottom = std::max( 0, con_borderWidth->integer );

	if(con_margin->value > 0) {
		horizontalMargin = con_margin->value;
		verticalMargin = con_margin->value;
		consoleState.border.sides = consoleState.border.bottom;
		consoleState.border.top = consoleState.border.bottom;
	} else {
		horizontalMargin = - con_margin->value;
		verticalMargin = 0;
		consoleState.border.sides = 0;
		consoleState.border.top = 0;
	}

	SCR_AdjustFrom640( &horizontalMargin, &verticalMargin, NULL, NULL );

	consoleState.margin.top = verticalMargin;
	consoleState.margin.bottom = verticalMargin;
	consoleState.margin.sides = horizontalMargin;

	/*
	 * calculate padding
	 */
	consoleState.padding.top = floor( verticalMargin * 0.3f );
	consoleState.padding.bottom = std::max( 3, consoleState.padding.top );

	// on wide screens, this will lead to somewhat of a centering of the text
	if(con_horizontalPadding->integer)
	{
		float horizontalVidPadding = con_horizontalPadding->value;
		SCR_AdjustFrom640( &horizontalVidPadding, NULL, NULL, NULL );
		consoleState.padding.sides = horizontalVidPadding;
	}
	else
	{
		consoleState.padding.sides = floor( horizontalMargin * 0.3f );
	}

	/*
	 * calculate global alpha factor
	 * apply the fade animation if the type is set, otherwise remain completly visible
	 */
	consoleState.currentAlphaFactor = ( con_animationType->integer & ANIMATION_TYPE_FADE ) ? consoleState.currentAnimationFraction : 1.0f;

	/*
	 * calculate current console height
	 */
	consoleState.height = con_height->integer * 0.01 * (cls.glconfig.vidHeight
						- consoleState.margin.top - consoleState.margin.bottom
						- consoleState.border.top - consoleState.border.bottom
						);

	totalVerticalPadding = consoleState.padding.top + consoleState.padding.bottom;

	// clip to a multiple of the character height, plus padding
	consoleState.height -= ( consoleState.height - totalVerticalPadding - charPadding ) % charHeight;
	// ... and ensure that at least three lines are visible
	consoleState.height = std::max( 3 * charHeight + totalVerticalPadding, consoleState.height );


	//animate via scroll animation if the type is set
	if ( con_animationType->integer & ANIMATION_TYPE_SCROLL_DOWN)
	{
		consoleState.height *= consoleState.currentAnimationFraction;
	}

	if ( consoleState.height > cls.glconfig.vidHeight )
	{
		consoleState.height = cls.glconfig.vidHeight;
	}

	/*
	 * calculate current amount of visible lines after we learned about the current height
	 */

	consoleState.visibleAmountOfLines = ( consoleState.height - consoleState.padding.top - consoleState.padding.bottom )
	                                    / charHeight //rowheight in pixel -> amount of rows
	                                    - 2 ; // dont count the input and the scrollbackindicator

}
Exemplo n.º 5
0
/*
================
Con_DrawSolidConsole

Draws the console with the solid background
================
*/
void Con_DrawSolidConsole( float frac )
{
	int    i, x, y;
	int    rows;
	int    row;
	int    lines;
//	qhandle_t    conShader;
	int    currentColor;
	vec4_t color;
	float  yVer;
	float  totalwidth;
	float  currentWidthLocation = 0;

	const int charHeight = SCR_ConsoleFontCharHeight();

	if ( scr_conUseOld->integer )
	{
		lines = cls.glconfig.vidHeight * frac;

		if ( lines <= 0 )
		{
			return;
		}

		if ( lines > cls.glconfig.vidHeight )
		{
			lines = cls.glconfig.vidHeight;
		}
	}
	else
	{
		lines = cls.glconfig.vidHeight * frac;
	}
	lines += charHeight / ( CONSOLE_FONT_VPADDING + 1 );

	// on wide screens, we will center the text
	if (!scr_conUseOld->integer)
	{
		con.xadjust = 15;
	}

	SCR_AdjustFrom640 (&con.xadjust, NULL, NULL, NULL);

	// draw the background
	if ( scr_conUseOld->integer )
	{
		yVer = 5 + charHeight;
		y = frac * SCREEN_HEIGHT;

		if ( y < 1 )
		{
			y = 0;
		}
		else
		{
			if ( scr_conUseShader->integer )
			{
				SCR_DrawPic( 0, 0, SCREEN_WIDTH, y, cls.consoleShader );
			}
			else
			{
				// This will be overwritten, so i'll just abuse it here, no need to define another array
				color[ 0 ] = scr_conColorRed->value;
				color[ 1 ] = scr_conColorGreen->value;
				color[ 2 ] = scr_conColorBlue->value;
				color[ 3 ] = scr_conColorAlpha->value;

				SCR_FillRect( 0, 0, SCREEN_WIDTH, y, color );
			}
		}

		color[ 0 ] = scr_conBarColorRed->value;
		color[ 1 ] = scr_conBarColorGreen->value;
		color[ 2 ] = scr_conBarColorBlue->value;
		color[ 3 ] = scr_conBarColorAlpha->value;

		SCR_FillRect( 0, y, SCREEN_WIDTH, scr_conBarSize->value, color );
	}
	else
	{
		yVer = 10;
		SCR_AdjustFrom640( NULL, &yVer, NULL, NULL );
		yVer = floor( yVer + 5 + charHeight );

		color[ 0 ] = scr_conColorRed->value;
		color[ 1 ] = scr_conColorGreen->value;
		color[ 2 ] = scr_conColorBlue->value;
		color[ 3 ] = frac * 2 * scr_conColorAlpha->value;
		SCR_FillRect( 10, 10, 620, 460 * scr_conHeight->integer * 0.01, color );

		color[ 0 ] = scr_conBarColorRed->value;
		color[ 1 ] = scr_conBarColorGreen->value;
		color[ 2 ] = scr_conBarColorBlue->value;
		color[ 3 ] = frac * 2 * scr_conBarColorAlpha->value;
		SCR_FillRect( 10, 10, 620, 1, color );  //top
		SCR_FillRect( 10, 460 * scr_conHeight->integer * 0.01 + 10, 621, 1, color );  //bottom
		SCR_FillRect( 10, 10, 1, 460 * scr_conHeight->integer * 0.01, color );  //left
		SCR_FillRect( 630, 10, 1, 460 * scr_conHeight->integer * 0.01, color );  //right
	}

	// draw the version number

	color[ 0 ] = 1.0f;
	color[ 1 ] = 1.0f;
	color[ 2 ] = 1.0f;
	color[ 3 ] = ( scr_conUseOld->integer ? 0.75f : frac * 0.75f );
	re.SetColor( color );

	i = strlen( Q3_VERSION );
	totalwidth = SCR_ConsoleFontStringWidth( Q3_VERSION, i ) + cl_conXOffset->integer;

	if ( !scr_conUseOld->integer )
	{
		totalwidth += 30;
	}

	currentWidthLocation = cls.glconfig.vidWidth - totalwidth;

	for ( x = 0; x < i; x++ )
	{
		int ch = Q_UTF8CodePoint( &Q3_VERSION[ x ] );
		SCR_DrawConsoleFontUnichar( currentWidthLocation, yVer, ch );
		currentWidthLocation += SCR_ConsoleFontUnicharWidth( ch );
	}

	// engine string
	i = strlen( Q3_ENGINE );
	totalwidth = SCR_ConsoleFontStringWidth( Q3_ENGINE, i ) + cl_conXOffset->integer;

	if ( !scr_conUseOld->integer )
	{
		totalwidth += 30;
	}

	currentWidthLocation = cls.glconfig.vidWidth - totalwidth;

	for ( x = 0; x < i; x++ )
	{
		int ch = Q_UTF8CodePoint( &Q3_ENGINE[ x ] );
		SCR_DrawConsoleFontUnichar( currentWidthLocation, yVer + charHeight, ch );
		currentWidthLocation += SCR_ConsoleFontUnicharWidth( ch );
	}

	// draw the input prompt, user text, and cursor if desired
	// moved back here (have observed render issues to do with time taken)
	Con_DrawInput();

	// draw the text
	con.vislines = lines;
	rows = ( lines ) / SCR_ConsoleFontCharHeight() - 3; // rows of text to draw

	if ( scr_conUseOld->integer )
	{
		rows++;
	}

	y = lines - ( SCR_ConsoleFontCharHeight() * 3 ) + 10;

	// draw from the bottom up
	if ( con.display != con.current )
	{
		// draw arrows to show the buffer is backscrolled
		const int hatWidth = SCR_ConsoleFontUnicharWidth( '^' );

		color[ 0 ] = 1.0f;
		color[ 1 ] = 0.0f;
		color[ 2 ] = 0.0f;
		color[ 3 ] = ( scr_conUseOld->integer ? 1.0f : frac * 2.0f );
		re.SetColor( color );

		for ( x = 0; x < con.linewidth - ( scr_conUseOld->integer ? 0 : 4 ); x += 4 )
		{
			SCR_DrawConsoleFontUnichar( con.xadjust + ( x + 1 ) * hatWidth, y, '^' );
		}

		y -= charHeight;
		rows--;
	}

	row = con.display;

	if ( con.x == 0 )
	{
		row--;
	}

	currentColor = 7;
	color[ 0 ] = g_color_table[ currentColor ][ 0 ];
	color[ 1 ] = g_color_table[ currentColor ][ 1 ];
	color[ 2 ] = g_color_table[ currentColor ][ 2 ];
	color[ 3 ] = ( scr_conUseOld->integer ? 1.0f : frac * 2.0f );
	re.SetColor( color );

	for ( i = 0; i < rows; i++, y -= charHeight, row-- )
	{
		conChar_t *text;

		if ( row < 0 )
		{
			break;
		}

		if ( con.current - row >= con.totallines )
		{
			// past scrollback wrap point
			continue;
		}

		text = con.text + CON_LINE( row );

		currentWidthLocation = cl_conXOffset->integer;

		for ( x = 0; x < con.linewidth && text[x].ch; ++x )
		{
			if ( text[ x ].ink != currentColor )
			{
				currentColor = text[ x ].ink;
				color[ 0 ] = g_color_table[ currentColor ][ 0 ];
				color[ 1 ] = g_color_table[ currentColor ][ 1 ];
				color[ 2 ] = g_color_table[ currentColor ][ 2 ];
				color[ 3 ] = ( scr_conUseOld->integer ? 1.0f : frac * 2.0f );
				re.SetColor( color );
			}

			SCR_DrawConsoleFontUnichar( con.xadjust + currentWidthLocation, y, text[ x ].ch );
			currentWidthLocation += SCR_ConsoleFontUnicharWidth( text[ x ].ch );
		}
	}

	re.SetColor( NULL );
}