SDL: Bug: SDL_SetRelativeMouseMode() does not restore cursor position correctly
https://github.com/libsdl-org/SDL/assets/77922942/8d228139-6b8d-462b-9330-9ee159ec1a0f
Using Love2D 11.4 on Windows, tested both the default distribution as well as with SDL.dll replaced to latest release.
crosshairX, crosshairY = 0 , 0
posX, posY = 0 , 0
panning = false
function love.mousepressed( x, y, button, istouch, presses )
if button==3 then
crosshairX , crosshairY = x , y
panning = true
love.mouse.setRelativeMode(true)
end
end
function love.mousereleased( x, y, button, istouch, presses )
if button==3 then
love.mouse.setRelativeMode(false)
panning = false
crosshairX , crosshairY = 0 , 0
end
end
function love.mousemoved( x, y, dx, dy, istouch )
if panning then
posX = posX + dx
posY = posY + dy
end
end
function love.draw()
local w,h = love.graphics.getDimensions()
local x,y = w/2 - posX , h/2 - posY
love.graphics.rectangle('line',x-50,y-50,100,100)
love.graphics.line(x,0,x,h)
love.graphics.line(0,y,w,y)
if panning then
love.graphics.line(crosshairX,0,crosshairX,h)
love.graphics.line(0,crosshairY,w,crosshairY)
end
end
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 22 (14 by maintainers)
Ah I see, it’s a bit ambiguous here whether we’re talking about the OS logical cursor position or SDL’s internal position when we say “mouse position”. Indeed this will solve the usecase.
Perhaps can we also have a flag that keeps the cursor visible at where it’s logically locked to (screen center), for those who really want the under-the-hood behavior to be visible?
Or maybe just make it a different API call altogether that has the more fine-grained control over what you want, rather than overloading the out-of-box experience of the RelativeMode API with flags? Something that lets you declare that you want to subscribe to a particular input source, rather than setting a global state. This architecture would also open the door for easier ManyMouse integration. These are just spurious suggestions so take it with a grain of salt, the main point is to conveying the existence of a desired usecase.
Out of curiosity, could you elaborate a bit more on what you meant with the map edge scrolling mechanic?