mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-03-20 15:51:07 +01:00
MacOS: improve scroll smoothing
Use scrollingDelta instead of delta, as recommended by the Apple documentation. It gives much smoother scrolling.
This commit is contained in:
committed by
Sam Lantinga
parent
70eceec77b
commit
5dab2c73f0
@@ -545,27 +545,17 @@ void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
|
||||
SDL_MouseWheelDirection direction;
|
||||
CGFloat x, y;
|
||||
|
||||
x = -[event deltaX];
|
||||
y = [event deltaY];
|
||||
x = -[event scrollingDeltaX];
|
||||
y = [event scrollingDeltaY];
|
||||
direction = SDL_MOUSEWHEEL_NORMAL;
|
||||
|
||||
if ([event isDirectionInvertedFromDevice] == YES) {
|
||||
direction = SDL_MOUSEWHEEL_FLIPPED;
|
||||
}
|
||||
|
||||
/* For discrete scroll events from conventional mice, always send a full tick.
|
||||
For continuous scroll events from trackpads, send fractional deltas for smoother scrolling. */
|
||||
if (![event hasPreciseScrollingDeltas]) {
|
||||
if (x > 0) {
|
||||
x = SDL_ceil(x);
|
||||
} else if (x < 0) {
|
||||
x = SDL_floor(x);
|
||||
}
|
||||
if (y > 0) {
|
||||
y = SDL_ceil(y);
|
||||
} else if (y < 0) {
|
||||
y = SDL_floor(y);
|
||||
}
|
||||
if ([event hasPreciseScrollingDeltas]) {
|
||||
x *= 0.1;
|
||||
y *= 0.1;
|
||||
}
|
||||
|
||||
SDL_SendMouseWheel(Cocoa_GetEventTimestamp([event timestamp]), window, mouseID, x, y, direction);
|
||||
|
||||
Reference in New Issue
Block a user