• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef SkTouchGesture_DEFINED
2 #define SkTouchGesture_DEFINED
3 
4 #include "SkTDArray.h"
5 #include "SkMatrix.h"
6 
7 struct SkFlingState {
SkFlingStateSkFlingState8     SkFlingState() : fActive(false) {}
9 
isActiveSkFlingState10     bool isActive() const { return fActive; }
stopSkFlingState11     void stop() { fActive = false; }
12 
13     void reset(float sx, float sy);
14     bool evaluateMatrix(SkMatrix* matrix);
15 
16 private:
17     SkPoint     fDirection;
18     SkScalar    fSpeed0;
19     double      fTime0;
20     bool        fActive;
21 };
22 
23 class SkTouchGesture {
24 public:
25     SkTouchGesture();
26     ~SkTouchGesture();
27 
28     void touchBegin(void* owner, float x, float y);
29     void touchMoved(void* owner, float x, float y);
30     void touchEnd(void* owner);
31     void reset();
32 
isActive()33     bool isActive() { return fFlinger.isActive(); }
stop()34     void stop() { fFlinger.stop(); }
35 
36     const SkMatrix& localM();
globalM()37     const SkMatrix& globalM() const { return fGlobalM; }
38 
39 private:
40     enum State {
41         kEmpty_State,
42         kTranslate_State,
43         kZoom_State,
44     };
45 
46     struct Rec {
47         void*   fOwner;
48         float   fStartX, fStartY;
49         float   fPrevX, fPrevY;
50         float   fLastX, fLastY;
51         SkMSec  fPrevT, fLastT;
52     };
53     SkTDArray<Rec> fTouches;
54 
55     State           fState;
56     SkMatrix        fLocalM, fGlobalM;
57     SkFlingState    fFlinger;
58     SkMSec          fLastUpT;
59     SkPoint         fLastUpP;
60 
61 
62     void flushLocalM();
63     int findRec(void* owner) const;
64     void appendNewRec(void* owner, float x, float y);
65     float computePinch(const Rec&, const Rec&);
66     float limitTotalZoom(float scale) const;
67     bool handleDblTap(float, float);
68 };
69 
70 #endif
71 
72 
73