[dali_2.3.26] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / public-api / events / touch-event.h
1 #ifndef DALI_TOUCH_EVENT_H
2 #define DALI_TOUCH_EVENT_H
3
4 /*
5  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <stdint.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/common/dali-common.h>
26 #include <dali/public-api/events/device.h>
27 #include <dali/public-api/events/mouse-button.h>
28 #include <dali/public-api/events/point-state.h>
29 #include <dali/public-api/math/degree.h>
30 #include <dali/public-api/object/base-handle.h>
31 #include <dali/public-api/render-tasks/render-task.h>
32
33 namespace Dali
34 {
35 namespace Internal DALI_INTERNAL
36 {
37 class TouchEvent;
38 }
39
40 /**
41  * @addtogroup dali_core_events
42  * @{
43  */
44
45 class Actor;
46 struct Vector2;
47
48 /**
49  * @brief Touch events are a collection of points at a specific moment in time.
50  *
51  * When a multi-touch event occurs, each point represents the points that are currently being
52  * touched or the points where a touch has stopped.
53  *
54  * The first point is the primary point that's used for hit-testing.
55  * @SINCE_1_9.26
56  * @note As this is a handle to an internal object, it should not be copied (or used in a container) as all that will do is copy the handle to the same object.
57  * The internal object can change which may not be what an application writer expects.
58  * If data does need to be stored in the application, then only the required data should be saved (retrieved using the methods of this class).
59  *
60  * Should not use this in a TouchEvent container as it is just a handle and the internal object can change.
61  */
62 class DALI_CORE_API TouchEvent : public BaseHandle
63 {
64 public:
65   // Construction & Destruction
66
67   /**
68    * @brief An uninitialized TouchEvent instance.
69    *
70    * Calling member functions with an uninitialized TouchEvent handle is not allowed.
71    * @SINCE_1_9.26
72    */
73   TouchEvent();
74
75   /**
76    * @brief Copy constructor.
77    *
78    * @SINCE_1_9.26
79    * @param[in] other The TouchEvent to copy from
80    */
81   TouchEvent(const TouchEvent& other);
82
83   /**
84    * @brief Move constructor.
85    *
86    * @SINCE_1_9.28
87    * @param[in] other The TouchEvent to move
88    */
89   TouchEvent(TouchEvent&& other) noexcept;
90
91   /**
92    * @brief Destructor.
93    *
94    * @SINCE_1_9.26
95    */
96   ~TouchEvent();
97
98   // Operators
99
100   /**
101    * @brief Assignment Operator.
102    *
103    * @SINCE_1_9.26
104    * @param[in] other The TouchEvent to copy from
105    * @return A reference to this
106    */
107   TouchEvent& operator=(const TouchEvent& other);
108
109   /**
110    * @brief Move assignment Operator.
111    *
112    * @SINCE_1_9.28
113    * @param[in] other The TouchEvent to move
114    * @return A reference to this
115    */
116   TouchEvent& operator=(TouchEvent&& other) noexcept;
117
118   // Getters
119
120   /**
121    * @brief Returns the time (in ms) that the touch event occurred.
122    *
123    * @SINCE_1_9.26
124    * @return The time (in ms) that the touch event occurred
125    */
126   unsigned long GetTime() const;
127
128   /**
129    * @brief Returns the total number of points in this TouchEvent.
130    *
131    * @SINCE_1_9.26
132    * @return Total number of Points
133    */
134   std::size_t GetPointCount() const;
135
136   /**
137    * @brief Returns the ID of the device used for the Point specified.
138    *
139    * Each point has a unique device ID which specifies the device used for that
140    * point. This is returned by this method.
141    *
142    * @SINCE_1_9.26
143    * @param[in] point The point required
144    * @return The Device ID of this point
145    * @note If point is greater than GetPointCount() then this method will return -1.
146    */
147   int32_t GetDeviceId(std::size_t point) const;
148
149   /**
150    * @brief Retrieves the State of the point specified.
151    *
152    * @SINCE_1_9.26
153    * @param[in] point The point required
154    * @return The state of the point specified
155    * @note If point is greater than GetPointCount() then this method will return PointState::FINISHED.
156    * @see State
157    */
158   PointState::Type GetState(std::size_t point) const;
159
160   /**
161    * @brief Retrieves the actor that was underneath the point specified.
162    *
163    * @SINCE_1_9.26
164    * @param[in] point The point required
165    * @return The actor that was underneath the point specified
166    * @note If point is greater than GetPointCount() then this method will return an empty handle.
167    */
168   Actor GetHitActor(std::size_t point) const;
169
170   /**
171    * @brief Retrieves the co-ordinates relative to the top-left of the hit-actor at the point specified.
172    *
173    * @SINCE_1_9.26
174    * @param[in] point The point required
175    * @return The co-ordinates relative to the top-left of the hit-actor of the point specified
176    *
177    * @note The top-left of an actor is (0.0, 0.0, 0.5).
178    * @note If you require the local coordinates of another actor (e.g the parent of the hit actor),
179    * then you should use Actor::ScreenToLocal().
180    * @note If point is greater than GetPointCount() then this method will return Vector2::ZERO.
181    */
182   const Vector2& GetLocalPosition(std::size_t point) const;
183
184   /**
185    * @brief Retrieves the co-ordinates relative to the top-left of the screen of the point specified.
186    *
187    * @SINCE_1_9.26
188    * @param[in] point The point required
189    * @return The co-ordinates relative to the top-left of the screen of the point specified
190    * @note If point is greater than GetPointCount() then this method will return Vector2::ZERO.
191    */
192   const Vector2& GetScreenPosition(std::size_t point) const;
193
194   /**
195    * @brief Retrieves the radius of the press point.
196    *
197    * This is the average of both the horizontal and vertical radii of the press point.
198    *
199    * @SINCE_1_9.26
200    * @param[in] point The point required
201    * @return The radius of the press point
202    * @note If point is greater than GetPointCount() then this method will return 0.0f.
203    */
204   float GetRadius(std::size_t point) const;
205
206   /**
207    * @brief Retrieves BOTH the horizontal and the vertical radii of the press point.
208    *
209    * @SINCE_1_9.26
210    * @param[in] point The point required
211    * @return The horizontal and vertical radii of the press point
212    * @note If point is greater than GetPointCount() then this method will return Vector2::ZERO.
213    */
214   const Vector2& GetEllipseRadius(std::size_t point) const;
215
216   /**
217    * @brief Retrieves the touch pressure.
218    *
219    * The pressure range starts at 0.0f.
220    * Normal pressure is defined as 1.0f.
221    * A value between 0.0f and 1.0f means light pressure has been applied.
222    * A value greater than 1.0f means more pressure than normal has been applied.
223    *
224    * @SINCE_1_9.26
225    * @param[in] point The point required
226    * @return The touch pressure
227    * @note If point is greater than GetPointCount() then this method will return 1.0f.
228    */
229   float GetPressure(std::size_t point) const;
230
231   /**
232    * @brief Retrieves the angle of the press point relative to the Y-Axis.
233    *
234    * @SINCE_1_9.26
235    * @param[in] point The point required
236    * @return The angle of the press point
237    * @note If point is greater than GetPointCount() then this method will return Degree().
238    */
239   Degree GetAngle(std::size_t point) const;
240
241   /**
242    * @brief Gets the device class type from which the mouse/touch event is originated.
243    *
244    * The device class type is classification type of the input device of event received.
245    * @SINCE_1_9.26
246    * @param[in] point The point required
247    * @return The type of the device class
248    */
249   Device::Class::Type GetDeviceClass(std::size_t point) const;
250
251   /**
252    * @brief Gets the subclass type of the device from which the mouse/touch event is originated.
253    *
254    * The device subclass type is subclassification type of the input device of event received.
255    * @SINCE_1_9.26
256    * @param[in] point The point required
257    * @return The type of the device subclass
258    */
259   Device::Subclass::Type GetDeviceSubclass(std::size_t point) const;
260
261   /**
262    * @brief Gets the value, which indicates a mouse button. (ex: right/left button)
263    *
264    * @SINCE_1_9.26
265    * @param[in] point The point required
266    * @return The mouse button value
267    */
268   MouseButton::Type GetMouseButton(std::size_t point) const;
269
270   /**
271    * @brief Retrieves the render-task that was used to generate this touch-event.
272    *
273    * @SINCE_2_3.0
274    * @return The render-task used to generate this touch-event.
275    */
276   RenderTask GetRenderTask() const;
277
278 public: // Not intended for application developers
279   /// @cond internal
280   /**
281    * @brief This constructor is used internally to Create an initialized TouchEvent handle.
282    *
283    * @SINCE_1_9.26
284    * @param[in] internal A pointer to a newly allocated Dali resource
285    */
286   explicit DALI_INTERNAL TouchEvent(Internal::TouchEvent* internal);
287   /// @endcond
288 };
289
290 /**
291  * @}
292  */
293 } // namespace Dali
294
295 #endif // DALI_TOUCH_EVENT_H