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 | */ |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 8 | #ifndef TouchGesture_DEFINED |
| 9 | #define TouchGesture_DEFINED |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 10 | |
bungeman | a7e9f05 | 2016-02-18 08:53:33 -0800 | [diff] [blame] | 11 | #include "../private/SkTDArray.h" |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 12 | #include "SkMatrix.h" |
| 13 | |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 14 | class TouchGesture { |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 15 | public: |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 16 | TouchGesture(); |
| 17 | ~TouchGesture(); |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 18 | |
| 19 | void touchBegin(void* owner, float x, float y); |
| 20 | void touchMoved(void* owner, float x, float y); |
| 21 | void touchEnd(void* owner); |
| 22 | void reset(); |
Brian Salomon | 88d99df | 2018-01-05 11:58:16 -0500 | [diff] [blame] | 23 | void resetTouchState(); |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 24 | |
| 25 | bool isActive() { return fFlinger.isActive(); } |
| 26 | void stop() { fFlinger.stop(); } |
Brian Osman | b53f48c | 2017-06-07 10:00:30 -0400 | [diff] [blame] | 27 | bool isBeingTouched() { return kEmpty_State != fState; } |
Jim Van Verth | 234e5a2 | 2018-07-23 13:46:01 -0400 | [diff] [blame] | 28 | bool isFling(SkPoint* dir); |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 29 | |
| 30 | const SkMatrix& localM(); |
| 31 | const SkMatrix& globalM() const { return fGlobalM; } |
| 32 | |
Brian Osman | 42bb6ac | 2017-06-05 08:46:04 -0400 | [diff] [blame] | 33 | void setTransLimit(const SkRect& contentRect, const SkRect& windowRect, |
| 34 | const SkMatrix& preTouchM); |
liyuqian | e46e4f0 | 2016-05-20 07:32:19 -0700 | [diff] [blame] | 35 | |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 36 | private: |
| 37 | enum State { |
| 38 | kEmpty_State, |
| 39 | kTranslate_State, |
| 40 | kZoom_State, |
| 41 | }; |
| 42 | |
| 43 | struct Rec { |
| 44 | void* fOwner; |
| 45 | float fStartX, fStartY; |
| 46 | float fPrevX, fPrevY; |
| 47 | float fLastX, fLastY; |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 48 | float fPrevT, fLastT; |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 49 | }; |
| 50 | SkTDArray<Rec> fTouches; |
| 51 | |
| 52 | State fState; |
Brian Osman | 42bb6ac | 2017-06-05 08:46:04 -0400 | [diff] [blame] | 53 | SkMatrix fLocalM, fGlobalM, fPreTouchM; |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 54 | |
| 55 | struct FlingState { |
| 56 | FlingState() : fActive(false) {} |
| 57 | |
| 58 | bool isActive() const { return fActive; } |
| 59 | void stop() { fActive = false; } |
| 60 | |
| 61 | void reset(float sx, float sy); |
| 62 | bool evaluateMatrix(SkMatrix* matrix); |
| 63 | |
| 64 | void get(SkPoint* dir, SkScalar* speed) { |
| 65 | *dir = fDirection; |
| 66 | *speed = fSpeed0; |
| 67 | } |
| 68 | |
| 69 | private: |
| 70 | SkPoint fDirection; |
| 71 | SkScalar fSpeed0; |
| 72 | double fTime0; |
| 73 | bool fActive; |
| 74 | }; |
| 75 | FlingState fFlinger; |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 76 | double fLastUpMillis; |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 77 | SkPoint fLastUpP; |
| 78 | |
liyuqian | e46e4f0 | 2016-05-20 07:32:19 -0700 | [diff] [blame] | 79 | // The following rects are used to limit the translation so the content never leaves the window |
| 80 | SkRect fContentRect, fWindowRect; |
| 81 | bool fIsTransLimited = false; |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 82 | |
liyuqian | e46e4f0 | 2016-05-20 07:32:19 -0700 | [diff] [blame] | 83 | void limitTrans(); // here we only limit the translation with respect to globalM |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 84 | void flushLocalM(); |
| 85 | int findRec(void* owner) const; |
| 86 | void appendNewRec(void* owner, float x, float y); |
| 87 | float computePinch(const Rec&, const Rec&); |
| 88 | float limitTotalZoom(float scale) const; |
| 89 | bool handleDblTap(float, float); |
| 90 | }; |
| 91 | |
| 92 | #endif |