1 #ifndef __DALI_INTERNAL_GESTURE_DETECTOR_H__
2 #define __DALI_INTERNAL_GESTURE_DETECTOR_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
21 #include <dali/public-api/common/vector-wrapper.h>
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/public-api/events/gesture.h>
24 #include <dali/public-api/signals/slot-delegate.h>
25 #include <dali/public-api/events/gesture-detector.h>
26 #include <dali/internal/event/actors/actor-impl.h>
39 class GestureDetector;
40 class GestureEventProcessor;
42 typedef IntrusivePtr<GestureDetector> GestureDetectorPtr;
43 typedef std::vector<GestureDetector*> GestureDetectorContainer;
44 typedef std::vector<Actor*> GestureDetectorActorContainer;
47 * This is a type trait that should be used by deriving gesture detectors for their container type.
49 template< typename Detector >
50 struct DerivedGestureDetectorContainer
52 typedef std::vector<Detector*> type;
56 * @copydoc Dali::GestureDetector
58 class GestureDetector : public ProxyObject, public ProxyObject::Observer
63 * @copydoc Dali::GestureDetector::Attach()
65 void Attach(Actor& actor);
68 * @copydoc Dali::GestureDetector::Detach()
70 void Detach(Actor& actor);
73 * @copydoc Dali::GestureDetector::DetachAll()
78 * @copydoc Dali::GestureDetector::GetAttachedActors() const
80 std::vector<Dali::Actor> GetAttachedActors() const;
83 * Returns a const reference to the container of attached actor pointers.
84 * @return A const reference to the attached internal actors.
86 const GestureDetectorActorContainer& GetAttachedActorPointers() const
88 return mAttachedActors;
92 * Retrieves the type of GestureDetector
93 * @return The GestureDetector Type
95 Gesture::Type GetType() const
101 * Checks if the specified actor is still attached.
102 * @param[in] actor The actor to check.
103 * @return true, if the actor is attached, false otherwise.
105 bool IsAttached(Actor& actor) const;
107 protected: // Creation & Destruction
110 * Construct a new GestureDetector.
112 GestureDetector(Gesture::Type mType);
115 * A reference counted object may only be deleted by calling Unreference()
117 virtual ~GestureDetector();
122 GestureDetector(const GestureDetector&);
125 GestureDetector& operator=(const GestureDetector& rhs);
128 * @copydoc Dali::Internal::ProxyObject::Observer::SceneObjectAdded()
130 virtual void SceneObjectAdded(ProxyObject& proxy) {}
133 * @copydoc Dali::Internal::ProxyObject::Observer::SceneObjectAdded()
135 virtual void SceneObjectRemoved(ProxyObject& proxy) {}
138 * @copydoc Dali::Internal::ProxyObject::Observer::ProxyDestroyed()
140 virtual void ProxyDestroyed(ProxyObject& proxy);
143 * For use in derived classes, called after an actor is attached.
144 * @param[in] actor The actor that is being attached.
146 virtual void OnActorAttach(Actor& actor) = 0;
149 * For use in derived classes, called after an actor is detached.
150 * @param[in] actor The actor that is being detached.
152 virtual void OnActorDetach(Actor& actor) = 0;
155 * For use in derived classes, called when an attached actor is destroyed.
156 * @param[in] object The object (Actor's base class) that has been destroyed.
157 * @note Derived classes should not call any Actor specific APIs in this method as the Actor's
158 * destructor would have already been called.
160 virtual void OnActorDestroyed(Object& object) = 0;
163 * Dummy touch event handler. We do not need to know when touch happens on our actor. We just
164 * need to connect a function so that our attached actor is checked during our hit testing.
165 * @param[in] actor The hit actor (or one of its parents).
166 * @param[in] event The touch event.
167 * @return false always as we do not process the event.
169 bool OnTouchEvent(Dali::Actor actor, const TouchEvent& event);
171 private: // Default property extensions from ProxyObject
174 * @copydoc Dali::Internal::ProxyObject::IsSceneObjectRemovable()
176 virtual bool IsSceneObjectRemovable() const;
179 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyCount()
181 virtual unsigned int GetDefaultPropertyCount() const;
184 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
186 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
189 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
191 virtual const std::string& GetDefaultPropertyName(Property::Index index) const;
194 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
196 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
199 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyWritable()
201 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
204 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAnimatable()
206 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
209 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
211 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
214 * @copydoc Dali::Internal::ProxyObject::SetDefaultProperty()
216 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
219 * @copydoc Dali::Internal::ProxyObject::SetCustomProperty()
221 virtual void SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value );
224 * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
226 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
229 * @copydoc Dali::Internal::ProxyObject::InstallSceneObjectProperty()
231 virtual void InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index );
234 * @copydoc Dali::Internal::ProxyObject::GetSceneObject()
236 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
239 * @copydoc Dali::Internal::ProxyObject::GetSceneObjectAnimatableProperty()
241 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
244 * @copydoc Dali::Internal::ProxyObject::GetSceneObjectInputProperty()
246 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
250 Gesture::Type mType; ///< The gesture detector will detect this type of gesture.
251 GestureDetectorActorContainer mAttachedActors; ///< Proxy<Node>::Observer is used to provide weak-pointer behaviour
252 GestureEventProcessor& mGestureEventProcessor; ///< A reference to the gesture event processor.
256 SlotDelegate< GestureDetector > mSlotDelegate;
259 } // namespace Internal
261 // Helpers for public-api forwarding methods
263 inline Internal::GestureDetector& GetImplementation(Dali::GestureDetector& detector)
265 DALI_ASSERT_ALWAYS( detector && "GestureDetector handle is empty" );
267 BaseObject& handle = detector.GetBaseObject();
269 return static_cast<Internal::GestureDetector&>(handle);
272 inline const Internal::GestureDetector& GetImplementation(const Dali::GestureDetector& detector)
274 DALI_ASSERT_ALWAYS( detector && "GestureDetector handle is empty" );
276 const BaseObject& handle = detector.GetBaseObject();
278 return static_cast<const Internal::GestureDetector&>(handle);
283 #endif // __DALI_INTERNAL_GESTURE_DETECTOR_H__