Merge pull request #3412 from Morph1984/aspect-ratio
GUI: Add aspect ratio dropdown
This commit is contained in:
		
						commit
						72d4c6fee0
					
				@ -27,9 +27,9 @@ FramebufferLayout DefaultFrameLayout(u32 width, u32 height) {
 | 
				
			|||||||
    // so just calculate them both even if the other isn't showing.
 | 
					    // so just calculate them both even if the other isn't showing.
 | 
				
			||||||
    FramebufferLayout res{width, height};
 | 
					    FramebufferLayout res{width, height};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const float emulation_aspect_ratio{static_cast<float>(ScreenUndocked::Height) /
 | 
					    const float window_aspect_ratio = static_cast<float>(height) / width;
 | 
				
			||||||
                                       ScreenUndocked::Width};
 | 
					    const float emulation_aspect_ratio = EmulationAspectRatio(
 | 
				
			||||||
    const auto window_aspect_ratio = static_cast<float>(height) / width;
 | 
					        static_cast<AspectRatio>(Settings::values.aspect_ratio), window_aspect_ratio);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const Common::Rectangle<u32> screen_window_area{0, 0, width, height};
 | 
					    const Common::Rectangle<u32> screen_window_area{0, 0, width, height};
 | 
				
			||||||
    Common::Rectangle<u32> screen = MaxRectangle(screen_window_area, emulation_aspect_ratio);
 | 
					    Common::Rectangle<u32> screen = MaxRectangle(screen_window_area, emulation_aspect_ratio);
 | 
				
			||||||
@ -58,4 +58,19 @@ FramebufferLayout FrameLayoutFromResolutionScale(u32 res_scale) {
 | 
				
			|||||||
    return DefaultFrameLayout(width, height);
 | 
					    return DefaultFrameLayout(width, height);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					float EmulationAspectRatio(AspectRatio aspect, float window_aspect_ratio) {
 | 
				
			||||||
 | 
					    switch (aspect) {
 | 
				
			||||||
 | 
					    case AspectRatio::Default:
 | 
				
			||||||
 | 
					        return static_cast<float>(ScreenUndocked::Height) / ScreenUndocked::Width;
 | 
				
			||||||
 | 
					    case AspectRatio::R4_3:
 | 
				
			||||||
 | 
					        return 3.0f / 4.0f;
 | 
				
			||||||
 | 
					    case AspectRatio::R21_9:
 | 
				
			||||||
 | 
					        return 9.0f / 21.0f;
 | 
				
			||||||
 | 
					    case AspectRatio::StretchToWindow:
 | 
				
			||||||
 | 
					        return window_aspect_ratio;
 | 
				
			||||||
 | 
					    default:
 | 
				
			||||||
 | 
					        return static_cast<float>(ScreenUndocked::Height) / ScreenUndocked::Width;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace Layout
 | 
					} // namespace Layout
 | 
				
			||||||
 | 
				
			|||||||
@ -18,6 +18,13 @@ enum ScreenDocked : u32 {
 | 
				
			|||||||
    HeightDocked = 1080,
 | 
					    HeightDocked = 1080,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					enum class AspectRatio {
 | 
				
			||||||
 | 
					    Default,
 | 
				
			||||||
 | 
					    R4_3,
 | 
				
			||||||
 | 
					    R21_9,
 | 
				
			||||||
 | 
					    StretchToWindow,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Describes the layout of the window framebuffer
 | 
					/// Describes the layout of the window framebuffer
 | 
				
			||||||
struct FramebufferLayout {
 | 
					struct FramebufferLayout {
 | 
				
			||||||
    u32 width{ScreenUndocked::Width};
 | 
					    u32 width{ScreenUndocked::Width};
 | 
				
			||||||
@ -48,4 +55,12 @@ FramebufferLayout DefaultFrameLayout(u32 width, u32 height);
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
FramebufferLayout FrameLayoutFromResolutionScale(u32 res_scale);
 | 
					FramebufferLayout FrameLayoutFromResolutionScale(u32 res_scale);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Convenience method to determine emulation aspect ratio
 | 
				
			||||||
 | 
					 * @param aspect Represents the index of aspect ratio stored in Settings::values.aspect_ratio
 | 
				
			||||||
 | 
					 * @param window_aspect_ratio Current window aspect ratio
 | 
				
			||||||
 | 
					 * @return Emulation render window aspect ratio
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					float EmulationAspectRatio(AspectRatio aspect, float window_aspect_ratio);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace Layout
 | 
					} // namespace Layout
 | 
				
			||||||
 | 
				
			|||||||
@ -429,6 +429,7 @@ struct Values {
 | 
				
			|||||||
    int vulkan_device;
 | 
					    int vulkan_device;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    float resolution_factor;
 | 
					    float resolution_factor;
 | 
				
			||||||
 | 
					    int aspect_ratio;
 | 
				
			||||||
    bool use_frame_limit;
 | 
					    bool use_frame_limit;
 | 
				
			||||||
    u16 frame_limit;
 | 
					    u16 frame_limit;
 | 
				
			||||||
    bool use_disk_shader_cache;
 | 
					    bool use_disk_shader_cache;
 | 
				
			||||||
 | 
				
			|||||||
@ -630,6 +630,7 @@ void Config::ReadRendererValues() {
 | 
				
			|||||||
    Settings::values.vulkan_device = ReadSetting(QStringLiteral("vulkan_device"), 0).toInt();
 | 
					    Settings::values.vulkan_device = ReadSetting(QStringLiteral("vulkan_device"), 0).toInt();
 | 
				
			||||||
    Settings::values.resolution_factor =
 | 
					    Settings::values.resolution_factor =
 | 
				
			||||||
        ReadSetting(QStringLiteral("resolution_factor"), 1.0).toFloat();
 | 
					        ReadSetting(QStringLiteral("resolution_factor"), 1.0).toFloat();
 | 
				
			||||||
 | 
					    Settings::values.aspect_ratio = ReadSetting(QStringLiteral("aspect_ratio"), 0).toInt();
 | 
				
			||||||
    Settings::values.use_frame_limit =
 | 
					    Settings::values.use_frame_limit =
 | 
				
			||||||
        ReadSetting(QStringLiteral("use_frame_limit"), true).toBool();
 | 
					        ReadSetting(QStringLiteral("use_frame_limit"), true).toBool();
 | 
				
			||||||
    Settings::values.frame_limit = ReadSetting(QStringLiteral("frame_limit"), 100).toInt();
 | 
					    Settings::values.frame_limit = ReadSetting(QStringLiteral("frame_limit"), 100).toInt();
 | 
				
			||||||
@ -1064,6 +1065,7 @@ void Config::SaveRendererValues() {
 | 
				
			|||||||
    WriteSetting(QStringLiteral("vulkan_device"), Settings::values.vulkan_device, 0);
 | 
					    WriteSetting(QStringLiteral("vulkan_device"), Settings::values.vulkan_device, 0);
 | 
				
			||||||
    WriteSetting(QStringLiteral("resolution_factor"),
 | 
					    WriteSetting(QStringLiteral("resolution_factor"),
 | 
				
			||||||
                 static_cast<double>(Settings::values.resolution_factor), 1.0);
 | 
					                 static_cast<double>(Settings::values.resolution_factor), 1.0);
 | 
				
			||||||
 | 
					    WriteSetting(QStringLiteral("aspect_ratio"), Settings::values.aspect_ratio, 0);
 | 
				
			||||||
    WriteSetting(QStringLiteral("use_frame_limit"), Settings::values.use_frame_limit, true);
 | 
					    WriteSetting(QStringLiteral("use_frame_limit"), Settings::values.use_frame_limit, true);
 | 
				
			||||||
    WriteSetting(QStringLiteral("frame_limit"), Settings::values.frame_limit, 100);
 | 
					    WriteSetting(QStringLiteral("frame_limit"), Settings::values.frame_limit, 100);
 | 
				
			||||||
    WriteSetting(QStringLiteral("use_disk_shader_cache"), Settings::values.use_disk_shader_cache,
 | 
					    WriteSetting(QStringLiteral("use_disk_shader_cache"), Settings::values.use_disk_shader_cache,
 | 
				
			||||||
 | 
				
			|||||||
@ -97,6 +97,7 @@ void ConfigureGraphics::SetConfiguration() {
 | 
				
			|||||||
    ui->api->setCurrentIndex(static_cast<int>(Settings::values.renderer_backend));
 | 
					    ui->api->setCurrentIndex(static_cast<int>(Settings::values.renderer_backend));
 | 
				
			||||||
    ui->resolution_factor_combobox->setCurrentIndex(
 | 
					    ui->resolution_factor_combobox->setCurrentIndex(
 | 
				
			||||||
        static_cast<int>(FromResolutionFactor(Settings::values.resolution_factor)));
 | 
					        static_cast<int>(FromResolutionFactor(Settings::values.resolution_factor)));
 | 
				
			||||||
 | 
					    ui->aspect_ratio_combobox->setCurrentIndex(Settings::values.aspect_ratio);
 | 
				
			||||||
    ui->use_disk_shader_cache->setEnabled(runtime_lock);
 | 
					    ui->use_disk_shader_cache->setEnabled(runtime_lock);
 | 
				
			||||||
    ui->use_disk_shader_cache->setChecked(Settings::values.use_disk_shader_cache);
 | 
					    ui->use_disk_shader_cache->setChecked(Settings::values.use_disk_shader_cache);
 | 
				
			||||||
    ui->use_accurate_gpu_emulation->setChecked(Settings::values.use_accurate_gpu_emulation);
 | 
					    ui->use_accurate_gpu_emulation->setChecked(Settings::values.use_accurate_gpu_emulation);
 | 
				
			||||||
@ -114,6 +115,7 @@ void ConfigureGraphics::ApplyConfiguration() {
 | 
				
			|||||||
    Settings::values.vulkan_device = vulkan_device;
 | 
					    Settings::values.vulkan_device = vulkan_device;
 | 
				
			||||||
    Settings::values.resolution_factor =
 | 
					    Settings::values.resolution_factor =
 | 
				
			||||||
        ToResolutionFactor(static_cast<Resolution>(ui->resolution_factor_combobox->currentIndex()));
 | 
					        ToResolutionFactor(static_cast<Resolution>(ui->resolution_factor_combobox->currentIndex()));
 | 
				
			||||||
 | 
					    Settings::values.aspect_ratio = ui->aspect_ratio_combobox->currentIndex();
 | 
				
			||||||
    Settings::values.use_disk_shader_cache = ui->use_disk_shader_cache->isChecked();
 | 
					    Settings::values.use_disk_shader_cache = ui->use_disk_shader_cache->isChecked();
 | 
				
			||||||
    Settings::values.use_accurate_gpu_emulation = ui->use_accurate_gpu_emulation->isChecked();
 | 
					    Settings::values.use_accurate_gpu_emulation = ui->use_accurate_gpu_emulation->isChecked();
 | 
				
			||||||
    Settings::values.use_asynchronous_gpu_emulation =
 | 
					    Settings::values.use_asynchronous_gpu_emulation =
 | 
				
			||||||
 | 
				
			|||||||
@ -138,6 +138,41 @@
 | 
				
			|||||||
          </item>
 | 
					          </item>
 | 
				
			||||||
         </layout>
 | 
					         </layout>
 | 
				
			||||||
        </item>
 | 
					        </item>
 | 
				
			||||||
 | 
					        <item>
 | 
				
			||||||
 | 
					         <layout class="QHBoxLayout" name="horizontalLayout_6">
 | 
				
			||||||
 | 
					          <item>
 | 
				
			||||||
 | 
					           <widget class="QLabel" name="ar_label">
 | 
				
			||||||
 | 
					            <property name="text">
 | 
				
			||||||
 | 
					             <string>Aspect Ratio:</string>
 | 
				
			||||||
 | 
					            </property>
 | 
				
			||||||
 | 
					           </widget>
 | 
				
			||||||
 | 
					          </item>
 | 
				
			||||||
 | 
					          <item>
 | 
				
			||||||
 | 
					           <widget class="QComboBox" name="aspect_ratio_combobox">
 | 
				
			||||||
 | 
					            <item>
 | 
				
			||||||
 | 
					             <property name="text">
 | 
				
			||||||
 | 
					              <string>Default (16:9)</string>
 | 
				
			||||||
 | 
					             </property>
 | 
				
			||||||
 | 
					            </item>
 | 
				
			||||||
 | 
					            <item>
 | 
				
			||||||
 | 
					             <property name="text">
 | 
				
			||||||
 | 
					              <string>Force 4:3</string>
 | 
				
			||||||
 | 
					             </property>
 | 
				
			||||||
 | 
					            </item>
 | 
				
			||||||
 | 
					            <item>
 | 
				
			||||||
 | 
					             <property name="text">
 | 
				
			||||||
 | 
					              <string>Force 21:9</string>
 | 
				
			||||||
 | 
					             </property>
 | 
				
			||||||
 | 
					            </item>
 | 
				
			||||||
 | 
					            <item>
 | 
				
			||||||
 | 
					             <property name="text">
 | 
				
			||||||
 | 
					              <string>Stretch to Window</string>
 | 
				
			||||||
 | 
					             </property>
 | 
				
			||||||
 | 
					            </item>
 | 
				
			||||||
 | 
					           </widget>
 | 
				
			||||||
 | 
					          </item>
 | 
				
			||||||
 | 
					         </layout>
 | 
				
			||||||
 | 
					        </item>
 | 
				
			||||||
        <item>
 | 
					        <item>
 | 
				
			||||||
         <layout class="QHBoxLayout" name="horizontalLayout_3">
 | 
					         <layout class="QHBoxLayout" name="horizontalLayout_3">
 | 
				
			||||||
          <item>
 | 
					          <item>
 | 
				
			||||||
 | 
				
			|||||||
@ -379,6 +379,8 @@ void Config::ReadValues() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    Settings::values.resolution_factor =
 | 
					    Settings::values.resolution_factor =
 | 
				
			||||||
        static_cast<float>(sdl2_config->GetReal("Renderer", "resolution_factor", 1.0));
 | 
					        static_cast<float>(sdl2_config->GetReal("Renderer", "resolution_factor", 1.0));
 | 
				
			||||||
 | 
					    Settings::values.aspect_ratio =
 | 
				
			||||||
 | 
					        static_cast<int>(sdl2_config->GetInteger("Renderer", "aspect_ratio", 0));
 | 
				
			||||||
    Settings::values.use_frame_limit = sdl2_config->GetBoolean("Renderer", "use_frame_limit", true);
 | 
					    Settings::values.use_frame_limit = sdl2_config->GetBoolean("Renderer", "use_frame_limit", true);
 | 
				
			||||||
    Settings::values.frame_limit =
 | 
					    Settings::values.frame_limit =
 | 
				
			||||||
        static_cast<u16>(sdl2_config->GetInteger("Renderer", "frame_limit", 100));
 | 
					        static_cast<u16>(sdl2_config->GetInteger("Renderer", "frame_limit", 100));
 | 
				
			||||||
 | 
				
			|||||||
@ -122,6 +122,10 @@ use_shader_jit =
 | 
				
			|||||||
# factor for the Switch resolution
 | 
					# factor for the Switch resolution
 | 
				
			||||||
resolution_factor =
 | 
					resolution_factor =
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Aspect ratio
 | 
				
			||||||
 | 
					# 0: Default (16:9), 1: Force 4:3, 2: Force 21:9, 3: Stretch to Window
 | 
				
			||||||
 | 
					aspect_ratio =
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Whether to enable V-Sync (caps the framerate at 60FPS) or not.
 | 
					# Whether to enable V-Sync (caps the framerate at 60FPS) or not.
 | 
				
			||||||
# 0 (default): Off, 1: On
 | 
					# 0 (default): Off, 1: On
 | 
				
			||||||
use_vsync =
 | 
					use_vsync =
 | 
				
			||||||
 | 
				
			|||||||
@ -118,6 +118,8 @@ void Config::ReadValues() {
 | 
				
			|||||||
    // Renderer
 | 
					    // Renderer
 | 
				
			||||||
    Settings::values.resolution_factor =
 | 
					    Settings::values.resolution_factor =
 | 
				
			||||||
        static_cast<float>(sdl2_config->GetReal("Renderer", "resolution_factor", 1.0));
 | 
					        static_cast<float>(sdl2_config->GetReal("Renderer", "resolution_factor", 1.0));
 | 
				
			||||||
 | 
					    Settings::values.aspect_ratio =
 | 
				
			||||||
 | 
					        static_cast<int>(sdl2_config->GetInteger("Renderer", "aspect_ratio", 0));
 | 
				
			||||||
    Settings::values.use_frame_limit = false;
 | 
					    Settings::values.use_frame_limit = false;
 | 
				
			||||||
    Settings::values.frame_limit = 100;
 | 
					    Settings::values.frame_limit = 100;
 | 
				
			||||||
    Settings::values.use_disk_shader_cache =
 | 
					    Settings::values.use_disk_shader_cache =
 | 
				
			||||||
 | 
				
			|||||||
@ -26,6 +26,10 @@ use_shader_jit =
 | 
				
			|||||||
# factor for the Switch resolution
 | 
					# factor for the Switch resolution
 | 
				
			||||||
resolution_factor =
 | 
					resolution_factor =
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Aspect ratio
 | 
				
			||||||
 | 
					# 0: Default (16:9), 1: Force 4:3, 2: Force 21:9, 3: Stretch to Window
 | 
				
			||||||
 | 
					aspect_ratio =
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Whether to enable V-Sync (caps the framerate at 60FPS) or not.
 | 
					# Whether to enable V-Sync (caps the framerate at 60FPS) or not.
 | 
				
			||||||
# 0 (default): Off, 1: On
 | 
					# 0 (default): Off, 1: On
 | 
				
			||||||
use_vsync =
 | 
					use_vsync =
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user