1 #ifndef DALI_INTERNAL_GESTURE_DETECTOR_H
2 #define DALI_INTERNAL_GESTURE_DETECTOR_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/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 Object, public Object::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::GetAttachedActorCount() const
81 size_t GetAttachedActorCount() const;
84 * @copydoc Dali::GestureDetector::GetAttachedActor() const
86 Dali::Actor GetAttachedActor(size_t index) const;
89 * Returns a const reference to the container of attached actor pointers.
90 * @return A const reference to the attached internal actors.
92 const GestureDetectorActorContainer& GetAttachedActorPointers() const
94 return mAttachedActors;
98 * Retrieves the type of GestureDetector
99 * @return The GestureDetector Type
101 DevelGesture::Type GetType() const
107 * Checks if the specified actor is still attached or pending attachment.
108 * @param[in] actor The actor to check.
109 * @return true, if the actor is attached or pending, false otherwise.
111 bool IsAttached(Actor& actor) const;
113 protected: // Creation & Destruction
116 * Construct a new GestureDetector.
117 * @param type the type of gesture
118 * @param pointer to the scene object, nullptr if none
119 * by default GestureDetectors don't have our own scene object
121 GestureDetector( DevelGesture::Type type, const SceneGraph::PropertyOwner* sceneObject = nullptr );
124 * @copydoc GestureDetector( DevelGesture::Type, const SceneGraph::PropertyOwner* )
126 GestureDetector( Gesture::Type type, const SceneGraph::PropertyOwner* sceneObject = nullptr );
129 * A reference counted object may only be deleted by calling Unreference()
131 virtual ~GestureDetector();
136 GestureDetector() = delete;
137 GestureDetector(const GestureDetector&) = delete;
138 GestureDetector& operator=(const GestureDetector& rhs) = delete;
141 * @copydoc Dali::Internal::Object::Observer::SceneObjectAdded()
143 virtual void SceneObjectAdded(Object& object);
146 * @copydoc Dali::Internal::Object::Observer::SceneObjectAdded()
148 virtual void SceneObjectRemoved(Object& object) {}
151 * @copydoc Dali::Internal::Object::Observer::ObjectDestroyed()
153 virtual void ObjectDestroyed(Object& object);
156 * For use in derived classes, called after an actor is attached.
157 * @param[in] actor The actor that is being attached.
159 virtual void OnActorAttach(Actor& actor) = 0;
162 * For use in derived classes, called after an actor is detached.
163 * @param[in] actor The actor that is being detached.
165 virtual void OnActorDetach(Actor& actor) = 0;
168 * For use in derived classes, called when an attached actor is destroyed.
169 * @param[in] object The object (Actor's base class) that has been destroyed.
170 * @note Derived classes should not call any Actor specific APIs in this method as the Actor's
171 * destructor would have already been called.
173 virtual void OnActorDestroyed(Object& object) = 0;
177 DevelGesture::Type mType; ///< The gesture detector will detect this type of gesture.
178 GestureDetectorActorContainer mAttachedActors; ///< Object::Observer is used to provide weak-pointer behaviour
179 GestureDetectorActorContainer mPendingAttachActors; ///< Object::Observer is used to provide weak-pointer behaviour
180 GestureEventProcessor& mGestureEventProcessor; ///< A reference to the gesture event processor.
183 } // namespace Internal
185 // Helpers for public-api forwarding methods
187 inline Internal::GestureDetector& GetImplementation(Dali::GestureDetector& detector)
189 DALI_ASSERT_ALWAYS( detector && "GestureDetector handle is empty" );
191 BaseObject& handle = detector.GetBaseObject();
193 return static_cast<Internal::GestureDetector&>(handle);
196 inline const Internal::GestureDetector& GetImplementation(const Dali::GestureDetector& detector)
198 DALI_ASSERT_ALWAYS( detector && "GestureDetector handle is empty" );
200 const BaseObject& handle = detector.GetBaseObject();
202 return static_cast<const Internal::GestureDetector&>(handle);
207 #endif // DALI_INTERNAL_GESTURE_DETECTOR_H