1 #ifndef DALI_INTERNAL_GESTURE_PROCESSOR_H
2 #define DALI_INTERNAL_GESTURE_PROCESSOR_H
5 * Copyright (c) 2019 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/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>
37 * Base class for the different Gesture Processors.
39 class GestureProcessor : public Object::Observer
44 * Process the touch event in the attached recognizer
45 * @param[in] scene Scene.
46 * @param[in] event Touch event to process
48 void ProcessTouch( Scene& scene, const Integration::TouchEvent& event );
51 * Returns whether any GestureDetector requires a Core::Update
52 * @return true if update required
54 inline bool NeedsUpdate()
56 bool updateRequired = mNeedsUpdate;
58 return updateRequired;
63 // Construction & Destruction
66 * Protected constructor. Cannot create an instance of GestureProcessor
68 GestureProcessor( DevelGesture::Type type );
71 * Protected constructor. Cannot create an instance of GestureProcessor
73 GestureProcessor( Gesture::Type type );
76 * Virtual protected destructor.
78 virtual ~GestureProcessor();
80 // Methods to be used by deriving classes
83 * Given the hit actor, this walks up the actor tree to determine the actor that is connected to one (or several) gesture detectors.
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.
88 * @note Uses CheckGestureDetector() to check if a the current gesture matches the criteria the gesture detector requires.
89 * @pre gestureDetectors should be empty.
91 void GetGesturedActor( Actor*& actor, GestureDetectorContainer& gestureDetectors );
94 * Calls the emission method in the deriving class for matching gesture-detectors with the hit-actor (or one of its parents).
96 * @param[in] hitTestResults The Hit Test Results.
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.
102 void ProcessAndEmit( HitTestAlgorithm::Results& hitTestResults );
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.
111 virtual bool HitTest( Scene& scene, Vector2 screenCoordinates, HitTestAlgorithm::Results& hitTestResults);
114 * Sets the mCurrentGesturedActor and connects to the required signals.
115 * @actor actor The actor so set.
117 void SetActor( Actor* actor );
120 * Resets the set actor and disconnects any connected signals.
125 * Returns the current gestured actor if it is on stage
127 * @return The current gestured actor
129 Actor* GetCurrentGesturedActor();
133 // For derived classes to override
136 * Called when the gestured actor is removed from the stage.
138 virtual void OnGesturedActorStageDisconnection() = 0;
141 * Called by the ProcessAndEmit() & GetGesturedActor() methods to check if the provided
142 * gesture-detector meets the parameters of the current gesture.
144 * @param[in] detector The gesture detector to check.
145 * @param[in] actor The actor that has been gestured.
147 * @return true, if the detector meets the parameters, false otherwise.
149 virtual bool CheckGestureDetector( GestureDetector* detector, Actor* actor ) = 0;
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.
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.
160 virtual void EmitGestureSignal( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates ) = 0;
164 GestureProcessor( const GestureProcessor& );
165 GestureProcessor& operator=( const GestureProcessor& );
167 // SceneObject overrides
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()
174 virtual void SceneObjectAdded(Object& object) { }
177 * This will be called when the actor is removed from the stage, we should clear and stop
179 * @param[in] object The object object.
180 * @see Object::Observer::SceneObjectRemoved()
182 virtual void SceneObjectRemoved(Object& object);
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()
189 virtual void ObjectDestroyed(Object& object);
194 GestureRecognizerPtr mGestureRecognizer; ///< The gesture recognizer
195 bool mNeedsUpdate; ///< Indicates if any GestureDetector requires a Core::Update
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
204 } // namespace Internal
208 #endif // DALI_INTERNAL_GESTURE_PROCESSOR_H