[NUI] Binding GetDeviceClass and GetDeviceSubclass of touch event
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Events / Touch.cs
1 /*
2  * Copyright(c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 using System.ComponentModel;
18 using Tizen.NUI.BaseComponents;
19
20 namespace Tizen.NUI
21 {
22     /// <summary>
23     /// Touch events are a collection of points at a specific moment in time.<br />
24     /// When a multi-touch event occurs, each point represents the points that are currently being
25     /// touched or the points where a touch has stopped.<br />
26     /// </summary>
27     /// <since_tizen> 3 </since_tizen>
28     public class Touch : BaseHandle
29     {
30         /// <summary>
31         /// An uninitialized touch instance.<br />
32         /// Calling member functions with an uninitialized touch handle is not allowed.<br />
33         /// </summary>
34         /// <since_tizen> 3 </since_tizen>
35         public Touch() : this(Interop.Touch.NewTouch(), true)
36         {
37             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
38         }
39
40         internal Touch(Touch other) : this(Interop.Touch.NewTouch(Touch.getCPtr(other)), true)
41         {
42             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
43         }
44
45         internal Touch(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.Touch.Upcast(cPtr), cMemoryOwn)
46         {
47         }
48
49         /// <summary>
50         /// Returns the time (in ms) that the touch event occurred.
51         /// </summary>
52         /// <returns>The time (in ms) that the touch event occurred.</returns>
53         /// <since_tizen> 3 </since_tizen>
54         public uint GetTime()
55         {
56             uint ret = Interop.Touch.GetTime(SwigCPtr);
57             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
58             return ret;
59         }
60
61         /// <summary>
62         /// Returns the total number of points in this TouchData.
63         /// Point means the touched point.
64         /// If there is one touch point, the point index is 0.
65         /// If there are two touch points, the point index has 0 and 1.
66         /// </summary>
67         /// <returns>The total number of points.</returns>
68         /// <since_tizen> 3 </since_tizen>
69         public uint GetPointCount()
70         {
71             uint ret = Interop.Touch.GetPointCount(SwigCPtr);
72             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
73             return ret;
74         }
75
76         /// <summary>
77         /// Returns the ID of the device used for the point specified.<br />
78         /// Each point has a unique device ID, which specifies the device used for that
79         /// point. This is returned by this method.<br />
80         /// If a point is greater than GetPointCount(), then this method will return -1.<br />
81         /// </summary>
82         /// <param name="point">The index of a touch point</param>
83         /// <returns>The device ID of this point.</returns>
84         /// <since_tizen> 3 </since_tizen>
85         public int GetDeviceId(uint point)
86         {
87             int ret = Interop.Touch.GetDeviceId(SwigCPtr, point);
88             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
89             return ret;
90         }
91
92         /// <summary>
93         /// Retrieves the state of the point specified.<br />
94         /// If a point is greater than GetPointCount(), then this method will return PointState.Finished.<br />
95         /// </summary>
96         /// <param name="point">The index of a touch point.</param>
97         /// <returns>The state of the point specified.</returns>
98         /// <since_tizen> 3 </since_tizen>
99         public PointStateType GetState(uint point)
100         {
101             PointStateType ret = (PointStateType)Interop.Touch.GetState(SwigCPtr, point);
102             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
103             return ret;
104         }
105
106         /// <summary>
107         /// Retrieves the view that was underneath the point specified.<br />
108         /// If a point is greater than GetPointCount(), then this method will return an empty handle.<br />
109         /// </summary>
110         /// <param name="point">The index of a touch point.</param>
111         /// <returns>The view that was underneath the point specified.</returns>
112         /// <since_tizen> 3 </since_tizen>
113         public View GetHitView(uint point)
114         {
115             //to fix memory leak issue, match the handle count with native side.
116             global::System.IntPtr cPtr = Interop.Touch.GetHitActor(SwigCPtr, point);
117             View ret = this.GetInstanceSafely<View>(cPtr);
118             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
119             return ret;
120         }
121
122         /// <summary>
123         /// Retrieves the coordinates relative to the top-left of the hit view at the point specified.<br />
124         /// The top-left of an view is (0.0, 0.0, 0.5).<br />
125         /// If you require the local coordinates of another view (for example, the parent of the hit view),
126         /// then you should use ScreenToLocal().<br />
127         /// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.<br />
128         /// </summary>
129         /// <param name="point">The index of a touch point.</param>
130         /// <returns>The coordinates relative to the top-left of the hit view of the point specified.</returns>
131         /// <since_tizen> 3 </since_tizen>
132         public Vector2 GetLocalPosition(uint point)
133         {
134             Vector2 ret = new Vector2(Interop.Touch.GetLocalPosition(SwigCPtr, point), false);
135             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
136             return ret;
137         }
138
139         /// <summary>
140         /// Retrieves the coordinates relative to the top-left of the screen of the point specified.<br />
141         /// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.<br />
142         /// </summary>
143         /// <param name="point">The index of a touch point.</param>
144         /// <returns>The coordinates relative to the top-left of the screen of the point specified.</returns>
145         /// <since_tizen> 3 </since_tizen>
146         public Vector2 GetScreenPosition(uint point)
147         {
148             Vector2 ret = new Vector2(Interop.Touch.GetScreenPosition(SwigCPtr, point), false);
149             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
150             return ret;
151         }
152
153         /// <summary>
154         /// Retrieves the radius of the press point.<br />
155         /// This is the average of both the horizontal and vertical radii of the press point.<br />
156         /// If point is greater than GetPointCount(), then this method will return 0.0f.<br />
157         /// </summary>
158         /// <param name="point">The index of a touch point.</param>
159         /// <returns>The radius of the press point.</returns>
160         /// <since_tizen> 3 </since_tizen>
161         public float GetRadius(uint point)
162         {
163             float ret = Interop.Touch.GetRadius(SwigCPtr, point);
164             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
165             return ret;
166         }
167
168         /// <summary>
169         /// Retrieves both the horizontal and the vertical radii of the press point.<br />
170         /// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.<br />
171         /// </summary>
172         /// <param name="point">The index of a touch point.</param>
173         /// <returns>The horizontal and vertical radii of the press point.</returns>
174         /// <since_tizen> 3 </since_tizen>
175         public Vector2 GetEllipseRadius(uint point)
176         {
177             Vector2 ret = new Vector2(Interop.Touch.GetEllipseRadius(SwigCPtr, point), false);
178             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
179             return ret;
180         }
181
182         /// <summary>
183         /// Retrieves the touch pressure.<br />
184         /// The pressure range starts at 0.0f.<br />
185         /// Normal pressure is defined as 1.0f.<br />
186         /// A value between 0.0f and 1.0f means light pressure has been applied.<br />
187         /// A value greater than 1.0f means more pressure than normal has been applied.<br />
188         /// If point is greater than GetPointCount(), then this method will return 1.0f.<br />
189         /// </summary>
190         /// <param name="point">The index of a touch point.</param>
191         /// <returns>The touch pressure.</returns>
192         /// <since_tizen> 3 </since_tizen>
193         public float GetPressure(uint point)
194         {
195             float ret = Interop.Touch.GetPressure(SwigCPtr, point);
196             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
197             return ret;
198         }
199
200         /// <summary>
201         /// Get mouse device's button value (for example, right or left button)
202         /// </summary>
203         /// <param name="point">The index of a touch point.</param>
204         /// <returns></returns>
205         /// <since_tizen> 5 </since_tizen>
206         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
207         [EditorBrowsable(EditorBrowsableState.Never)]
208         public MouseButton GetMouseButton(uint point)
209         {
210             int ret = Interop.Touch.GetMouseButton(SwigCPtr, point);
211             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
212             return (MouseButton)ret;
213         }
214
215         /// <summary>
216         /// Gets the device class type from which the mouse/touch event is originated.
217         /// </summary>
218         /// <param name="point">The index of a touch point.</param>
219         [EditorBrowsable(EditorBrowsableState.Never)]
220         public DeviceClassType GetDeviceClass(uint point)
221         {
222             int ret = Interop.Touch.GetDeviceClass(SwigCPtr, point);
223             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
224             return (DeviceClassType)ret;
225         }
226
227         /// <summary>
228         /// Gets the subclass type of the device from which the mouse/touch event is originated.
229         /// </summary>
230         /// <param name="point">The index of a touch point.</param>
231         [EditorBrowsable(EditorBrowsableState.Never)]
232         public DeviceSubClassType GetDeviceSubClass(uint point)
233         {
234             int ret = Interop.Touch.GetDeviceSubClass(SwigCPtr, point);
235             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
236             return (DeviceSubClassType)ret;
237         }
238
239
240         internal static Touch GetTouchFromPtr(global::System.IntPtr cPtr)
241         {
242             Touch ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Touch;
243             if (ret == null)
244             {
245                 ret = new Touch(cPtr, false);
246             }
247
248             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
249             return ret;
250         }
251
252         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
253         [EditorBrowsable(EditorBrowsableState.Never)]
254         public Degree GetAngle(uint point)
255         {
256             Degree ret = new Degree(Interop.Touch.GetAngle(SwigCPtr, point), true);
257             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
258             return ret;
259         }
260
261         /// This will not be public opened.
262         [EditorBrowsable(EditorBrowsableState.Never)]
263         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
264         {
265             Interop.Touch.DeleteTouch(swigCPtr);
266         }
267     }
268
269     /// <summary>
270     /// Mouse device button type.
271     /// </summary>
272     /// <since_tizen> 5 </since_tizen>
273     /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
274     [EditorBrowsable(EditorBrowsableState.Never)]
275     public enum MouseButton
276     {
277         /// <summary>
278         /// No mouse button event or invalid data.
279         /// </summary>
280         /// <since_tizen> 5 </since_tizen>
281         Invalid = -1,
282         /// <summary>
283         /// Primary(Left) mouse button.
284         /// </summary>
285         /// <since_tizen> 5 </since_tizen>
286         Primary = 1,
287         /// <summary>
288         /// Secondary(Right) mouse button.
289         /// </summary>
290         /// <since_tizen> 5 </since_tizen>
291         Secondary = 3,
292         /// <summary>
293         /// Center(Wheel) mouse button.
294         /// </summary>
295         /// <since_tizen> 5 </since_tizen>
296         Tertiary = 2,
297     }
298 }