(Gestures) Use the actor-gesture-data containers and use raw Actor pointers.
[platform/core/uifw/dali-core.git] / dali / internal / event / events / gesture-processor.h
1 #ifndef __DALI_INTERNAL_GESTURE_PROCESSOR_H__
2 #define __DALI_INTERNAL_GESTURE_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/internal/event/events/gesture-detector-impl.h>
23 #include <dali/internal/event/events/hit-test-algorithm-impl.h>
24 #include <dali/internal/event/common/proxy-object.h>
25
26 namespace Dali
27 {
28
29 class Actor;
30
31 namespace Internal
32 {
33
34 /**
35  * Base class for the different Gesture Processors.
36  */
37 class GestureProcessor : public ProxyObject::Observer
38 {
39 protected: // Construction & Destruction
40
41   /**
42    * Protected constructor.  Cannot create an instance of GestureProcessor
43    */
44   GestureProcessor( Gesture::Type type );
45
46   /**
47    * Virtual protected destructor.
48    */
49   virtual ~GestureProcessor();
50
51   // Types for deriving classes
52
53   /**
54    * Functor to use in GetGesturedActor() and ProcessAndEmit() methods.
55    */
56   struct Functor
57   {
58     /**
59      * This operator should be overridden to check if the gesture detector meets the parameters of the current gesture.
60      * @param[in]  detector  The gesture detector to check.
61      * @param[in]  actor     The actor that has been gestured.
62      * @return true, if it meets the parameters, false otherwise.
63      */
64     virtual bool operator() ( GestureDetector* detector, Actor* actor ) = 0;
65
66     /**
67      * This operator should be overridden to emit the gesture signal on the provided container of gesture detectors along with the actor
68      * the gesture has occurred on.
69      * @param[in]  actor             The actor which has been gestured.
70      * @param[in]  gestureDetectors  The detectors that should emit the signal.
71      * @param[in]  actorCoordinates  The local actor coordinates where the gesture took place.
72      */
73     virtual void operator() ( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates ) = 0;
74   };
75
76   // Methods for deriving classes
77
78   /**
79    * Given the hit actor, this walks up the actor tree to determine the actor that is connected to one (or several) gesture detectors.
80    *
81    * @param[in,out]  actor               The gestured actor. When this function returns, this is the actor that has been hit by the gesture.
82    * @param[out]     gestureDetectors    A container containing all the gesture detectors that have the hit actor attached and satisfy the functor parameters.
83    * @param[in]      functor             Used to check if a gesture-detector matches the criteria the gesture detector requires.
84    *
85    * @pre gestureDetectors should be empty.
86    */
87   void GetGesturedActor( Actor*& actor, GestureDetectorContainer& gestureDetectors, Functor& functor );
88
89   /**
90    * Calls the emission method in the deriving class for matching gesture-detectors with the hit-actor (or one of its parents).
91    *
92    * @param[in]  hitTestResults      The Hit Test Results.
93    * @param[in]  functor             Used to check if a gesture-detector matches the criteria the gesture detector requires and for emitting the signal.
94    *
95    * @pre Hit Testing should already be done.
96    */
97   void ProcessAndEmit( HitTestAlgorithm::Results& hitTestResults, Functor& functor );
98
99   /**
100    * Hit test the screen coordinates, and place the results in hitTestResults.
101    * @param[in] stage Stage.
102    * @param[in] screenCoordinates The screen coordinates to test.
103    * @param[out] hitTestResults Structure to write results into.
104    * @return false if the system overlay was hit or no actor was hit.
105    */
106   virtual bool HitTest(Stage& stage, Vector2 screenCoordinates, HitTestAlgorithm::Results& hitTestResults);
107
108   /**
109    * Sets the mCurrentGesturedActor and connects to the required signals.
110    * @actor  actor  The actor so set.
111    */
112   void SetActor( Actor* actor );
113
114   /**
115    * Resets the set actor and disconnects any connected signals.
116    */
117   void ResetActor();
118
119   /**
120    * Returns the current gestured actor if it is on stage
121    *
122    * @return The current gestured actor
123    */
124   Actor* GetCurrentGesturedActor();
125
126   // For derived classes to override
127
128   /**
129    * Called when the gestured actor is removed from the stage.
130    */
131   virtual void OnGesturedActorStageDisconnection() = 0;
132
133 private:
134
135   // Undefined
136   GestureProcessor( const GestureProcessor& );
137   GestureProcessor& operator=( const GestureProcessor& );
138
139 private:
140
141   /**
142    * This will never get called as we do not observe objects that have not been added to the scene.
143    * @param[in] proxy The proxy object.
144    * @see ProxyObject::Observer::SceneObjectAdded()
145    */
146   virtual void SceneObjectAdded(ProxyObject& proxy) { }
147
148   /**
149    * This will be called when the actor is removed from the stage, we should clear and stop
150    * observing it.
151    * @param[in] proxy The proxy object.
152    * @see ProxyObject::Observer::SceneObjectRemoved()
153    */
154   virtual void SceneObjectRemoved(ProxyObject& proxy);
155
156   /**
157    * This will be called when the actor is destroyed. We should clear the actor.
158    * No need to stop observing as the object is being destroyed anyway.
159    * @see ProxyObject::Observer::ProxyDestroyed()
160    */
161   virtual void ProxyDestroyed(ProxyObject& proxy);
162
163   // Signal Handlers
164
165   /**
166    * Signal handler called when the actor is removed from the stage.
167    * @param[in]  actor  The actor removed from the stage.
168    */
169   void OnStageDisconnection( Dali::Actor actor );
170
171 private: // Data
172
173   Gesture::Type mType;                 ///< Type of GestureProcessor
174   Actor* mCurrentGesturedActor;        ///< The current actor that has been gestured.
175   bool   mGesturedActorDisconnected:1; ///< Indicates whether the gestured actor has been disconnected from the scene
176 };
177
178 } // namespace Internal
179
180 } // namespace Dali
181
182 #endif // __DALI_INTERNAL_GESTURE_PROCESSOR_H__