1 #ifndef DALI_INTERNAL_TOUCH_EVENT_H
2 #define DALI_INTERNAL_TOUCH_EVENT_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/point.h>
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <dali/public-api/events/point-state.h>
25 #include <dali/public-api/events/touch-event.h>
26 #include <dali/public-api/object/base-object.h>
27 #include <dali/public-api/render-tasks/render-task.h>
37 using TouchEventPtr = IntrusivePtr<TouchEvent>;
40 * @copydoc Dali::TouchEvent
42 class TouchEvent : public BaseObject
45 // Construction & Destruction
48 * @brief Default constructor
50 TouchEvent() = default;
54 * @param[in] time The time the event occurred
56 TouchEvent(unsigned long time)
62 * @brief Clones the TouchEvent object.
64 * Required because base class copy constructor is not implemented.
65 * @param[in] other The TouchEvent to clone from.
66 * @return A new TouchEvent object which has the same touch point data.
68 static TouchEventPtr Clone(const TouchEvent& other);
70 TouchEvent(const TouchEvent& other) = delete; ///< Deleted copy constructor.
71 TouchEvent(TouchEvent&& other) = delete; ///< Deleted move constructor.
72 TouchEvent& operator=(const TouchEvent& other) = delete; ///< Deleted copy assignment operator.
73 TouchEvent& operator=(TouchEvent&& other) = delete; ///< Deleted move assignment operator.
78 * @copydoc Dali::TouchEvent::GetTime()
80 inline unsigned long GetTime() const
86 * @copydoc Dali::TouchEvent::GetPointCount()
88 inline std::size_t GetPointCount() const
90 return mPoints.size();
94 * @copydoc Dali::TouchEvent::GetDeviceId()
96 int32_t GetDeviceId(std::size_t point) const;
99 * @copydoc Dali::TouchEvent::GetGetState()
101 PointState::Type GetState(std::size_t point) const;
104 * @copydoc Dali::TouchEvent::GetHitActor()
106 Dali::Actor GetHitActor(std::size_t point) const;
109 * @copydoc Dali::TouchEvent::GetLocalPosition()
111 const Vector2& GetLocalPosition(std::size_t point) const;
114 * @copydoc Dali::TouchEvent::GetScreenPosition()
116 const Vector2& GetScreenPosition(std::size_t point) const;
119 * @copydoc Dali::TouchEvent::GetRadius()
121 float GetRadius(std::size_t point) const;
124 * @copydoc Dali::TouchEvent::GetEllipseRadius()
126 const Vector2& GetEllipseRadius(std::size_t point) const;
129 * @copydoc Dali::TouchEvent::GetPressure()
131 float GetPressure(std::size_t point) const;
134 * @copydoc Dali::TouchEvent::GetAngle()
136 Degree GetAngle(std::size_t point) const;
139 * @brief Returns a const reference to a point at the index requested.
141 * The first point in the set is always the primary point (i.e. the first point touched in a multi-touch event).
143 * @param[in] point The index of the required Point.
144 * @return A const reference to the Point at the position requested
145 * @note point should be less than the value returned by GetPointCount(). Will assert if out of range.
147 const Integration::Point& GetPoint(std::size_t point) const;
150 * @brief Returns a reference to a point at the index requested.
152 * The first point in the set is always the primary point (i.e. the first point touched in a multi-touch event).
154 * @param[in] point The index of the required Point.
155 * @return A reference to the Point at the position requested
156 * @note point should be less than the value returned by GetPointCount(). Will assert if out of range.
158 Integration::Point& GetPoint(std::size_t point);
161 * @brief Get the device class the mouse/touch event originated from
163 * @return The device class
165 Device::Class::Type GetDeviceClass(std::size_t point) const;
168 * @brief Get the device subclass the mouse/touch event originated from
170 * @return The device subclass
172 Device::Subclass::Type GetDeviceSubclass(std::size_t point) const;
175 * @brief Get mouse's button value (ex: right/left button)
177 * @return The value of mouse button
179 MouseButton::Type GetMouseButton(std::size_t point) const;
181 Dali::RenderTask GetRenderTask() const
189 * @brief Adds a point to this touch event handler.
190 * @param[in] point The point to add to the touch event handler.
192 void AddPoint(const Integration::Point& point);
194 void SetRenderTask(Dali::RenderTask renderTask)
196 mRenderTask = renderTask;
201 * @brief Virtual Destructor
203 * A reference counted object may only be deleted by calling Unreference()
205 ~TouchEvent() override = default;
208 std::vector<Integration::Point> mPoints; ///< Container of the points for this touch event.
209 Dali::RenderTask mRenderTask; ///< The render task used to generate this touch event.
210 unsigned long mTime{0u}; ///< The time (in ms) that the touch event occurred.
213 } // namespace Internal
215 // Helpers for public-api forwarding methods
217 inline Internal::TouchEvent& GetImplementation(Dali::TouchEvent& touchEvent)
219 DALI_ASSERT_ALWAYS(touchEvent && "Touch Event handle is empty");
221 BaseObject& object = touchEvent.GetBaseObject();
223 return static_cast<Internal::TouchEvent&>(object);
226 inline const Internal::TouchEvent& GetImplementation(const Dali::TouchEvent& touchEvent)
228 DALI_ASSERT_ALWAYS(touchEvent && "Touch Event handle is empty");
230 const BaseObject& object = touchEvent.GetBaseObject();
232 return static_cast<const Internal::TouchEvent&>(object);
237 #endif // DALI_INTERNAL_TOUCH_EVENT_H