mirror of
https://github.com/love2d/love.git
synced 2026-08-17 11:00:31 +02:00
Added a love.keyboard.setTextInput variant (setTextInput(enable, x, y, width, height)) to specify a rectangle where text is expected to be displayed on the screen. This is used as a hint so on-screen keyboards won't cover the text area.
Added love.keyboard.hasScreenKeyboard. --HG-- branch : minor
This commit is contained in:
@@ -563,16 +563,29 @@ public:
|
|||||||
virtual Scancode getScancodeFromKey(Key key) const = 0;
|
virtual Scancode getScancodeFromKey(Key key) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether text input events should be sent
|
* Sets whether text input events should be received.
|
||||||
* @param enable Whether to send text input events.
|
* @param enable Whether to receive text input events.
|
||||||
**/
|
**/
|
||||||
virtual void setTextInput(bool enable) = 0;
|
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.
|
* Gets whether text input events are enabled.
|
||||||
**/
|
**/
|
||||||
virtual bool hasTextInput() const = 0;
|
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(const char *in, Key &out);
|
||||||
static bool getConstant(Key in, const char *&out);
|
static bool getConstant(Key in, const char *&out);
|
||||||
|
|
||||||
|
|||||||
@@ -117,11 +117,26 @@ void Keyboard::setTextInput(bool enable)
|
|||||||
SDL_StopTextInput();
|
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
|
bool Keyboard::hasTextInput() const
|
||||||
{
|
{
|
||||||
return SDL_IsTextInputActive();
|
return SDL_IsTextInputActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Keyboard::hasScreenKeyboard() const
|
||||||
|
{
|
||||||
|
return SDL_HasScreenKeyboardSupport();
|
||||||
|
}
|
||||||
|
|
||||||
bool Keyboard::getConstant(Scancode in, SDL_Scancode &out)
|
bool Keyboard::getConstant(Scancode in, SDL_Scancode &out)
|
||||||
{
|
{
|
||||||
return scancodes.find(in, out);
|
return scancodes.find(in, out);
|
||||||
|
|||||||
@@ -53,7 +53,9 @@ public:
|
|||||||
Scancode getScancodeFromKey(Key key) const;
|
Scancode getScancodeFromKey(Key key) const;
|
||||||
|
|
||||||
void setTextInput(bool enable);
|
void setTextInput(bool enable);
|
||||||
|
void setTextInput(bool enable, int x, int y, int w, int h);
|
||||||
bool hasTextInput() const;
|
bool hasTextInput() const;
|
||||||
|
bool hasScreenKeyboard() const;
|
||||||
|
|
||||||
static bool getConstant(Scancode in, SDL_Scancode &out);
|
static bool getConstant(Scancode in, SDL_Scancode &out);
|
||||||
static bool getConstant(SDL_Scancode in, Scancode &out);
|
static bool getConstant(SDL_Scancode in, Scancode &out);
|
||||||
|
|||||||
@@ -113,7 +113,19 @@ int w_getKeyFromScancode(lua_State *L)
|
|||||||
|
|
||||||
int w_setTextInput(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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,6 +135,12 @@ int w_hasTextInput(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int w_hasScreenKeyboard(lua_State *L)
|
||||||
|
{
|
||||||
|
luax_pushboolean(L, instance()->hasScreenKeyboard());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// List of functions to wrap.
|
// List of functions to wrap.
|
||||||
static const luaL_Reg functions[] =
|
static const luaL_Reg functions[] =
|
||||||
{
|
{
|
||||||
@@ -130,6 +148,7 @@ static const luaL_Reg functions[] =
|
|||||||
{ "hasKeyRepeat", w_hasKeyRepeat },
|
{ "hasKeyRepeat", w_hasKeyRepeat },
|
||||||
{ "setTextInput", w_setTextInput },
|
{ "setTextInput", w_setTextInput },
|
||||||
{ "hasTextInput", w_hasTextInput },
|
{ "hasTextInput", w_hasTextInput },
|
||||||
|
{ "hasScreenKeyboard", w_hasScreenKeyboard },
|
||||||
{ "isDown", w_isDown },
|
{ "isDown", w_isDown },
|
||||||
{ "isScancodeDown", w_isScancodeDown },
|
{ "isScancodeDown", w_isScancodeDown },
|
||||||
{ "getScancodeFromKey", w_getScancodeFromKey },
|
{ "getScancodeFromKey", w_getScancodeFromKey },
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ int w_getKeyFromScancode(lua_State *L);
|
|||||||
int w_getScancodeFromkey(lua_State *L);
|
int w_getScancodeFromkey(lua_State *L);
|
||||||
int w_setTextInput(lua_State *L);
|
int w_setTextInput(lua_State *L);
|
||||||
int w_hasTextInput(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);
|
extern "C" LOVE_EXPORT int luaopen_love_keyboard(lua_State *L);
|
||||||
|
|
||||||
} // keyboard
|
} // keyboard
|
||||||
|
|||||||
Reference in New Issue
Block a user