1
0
Fork 0

Added \con_scale - to scale console font size relative to default smallchar width/height

This commit is contained in:
Eugene 2021-12-10 21:18:25 +02:00
parent b6e44359cb
commit 2bdc3692a7
3 changed files with 46 additions and 29 deletions

View File

@ -71,8 +71,9 @@ console_t con;
cvar_t *con_conspeed;
cvar_t *con_notifytime;
cvar_t *con_scale;
int g_console_field_width = DEFAULT_CONSOLE_WIDTH;
int g_console_field_width;
void Con_Fixup( void );
@ -284,23 +285,25 @@ void Con_CheckResize( void )
short tbuf[CON_TEXTSIZE], *src, *dst;
static int old_width, old_vispage;
int vispage;
float scale;
if ( con.viswidth == cls.glconfig.vidWidth )
if ( con.viswidth == cls.glconfig.vidWidth && !con_scale->modified ) {
return;
}
scale = con_scale->value;
con.viswidth = cls.glconfig.vidWidth;
if ( smallchar_width == 0 ) // might happen on early init
{
smallchar_width = SMALLCHAR_WIDTH;
smallchar_height = SMALLCHAR_HEIGHT;
bigchar_width = BIGCHAR_WIDTH;
bigchar_height = BIGCHAR_HEIGHT;
}
smallchar_width = SMALLCHAR_WIDTH * scale * cls.con_factor;
smallchar_height = SMALLCHAR_HEIGHT * scale * cls.con_factor;
bigchar_width = BIGCHAR_WIDTH * scale * cls.con_factor;
bigchar_height = BIGCHAR_HEIGHT * scale * cls.con_factor;
if ( cls.glconfig.vidWidth == 0 ) // video hasn't been initialized yet
{
width = DEFAULT_CONSOLE_WIDTH;
g_console_field_width = DEFAULT_CONSOLE_WIDTH;
width = DEFAULT_CONSOLE_WIDTH * scale;
con.linewidth = width;
con.totallines = CON_TEXTSIZE / con.linewidth;
con.vispage = 4;
@ -309,7 +312,10 @@ void Con_CheckResize( void )
}
else
{
width = (cls.glconfig.vidWidth / smallchar_width) - 2;
width = ((cls.glconfig.vidWidth / smallchar_width) - 2);
g_console_field_width = width;
g_consoleField.widthInChars = g_console_field_width;
if ( width > MAX_CONSOLE_WIDTH )
width = MAX_CONSOLE_WIDTH;
@ -322,6 +328,7 @@ void Con_CheckResize( void )
oldwidth = con.linewidth;
oldtotallines = con.totallines;
oldcurrent = con.current;
con.linewidth = width;
con.totallines = CON_TEXTSIZE / con.linewidth;
con.vispage = vispage;
@ -360,6 +367,8 @@ void Con_CheckResize( void )
}
con.display = con.current;
con_scale->modified = qfalse;
}
@ -385,6 +394,9 @@ void Con_Init( void )
con_notifytime = Cvar_Get( "con_notifytime", "3", 0 );
con_conspeed = Cvar_Get( "scr_conspeed", "3", 0 );
con_scale = Cvar_Get( "con_scale", "1", CVAR_ARCHIVE_ND );
Cvar_CheckRange( con_scale, "0.5", "8", CV_FLOAT );
Field_Clear( &g_consoleField );
g_consoleField.widthInChars = g_console_field_width;
@ -521,11 +533,16 @@ void CL_ConsolePrint( const char *txt ) {
}
if ( !con.initialized ) {
con.color[0] =
con.color[1] =
static cvar_t null_cvar = { 0 };
con.color[0] =
con.color[1] =
con.color[2] =
con.color[3] = 1.0f;
con.viswidth = -9999;
cls.con_factor = 1.0f;
con_scale = &null_cvar;
con_scale->value = 1.0f;
con_scale->modified = qtrue;
Con_CheckResize();
con.initialized = qtrue;
}
@ -864,6 +881,7 @@ Con_DrawConsole
==================
*/
void Con_DrawConsole( void ) {
// check for console width changes from a vid mode change
Con_CheckResize();

View File

@ -3162,6 +3162,7 @@ CL_InitRenderer
============
*/
static void CL_InitRenderer( void ) {
// this sets up the renderer and calls R_Init
re.BeginRegistration( &cls.glconfig );
@ -3169,7 +3170,10 @@ static void CL_InitRenderer( void ) {
cls.charSetShader = re.RegisterShader( "gfx/2d/bigchars" );
cls.whiteShader = re.RegisterShader( "white" );
cls.consoleShader = re.RegisterShader( "console" );
g_console_field_width = cls.glconfig.vidWidth / smallchar_width - 2;
Con_CheckResize();
g_console_field_width = ((cls.glconfig.vidWidth / smallchar_width)) - 2;
g_consoleField.widthInChars = g_console_field_width;
// for 640x480 virtualized screen
@ -3279,22 +3283,12 @@ Sets console chars height
*/
static void CL_SetScaling( float factor, int captureWidth, int captureHeight ) {
float scale;
int h;
if ( cls.con_factor != factor ) {
// rescale console
con_scale->modified = qtrue;
}
// adjust factor proportionally to FullHD height (1080 pixels), with 1/16 granularity
h = (captureHeight * 16 / 1080);
scale = h / 16.0f;
if ( scale < 1.0f )
scale = 1.0f;
factor *= scale;
// set console scaling
smallchar_width = SMALLCHAR_WIDTH * factor;
smallchar_height = SMALLCHAR_HEIGHT * factor;
bigchar_width = BIGCHAR_WIDTH * factor;
bigchar_height = BIGCHAR_HEIGHT * factor;
cls.con_factor = factor;
// set custom capture resolution
cls.captureWidth = captureWidth;

View File

@ -345,6 +345,8 @@ typedef struct {
int captureWidth;
int captureHeight;
float con_factor;
float scale;
float biasX;
float biasY;
@ -497,6 +499,9 @@ qboolean CL_ValidPakSignature( const byte *data, int len );
//
// console
//
extern cvar_t *con_scale;
void Con_CheckResize( void );
void Con_Init( void );
void Con_Shutdown( void );