1 #ifndef DALI_INTERNAL_GESTURE_PROCESSOR_H
2 #define DALI_INTERNAL_GESTURE_PROCESSOR_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/internal/event/common/object-impl.h>
23 #include <dali/internal/event/events/gesture-detector-impl.h>
24 #include <dali/internal/event/events/gesture-recognizer.h>
25 #include <dali/internal/event/events/hit-test-algorithm-impl.h>
34 * Base class for the different Gesture Processors.
36 class GestureProcessor : public Object::Observer
40 * Process the touch event in the attached recognizer
41 * @param[in] scene Scene.
42 * @param[in] event Touch event to process
44 void ProcessTouch(Scene& scene, const Integration::TouchEvent& event);
47 * Process the touch event in the attached recognizer
48 * @param[in] gestureDetector The gesture detector which gesture want to recognize.
49 * @param[in] actor The actor which gesture want to recognize.
50 * @param[in] renderTask RenderTask.
51 * @param[in] scene Scene.
52 * @param[in] event Touch event to process
54 void ProcessTouch(GestureDetector* gestureDetector, Actor& actor, Dali::Internal::RenderTask& renderTask, Scene& scene, const Integration::TouchEvent& event);
57 * Returns whether any GestureDetector requires a Core::Update
58 * @return true if update required
60 inline bool NeedsUpdate()
62 bool updateRequired = mNeedsUpdate;
64 return updateRequired;
68 // Construction & Destruction
71 * Protected constructor. Cannot create an instance of GestureProcessor
73 GestureProcessor(GestureType::Value type);
76 * Virtual protected destructor.
78 ~GestureProcessor() override;
80 // Methods to be used by deriving classes
83 * @brief Gets the Feeded actor
84 * @return The actor which gesture want to recognize.
86 Actor* GetFeededActor();
89 * @brief Gets the Feeded Gesture Detector.
90 * @return The gesture detector which gesture want to recognize.
92 GestureDetector* GetFeededGestureDetector();
95 * @brief Get the Feeded Render Task object
96 * @return RenderTaskPtr
98 RenderTaskPtr GetFeededRenderTask();
101 * Given the hit actor, this walks up the actor tree to determine the actor that is connected to one (or several) gesture detectors.
103 * @param[in,out] actor The gestured actor. When this function returns, this is the actor that has been hit by the gesture.
104 * @param[out] gestureDetectors A container containing all the gesture detectors that have the hit actor attached and satisfy the functor parameters.
106 * @note Uses CheckGestureDetector() to check if a the current gesture matches the criteria the gesture detector requires.
107 * @pre gestureDetectors should be empty.
109 void GetGesturedActor(Actor*& actor, GestureDetectorContainer& gestureDetectors);
112 * Calls the emission method in the deriving class for matching gesture-detectors with the hit-actor (or one of its parents).
114 * @param[in] hitTestResults The Hit Test Results.
116 * @note Uses the CheckGestureDetector() to check if the gesture matches the criteria of the given gesture detector
117 * and EmitGestureSignal() to emit the signal.
118 * @pre Hit Testing should already be done.
120 void ProcessAndEmit(HitTestAlgorithm::Results& hitTestResults);
123 * Calls the emission method in the deriving class for actor
125 * @param[in] hitTestResults The Hit Test Results.
127 * @note Uses the CheckGestureDetector() to check if the gesture matches the criteria of the given gesture detector
128 * and EmitGestureSignal() to emit the signal.
129 * @pre Hit Testing should already be done.
131 void ProcessAndEmitActor(HitTestAlgorithm::Results& hitTestResults, GestureDetector* gestureDetector);
134 * Hit test the screen coordinates, and place the results in hitTestResults.
135 * @param[in] scene Scene.
136 * @param[in] screenCoordinates The screen coordinates to test.
137 * @param[out] hitTestResults Structure to write results into.
138 * @return false if the system overlay was hit or no actor was hit.
140 virtual bool HitTest(Scene& scene, Vector2 screenCoordinates, HitTestAlgorithm::Results& hitTestResults);
143 * Sets the mCurrentGesturedActor and connects to the required signals.
144 * @actor actor The actor so set.
146 void SetActor(Actor* actor);
149 * Resets the set actor and disconnects any connected signals.
154 * Returns the current gestured actor if it is on stage
156 * @return The current gestured actor
158 Actor* GetCurrentGesturedActor();
161 // For derived classes to override
164 * Called when the gestured actor is removed from the stage.
166 virtual void OnGesturedActorStageDisconnection() = 0;
169 * Called by the ProcessAndEmit() & GetGesturedActor() methods to check if the provided
170 * gesture-detector meets the parameters of the current gesture.
172 * @param[in] detector The gesture detector to check.
173 * @param[in] actor The actor that has been gestured.
175 * @return true, if the detector meets the parameters, false otherwise.
177 virtual bool CheckGestureDetector(GestureDetector* detector, Actor* actor) = 0;
180 * Called by the ProcessAndEmit() method when the gesture meets all applicable criteria and
181 * should be overridden by deriving classes to emit the gesture signal on gesture-detectors
182 * provided for the actor the gesture has occurred on.
184 * @param[in] actor The actor which has been gestured.
185 * @param[in] gestureDetectors The detectors that should emit the signal.
186 * @param[in] actorCoordinates The local actor coordinates where the gesture took place.
188 virtual void EmitGestureSignal(Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates) = 0;
192 GestureProcessor(const GestureProcessor&);
193 GestureProcessor& operator=(const GestureProcessor&);
195 // SceneObject overrides
198 * This will never get called as we do not observe objects that have not been added to the scene.
199 * @param[in] object The object object.
200 * @see Object::Observer::SceneObjectAdded()
202 void SceneObjectAdded(Object& object) override
207 * This will be called when the actor is removed from the stage, we should clear and stop
209 * @param[in] object The object object.
210 * @see Object::Observer::SceneObjectRemoved()
212 void SceneObjectRemoved(Object& object) override;
215 * This will be called when the actor is destroyed. We should clear the actor.
216 * No need to stop observing as the object is being destroyed anyway.
217 * @see Object::Observer::ObjectDestroyed()
219 void ObjectDestroyed(Object& object) override;
222 GestureRecognizerPtr mGestureRecognizer; ///< The gesture recognizer
223 bool mNeedsUpdate; ///< Indicates if any GestureDetector requires a Core::Update
226 GestureType::Value mType; ///< Type of GestureProcessor
227 Actor* mCurrentGesturedActor; ///< The current actor that has been gestured.
228 Integration::Point mPoint; ///< The point of event touched.
229 uint32_t mEventTime; ///< The time the event occurred.
230 bool mGesturedActorDisconnected : 1; ///< Indicates whether the gestured actor has been disconnected from the scene
231 ActorObserver mFeededActor; ///< The actor used to generate this touch event.
232 RenderTaskPtr mRenderTask; ///< The render task used to generate this touch event.
233 GestureDetector* mGestureDetector; ///< The gesture detector which gesture want to recognize.
237 } // namespace Internal
241 #endif // DALI_INTERNAL_GESTURE_PROCESSOR_H