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