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