OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 | 8 #include <algorithm> |
9 | 9 |
10 #include "SkTouchGesture.h" | 10 #include "SkTouchGesture.h" |
11 #include "SkMatrix.h" | 11 #include "SkMatrix.h" |
12 #include "SkTime.h" | 12 #include "SkTime.h" |
13 | 13 |
14 #define DISCRETIZE_TRANSLATE_TO_AVOID_FLICKER true | 14 #define DISCRETIZE_TRANSLATE_TO_AVOID_FLICKER true |
15 | 15 |
16 static const SkScalar MAX_FLING_SPEED = SkIntToScalar(1500); | 16 static const SkScalar MAX_FLING_SPEED = SkIntToScalar(1500); |
17 | 17 |
18 static SkScalar pin_max_fling(SkScalar speed) { | 18 static SkScalar pin_max_fling(SkScalar speed) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 /////////////////////////////////////////////////////////////////////////////// | 102 /////////////////////////////////////////////////////////////////////////////// |
103 | 103 |
104 SkTouchGesture::SkTouchGesture() { | 104 SkTouchGesture::SkTouchGesture() { |
105 this->reset(); | 105 this->reset(); |
106 } | 106 } |
107 | 107 |
108 SkTouchGesture::~SkTouchGesture() { | 108 SkTouchGesture::~SkTouchGesture() { |
109 } | 109 } |
110 | 110 |
111 void SkTouchGesture::reset() { | 111 void SkTouchGesture::reset() { |
| 112 fIsTransLimited = false; |
112 fTouches.reset(); | 113 fTouches.reset(); |
113 fState = kEmpty_State; | 114 fState = kEmpty_State; |
114 fLocalM.reset(); | 115 fLocalM.reset(); |
115 fGlobalM.reset(); | 116 fGlobalM.reset(); |
116 | 117 |
117 fLastUpMillis = SkTime::GetMSecs() - 2*MAX_DBL_TAP_INTERVAL; | 118 fLastUpMillis = SkTime::GetMSecs() - 2*MAX_DBL_TAP_INTERVAL; |
118 fLastUpP.set(0, 0); | 119 fLastUpP.set(0, 0); |
119 } | 120 } |
120 | 121 |
121 void SkTouchGesture::flushLocalM() { | 122 void SkTouchGesture::flushLocalM() { |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 this->flushLocalM(); | 287 this->flushLocalM(); |
287 SkASSERT(kZoom_State == fState); | 288 SkASSERT(kZoom_State == fState); |
288 fState = kEmpty_State; | 289 fState = kEmpty_State; |
289 break; | 290 break; |
290 default: | 291 default: |
291 SkASSERT(kZoom_State == fState); | 292 SkASSERT(kZoom_State == fState); |
292 break; | 293 break; |
293 } | 294 } |
294 | 295 |
295 fTouches.removeShuffle(index); | 296 fTouches.removeShuffle(index); |
| 297 |
| 298 limitTrans(); |
296 } | 299 } |
297 | 300 |
298 float SkTouchGesture::computePinch(const Rec& rec0, const Rec& rec1) { | 301 float SkTouchGesture::computePinch(const Rec& rec0, const Rec& rec1) { |
299 double dx = rec0.fStartX - rec1.fStartX; | 302 double dx = rec0.fStartX - rec1.fStartX; |
300 double dy = rec0.fStartY - rec1.fStartY; | 303 double dy = rec0.fStartY - rec1.fStartY; |
301 double dist0 = sqrt(dx*dx + dy*dy); | 304 double dist0 = sqrt(dx*dx + dy*dy); |
302 | 305 |
303 dx = rec0.fLastX - rec1.fLastX; | 306 dx = rec0.fLastX - rec1.fLastX; |
304 dy = rec0.fLastY - rec1.fLastY; | 307 dy = rec0.fLastY - rec1.fLastY; |
305 double dist1 = sqrt(dx*dx + dy*dy); | 308 double dist1 = sqrt(dx*dx + dy*dy); |
(...skipping 14 matching lines...) Expand all Loading... |
320 fTouches.reset(); | 323 fTouches.reset(); |
321 fState = kEmpty_State; | 324 fState = kEmpty_State; |
322 found = true; | 325 found = true; |
323 } | 326 } |
324 } | 327 } |
325 | 328 |
326 fLastUpMillis = now; | 329 fLastUpMillis = now; |
327 fLastUpP.set(x, y); | 330 fLastUpP.set(x, y); |
328 return found; | 331 return found; |
329 } | 332 } |
| 333 |
| 334 void SkTouchGesture::setTransLimit(const SkRect& contentRect, const SkRect& wind
owRect) { |
| 335 fIsTransLimited = true; |
| 336 fContentRect = contentRect; |
| 337 fWindowRect = windowRect; |
| 338 } |
| 339 |
| 340 void SkTouchGesture::limitTrans() { |
| 341 if (!fIsTransLimited) { |
| 342 return; |
| 343 } |
| 344 |
| 345 SkRect scaledContent = fContentRect; |
| 346 fGlobalM.mapRect(&scaledContent); |
| 347 const SkScalar ZERO = 0; |
| 348 |
| 349 fGlobalM.postTranslate(ZERO, std::min(ZERO, fWindowRect.fBottom - scaledCont
ent.fTop)); |
| 350 fGlobalM.postTranslate(ZERO, std::max(ZERO, fWindowRect.fTop - scaledContent
.fBottom)); |
| 351 fGlobalM.postTranslate(std::min(ZERO, fWindowRect.fRight - scaledContent.fLe
ft), ZERO); |
| 352 fGlobalM.postTranslate(std::max(ZERO, fWindowRect.fLeft - scaledContent.fRig
ht), ZERO); |
| 353 } |
OLD | NEW |