Revert "License conversion from Flora to Apache 2.0"
[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 Flora License, Version 1.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://floralicense.org/license/
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 // INTERNAL INCLUDES
21 #include <dali/public-api/render-tasks/render-task.h>
22 #include <dali/internal/event/events/pan-gesture-detector-impl.h>
23 #include <dali/internal/event/events/gesture-processor.h>
24
25 namespace Dali
26 {
27
28 namespace Integration
29 {
30 class GestureManager;
31 struct GestureEvent;
32 struct PanGestureEvent;
33 }
34
35 namespace Internal
36 {
37
38 class Stage;
39
40 namespace SceneGraph
41 {
42 class PanGesture;
43 }
44
45 /**
46  * Pan Gesture Event Processing:
47  *
48  * When we receive a pinch gesture event, we do the following:
49  * - Determine the hot actor underneath the current position of the pan gesture event.
50  * - Determine whether this actor is, or is a child of, the actor(s) attached to any of the
51  *   detectors.
52  * - Emit the gesture when all the above conditions are met.
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    */
66   PanGestureProcessor( Stage& stage, Integration::GestureManager& gestureManager );
67
68   /**
69    * Non-virtual destructor; PanGestureProcessor is not a base class
70    */
71   ~PanGestureProcessor();
72
73 public: // To be called by GestureEventProcessor
74
75   /**
76    * This method is called whenever a pinch gesture event occurs.
77    * @param[in] panEvent The event that has occurred.
78    */
79   void Process( const Integration::PanGestureEvent& panEvent );
80
81   /**
82    * Adds a gesture detector to this gesture processor.
83    * If this is the first gesture detector being added, then this method registers the required
84    * gesture with the adaptor.
85    * @param[in]  gestureDetector  The gesture detector being added.
86    */
87   void AddGestureDetector( PanGestureDetector* gestureDetector );
88
89   /**
90    * Removes the specified gesture detector from this gesture processor.  If, after removing this
91    * gesture detector, there are no more gesture detectors registered, then this method unregisters
92    * the gesture from the adaptor.
93    * @param[in]  gestureDetector  The gesture detector being removed.
94    */
95   void RemoveGestureDetector( PanGestureDetector* gestureDetector );
96
97   /**
98    * This method updates the gesture detection parameters.
99    * @param[in]  gestureDetector  The gesture detector that has been updated.
100    */
101   void GestureDetectorUpdated( PanGestureDetector* gestureDetector );
102
103   /**
104    * Sets the pan gesture properties stored in the scene object directly,
105    * @param[in]  pan  The pan gesture to override the properties with.
106    * @note If we are already processing a normal pan, then this call is ignored.
107    */
108   void SetPanGestureProperties( const PanGesture& pan );
109
110   /**
111    * Called to provide pan-gesture profiling information.
112    */
113   void EnableProfiling();
114
115   /**
116    * Called to set the prediction mode for pan gestures
117    *
118    * @param[in] mode The prediction mode
119    *
120    * Valid modes:
121    * 0 - No prediction
122    * 1 - Average Smoothing (no actual prediction)
123    * 2 - Interpolation using last vsync time and event time
124    * 3 - Same as 2 for now, in progress
125    */
126   void SetPredictionMode(int mode);
127
128 private:
129
130   // Undefined
131   PanGestureProcessor( const PanGestureProcessor& );
132   PanGestureProcessor& operator=( const PanGestureProcessor& rhs );
133
134   /**
135    * Iterates through our GestureDetectors and determines if we need to ask the adaptor to update
136    * its detection policy.  If it does, it sends the appropriate gesture update request to adaptor.
137    */
138   void UpdateDetection();
139
140   /**
141    * Creates a PanGesture and asks the specified detector to emit its detected signal.
142    * @param[in]  actor             The actor that has been panned.
143    * @param[in]  gestureDetectors  The gesture detector container that should emit the signal.
144    * @param[in]  panEvent          The panEvent received from the adaptor.
145    * @param[in]  localCurrent      Current position relative to the actor attached to the detector.
146    * @param[in]  state             The state of the gesture.
147    * @param[in]  renderTask        The renderTask to use.
148    */
149   void EmitPanSignal( Dali::Actor actor,
150                       PanGestureDetectorContainer& gestureDetectors,
151                       const Integration::PanGestureEvent& panEvent,
152                       Vector2 localCurrent,
153                       Gesture::State state,
154                       Dali::RenderTask renderTask );
155
156   // GestureProcessor overrides
157
158   /**
159    * @copydoc GestureProcessor::OnGesturedActorStageDisconnection()
160    */
161   void OnGesturedActorStageDisconnection();
162
163 private:
164
165   Stage& mStage;
166   Integration::GestureManager& mGestureManager;
167   PanGestureDetectorContainer mGestureDetectors;
168   PanGestureDetectorContainer mCurrentPanEmitters;
169   Dali::RenderTask mCurrentRenderTask;
170   Vector2 mPossiblePanPosition;
171
172   unsigned int mMinTouchesRequired;
173   unsigned int mMaxTouchesRequired;
174
175   Vector2 mLastVelocity;       ///< The last recorded velocity in local actor coordinates.
176   Vector2 mLastScreenVelocity; ///< The last recorded velocity in screen coordinates.
177
178   struct PanEventFunctor;
179
180   SceneGraph::PanGesture* mSceneObject; ///< Not owned, but we write to it directly
181 };
182
183 } // namespace Internal
184
185 } // namespace Dali
186
187 #endif // __DALI_INTERNAL_PAN_GESTURE_EVENT_PROCESSOR_H__