summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-04-19 14:36:27 +0200
committerKonstantin Käfer <mail@kkaefer.com>2016-04-26 10:42:33 +0200
commit4770a9eb21450bbc002201de81b2310287935d67 (patch)
treecf1251f5e1b31deb848cec8ac31a062e7b81eefc
parentf9bdaa9d3a43ec7bb8ec8993b65177807e82f80f (diff)
downloadqtlocation-mapboxgl-4770a9eb21450bbc002201de81b2310287935d67.tar.gz
[osx] make scrollwheel zooming smoother
- uses the same algorithm as the GLFW app to determine scrollwheel zoom speed - disables transitions which makes the trackpad feel faster due to immediate response
-rw-r--r--platform/osx/src/MGLMapView.mm20
1 files changed, 14 insertions, 6 deletions
diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm
index d6f55a92ff..2f211d56a2 100644
--- a/platform/osx/src/MGLMapView.mm
+++ b/platform/osx/src/MGLMapView.mm
@@ -1416,12 +1416,20 @@ public:
BOOL isScrollWheel = event.phase == NSEventPhaseNone && event.momentumPhase == NSEventPhaseNone && !event.hasPreciseScrollingDeltas;
if (isScrollWheel || [[NSUserDefaults standardUserDefaults] boolForKey:MGLScrollWheelZoomsMapViewDefaultKey]) {
// A traditional, vertical scroll wheel zooms instead of panning.
- if (self.zoomEnabled && std::abs(event.scrollingDeltaX) < std::abs(event.scrollingDeltaY)) {
- _mbglMap->cancelTransitions();
-
- NSPoint gesturePoint = [self convertPoint:event.locationInWindow fromView:nil];
- double zoomDelta = event.scrollingDeltaY / 4;
- [self scaleBy:exp2(zoomDelta) atPoint:gesturePoint animated:YES];
+ if (self.zoomEnabled) {
+ const double delta =
+ event.scrollingDeltaY / ([event hasPreciseScrollingDeltas] ? 100 : 10);
+ if (delta != 0) {
+ double scale = 2.0 / (1.0 + std::exp(-std::abs(delta)));
+
+ // Zooming out.
+ if (delta < 0) {
+ scale = 1.0 / scale;
+ }
+
+ NSPoint gesturePoint = [self convertPoint:event.locationInWindow fromView:nil];
+ [self scaleBy:scale atPoint:gesturePoint animated:NO];
+ }
}
} else if (self.scrollEnabled
&& _magnificationGestureRecognizer.state == NSGestureRecognizerStatePossible