mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
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:
@@ -112,18 +112,10 @@ love::mouse::Cursor *Mouse::getCursor() const
|
|||||||
return curCursor.get();
|
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 Mouse::getX() const
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
GetSDLMouseState(&x, nullptr);
|
SDL_GetMouseState(&x, nullptr);
|
||||||
windowToPixelCoords(&x, nullptr);
|
windowToPixelCoords(&x, nullptr);
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
@@ -132,7 +124,7 @@ int Mouse::getX() const
|
|||||||
int Mouse::getY() const
|
int Mouse::getY() const
|
||||||
{
|
{
|
||||||
int y;
|
int y;
|
||||||
GetSDLMouseState(nullptr, &y);
|
SDL_GetMouseState(nullptr, &y);
|
||||||
windowToPixelCoords(nullptr, &y);
|
windowToPixelCoords(nullptr, &y);
|
||||||
|
|
||||||
return y;
|
return y;
|
||||||
@@ -141,7 +133,7 @@ int Mouse::getY() const
|
|||||||
void Mouse::getPosition(int &x, int &y) const
|
void Mouse::getPosition(int &x, int &y) const
|
||||||
{
|
{
|
||||||
int mx, my;
|
int mx, my;
|
||||||
GetSDLMouseState(&mx, &my);
|
SDL_GetMouseState(&mx, &my);
|
||||||
windowToPixelCoords(&mx, &my);
|
windowToPixelCoords(&mx, &my);
|
||||||
|
|
||||||
x = mx;
|
x = mx;
|
||||||
@@ -158,6 +150,11 @@ void Mouse::setPosition(int x, int y)
|
|||||||
|
|
||||||
pixelToWindowCoords(&x, &y);
|
pixelToWindowCoords(&x, &y);
|
||||||
SDL_WarpMouseInWindow(handle, 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)
|
void Mouse::setX(int x)
|
||||||
|
|||||||
Reference in New Issue
Block a user