Pump events when calling love.mouse.getPosition/getX/getY/setX/setY, since some of SDL's backends don't update the internal mouse state until the next PumpEvents, if SDL_WarpMouseInWindow was called previously.

Resolves issue #968.
This commit is contained in:
Alex Szpakowski
2015-01-03 23:02:10 -04:00
parent c7b45b3505
commit 8a9a73151d
+11 -3
View File
@@ -112,10 +112,18 @@ love::mouse::Cursor *Mouse::getCursor() const
return curCursor.get();
}
static Uint32 GetSDLMouseState(int *x, int *y)
{
// SDL's Linux and Windows video backends don't update the internal mouse
// state until the next PumpEvents, if SDL_WarpMouse was called previously.
SDL_PumpEvents();
return SDL_GetMouseState(x, y);
}
int Mouse::getX() const
{
int x;
SDL_GetMouseState(&x, nullptr);
GetSDLMouseState(&x, nullptr);
windowToPixelCoords(&x, nullptr);
return x;
@@ -124,7 +132,7 @@ int Mouse::getX() const
int Mouse::getY() const
{
int y;
SDL_GetMouseState(nullptr, &y);
GetSDLMouseState(nullptr, &y);
windowToPixelCoords(nullptr, &y);
return y;
@@ -133,7 +141,7 @@ int Mouse::getY() const
void Mouse::getPosition(int &x, int &y) const
{
int mx, my;
SDL_GetMouseState(&mx, &my);
GetSDLMouseState(&mx, &my);
windowToPixelCoords(&mx, &my);
x = mx;