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