aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/viewer
diff options
context:
space:
mode:
authorGravatar liyuqian <liyuqian@google.com>2016-05-20 07:32:19 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-05-20 07:32:19 -0700
commite46e4f075bfa8acf038aa68a8e7da282d4c1015b (patch)
treea599a8727b8903da82c1c192323b93def50943f4 /tools/viewer
parent87751127172bd49c632c9290ffde43385d38ce61 (diff)
Correct gesture scale and translation
Diffstat (limited to 'tools/viewer')
-rw-r--r--tools/viewer/Viewer.cpp36
-rw-r--r--tools/viewer/Viewer.h4
2 files changed, 30 insertions, 10 deletions
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index 7f18652c2c..a0b2a2abe3 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -213,6 +213,28 @@ void Viewer::updateTitle() {
}
void Viewer::setupCurrentSlide(int previousSlide) {
+ fGesture.reset();
+ fDefaultMatrix.reset();
+ fDefaultMatrixInv.reset();
+
+ if (fWindow->supportsContentRect() && fWindow->scaleContentToFit()) {
+ const SkRect contentRect = fWindow->getContentRect();
+ const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions();
+ const SkRect slideBounds = SkRect::MakeIWH(slideSize.width(), slideSize.height());
+ if (contentRect.width() > 0 && contentRect.height() > 0) {
+ fDefaultMatrix.setRectToRect(slideBounds, contentRect, SkMatrix::kStart_ScaleToFit);
+ bool inverted = fDefaultMatrix.invert(&fDefaultMatrixInv);
+ SkASSERT(inverted);
+ }
+ }
+
+ if (fWindow->supportsContentRect()) {
+ const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions();
+ SkRect windowRect = fWindow->getContentRect();
+ fDefaultMatrixInv.mapRect(&windowRect);
+ fGesture.setTransLimit(SkRect::MakeWH(slideSize.width(), slideSize.height()), windowRect);
+ }
+
this->updateTitle();
fSlides[fCurrentSlide]->load();
if (previousSlide >= 0) {
@@ -269,14 +291,7 @@ void Viewer::onPaint(SkCanvas* canvas) {
}
canvas->clear(SK_ColorWHITE);
- if (fWindow->supportsContentRect() && fWindow->scaleContentToFit()) {
- const SkRect contentRect = fWindow->getContentRect();
- const SkISize slideSize = fSlides[fCurrentSlide]->getDimensions();
- const SkRect slideBounds = SkRect::MakeIWH(slideSize.width(), slideSize.height());
- SkMatrix matrix;
- matrix.setRectToRect(slideBounds, contentRect, SkMatrix::kCenter_ScaleToFit);
- canvas->concat(matrix);
- }
+ canvas->concat(fDefaultMatrix);
canvas->concat(computeMatrix());
fSlides[fCurrentSlide]->draw(canvas);
@@ -290,17 +305,18 @@ void Viewer::onPaint(SkCanvas* canvas) {
bool Viewer::onTouch(int owner, Window::InputState state, float x, float y) {
void* castedOwner = reinterpret_cast<void*>(owner);
+ SkPoint touchPoint = fDefaultMatrixInv.mapXY(x, y);
switch (state) {
case Window::kUp_InputState: {
fGesture.touchEnd(castedOwner);
break;
}
case Window::kDown_InputState: {
- fGesture.touchBegin(castedOwner, x, y);
+ fGesture.touchBegin(castedOwner, touchPoint.fX, touchPoint.fY);
break;
}
case Window::kMove_InputState: {
- fGesture.touchMoved(castedOwner, x, y);
+ fGesture.touchMoved(castedOwner, touchPoint.fX, touchPoint.fY);
break;
}
}
diff --git a/tools/viewer/Viewer.h b/tools/viewer/Viewer.h
index c785cff78e..0bafee175b 100644
--- a/tools/viewer/Viewer.h
+++ b/tools/viewer/Viewer.h
@@ -59,6 +59,10 @@ private:
sk_app::CommandSet fCommands;
SkTouchGesture fGesture;
+
+ // identity unless the window initially scales the content to fit the screen.
+ SkMatrix fDefaultMatrix;
+ SkMatrix fDefaultMatrixInv;
};