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