diff options
author | Yuqian Li <liyuqian@google.com> | 2018-03-28 16:23:31 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-03-28 20:51:44 +0000 |
commit | 755778cda0608e314340f3937618d3410b54e668 (patch) | |
tree | 4990bad5305a7adfa2147f2d59bf3294eadebf01 /tools/viewer/Viewer.cpp | |
parent | 470d82973182d0c4e30568c20af9d96dcfd63485 (diff) |
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 <brianosman@google.com>
Commit-Queue: Yuqian Li <liyuqian@google.com>
Diffstat (limited to 'tools/viewer/Viewer.cpp')
-rw-r--r-- | tools/viewer/Viewer.cpp | 22 |
1 files changed, 15 insertions, 7 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); -} -SkMatrix Viewer::computeMatrix() { - SkMatrix m; + // 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 = fGesture.localM(); - m.preConcat(fGesture.globalM()); - m.preConcat(fDefaultMatrix); m.preScale(zoomScale, zoomScale); + return m; +} +SkMatrix Viewer::computeMatrix() { + SkMatrix m = fGesture.localM(); + m.preConcat(fGesture.globalM()); + m.preConcat(this->computePreTouchMatrix()); return m; } |