libgdx / libgdx.github.io

Github hosted site for libGDX
61 stars 217 forks source link

`scrolled` event is sorta wrong #175

Closed Frosty-J closed 8 months ago

Frosty-J commented 8 months ago

I can't think of the good words at the mo...

Reports either -1 or 1 depending on the direction of spin.

...but this is not entirely correct. Pre-1.9.12, yeah, good enough. It would only not be -1 or 1 if the user managed to scroll two or more clicks in one frame.

But since then, either axis can be 0 (X if the user is scrolling Y, or vice-versa) and fractional amounts (on my touchpad I get 0.016666668, 0.025, 0.033333335...). In my testing, if you scroll diagonally, it will alternate between X and Y (or Y and X - it's hard to tell).

1.95, -0.0
-0.0, -2.5166667
3.3416667, -0.0
-0.0, -1.675

https://libgdx.com/wiki/input/event-handling

Frosty-J commented 8 months ago

See, it can be 0 as well (interestingly, positive 0 instead of negative 0 when on LWJGL2). "Positive or negative" could lead someone to believe the following code is safe, when it would inadvertently report as scrolling up if the user scrolls horizontally (with touchpad, not sure how else):

if (amountY > 0) Gdx.app.log("scroll", "down");
else Gdx.app.log("scroll", "up");

I'm overthinking this, to be fair. Never had a reason to perform that sort of condition check, just stuff like scrollY += amountY.

crykn commented 8 months ago

Changed in 13a5e9c.