Moved Gesture::State and -::Type to gesture-enumerations.h.
[platform/core/uifw/dali-core.git] / dali / internal / event / events / pan-gesture / pan-gesture-recognizer.h
1 #ifndef DALI_INTERNAL_EVENT_PAN_GESTURE_RECOGNIZER_H
2 #define DALI_INTERNAL_EVENT_PAN_GESTURE_RECOGNIZER_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <cstdint> // uint32_t
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <dali/public-api/math/vector2.h>
25
26 // INTERNAL INCLUDES
27 #include <dali/internal/event/events/gesture-recognizer.h>
28 #include <dali/internal/event/events/pan-gesture/pan-gesture-event.h>
29
30 namespace Dali
31 {
32
33 namespace Integration
34 {
35 class Core;
36 struct TouchEvent;
37
38 }
39
40 namespace Internal
41 {
42
43 struct PanGestureRequest;
44 /**
45  * When given a set of touch events, this detector attempts to determine if a pan gesture has taken place.
46  */
47 class PanGestureRecognizer : public GestureRecognizer
48 {
49 public:
50
51   using Observer = RecognizerObserver<PanGestureEvent>;
52
53   /**
54    * Constructor
55    * @param[in]  screenSize  The size of the screen.
56    * @param[in]  request     The details of the request.
57    */
58   PanGestureRecognizer( Observer& observer, Vector2 screenSize, const PanGestureRequest& request, int32_t minimumDistance, int32_t minimumPanEvents);
59
60   /**
61    * Virtual destructor.
62    */
63   virtual ~PanGestureRecognizer();
64
65 public:
66
67   /**
68    * @copydoc Dali::Internal::GestureDetector::SendEvent(const Integration::TouchEvent&)
69    */
70   virtual void SendEvent(const Integration::TouchEvent& event);
71
72   /**
73    * @copydoc Dali::Internal::GestureDetector::Update(const Integration::GestureRequest&)
74    */
75   virtual void Update(const GestureRequest& request);
76
77 private:
78
79   /**
80    * Emits the pan gesture event (performs some smoothing operation).
81    * @param[in]  state         The state of the pan.
82    * @param[in]  currentEvent  The latest touch event.
83    */
84   void SendPan(GestureState state, const Integration::TouchEvent& currentEvent);
85
86 private:
87
88   // Reference to the gesture processor for this recognizer
89   Observer& mObserver;
90
91   /**
92    * Internal state machine.
93    */
94   enum State
95   {
96     CLEAR,    ///< No gesture detected.
97     POSSIBLE, ///< The current touch event data suggests that a gesture is possible.
98     STARTED,  ///< A gesture has been detected.
99     FINISHED, ///< A previously started pan gesture has finished.
100     FAILED,   ///< Current touch event data suggests a pan gesture is not possible.
101   };
102
103   State mState; ///< The current state of the detector.
104   std::vector<Integration::TouchEvent> mTouchEvents;     ///< A container of all touch events after an initial down event.
105
106   Vector2 mPrimaryTouchDownLocation;    ///< The initial touch down point.
107   Vector2 mThresholdAdjustmentPerFrame; ///< The adjustment per frame at the start of a slow pan.
108   Vector2 mPreviousPosition;            ///< The previous position.
109
110   unsigned int mThresholdAdjustmentsRemaining; ///< No. of threshold adjustments still to apply (for a slow-pan).
111   unsigned int mThresholdTotalAdjustments;     ///< The total number of adjustments required.
112
113   uint32_t mPrimaryTouchDownTime;       ///< The initial touch down time.
114   unsigned int mMinimumTouchesRequired; ///< The minimum touches required before a pan should be emitted.
115   unsigned int mMaximumTouchesRequired; ///< The maximum touches after which a pan should not be emitted.
116
117   unsigned int mMinimumDistanceSquared; ///< The minimum distance squared before pan should start.
118   unsigned int mMinimumMotionEvents;    ///< The minimum motion events before pan should start.
119   unsigned int mMotionEvents;           ///< The motion events received so far (before pan is emitted).
120 };
121
122 } // namespace Internal
123
124 } // namespace Dali
125
126 #endif // DALI_INTERNAL_EVENT_PAN_GESTURE_RECOGNIZER_H