1 #ifndef __DALI_INTERNAL_GESTURE_PROCESSOR_H__
2 #define __DALI_INTERNAL_GESTURE_PROCESSOR_H__
5 * Copyright (c) 2014 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/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>
35 * Base class for the different Gesture Processors.
37 class GestureProcessor : public ProxyObject::Observer
39 protected: // Construction & Destruction
42 * Protected constructor. Cannot create an instance of GestureProcessor
44 GestureProcessor( Gesture::Type type );
47 * Virtual protected destructor.
49 virtual ~GestureProcessor();
51 // Types for deriving classes
54 * Functor to use in GetGesturedActor() and ProcessAndEmit() methods.
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.
64 virtual bool operator() ( GestureDetector* detector, Actor* actor ) = 0;
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.
73 virtual void operator() ( Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates ) = 0;
76 // Methods for deriving classes
79 * Given the hit actor, this walks up the actor tree to determine the actor that is connected to one (or several) gesture detectors.
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.
85 * @pre gestureDetectors should be empty.
87 void GetGesturedActor( Actor*& actor, GestureDetectorContainer& gestureDetectors, Functor& functor );
90 * Calls the emission method in the deriving class for matching gesture-detectors with the hit-actor (or one of its parents).
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.
95 * @pre Hit Testing should already be done.
97 void ProcessAndEmit( HitTestAlgorithm::Results& hitTestResults, Functor& functor );
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.
106 virtual bool HitTest(Stage& stage, Vector2 screenCoordinates, HitTestAlgorithm::Results& hitTestResults);
109 * Sets the mCurrentGesturedActor and connects to the required signals.
110 * @actor actor The actor so set.
112 void SetActor( Actor* actor );
115 * Resets the set actor and disconnects any connected signals.
120 * Returns the current gestured actor if it is on stage
122 * @return The current gestured actor
124 Actor* GetCurrentGesturedActor();
126 // For derived classes to override
129 * Called when the gestured actor is removed from the stage.
131 virtual void OnGesturedActorStageDisconnection() = 0;
136 GestureProcessor( const GestureProcessor& );
137 GestureProcessor& operator=( const GestureProcessor& );
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()
146 virtual void SceneObjectAdded(ProxyObject& proxy) { }
149 * This will be called when the actor is removed from the stage, we should clear and stop
151 * @param[in] proxy The proxy object.
152 * @see ProxyObject::Observer::SceneObjectRemoved()
154 virtual void SceneObjectRemoved(ProxyObject& proxy);
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()
161 virtual void ProxyDestroyed(ProxyObject& proxy);
166 * Signal handler called when the actor is removed from the stage.
167 * @param[in] actor The actor removed from the stage.
169 void OnStageDisconnection( Dali::Actor actor );
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
178 } // namespace Internal
182 #endif // __DALI_INTERNAL_GESTURE_PROCESSOR_H__