reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | #ifndef GrTouchGesture_DEFINED |
| 2 | #define GrTouchGesture_DEFINED |
| 3 | |
| 4 | #include "GrTypes.h" |
| 5 | #include "SkTDArray.h" |
| 6 | #include "SkMatrix.h" |
| 7 | |
| 8 | #include "FlingState.h" |
| 9 | |
| 10 | class GrTouchGesture { |
| 11 | public: |
| 12 | GrTouchGesture(); |
| 13 | ~GrTouchGesture(); |
| 14 | |
| 15 | void touchBegin(void* owner, float x, float y); |
| 16 | void touchMoved(void* owner, float x, float y); |
| 17 | void touchEnd(void* owner); |
| 18 | void reset(); |
| 19 | |
| 20 | const SkMatrix& localM(); |
| 21 | const SkMatrix& globalM() const { return fGlobalM; } |
| 22 | |
| 23 | private: |
| 24 | enum State { |
| 25 | kEmpty_State, |
| 26 | kTranslate_State, |
| 27 | kZoom_State, |
| 28 | }; |
| 29 | |
| 30 | struct Rec { |
| 31 | void* fOwner; |
| 32 | float fStartX, fStartY; |
| 33 | float fPrevX, fPrevY; |
| 34 | float fLastX, fLastY; |
| 35 | SkMSec fPrevT, fLastT; |
| 36 | }; |
| 37 | SkTDArray<Rec> fTouches; |
| 38 | |
| 39 | State fState; |
| 40 | SkMatrix fLocalM, fGlobalM; |
| 41 | FlingState fFlinger; |
| 42 | SkMSec fLastUpT; |
| 43 | SkPoint fLastUpP; |
| 44 | |
| 45 | |
| 46 | void flushLocalM(); |
| 47 | int findRec(void* owner) const; |
| 48 | void appendNewRec(void* owner, float x, float y); |
| 49 | float computePinch(const Rec&, const Rec&); |
| 50 | float limitTotalZoom(float scale) const; |
| 51 | bool handleDblTap(float, float); |
| 52 | }; |
| 53 | |
| 54 | #endif |
| 55 | |
| 56 | |