summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/yuzu/bootmanager.cpp16
-rw-r--r--src/yuzu/configuration/configure_ui.cpp93
-rw-r--r--src/yuzu/configuration/configure_ui.ui51
-rw-r--r--src/yuzu/uisettings.cpp31
-rw-r--r--src/yuzu/uisettings.h10
5 files changed, 198 insertions, 3 deletions
diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp
index bdd1497b5..593e59e8e 100644
--- a/src/yuzu/bootmanager.cpp
+++ b/src/yuzu/bootmanager.cpp
@@ -11,6 +11,8 @@
11#include <glad/glad.h> 11#include <glad/glad.h>
12 12
13#include <QtCore/qglobal.h> 13#include <QtCore/qglobal.h>
14#include "common/settings_enums.h"
15#include "uisettings.h"
14#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) && YUZU_USE_QT_MULTIMEDIA 16#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) && YUZU_USE_QT_MULTIMEDIA
15#include <QCamera> 17#include <QCamera>
16#include <QCameraImageCapture> 18#include <QCameraImageCapture>
@@ -924,7 +926,19 @@ void GRenderWindow::CaptureScreenshot(const QString& screenshot_path) {
924 return; 926 return;
925 } 927 }
926 928
927 const Layout::FramebufferLayout layout{Layout::FrameLayoutFromResolutionScale(res_scale)}; 929 const Layout::FramebufferLayout layout{[res_scale]() {
930 if (UISettings::values.screenshot_height.GetValue() == 0 &&
931 UISettings::values.screenshot_aspect_ratio.GetValue() ==
932 Settings::ScreenshotAspectRatio::Auto) {
933 return Layout::FrameLayoutFromResolutionScale(res_scale);
934 }
935 const u32 height = UISettings::values.screenshot_height.GetValue();
936 const u32 width = UISettings::CalculateWidth(
937 height, UISettings::ConvertScreenshotRatioToRatio(
938 UISettings::values.screenshot_aspect_ratio.GetValue()));
939 return Layout::DefaultFrameLayout(width, height);
940 }()};
941
928 screenshot_image = QImage(QSize(layout.width, layout.height), QImage::Format_RGB32); 942 screenshot_image = QImage(QSize(layout.width, layout.height), QImage::Format_RGB32);
929 renderer.RequestScreenshot( 943 renderer.RequestScreenshot(
930 screenshot_image.bits(), 944 screenshot_image.bits(),
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 @@
1// SPDX-FileCopyrightText: 2016 Citra Emulator Project 1// SPDX-FileCopyrightText: 2016 Citra Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later 2// SPDX-License-Identifier: GPL-2.0-or-later
3 3
4#include "yuzu/configuration/configure_ui.h"
5
4#include <array> 6#include <array>
7#include <set>
8#include <stdexcept>
9#include <string>
5#include <utility> 10#include <utility>
6#include <QFileDialog>
7 11
12#include <QCheckBox>
13#include <QComboBox>
14#include <QCoreApplication>
8#include <QDirIterator> 15#include <QDirIterator>
16#include <QFileDialog>
17#include <QString>
18#include <QToolButton>
19#include <QVariant>
20
9#include "common/common_types.h" 21#include "common/common_types.h"
10#include "common/fs/path_util.h" 22#include "common/fs/path_util.h"
11#include "common/logging/log.h" 23#include "common/logging/log.h"
12#include "common/settings.h" 24#include "common/settings.h"
25#include "common/settings_enums.h"
13#include "core/core.h" 26#include "core/core.h"
14#include "ui_configure_ui.h" 27#include "ui_configure_ui.h"
15#include "yuzu/configuration/configure_ui.h"
16#include "yuzu/uisettings.h" 28#include "yuzu/uisettings.h"
17 29
18namespace { 30namespace {
@@ -54,6 +66,52 @@ QString GetTranslatedRowTextName(size_t index) {
54} 66}
55} // Anonymous namespace 67} // Anonymous namespace
56 68
69constexpr static std::array<std::pair<Settings::ScreenshotAspectRatio, std::string>, 5>
70 screenshot_aspect_ratio_translations = {
71 std::pair{Settings::ScreenshotAspectRatio::Auto, "Auto"},
72 std::pair{Settings::ScreenshotAspectRatio::R16_9, "16:9"},
73 std::pair{Settings::ScreenshotAspectRatio::R4_3, "4:3"},
74 std::pair{Settings::ScreenshotAspectRatio::R21_9, "21:9"},
75 std::pair{Settings::ScreenshotAspectRatio::R16_10, "16:10"},
76};
77
78static void PopulateAspectRatioComboBox(QComboBox* screenshot_aspect_ratio) {
79 screenshot_aspect_ratio->clear();
80
81 for (const auto& [value, name] : screenshot_aspect_ratio_translations) {
82 screenshot_aspect_ratio->addItem(QString::fromStdString(name));
83 }
84}
85
86static void PopulateResolutionComboBox(QComboBox* screenshot_height) {
87 screenshot_height->clear();
88
89 const auto& enumeration =
90 Settings::EnumMetadata<Settings::ResolutionSetup>::Canonicalizations();
91 Settings::ResolutionScalingInfo info{};
92 std::set<u32> resolutions{};
93 for (const auto& [name, value] : enumeration) {
94 Settings::TranslateResolutionInfo(value, info);
95 u32 height_undocked = 720 * info.up_factor;
96 u32 height_docked = 1080 * info.up_factor;
97 resolutions.emplace(height_undocked);
98 resolutions.emplace(height_docked);
99 }
100
101 screenshot_height->addItem(QStringLiteral("0"));
102 for (const auto res : resolutions) {
103 screenshot_height->addItem(QString::fromStdString(std::to_string(res)));
104 }
105}
106
107static u32 HeightToInt(const QString& height) {
108 try {
109 return std::stoi(height.toStdString());
110 } catch (std::invalid_argument& e) {
111 return 0;
112 }
113}
114
57ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent) 115ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent)
58 : QWidget(parent), ui{std::make_unique<Ui::ConfigureUi>()}, system{system_} { 116 : QWidget(parent), ui{std::make_unique<Ui::ConfigureUi>()}, system{system_} {
59 ui->setupUi(this); 117 ui->setupUi(this);
@@ -68,6 +126,9 @@ ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent)
68 InitializeIconSizeComboBox(); 126 InitializeIconSizeComboBox();
69 InitializeRowComboBoxes(); 127 InitializeRowComboBoxes();
70 128
129 PopulateAspectRatioComboBox(ui->screenshot_aspect_ratio);
130 PopulateResolutionComboBox(ui->screenshot_height);
131
71 SetConfiguration(); 132 SetConfiguration();
72 133
73 // Force game list reload if any of the relevant settings are changed. 134 // Force game list reload if any of the relevant settings are changed.
@@ -104,6 +165,25 @@ ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent)
104 ui->screenshot_path_edit->setText(dir); 165 ui->screenshot_path_edit->setText(dir);
105 } 166 }
106 }); 167 });
168
169 const auto update_height_text = [this]() {
170 const auto index = ui->screenshot_aspect_ratio->currentIndex();
171 const Settings::AspectRatio ratio = UISettings::ConvertScreenshotRatioToRatio(
172 screenshot_aspect_ratio_translations[index].first);
173 const auto height = HeightToInt(ui->screenshot_height->currentText());
174 const auto width = UISettings::CalculateWidth(height, ratio);
175 if (height == 0) {
176 ui->screenshot_width->setText(QString::fromStdString(fmt::format("Auto")));
177 } else {
178 ui->screenshot_width->setText(QString::fromStdString(std::to_string(width)));
179 }
180 };
181
182 connect(ui->screenshot_aspect_ratio, QOverload<int>::of(&QComboBox::currentIndexChanged),
183 update_height_text);
184 connect(ui->screenshot_height, &QComboBox::currentTextChanged, update_height_text);
185
186 update_height_text();
107} 187}
108 188
109ConfigureUi::~ConfigureUi() = default; 189ConfigureUi::~ConfigureUi() = default;
@@ -123,6 +203,15 @@ void ConfigureUi::ApplyConfiguration() {
123 UISettings::values.enable_screenshot_save_as = ui->enable_screenshot_save_as->isChecked(); 203 UISettings::values.enable_screenshot_save_as = ui->enable_screenshot_save_as->isChecked();
124 Common::FS::SetYuzuPath(Common::FS::YuzuPath::ScreenshotsDir, 204 Common::FS::SetYuzuPath(Common::FS::YuzuPath::ScreenshotsDir,
125 ui->screenshot_path_edit->text().toStdString()); 205 ui->screenshot_path_edit->text().toStdString());
206
207 const auto ratio =
208 screenshot_aspect_ratio_translations[ui->screenshot_aspect_ratio->currentIndex()].first;
209 UISettings::values.screenshot_aspect_ratio.SetValue(ratio);
210 const u32 height = HeightToInt(ui->screenshot_height->currentText());
211 UISettings::values.screenshot_height.SetValue(height);
212 UISettings::values.screenshot_width.SetValue(
213 UISettings::CalculateWidth(height, UISettings::ConvertScreenshotRatioToRatio(ratio)));
214
126 system.ApplySettings(); 215 system.ApplySettings();
127} 216}
128 217
diff --git a/src/yuzu/configuration/configure_ui.ui b/src/yuzu/configuration/configure_ui.ui
index 10bb27312..906fdd5b3 100644
--- a/src/yuzu/configuration/configure_ui.ui
+++ b/src/yuzu/configuration/configure_ui.ui
@@ -201,6 +201,57 @@
201 </item> 201 </item>
202 </layout> 202 </layout>
203 </item> 203 </item>
204 <item>
205 <layout class="QGridLayout" name="gridLayout">
206 <property name="spacing">
207 <number>6</number>
208 </property>
209 <item row="1" column="0">
210 <widget class="QLabel" name="label_3">
211 <property name="text">
212 <string>Resolution:</string>
213 </property>
214 </widget>
215 </item>
216 <item row="0" column="1">
217 <widget class="QComboBox" name="screenshot_aspect_ratio"/>
218 </item>
219 <item row="0" column="0">
220 <widget class="QLabel" name="label_2">
221 <property name="text">
222 <string>Aspect Ratio:</string>
223 </property>
224 </widget>
225 </item>
226 <item row="1" column="1">
227 <layout class="QHBoxLayout" name="horizontalLayout_5">
228 <item>
229 <widget class="QLineEdit" name="screenshot_width">
230 <property name="enabled">
231 <bool>true</bool>
232 </property>
233 <property name="sizePolicy">
234 <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
235 <horstretch>0</horstretch>
236 <verstretch>0</verstretch>
237 </sizepolicy>
238 </property>
239 <property name="readOnly">
240 <bool>true</bool>
241 </property>
242 </widget>
243 </item>
244 <item>
245 <widget class="QComboBox" name="screenshot_height">
246 <property name="editable">
247 <bool>true</bool>
248 </property>
249 </widget>
250 </item>
251 </layout>
252 </item>
253 </layout>
254 </item>
204 </layout> 255 </layout>
205 </item> 256 </item>
206 </layout> 257 </layout>
diff --git a/src/yuzu/uisettings.cpp b/src/yuzu/uisettings.cpp
index f03dc01dd..3ab0d1b45 100644
--- a/src/yuzu/uisettings.cpp
+++ b/src/yuzu/uisettings.cpp
@@ -36,4 +36,35 @@ bool IsDarkTheme() {
36 36
37Values values = {}; 37Values values = {};
38 38
39u32 CalculateWidth(u32 height, Settings::AspectRatio ratio) {
40 switch (ratio) {
41 case Settings::AspectRatio::R4_3:
42 return height * 4 / 3;
43 case Settings::AspectRatio::R21_9:
44 return height * 21 / 9;
45 case Settings::AspectRatio::R16_10:
46 return height * 16 / 10;
47 case Settings::AspectRatio::R16_9:
48 case Settings::AspectRatio::Stretch:
49 break;
50 }
51 return height * 16 / 9;
52}
53
54Settings::AspectRatio ConvertScreenshotRatioToRatio(Settings::ScreenshotAspectRatio ratio) {
55 switch (ratio) {
56 case Settings::ScreenshotAspectRatio::Auto:
57 return Settings::values.aspect_ratio.GetValue();
58 case Settings::ScreenshotAspectRatio::R16_9:
59 return Settings::AspectRatio::R16_9;
60 case Settings::ScreenshotAspectRatio::R4_3:
61 return Settings::AspectRatio::R4_3;
62 case Settings::ScreenshotAspectRatio::R21_9:
63 return Settings::AspectRatio::R21_9;
64 case Settings::ScreenshotAspectRatio::R16_10:
65 return Settings::AspectRatio::R16_10;
66 }
67 return Settings::AspectRatio::R16_9;
68}
69
39} // namespace UISettings 70} // namespace UISettings
diff --git a/src/yuzu/uisettings.h b/src/yuzu/uisettings.h
index c9c89cee4..7b5d630d7 100644
--- a/src/yuzu/uisettings.h
+++ b/src/yuzu/uisettings.h
@@ -13,6 +13,7 @@
13#include <QVector> 13#include <QVector>
14#include "common/common_types.h" 14#include "common/common_types.h"
15#include "common/settings.h" 15#include "common/settings.h"
16#include "common/settings_enums.h"
16 17
17using Settings::Category; 18using Settings::Category;
18using Settings::Setting; 19using Settings::Setting;
@@ -127,8 +128,14 @@ struct Values {
127 // logging 128 // logging
128 Setting<bool> show_console{linkage, false, "showConsole", Category::Ui}; 129 Setting<bool> show_console{linkage, false, "showConsole", Category::Ui};
129 130
131 // Screenshots
130 Setting<bool> enable_screenshot_save_as{linkage, true, "enable_screenshot_save_as", 132 Setting<bool> enable_screenshot_save_as{linkage, true, "enable_screenshot_save_as",
131 Category::Screenshots}; 133 Category::Screenshots};
134 Setting<u32> screenshot_height{linkage, 0, "screenshot_height", Category::Screenshots};
135 Setting<u32> screenshot_width{linkage, 0, "screenshot_width", Category::Screenshots};
136 Setting<Settings::ScreenshotAspectRatio> screenshot_aspect_ratio{
137 linkage, Settings::ScreenshotAspectRatio::Auto, "screenshot_aspect_ratio",
138 Category::Screenshots};
132 139
133 QString roms_path; 140 QString roms_path;
134 QString symbols_path; 141 QString symbols_path;
@@ -187,6 +194,9 @@ struct Values {
187 194
188extern Values values; 195extern Values values;
189 196
197u32 CalculateWidth(u32 height, Settings::AspectRatio ratio);
198Settings::AspectRatio ConvertScreenshotRatioToRatio(Settings::ScreenshotAspectRatio ratio);
199
190} // namespace UISettings 200} // namespace UISettings
191 201
192Q_DECLARE_METATYPE(UISettings::GameDir*); 202Q_DECLARE_METATYPE(UISettings::GameDir*);