mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user