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:
Alex Szpakowski
2015-02-23 17:55:30 -04:00
parent 182792de85
commit 52c4f2c119
14 changed files with 112 additions and 114 deletions
+12 -4
View File
@@ -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);