From 4f91b2430f708c4ed5f662588a84009b53adc3cf Mon Sep 17 00:00:00 2001 From: BearOso Date: Sun, 6 Aug 2023 15:59:24 -0500 Subject: [PATCH] Qt: More updates. --- qt/src/EmuCanvasOpenGL.cpp | 2 +- qt/src/EmuCanvasQt.cpp | 2 +- qt/src/EmuCanvasVulkan.cpp | 2 +- qt/src/EmuConfig.cpp | 36 ++++++++++++++++++++++++++---------- qt/src/EmuConfig.hpp | 2 +- qt/src/EmuMainWindow.cpp | 3 ++- qt/src/EmuSettingsWindow.cpp | 15 ++++++++++++++- qt/src/EmuSettingsWindow.ui | 6 ++++++ 8 files changed, 52 insertions(+), 16 deletions(-) diff --git a/qt/src/EmuCanvasOpenGL.cpp b/qt/src/EmuCanvasOpenGL.cpp index 63e99ff1..71557d9a 100644 --- a/qt/src/EmuCanvasOpenGL.cpp +++ b/qt/src/EmuCanvasOpenGL.cpp @@ -49,7 +49,7 @@ void main() EmuCanvasOpenGL::EmuCanvasOpenGL(EmuConfig *config, QWidget *parent, QWidget *main_window) : EmuCanvas(config, parent, main_window) { - setMinimumSize(256, 224); + setMinimumSize(256 / devicePixelRatioF(), 224 / devicePixelRatioF()); setUpdatesEnabled(false); setAutoFillBackground(false); setAttribute(Qt::WA_NoSystemBackground, true); diff --git a/qt/src/EmuCanvasQt.cpp b/qt/src/EmuCanvasQt.cpp index dd414a3f..19031c4b 100644 --- a/qt/src/EmuCanvasQt.cpp +++ b/qt/src/EmuCanvasQt.cpp @@ -8,7 +8,7 @@ EmuCanvasQt::EmuCanvasQt(EmuConfig *config, QWidget *parent, QWidget *main_window) : EmuCanvas(config, parent, main_window) { - setMinimumSize(256, 224); + setMinimumSize(256 / devicePixelRatioF(), 224 / devicePixelRatioF()); } EmuCanvasQt::~EmuCanvasQt() diff --git a/qt/src/EmuCanvasVulkan.cpp b/qt/src/EmuCanvasVulkan.cpp index 566d4ac3..d604ee70 100644 --- a/qt/src/EmuCanvasVulkan.cpp +++ b/qt/src/EmuCanvasVulkan.cpp @@ -15,7 +15,7 @@ using namespace QNativeInterface; EmuCanvasVulkan::EmuCanvasVulkan(EmuConfig *config, QWidget *parent, QWidget *main_window) : EmuCanvas(config, parent, main_window) { - setMinimumSize(256, 224); + setMinimumSize(256 / devicePixelRatioF(), 224 / devicePixelRatioF()); setUpdatesEnabled(false); setAutoFillBackground(false); setAttribute(Qt::WA_NoSystemBackground, true); diff --git a/qt/src/EmuConfig.cpp b/qt/src/EmuConfig.cpp index a87843b4..1627eb66 100644 --- a/qt/src/EmuConfig.cpp +++ b/qt/src/EmuConfig.cpp @@ -185,8 +185,20 @@ std::string EmuConfig::findConfigFile() return path.string(); } -void EmuConfig::setDefaults(int section) +bool EmuConfig::setDefaults(int section) { + main_window_width = 640; + main_window_height = 480; + + bool restart = false; + auto restart_set = [&](auto& dst, auto str) { + if (dst != str) + { + restart = true; + dst = str; + } + }; + if (section == -1 || section == 0) { // General @@ -203,20 +215,22 @@ void EmuConfig::setDefaults(int section) if (section == -1 || section == 1) { // Display - display_driver = {}; - display_device_index = 0; + restart_set(display_driver, "vulkan"); + restart_set(display_device_index, 0); enable_vsync = true; ; bilinear_filter = true; ; reduce_input_lag = true; adjust_for_vrr = false; - use_shader = false; - shader = {}; + restart_set(use_shader, false); + if (use_shader) + restart_set(shader, ""); + else + shader = {}; last_shader_folder = {}; scale_image = true; - ; maintain_aspect_ratio = true; use_integer_scaling = false; aspect_ratio_numerator = 4; @@ -233,10 +247,10 @@ void EmuConfig::setDefaults(int section) if (section == -1 || section == 2) { // Sound - sound_driver = {}; + restart_set(sound_driver, "cubeb"); sound_device = {}; - playback_rate = 48000; - audio_buffer_size_ms = 64; + restart_set(playback_rate, 48000); + restart_set(audio_buffer_size_ms, 64); adjust_input_rate_automatically = true; input_rate = 31979; @@ -301,6 +315,8 @@ void EmuConfig::setDefaults(int section) patch_location = eROMDirectory; export_location = eROMDirectory; } + + return restart; } void EmuConfig::config(std::string filename, bool write) @@ -370,7 +386,7 @@ void EmuConfig::config(std::string filename, bool write) if (settings.contains(key)) entry = settings.value(key).toString().toLower(); - else + else return; for (size_t i = 0; i < map.size(); i++) diff --git a/qt/src/EmuConfig.hpp b/qt/src/EmuConfig.hpp index 03570916..01ab6adb 100644 --- a/qt/src/EmuConfig.hpp +++ b/qt/src/EmuConfig.hpp @@ -10,7 +10,7 @@ struct EmuConfig { static std::string findConfigFile(); static std::string findConfigDir(); - void setDefaults(int section = -1); + bool setDefaults(int section = -1); void config(std::string filename, bool write); void loadFile(std::string filename) { diff --git a/qt/src/EmuMainWindow.cpp b/qt/src/EmuMainWindow.cpp index 4532107c..f398418a 100644 --- a/qt/src/EmuMainWindow.cpp +++ b/qt/src/EmuMainWindow.cpp @@ -333,7 +333,8 @@ void EmuMainWindow::createWidgets() void EmuMainWindow::resizeToMultiple(int multiple) { - resize((224 * multiple) * app->config->aspect_ratio_numerator / app->config->aspect_ratio_denominator, (224 * multiple) + menuBar()->height()); + double hidpi_height = 224 / devicePixelRatioF(); + resize((hidpi_height * multiple) * app->config->aspect_ratio_numerator / app->config->aspect_ratio_denominator, (hidpi_height * multiple) + menuBar()->height()); } void EmuMainWindow::setBypassCompositor(bool bypass) diff --git a/qt/src/EmuSettingsWindow.cpp b/qt/src/EmuSettingsWindow.cpp index 67fd4bd8..ddd1332b 100644 --- a/qt/src/EmuSettingsWindow.cpp +++ b/qt/src/EmuSettingsWindow.cpp @@ -45,9 +45,21 @@ EmuSettingsWindow::EmuSettingsWindow(QWidget *parent, EmuApplication *app_) }); connect(defaultsButton, &QPushButton::clicked, [&](bool) { - app->config->setDefaults(stackedWidget->currentIndex()); + auto section = stackedWidget->currentIndex(); + bool restart_needed = app->config->setDefaults(stackedWidget->currentIndex()); stackedWidget->currentWidget()->hide(); stackedWidget->currentWidget()->show(); + + if (restart_needed) + { + if (section == 1) // Display + app->window->recreateCanvas(); + else if (section == 2) // Sound + app->restartAudio(); + else if (section == 4 || section == 5) // Controller Bindings + app->updateBindings(); + } + app->updateSettings(); }); } @@ -61,4 +73,5 @@ void EmuSettingsWindow::show(int page) stackedWidget->setCurrentIndex(page); if (!isVisible()) open(); + closeButton->setDefault(false); } \ No newline at end of file diff --git a/qt/src/EmuSettingsWindow.ui b/qt/src/EmuSettingsWindow.ui index 5f85eb39..b3ac1303 100644 --- a/qt/src/EmuSettingsWindow.ui +++ b/qt/src/EmuSettingsWindow.ui @@ -114,6 +114,9 @@ + + Qt::TabFocus + Restore Defaults @@ -121,6 +124,9 @@ .. + + false +