From d9275b77570562a94c726f3fe630886c96850396 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Tue, 15 Aug 2023 22:42:28 -0400 Subject: yuzu-qt: Enable specifying screenshot resolution --- src/yuzu/configuration/configure_ui.cpp | 93 ++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 2 deletions(-) (limited to 'src/yuzu/configuration/configure_ui.cpp') diff --git a/src/yuzu/configuration/configure_ui.cpp b/src/yuzu/configuration/configure_ui.cpp index 2ebb80302..3c99c5709 100644 --- a/src/yuzu/configuration/configure_ui.cpp +++ b/src/yuzu/configuration/configure_ui.cpp @@ -1,18 +1,30 @@ // SPDX-FileCopyrightText: 2016 Citra Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include "yuzu/configuration/configure_ui.h" + #include +#include +#include +#include #include -#include +#include +#include +#include #include +#include +#include +#include +#include + #include "common/common_types.h" #include "common/fs/path_util.h" #include "common/logging/log.h" #include "common/settings.h" +#include "common/settings_enums.h" #include "core/core.h" #include "ui_configure_ui.h" -#include "yuzu/configuration/configure_ui.h" #include "yuzu/uisettings.h" namespace { @@ -54,6 +66,52 @@ QString GetTranslatedRowTextName(size_t index) { } } // Anonymous namespace +constexpr static std::array, 5> + screenshot_aspect_ratio_translations = { + std::pair{Settings::ScreenshotAspectRatio::Auto, "Auto"}, + std::pair{Settings::ScreenshotAspectRatio::R16_9, "16:9"}, + std::pair{Settings::ScreenshotAspectRatio::R4_3, "4:3"}, + std::pair{Settings::ScreenshotAspectRatio::R21_9, "21:9"}, + std::pair{Settings::ScreenshotAspectRatio::R16_10, "16:10"}, +}; + +static void PopulateAspectRatioComboBox(QComboBox* screenshot_aspect_ratio) { + screenshot_aspect_ratio->clear(); + + for (const auto& [value, name] : screenshot_aspect_ratio_translations) { + screenshot_aspect_ratio->addItem(QString::fromStdString(name)); + } +} + +static void PopulateResolutionComboBox(QComboBox* screenshot_height) { + screenshot_height->clear(); + + const auto& enumeration = + Settings::EnumMetadata::Canonicalizations(); + Settings::ResolutionScalingInfo info{}; + std::set resolutions{}; + for (const auto& [name, value] : enumeration) { + Settings::TranslateResolutionInfo(value, info); + u32 height_undocked = 720 * info.up_factor; + u32 height_docked = 1080 * info.up_factor; + resolutions.emplace(height_undocked); + resolutions.emplace(height_docked); + } + + screenshot_height->addItem(QStringLiteral("0")); + for (const auto res : resolutions) { + screenshot_height->addItem(QString::fromStdString(std::to_string(res))); + } +} + +static u32 HeightToInt(const QString& height) { + try { + return std::stoi(height.toStdString()); + } catch (std::invalid_argument& e) { + return 0; + } +} + ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent) : QWidget(parent), ui{std::make_unique()}, system{system_} { ui->setupUi(this); @@ -68,6 +126,9 @@ ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent) InitializeIconSizeComboBox(); InitializeRowComboBoxes(); + PopulateAspectRatioComboBox(ui->screenshot_aspect_ratio); + PopulateResolutionComboBox(ui->screenshot_height); + SetConfiguration(); // Force game list reload if any of the relevant settings are changed. @@ -104,6 +165,25 @@ ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent) ui->screenshot_path_edit->setText(dir); } }); + + const auto update_height_text = [this]() { + const auto index = ui->screenshot_aspect_ratio->currentIndex(); + const Settings::AspectRatio ratio = UISettings::ConvertScreenshotRatioToRatio( + screenshot_aspect_ratio_translations[index].first); + const auto height = HeightToInt(ui->screenshot_height->currentText()); + const auto width = UISettings::CalculateWidth(height, ratio); + if (height == 0) { + ui->screenshot_width->setText(QString::fromStdString(fmt::format("Auto"))); + } else { + ui->screenshot_width->setText(QString::fromStdString(std::to_string(width))); + } + }; + + connect(ui->screenshot_aspect_ratio, QOverload::of(&QComboBox::currentIndexChanged), + update_height_text); + connect(ui->screenshot_height, &QComboBox::currentTextChanged, update_height_text); + + update_height_text(); } ConfigureUi::~ConfigureUi() = default; @@ -123,6 +203,15 @@ void ConfigureUi::ApplyConfiguration() { UISettings::values.enable_screenshot_save_as = ui->enable_screenshot_save_as->isChecked(); Common::FS::SetYuzuPath(Common::FS::YuzuPath::ScreenshotsDir, ui->screenshot_path_edit->text().toStdString()); + + const auto ratio = + screenshot_aspect_ratio_translations[ui->screenshot_aspect_ratio->currentIndex()].first; + UISettings::values.screenshot_aspect_ratio.SetValue(ratio); + const u32 height = HeightToInt(ui->screenshot_height->currentText()); + UISettings::values.screenshot_height.SetValue(height); + UISettings::values.screenshot_width.SetValue( + UISettings::CalculateWidth(height, UISettings::ConvertScreenshotRatioToRatio(ratio))); + system.ApplySettings(); } -- cgit v1.2.3 From 95409c68597c509e9f6ced959a73a41a05de372c Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Tue, 15 Aug 2023 23:08:02 -0400 Subject: configure_ui: Update the screenshots data --- src/yuzu/configuration/configure_ui.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/yuzu/configuration/configure_ui.cpp') diff --git a/src/yuzu/configuration/configure_ui.cpp b/src/yuzu/configuration/configure_ui.cpp index 3c99c5709..77aff01b7 100644 --- a/src/yuzu/configuration/configure_ui.cpp +++ b/src/yuzu/configuration/configure_ui.cpp @@ -166,7 +166,7 @@ ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent) } }); - const auto update_height_text = [this]() { + const auto update_width_text = [this]() { const auto index = ui->screenshot_aspect_ratio->currentIndex(); const Settings::AspectRatio ratio = UISettings::ConvertScreenshotRatioToRatio( screenshot_aspect_ratio_translations[index].first); @@ -180,10 +180,10 @@ ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent) }; connect(ui->screenshot_aspect_ratio, QOverload::of(&QComboBox::currentIndexChanged), - update_height_text); - connect(ui->screenshot_height, &QComboBox::currentTextChanged, update_height_text); + update_width_text); + connect(ui->screenshot_height, &QComboBox::currentTextChanged, update_width_text); - update_height_text(); + update_width_text(); } ConfigureUi::~ConfigureUi() = default; @@ -236,6 +236,15 @@ void ConfigureUi::SetConfiguration() { UISettings::values.enable_screenshot_save_as.GetValue()); ui->screenshot_path_edit->setText(QString::fromStdString( Common::FS::GetYuzuPathString(Common::FS::YuzuPath::ScreenshotsDir))); + + for (u32 i = 0; i < screenshot_aspect_ratio_translations.size(); i++) { + const auto ratio = screenshot_aspect_ratio_translations[i].first; + if (ratio == UISettings::values.screenshot_aspect_ratio.GetValue()) { + ui->screenshot_aspect_ratio->setCurrentIndex(i); + } + } + ui->screenshot_height->setCurrentText( + QString::fromStdString(fmt::format("{}", UISettings::values.screenshot_height.GetValue()))); } void ConfigureUi::changeEvent(QEvent* event) { -- cgit v1.2.3 From 96c98d09cb9200c9b623404381c33b3379411eeb Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Wed, 16 Aug 2023 00:18:47 -0400 Subject: yuzu-qt: Implement unspecified screenshot ratio --- src/yuzu/configuration/configure_ui.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'src/yuzu/configuration/configure_ui.cpp') diff --git a/src/yuzu/configuration/configure_ui.cpp b/src/yuzu/configuration/configure_ui.cpp index 77aff01b7..206af81a8 100644 --- a/src/yuzu/configuration/configure_ui.cpp +++ b/src/yuzu/configuration/configure_ui.cpp @@ -66,9 +66,10 @@ QString GetTranslatedRowTextName(size_t index) { } } // Anonymous namespace -constexpr static std::array, 5> +constexpr static std::array, 6> screenshot_aspect_ratio_translations = { std::pair{Settings::ScreenshotAspectRatio::Auto, "Auto"}, + std::pair{Settings::ScreenshotAspectRatio::Unspecified, "Unspecified"}, std::pair{Settings::ScreenshotAspectRatio::R16_9, "16:9"}, std::pair{Settings::ScreenshotAspectRatio::R4_3, "4:3"}, std::pair{Settings::ScreenshotAspectRatio::R21_9, "21:9"}, @@ -104,7 +105,7 @@ static void PopulateResolutionComboBox(QComboBox* screenshot_height) { } } -static u32 HeightToInt(const QString& height) { +static u32 ScreenshotDimensionToInt(const QString& height) { try { return std::stoi(height.toStdString()); } catch (std::invalid_argument& e) { @@ -168,9 +169,16 @@ ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent) const auto update_width_text = [this]() { const auto index = ui->screenshot_aspect_ratio->currentIndex(); - const Settings::AspectRatio ratio = UISettings::ConvertScreenshotRatioToRatio( - screenshot_aspect_ratio_translations[index].first); - const auto height = HeightToInt(ui->screenshot_height->currentText()); + const auto selected_ratio = screenshot_aspect_ratio_translations[index].first; + if (selected_ratio == Settings::ScreenshotAspectRatio::Unspecified) { + ui->screenshot_width->setReadOnly(false); + return; + } else { + ui->screenshot_width->setReadOnly(true); + } + const Settings::AspectRatio ratio = + UISettings::ConvertScreenshotRatioToRatio(selected_ratio); + const auto height = ScreenshotDimensionToInt(ui->screenshot_height->currentText()); const auto width = UISettings::CalculateWidth(height, ratio); if (height == 0) { ui->screenshot_width->setText(QString::fromStdString(fmt::format("Auto"))); @@ -207,10 +215,13 @@ void ConfigureUi::ApplyConfiguration() { const auto ratio = screenshot_aspect_ratio_translations[ui->screenshot_aspect_ratio->currentIndex()].first; UISettings::values.screenshot_aspect_ratio.SetValue(ratio); - const u32 height = HeightToInt(ui->screenshot_height->currentText()); + const u32 height = ScreenshotDimensionToInt(ui->screenshot_height->currentText()); + const u32 calculated_width = + UISettings::CalculateWidth(height, UISettings::ConvertScreenshotRatioToRatio(ratio)); + const u32 width_readout = ScreenshotDimensionToInt(ui->screenshot_width->text()); UISettings::values.screenshot_height.SetValue(height); UISettings::values.screenshot_width.SetValue( - UISettings::CalculateWidth(height, UISettings::ConvertScreenshotRatioToRatio(ratio))); + ratio == Settings::ScreenshotAspectRatio::Unspecified ? width_readout : calculated_width); system.ApplySettings(); } @@ -245,6 +256,8 @@ void ConfigureUi::SetConfiguration() { } ui->screenshot_height->setCurrentText( QString::fromStdString(fmt::format("{}", UISettings::values.screenshot_height.GetValue()))); + ui->screenshot_width->setText( + QString::fromStdString(fmt::format("{}", UISettings::values.screenshot_width.GetValue()))); } void ConfigureUi::changeEvent(QEvent* event) { -- cgit v1.2.3 From 6fe51b48e960e81b1304d833b2d69b468a4a238a Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Wed, 16 Aug 2023 16:12:42 -0400 Subject: yuzu-qt: Screenshots depend more on the graphics settings --- src/yuzu/configuration/configure_ui.cpp | 113 +++++++++++++------------------- 1 file changed, 47 insertions(+), 66 deletions(-) (limited to 'src/yuzu/configuration/configure_ui.cpp') diff --git a/src/yuzu/configuration/configure_ui.cpp b/src/yuzu/configuration/configure_ui.cpp index 206af81a8..8d298993a 100644 --- a/src/yuzu/configuration/configure_ui.cpp +++ b/src/yuzu/configuration/configure_ui.cpp @@ -24,6 +24,7 @@ #include "common/settings.h" #include "common/settings_enums.h" #include "core/core.h" +#include "core/frontend/framebuffer_layout.h" #include "ui_configure_ui.h" #include "yuzu/uisettings.h" @@ -66,40 +67,27 @@ QString GetTranslatedRowTextName(size_t index) { } } // Anonymous namespace -constexpr static std::array, 6> - screenshot_aspect_ratio_translations = { - std::pair{Settings::ScreenshotAspectRatio::Auto, "Auto"}, - std::pair{Settings::ScreenshotAspectRatio::Unspecified, "Unspecified"}, - std::pair{Settings::ScreenshotAspectRatio::R16_9, "16:9"}, - std::pair{Settings::ScreenshotAspectRatio::R4_3, "4:3"}, - std::pair{Settings::ScreenshotAspectRatio::R21_9, "21:9"}, - std::pair{Settings::ScreenshotAspectRatio::R16_10, "16:10"}, -}; - -static void PopulateAspectRatioComboBox(QComboBox* screenshot_aspect_ratio) { - screenshot_aspect_ratio->clear(); - - for (const auto& [value, name] : screenshot_aspect_ratio_translations) { - screenshot_aspect_ratio->addItem(QString::fromStdString(name)); - } +static float GetUpFactor(Settings::ResolutionSetup res_setup) { + Settings::ResolutionScalingInfo info{}; + Settings::TranslateResolutionInfo(res_setup, info); + return info.up_factor; } -static void PopulateResolutionComboBox(QComboBox* screenshot_height) { +static void PopulateResolutionComboBox(QComboBox* screenshot_height, QWidget* parent) { screenshot_height->clear(); const auto& enumeration = Settings::EnumMetadata::Canonicalizations(); - Settings::ResolutionScalingInfo info{}; std::set resolutions{}; for (const auto& [name, value] : enumeration) { - Settings::TranslateResolutionInfo(value, info); - u32 height_undocked = 720 * info.up_factor; - u32 height_docked = 1080 * info.up_factor; + const float up_factor = GetUpFactor(value); + u32 height_undocked = Layout::ScreenUndocked::Height * up_factor; + u32 height_docked = Layout::ScreenDocked::Height * up_factor; resolutions.emplace(height_undocked); resolutions.emplace(height_docked); } - screenshot_height->addItem(QStringLiteral("0")); + screenshot_height->addItem(parent->tr("Auto", "Screenshot height option")); for (const auto res : resolutions) { screenshot_height->addItem(QString::fromStdString(std::to_string(res))); } @@ -114,7 +102,9 @@ static u32 ScreenshotDimensionToInt(const QString& height) { } ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent) - : QWidget(parent), ui{std::make_unique()}, system{system_} { + : QWidget(parent), ui{std::make_unique()}, + ratio{Settings::values.aspect_ratio.GetValue()}, + resolution_setting{Settings::values.resolution_setup.GetValue()}, system{system_} { ui->setupUi(this); InitializeLanguageComboBox(); @@ -127,8 +117,7 @@ ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent) InitializeIconSizeComboBox(); InitializeRowComboBoxes(); - PopulateAspectRatioComboBox(ui->screenshot_aspect_ratio); - PopulateResolutionComboBox(ui->screenshot_height); + PopulateResolutionComboBox(ui->screenshot_height, this); SetConfiguration(); @@ -167,31 +156,9 @@ ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent) } }); - const auto update_width_text = [this]() { - const auto index = ui->screenshot_aspect_ratio->currentIndex(); - const auto selected_ratio = screenshot_aspect_ratio_translations[index].first; - if (selected_ratio == Settings::ScreenshotAspectRatio::Unspecified) { - ui->screenshot_width->setReadOnly(false); - return; - } else { - ui->screenshot_width->setReadOnly(true); - } - const Settings::AspectRatio ratio = - UISettings::ConvertScreenshotRatioToRatio(selected_ratio); - const auto height = ScreenshotDimensionToInt(ui->screenshot_height->currentText()); - const auto width = UISettings::CalculateWidth(height, ratio); - if (height == 0) { - ui->screenshot_width->setText(QString::fromStdString(fmt::format("Auto"))); - } else { - ui->screenshot_width->setText(QString::fromStdString(std::to_string(width))); - } - }; + connect(ui->screenshot_height, &QComboBox::currentTextChanged, [this]() { UpdateWidthText(); }); - connect(ui->screenshot_aspect_ratio, QOverload::of(&QComboBox::currentIndexChanged), - update_width_text); - connect(ui->screenshot_height, &QComboBox::currentTextChanged, update_width_text); - - update_width_text(); + UpdateWidthText(); } ConfigureUi::~ConfigureUi() = default; @@ -212,16 +179,8 @@ void ConfigureUi::ApplyConfiguration() { Common::FS::SetYuzuPath(Common::FS::YuzuPath::ScreenshotsDir, ui->screenshot_path_edit->text().toStdString()); - const auto ratio = - screenshot_aspect_ratio_translations[ui->screenshot_aspect_ratio->currentIndex()].first; - UISettings::values.screenshot_aspect_ratio.SetValue(ratio); const u32 height = ScreenshotDimensionToInt(ui->screenshot_height->currentText()); - const u32 calculated_width = - UISettings::CalculateWidth(height, UISettings::ConvertScreenshotRatioToRatio(ratio)); - const u32 width_readout = ScreenshotDimensionToInt(ui->screenshot_width->text()); UISettings::values.screenshot_height.SetValue(height); - UISettings::values.screenshot_width.SetValue( - ratio == Settings::ScreenshotAspectRatio::Unspecified ? width_readout : calculated_width); system.ApplySettings(); } @@ -248,16 +207,12 @@ void ConfigureUi::SetConfiguration() { ui->screenshot_path_edit->setText(QString::fromStdString( Common::FS::GetYuzuPathString(Common::FS::YuzuPath::ScreenshotsDir))); - for (u32 i = 0; i < screenshot_aspect_ratio_translations.size(); i++) { - const auto ratio = screenshot_aspect_ratio_translations[i].first; - if (ratio == UISettings::values.screenshot_aspect_ratio.GetValue()) { - ui->screenshot_aspect_ratio->setCurrentIndex(i); - } + const auto height = UISettings::values.screenshot_height.GetValue(); + if (height == 0) { + ui->screenshot_height->setCurrentIndex(0); + } else { + ui->screenshot_height->setCurrentText(QStringLiteral("%1").arg(height)); } - ui->screenshot_height->setCurrentText( - QString::fromStdString(fmt::format("{}", UISettings::values.screenshot_height.GetValue()))); - ui->screenshot_width->setText( - QString::fromStdString(fmt::format("{}", UISettings::values.screenshot_width.GetValue()))); } void ConfigureUi::changeEvent(QEvent* event) { @@ -428,3 +383,29 @@ void ConfigureUi::OnLanguageChanged(int index) { emit LanguageChanged(ui->language_combobox->itemData(index).toString()); } + +void ConfigureUi::UpdateWidthText() { + const u32 height = ScreenshotDimensionToInt(ui->screenshot_height->currentText()); + const u32 width = UISettings::CalculateWidth(height, ratio); + if (height == 0) { + const auto up_factor = GetUpFactor(resolution_setting); + const u32 height_docked = Layout::ScreenDocked::Height * up_factor; + const u32 width_docked = UISettings::CalculateWidth(height_docked, ratio); + const u32 height_undocked = Layout::ScreenUndocked::Height * up_factor; + const u32 width_undocked = UISettings::CalculateWidth(height_undocked, ratio); + ui->screenshot_width->setText(tr("Auto (%1 x %2, %3 x %4)", "Screenshot width value") + .arg(width_undocked) + .arg(height_undocked) + .arg(width_docked) + .arg(height_docked)); + } else { + ui->screenshot_width->setText(QStringLiteral("%1 x").arg(width)); + } +} + +void ConfigureUi::UpdateScreenshotInfo(Settings::AspectRatio ratio_, + Settings::ResolutionSetup resolution_setting_) { + ratio = ratio_; + resolution_setting = resolution_setting_; + UpdateWidthText(); +} -- cgit v1.2.3 From e28b93695096a15aa46eb7ffe9ab66a92d7d8330 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Wed, 16 Aug 2023 16:28:44 -0400 Subject: configure_ui: Silence MSVC warning --- src/yuzu/configuration/configure_ui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/yuzu/configuration/configure_ui.cpp') diff --git a/src/yuzu/configuration/configure_ui.cpp b/src/yuzu/configuration/configure_ui.cpp index 8d298993a..34ab01617 100644 --- a/src/yuzu/configuration/configure_ui.cpp +++ b/src/yuzu/configuration/configure_ui.cpp @@ -96,7 +96,7 @@ static void PopulateResolutionComboBox(QComboBox* screenshot_height, QWidget* pa static u32 ScreenshotDimensionToInt(const QString& height) { try { return std::stoi(height.toStdString()); - } catch (std::invalid_argument& e) { + } catch (std::invalid_argument&) { return 0; } } -- cgit v1.2.3