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>
This commit is contained in:
Yuqian Li 2018-03-28 16:23:31 -04:00 committed by Skia Commit-Bot
parent 470d829731
commit 755778cda0
2 changed files with 18 additions and 9 deletions

View File

@ -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;
}

View File

@ -99,6 +99,7 @@ private:
void drawImGui();
void changeZoomLevel(float delta);
SkMatrix computePreTouchMatrix();
SkMatrix computeMatrix();
SkPoint mapEvent(float x, float y);