64e44067a9d96851c2aa3ce8f7b79f55aaf70ab0
[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         /// </summary>
64         /// <returns>The total number of points.</returns>
65         /// <since_tizen> 3 </since_tizen>
66         public uint GetPointCount()
67         {
68             uint ret = Interop.Touch.GetPointCount(SwigCPtr);
69             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
70             return ret;
71         }
72
73         /// <summary>
74         /// Returns the ID of the device used for the point specified.<br />
75         /// Each point has a unique device ID, which specifies the device used for that
76         /// point. This is returned by this method.<br />
77         /// If a point is greater than GetPointCount(), then this method will return -1.<br />
78         /// </summary>
79         /// <param name="point">The point required.</param>
80         /// <returns>The device ID of this point.</returns>
81         /// <since_tizen> 3 </since_tizen>
82         public int GetDeviceId(uint point)
83         {
84             int ret = Interop.Touch.GetDeviceId(SwigCPtr, point);
85             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
86             return ret;
87         }
88
89         /// <summary>
90         /// Retrieves the state of the point specified.<br />
91         /// If a point is greater than GetPointCount(), then this method will return PointState.Finished.<br />
92         /// </summary>
93         /// <param name="point">The point required.</param>
94         /// <returns>The state of the point specified.</returns>
95         /// <since_tizen> 3 </since_tizen>
96         public PointStateType GetState(uint point)
97         {
98             PointStateType ret = (PointStateType)Interop.Touch.GetState(SwigCPtr, point);
99             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
100             return ret;
101         }
102
103         /// <summary>
104         /// Retrieves the actor that was underneath the point specified.<br />
105         /// If a point is greater than GetPointCount(), then this method will return an empty handle.<br />
106         /// </summary>
107         /// <param name="point">The point required.</param>
108         /// <returns>The actor that was underneath the point specified.</returns>
109         /// <since_tizen> 3 </since_tizen>
110         public View GetHitView(uint point)
111         {
112             //to fix memory leak issue, match the handle count with native side.
113             global::System.IntPtr cPtr = Interop.Touch.GetHitActor(SwigCPtr, point);
114             View ret = this.GetInstanceSafely<View>(cPtr);
115             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
116             return ret;
117         }
118
119         /// <summary>
120         /// Retrieves the coordinates relative to the top-left of the hit actor at the point specified.<br />
121         /// The top-left of an actor is (0.0, 0.0, 0.5).<br />
122         /// If you require the local coordinates of another actor (for example, the parent of the hit actor),
123         /// then you should use Actor::ScreenToLocal().<br />
124         /// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.<br />
125         /// </summary>
126         /// <param name="point">The point required.</param>
127         /// <returns>The coordinates relative to the top-left of the hit actor of the point specified.</returns>
128         /// <since_tizen> 3 </since_tizen>
129         public Vector2 GetLocalPosition(uint point)
130         {
131             Vector2 ret = new Vector2(Interop.Touch.GetLocalPosition(SwigCPtr, point), false);
132             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
133             return ret;
134         }
135
136         /// <summary>
137         /// Retrieves the coordinates relative to the top-left of the screen of the point specified.<br />
138         /// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.<br />
139         /// </summary>
140         /// <param name="point">The point required.</param>
141         /// <returns>The coordinates relative to the top-left of the screen of the point specified.</returns>
142         /// <since_tizen> 3 </since_tizen>
143         public Vector2 GetScreenPosition(uint point)
144         {
145             Vector2 ret = new Vector2(Interop.Touch.GetScreenPosition(SwigCPtr, point), false);
146             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
147             return ret;
148         }
149
150         /// <summary>
151         /// Retrieves the radius of the press point.<br />
152         /// This is the average of both the horizontal and vertical radii of the press point.<br />
153         /// If point is greater than GetPointCount(), then this method will return 0.0f.<br />
154         /// </summary>
155         /// <param name="point">The point required.</param>
156         /// <returns>The radius of the press point.</returns>
157         /// <since_tizen> 3 </since_tizen>
158         public float GetRadius(uint point)
159         {
160             float ret = Interop.Touch.GetRadius(SwigCPtr, point);
161             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
162             return ret;
163         }
164
165         /// <summary>
166         /// Retrieves both the horizontal and the vertical radii of the press point.<br />
167         /// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.<br />
168         /// </summary>
169         /// <param name="point">The point required.</param>
170         /// <returns>The horizontal and vertical radii of the press point.</returns>
171         /// <since_tizen> 3 </since_tizen>
172         public Vector2 GetEllipseRadius(uint point)
173         {
174             Vector2 ret = new Vector2(Interop.Touch.GetEllipseRadius(SwigCPtr, point), false);
175             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
176             return ret;
177         }
178
179         /// <summary>
180         /// Retrieves the touch pressure.<br />
181         /// The pressure range starts at 0.0f.<br />
182         /// Normal pressure is defined as 1.0f.<br />
183         /// A value between 0.0f and 1.0f means light pressure has been applied.<br />
184         /// A value greater than 1.0f means more pressure than normal has been applied.<br />
185         /// If point is greater than GetPointCount(), then this method will return 1.0f.<br />
186         /// </summary>
187         /// <param name="point">The point required.</param>
188         /// <returns>The touch pressure.</returns>
189         /// <since_tizen> 3 </since_tizen>
190         public float GetPressure(uint point)
191         {
192             float ret = Interop.Touch.GetPressure(SwigCPtr, point);
193             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
194             return ret;
195         }
196
197         /// <summary>
198         /// Get mouse device's button value (for example, right or left button)
199         /// </summary>
200         /// <param name="point">The point required.</param>
201         /// <returns></returns>
202         /// <since_tizen> 5 </since_tizen>
203         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
204         [EditorBrowsable(EditorBrowsableState.Never)]
205         public MouseButton GetMouseButton(uint point)
206         {
207             int ret = Interop.Touch.GetMouseButton(SwigCPtr, point);
208             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
209             return (MouseButton)ret;
210         }
211
212         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Touch obj)
213         {
214             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
215         }
216
217         internal static Touch GetTouchFromPtr(global::System.IntPtr cPtr)
218         {
219             Touch ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Touch;
220             if (ret == null)
221             {
222                 ret = new Touch(cPtr, false);
223             }
224
225             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
226             return ret;
227         }
228
229         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
230         [EditorBrowsable(EditorBrowsableState.Never)]
231         public Degree GetAngle(uint point)
232         {
233             Degree ret = new Degree(Interop.Touch.GetAngle(SwigCPtr, point), true);
234             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
235             return ret;
236         }
237
238         /// This will not be public opened.
239         [EditorBrowsable(EditorBrowsableState.Never)]
240         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
241         {
242             Interop.Touch.DeleteTouch(swigCPtr);
243         }
244     }
245
246     /// <summary>
247     /// Mouse device button type.
248     /// </summary>
249     /// <since_tizen> 5 </since_tizen>
250     /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
251     [EditorBrowsable(EditorBrowsableState.Never)]
252     public enum MouseButton
253     {
254         /// <summary>
255         /// No mouse button event or invalid data.
256         /// </summary>
257         /// <since_tizen> 5 </since_tizen>
258         Invalid = -1,
259         /// <summary>
260         /// Primary(Left) mouse button.
261         /// </summary>
262         /// <since_tizen> 5 </since_tizen>
263         Primary = 1,
264         /// <summary>
265         /// Secondary(Right) mouse button.
266         /// </summary>
267         /// <since_tizen> 5 </since_tizen>
268         Secondary = 3,
269         /// <summary>
270         /// Center(Wheel) mouse button.
271         /// </summary>
272         /// <since_tizen> 5 </since_tizen>
273         Tertiary = 2,
274     }
275 }