mirror of
https://github.com/love2d/love.git
synced 2026-08-16 16:20:42 +02:00
Improved the performance of love.window.getPixelScale / toPixels / fromPixels by caching some values. Made some coordinate space-sensitive code use the proper conversions to get to the correct coordinate space.
--HG-- branch : minor
This commit is contained in:
@@ -573,7 +573,7 @@ public:
|
||||
* 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;
|
||||
virtual void setTextInput(bool enable, double x, double y, double w, double h) = 0;
|
||||
|
||||
/**
|
||||
* Gets whether text input events are enabled.
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
**/
|
||||
|
||||
#include "Keyboard.h"
|
||||
#include "window/Window.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -117,11 +118,18 @@ void Keyboard::setTextInput(bool enable)
|
||||
SDL_StopTextInput();
|
||||
}
|
||||
|
||||
void Keyboard::setTextInput(bool enable, int x, int y, int w, int h)
|
||||
void Keyboard::setTextInput(bool enable, double x, double y, double w, double 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 expects coordinates in window-space but setTextInput
|
||||
// takes pixels, so we should convert.
|
||||
window::Window *window = Module::getInstance<window::Window>(M_WINDOW);
|
||||
if (window)
|
||||
{
|
||||
window->pixelToWindowCoords(&x, &y);
|
||||
window->pixelToWindowCoords(&w, &h);
|
||||
}
|
||||
|
||||
SDL_Rect rect = {(int) x, (int) y, (int) w, (int) h};
|
||||
SDL_SetTextInputRect(&rect);
|
||||
|
||||
setTextInput(enable);
|
||||
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
Scancode getScancodeFromKey(Key key) const;
|
||||
|
||||
void setTextInput(bool enable);
|
||||
void setTextInput(bool enable, int x, int y, int w, int h);
|
||||
void setTextInput(bool enable, double x, double y, double w, double h);
|
||||
bool hasTextInput() const;
|
||||
bool hasScreenKeyboard() const;
|
||||
|
||||
|
||||
@@ -119,10 +119,10 @@ int w_setTextInput(lua_State *L)
|
||||
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);
|
||||
double x = luaL_checknumber(L, 2);
|
||||
double y = luaL_checknumber(L, 3);
|
||||
double w = luaL_checknumber(L, 4);
|
||||
double h = luaL_checknumber(L, 5);
|
||||
instance()->setTextInput(enable, x, y, w, h);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user