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>
30 #include <dali/public-api/events/gesture-detector.h>
41 struct GestureRequest;
45 class RecognizerObserver
48 virtual void Process(Scene& scene, const T& event) = 0;
50 virtual ~RecognizerObserver() = default;
55 * Abstract Base class for all adaptor gesture detectors.
57 * @note this may be replaced by gesture events sent directly from X.
59 class GestureRecognizer : public RefObject
63 * Called when it gets a touch event. The gesture recognizer should
64 * evaluate this event along with previously received events to determine
65 * whether the gesture they require has taken place.
66 * @param[in] event The latest touch event.
68 virtual void SendEvent(const Integration::TouchEvent& event) = 0;
71 * Called when Core updates the gesture's detection requirements.
72 * @param[in] request The updated detection requirements.
74 virtual void Update(const GestureRequest& request) = 0;
77 * Returns the type of gesture detector.
78 * @return Type of gesture detector.
80 GestureType::Value GetType() const
86 * Called when we get a touch event.
87 * @param[in] scene The scene the touch event has occurred on
88 * @param[in] event The latest touch event
90 void SendEvent(Scene& scene, const Integration::TouchEvent& event)
93 if(event.GetPointCount() > 0)
95 const Integration::Point& point = event.points[0];
96 MouseButton::Type mouseButton = point.GetMouseButton();
97 if(mouseButton != MouseButton::INVALID)
99 Device::Class::Type type = point.GetDeviceClass();
100 if(type == Device::Class::Type::MOUSE)
102 mSourceType = GestureSourceType::MOUSE;
104 else if(type == Device::Class::Type::TOUCH)
106 mSourceType = GestureSourceType::TOUCH;
110 case MouseButton::PRIMARY:
112 mSourceData = GestureSourceData::MOUSE_PRIMARY;
115 case MouseButton::SECONDARY:
117 mSourceData = GestureSourceData::MOUSE_SECONDARY;
120 case MouseButton::TERTIARY:
122 mSourceData = GestureSourceData::MOUSE_TERTIARY;
127 mSourceData = GestureSourceData::INVALID;
138 * Protected Constructor. Should only be able to create derived class objects.
139 * @param[in] screenSize The size of the screen.
140 * @param[in] detectorType The type of gesture detector.
142 GestureRecognizer(Vector2 screenSize, GestureType::Value detectorType)
143 : mScreenSize(screenSize),
146 mSourceType(GestureSourceType::INVALID),
147 mSourceData(GestureSourceData::INVALID)
152 * Protected Constructor. Should only be able to create derived class objects.
154 * Use this constructor with the screen size is not used in the dereived class.
155 * @param[in] detectorType The type of gesture detector.
157 GestureRecognizer(GestureType::Value detectorType)
158 : GestureRecognizer(Vector2::ZERO, detectorType)
163 * Virtual destructor.
165 ~GestureRecognizer() override = default;
169 GestureType::Value mType;
171 GestureSourceType mSourceType; /// < Gesture input source type.
172 GestureSourceData mSourceData; /// < Gesture input source data.
175 using GestureRecognizerPtr = IntrusivePtr<GestureRecognizer>;
177 } // namespace Internal
181 #endif // DALI_INTERNAL_GESTURE_RECOGNIZER_H