2
1
Fork 0
mirror of https://github.com/yuzu-emu/yuzu.git synced 2024-07-04 23:31:19 +01:00

yuzu-qt: Implement unspecified screenshot ratio

This commit is contained in:
lat9nq 2023-08-16 00:18:47 -04:00
parent 76a03e99b6
commit 96c98d09cb
4 changed files with 30 additions and 11 deletions

View file

@ -146,7 +146,7 @@ ENUM(AntiAliasing, None, Fxaa, Smaa, MaxEnum);
ENUM(AspectRatio, R16_9, R4_3, R21_9, R16_10, Stretch); ENUM(AspectRatio, R16_9, R4_3, R21_9, R16_10, Stretch);
ENUM(ScreenshotAspectRatio, Auto, R16_9, R4_3, R21_9, R16_10); ENUM(ScreenshotAspectRatio, Auto, Unspecified, R16_9, R4_3, R21_9, R16_10);
template <typename Type> template <typename Type>
inline std::string CanonicalizeEnum(Type id) { inline std::string CanonicalizeEnum(Type id) {

View file

@ -932,9 +932,13 @@ void GRenderWindow::CaptureScreenshot(const QString& screenshot_path) {
: Layout::ScreenUndocked::Height; : Layout::ScreenUndocked::Height;
height *= Settings::values.resolution_info.up_factor; height *= Settings::values.resolution_info.up_factor;
} }
const u32 width = UISettings::CalculateWidth( const auto selected_ratio = UISettings::values.screenshot_aspect_ratio.GetValue();
height, UISettings::ConvertScreenshotRatioToRatio( const u32 width =
UISettings::values.screenshot_aspect_ratio.GetValue())); selected_ratio == Settings::ScreenshotAspectRatio::Unspecified
? UISettings::values.screenshot_width.GetValue()
: UISettings::CalculateWidth(
height, UISettings::ConvertScreenshotRatioToRatio(
UISettings::values.screenshot_aspect_ratio.GetValue()));
return Layout::DefaultFrameLayout(width, height); return Layout::DefaultFrameLayout(width, height);
}()}; }()};

View file

@ -66,9 +66,10 @@ QString GetTranslatedRowTextName(size_t index) {
} }
} // Anonymous namespace } // Anonymous namespace
constexpr static std::array<std::pair<Settings::ScreenshotAspectRatio, std::string>, 5> constexpr static std::array<std::pair<Settings::ScreenshotAspectRatio, std::string>, 6>
screenshot_aspect_ratio_translations = { screenshot_aspect_ratio_translations = {
std::pair{Settings::ScreenshotAspectRatio::Auto, "Auto"}, std::pair{Settings::ScreenshotAspectRatio::Auto, "Auto"},
std::pair{Settings::ScreenshotAspectRatio::Unspecified, "Unspecified"},
std::pair{Settings::ScreenshotAspectRatio::R16_9, "16:9"}, std::pair{Settings::ScreenshotAspectRatio::R16_9, "16:9"},
std::pair{Settings::ScreenshotAspectRatio::R4_3, "4:3"}, std::pair{Settings::ScreenshotAspectRatio::R4_3, "4:3"},
std::pair{Settings::ScreenshotAspectRatio::R21_9, "21:9"}, 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 { try {
return std::stoi(height.toStdString()); return std::stoi(height.toStdString());
} catch (std::invalid_argument& e) { } catch (std::invalid_argument& e) {
@ -168,9 +169,16 @@ ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent)
const auto update_width_text = [this]() { const auto update_width_text = [this]() {
const auto index = ui->screenshot_aspect_ratio->currentIndex(); const auto index = ui->screenshot_aspect_ratio->currentIndex();
const Settings::AspectRatio ratio = UISettings::ConvertScreenshotRatioToRatio( const auto selected_ratio = screenshot_aspect_ratio_translations[index].first;
screenshot_aspect_ratio_translations[index].first); if (selected_ratio == Settings::ScreenshotAspectRatio::Unspecified) {
const auto height = HeightToInt(ui->screenshot_height->currentText()); 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); const auto width = UISettings::CalculateWidth(height, ratio);
if (height == 0) { if (height == 0) {
ui->screenshot_width->setText(QString::fromStdString(fmt::format("Auto"))); ui->screenshot_width->setText(QString::fromStdString(fmt::format("Auto")));
@ -207,10 +215,13 @@ void ConfigureUi::ApplyConfiguration() {
const auto ratio = const auto ratio =
screenshot_aspect_ratio_translations[ui->screenshot_aspect_ratio->currentIndex()].first; screenshot_aspect_ratio_translations[ui->screenshot_aspect_ratio->currentIndex()].first;
UISettings::values.screenshot_aspect_ratio.SetValue(ratio); 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_height.SetValue(height);
UISettings::values.screenshot_width.SetValue( UISettings::values.screenshot_width.SetValue(
UISettings::CalculateWidth(height, UISettings::ConvertScreenshotRatioToRatio(ratio))); ratio == Settings::ScreenshotAspectRatio::Unspecified ? width_readout : calculated_width);
system.ApplySettings(); system.ApplySettings();
} }
@ -245,6 +256,8 @@ void ConfigureUi::SetConfiguration() {
} }
ui->screenshot_height->setCurrentText( ui->screenshot_height->setCurrentText(
QString::fromStdString(fmt::format("{}", UISettings::values.screenshot_height.GetValue()))); 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) { void ConfigureUi::changeEvent(QEvent* event) {

View file

@ -63,6 +63,8 @@ Settings::AspectRatio ConvertScreenshotRatioToRatio(Settings::ScreenshotAspectRa
return Settings::AspectRatio::R21_9; return Settings::AspectRatio::R21_9;
case Settings::ScreenshotAspectRatio::R16_10: case Settings::ScreenshotAspectRatio::R16_10:
return Settings::AspectRatio::R16_10; return Settings::AspectRatio::R16_10;
case Settings::ScreenshotAspectRatio::Unspecified:
break;
} }
return Settings::AspectRatio::R16_9; return Settings::AspectRatio::R16_9;
} }