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 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/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/common/dali-common.h>
24 #include <dali/public-api/events/gesture.h>
25 #include <dali/public-api/signals/slot-delegate.h>
26 #include <dali/public-api/events/gesture-detector.h>
27 #include <dali/internal/event/actors/actor-impl.h>
40 class GestureDetector;
41 class GestureEventProcessor;
43 typedef IntrusivePtr<GestureDetector> GestureDetectorPtr;
44 typedef std::vector<GestureDetector*> GestureDetectorContainer;
45 typedef std::vector<Actor*> GestureDetectorActorContainer;
48 * This is a type trait that should be used by deriving gesture detectors for their container type.
50 template< typename Detector >
51 struct DerivedGestureDetectorContainer
53 typedef std::vector<Detector*> type;
57 * @copydoc Dali::GestureDetector
59 class GestureDetector : public ProxyObject, public ProxyObject::Observer
64 * @copydoc Dali::GestureDetector::Attach()
66 void Attach(Actor& actor);
69 * @copydoc Dali::GestureDetector::Detach()
71 void Detach(Actor& actor);
74 * @copydoc Dali::GestureDetector::DetachAll()
79 * @copydoc Dali::GestureDetector::GetAttachedActors() const
81 std::vector<Dali::Actor> GetAttachedActors() const;
84 * Returns a const reference to the container of attached actor pointers.
85 * @return A const reference to the attached internal actors.
87 const GestureDetectorActorContainer& GetAttachedActorPointers() const
89 return mAttachedActors;
93 * Retrieves the type of GestureDetector
94 * @return The GestureDetector Type
96 Gesture::Type GetType() const
102 * Checks if the specified actor is still attached.
103 * @param[in] actor The actor to check.
104 * @return true, if the actor is attached, false otherwise.
106 bool IsAttached(Actor& actor) const;
108 protected: // Creation & Destruction
111 * Construct a new GestureDetector.
113 GestureDetector(Gesture::Type mType);
116 * A reference counted object may only be deleted by calling Unreference()
118 virtual ~GestureDetector();
123 GestureDetector(const GestureDetector&);
126 GestureDetector& operator=(const GestureDetector& rhs);
129 * @copydoc Dali::Internal::ProxyObject::Observer::SceneObjectAdded()
131 virtual void SceneObjectAdded(ProxyObject& proxy) {}
134 * @copydoc Dali::Internal::ProxyObject::Observer::SceneObjectAdded()
136 virtual void SceneObjectRemoved(ProxyObject& proxy) {}
139 * @copydoc Dali::Internal::ProxyObject::Observer::ProxyDestroyed()
141 virtual void ProxyDestroyed(ProxyObject& proxy);
144 * For use in derived classes, called after an actor is attached.
145 * @param[in] actor The actor that is being attached.
147 virtual void OnActorAttach(Actor& actor) = 0;
150 * For use in derived classes, called after an actor is detached.
151 * @param[in] actor The actor that is being detached.
153 virtual void OnActorDetach(Actor& actor) = 0;
156 * For use in derived classes, called when an attached actor is destroyed.
157 * @param[in] object The object (Actor's base class) that has been destroyed.
158 * @note Derived classes should not call any Actor specific APIs in this method as the Actor's
159 * destructor would have already been called.
161 virtual void OnActorDestroyed(Object& object) = 0;
164 * Dummy touch event handler. We do not need to know when touch happens on our actor. We just
165 * need to connect a function so that our attached actor is checked during our hit testing.
166 * @param[in] actor The hit actor (or one of its parents).
167 * @param[in] event The touch event.
168 * @return false always as we do not process the event.
170 bool OnTouchEvent(Dali::Actor actor, const TouchEvent& event);
172 private: // Default property extensions from ProxyObject
175 * @copydoc Dali::Internal::ProxyObject::IsSceneObjectRemovable()
177 virtual bool IsSceneObjectRemovable() const;
180 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyCount()
182 virtual unsigned int GetDefaultPropertyCount() const;
185 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
187 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
190 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
192 virtual const std::string& GetDefaultPropertyName(Property::Index index) const;
195 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
197 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
200 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyWritable()
202 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
205 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAnimatable()
207 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
210 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAConstraintInput()
212 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
215 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
217 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
220 * @copydoc Dali::Internal::ProxyObject::SetDefaultProperty()
222 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
225 * @copydoc Dali::Internal::ProxyObject::SetCustomProperty()
227 virtual void SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value );
230 * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
232 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
235 * @copydoc Dali::Internal::ProxyObject::InstallSceneObjectProperty()
237 virtual void InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index );
240 * @copydoc Dali::Internal::ProxyObject::GetSceneObject()
242 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
245 * @copydoc Dali::Internal::ProxyObject::GetSceneObjectAnimatableProperty()
247 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
250 * @copydoc Dali::Internal::ProxyObject::GetSceneObjectInputProperty()
252 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
256 Gesture::Type mType; ///< The gesture detector will detect this type of gesture.
257 GestureDetectorActorContainer mAttachedActors; ///< Proxy<Node>::Observer is used to provide weak-pointer behaviour
258 GestureEventProcessor& mGestureEventProcessor; ///< A reference to the gesture event processor.
262 SlotDelegate< GestureDetector > mSlotDelegate;
265 } // namespace Internal
267 // Helpers for public-api forwarding methods
269 inline Internal::GestureDetector& GetImplementation(Dali::GestureDetector& detector)
271 DALI_ASSERT_ALWAYS( detector && "GestureDetector handle is empty" );
273 BaseObject& handle = detector.GetBaseObject();
275 return static_cast<Internal::GestureDetector&>(handle);
278 inline const Internal::GestureDetector& GetImplementation(const Dali::GestureDetector& detector)
280 DALI_ASSERT_ALWAYS( detector && "GestureDetector handle is empty" );
282 const BaseObject& handle = detector.GetBaseObject();
284 return static_cast<const Internal::GestureDetector&>(handle);
289 #endif // __DALI_INTERNAL_GESTURE_DETECTOR_H__