diff --git a/src/graphics/ui/elements/UINode.cpp b/src/graphics/ui/elements/UINode.cpp index 1e8f48d6e..3adcb1da9 100644 --- a/src/graphics/ui/elements/UINode.cpp +++ b/src/graphics/ui/elements/UINode.cpp @@ -4,6 +4,7 @@ #include "Container.hpp" #include "graphics/core/Batch2D.hpp" +#include "graphics/ui/GUI.hpp" using gui::UINode; using gui::Align; @@ -107,11 +108,13 @@ bool UINode::isPressed() const { } void UINode::onFocus() { + gui.getInput().startTextInput(); focused = true; focusCallbacks.notify(gui); } void UINode::defocus() { + gui.getInput().stopTextInput(); focused = false; defocusCallbacks.notify(gui); } diff --git a/src/window/detail/SDLInput.cpp b/src/window/detail/SDLInput.cpp index bfda70b04..5eec64c12 100644 --- a/src/window/detail/SDLInput.cpp +++ b/src/window/detail/SDLInput.cpp @@ -121,8 +121,6 @@ Mousecode input_util::mousecode_from(const std::string& name) { SDLInput::SDLInput(SDLWindow& window) : window(window) { input_util::initialize(); - // We should always get char stream (maybe) - SDL_StartTextInput(window.getSdlWindow()); } void SDLInput::pollEvents() { @@ -234,6 +232,15 @@ void SDLInput::setClipboardText(const char* text) { SDL_SetClipboardText(text); } +void SDLInput::startTextInput() { + logger.debug() << "Start text input"; + SDL_StartTextInput(window.getSdlWindow()); +} +void SDLInput::stopTextInput() { + logger.debug() << "Stop text input"; + SDL_StopTextInput(window.getSdlWindow()); +} + int SDLInput::getScroll() { return scroll; } diff --git a/src/window/detail/SDLInput.hpp b/src/window/detail/SDLInput.hpp index 707eed78e..dd1ec2447 100644 --- a/src/window/detail/SDLInput.hpp +++ b/src/window/detail/SDLInput.hpp @@ -1,7 +1,7 @@ #include -#include "window/input.hpp" #include "window/Window.hpp" +#include "window/input.hpp" class SDLWindow; @@ -18,6 +18,9 @@ public: const char* getClipboardText() const override; void setClipboardText(const char* str) override; + void startTextInput() override; + void stopTextInput() override; + int getScroll() override; bool pressed(Keycode keycode) const override; diff --git a/src/window/input.hpp b/src/window/input.hpp index 6e4c2a6c9..dfd5d9d5c 100644 --- a/src/window/input.hpp +++ b/src/window/input.hpp @@ -258,6 +258,9 @@ public: virtual const char* getClipboardText() const = 0; virtual void setClipboardText(const char* str) = 0; + virtual void startTextInput() = 0; + virtual void stopTextInput() = 0; + virtual int getScroll() = 0; virtual bool pressed(Keycode keycode) const = 0;