diff options
author | liyuqian <liyuqian@google.com> | 2016-05-20 07:32:19 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-20 07:32:19 -0700 |
commit | e46e4f075bfa8acf038aa68a8e7da282d4c1015b (patch) | |
tree | a599a8727b8903da82c1c192323b93def50943f4 /src/views/SkTouchGesture.cpp | |
parent | 87751127172bd49c632c9290ffde43385d38ce61 (diff) |
Correct gesture scale and translation
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1996613002
Review-Url: https://codereview.chromium.org/1996613002
Diffstat (limited to 'src/views/SkTouchGesture.cpp')
-rw-r--r-- | src/views/SkTouchGesture.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/views/SkTouchGesture.cpp b/src/views/SkTouchGesture.cpp index 5fc8d7ee90..752828e37f 100644 --- a/src/views/SkTouchGesture.cpp +++ b/src/views/SkTouchGesture.cpp @@ -5,7 +5,7 @@ * found in the LICENSE file. */ - +#include <algorithm> #include "SkTouchGesture.h" #include "SkMatrix.h" @@ -109,6 +109,7 @@ SkTouchGesture::~SkTouchGesture() { } void SkTouchGesture::reset() { + fIsTransLimited = false; fTouches.reset(); fState = kEmpty_State; fLocalM.reset(); @@ -293,6 +294,8 @@ void SkTouchGesture::touchEnd(void* owner) { } fTouches.removeShuffle(index); + + limitTrans(); } float SkTouchGesture::computePinch(const Rec& rec0, const Rec& rec1) { @@ -327,3 +330,24 @@ bool SkTouchGesture::handleDblTap(float x, float y) { fLastUpP.set(x, y); return found; } + +void SkTouchGesture::setTransLimit(const SkRect& contentRect, const SkRect& windowRect) { + fIsTransLimited = true; + fContentRect = contentRect; + fWindowRect = windowRect; +} + +void SkTouchGesture::limitTrans() { + if (!fIsTransLimited) { + return; + } + + SkRect scaledContent = fContentRect; + fGlobalM.mapRect(&scaledContent); + const SkScalar ZERO = 0; + + fGlobalM.postTranslate(ZERO, std::min(ZERO, fWindowRect.fBottom - scaledContent.fTop)); + fGlobalM.postTranslate(ZERO, std::max(ZERO, fWindowRect.fTop - scaledContent.fBottom)); + fGlobalM.postTranslate(std::min(ZERO, fWindowRect.fRight - scaledContent.fLeft), ZERO); + fGlobalM.postTranslate(std::max(ZERO, fWindowRect.fLeft - scaledContent.fRight), ZERO); +} |