From 23f874ae60eebae5451722cd89101e76e1e14065 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Tue, 9 May 2023 15:10:22 -0400 Subject: [PATCH] configure_graphics: Reimplement bg_color To specialized a setting to be worth adding to the shared_widget imo, so add it roughly like before. --- src/yuzu/configuration/configure_graphics.cpp | 74 +++++++++++++++---- src/yuzu/configuration/configure_graphics.h | 2 + src/yuzu/configuration/configure_graphics.ui | 50 +++++++++++++ 3 files changed, 111 insertions(+), 15 deletions(-) diff --git a/src/yuzu/configuration/configure_graphics.cpp b/src/yuzu/configuration/configure_graphics.cpp index 0b21f80f52..4c6d697033 100644 --- a/src/yuzu/configuration/configure_graphics.cpp +++ b/src/yuzu/configuration/configure_graphics.cpp @@ -88,7 +88,7 @@ ConfigureGraphics::ConfigureGraphics( ui->setupUi(this); - SetConfiguration(); + Setup(); for (const auto& device : vulkan_devices) { vulkan_device_combobox->addItem(device); @@ -128,20 +128,22 @@ ConfigureGraphics::ConfigureGraphics( connect(shader_backend_combobox, qOverload(&QComboBox::activated), this, [this](int backend) { UpdateShaderBackendSelection(backend); }); - // connect(ui->bg_button, &QPushButton::clicked, this, [this] { - // const QColor new_bg_color = QColorDialog::getColor(bg_color); - // if (!new_bg_color.isValid()) { - // return; - // } - // UpdateBackgroundColorButton(new_bg_color); - // }); - // ui->bg_label->setVisible(Settings::IsConfiguringGlobal()); - // ui->bg_combobox->setVisible(!Settings::IsConfiguringGlobal()); + connect(ui->bg_button, &QPushButton::clicked, this, [this] { + const QColor new_bg_color = QColorDialog::getColor(bg_color); + if (!new_bg_color.isValid()) { + return; + } + UpdateBackgroundColorButton(new_bg_color); + }); api_combobox->setEnabled(!UISettings::values.has_broken_vulkan && api_combobox->isEnabled()); ui->api_widget->setEnabled( (!UISettings::values.has_broken_vulkan || Settings::IsConfiguringGlobal()) && ui->api_widget->isEnabled()); + + if (Settings::IsConfiguringGlobal()) { + ui->bg_widget->setEnabled(Settings::values.bg_red.UsingGlobal()); + } } void ConfigureGraphics::PopulateVSyncModeSelection() { @@ -205,7 +207,9 @@ void ConfigureGraphics::UpdateShaderBackendSelection(int backend) { ConfigureGraphics::~ConfigureGraphics() = default; -void ConfigureGraphics::SetConfiguration() { +void ConfigureGraphics::SetConfiguration() {} + +void ConfigureGraphics::Setup() { const bool runtime_lock = !system.IsPoweredOn(); QLayout* api_layout = ui->api_widget->layout(); QWidget* api_grid_widget = new QWidget(this); @@ -305,6 +309,46 @@ void ConfigureGraphics::SetConfiguration() { for (auto widget : hold_api) { api_grid_layout->addWidget(widget); } + + if (Settings::IsConfiguringGlobal()) { + apply_funcs.push_front([this](bool powered_on) { + Settings::values.bg_red.SetValue(static_cast(bg_color.red())); + Settings::values.bg_green.SetValue(static_cast(bg_color.green())); + Settings::values.bg_blue.SetValue(static_cast(bg_color.blue())); + }); + } else { + QPushButton* bg_restore_button = ConfigurationShared::Widget::CreateRestoreGlobalButton( + Settings::values.bg_red, ui->bg_widget); + ui->bg_widget->layout()->addWidget(bg_restore_button); + + QObject::connect(bg_restore_button, &QAbstractButton::clicked, + [bg_restore_button, this](bool) { + const int r = Settings::values.bg_red.GetValue(true); + const int g = Settings::values.bg_green.GetValue(true); + const int b = Settings::values.bg_blue.GetValue(true); + UpdateBackgroundColorButton(QColor::fromRgb(r, g, b)); + + bg_restore_button->setVisible(false); + bg_restore_button->setEnabled(false); + }); + + QObject::connect(ui->bg_button, &QAbstractButton::clicked, [bg_restore_button](bool) { + bg_restore_button->setVisible(true); + bg_restore_button->setEnabled(true); + }); + + apply_funcs.push_front([bg_restore_button, this](bool powered_on) { + const bool using_global = !bg_restore_button->isEnabled(); + Settings::values.bg_red.SetGlobal(using_global); + Settings::values.bg_green.SetGlobal(using_global); + Settings::values.bg_blue.SetGlobal(using_global); + if (!using_global) { + Settings::values.bg_red.SetValue(static_cast(bg_color.red())); + Settings::values.bg_green.SetValue(static_cast(bg_color.green())); + Settings::values.bg_blue.SetValue(static_cast(bg_color.blue())); + } + }); + } } const QString ConfigureGraphics::TranslateVSyncMode(VkPresentModeKHR mode, @@ -375,11 +419,11 @@ void ConfigureGraphics::RetranslateUI() { void ConfigureGraphics::UpdateBackgroundColorButton(QColor color) { bg_color = color; - // QPixmap pixmap(ui->bg_button->size()); - // pixmap.fill(bg_color); + QPixmap pixmap(ui->bg_button->size()); + pixmap.fill(bg_color); - // const QIcon color_icon(pixmap); - // ui->bg_button->setIcon(color_icon); + const QIcon color_icon(pixmap); + ui->bg_button->setIcon(color_icon); } void ConfigureGraphics::UpdateAPILayout() { diff --git a/src/yuzu/configuration/configure_graphics.h b/src/yuzu/configuration/configure_graphics.h index 4ef551341a..61eb2f2fc5 100644 --- a/src/yuzu/configuration/configure_graphics.h +++ b/src/yuzu/configuration/configure_graphics.h @@ -51,6 +51,8 @@ private: void changeEvent(QEvent* event) override; void RetranslateUI(); + void Setup(); + void PopulateVSyncModeSelection(); void UpdateBackgroundColorButton(QColor color); void UpdateAPILayout(); diff --git a/src/yuzu/configuration/configure_graphics.ui b/src/yuzu/configuration/configure_graphics.ui index 1f6ffea1a8..d09415d702 100644 --- a/src/yuzu/configuration/configure_graphics.ui +++ b/src/yuzu/configuration/configure_graphics.ui @@ -76,6 +76,56 @@ + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + Background Color: + + + + + + + + 0 + 0 + + + + + 40 + 16777215 + + + + + + + + + +