[SRUK] Initial copy from Tizen 2.2 version
[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 private:
111
112   // Undefined
113   PanGestureProcessor( const PanGestureProcessor& );
114   PanGestureProcessor& operator=( const PanGestureProcessor& rhs );
115
116   /**
117    * Iterates through our GestureDetectors and determines if we need to ask the adaptor to update
118    * its detection policy.  If it does, it sends the appropriate gesture update request to adaptor.
119    */
120   void UpdateDetection();
121
122   /**
123    * Creates a PanGesture and asks the specified detector to emit its detected signal.
124    * @param[in]  actor             The actor that has been panned.
125    * @param[in]  gestureDetectors  The gesture detector container that should emit the signal.
126    * @param[in]  panEvent          The panEvent received from the adaptor.
127    * @param[in]  localCurrent      Current position relative to the actor attached to the detector.
128    * @param[in]  state             The state of the gesture.
129    * @param[in]  renderTask        The renderTask to use.
130    */
131   void EmitPanSignal( Dali::Actor actor,
132                       PanGestureDetectorContainer& gestureDetectors,
133                       const Integration::PanGestureEvent& panEvent,
134                       Vector2 localCurrent,
135                       Gesture::State state,
136                       Dali::RenderTask renderTask );
137
138   // GestureProcessor overrides
139
140   /**
141    * @copydoc GestureProcessor::OnGesturedActorStageDisconnection()
142    */
143   void OnGesturedActorStageDisconnection();
144
145 private:
146
147   Stage& mStage;
148   Integration::GestureManager& mGestureManager;
149   PanGestureDetectorContainer mGestureDetectors;
150   PanGestureDetectorContainer mCurrentPanEmitters;
151   Dali::RenderTask mCurrentRenderTask;
152   Vector2 mPossiblePanPosition;
153
154   unsigned int mMinTouchesRequired;
155   unsigned int mMaxTouchesRequired;
156
157   Vector2 mLastVelocity;       ///< The last recorded velocity in local actor coordinates.
158   Vector2 mLastScreenVelocity; ///< The last recorded velocity in screen coordinates.
159
160   struct PanEventFunctor;
161
162   SceneGraph::PanGesture* mSceneObject; ///< Not owned, but we write to it directly
163 };
164
165 } // namespace Internal
166
167 } // namespace Dali
168
169 #endif // __DALI_INTERNAL_PAN_GESTURE_EVENT_PROCESSOR_H__