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/gesture-event.h>
24 #include <dali/public-api/common/vector-wrapper.h>
25 #include <dali/public-api/events/gesture.h>
26 #include <dali/public-api/math/vector2.h>
27 #include <dali/public-api/object/ref-object.h>
38 struct GestureRequest;
42 class RecognizerObserver
45 virtual void Process(Scene& scene, const T& event) = 0;
47 virtual ~RecognizerObserver() = default;
52 * Abstract Base class for all adaptor gesture detectors.
54 * @note this may be replaced by gesture events sent directly from X.
56 class GestureRecognizer : public RefObject
60 * Called when it gets a touch event. The gesture recognizer should
61 * evaluate this event along with previously received events to determine
62 * whether the gesture they require has taken place.
63 * @param[in] event The latest touch event.
65 virtual void SendEvent(const Integration::TouchEvent& event) = 0;
68 * Called when Core updates the gesture's detection requirements.
69 * @param[in] request The updated detection requirements.
71 virtual void Update(const GestureRequest& request) = 0;
74 * Returns the type of gesture detector.
75 * @return Type of gesture detector.
77 GestureType::Value GetType() const
83 * Called when we get a touch event.
84 * @param[in] scene The scene the touch event has occurred on
85 * @param[in] event The latest touch event
87 void SendEvent(Scene& scene, const Integration::TouchEvent& event)
90 if(event.GetPointCount() > 0)
92 const Integration::Point& point = event.points[0];
93 MouseButton::Type mouseButton = point.GetMouseButton();
94 if(mouseButton != MouseButton::INVALID)
96 Device::Class::Type type = point.GetDeviceClass();
97 if(type == Device::Class::Type::MOUSE)
99 mSourceType = GestureSourceType::MOUSE;
101 else if(type == Device::Class::Type::TOUCH)
103 mSourceType = GestureSourceType::TOUCH;
107 case MouseButton::PRIMARY:
109 mSourceData = GestureSourceData::MOUSE_PRIMARY;
112 case MouseButton::SECONDARY:
114 mSourceData = GestureSourceData::MOUSE_SECONDARY;
117 case MouseButton::TERTIARY:
119 mSourceData = GestureSourceData::MOUSE_TERTIARY;
124 mSourceData = GestureSourceData::INVALID;
135 * Protected Constructor. Should only be able to create derived class objects.
136 * @param[in] screenSize The size of the screen.
137 * @param[in] detectorType The type of gesture detector.
139 GestureRecognizer(Vector2 screenSize, GestureType::Value detectorType)
140 : mScreenSize(screenSize),
143 mSourceType(GestureSourceType::INVALID),
144 mSourceData(GestureSourceData::INVALID)
149 * Protected Constructor. Should only be able to create derived class objects.
151 * Use this constructor with the screen size is not used in the dereived class.
152 * @param[in] detectorType The type of gesture detector.
154 GestureRecognizer(GestureType::Value detectorType)
155 : GestureRecognizer(Vector2::ZERO, detectorType)
160 * Virtual destructor.
162 ~GestureRecognizer() override = default;
166 GestureType::Value mType;
168 GestureSourceType mSourceType; /// < Gesture input source type.
169 GestureSourceData mSourceData; /// < Gesture input source data.
172 using GestureRecognizerPtr = IntrusivePtr<GestureRecognizer>;
174 } // namespace Internal
178 #endif // DALI_INTERNAL_GESTURE_RECOGNIZER_H