Skip to content

Commit

Permalink
Merge pull request #5236 from Susko3/precise-scroll
Browse files Browse the repository at this point in the history
Properly set `IsPrecise` for SDL scroll events
  • Loading branch information
peppy committed Jun 8, 2022
2 parents c7c990f + 0be8d4c commit 57d2170
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions osu.Framework/Platform/SDL2DesktopWindow.cs
Expand Up @@ -965,11 +965,22 @@ private void handleJoyAxisEvent(SDL.SDL_JoyAxisEvent evtJaxis)
enqueueJoystickAxisInput(JoystickAxisSource.Axis1 + evtJaxis.axis, evtJaxis.axisValue);
}

private void handleMouseWheelEvent(SDL.SDL_MouseWheelEvent evtWheel) =>
private uint lastPreciseScroll;

private const uint precise_scroll_debounce = 100;

private void handleMouseWheelEvent(SDL.SDL_MouseWheelEvent evtWheel)
{
bool isPrecise(float f) => f % 1 != 0;

if (isPrecise(evtWheel.preciseX) || isPrecise(evtWheel.preciseY))
lastPreciseScroll = evtWheel.timestamp;

bool precise = evtWheel.timestamp < lastPreciseScroll + precise_scroll_debounce;

// SDL reports horizontal scroll opposite of what framework expects (in non-"natural" mode, scrolling to the right gives positive deltas while we want negative).
// TODO: we should be setting the `precise` bool, but it's not simple to detect on some platforms.
// see https://github.com/ppy/osu-framework/pull/5186#issuecomment-1132064369 for further explanation.
TriggerMouseWheel(new Vector2(-evtWheel.preciseX, evtWheel.preciseY), false);
TriggerMouseWheel(new Vector2(-evtWheel.preciseX, evtWheel.preciseY), precise);
}

private void handleMouseButtonEvent(SDL.SDL_MouseButtonEvent evtButton)
{
Expand Down

0 comments on commit 57d2170

Please sign in to comment.