1 #ifndef DALI_INTERNAL_GESTURE_RECOGNIZER_H
2 #define DALI_INTERNAL_GESTURE_RECOGNIZER_H
5 * Copyright (c) 2023 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/integration-api/events/touch-event-integ.h>
23 #include <dali/internal/event/events/actor-observer.h>
24 #include <dali/internal/event/events/gesture-event.h>
25 #include <dali/internal/event/render-tasks/render-task-impl.h>
26 #include <dali/public-api/common/vector-wrapper.h>
27 #include <dali/public-api/events/gesture.h>
28 #include <dali/public-api/math/vector2.h>
29 #include <dali/public-api/object/ref-object.h>
40 struct GestureRequest;
44 class RecognizerObserver
47 virtual void Process(Scene& scene, const T& event, Actor* actor = nullptr) = 0;
49 virtual ~RecognizerObserver() = default;
54 * Abstract Base class for all adaptor gesture detectors.
56 * @note this may be replaced by gesture events sent directly from X.
58 class GestureRecognizer : public RefObject
62 * Called when it gets a touch event. The gesture recognizer should
63 * evaluate this event along with previously received events to determine
64 * whether the gesture they require has taken place.
65 * @param[in] event The latest touch event.
67 virtual void SendEvent(const Integration::TouchEvent& event) = 0;
70 * Called when Core updates the gesture's detection requirements.
71 * @param[in] request The updated detection requirements.
73 virtual void Update(const GestureRequest& request) = 0;
76 * Returns the type of gesture detector.
77 * @return Type of gesture detector.
79 GestureType::Value GetType() const
85 * Called when we get a touch event.
86 * @param[in] scene The scene the touch event has occurred on
87 * @param[in] event The latest touch event
89 void SendEvent(Scene& scene, const Integration::TouchEvent& event)
92 if(event.GetPointCount() > 0)
94 const Integration::Point& point = event.points[0];
95 MouseButton::Type mouseButton = point.GetMouseButton();
96 if(mouseButton != MouseButton::INVALID)
98 Device::Class::Type type = point.GetDeviceClass();
99 if(type == Device::Class::Type::MOUSE)
101 mSourceType = GestureSourceType::MOUSE;
103 else if(type == Device::Class::Type::TOUCH)
105 mSourceType = GestureSourceType::TOUCH;
109 case MouseButton::PRIMARY:
111 mSourceData = GestureSourceData::MOUSE_PRIMARY;
114 case MouseButton::SECONDARY:
116 mSourceData = GestureSourceData::MOUSE_SECONDARY;
119 case MouseButton::TERTIARY:
121 mSourceData = GestureSourceData::MOUSE_TERTIARY;
126 mSourceData = GestureSourceData::INVALID;
136 * Called when we get a touch event.
137 * @param[in] actor The actor the touch event has occurred on
138 * @param[in] renderTask The renderTask the touch event has occurred on
139 * @param[in] scene The scene the touch event has occurred on
140 * @param[in] event The latest touch event
142 void SendEvent(Actor& actor, Dali::Internal::RenderTask& renderTask, Scene& scene, const Integration::TouchEvent& event)
144 mActor.SetActor(&actor);
145 mRenderTask = &renderTask;
146 SendEvent(scene, event);
151 * Protected Constructor. Should only be able to create derived class objects.
152 * @param[in] screenSize The size of the screen.
153 * @param[in] detectorType The type of gesture detector.
155 GestureRecognizer(Vector2 screenSize, GestureType::Value detectorType)
156 : mScreenSize(screenSize),
159 mSourceType(GestureSourceType::INVALID),
160 mSourceData(GestureSourceData::INVALID),
167 * Protected Constructor. Should only be able to create derived class objects.
169 * Use this constructor with the screen size is not used in the dereived class.
170 * @param[in] detectorType The type of gesture detector.
172 GestureRecognizer(GestureType::Value detectorType)
173 : GestureRecognizer(Vector2::ZERO, detectorType)
178 * Virtual destructor.
180 ~GestureRecognizer() override = default;
184 GestureType::Value mType;
186 GestureSourceType mSourceType; /// < Gesture input source type.
187 GestureSourceData mSourceData; /// < Gesture input source data.
188 ActorObserver mActor; /// < The actor used to generate this touch event.
189 RenderTaskPtr mRenderTask; /// < The render task used to generate this touch event.
192 using GestureRecognizerPtr = IntrusivePtr<GestureRecognizer>;
194 } // namespace Internal
198 #endif // DALI_INTERNAL_GESTURE_RECOGNIZER_H