Add an environment variable for long press gesture
[platform/core/uifw/dali-core.git] / dali / internal / event / events / gesture-event-processor.h
1 #ifndef DALI_INTERNAL_GESTURE_EVENT_PROCESSOR_H
2 #define DALI_INTERNAL_GESTURE_EVENT_PROCESSOR_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 // INTERNAL INCLUDES
22 #include <dali/public-api/actors/actor.h>
23 #include <dali/internal/event/events/gesture-detector-impl.h>
24 #include <dali/internal/event/events/long-press-gesture/long-press-gesture-processor.h>
25 #include <dali/internal/event/events/pan-gesture/pan-gesture-processor.h>
26 #include <dali/internal/event/events/pinch-gesture/pinch-gesture-processor.h>
27 #include <dali/internal/event/events/rotation-gesture/rotation-gesture-processor.h>
28 #include <dali/internal/event/events/tap-gesture/tap-gesture-processor.h>
29
30 namespace Dali
31 {
32
33 struct Gesture;
34
35 namespace Integration
36 {
37
38 class RenderController;
39 }
40
41 namespace SceneGraph
42 {
43 class UpdateManager;
44 }
45
46 namespace Internal
47 {
48
49 class Stage;
50 class Scene;
51
52 /**
53  * Gesture Event Processing:
54  *
55  * The GestureEventProcessor determines what type of gesture event we have received and sends it to
56  * the appropriate gesture processor for processing.
57  */
58 class GestureEventProcessor
59 {
60 public:
61
62   /**
63    * Create a gesture event processor.
64    * @param[in] updateManager The update manager
65    * @param[in] renderController The render controller
66    */
67   GestureEventProcessor( SceneGraph::UpdateManager& updateManager, Integration::RenderController& renderController );
68
69   /**
70    * Non-virtual destructor; GestureProcessor is not a base class
71    */
72   ~GestureEventProcessor();
73
74 public: // To be called by EventProcessor
75
76   /**
77    * This function is called by Core whenever a touch event occurs
78    * @param[in] scene The scene
79    * @param[in] event The event that has occurred
80    */
81   void ProcessTouchEvent( Scene& scene, const Integration::TouchEvent& event);
82
83 public: // To be called by gesture detectors
84
85   /**
86    * This method adds the specified gesture detector to the relevant gesture processor.
87    * @param[in]  gestureDetector  The gesture detector to add
88    */
89   void AddGestureDetector(GestureDetector* gestureDetector, Scene& scene);
90
91   /**
92    * This method removes the specified gesture detector from the relevant gesture processor.
93    * @param[in]  gestureDetector  The gesture detector to remove.
94    */
95   void RemoveGestureDetector(GestureDetector* gestureDetector);
96
97   /**
98    * This method informs the appropriate processor that the gesture detector has been updated.
99    * @param[in]  gestureDetector  The gesture detector that has been updated.
100    */
101   void GestureDetectorUpdated(GestureDetector* gestureDetector);
102
103   /**
104    * Called by GestureDetectors to set the gesture properties in the update thread.
105    * @param[in]  gesture  The gesture whose values will be used in the Update object.
106    * @note If we are in the middle of processing the gesture being set, then this call is ignored.
107    */
108   void SetGestureProperties( const Gesture& gesture );
109
110 public: // Called by Core
111
112   /**
113    * Returns true if any GestureDetector requires a Core::Update. Clears
114    * the state flag after reading.
115    *
116    * @return true if any GestureDetector requires a Core::Update
117    */
118   bool NeedsUpdate();
119
120   /**
121    * Called to provide pan-gesture profiling information.
122    */
123   void EnablePanGestureProfiling();
124
125   /**
126    * @brief Called to set how pan gestures predict input
127    *
128    * @param[in] mode The prediction mode to use
129    */
130   void SetPanGesturePredictionMode( int32_t mode );
131
132   /**
133    * @brief Sets the prediction amount of the pan gesture
134    *
135    * @param[in] amount The prediction amount in milliseconds
136    */
137   void SetPanGesturePredictionAmount( uint32_t amount );
138
139   /**
140    * @brief Sets the upper bound of the prediction amount for clamping
141    *
142    * @param[in] amount The prediction amount in milliseconds
143    */
144   void SetPanGestureMaximumPredictionAmount( uint32_t amount );
145
146   /**
147    * @brief Sets the lower bound of the prediction amount for clamping
148    *
149    * @param[in] amount The prediction amount in milliseconds
150    */
151   void SetPanGestureMinimumPredictionAmount( uint32_t amount );
152
153   /**
154    * @brief Sets the prediction amount to adjust when the pan velocity is changed.
155    * If the pan velocity is accelerating, the prediction amount will be increased
156    * by the specified amount until it reaches the upper bound. If the pan velocity
157    * is decelerating, the prediction amount will be decreased by the specified amount
158    * until it reaches the lower bound.
159    *
160    * @param[in] amount The prediction amount in milliseconds
161    */
162   void SetPanGesturePredictionAmountAdjustment( uint32_t amount );
163
164   /**
165    * @brief Called to set how pan gestures smooth input
166    *
167    * @param[in] mode The smoothing mode to use
168    */
169   void SetPanGestureSmoothingMode( int32_t mode );
170
171   /**
172    * @brief Sets the prediction amount of the pan gesture
173    *
174    * @param[in] amount The smoothing amount [0.0f,1.0f] - 0.0f would be no smoothing, 1.0f maximum smoothing
175    */
176   void SetPanGestureSmoothingAmount( float amount );
177
178   /*
179    * @brief Sets whether to use actual times of the real gesture and frames or not.
180    *
181    * @param[in] value True = use actual times, False = use perfect values
182    */
183   void SetPanGestureUseActualTimes( bool value );
184
185   /**
186    * @brief Sets the interpolation time range (ms) of past points to use (with weights) when interpolating.
187    *
188    * @param[in] value Time range in ms
189    */
190   void SetPanGestureInterpolationTimeRange( int32_t value );
191
192   /**
193    * @brief Sets whether to use scalar only prediction, which when enabled, ignores acceleration.
194    *
195    * @param[in] value True = use scalar prediction only
196    */
197   void SetPanGestureScalarOnlyPredictionEnabled( bool value );
198
199   /**
200    * @brief Sets whether to use two point prediction. This combines two interpolated points to get more steady acceleration and velocity values.
201    *
202    * @param[in] value True = use two point prediction
203    */
204   void SetPanGestureTwoPointPredictionEnabled( bool value );
205
206   /**
207    * @brief Sets the time in the past to interpolate the second point when using two point interpolation.
208    *
209    * @param[in] value Time in past in ms
210    */
211   void SetPanGestureTwoPointInterpolatePastTime( int32_t value );
212
213   /**
214    * @brief Sets the two point velocity bias. This is the ratio of first and second points to use for velocity.
215    *
216    * @param[in] value 0.0f = 100% first point. 1.0f = 100% of second point.
217    */
218   void SetPanGestureTwoPointVelocityBias( float value );
219
220   /**
221    * @brief Sets the two point acceleration bias. This is the ratio of first and second points to use for acceleration.
222    *
223    * @param[in] value 0.0f = 100% first point. 1.0f = 100% of second point.
224    */
225   void SetPanGestureTwoPointAccelerationBias( float value );
226
227   /**
228    * @brief Sets the range of time (ms) of points in the history to perform multitap smoothing with (if enabled).
229    *
230    * @param[in] value Time in past in ms
231    */
232   void SetPanGestureMultitapSmoothingRange( int32_t value );
233
234   /**
235    * @brief Sets the minimum distance required to start a pan event
236    *
237    * @param[in] value Distance in pixels
238    */
239   void SetPanGestureMinimumDistance( int32_t value );
240
241   /**
242    * @brief Sets the minimum number of touch events required to start a pan
243    *
244    * @param[in] value Number of touch events
245    */
246   void SetPanGestureMinimumPanEvents( int32_t value );
247
248   /**
249    * @brief Sets the minimum distance required to start a pinch event
250    *
251    * @param[in] value Distance in pixels
252    */
253   void SetPinchGestureMinimumDistance( float value);
254
255   /**
256    * @brief Sets the minimum holding time required to be recognized as a long press gesture
257    *
258    * @param[in] value The time value in milliseconds
259    */
260   void SetLongPressMinimumHoldingTime( uint32_t value );
261
262   /**
263    * @return The minimum holding time required to be recognized as a long press gesture in milliseconds
264    */
265   uint32_t GetLongPressMinimumHoldingTime() const;
266
267 public: // needed for PanGesture
268
269   /**
270    * @return the pan gesture processor
271    */
272   const PanGestureProcessor& GetPanGestureProcessor();
273
274 private:
275
276   // Undefined
277   GestureEventProcessor(const GestureEventProcessor&);
278   GestureEventProcessor& operator=(const GestureEventProcessor& rhs);
279
280 private:
281
282   LongPressGestureProcessor mLongPressGestureProcessor;
283   PanGestureProcessor mPanGestureProcessor;
284   PinchGestureProcessor mPinchGestureProcessor;
285   TapGestureProcessor mTapGestureProcessor;
286   RotationGestureProcessor mRotationGestureProcessor;
287   Integration::RenderController& mRenderController;
288
289   int32_t envOptionMinimumPanDistance;
290   int32_t envOptionMinimumPanEvents;
291 };
292
293 } // namespace Internal
294
295 } // namespace Dali
296
297 #endif // DALI_INTERNAL_GESTURE_EVENT_PROCESSOR_H