Move the gui input handler to CGUIManager

`gui_handler` isn't global anymore. That makes the interface simpler and
might make the compilation and the runtime faster.
This commit is contained in:
phosit 2025-04-17 14:54:38 +02:00
parent ac100088c3
commit 7b3ba5be13
No known key found for this signature in database
GPG key ID: C9430B600671C268
3 changed files with 11 additions and 16 deletions

View file

@ -78,17 +78,11 @@ CGUIManager* g_GUI = nullptr;
// multiple pages, instead of treating them as completely independent, to save
// memory and loading time.
// called from main loop when (input) events are received.
// event is passed to other handlers if false is returned.
// trampoline: we don't want to make the HandleEvent implementation static
Input::Reaction gui_handler(const SDL_Event& ev)
Input::Reaction CGUIManager::InputHandler::operator()(const SDL_Event& ev)
{
if (!g_GUI)
return Input::Reaction::PASS;
PROFILE("GUI event handler");
return g_GUI->HandleEvent(ev);
return gui.HandleEvent(ev);
}
static Status ReloadChangedFileCB(void* param, const VfsPath& path)
@ -98,7 +92,8 @@ static Status ReloadChangedFileCB(void* param, const VfsPath& path)
CGUIManager::CGUIManager(ScriptContext& scriptContext, ScriptInterface& scriptInterface) :
m_ScriptContext{scriptContext},
m_ScriptInterface{scriptInterface}
m_ScriptInterface{scriptInterface},
m_InputHandler{g_VideoMode.m_InputManager, Input::Slot::GUI, {*this}}
{
m_ScriptInterface.SetCallbackData(this);
m_ScriptInterface.LoadGlobalScripts();

View file

@ -237,10 +237,15 @@ private:
PS::StaticVector<SGUIPage, 16> GetCopyOfFrozenStack() const;
CTemplateLoader m_TemplateLoader;
struct InputHandler
{
CGUIManager& gui;
Input::Reaction operator()(const SDL_Event& ev);
};
Input::Handler<InputHandler> m_InputHandler;
};
extern CGUIManager* g_GUI;
extern Input::Reaction gui_handler(const SDL_Event& ev);
#endif // INCLUDED_GUIMANAGER

View file

@ -264,11 +264,6 @@ static void InitPs(bool setup_gui, const CStrW& gui_page, ScriptInterface* srcSc
handlers->emplace(g_VideoMode.m_InputManager, Input::Slot::HOTKEY_INPUT, HotkeyInputActualHandler);
// gui_handler needs to be registered after (i.e. called before!) the
// hotkey handler so that input boxes can be typed in without
// setting off hotkeys.
handlers->emplace(g_VideoMode.m_InputManager, Input::Slot::GUI, gui_handler);
handlers->emplace(g_VideoMode.m_InputManager, Input::Slot::TOUCH_INPUT, touch_input_handler);
// Should be called after scancode map update (i.e. after the global input, but before UI).