[dali_2.3.6] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / event / events / pan-gesture / pan-gesture-processor.h
1 #ifndef DALI_INTERNAL_EVENT_PAN_GESTURE_EVENT_PROCESSOR_H
2 #define DALI_INTERNAL_EVENT_PAN_GESTURE_EVENT_PROCESSOR_H
3
4 /*
5  * Copyright (c) 2022 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-processor.h>
23 #include <dali/internal/event/events/pan-gesture/pan-gesture-detector-impl.h>
24 #include <dali/internal/event/render-tasks/render-task-impl.h>
25
26 namespace Dali
27 {
28 namespace Internal
29 {
30 class Stage;
31 class Scene;
32 struct GestureEvent;
33 struct PanGestureEvent;
34
35 namespace SceneGraph
36 {
37 class PanGesture;
38 class UpdateManager;
39 } // namespace SceneGraph
40
41 /**
42  * Pan Gesture Event Processing:
43  *
44  * When we receive a pan gesture event, we do the following:
45  * - Find the actor that requires a pan where the pan started from (i.e. the down position).
46  * - Emit the gesture if the event satisfies the detector conditions.
47  *
48  * The above is only checked when our gesture starts.  We continue sending the pan gesture to the
49  * same actor and detector until the pan ends or is cancelled.
50  */
51 class PanGestureProcessor : public GestureProcessor, public RecognizerObserver<PanGestureEvent>
52 {
53 public:
54   /**
55    * Create a pan gesture processor.
56    * @param[in] updateManager The Update Manager
57    */
58   PanGestureProcessor(SceneGraph::UpdateManager& updateManager);
59
60   /**
61    * Destructor
62    */
63   ~PanGestureProcessor() override;
64
65 public: // To be called by GestureEventProcessor
66   /**
67    * This method is called whenever a pan gesture event occurs.
68    * @param[in] scene The scene the pan gesture event occurs in.
69    * @param[in] panEvent The event that has occurred.
70    * @param[in] actor The actor where the event occurred. If this is null, the actor is found through hittest.
71    */
72   void Process(Scene& scene, const PanGestureEvent& panEvent, Actor* actor = nullptr) override;
73
74   /**
75    * Adds a gesture detector to this gesture processor.
76    * If this is the first gesture detector being added, then this method registers the required
77    * gesture with the adaptor.
78    * @param[in] gestureDetector The gesture detector being added.
79    * @param[in] scene           The scene the pan gesture event occurs in.
80    * @param[in] minDistance     The minimum required motion distance to start pan gesture. If this value is less than 0, we use default setuped distance.
81    * @param[in] minPanEvents    The minimum required motion event number to start pan gesture. If this value is less than 1, we use default setuped number.
82    */
83   void AddGestureDetector(PanGestureDetector* gestureDetector, Scene& scene, int32_t minDistance, int32_t minPanEvents);
84
85   /**
86    * Removes the specified gesture detector from this gesture processor.  If, after removing this
87    * gesture detector, there are no more gesture detectors registered, then this method unregisters
88    * the gesture from the adaptor.
89    * @param[in]  gestureDetector  The gesture detector being removed.
90    */
91   void RemoveGestureDetector(PanGestureDetector* gestureDetector);
92
93   /**
94    * This method updates the gesture detection parameters.
95    * @param[in]  gestureDetector  The gesture detector that has been updated.
96    */
97   void GestureDetectorUpdated(PanGestureDetector* gestureDetector);
98
99   /**
100    * Sets the pan gesture properties stored in the scene object directly,
101    * @param[in]  pan  The pan gesture to override the properties with.
102    * @return true if Core::Update required
103    * @note If we are already processing a normal pan, then this call is ignored.
104    */
105   bool SetPanGestureProperties(const Dali::PanGesture& pan);
106
107   /**
108    * Called to provide pan-gesture profiling information.
109    */
110   void EnableProfiling();
111
112   /**
113    * Called to set the prediction mode for pan gestures
114    *
115    * @param[in] mode The prediction mode
116    *
117    * Valid modes:
118    * 0 - No prediction
119    * 1 - Prediction using average acceleration
120    */
121   void SetPredictionMode(int mode);
122
123   /**
124    * @brief Sets the prediction amount of the pan gesture
125    *
126    * @param[in] amount The prediction amount in milliseconds
127    */
128   void SetPredictionAmount(unsigned int amount);
129
130   /**
131    * @brief Sets the upper bound of the prediction amount for clamping
132    *
133    * @param[in] amount The prediction amount in milliseconds
134    */
135   void SetMaximumPredictionAmount(unsigned int amount);
136
137   /**
138    * @brief Sets the lower bound of the prediction amount for clamping
139    *
140    * @param[in] amount The prediction amount in milliseconds
141    */
142   void SetMinimumPredictionAmount(unsigned int amount);
143
144   /**
145    * @brief Sets the amount of prediction interpolation to adjust when the pan velocity is changed
146    *
147    * @param[in] amount The prediction amount in milliseconds
148    */
149   void SetPredictionAmountAdjustment(unsigned int amount);
150
151   /**
152    * Called to set the prediction mode for pan gestures
153    *
154    * @param[in] mode The prediction mode
155    *
156    * Valid modes:
157    * 0 - No smoothing
158    * 1 - average between last 2 values
159    */
160   void SetSmoothingMode(int mode);
161
162   /**
163    * @brief Sets the smoothing amount of the pan gesture
164    *
165    * @param[in] amount The smotthing amount from 0.0f (none) to 1.0f (full)
166    */
167   void SetSmoothingAmount(float amount);
168
169   /*
170    * @brief Sets whether to use actual times of the real gesture and frames or not.
171    *
172    * @param[in] value True = use actual times, False = use perfect values
173    */
174   void SetUseActualTimes(bool value);
175
176   /**
177    * @brief Sets the interpolation time range (ms) of past points to use (with weights) when interpolating.
178    *
179    * @param[in] value Time range in ms
180    */
181   void SetInterpolationTimeRange(int value);
182
183   /**
184    * @brief Sets whether to use scalar only prediction, which when enabled, ignores acceleration.
185    *
186    * @param[in] value True = use scalar prediction only
187    */
188   void SetScalarOnlyPredictionEnabled(bool value);
189
190   /**
191    * @brief Sets whether to use two point prediction. This combines two interpolated points to get more steady acceleration and velocity values.
192    *
193    * @param[in] value True = use two point prediction
194    */
195   void SetTwoPointPredictionEnabled(bool value);
196
197   /**
198    * @brief Sets the time in the past to interpolate the second point when using two point interpolation.
199    *
200    * @param[in] value Time in past in ms
201    */
202   void SetTwoPointInterpolatePastTime(int value);
203
204   /**
205    * @brief Sets the two point velocity bias. This is the ratio of first and second points to use for velocity.
206    *
207    * @param[in] value 0.0f = 100% first point. 1.0f = 100% of second point.
208    */
209   void SetTwoPointVelocityBias(float value);
210
211   /**
212    * @brief Sets the two point acceleration bias. This is the ratio of first and second points to use for acceleration.
213    *
214    * @param[in] value 0.0f = 100% first point. 1.0f = 100% of second point.
215    */
216   void SetTwoPointAccelerationBias(float value);
217
218   /**
219    * @brief Sets the range of time (ms) of points in the history to perform multitap smoothing with (if enabled).
220    *
221    * @param[in] value Time in past in ms
222    */
223   void SetMultitapSmoothingRange(int value);
224
225 public: // for PanGestureDetector
226   /**
227    * @return the pan gesture scene object
228    */
229   const SceneGraph::PanGesture& GetSceneObject() const;
230
231 private:
232   // Undefined
233   PanGestureProcessor(const PanGestureProcessor&);
234   PanGestureProcessor& operator=(const PanGestureProcessor& rhs);
235
236   /**
237    * Iterates through our GestureDetectors and determines if we need to ask the adaptor to update
238    * its detection policy.  If it does, it sends the appropriate gesture update request to adaptor.
239    */
240   void UpdateDetection();
241
242   /**
243    * Creates a PanGesture and asks the specified detector to emit its detected signal.
244    * @param[in]  actor             The actor that has been panned.
245    * @param[in]  gestureDetectors  The gesture detector container that should emit the signal.
246    * @param[in]  panEvent          The panEvent received from the adaptor.
247    * @param[in]  localCurrent      Current position relative to the actor attached to the detector.
248    * @param[in]  state             The state of the gesture.
249    * @param[in]  renderTask        The renderTask to use.
250    */
251   void EmitPanSignal(Actor*                          actor,
252                      const GestureDetectorContainer& gestureDetectors,
253                      const PanGestureEvent&          panEvent,
254                      Vector2                         localCurrent,
255                      GestureState                    state,
256                      RenderTaskPtr                   renderTask);
257
258   // GestureProcessor overrides
259
260   /**
261    * @copydoc GestureProcessor::OnGesturedActorStageDisconnection()
262    */
263   void OnGesturedActorStageDisconnection() override;
264
265   /**
266    * @copydoc GestureProcessor::CheckGestureDetector()
267    */
268   bool CheckGestureDetector(GestureDetector* detector, Actor* actor) override;
269
270   /**
271    * @copydoc GestureProcessor::EmitGestureSignal()
272    */
273   void EmitGestureSignal(Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates) override;
274
275 private:
276   PanGestureDetectorContainer mPanGestureDetectors;
277   GestureDetectorContainer    mCurrentPanEmitters;
278   RenderTaskPtr               mCurrentRenderTask;
279   Vector2                     mPossiblePanPosition;
280
281   uint32_t mMinTouchesRequired;
282   uint32_t mMaxTouchesRequired;
283   uint32_t mMaxMotionEventAge;
284
285   Vector2 mLastVelocity;       ///< The last recorded velocity in local actor coordinates.
286   Vector2 mLastScreenVelocity; ///< The last recorded velocity in screen coordinates.
287
288   const PanGestureEvent*  mCurrentPanEvent; ///< Pointer to current PanEvent, used when calling ProcessAndEmit()
289   SceneGraph::PanGesture* mSceneObject;     ///< Not owned, but we write to it directly
290 };
291
292 } // namespace Internal
293
294 } // namespace Dali
295
296 #endif // DALI_INTERNAL_EVENT_PAN_GESTURE_EVENT_PROCESSOR_H