From 2a634b2ec0981097921ced5ea30738dabcc3a005 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Wed, 5 Jul 2023 18:14:37 +0300 Subject: [PATCH] Fixed UI updates on switching to/from fullscreen --- client/CMT.cpp | 13 ------------- client/eventsSDL/InputHandler.cpp | 2 ++ client/eventsSDL/InputSourceText.cpp | 4 ---- client/renderSDL/ScreenHandler.cpp | 4 ++++ client/widgets/Buttons.cpp | 9 +++++++-- client/widgets/Buttons.h | 3 +++ client/windows/settings/GeneralOptionsTab.cpp | 17 +++++++++++++++-- 7 files changed, 31 insertions(+), 21 deletions(-) diff --git a/client/CMT.cpp b/client/CMT.cpp index 83ef687e4..8f99a64a9 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -449,19 +449,6 @@ void playIntro() static void mainLoop() { - SettingsListener resChanged = settings.listen["video"]["resolution"]; - SettingsListener fsChanged = settings.listen["video"]["fullscreen"]; - - auto functor = [](const JsonNode &newState){ - GH.dispatchMainThread([](){ - boost::unique_lock lock(*CPlayerInterface::pim); - GH.onScreenResize(); - }); - }; - - resChanged(functor); - fsChanged(functor); - inGuiThread.reset(new bool(true)); while(1) //main SDL events loop diff --git a/client/eventsSDL/InputHandler.cpp b/client/eventsSDL/InputHandler.cpp index 0ed239c2a..3d46c8ef2 100644 --- a/client/eventsSDL/InputHandler.cpp +++ b/client/eventsSDL/InputHandler.cpp @@ -121,6 +121,8 @@ void InputHandler::preprocessEvent(const SDL_Event & ev) { Settings full = settings.write["video"]["fullscreen"]; full->Bool() = !full->Bool(); + + GH.onScreenResize(); return; } else if(ev.type == SDL_USEREVENT) diff --git a/client/eventsSDL/InputSourceText.cpp b/client/eventsSDL/InputSourceText.cpp index 1357057f2..72afc978d 100644 --- a/client/eventsSDL/InputSourceText.cpp +++ b/client/eventsSDL/InputSourceText.cpp @@ -25,10 +25,6 @@ # include #endif -#ifdef VCMI_IOS -# include "ios/utils.h" -#endif - void InputSourceText::handleEventTextInput(const SDL_TextInputEvent & text) { GH.events().dispatchTextInput(text.text); diff --git a/client/renderSDL/ScreenHandler.cpp b/client/renderSDL/ScreenHandler.cpp index 010e13fd4..18b2bebfb 100644 --- a/client/renderSDL/ScreenHandler.cpp +++ b/client/renderSDL/ScreenHandler.cpp @@ -22,6 +22,10 @@ #include "../lib/CAndroidVMHelper.h" #endif +#ifdef VCMI_IOS +# include "ios/utils.h" +#endif + #include // TODO: should be made into a private members of ScreenHandler diff --git a/client/widgets/Buttons.cpp b/client/widgets/Buttons.cpp index f5d52d006..c1df84b0d 100644 --- a/client/widgets/Buttons.cpp +++ b/client/widgets/Buttons.cpp @@ -331,11 +331,16 @@ void CToggleBase::setEnabled(bool enabled) // for overrides } +void CToggleBase::setSelectedSilent(bool on) +{ + selected = on; + doSelect(on); +} + void CToggleBase::setSelected(bool on) { bool changed = (on != selected); - selected = on; - doSelect(on); + setSelectedSilent(on); if (changed) callback(on); } diff --git a/client/widgets/Buttons.h b/client/widgets/Buttons.h index 993beb33f..ec4f00ae1 100644 --- a/client/widgets/Buttons.h +++ b/client/widgets/Buttons.h @@ -136,6 +136,9 @@ public: /// Changes selection to "on", and calls callback void setSelected(bool on); + /// Changes selection to "on" without calling callback + void setSelectedSilent(bool on); + void addCallback(std::function callback); /// Set whether the toggle is currently enabled for user to use, this is only inplemented in ToggleButton, not for other toggles yet. diff --git a/client/windows/settings/GeneralOptionsTab.cpp b/client/windows/settings/GeneralOptionsTab.cpp index 4710067cc..df35ea811 100644 --- a/client/windows/settings/GeneralOptionsTab.cpp +++ b/client/windows/settings/GeneralOptionsTab.cpp @@ -277,10 +277,18 @@ void GeneralOptionsTab::setGameResolution(int index) gameRes["height"].Float() = resolution.y; widget("resolutionLabel")->setText(resolutionToLabelString(resolution.x, resolution.y)); + + GH.dispatchMainThread([](){ + boost::unique_lock lock(*CPlayerInterface::pim); + GH.onScreenResize(); + }); } void GeneralOptionsTab::setFullscreenMode(bool on, bool exclusive) { + if (on == settings["video"]["fullscreen"].Bool() && exclusive == settings["video"]["realFullscreen"].Bool()) + return; + setBoolSetting("video", "realFullscreen", exclusive); setBoolSetting("video", "fullscreen", on); @@ -288,12 +296,17 @@ void GeneralOptionsTab::setFullscreenMode(bool on, bool exclusive) std::shared_ptr fullscreenBorderlessCheckbox = widget("fullscreenBorderlessCheckbox"); if (fullscreenBorderlessCheckbox) - fullscreenBorderlessCheckbox->setSelected(on && !exclusive); + fullscreenBorderlessCheckbox->setSelectedSilent(on && !exclusive); if (fullscreenExclusiveCheckbox) - fullscreenExclusiveCheckbox->setSelected(on && exclusive); + fullscreenExclusiveCheckbox->setSelectedSilent(on && exclusive); updateResolutionSelector(); + + GH.dispatchMainThread([](){ + boost::unique_lock lock(*CPlayerInterface::pim); + GH.onScreenResize(); + }); } void GeneralOptionsTab::selectGameScaling()