Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Unified Diff: tools/viewer/Viewer.cpp

Issue 1996613002: Correct gesture scale and translation (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: nits Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/viewer/Viewer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/viewer/Viewer.cpp
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index d492cdeefeb854246b90d5e721cfa43c28662cb9..12b9ebf294f0a7216dcc520941171e336f7c4f94 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -190,6 +190,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) {
@@ -247,14 +269,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);
@@ -268,17 +283,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;
}
}
« no previous file with comments | « tools/viewer/Viewer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698