Browse Source

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.
Alex Szpakowski 10 years ago
parent
commit
8a9a73151d
1 changed files with 11 additions and 3 deletions
  1. 11 3
      src/modules/mouse/sdl/Mouse.cpp

+ 11 - 3
src/modules/mouse/sdl/Mouse.cpp

@@ -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;