1 #ifndef DALI_INTERNAL_GESTURE_DETECTOR_H
2 #define DALI_INTERNAL_GESTURE_DETECTOR_H
5 * Copyright (c) 2021 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/actors/actor-impl.h>
23 #include <dali/public-api/common/dali-common.h>
24 #include <dali/public-api/common/vector-wrapper.h>
25 #include <dali/public-api/events/gesture-detector.h>
26 #include <dali/public-api/events/gesture.h>
27 #include <dali/public-api/signals/slot-delegate.h>
38 class GestureDetector;
39 class GestureEventProcessor;
41 using GestureDetectorPtr = IntrusivePtr<GestureDetector>;
42 using GestureDetectorContainer = std::vector<GestureDetector*>;
43 using GestureDetectorActorContainer = std::vector<Actor*>;
46 * This is a type trait that should be used by deriving gesture detectors for their container type.
48 template<typename Detector>
49 struct DerivedGestureDetectorContainer
51 using type = std::vector<Detector*>;
55 * @copydoc Dali::GestureDetector
57 class GestureDetector : public Object, public Object::Observer
61 * @copydoc Dali::GestureDetector::Attach()
63 void Attach(Actor& actor);
66 * @copydoc Dali::GestureDetector::Detach()
68 void Detach(Actor& actor);
71 * @copydoc Dali::GestureDetector::DetachAll()
76 * @copydoc Dali::GestureDetector::GetAttachedActorCount() const
78 size_t GetAttachedActorCount() const;
81 * @copydoc Dali::GestureDetector::GetAttachedActor() const
83 Dali::Actor GetAttachedActor(size_t index) const;
86 * @copydoc Dali::GestureDetector::FeedTouch()
88 bool FeedTouch(Dali::Actor& actor, Dali::TouchEvent& touch);
91 * Returns a const reference to the container of attached actor pointers.
92 * @return A const reference to the attached internal actors.
94 const GestureDetectorActorContainer& GetAttachedActorPointers() const
96 return mAttachedActors;
100 * Retrieves the type of GestureDetector
101 * @return The GestureDetector Type
103 GestureType::Value GetType() const
109 * Checks if the specified actor is still attached or pending attachment.
110 * @param[in] actor The actor to check.
111 * @return true, if the actor is attached or pending, false otherwise.
113 bool IsAttached(Actor& actor) const;
115 protected: // Creation & Destruction
117 * Construct a new GestureDetector.
118 * @param type the type of gesture
119 * @param pointer to the scene object, nullptr if none
120 * by default GestureDetectors don't have our own scene object
122 GestureDetector(GestureType::Value type, const SceneGraph::PropertyOwner* sceneObject = nullptr);
125 * A reference counted object may only be deleted by calling Unreference()
127 ~GestureDetector() override;
131 GestureDetector() = delete;
132 GestureDetector(const GestureDetector&) = delete;
133 GestureDetector& operator=(const GestureDetector& rhs) = delete;
136 * @copydoc Dali::Internal::Object::Observer::SceneObjectAdded()
138 void SceneObjectAdded(Object& object) override;
141 * @copydoc Dali::Internal::Object::Observer::SceneObjectAdded()
143 void SceneObjectRemoved(Object& object) override
148 * @copydoc Dali::Internal::Object::Observer::ObjectDestroyed()
150 void ObjectDestroyed(Object& object) override;
153 * For use in derived classes, called after an actor is attached.
154 * @param[in] actor The actor that is being attached.
156 virtual void OnActorAttach(Actor& actor) = 0;
159 * For use in derived classes, called after an actor is detached.
160 * @param[in] actor The actor that is being detached.
162 virtual void OnActorDetach(Actor& actor) = 0;
165 * For use in derived classes, called when an attached actor is destroyed.
166 * @param[in] object The object (Actor's base class) that has been destroyed.
167 * @note Derived classes should not call any Actor specific APIs in this method as the Actor's
168 * destructor would have already been called.
170 virtual void OnActorDestroyed(Object& object) = 0;
173 GestureType::Value mType; ///< The gesture detector will detect this type of gesture.
174 GestureDetectorActorContainer mAttachedActors; ///< Object::Observer is used to provide weak-pointer behaviour
175 GestureDetectorActorContainer mPendingAttachActors; ///< Object::Observer is used to provide weak-pointer behaviour
176 GestureEventProcessor& mGestureEventProcessor; ///< A reference to the gesture event processor.
179 } // namespace Internal
181 // Helpers for public-api forwarding methods
183 inline Internal::GestureDetector& GetImplementation(Dali::GestureDetector& detector)
185 DALI_ASSERT_ALWAYS(detector && "GestureDetector handle is empty");
187 BaseObject& handle = detector.GetBaseObject();
189 return static_cast<Internal::GestureDetector&>(handle);
192 inline const Internal::GestureDetector& GetImplementation(const Dali::GestureDetector& detector)
194 DALI_ASSERT_ALWAYS(detector && "GestureDetector handle is empty");
196 const BaseObject& handle = detector.GetBaseObject();
198 return static_cast<const Internal::GestureDetector&>(handle);
203 #endif // DALI_INTERNAL_GESTURE_DETECTOR_H