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