Merge branch 'devel/master' into tizen
[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) 2021 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    */
71   void Process(Scene& scene, const PanGestureEvent& panEvent) override;
72
73   /**
74    * Adds a gesture detector to this gesture processor.
75    * If this is the first gesture detector being added, then this method registers the required
76    * gesture with the adaptor.
77    * @param[in]  gestureDetector  The gesture detector being added.
78    */
79   void AddGestureDetector(PanGestureDetector* gestureDetector, Scene& scene, int32_t minDistance, int32_t minPanEvents);
80
81   /**
82    * Removes the specified gesture detector from this gesture processor.  If, after removing this
83    * gesture detector, there are no more gesture detectors registered, then this method unregisters
84    * the gesture from the adaptor.
85    * @param[in]  gestureDetector  The gesture detector being removed.
86    */
87   void RemoveGestureDetector(PanGestureDetector* gestureDetector);
88
89   /**
90    * This method updates the gesture detection parameters.
91    * @param[in]  gestureDetector  The gesture detector that has been updated.
92    */
93   void GestureDetectorUpdated(PanGestureDetector* gestureDetector);
94
95   /**
96    * Sets the pan gesture properties stored in the scene object directly,
97    * @param[in]  pan  The pan gesture to override the properties with.
98    * @return true if Core::Update required
99    * @note If we are already processing a normal pan, then this call is ignored.
100    */
101   bool SetPanGestureProperties(const Dali::PanGesture& pan);
102
103   /**
104    * Called to provide pan-gesture profiling information.
105    */
106   void EnableProfiling();
107
108   /**
109    * Called to set the prediction mode for pan gestures
110    *
111    * @param[in] mode The prediction mode
112    *
113    * Valid modes:
114    * 0 - No prediction
115    * 1 - Prediction using average acceleration
116    */
117   void SetPredictionMode(int mode);
118
119   /**
120    * @brief Sets the prediction amount of the pan gesture
121    *
122    * @param[in] amount The prediction amount in milliseconds
123    */
124   void SetPredictionAmount(unsigned int amount);
125
126   /**
127    * @brief Sets the upper bound of the prediction amount for clamping
128    *
129    * @param[in] amount The prediction amount in milliseconds
130    */
131   void SetMaximumPredictionAmount(unsigned int amount);
132
133   /**
134    * @brief Sets the lower bound of the prediction amount for clamping
135    *
136    * @param[in] amount The prediction amount in milliseconds
137    */
138   void SetMinimumPredictionAmount(unsigned int amount);
139
140   /**
141    * @brief Sets the amount of prediction interpolation to adjust when the pan velocity is changed
142    *
143    * @param[in] amount The prediction amount in milliseconds
144    */
145   void SetPredictionAmountAdjustment(unsigned int amount);
146
147   /**
148    * Called to set the prediction mode for pan gestures
149    *
150    * @param[in] mode The prediction mode
151    *
152    * Valid modes:
153    * 0 - No smoothing
154    * 1 - average between last 2 values
155    */
156   void SetSmoothingMode(int mode);
157
158   /**
159    * @brief Sets the smoothing amount of the pan gesture
160    *
161    * @param[in] amount The smotthing amount from 0.0f (none) to 1.0f (full)
162    */
163   void SetSmoothingAmount(float amount);
164
165   /*
166    * @brief Sets whether to use actual times of the real gesture and frames or not.
167    *
168    * @param[in] value True = use actual times, False = use perfect values
169    */
170   void SetUseActualTimes(bool value);
171
172   /**
173    * @brief Sets the interpolation time range (ms) of past points to use (with weights) when interpolating.
174    *
175    * @param[in] value Time range in ms
176    */
177   void SetInterpolationTimeRange(int value);
178
179   /**
180    * @brief Sets whether to use scalar only prediction, which when enabled, ignores acceleration.
181    *
182    * @param[in] value True = use scalar prediction only
183    */
184   void SetScalarOnlyPredictionEnabled(bool value);
185
186   /**
187    * @brief Sets whether to use two point prediction. This combines two interpolated points to get more steady acceleration and velocity values.
188    *
189    * @param[in] value True = use two point prediction
190    */
191   void SetTwoPointPredictionEnabled(bool value);
192
193   /**
194    * @brief Sets the time in the past to interpolate the second point when using two point interpolation.
195    *
196    * @param[in] value Time in past in ms
197    */
198   void SetTwoPointInterpolatePastTime(int value);
199
200   /**
201    * @brief Sets the two point velocity bias. This is the ratio of first and second points to use for velocity.
202    *
203    * @param[in] value 0.0f = 100% first point. 1.0f = 100% of second point.
204    */
205   void SetTwoPointVelocityBias(float value);
206
207   /**
208    * @brief Sets the two point acceleration bias. This is the ratio of first and second points to use for acceleration.
209    *
210    * @param[in] value 0.0f = 100% first point. 1.0f = 100% of second point.
211    */
212   void SetTwoPointAccelerationBias(float value);
213
214   /**
215    * @brief Sets the range of time (ms) of points in the history to perform multitap smoothing with (if enabled).
216    *
217    * @param[in] value Time in past in ms
218    */
219   void SetMultitapSmoothingRange(int value);
220
221 public: // for PanGestureDetector
222   /**
223    * @return the pan gesture scene object
224    */
225   const SceneGraph::PanGesture& GetSceneObject() const;
226
227 private:
228   // Undefined
229   PanGestureProcessor(const PanGestureProcessor&);
230   PanGestureProcessor& operator=(const PanGestureProcessor& rhs);
231
232   /**
233    * Iterates through our GestureDetectors and determines if we need to ask the adaptor to update
234    * its detection policy.  If it does, it sends the appropriate gesture update request to adaptor.
235    */
236   void UpdateDetection();
237
238   /**
239    * Creates a PanGesture and asks the specified detector to emit its detected signal.
240    * @param[in]  actor             The actor that has been panned.
241    * @param[in]  gestureDetectors  The gesture detector container that should emit the signal.
242    * @param[in]  panEvent          The panEvent received from the adaptor.
243    * @param[in]  localCurrent      Current position relative to the actor attached to the detector.
244    * @param[in]  state             The state of the gesture.
245    * @param[in]  renderTask        The renderTask to use.
246    */
247   void EmitPanSignal(Actor*                          actor,
248                      const GestureDetectorContainer& gestureDetectors,
249                      const PanGestureEvent&          panEvent,
250                      Vector2                         localCurrent,
251                      GestureState                    state,
252                      RenderTaskPtr                   renderTask);
253
254   // GestureProcessor overrides
255
256   /**
257    * @copydoc GestureProcessor::OnGesturedActorStageDisconnection()
258    */
259   void OnGesturedActorStageDisconnection() override;
260
261   /**
262    * @copydoc GestureProcessor::CheckGestureDetector()
263    */
264   bool CheckGestureDetector(GestureDetector* detector, Actor* actor) override;
265
266   /**
267    * @copydoc GestureProcessor::EmitGestureSignal()
268    */
269   void EmitGestureSignal(Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates) override;
270
271 private:
272   PanGestureDetectorContainer mPanGestureDetectors;
273   GestureDetectorContainer    mCurrentPanEmitters;
274   RenderTaskPtr               mCurrentRenderTask;
275   Vector2                     mPossiblePanPosition;
276
277   uint32_t mMinTouchesRequired;
278   uint32_t mMaxTouchesRequired;
279
280   Vector2 mLastVelocity;       ///< The last recorded velocity in local actor coordinates.
281   Vector2 mLastScreenVelocity; ///< The last recorded velocity in screen coordinates.
282
283   const PanGestureEvent*  mCurrentPanEvent; ///< Pointer to current PanEvent, used when calling ProcessAndEmit()
284   SceneGraph::PanGesture* mSceneObject;     ///< Not owned, but we write to it directly
285 };
286
287 } // namespace Internal
288
289 } // namespace Dali
290
291 #endif // DALI_INTERNAL_EVENT_PAN_GESTURE_EVENT_PROCESSOR_H