diff --git a/libs/app/include/psemek/app/application.hpp b/libs/app/include/psemek/app/application.hpp index 96a1f110..b6948266 100644 --- a/libs/app/include/psemek/app/application.hpp +++ b/libs/app/include/psemek/app/application.hpp @@ -37,6 +37,7 @@ namespace psemek::app std::function show_cursor; std::function relative_mouse_mode; std::function windowed; + std::function text_input; #if defined(PSEMEK_GRAPHICS_API_OPENGL) std::function vsync; #endif diff --git a/libs/app/include/psemek/app/event_handler.hpp b/libs/app/include/psemek/app/event_handler.hpp index 3094555a..913d708a 100644 --- a/libs/app/include/psemek/app/event_handler.hpp +++ b/libs/app/include/psemek/app/event_handler.hpp @@ -16,6 +16,7 @@ namespace psemek::app virtual void on_event(touch_up_event const &) {} virtual void on_event(touch_move_event const &) {} virtual void on_event(key_event const &) {} + virtual void on_event(text_input_event const &) {} virtual ~event_handler() {} }; diff --git a/libs/app/include/psemek/app/events.hpp b/libs/app/include/psemek/app/events.hpp index e3e21ade..ea0fe495 100644 --- a/libs/app/include/psemek/app/events.hpp +++ b/libs/app/include/psemek/app/events.hpp @@ -2,6 +2,8 @@ #include +#include + namespace psemek::app { @@ -172,4 +174,9 @@ namespace psemek::app bool down; }; + struct text_input_event + { + std::string input; + }; + } diff --git a/libs/sdl2/source/events.cpp b/libs/sdl2/source/events.cpp index 37b486d7..4b5fec15 100644 --- a/libs/sdl2/source/events.cpp +++ b/libs/sdl2/source/events.cpp @@ -192,6 +192,9 @@ namespace psemek::sdl2 if (auto key = keycode(e.key.keysym)) handler.on_event(app::key_event{*key, false}); break; + case SDL_TEXTINPUT: + handler.on_event(app::text_input_event{e.text.text}); + break; } return false; diff --git a/libs/sdl2/source/main.cpp b/libs/sdl2/source/main.cpp index 714399a8..989dfd3e 100644 --- a/libs/sdl2/source/main.cpp +++ b/libs/sdl2/source/main.cpp @@ -48,6 +48,7 @@ int main(int argc, char ** argv) try context.show_cursor = [&](bool show){ window.show_cursor(show); }; context.relative_mouse_mode = [&](bool mode){ window.relative_mouse_mode(mode); }; context.windowed = [&](bool on){ window.windowed(on); }; + context.text_input = [](bool on){ if (on) SDL_StartTextInput(); else SDL_StopTextInput(); }; #if defined(PSEMEK_GRAPHICS_API_OPENGL) context.vsync = [&](bool on){ window.vsync(on); };