diff --git a/src/modules/keyboard/Keyboard.h b/src/modules/keyboard/Keyboard.h index 513bb2dbc..ab36eeda6 100644 --- a/src/modules/keyboard/Keyboard.h +++ b/src/modules/keyboard/Keyboard.h @@ -563,16 +563,29 @@ public: virtual Scancode getScancodeFromKey(Key key) const = 0; /** - * Sets whether text input events should be sent - * @param enable Whether to send text input events. + * Sets whether text input events should be received. + * @param enable Whether to receive text input events. **/ virtual void setTextInput(bool enable) = 0; + /** + * Sets whether text input events should be received, and specifies where + * on the screen the text will appear. This is used as a hint so on-screen + * keyboards don't cover the text area. + **/ + virtual void setTextInput(bool enable, int x, int y, int w, int h) = 0; + /** * Gets whether text input events are enabled. **/ virtual bool hasTextInput() const = 0; + /** + * Gets whether the system will display an on-screen keyboard when text input + * events are enabled. + **/ + virtual bool hasScreenKeyboard() const = 0; + static bool getConstant(const char *in, Key &out); static bool getConstant(Key in, const char *&out); diff --git a/src/modules/keyboard/sdl/Keyboard.cpp b/src/modules/keyboard/sdl/Keyboard.cpp index 77e4ee296..e6c5a6d8b 100644 --- a/src/modules/keyboard/sdl/Keyboard.cpp +++ b/src/modules/keyboard/sdl/Keyboard.cpp @@ -117,11 +117,26 @@ void Keyboard::setTextInput(bool enable) SDL_StopTextInput(); } +void Keyboard::setTextInput(bool enable, int x, int y, int w, int h) +{ + // TODO: SetTextInputRect expects coordinates in window-space, but + // setTextInput uses pixels. We should convert here. + SDL_Rect rect = {x, y, w, h}; + SDL_SetTextInputRect(&rect); + + setTextInput(enable); +} + bool Keyboard::hasTextInput() const { return SDL_IsTextInputActive(); } +bool Keyboard::hasScreenKeyboard() const +{ + return SDL_HasScreenKeyboardSupport(); +} + bool Keyboard::getConstant(Scancode in, SDL_Scancode &out) { return scancodes.find(in, out); diff --git a/src/modules/keyboard/sdl/Keyboard.h b/src/modules/keyboard/sdl/Keyboard.h index 9e777f9bd..27a16f67b 100644 --- a/src/modules/keyboard/sdl/Keyboard.h +++ b/src/modules/keyboard/sdl/Keyboard.h @@ -53,7 +53,9 @@ public: Scancode getScancodeFromKey(Key key) const; void setTextInput(bool enable); + void setTextInput(bool enable, int x, int y, int w, int h); bool hasTextInput() const; + bool hasScreenKeyboard() const; static bool getConstant(Scancode in, SDL_Scancode &out); static bool getConstant(SDL_Scancode in, Scancode &out); diff --git a/src/modules/keyboard/wrap_Keyboard.cpp b/src/modules/keyboard/wrap_Keyboard.cpp index 3c8e1ed53..136a3a0f1 100644 --- a/src/modules/keyboard/wrap_Keyboard.cpp +++ b/src/modules/keyboard/wrap_Keyboard.cpp @@ -113,7 +113,19 @@ int w_getKeyFromScancode(lua_State *L) int w_setTextInput(lua_State *L) { - instance()->setTextInput(luax_toboolean(L, 1)); + bool enable = luax_toboolean(L, 1); + + if (lua_gettop(L) <= 1) + instance()->setTextInput(enable); + else + { + int x = (int) luaL_checkinteger(L, 2); + int y = (int) luaL_checkinteger(L, 3); + int w = (int) luaL_checkinteger(L, 4); + int h = (int) luaL_checkinteger(L, 5); + instance()->setTextInput(enable, x, y, w, h); + } + return 0; } @@ -123,6 +135,12 @@ int w_hasTextInput(lua_State *L) return 1; } +int w_hasScreenKeyboard(lua_State *L) +{ + luax_pushboolean(L, instance()->hasScreenKeyboard()); + return 1; +} + // List of functions to wrap. static const luaL_Reg functions[] = { @@ -130,6 +148,7 @@ static const luaL_Reg functions[] = { "hasKeyRepeat", w_hasKeyRepeat }, { "setTextInput", w_setTextInput }, { "hasTextInput", w_hasTextInput }, + { "hasScreenKeyboard", w_hasScreenKeyboard }, { "isDown", w_isDown }, { "isScancodeDown", w_isScancodeDown }, { "getScancodeFromKey", w_getScancodeFromKey }, diff --git a/src/modules/keyboard/wrap_Keyboard.h b/src/modules/keyboard/wrap_Keyboard.h index 28657d17d..952fe018a 100644 --- a/src/modules/keyboard/wrap_Keyboard.h +++ b/src/modules/keyboard/wrap_Keyboard.h @@ -38,6 +38,7 @@ int w_getKeyFromScancode(lua_State *L); int w_getScancodeFromkey(lua_State *L); int w_setTextInput(lua_State *L); int w_hasTextInput(lua_State *L); +int w_hasScreenKeyboard(lua_State *L); extern "C" LOVE_EXPORT int luaopen_love_keyboard(lua_State *L); } // keyboard