New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[OSX] NSScrollWheel event handling for 2D scrolling should use scrollingDeltaX/Y #6800
Comments
Untested (i.e. just written from memory) and not really pretty either, but an alternative would be: But conditional compilation isn't that bad either. I'd recommend breaking coding style here though to loose the second |
I don't quite understand why the /* Set the scroll count for scrollwheel scrolling */
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)
#define deltaSelector(AXIS) scrollingDelta##AXIS
#else
#define deltaSelector(AXIS) delta##AXIS
#endif
_cursor.h_wheel -= (int)([ event deltaSelector(X) ] / 5 * _settings_client.gui.scrollwheel_multiplier);
_cursor.v_wheel -= (int)([ event deltaSelector(Y) ] / 5 * _settings_client.gui.scrollwheel_multiplier);
#undef deltaSelector |
|
Right - my question was regarding the original post. I wondered why it was needed when the compile time check is there anyway - my example omits that because if you have a compile time check there's no point in also doing a run-time check, unless I'm mistaken. |
The compile time check/define itself doesn't prevent the app to run on an older system. Unless you stop that somewhere else, you still always need a runtime check or the user will get "unexplainable" errors. |
Right you are - I foolishly assumed that everyone would compile on the computer they're playing on. 🤦♂️ Then another suggestion is to use if (@available(macOS 10.7, *)) {
_cursor.h_wheel -= (int)([ event scrollingDeltaX ] / 5 * _settings_client.gui.scrollwheel_multiplier);
_cursor.v_wheel -= (int)([ event scrollingDeltaY ] / 5 * _settings_client.gui.scrollwheel_multiplier);
} else {
_cursor.h_wheel -= (int)([ event deltaX ] * 5 * _settings_client.gui.scrollwheel_multiplier);
_cursor.v_wheel -= (int)([ event deltaY ] * 5 * _settings_client.gui.scrollwheel_multiplier);
} More info: https://clang.llvm.org/docs/LanguageExtensions.html#objective-c-available |
This issue has been automatically marked as stale because it has not had any activity in the last two months. |
Completely forgot about this but thanks for the input! The function pointer suggestion works well, but with conditional compilation it's indeed not necessary (I got confused there).
In any case, I'll get a PR in today using |
Apple recommends using scrollingDeltaX/Y (https://developer.apple.com/documentation/appkit/nsevent/1524505-scrollingdeltax?language=objc#discussion) instead of deltaX/Y for scrolling events , which are currently being used:
OpenTTD/src/video/cocoa/event.mm
Lines 578 to 580 in e1a164b
I tried this out quickly and it makes scrolling the viewport using 2D scrolling significantly smoother: on par with dragging the viewport. I'd add it to #6793 or open a new pull request, but it's only supported since OS X 10.7 so it requires some conditional compilation and/or using selectors.
Using
respondsToSelector
andperformSelector
would be nicest, butperformSelector
doesn't work with primitives, so I've now combined it with conditional compilation, but it looks a little ugly. Using an invocation doesn't seem much better though.(Note: I've changed the multiplier for scrollingDeltaX to keep the speed similar)
Any thoughts?
The text was updated successfully, but these errors were encountered: