From dd14a3e88e76e83c3c305c3e73f87ab0f3d4f915 Mon Sep 17 00:00:00 2001
From: Arisotura <thetotalworm@gmail.com>
Date: Sat, 25 May 2019 21:03:39 +0200
Subject: for config dialogs that reflect changes instantly, make behavior of
 window close button consistent with that of Cancel button

---
 src/libui_sdl/DlgAudioSettings.cpp |  9 +++-
 src/libui_sdl/DlgVideoSettings.cpp | 84 ++++++++++++++++++++------------------
 2 files changed, 53 insertions(+), 40 deletions(-)

(limited to 'src')

diff --git a/src/libui_sdl/DlgAudioSettings.cpp b/src/libui_sdl/DlgAudioSettings.cpp
index 385128c..d649321 100644
--- a/src/libui_sdl/DlgAudioSettings.cpp
+++ b/src/libui_sdl/DlgAudioSettings.cpp
@@ -44,8 +44,15 @@ uiEntry* txMicWavPath;
 int oldvolume;
 
 
+void RevertSettings()
+{
+    Config::AudioVolume = oldvolume;
+}
+
+
 int OnCloseWindow(uiWindow* window, void* blarg)
 {
+    RevertSettings();
     opened = false;
     return 1;
 }
@@ -69,7 +76,7 @@ void OnMicWavBrowse(uiButton* btn, void* blarg)
 
 void OnCancel(uiButton* btn, void* blarg)
 {
-    Config::AudioVolume = oldvolume;
+    RevertSettings();
 
     uiControlDestroy(uiControl(win));
     opened = false;
diff --git a/src/libui_sdl/DlgVideoSettings.cpp b/src/libui_sdl/DlgVideoSettings.cpp
index 8749dc5..5c5d5f9 100644
--- a/src/libui_sdl/DlgVideoSettings.cpp
+++ b/src/libui_sdl/DlgVideoSettings.cpp
@@ -70,9 +70,53 @@ void UpdateControls()
     }
 }
 
+void RevertSettings()
+{
+    bool apply0 = false;
+    bool apply2 = false;
+    bool apply3 = false;
+
+    bool old_usegl = (old_gldisplay != 0) || (old_renderer != 0);
+    bool new_usegl = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0);
+
+    if (old_renderer != Config::_3DRenderer)
+    {
+        Config::_3DRenderer = old_renderer;
+        apply3 = true;
+    }
+
+    if (old_gldisplay != Config::ScreenUseGL)
+    {
+        Config::ScreenUseGL = old_gldisplay;
+    }
+    if (old_usegl != new_usegl)
+    {
+        apply2 = true;
+    }
+
+    if (old_threaded3D != Config::Threaded3D)
+    {
+        Config::Threaded3D = old_threaded3D;
+        apply0 = true;
+    }
+
+    if (old_resolution != Config::GL_ScaleFactor ||
+        old_antialias != Config::GL_Antialias)
+    {
+        Config::GL_ScaleFactor = old_resolution;
+        Config::GL_Antialias = old_antialias;
+        apply0 = true;
+    }
+
+    if (apply2) ApplyNewSettings(2);
+    else if (apply3) ApplyNewSettings(3);
+    if (apply0) ApplyNewSettings(0);
+}
+
 
 int OnCloseWindow(uiWindow* window, void* blarg)
 {
+    RevertSettings();
     opened = false;
     return 1;
 }
@@ -121,45 +165,7 @@ void OnAntialiasChanged(uiCheckbox* cb, void* blarg)
 
 void OnCancel(uiButton* btn, void* blarg)
 {
-    bool apply0 = false;
-    bool apply2 = false;
-    bool apply3 = false;
-
-    bool old_usegl = (old_gldisplay != 0) || (old_renderer != 0);
-    bool new_usegl = (Config::ScreenUseGL != 0) || (Config::_3DRenderer != 0);
-
-    if (old_renderer != Config::_3DRenderer)
-    {
-        Config::_3DRenderer = old_renderer;
-        apply3 = true;
-    }
-
-    if (old_gldisplay != Config::ScreenUseGL)
-    {
-        Config::ScreenUseGL = old_gldisplay;
-    }
-    if (old_usegl != new_usegl)
-    {
-        apply2 = true;
-    }
-
-    if (old_threaded3D != Config::Threaded3D)
-    {
-        Config::Threaded3D = old_threaded3D;
-        apply0 = true;
-    }
-
-    if (old_resolution != Config::GL_ScaleFactor ||
-        old_antialias != Config::GL_Antialias)
-    {
-        Config::GL_ScaleFactor = old_resolution;
-        Config::GL_Antialias = old_antialias;
-        apply0 = true;
-    }
-
-    if (apply2) ApplyNewSettings(2);
-    else if (apply3) ApplyNewSettings(3);
-    if (apply0) ApplyNewSettings(0);
+    RevertSettings();
 
     uiControlDestroy(uiControl(win));
     opened = false;
-- 
cgit v1.2.3