Skip to content

Instantly share code, notes, and snippets.

@josephg
Created October 14, 2017 06:26
Show Gist options
  • Select an option

  • Save josephg/a54367b678e6c38c38e6e247f97b1624 to your computer and use it in GitHub Desktop.

Select an option

Save josephg/a54367b678e6c38c38e6e247f97b1624 to your computer and use it in GitHub Desktop.
Smooth scrolling fixes for SDL and love2d
diff -r 37e1ced87caf src/modules/event/sdl/Event.cpp
--- a/src/modules/event/sdl/Event.cpp Wed Aug 02 02:56:02 2017 +0300
+++ b/src/modules/event/sdl/Event.cpp Sat Oct 14 17:25:09 2017 +1100
@@ -270,8 +270,8 @@
}
break;
case SDL_MOUSEWHEEL:
- vargs.emplace_back((double) e.wheel.x);
- vargs.emplace_back((double) e.wheel.y);
+ vargs.emplace_back((double) e.wheel.preciseX);
+ vargs.emplace_back((double) e.wheel.preciseY);
msg = new Message("wheelmoved", vargs);
break;
case SDL_FINGERDOWN:
diff -r 817e632daa35 include/SDL_events.h
--- a/include/SDL_events.h Fri Oct 13 19:55:07 2017 -0700
+++ b/include/SDL_events.h Sat Oct 14 17:24:40 2017 +1100
@@ -271,6 +271,7 @@
Sint32 x; /**< The amount scrolled horizontally, positive to the right and negative to the left */
Sint32 y; /**< The amount scrolled vertically, positive away from the user and negative toward the user */
Uint32 direction; /**< Set to one of the SDL_MOUSEWHEEL_* defines. When FLIPPED the values in X and Y will be opposite. Multiply by -1 to change them back */
+ float preciseX, preciseY;
} SDL_MouseWheelEvent;
/**
diff -r 817e632daa35 src/events/SDL_mouse.c
--- a/src/events/SDL_mouse.c Fri Oct 13 19:55:07 2017 -0700
+++ b/src/events/SDL_mouse.c Sat Oct 14 17:24:40 2017 +1100
@@ -550,7 +550,7 @@
event.type = SDL_MOUSEWHEEL;
event.wheel.windowID = mouse->focus ? mouse->focus->id : 0;
event.wheel.which = mouseID;
-#if 0 /* Uncomment this when it goes in for SDL 2.1 */
+#if 1 /* Uncomment this when it goes in for SDL 2.1 */
event.wheel.preciseX = x;
event.wheel.preciseY = y;
#endif
diff -r 817e632daa35 src/video/cocoa/SDL_cocoaevents.m
--- a/src/video/cocoa/SDL_cocoaevents.m Fri Oct 13 19:55:07 2017 -0700
+++ b/src/video/cocoa/SDL_cocoaevents.m Sat Oct 14 17:24:40 2017 +1100
@@ -380,7 +380,7 @@
}
[NSApp finishLaunching];
NSDictionary *appDefaults = [[NSDictionary alloc] initWithObjectsAndKeys:
- [NSNumber numberWithBool:NO], @"AppleMomentumScrollSupported",
+// [NSNumber numberWithBool:NO], @"AppleMomentumScrollSupported",
[NSNumber numberWithBool:NO], @"ApplePressAndHoldEnabled",
[NSNumber numberWithBool:YES], @"ApplePersistenceIgnoreState",
nil];
diff -r 817e632daa35 src/video/cocoa/SDL_cocoamouse.m
--- a/src/video/cocoa/SDL_cocoamouse.m Fri Oct 13 19:55:07 2017 -0700
+++ b/src/video/cocoa/SDL_cocoamouse.m Sat Oct 14 17:24:40 2017 +1100
@@ -422,17 +422,21 @@
{
SDL_Mouse *mouse = SDL_GetMouse();
- CGFloat x = -[event deltaX];
- CGFloat y = [event deltaY];
+ CGFloat x, y;
+ if ([event hasPreciseScrollingDeltas]) {
+ x = [event scrollingDeltaX] / 10;
+ y = [event scrollingDeltaY] / 10;
+ } else {
+ x = [event deltaX];
+ y = [event deltaY];
+ }
SDL_MouseWheelDirection direction = SDL_MOUSEWHEEL_NORMAL;
- if ([event respondsToSelector:@selector(isDirectionInvertedFromDevice)]) {
- if ([event isDirectionInvertedFromDevice] == YES) {
- direction = SDL_MOUSEWHEEL_FLIPPED;
- }
+ if ([event isDirectionInvertedFromDevice] == YES) {
+ direction = SDL_MOUSEWHEEL_FLIPPED;
}
- SDL_SendMouseWheel(window, mouse->mouseID, x, y, direction);
+ SDL_SendMouseWheel(window, mouse->mouseID, -x, y, direction);
}
void
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment