From d7e926fc6342a28b4441df306b525b1aac016fad Mon Sep 17 00:00:00 2001 From: 7oxicshadow <7oxicshadow@googlemail.com> Date: Sat, 31 Jul 2021 22:38:45 +0100 Subject: [PATCH] ui: Add option for a fixed 16:9 display ratio --- ui/xemu-hud.cc | 2 +- ui/xemu-settings.c | 1 + ui/xemu-settings.h | 1 + ui/xemu.c | 11 +++++++++-- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ui/xemu-hud.cc b/ui/xemu-hud.cc index ab2b764706..d97962c96b 100644 --- a/ui/xemu-hud.cc +++ b/ui/xemu-hud.cc @@ -2118,7 +2118,7 @@ static void ShowMainMenu() nv2a_set_surface_scale_factor(rendering_scale+1); } - if (ImGui::Combo("Scaling Mode", &scaling_mode, "Center\0Scale\0Stretch\0")) { + if (ImGui::Combo("Scaling Mode", &scaling_mode, "Center\0Scale\0Scale (Widescreen 16:9)\0Stretch\0")) { xemu_settings_set_enum(XEMU_SETTINGS_DISPLAY_SCALE, scaling_mode); xemu_settings_save(); } diff --git a/ui/xemu-settings.c b/ui/xemu-settings.c index 71faba5c11..0c0c8ab975 100644 --- a/ui/xemu-settings.c +++ b/ui/xemu-settings.c @@ -81,6 +81,7 @@ struct enum_str_map { static const struct enum_str_map display_scale_map[DISPLAY_SCALE__COUNT+1] = { { DISPLAY_SCALE_CENTER, "center" }, { DISPLAY_SCALE_SCALE, "scale" }, + { DISPLAY_SCALE_WS169, "scale_ws169" }, { DISPLAY_SCALE_STRETCH, "stretch" }, { 0, NULL }, }; diff --git a/ui/xemu-settings.h b/ui/xemu-settings.h index bd0042f01b..2d0b0a7387 100644 --- a/ui/xemu-settings.h +++ b/ui/xemu-settings.h @@ -60,6 +60,7 @@ enum DISPLAY_SCALE { DISPLAY_SCALE_CENTER, DISPLAY_SCALE_SCALE, + DISPLAY_SCALE_WS169, DISPLAY_SCALE_STRETCH, DISPLAY_SCALE__COUNT, DISPLAY_SCALE_INVALID = -1 diff --git a/ui/xemu.c b/ui/xemu.c index 3542316108..8eb7e6d6f3 100644 --- a/ui/xemu.c +++ b/ui/xemu.c @@ -1165,8 +1165,15 @@ void sdl2_gl_refresh(DisplayChangeListener *dcl) scale[0] = (float)tw/(float)ww; scale[1] = (float)th/(float)wh; } else { - // Scale to fit - float t_ratio = (float)tw/(float)th; + float t_ratio; + if (scaling_mode == DISPLAY_SCALE_WS169) { + // Scale to fit window using a fixed 16:9 aspect ratio + t_ratio = 16.0f/9.0f; + } else { + // Scale to fit, preserving framebuffer aspect ratio + t_ratio = (float)tw/(float)th; + } + float w_ratio = (float)ww/(float)wh; if (w_ratio >= t_ratio) { scale[0] = t_ratio/w_ratio;