Merge remote-tracking branch 'origin/tizen' into new_text
[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) 2014 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 }
45
46 /**
47  * Pan Gesture Event Processing:
48  *
49  * When we receive a pan gesture event, we do the following:
50  * - Find the actor that requires a pan where the pan started from (i.e. the down position).
51  * - Emit the gesture if the event satisfies the detector conditions.
52  *
53  * The above is only checked when our gesture starts.  We continue sending the pan gesture to the
54  * same actor and detector until the pan ends or is cancelled.
55  */
56 class PanGestureProcessor : public GestureProcessor
57 {
58 public:
59
60   /**
61    * Create a pan gesture processor.
62    * @param[in] stage The stage.
63    * @param[in] gestureManager The gesture manager
64    */
65   PanGestureProcessor( Stage& stage, Integration::GestureManager& gestureManager );
66
67   /**
68    * Non-virtual destructor; PanGestureProcessor is not a base class
69    */
70   ~PanGestureProcessor();
71
72 public: // To be called by GestureEventProcessor
73
74   /**
75    * This method is called whenever a pan gesture event occurs.
76    * @param[in] panEvent The event that has occurred.
77    */
78   void Process( const Integration::PanGestureEvent& panEvent );
79
80   /**
81    * Adds a gesture detector to this gesture processor.
82    * If this is the first gesture detector being added, then this method registers the required
83    * gesture with the adaptor.
84    * @param[in]  gestureDetector  The gesture detector being added.
85    */
86   void AddGestureDetector( PanGestureDetector* gestureDetector );
87
88   /**
89    * Removes the specified gesture detector from this gesture processor.  If, after removing this
90    * gesture detector, there are no more gesture detectors registered, then this method unregisters
91    * the gesture from the adaptor.
92    * @param[in]  gestureDetector  The gesture detector being removed.
93    */
94   void RemoveGestureDetector( PanGestureDetector* gestureDetector );
95
96   /**
97    * This method updates the gesture detection parameters.
98    * @param[in]  gestureDetector  The gesture detector that has been updated.
99    */
100   void GestureDetectorUpdated( PanGestureDetector* gestureDetector );
101
102   /**
103    * Sets the pan gesture properties stored in the scene object directly,
104    * @param[in]  pan  The pan gesture to override the properties with.
105    * @note If we are already processing a normal pan, then this call is ignored.
106    */
107   void SetPanGestureProperties( const PanGesture& pan );
108
109   /**
110    * Called to provide pan-gesture profiling information.
111    */
112   void EnableProfiling();
113
114   /**
115    * Called to set the prediction mode for pan gestures
116    *
117    * @param[in] mode The prediction mode
118    *
119    * Valid modes:
120    * 0 - No prediction
121    * 1 - Prediction using average acceleration
122    */
123   void SetPredictionMode(int mode);
124
125   /**
126    * @brief Sets the prediction amount of the pan gesture
127    *
128    * @param[in] amount The prediction amount in milliseconds
129    */
130   void SetPredictionAmount(unsigned int amount);
131
132   /**
133    * @brief Sets the upper bound of the prediction amount for clamping
134    *
135    * @param[in] amount The prediction amount in milliseconds
136    */
137   void SetMaximumPredictionAmount(unsigned int amount);
138
139   /**
140    * @brief Sets the lower bound of the prediction amount for clamping
141    *
142    * @param[in] amount The prediction amount in milliseconds
143    */
144   void SetMinimumPredictionAmount(unsigned int amount);
145
146   /**
147    * @brief Sets the amount of prediction interpolation to adjust when the pan velocity is changed
148    *
149    * @param[in] amount The prediction amount in milliseconds
150    */
151   void SetPredictionAmountAdjustment(unsigned int amount);
152
153   /**
154    * Called to set the prediction mode for pan gestures
155    *
156    * @param[in] mode The prediction mode
157    *
158    * Valid modes:
159    * 0 - No smoothing
160    * 1 - average between last 2 values
161    */
162   void SetSmoothingMode(int mode);
163
164   /**
165    * @brief Sets the smoothing amount of the pan gesture
166    *
167    * @param[in] amount The smotthing amount from 0.0f (none) to 1.0f (full)
168    */
169   void SetSmoothingAmount(float amount);
170
171 private:
172
173   // Undefined
174   PanGestureProcessor( const PanGestureProcessor& );
175   PanGestureProcessor& operator=( const PanGestureProcessor& rhs );
176
177   /**
178    * Iterates through our GestureDetectors and determines if we need to ask the adaptor to update
179    * its detection policy.  If it does, it sends the appropriate gesture update request to adaptor.
180    */
181   void UpdateDetection();
182
183   /**
184    * Creates a PanGesture and asks the specified detector to emit its detected signal.
185    * @param[in]  actor             The actor that has been panned.
186    * @param[in]  gestureDetectors  The gesture detector container that should emit the signal.
187    * @param[in]  panEvent          The panEvent received from the adaptor.
188    * @param[in]  localCurrent      Current position relative to the actor attached to the detector.
189    * @param[in]  state             The state of the gesture.
190    * @param[in]  renderTask        The renderTask to use.
191    */
192   void EmitPanSignal( Actor* actor,
193                       const GestureDetectorContainer& gestureDetectors,
194                       const Integration::PanGestureEvent& panEvent,
195                       Vector2 localCurrent,
196                       Gesture::State state,
197                       Dali::RenderTask renderTask );
198
199   // GestureProcessor overrides
200
201   /**
202    * @copydoc GestureProcessor::OnGesturedActorStageDisconnection()
203    */
204   void OnGesturedActorStageDisconnection();
205
206   /**
207    * @copydoc GestureProcessor::CheckGestureDetector()
208    */
209   bool CheckGestureDetector( GestureDetector* detector, Actor* actor );
210
211   /**
212    * @copydoc GestureProcessor::EmitGestureSignal()
213    */
214   void EmitGestureSignal( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates );
215
216 private:
217
218   Stage& mStage;
219   Integration::GestureManager& mGestureManager;
220   PanGestureDetectorContainer mGestureDetectors;
221   GestureDetectorContainer mCurrentPanEmitters;
222   Dali::RenderTask mCurrentRenderTask;
223   Vector2 mPossiblePanPosition;
224
225   unsigned int mMinTouchesRequired;
226   unsigned int mMaxTouchesRequired;
227
228   Vector2 mLastVelocity;       ///< The last recorded velocity in local actor coordinates.
229   Vector2 mLastScreenVelocity; ///< The last recorded velocity in screen coordinates.
230
231   const Integration::PanGestureEvent* mCurrentPanEvent; ///< Pointer to current PanEvent, used when calling ProcessAndEmit()
232   SceneGraph::PanGesture* mSceneObject; ///< Not owned, but we write to it directly
233 };
234
235 } // namespace Internal
236
237 } // namespace Dali
238
239 #endif // __DALI_INTERNAL_PAN_GESTURE_EVENT_PROCESSOR_H__