|
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 */ |
|
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) {} |
|
16 |
|
17 bool isActive() const { return fActive; } |
|
18 void stop() { fActive = false; } |
|
19 |
|
20 void reset(float sx, float sy); |
|
21 bool evaluateMatrix(SkMatrix* matrix); |
|
22 |
|
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 |