epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 8 | #ifndef SkTouchGesture_DEFINED |
| 9 | #define SkTouchGesture_DEFINED |
| 10 | |
| 11 | #include "SkTDArray.h" |
| 12 | #include "SkMatrix.h" |
| 13 | |
| 14 | struct SkFlingState { |
| 15 | SkFlingState() : fActive(false) {} |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 16 | |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 17 | bool isActive() const { return fActive; } |
| 18 | void stop() { fActive = false; } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 19 | |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 20 | void reset(float sx, float sy); |
| 21 | bool evaluateMatrix(SkMatrix* matrix); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 22 | |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 23 | private: |
| 24 | SkPoint fDirection; |
| 25 | SkScalar fSpeed0; |
| 26 | double fTime0; |
| 27 | bool fActive; |
| 28 | }; |
| 29 | |
| 30 | class SkTouchGesture { |
| 31 | public: |
| 32 | SkTouchGesture(); |
| 33 | ~SkTouchGesture(); |
| 34 | |
| 35 | void touchBegin(void* owner, float x, float y); |
| 36 | void touchMoved(void* owner, float x, float y); |
| 37 | void touchEnd(void* owner); |
| 38 | void reset(); |
| 39 | |
| 40 | bool isActive() { return fFlinger.isActive(); } |
| 41 | void stop() { fFlinger.stop(); } |
| 42 | |
| 43 | const SkMatrix& localM(); |
| 44 | const SkMatrix& globalM() const { return fGlobalM; } |
| 45 | |
| 46 | private: |
| 47 | enum State { |
| 48 | kEmpty_State, |
| 49 | kTranslate_State, |
| 50 | kZoom_State, |
| 51 | }; |
| 52 | |
| 53 | struct Rec { |
| 54 | void* fOwner; |
| 55 | float fStartX, fStartY; |
| 56 | float fPrevX, fPrevY; |
| 57 | float fLastX, fLastY; |
| 58 | SkMSec fPrevT, fLastT; |
| 59 | }; |
| 60 | SkTDArray<Rec> fTouches; |
| 61 | |
| 62 | State fState; |
| 63 | SkMatrix fLocalM, fGlobalM; |
| 64 | SkFlingState fFlinger; |
| 65 | SkMSec fLastUpT; |
| 66 | SkPoint fLastUpP; |
| 67 | |
| 68 | |
| 69 | void flushLocalM(); |
| 70 | int findRec(void* owner) const; |
| 71 | void appendNewRec(void* owner, float x, float y); |
| 72 | float computePinch(const Rec&, const Rec&); |
| 73 | float limitTotalZoom(float scale) const; |
| 74 | bool handleDblTap(float, float); |
| 75 | }; |
| 76 | |
| 77 | #endif |