浏览代码

Fixed UI updates on switching to/from fullscreen

Ivan Savenko 2 年之前
父节点
当前提交
2a634b2ec0

+ 0 - 13
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<boost::recursive_mutex> lock(*CPlayerInterface::pim);
-			GH.onScreenResize();
-		});
-	};
-
-	resChanged(functor);
-	fsChanged(functor);
-
 	inGuiThread.reset(new bool(true));
 
 	while(1) //main SDL events loop

+ 2 - 0
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)

+ 0 - 4
client/eventsSDL/InputSourceText.cpp

@@ -25,10 +25,6 @@
 #	include <dispatch/dispatch.h>
 #endif
 
-#ifdef VCMI_IOS
-#	include "ios/utils.h"
-#endif
-
 void InputSourceText::handleEventTextInput(const SDL_TextInputEvent & text)
 {
 	GH.events().dispatchTextInput(text.text);

+ 4 - 0
client/renderSDL/ScreenHandler.cpp

@@ -22,6 +22,10 @@
 #include "../lib/CAndroidVMHelper.h"
 #endif
 
+#ifdef VCMI_IOS
+#	include "ios/utils.h"
+#endif
+
 #include <SDL.h>
 
 // TODO: should be made into a private members of ScreenHandler

+ 7 - 2
client/widgets/Buttons.cpp

@@ -331,11 +331,16 @@ void CToggleBase::setEnabled(bool enabled)
 	// for overrides
 }
 
-void CToggleBase::setSelected(bool on)
+void CToggleBase::setSelectedSilent(bool on)
 {
-	bool changed = (on != selected);
 	selected = on;
 	doSelect(on);
+}
+
+void CToggleBase::setSelected(bool on)
+{
+	bool changed = (on != selected);
+	setSelectedSilent(on);
 	if (changed)
 		callback(on);
 }

+ 3 - 0
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<void(bool)> callback);
 
 	/// Set whether the toggle is currently enabled for user to use, this is only inplemented in ToggleButton, not for other toggles yet.

+ 15 - 2
client/windows/settings/GeneralOptionsTab.cpp

@@ -277,10 +277,18 @@ void GeneralOptionsTab::setGameResolution(int index)
 	gameRes["height"].Float() = resolution.y;
 
 	widget<CLabel>("resolutionLabel")->setText(resolutionToLabelString(resolution.x, resolution.y));
+
+	GH.dispatchMainThread([](){
+		boost::unique_lock<boost::recursive_mutex> 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<CToggleButton> fullscreenBorderlessCheckbox = widget<CToggleButton>("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<boost::recursive_mutex> lock(*CPlayerInterface::pim);
+		GH.onScreenResize();
+	});
 }
 
 void GeneralOptionsTab::selectGameScaling()