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 | |
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 | |
| 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(); |
Brian Salomon | 88d99df | 2018-01-05 11:58:16 -0500 | [diff] [blame] | 39 | void resetTouchState(); |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 40 | |
| 41 | bool isActive() { return fFlinger.isActive(); } |
| 42 | void stop() { fFlinger.stop(); } |
Brian Osman | b53f48c | 2017-06-07 10:00:30 -0400 | [diff] [blame] | 43 | bool isBeingTouched() { return kEmpty_State != fState; } |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 44 | |
| 45 | const SkMatrix& localM(); |
| 46 | const SkMatrix& globalM() const { return fGlobalM; } |
| 47 | |
Brian Osman | 42bb6ac | 2017-06-05 08:46:04 -0400 | [diff] [blame] | 48 | void setTransLimit(const SkRect& contentRect, const SkRect& windowRect, |
| 49 | const SkMatrix& preTouchM); |
liyuqian | e46e4f0 | 2016-05-20 07:32:19 -0700 | [diff] [blame] | 50 | |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 51 | private: |
| 52 | enum State { |
| 53 | kEmpty_State, |
| 54 | kTranslate_State, |
| 55 | kZoom_State, |
| 56 | }; |
| 57 | |
| 58 | struct Rec { |
| 59 | void* fOwner; |
| 60 | float fStartX, fStartY; |
| 61 | float fPrevX, fPrevY; |
| 62 | float fLastX, fLastY; |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 63 | float fPrevT, fLastT; |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 64 | }; |
| 65 | SkTDArray<Rec> fTouches; |
| 66 | |
| 67 | State fState; |
Brian Osman | 42bb6ac | 2017-06-05 08:46:04 -0400 | [diff] [blame] | 68 | SkMatrix fLocalM, fGlobalM, fPreTouchM; |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 69 | SkFlingState fFlinger; |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 70 | double fLastUpMillis; |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 71 | SkPoint fLastUpP; |
| 72 | |
liyuqian | e46e4f0 | 2016-05-20 07:32:19 -0700 | [diff] [blame] | 73 | // The following rects are used to limit the translation so the content never leaves the window |
| 74 | SkRect fContentRect, fWindowRect; |
| 75 | bool fIsTransLimited = false; |
reed@google.com | 52f57e1 | 2011-03-16 12:10:02 +0000 | [diff] [blame] | 76 | |
liyuqian | e46e4f0 | 2016-05-20 07:32:19 -0700 | [diff] [blame] | 77 | 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] | 78 | void flushLocalM(); |
| 79 | int findRec(void* owner) const; |
| 80 | void appendNewRec(void* owner, float x, float y); |
| 81 | float computePinch(const Rec&, const Rec&); |
| 82 | float limitTotalZoom(float scale) const; |
| 83 | bool handleDblTap(float, float); |
| 84 | }; |
| 85 | |
| 86 | #endif |