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/internal/event/events/actor-observer.h>
24 #include <dali/internal/event/events/gesture-event.h>
25 #include <dali/internal/event/events/gesture-recognizer.h>
26 #include <dali/internal/event/render-tasks/render-task-impl.h>
27 #include <dali/public-api/common/dali-common.h>
28 #include <dali/public-api/common/vector-wrapper.h>
29 #include <dali/public-api/events/gesture-detector.h>
30 #include <dali/public-api/events/gesture.h>
31 #include <dali/public-api/signals/slot-delegate.h>
42 class GestureDetector;
43 class GestureEventProcessor;
45 using GestureDetectorPtr = IntrusivePtr<GestureDetector>;
46 using GestureDetectorContainer = std::vector<GestureDetector*>;
47 using GestureDetectorActorContainer = std::vector<Actor*>;
48 using GestureRecognizerPtr = IntrusivePtr<GestureRecognizer>;
51 * This is a type trait that should be used by deriving gesture detectors for their container type.
53 template<typename Detector>
54 struct DerivedGestureDetectorContainer
56 using type = std::vector<Detector*>;
60 * @copydoc Dali::GestureDetector
62 class GestureDetector : public Object, public Object::Observer, public ConnectionTracker
66 * @copydoc Dali::GestureDetector::Attach()
68 void Attach(Actor& actor);
71 * @copydoc Dali::GestureDetector::Detach()
73 void Detach(Actor& actor);
76 * @copydoc Dali::GestureDetector::DetachAll()
81 * @copydoc Dali::GestureDetector::GetAttachedActorCount() const
83 size_t GetAttachedActorCount() const;
86 * @copydoc Dali::GestureDetector::GetAttachedActor() const
88 Dali::Actor GetAttachedActor(size_t index) const;
91 * @copydoc Dali::GestureDetector::HandleEvent()
93 bool HandleEvent(Dali::Actor& actor, Dali::TouchEvent& touch);
96 * Returns a const reference to the container of attached actor pointers.
97 * @return A const reference to the attached internal actors.
99 const GestureDetectorActorContainer& GetAttachedActorPointers() const
101 return mAttachedActors;
105 * Retrieves the type of GestureDetector
106 * @return The GestureDetector Type
108 GestureType::Value GetType() const
114 * Checks if the specified actor is still attached or pending attachment.
115 * @param[in] actor The actor to check.
116 * @return true, if the actor is attached or pending, false otherwise.
118 bool IsAttached(Actor& actor) const;
121 * @brief This method that cancels all other gesture detectors except the current gesture detector
123 void CancelAllOtherGestureDetectors();
126 * @brief Returns whether the gesture was detected.
127 * @return true, if the gesture was detected, false otherwise.
129 bool IsDetected() const;
132 * @brief Sets whether the gesture was detected.
133 * @param detected Whether gesture detected.
135 void SetDetected(bool detected);
138 * gesture-detector meets the parameters of the current gesture.
140 * @param[in] gestureEvent The gesture event.
141 * @param[in] actor The actor that has been gestured.
142 * @param[in] renderTask The renderTask.
144 * @return true, if the detector meets the parameters, false otherwise.
146 virtual bool CheckGestureDetector(const GestureEvent* gestureEvent, Actor* actor, RenderTaskPtr renderTask) = 0;
149 * @brief This is canceling the ongoing gesture recognition process.
151 virtual void CancelProcessing() = 0;
153 protected: // Creation & Destruction
155 * Construct a new GestureDetector.
156 * @param type the type of gesture
157 * @param pointer to the scene object, nullptr if none
158 * by default GestureDetectors don't have our own scene object
160 GestureDetector(GestureType::Value type, const SceneGraph::PropertyOwner* sceneObject = nullptr);
163 * A reference counted object may only be deleted by calling Unreference()
165 ~GestureDetector() override;
169 GestureDetector() = delete;
170 GestureDetector(const GestureDetector&) = delete;
171 GestureDetector& operator=(const GestureDetector& rhs) = delete;
174 * @copydoc Dali::Internal::Object::Observer::SceneObjectAdded()
176 void SceneObjectAdded(Object& object) override;
179 * @copydoc Dali::Internal::Object::Observer::SceneObjectAdded()
181 void SceneObjectRemoved(Object& object) override
186 * @copydoc Dali::Internal::Object::Observer::ObjectDestroyed()
188 void ObjectDestroyed(Object& object) override;
191 * For use in derived classes, called after an actor is attached.
192 * @param[in] actor The actor that is being attached.
194 virtual void OnActorAttach(Actor& actor) = 0;
197 * For use in derived classes, called after an actor is detached.
198 * @param[in] actor The actor that is being detached.
200 virtual void OnActorDetach(Actor& actor) = 0;
203 * For use in derived classes, called when an attached actor is destroyed.
204 * @param[in] object The object (Actor's base class) that has been destroyed.
205 * @note Derived classes should not call any Actor specific APIs in this method as the Actor's
206 * destructor would have already been called.
208 virtual void OnActorDestroyed(Object& object) = 0;
211 * @brief Callback for TouchedSignal signal
213 * @param actor The actor
214 * @param touch The touch event that has occurred
216 virtual bool OnTouchEvent(Dali::Actor actor, const Dali::TouchEvent& touch) = 0;
219 * @brief Delivers touch events to each detector.
220 * This is an API that is called by FeedTouch and recognizes gestures directly from the Detector without going through the Reconizer.
222 * @param scene The scene
223 * @param event The touch event that has occurred
225 virtual void ProcessTouchEvent(Scene& scene, const Integration::TouchEvent& event) = 0;
228 * @brief Clears the detector.
233 GestureType::Value mType; ///< The gesture detector will detect this type of gesture.
234 GestureDetectorActorContainer mAttachedActors; ///< Object::Observer is used to provide weak-pointer behaviour
235 GestureDetectorActorContainer mPendingAttachActors; ///< Object::Observer is used to provide weak-pointer behaviour
236 GestureEventProcessor& mGestureEventProcessor; ///< A reference to the gesture event processor.
237 ActorObserver mFeededActor; ///< The Actor that feeds touch events
238 RenderTaskPtr mRenderTask; ///< The render task used to generate this touch event.
239 GestureRecognizerPtr mGestureRecognizer; ///< The gesture recognizer
240 bool mIsDetected : 1; ///< Whether gesture detected.
243 } // namespace Internal
245 // Helpers for public-api forwarding methods
247 inline Internal::GestureDetector& GetImplementation(Dali::GestureDetector& detector)
249 DALI_ASSERT_ALWAYS(detector && "GestureDetector handle is empty");
251 BaseObject& handle = detector.GetBaseObject();
253 return static_cast<Internal::GestureDetector&>(handle);
256 inline const Internal::GestureDetector& GetImplementation(const Dali::GestureDetector& detector)
258 DALI_ASSERT_ALWAYS(detector && "GestureDetector handle is empty");
260 const BaseObject& handle = detector.GetBaseObject();
262 return static_cast<const Internal::GestureDetector&>(handle);
267 #endif // DALI_INTERNAL_GESTURE_DETECTOR_H