From 755778cda0608e314340f3937618d3410b54e668 Mon Sep 17 00:00:00 2001 From: Yuqian Li Date: Wed, 28 Mar 2018 16:23:31 -0400 Subject: [PATCH] Update trans limit after zoom changes in viewer Previously, the trans limit assumes that only touch gesture can change the zoom level. That's not true on desktops so we need this fix. Otherwise, we won't be able to translate when we zoomed in. Bug: skia: Change-Id: I5901600a0044639a47514ab76b7e1914f04137a2 Reviewed-on: https://skia-review.googlesource.com/116987 Reviewed-by: Brian Osman Commit-Queue: Yuqian Li --- tools/viewer/Viewer.cpp | 26 +++++++++++++++++--------- tools/viewer/Viewer.h | 1 + 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp index f4b03065e2..ad02a6574b 100644 --- a/tools/viewer/Viewer.cpp +++ b/tools/viewer/Viewer.cpp @@ -782,7 +782,7 @@ void Viewer::setupCurrentSlide() { } // Prevent the user from dragging content so far outside the window they can't find it again - fGesture.setTransLimit(slideBounds, windowRect, fDefaultMatrix); + fGesture.setTransLimit(slideBounds, windowRect, this->computePreTouchMatrix()); this->updateTitle(); this->updateUIState(); @@ -799,18 +799,26 @@ void Viewer::setupCurrentSlide() { void Viewer::changeZoomLevel(float delta) { fZoomLevel += delta; fZoomLevel = SkScalarPin(fZoomLevel, MIN_ZOOM_LEVEL, MAX_ZOOM_LEVEL); + + // Update the trans limit as the zoom level changes. + const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions(); + const SkRect slideBounds = SkRect::MakeIWH(slideSize.width(), slideSize.height()); + const SkRect windowRect = SkRect::MakeIWH(fWindow->width(), fWindow->height()); + fGesture.setTransLimit(slideBounds, windowRect, this->computePreTouchMatrix()); +} + +SkMatrix Viewer::computePreTouchMatrix() { + SkMatrix m = fDefaultMatrix; + SkScalar zoomScale = (fZoomLevel < 0) ? SK_Scalar1 / (SK_Scalar1 - fZoomLevel) + : SK_Scalar1 + fZoomLevel; + m.preScale(zoomScale, zoomScale); + return m; } SkMatrix Viewer::computeMatrix() { - SkMatrix m; - - SkScalar zoomScale = (fZoomLevel < 0) ? SK_Scalar1 / (SK_Scalar1 - fZoomLevel) - : SK_Scalar1 + fZoomLevel; - m = fGesture.localM(); + SkMatrix m = fGesture.localM(); m.preConcat(fGesture.globalM()); - m.preConcat(fDefaultMatrix); - m.preScale(zoomScale, zoomScale); - + m.preConcat(this->computePreTouchMatrix()); return m; } diff --git a/tools/viewer/Viewer.h b/tools/viewer/Viewer.h index 0443399f9a..8a1e227ce3 100644 --- a/tools/viewer/Viewer.h +++ b/tools/viewer/Viewer.h @@ -99,6 +99,7 @@ private: void drawImGui(); void changeZoomLevel(float delta); + SkMatrix computePreTouchMatrix(); SkMatrix computeMatrix(); SkPoint mapEvent(float x, float y);