aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/views/SkTouchGesture.cpp
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 /src/views/SkTouchGesture.cpp
parent87751127172bd49c632c9290ffde43385d38ce61 (diff)
Correct gesture scale and translation
Diffstat (limited to 'src/views/SkTouchGesture.cpp')
-rw-r--r--src/views/SkTouchGesture.cpp26
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);
+}