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 // Templates and types for deriving classes
54 * Given a container of derived pointer types, this populates an equivalent container of base pointer types.
55 * @param[in] derivedContainer A const reference to the container with pointers to the derived class.
56 * @param[out] baseContainer A reference to the container to populate with equivalent pointers to the base class.
57 * @pre Ensure the baseContainer is empty.
59 template< typename Detector >
60 static void UpCastContainer( const typename DerivedGestureDetectorContainer<Detector>::type& derivedContainer, GestureDetectorContainer& baseContainer )
62 baseContainer.assign( derivedContainer.begin(), derivedContainer.end() );
66 * Given a container of base pointer types, this populates an equivalent container of derived pointer types.
67 * @param[in] baseContainer A const reference to the container with pointers to the base class.
68 * @param[out] derivedContainer A reference to the container to populate with equivalent pointers to the derived class.
69 * @pre Ensure the derivedContainer is empty.
71 template< typename Detector >
72 static void DownCastContainer( const GestureDetectorContainer& baseContainer, typename DerivedGestureDetectorContainer<Detector>::type& derivedContainer )
74 for ( GestureDetectorContainer::const_iterator iter = baseContainer.begin(), endIter = baseContainer.end(); iter != endIter; ++iter )
76 derivedContainer.push_back( static_cast< Detector* >( *iter ) );
81 * Functor to use in GetGesturedActor() and ProcessAndEmit() methods.
86 * This operator should be overridden to check if the gesture detector meets the parameters of the current gesture.
87 * @param[in] detector The gesture detector to check.
88 * @param[in] actor The actor that has been gestured.
89 * @return true, if it meets the parameters, false otherwise.
91 virtual bool operator() ( GestureDetector* detector, Actor* actor ) = 0;
94 * This operator should be overridden to emit the gesture signal on the provided container of gesture detectors along with the actor
95 * the gesture has occurred on.
96 * @param[in] actor The actor which has been gestured.
97 * @param[in] gestureDetectors The detectors that should emit the signal.
98 * @param[in] actorCoordinates The local actor coordinates where the gesture took place.
100 virtual void operator() ( Dali::Actor actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates ) = 0;
103 // Methods for deriving classes
106 * Given the hit actor and attached detectors, this walks up the actor tree to determine the actor that is connected to one (or several) gesture
107 * detectors. The functor is used to check whether the gesture falls within the gesture detector's parameters.
108 * Derived classes need to provide this functor.
110 * @param[in,out] actor The hit actor. When this function returns, this is the actor that has been hit by the gesture.
111 * @param[in] connectedDetectors Reference to the detectors connected to the derived processor
112 * @param[out] gestureDetectors A container containing all the gesture detectors that have the hit actor attached and satisfy the functor parameters.
113 * @param[in] functor A reference to Functor. The operator() (GestureDetector*) should be used to check if the connected gesture detector
114 * meets the current gesture's parameters.
116 void GetGesturedActor( Dali::Actor& actor, const GestureDetectorContainer& connectedDetectors, GestureDetectorContainer& gestureDetectors, Functor& functor );
119 * This does what GetGesturedActor() does but also starts emission of the gesture (using the functor).
121 * @param[in] hitTestResults The Hit Test Results.
122 * @param[in] connectedDetectors The detectors attached to the gesture processor.
123 * @param[in] functor A reference to the functor which should provide an operator() to check if detector satisfies current gesture and another
124 * operator() which will be called when all conditions are met and the gesture should be emitted for the actor and detectors.
126 * @pre Hit Testing should already be done.
128 void ProcessAndEmit( const HitTestAlgorithm::Results& hitTestResults, const GestureDetectorContainer& connectedDetectors, Functor& functor );
131 * Hit test the screen coordinates, and place the results in hitTestResults.
132 * @param[in] stage Stage.
133 * @param[in] screenCoordinates The screen coordinates to test.
134 * @param[out] hitTestResults Structure to write results into.
135 * @return false if the system overlay was hit or no actor was hit.
137 virtual bool HitTest(Stage& stage, Vector2 screenCoordinates, HitTestAlgorithm::Results& hitTestResults);
140 * Sets the mCurrentGesturedActor and connects to the required signals.
141 * @actor actor The actor so set.
143 void SetActor( Dali::Actor actor );
146 * Resets the set actor and disconnects any connected signals.
151 * Returns the current gestured actor if it is on stage
153 * @return The current gestured actor
155 Actor* GetCurrentGesturedActor();
157 // For derived classes to override
160 * Called when the gestured actor is removed from the stage.
162 virtual void OnGesturedActorStageDisconnection() = 0;
167 GestureProcessor( const GestureProcessor& );
168 GestureProcessor& operator=( const GestureProcessor& );
173 * This will never get called as we do not observe objects that have not been added to the scene.
174 * @param[in] proxy The proxy object.
175 * @see ProxyObject::Observer::SceneObjectAdded()
177 virtual void SceneObjectAdded(ProxyObject& proxy) { }
180 * This will be called when the actor is removed from the stage, we should clear and stop
182 * @param[in] proxy The proxy object.
183 * @see ProxyObject::Observer::SceneObjectRemoved()
185 virtual void SceneObjectRemoved(ProxyObject& proxy);
188 * This will be called when the actor is destroyed. We should clear the actor.
189 * No need to stop observing as the object is being destroyed anyway.
190 * @see ProxyObject::Observer::ProxyDestroyed()
192 virtual void ProxyDestroyed(ProxyObject& proxy);
197 * Signal handler called when the actor is removed from the stage.
198 * @param[in] actor The actor removed from the stage.
200 void OnStageDisconnection( Dali::Actor actor );
204 Gesture::Type mType; ///< Type of GestureProcessor
205 Actor* mCurrentGesturedActor; ///< The current actor that has been gestured.
206 bool mGesturedActorDisconnected:1; ///< Indicates whether the gestured actor has been disconnected from the scene
209 } // namespace Internal
213 #endif // __DALI_INTERNAL_GESTURE_PROCESSOR_H__