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