1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-03 14:52:11 +02:00

Fixed UI updates on switching to/from fullscreen

This commit is contained in:
Ivan Savenko 2023-07-05 18:14:37 +03:00
parent 7e00a702c1
commit 2a634b2ec0
7 changed files with 31 additions and 21 deletions

View File

@ -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

View File

@ -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)

View File

@ -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);

View File

@ -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

View File

@ -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);
}

View File

@ -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.

View File

@ -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()