diff --git a/src/input.cpp b/src/input.cpp index 8658a5c..5c78f4c 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -13,6 +13,7 @@ Input::Input(sf::Window *w) : m_window(w), m_closeRequested(false), + m_imgui_requested_focus(false), m_mouseGrabbed(false), m_mouseWasGrabbed(false) { @@ -71,9 +72,9 @@ void Input::updateEvents(){ m_actions.clear(); Action action; - - - bool focus_on_imgui = ImGui::IsWindowFocused(ImGuiFocusedFlags_AnyWindow); + bool focus_on_imgui = false; + if(m_imgui_requested_focus) + focus_on_imgui = ImGui::IsWindowFocused(ImGuiFocusedFlags_AnyWindow); if(focus_on_imgui) std::cout << "focused" << std::endl; @@ -258,6 +259,14 @@ bool Input::isResized() const return m_hasBeenResized; } +void Input::ImguiRequestFocus(){ + m_imgui_requested_focus = true; +} + +void Input::ImguiReleaseFocus(){ + m_imgui_requested_focus = false; +} + /* keyboard-related functions */ bool Input::isKeyPressed(int key) const diff --git a/src/input.h b/src/input.h index 45d453d..be6e1eb 100644 --- a/src/input.h +++ b/src/input.h @@ -18,6 +18,7 @@ private: sf::Window* m_window; bool m_closeRequested; bool m_hasBeenResized; + bool m_imgui_requested_focus; /* general action-mapping variables */ IKeysMap m_keysmap; @@ -69,6 +70,8 @@ public: /* window-related function */ bool isCloseRequested() const; bool isResized() const; + void ImguiRequestFocus(); + void ImguiReleaseFocus(); /* keyboard-related functions */ bool isKeyPressed(int key) const;