From 19a640286c89fdf95c5e90dd9132a124d69281f3 Mon Sep 17 00:00:00 2001
From: lat9nq <22451773+lat9nq@users.noreply.github.com>
Date: Fri, 25 Nov 2022 22:42:54 -0500
Subject: [PATCH] configure_graphics: Implement custom FSR Sharpening setting

---
 src/yuzu/configuration/configure_graphics.cpp |  26 +++
 src/yuzu/configuration/configure_graphics.ui  | 165 +++++++++++-------
 2 files changed, 129 insertions(+), 62 deletions(-)

diff --git a/src/yuzu/configuration/configure_graphics.cpp b/src/yuzu/configuration/configure_graphics.cpp
index 3a40872ab..f1385e972 100644
--- a/src/yuzu/configuration/configure_graphics.cpp
+++ b/src/yuzu/configuration/configure_graphics.cpp
@@ -66,6 +66,8 @@ ConfigureGraphics::ConfigureGraphics(const Core::System& system_, QWidget* paren
 
     connect(ui->fsr_sharpening_slider, &QSlider::valueChanged, this,
             &ConfigureGraphics::SetFSRIndicatorText);
+    ui->fsr_sharpening_combobox->setVisible(!Settings::IsConfiguringGlobal());
+    ui->fsr_sharpening_label->setVisible(Settings::IsConfiguringGlobal());
 }
 
 void ConfigureGraphics::UpdateDeviceSelection(int device) {
@@ -151,6 +153,15 @@ void ConfigureGraphics::SetConfiguration() {
         ConfigurationShared::SetHighlight(ui->anti_aliasing_label,
                                           !Settings::values.anti_aliasing.UsingGlobal());
 
+        ui->fsr_sharpening_combobox->setCurrentIndex(
+            Settings::values.fsr_sharpening_slider.UsingGlobal() ? 0 : 1);
+        ui->fsr_sharpening_slider->setEnabled(
+            !Settings::values.fsr_sharpening_slider.UsingGlobal());
+        ui->fsr_sharpening_value->setEnabled(!Settings::values.fsr_sharpening_slider.UsingGlobal());
+        ConfigurationShared::SetHighlight(ui->fsr_sharpening_layout,
+                                          !Settings::values.fsr_sharpening_slider.UsingGlobal());
+        ui->fsr_sharpening_slider->setValue(Settings::values.fsr_sharpening_slider.GetValue());
+
         ui->bg_combobox->setCurrentIndex(Settings::values.bg_red.UsingGlobal() ? 0 : 1);
         ui->bg_button->setEnabled(!Settings::values.bg_red.UsingGlobal());
         ConfigurationShared::SetHighlight(ui->bg_layout, !Settings::values.bg_red.UsingGlobal());
@@ -280,6 +291,13 @@ void ConfigureGraphics::ApplyConfiguration() {
             Settings::values.bg_green.SetValue(static_cast<u8>(bg_color.green()));
             Settings::values.bg_blue.SetValue(static_cast<u8>(bg_color.blue()));
         }
+
+        if (ui->fsr_sharpening_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
+            Settings::values.fsr_sharpening_slider.SetGlobal(true);
+        } else {
+            Settings::values.fsr_sharpening_slider.SetGlobal(false);
+            Settings::values.fsr_sharpening_slider.SetValue(ui->fsr_sharpening_slider->value());
+        }
     }
 }
 
@@ -399,6 +417,7 @@ void ConfigureGraphics::SetupPerGameUI() {
         ui->accelerate_astc->setEnabled(Settings::values.accelerate_astc.UsingGlobal());
         ui->use_disk_shader_cache->setEnabled(Settings::values.use_disk_shader_cache.UsingGlobal());
         ui->bg_button->setEnabled(Settings::values.bg_red.UsingGlobal());
+        ui->fsr_slider_layout->setEnabled(Settings::values.fsr_sharpening_slider.UsingGlobal());
 
         return;
     }
@@ -408,6 +427,13 @@ void ConfigureGraphics::SetupPerGameUI() {
         ConfigurationShared::SetHighlight(ui->bg_layout, index == 1);
     });
 
+    connect(ui->fsr_sharpening_combobox, qOverload<int>(&QComboBox::activated), this,
+            [this](int index) {
+                ui->fsr_sharpening_slider->setEnabled(index == 1);
+                ui->fsr_sharpening_value->setEnabled(index == 1);
+                ConfigurationShared::SetHighlight(ui->fsr_sharpening_layout, index == 1);
+            });
+
     ConfigurationShared::SetColoredTristate(
         ui->use_disk_shader_cache, Settings::values.use_disk_shader_cache, use_disk_shader_cache);
     ConfigurationShared::SetColoredTristate(ui->accelerate_astc, Settings::values.accelerate_astc,
diff --git a/src/yuzu/configuration/configure_graphics.ui b/src/yuzu/configuration/configure_graphics.ui
index de8b2f44e..1f8c84394 100644
--- a/src/yuzu/configuration/configure_graphics.ui
+++ b/src/yuzu/configuration/configure_graphics.ui
@@ -517,73 +517,114 @@
            <property name="bottomMargin">
             <number>0</number>
            </property>
-           <item alignment="Qt::AlignLeft">
-            <widget class="QLabel" name="fsr_sharpening_label">
-             <property name="sizePolicy">
-              <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
-               <horstretch>0</horstretch>
-               <verstretch>0</verstretch>
-              </sizepolicy>
-             </property>
-             <property name="text">
-              <string>FSR Sharpening:</string>
-             </property>
-            </widget>
+           <item>
+            <layout class="QHBoxLayout" name="fsr_sharpening_label_group">
+             <item>
+              <widget class="QComboBox" name="fsr_sharpening_combobox">
+               <property name="sizePolicy">
+                <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
+                 <horstretch>0</horstretch>
+                 <verstretch>0</verstretch>
+                </sizepolicy>
+               </property>
+               <item>
+                <property name="text">
+                 <string>Use global FSR Sharpening</string>
+                </property>
+               </item>
+               <item>
+                <property name="text">
+                 <string>Set FSR Sharpening</string>
+                </property>
+               </item>
+              </widget>
+             </item>
+             <item>
+              <widget class="QLabel" name="fsr_sharpening_label">
+               <property name="sizePolicy">
+                <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+                 <horstretch>0</horstretch>
+                 <verstretch>0</verstretch>
+                </sizepolicy>
+               </property>
+               <property name="text">
+                <string>FSR Sharpening:</string>
+               </property>
+              </widget>
+             </item>
+             <item>
+              <spacer name="horizontalSpacer_2">
+               <property name="orientation">
+                <enum>Qt::Horizontal</enum>
+               </property>
+               <property name="sizeHint" stdset="0">
+                <size>
+                 <width>40</width>
+                 <height>20</height>
+                </size>
+               </property>
+              </spacer>
+             </item>
+            </layout>
            </item>
            <item>
-            <widget class="QSlider" name="fsr_sharpening_slider">
-             <property name="sizePolicy">
-              <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
-               <horstretch>0</horstretch>
-               <verstretch>0</verstretch>
-              </sizepolicy>
+            <layout class="QHBoxLayout" name="fsr_slider_layout">
+             <property name="spacing">
+              <number>6</number>
              </property>
-             <property name="baseSize">
-              <size>
-               <width>0</width>
-               <height>0</height>
-              </size>
-             </property>
-             <property name="maximum">
-              <number>200</number>
-             </property>
-             <property name="sliderPosition">
-              <number>25</number>
-             </property>
-             <property name="orientation">
-              <enum>Qt::Horizontal</enum>
-             </property>
-             <property name="invertedAppearance">
-              <bool>true</bool>
-             </property>
-            </widget>
-           </item>
-           <item>
-            <widget class="QLabel" name="fsr_sharpening_value">
-             <property name="sizePolicy">
-              <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
-               <horstretch>0</horstretch>
-               <verstretch>0</verstretch>
-              </sizepolicy>
-             </property>
-             <property name="minimumSize">
-              <size>
-               <width>32</width>
-               <height>0</height>
-              </size>
-             </property>
-             <property name="text">
-              <string>100%</string>
-             </property>
-             <property name="alignment">
-              <set>Qt::AlignCenter</set>
-             </property>
-            </widget>
+             <item>
+              <widget class="QSlider" name="fsr_sharpening_slider">
+               <property name="sizePolicy">
+                <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
+                 <horstretch>0</horstretch>
+                 <verstretch>0</verstretch>
+                </sizepolicy>
+               </property>
+               <property name="baseSize">
+                <size>
+                 <width>0</width>
+                 <height>0</height>
+                </size>
+               </property>
+               <property name="maximum">
+                <number>200</number>
+               </property>
+               <property name="sliderPosition">
+                <number>25</number>
+               </property>
+               <property name="orientation">
+                <enum>Qt::Horizontal</enum>
+               </property>
+               <property name="invertedAppearance">
+                <bool>true</bool>
+               </property>
+              </widget>
+             </item>
+             <item>
+              <widget class="QLabel" name="fsr_sharpening_value">
+               <property name="sizePolicy">
+                <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
+                 <horstretch>0</horstretch>
+                 <verstretch>0</verstretch>
+                </sizepolicy>
+               </property>
+               <property name="minimumSize">
+                <size>
+                 <width>32</width>
+                 <height>0</height>
+                </size>
+               </property>
+               <property name="text">
+                <string>100%</string>
+               </property>
+               <property name="alignment">
+                <set>Qt::AlignCenter</set>
+               </property>
+              </widget>
+             </item>
+            </layout>
            </item>
           </layout>
-          <zorder>fsr_sharpening_value</zorder>
-          <zorder>fsr_sharpening_label</zorder>
-          <zorder>fsr_sharpening_slider</zorder>
          </widget>
         </item>
         <item>