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