Browse Source

Platform: make text input actually working on Emscripten.

The event handlers were still disabled and SDL_IsTexInputActive() needs
to be emulated.
pull/158/head
Vladimír Vondruš 10 years ago
parent
commit
e873af7777
  1. 26
      src/Magnum/Platform/Sdl2Application.cpp
  2. 10
      src/Magnum/Platform/Sdl2Application.h

26
src/Magnum/Platform/Sdl2Application.cpp

@ -395,7 +395,6 @@ void Sdl2Application::mainLoop() {
break; break;
} }
#ifndef CORRADE_TARGET_EMSCRIPTEN
case SDL_TEXTINPUT: { case SDL_TEXTINPUT: {
TextInputEvent e{{event.text.text, std::strlen(event.text.text)}}; TextInputEvent e{{event.text.text, std::strlen(event.text.text)}};
textInputEvent(e); textInputEvent(e);
@ -405,7 +404,6 @@ void Sdl2Application::mainLoop() {
TextEditingEvent e{{event.edit.text, std::strlen(event.text.text)}, event.edit.start, event.edit.length}; TextEditingEvent e{{event.edit.text, std::strlen(event.text.text)}, event.edit.start, event.edit.length};
textEditingEvent(e); textEditingEvent(e);
} break; } break;
#endif
case SDL_QUIT: case SDL_QUIT:
#ifndef CORRADE_TARGET_EMSCRIPTEN #ifndef CORRADE_TARGET_EMSCRIPTEN
@ -462,12 +460,32 @@ void Sdl2Application::setMouseLocked(bool enabled) {
#endif #endif
} }
#ifndef CORRADE_TARGET_EMSCRIPTEN bool Sdl2Application::isTextInputActive() {
#ifndef CORRADE_TARGET_EMSCRIPTEN
return SDL_IsTextInputActive();
#else
return _isTextInputActive;
#endif
}
void Sdl2Application::startTextInput() {
SDL_StartTextInput();
#ifdef CORRADE_TARGET_EMSCRIPTEN
_isTextInputActive = true;
#endif
}
void Sdl2Application::stopTextInput() {
SDL_StopTextInput();
#ifdef CORRADE_TARGET_EMSCRIPTEN
_isTextInputActive = false;
#endif
}
void Sdl2Application::setTextInputRect(const Range2Di& rect) { void Sdl2Application::setTextInputRect(const Range2Di& rect) {
SDL_Rect r{rect.min().x(), rect.min().y(), rect.sizeX(), rect.sizeY()}; SDL_Rect r{rect.min().x(), rect.min().y(), rect.sizeX(), rect.sizeY()};
SDL_SetTextInputRect(&r); SDL_SetTextInputRect(&r);
} }
#endif
void Sdl2Application::tickEvent() { void Sdl2Application::tickEvent() {
/* If this got called, the tick event is not implemented by user and thus /* If this got called, the tick event is not implemented by user and thus

10
src/Magnum/Platform/Sdl2Application.h

@ -605,9 +605,12 @@ class Sdl2Application {
* *
* If text input is active, text input events go to @ref textInputEvent() * If text input is active, text input events go to @ref textInputEvent()
* and @ref textEditingEvent(). * and @ref textEditingEvent().
* @note Note that in @ref CORRADE_TARGET_EMSCRIPTEN "Emscripten" the
* value is emulated and might not reflect external events like
* closing on-screen keyboard.
* @see @ref startTextInput(), @ref stopTextInput() * @see @ref startTextInput(), @ref stopTextInput()
*/ */
bool isTextInputActive() { return SDL_IsTextInputActive(); } bool isTextInputActive();
/** /**
* @brief Start text input * @brief Start text input
@ -617,7 +620,7 @@ class Sdl2Application {
* @see @ref stopTextInput(), @ref isTextInputActive(), * @see @ref stopTextInput(), @ref isTextInputActive(),
* @ref setTextInputRect() * @ref setTextInputRect()
*/ */
void startTextInput() { SDL_StartTextInput(); } void startTextInput();
/** /**
* @brief Stop text input * @brief Stop text input
@ -625,7 +628,7 @@ class Sdl2Application {
* @see @ref startTextInput(), @ref isTextInputActive(), @ref textInputEvent() * @see @ref startTextInput(), @ref isTextInputActive(), @ref textInputEvent()
* @ref textEditingEvent() * @ref textEditingEvent()
*/ */
void stopTextInput() { SDL_StopTextInput(); } void stopTextInput();
/** /**
* @brief Set text input rectangle * @brief Set text input rectangle
@ -683,6 +686,7 @@ class Sdl2Application {
UnsignedInt _minimalLoopPeriod; UnsignedInt _minimalLoopPeriod;
#else #else
SDL_Surface* _glContext; SDL_Surface* _glContext;
bool _isTextInputActive = false;
#endif #endif
std::unique_ptr<Platform::Context> _context; std::unique_ptr<Platform::Context> _context;

Loading…
Cancel
Save