Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[osx] make scrollwheel zooming smoother
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
kkaefer committed Apr 19, 2016
1 parent 1df5761 commit fb0ac3d
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions platform/osx/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1369,12 +1369,20 @@ - (void)scrollWheel:(NSEvent *)event {
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
Expand Down

0 comments on commit fb0ac3d

Please sign in to comment.