A better fix for love.mouse.setPosition not updating the return values of love.window.getPosition until the next love.event.pump call on Windows and Linux.

This commit is contained in:
Alex Szpakowski
2015-01-31 02:36:31 -04:00
parent f6bd177f84
commit 8989e39b1e
+8 -11
View File
@@ -112,18 +112,10 @@ 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;
GetSDLMouseState(&x, nullptr);
SDL_GetMouseState(&x, nullptr);
windowToPixelCoords(&x, nullptr);
return x;
@@ -132,7 +124,7 @@ int Mouse::getX() const
int Mouse::getY() const
{
int y;
GetSDLMouseState(nullptr, &y);
SDL_GetMouseState(nullptr, &y);
windowToPixelCoords(nullptr, &y);
return y;
@@ -141,7 +133,7 @@ int Mouse::getY() const
void Mouse::getPosition(int &x, int &y) const
{
int mx, my;
GetSDLMouseState(&mx, &my);
SDL_GetMouseState(&mx, &my);
windowToPixelCoords(&mx, &my);
x = mx;
@@ -158,6 +150,11 @@ void Mouse::setPosition(int x, int y)
pixelToWindowCoords(&x, &y);
SDL_WarpMouseInWindow(handle, x, y);
// SDL_WarpMouse doesn't directly update SDL's internal mouse state in Linux
// and Windows, so we call SDL_PumpEvents now to make sure the next
// getPosition call always returns the updated state.
SDL_PumpEvents();
}
void Mouse::setX(int x)