[NUI] Integration from dalihub (#1039)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Touch.cs
1 /*
2  * Copyright(c) 2017 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 System.Runtime.InteropServices;
19 using Tizen.NUI.BaseComponents;
20
21 namespace Tizen.NUI
22 {
23     /// <summary>
24     /// Touch events are a collection of points at a specific moment in time.<br />
25     /// When a multi-touch event occurs, each point represents the points that are currently being
26     /// touched or the points where a touch has stopped.<br />
27     /// </summary>
28     /// <since_tizen> 3 </since_tizen>
29     public class Touch : BaseHandle
30     {
31         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
32
33         /// <summary>
34         /// An uninitialized touch instance.<br />
35         /// Calling member functions with an uninitialized touch handle is not allowed.<br />
36         /// </summary>
37         /// <since_tizen> 3 </since_tizen>
38         public Touch() : this(Interop.Touch.new_Touch__SWIG_0(), true)
39         {
40             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
41         }
42
43         internal Touch(Touch other) : this(Interop.Touch.new_Touch__SWIG_1(Touch.getCPtr(other)), true)
44         {
45             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
46         }
47
48         internal Touch(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.Touch.Touch_SWIGUpcast(cPtr), cMemoryOwn)
49         {
50             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
51         }
52
53         /// <summary>
54         /// Returns the time (in ms) that the touch event occurred.
55         /// </summary>
56         /// <returns>The time (in ms) that the touch event occurred.</returns>
57         /// <since_tizen> 3 </since_tizen>
58         public uint GetTime()
59         {
60             uint ret = Interop.Touch.Touch_GetTime(swigCPtr);
61             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
62             return ret;
63         }
64
65         /// <summary>
66         /// Returns the total number of points in this TouchData.
67         /// </summary>
68         /// <returns>The total number of points.</returns>
69         /// <since_tizen> 3 </since_tizen>
70         public uint GetPointCount()
71         {
72             uint ret = Interop.Touch.Touch_GetPointCount(swigCPtr);
73             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
74             return ret;
75         }
76
77         /// <summary>
78         /// Returns the ID of the device used for the point specified.<br />
79         /// Each point has a unique device ID, which specifies the device used for that
80         /// point. This is returned by this method.<br />
81         /// If a point is greater than GetPointCount(), then this method will return -1.<br />
82         /// </summary>
83         /// <param name="point">The point required.</param>
84         /// <returns>The device ID of this point.</returns>
85         /// <since_tizen> 3 </since_tizen>
86         public int GetDeviceId(uint point)
87         {
88             int ret = Interop.Touch.Touch_GetDeviceId(swigCPtr, point);
89             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
90             return ret;
91         }
92
93         /// <summary>
94         /// Retrieves the state of the point specified.<br />
95         /// If a point is greater than GetPointCount(), then this method will return PointState.Finished.<br />
96         /// </summary>
97         /// <param name="point">The point required.</param>
98         /// <returns>The state of the point specified.</returns>
99         /// <since_tizen> 3 </since_tizen>
100         public PointStateType GetState(uint point)
101         {
102             PointStateType ret = (PointStateType)Interop.Touch.Touch_GetState(swigCPtr, point);
103             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
104             return ret;
105         }
106
107         /// <summary>
108         /// Retrieves the actor that was underneath the point specified.<br />
109         /// If a point is greater than GetPointCount(), then this method will return an empty handle.<br />
110         /// </summary>
111         /// <param name="point">The point required.</param>
112         /// <returns>The actor that was underneath the point specified.</returns>
113         /// <since_tizen> 3 </since_tizen>
114         public View GetHitView(uint point)
115         {
116             //to fix memory leak issue, match the handle count with native side.
117             global::System.IntPtr cPtr = Interop.Touch.Touch_GetHitActor(swigCPtr, point);
118             HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
119             View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View;
120             Interop.BaseHandle.delete_BaseHandle(CPtr);
121             CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
122
123             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
124             return ret;
125         }
126
127         /// <summary>
128         /// Retrieves the coordinates relative to the top-left of the hit actor at the point specified.<br />
129         /// The top-left of an actor is (0.0, 0.0, 0.5).<br />
130         /// If you require the local coordinates of another actor (for example, the parent of the hit actor),
131         /// then you should use Actor::ScreenToLocal().<br />
132         /// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.<br />
133         /// </summary>
134         /// <param name="point">The point required.</param>
135         /// <returns>The coordinates relative to the top-left of the hit actor of the point specified.</returns>
136         /// <since_tizen> 3 </since_tizen>
137         public Vector2 GetLocalPosition(uint point)
138         {
139             Vector2 ret = new Vector2(Interop.Touch.Touch_GetLocalPosition(swigCPtr, point), false);
140             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
141             return ret;
142         }
143
144         /// <summary>
145         /// Retrieves the coordinates relative to the top-left of the screen of the point specified.<br />
146         /// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.<br />
147         /// </summary>
148         /// <param name="point">The point required.</param>
149         /// <returns>The coordinates relative to the top-left of the screen of the point specified.</returns>
150         /// <since_tizen> 3 </since_tizen>
151         public Vector2 GetScreenPosition(uint point)
152         {
153             Vector2 ret = new Vector2(Interop.Touch.Touch_GetScreenPosition(swigCPtr, point), false);
154             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
155             return ret;
156         }
157
158         /// <summary>
159         /// Retrieves the radius of the press point.<br />
160         /// This is the average of both the horizontal and vertical radii of the press point.<br />
161         /// If point is greater than GetPointCount(), then this method will return 0.0f.<br />
162         /// </summary>
163         /// <param name="point">The point required.</param>
164         /// <returns>The radius of the press point.</returns>
165         /// <since_tizen> 3 </since_tizen>
166         public float GetRadius(uint point)
167         {
168             float ret = Interop.Touch.Touch_GetRadius(swigCPtr, point);
169             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
170             return ret;
171         }
172
173         /// <summary>
174         /// Retrieves both the horizontal and the vertical radii of the press point.<br />
175         /// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.<br />
176         /// </summary>
177         /// <param name="point">The point required.</param>
178         /// <returns>The horizontal and vertical radii of the press point.</returns>
179         /// <since_tizen> 3 </since_tizen>
180         public Vector2 GetEllipseRadius(uint point)
181         {
182             Vector2 ret = new Vector2(Interop.Touch.Touch_GetEllipseRadius(swigCPtr, point), false);
183             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
184             return ret;
185         }
186
187         /// <summary>
188         /// Retrieves the touch pressure.<br />
189         /// The pressure range starts at 0.0f.<br />
190         /// Normal pressure is defined as 1.0f.<br />
191         /// A value between 0.0f and 1.0f means light pressure has been applied.<br />
192         /// A value greater than 1.0f means more pressure than normal has been applied.<br />
193         /// If point is greater than GetPointCount(), then this method will return 1.0f.<br />
194         /// </summary>
195         /// <param name="point">The point required.</param>
196         /// <returns>The touch pressure.</returns>
197         /// <since_tizen> 3 </since_tizen>
198         public float GetPressure(uint point)
199         {
200             float ret = Interop.Touch.Touch_GetPressure(swigCPtr, point);
201             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
202             return ret;
203         }
204
205         /// <summary>
206         /// Get mouse device's button value (for example, right or left button)
207         /// </summary>
208         /// <param name="point">The point required.</param>
209         /// <returns></returns>
210         /// <since_tizen> 5 </since_tizen>
211         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
212         [EditorBrowsable(EditorBrowsableState.Never)]
213         public MouseButton GetMouseButton(uint point)
214         {
215             int ret = Interop.Touch.Touch_GetMouseButton(swigCPtr, point);
216             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
217             return (MouseButton)ret;
218         }
219
220         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Touch obj)
221         {
222             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
223         }
224
225         internal static Touch GetTouchFromPtr(global::System.IntPtr cPtr)
226         {
227             Touch ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Touch;
228             if (ret == null)
229             {
230                 ret = new Touch(cPtr, false);
231             }
232
233             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
234             return ret;
235         }
236
237         /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
238         [EditorBrowsable(EditorBrowsableState.Never)]
239         public Degree GetAngle(uint point)
240         {
241             Degree ret = new Degree(Interop.Touch.Touch_GetAngle(swigCPtr, point), true);
242             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
243             return ret;
244         }
245
246         /// <summary>
247         /// Dispose.
248         /// </summary>
249         /// <since_tizen> 3 </since_tizen>
250         protected override void Dispose(DisposeTypes type)
251         {
252             if (disposed)
253             {
254                 return;
255             }
256
257             //Release your own unmanaged resources here.
258             //You should not access any managed member here except static instance.
259             //because the execution order of Finalizes is non-deterministic.
260
261             if (swigCPtr.Handle != global::System.IntPtr.Zero)
262             {
263                 if (swigCMemOwn)
264                 {
265                     swigCMemOwn = false;
266                     Interop.Touch.delete_Touch(swigCPtr);
267                 }
268                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
269             }
270
271             base.Dispose(type);
272         }
273     }
274
275     /// <summary>
276     /// Mouse device button type.
277     /// </summary>
278     /// <since_tizen> 5 </since_tizen>
279     /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
280     [EditorBrowsable(EditorBrowsableState.Never)]
281     public enum MouseButton
282     {
283         /// <summary>
284         /// No mouse button event or invalid data.
285         /// </summary>
286         /// <since_tizen> 5 </since_tizen>
287         Invalid = -1,
288         /// <summary>
289         /// Primary(Left) mouse button.
290         /// </summary>
291         /// <since_tizen> 5 </since_tizen>
292         Primary = 1,
293         /// <summary>
294         /// Secondary(Right) mouse button.
295         /// </summary>
296         /// <since_tizen> 5 </since_tizen>
297         Secondary = 3,
298         /// <summary>
299         /// Center(Wheel) mouse button.
300         /// </summary>
301         /// <since_tizen> 5 </since_tizen>
302         Tertiary = 2,
303     }
304
305 }