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