Fix conversion warnings for event refactor
[platform/core/uifw/dali-adaptor.git] / dali / internal / input / common / pan-gesture-detector-base.h
1 #ifndef DALI_INTERNAL_PAN_GESTURE_DETECTOR_BASE_H
2 #define DALI_INTERNAL_PAN_GESTURE_DETECTOR_BASE_H
3
4 /*
5  * Copyright (c) 2019 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 #include <dali/integration-api/events/pan-gesture-event.h>
26
27 // INTERNAL INCLUDES
28 #include <dali/internal/input/common/gesture-detector.h>
29
30 namespace Dali
31 {
32
33 namespace Integration
34 {
35 class Core;
36 struct TouchEvent;
37 struct PanGestureRequest;
38 }
39
40 namespace Internal
41 {
42
43 namespace Adaptor
44 {
45
46 class EnvironmentOptions;
47
48 /**
49  * When given a set of touch events, this detector attempts to determine if a pan gesture has taken place.
50  */
51 class PanGestureDetectorBase : public GestureDetector
52 {
53 public:
54
55   /**
56    * Virtual destructor.
57    */
58   virtual ~PanGestureDetectorBase();
59
60 public:
61
62   /**
63    * @copydoc Dali::Internal::GestureDetector::SendEvent(const Integration::TouchEvent&)
64    */
65   virtual void SendEvent(const Integration::TouchEvent& event);
66
67   /**
68    * @copydoc Dali::Internal::GestureDetector::Update(const Integration::GestureRequest&)
69    */
70   virtual void Update(const Integration::GestureRequest& request);
71
72 protected:
73
74   /**
75    * Constructor
76    * @param[in]  screenSize  The size of the screen.
77    * @param[in]  request     The details of the request.
78    */
79   PanGestureDetectorBase(Vector2 screenSize, const Integration::PanGestureRequest& request, EnvironmentOptions* environmentOptions);
80
81 private:
82
83   /**
84    * Emits the pan gesture event (performs some smoothing operation).
85    * @param[in]  state         The state of the pan.
86    * @param[in]  currentEvent  The latest touch event.
87    */
88   void SendPan(Gesture::State state, const Integration::TouchEvent& currentEvent);
89
90   /**
91    * Emits the pan gesture event to the core.
92    * @param[in] gesture The pan gesture event.
93    */
94   virtual void EmitPan(const Integration::PanGestureEvent gesture) = 0;
95
96 private:
97
98   /**
99    * Internal state machine.
100    */
101   enum State
102   {
103     Clear,    ///< No gesture detected.
104     Possible, ///< The current touch event data suggests that a gesture is possible.
105     Started,  ///< A gesture has been detected.
106     Finished, ///< A previously started pan gesture has finished.
107     Failed,   ///< Current touch event data suggests a pan gesture is not possible.
108   };
109
110   State mState; ///< The current state of the detector.
111   std::vector<Integration::TouchEvent> mTouchEvents;     ///< A container of all touch events after an initial down event.
112
113   Vector2 mPrimaryTouchDownLocation;    ///< The initial touch down point.
114   Vector2 mThresholdAdjustmentPerFrame; ///< The adjustment per frame at the start of a slow pan.
115   Vector2 mPreviousPosition;            ///< The previous position.
116
117   unsigned int mThresholdAdjustmentsRemaining; ///< No. of threshold adjustments still to apply (for a slow-pan).
118   unsigned int mThresholdTotalAdjustments;     ///< The total number of adjustments required.
119
120   uint32_t mPrimaryTouchDownTime;       ///< The initial touch down time.
121   unsigned int mMinimumTouchesRequired; ///< The minimum touches required before a pan should be emitted.
122   unsigned int mMaximumTouchesRequired; ///< The maximum touches after which a pan should not be emitted.
123
124   unsigned int mMinimumDistanceSquared; ///< The minimum distance squared before pan should start.
125   unsigned int mMinimumMotionEvents;    ///< The minimum motion events before pan should start.
126   unsigned int mMotionEvents;           ///< The motion events received so far (before pan is emitted).
127 };
128
129 } // namespace Adaptor
130
131 } // namespace Internal
132
133 } // namespace Dali
134
135 #endif // DALI_INTERNAL_PAN_GESTURE_DETECTOR_BASE_H