| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 | 10 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 108 |
| 109 SkTouchGesture::~SkTouchGesture() { | 109 SkTouchGesture::~SkTouchGesture() { |
| 110 } | 110 } |
| 111 | 111 |
| 112 void SkTouchGesture::reset() { | 112 void SkTouchGesture::reset() { |
| 113 fTouches.reset(); | 113 fTouches.reset(); |
| 114 fState = kEmpty_State; | 114 fState = kEmpty_State; |
| 115 fLocalM.reset(); | 115 fLocalM.reset(); |
| 116 fGlobalM.reset(); | 116 fGlobalM.reset(); |
| 117 | 117 |
| 118 fLastUpT = SkTime::GetMSecs() - 2*MAX_DBL_TAP_INTERVAL; | 118 fLastUpMillis = SkTime::GetMSecs() - 2*MAX_DBL_TAP_INTERVAL; |
| 119 fLastUpP.set(0, 0); | 119 fLastUpP.set(0, 0); |
| 120 } | 120 } |
| 121 | 121 |
| 122 void SkTouchGesture::flushLocalM() { | 122 void SkTouchGesture::flushLocalM() { |
| 123 fGlobalM.postConcat(fLocalM); | 123 fGlobalM.postConcat(fLocalM); |
| 124 fLocalM.reset(); | 124 fLocalM.reset(); |
| 125 } | 125 } |
| 126 | 126 |
| 127 const SkMatrix& SkTouchGesture::localM() { | 127 const SkMatrix& SkTouchGesture::localM() { |
| 128 if (fFlinger.isActive()) { | 128 if (fFlinger.isActive()) { |
| 129 if (!fFlinger.evaluateMatrix(&fLocalM)) { | 129 if (!fFlinger.evaluateMatrix(&fLocalM)) { |
| 130 this->flushLocalM(); | 130 this->flushLocalM(); |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 return fLocalM; | 133 return fLocalM; |
| 134 } | 134 } |
| 135 | 135 |
| 136 void SkTouchGesture::appendNewRec(void* owner, float x, float y) { | 136 void SkTouchGesture::appendNewRec(void* owner, float x, float y) { |
| 137 Rec* rec = fTouches.append(); | 137 Rec* rec = fTouches.append(); |
| 138 rec->fOwner = owner; | 138 rec->fOwner = owner; |
| 139 rec->fStartX = rec->fPrevX = rec->fLastX = x; | 139 rec->fStartX = rec->fPrevX = rec->fLastX = x; |
| 140 rec->fStartY = rec->fPrevY = rec->fLastY = y; | 140 rec->fStartY = rec->fPrevY = rec->fLastY = y; |
| 141 rec->fLastT = rec->fPrevT = SkTime::GetMSecs(); | 141 rec->fLastT = rec->fPrevT = static_cast<float>(SkTime::GetSecs()); |
| 142 } | 142 } |
| 143 | 143 |
| 144 void SkTouchGesture::touchBegin(void* owner, float x, float y) { | 144 void SkTouchGesture::touchBegin(void* owner, float x, float y) { |
| 145 // SkDebugf("--- %d touchBegin %p %g %g\n", fTouches.count(), owner, x, y); | 145 // SkDebugf("--- %d touchBegin %p %g %g\n", fTouches.count(), owner, x, y); |
| 146 | 146 |
| 147 int index = this->findRec(owner); | 147 int index = this->findRec(owner); |
| 148 if (index >= 0) { | 148 if (index >= 0) { |
| 149 this->flushLocalM(); | 149 this->flushLocalM(); |
| 150 fTouches.removeShuffle(index); | 150 fTouches.removeShuffle(index); |
| 151 SkDebugf("---- already exists, removing\n"); | 151 SkDebugf("---- already exists, removing\n"); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 // not sure how valuable this is | 220 // not sure how valuable this is |
| 221 if (fTouches.count() == 2) { | 221 if (fTouches.count() == 2) { |
| 222 if (close_enough_for_jitter(rec.fLastX, rec.fLastY, x, y)) { | 222 if (close_enough_for_jitter(rec.fLastX, rec.fLastY, x, y)) { |
| 223 // SkDebugf("--- drop touchMove, withing jitter tolerance %g %g\n", r
ec.fLastX - x, rec.fLastY - y); | 223 // SkDebugf("--- drop touchMove, withing jitter tolerance %g %g\n", r
ec.fLastX - x, rec.fLastY - y); |
| 224 return; | 224 return; |
| 225 } | 225 } |
| 226 } | 226 } |
| 227 | 227 |
| 228 rec.fPrevX = rec.fLastX; rec.fLastX = x; | 228 rec.fPrevX = rec.fLastX; rec.fLastX = x; |
| 229 rec.fPrevY = rec.fLastY; rec.fLastY = y; | 229 rec.fPrevY = rec.fLastY; rec.fLastY = y; |
| 230 rec.fPrevT = rec.fLastT; rec.fLastT = SkTime::GetMSecs(); | 230 rec.fPrevT = rec.fLastT; |
| 231 rec.fLastT = static_cast<float>(SkTime::GetSecs()); |
| 231 | 232 |
| 232 switch (fTouches.count()) { | 233 switch (fTouches.count()) { |
| 233 case 1: { | 234 case 1: { |
| 234 float dx = rec.fLastX - rec.fStartX; | 235 float dx = rec.fLastX - rec.fStartX; |
| 235 float dy = rec.fLastY - rec.fStartY; | 236 float dy = rec.fLastY - rec.fStartY; |
| 236 dx = (float)sk_float_round2int(dx); | 237 dx = (float)sk_float_round2int(dx); |
| 237 dy = (float)sk_float_round2int(dy); | 238 dy = (float)sk_float_round2int(dy); |
| 238 fLocalM.setTranslate(dx, dy); | 239 fLocalM.setTranslate(dx, dy); |
| 239 } break; | 240 } break; |
| 240 case 2: { | 241 case 2: { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 269 if (this->handleDblTap(rec.fLastX, rec.fLastY)) { | 270 if (this->handleDblTap(rec.fLastX, rec.fLastY)) { |
| 270 return; | 271 return; |
| 271 } | 272 } |
| 272 | 273 |
| 273 // count() reflects the number before we removed the owner | 274 // count() reflects the number before we removed the owner |
| 274 switch (fTouches.count()) { | 275 switch (fTouches.count()) { |
| 275 case 1: { | 276 case 1: { |
| 276 this->flushLocalM(); | 277 this->flushLocalM(); |
| 277 float dx = rec.fLastX - rec.fPrevX; | 278 float dx = rec.fLastX - rec.fPrevX; |
| 278 float dy = rec.fLastY - rec.fPrevY; | 279 float dy = rec.fLastY - rec.fPrevY; |
| 279 float dur = (rec.fLastT - rec.fPrevT) * 0.001f; | 280 float dur = rec.fLastT - rec.fPrevT; |
| 280 if (dur > 0) { | 281 if (dur > 0) { |
| 281 fFlinger.reset(dx / dur, dy / dur); | 282 fFlinger.reset(dx / dur, dy / dur); |
| 282 } | 283 } |
| 283 fState = kEmpty_State; | 284 fState = kEmpty_State; |
| 284 } break; | 285 } break; |
| 285 case 2: | 286 case 2: |
| 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; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 303 dx = rec0.fLastX - rec1.fLastX; | 304 dx = rec0.fLastX - rec1.fLastX; |
| 304 dy = rec0.fLastY - rec1.fLastY; | 305 dy = rec0.fLastY - rec1.fLastY; |
| 305 double dist1 = sqrt(dx*dx + dy*dy); | 306 double dist1 = sqrt(dx*dx + dy*dy); |
| 306 | 307 |
| 307 double scale = dist1 / dist0; | 308 double scale = dist1 / dist0; |
| 308 return (float)scale; | 309 return (float)scale; |
| 309 } | 310 } |
| 310 | 311 |
| 311 bool SkTouchGesture::handleDblTap(float x, float y) { | 312 bool SkTouchGesture::handleDblTap(float x, float y) { |
| 312 bool found = false; | 313 bool found = false; |
| 313 SkMSec now = SkTime::GetMSecs(); | 314 double now = SkTime::GetMSecs(); |
| 314 if (now - fLastUpT <= MAX_DBL_TAP_INTERVAL) { | 315 if (now - fLastUpMillis <= MAX_DBL_TAP_INTERVAL) { |
| 315 if (SkPoint::Length(fLastUpP.fX - x, | 316 if (SkPoint::Length(fLastUpP.fX - x, |
| 316 fLastUpP.fY - y) <= MAX_DBL_TAP_DISTANCE) { | 317 fLastUpP.fY - y) <= MAX_DBL_TAP_DISTANCE) { |
| 317 fFlinger.stop(); | 318 fFlinger.stop(); |
| 318 fLocalM.reset(); | 319 fLocalM.reset(); |
| 319 fGlobalM.reset(); | 320 fGlobalM.reset(); |
| 320 fTouches.reset(); | 321 fTouches.reset(); |
| 321 fState = kEmpty_State; | 322 fState = kEmpty_State; |
| 322 found = true; | 323 found = true; |
| 323 } | 324 } |
| 324 } | 325 } |
| 325 | 326 |
| 326 fLastUpT = now; | 327 fLastUpMillis = now; |
| 327 fLastUpP.set(x, y); | 328 fLastUpP.set(x, y); |
| 328 return found; | 329 return found; |
| 329 } | 330 } |
| OLD | NEW |