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