From f98755c7ce2924ad8d12cea59587164817e54fef Mon Sep 17 00:00:00 2001 From: Noah Metzger Date: Sun, 13 Nov 2022 20:25:19 -0600 Subject: [PATCH] support font scaling in server info page Shrink font if needed to allow large info values to fit on the screen. --- code/common/aspect_correct.c | 17 +++++++++++++++++ code/common/aspect_correct.h | 1 + code/ui/ui_servers2.c | 4 +++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/code/common/aspect_correct.c b/code/common/aspect_correct.c index 8a703e7..fe03d09 100644 --- a/code/common/aspect_correct.c +++ b/code/common/aspect_correct.c @@ -232,6 +232,23 @@ qboolean AspectCorrect_UseCorrectedGunPosition( void ) { } #endif +#ifdef MODULE_UI +/* +================ +AspectCorrect_WidthScale + +Returns the ratio of stretched graphics width to centered width. +================ +*/ +float AspectCorrect_WidthScale( void ) { + if ( ASPECT_CORRECT_ENABLED ) { + return uix.XStretchFactor / uix.XScaledFactor; + } else { + return 1.0f; + } +} +#endif + /* ================ AspectCorrect_RunFrame diff --git a/code/common/aspect_correct.h b/code/common/aspect_correct.h index c6d1ba8..9f564c7 100644 --- a/code/common/aspect_correct.h +++ b/code/common/aspect_correct.h @@ -18,6 +18,7 @@ void AspectCorrect_ResetMode( void ); void AspectCorrect_AdjustFrom640( float *x, float *y, float *w, float *h ); void AspectCorrect_DrawAdjustedStretchPic( float x, float y, float w, float h, float s1, float t1, float s2, float t2, qhandle_t hShader ); qboolean AspectCorrect_UseCorrectedGunPosition( void ); +float AspectCorrect_WidthScale( void ); void AspectCorrect_RunFrame( void ); void AspectCorrect_Shutdown( void ); void AspectCorrect_Init( int width, int height ); diff --git a/code/ui/ui_servers2.c b/code/ui/ui_servers2.c index b973f41..fcdc187 100644 --- a/code/ui/ui_servers2.c +++ b/code/ui/ui_servers2.c @@ -300,7 +300,9 @@ void BrowserServerInfo_RenderInfoField( int *currentLine, const char *key, const char buffer[128]; Com_sprintf( buffer, sizeof( buffer ), "%s:", key ); UI_DrawProportionalString( 375 - 8, yPos, buffer, UI_RIGHT | UI_SMALLFONT | UI_NO_BLACK, colorTable[CT_LTBLUE2] ); - UI_DrawProportionalString( 375 + 8, yPos, value, UI_LEFT | UI_SMALLFONT | UI_NO_BLACK, colorTable[CT_LTGOLD1] ); + // let string use the entire right side of the screen before shrinking + UI_DrawAutoProportionalString( 375 + 8, yPos, value, UI_LEFT | UI_NO_BLACK, colorTable[CT_LTGOLD1], + 320 * AspectCorrect_WidthScale() - ( 375 + 8 - 320 ), 4 ); } }