From c61417b8e2e453e14e5a0d012910df5062186f2e Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Mon, 15 Apr 2019 22:04:20 -0500 Subject: [PATCH] Add current (custom) resolution to Q3 UI video mode list Custom resolution is displayed when entering system options menu and settings can be changed without being forced to change video resolution. --- code/q3_ui/ui_video.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/code/q3_ui/ui_video.c b/code/q3_ui/ui_video.c index 093b5a2c..536055db 100644 --- a/code/q3_ui/ui_video.c +++ b/code/q3_ui/ui_video.c @@ -358,6 +358,7 @@ static int resToRatio[ MAX_RESOLUTIONS ]; static char resbuf[ MAX_STRING_CHARS ]; static const char* detectedResolutions[ MAX_RESOLUTIONS ]; +static char currentResolution[ 20 ]; static const char** resolutions = builtinResolutions; static qboolean resolutionsDetected = qfalse; @@ -487,7 +488,7 @@ GraphicsOptions_GetResolutions */ static void GraphicsOptions_GetResolutions( void ) { - Q_strncpyz(resbuf, UI_Cvar_VariableString("r_availableModes"), sizeof(resbuf)); + trap_Cvar_VariableStringBuffer("r_availableModes", resbuf, sizeof(resbuf)); if(*resbuf) { char* s = resbuf; @@ -501,11 +502,26 @@ static void GraphicsOptions_GetResolutions( void ) } detectedResolutions[ i ] = NULL; - if( i > 0 ) + // add custom resolution if not in mode list + if ( i < ARRAY_LEN(detectedResolutions)-1 ) { - resolutions = detectedResolutions; - resolutionsDetected = qtrue; + Com_sprintf( currentResolution, sizeof ( currentResolution ), "%dx%d", uis.glconfig.vidWidth, uis.glconfig.vidHeight ); + + for( i = 0; detectedResolutions[ i ]; i++ ) + { + if ( strcmp( detectedResolutions[ i ], currentResolution ) == 0 ) + break; + } + + if ( detectedResolutions[ i ] == NULL ) + { + detectedResolutions[ i++ ] = currentResolution; + detectedResolutions[ i ] = NULL; + } } + + resolutions = detectedResolutions; + resolutionsDetected = qtrue; } }