diff options
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); +} |