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