Release 4.0.0-preview1-00301
[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
18 namespace Tizen.NUI
19 {
20     using Tizen.NUI.BaseComponents;
21     /// <summary>
22     /// Touch events are a collection of points at a specific moment in time.<br />
23     /// When a multi-touch event occurs, each point represents the points that are currently being
24     /// touched or the points where a touch has stopped.<br />
25     /// </summary>
26     public class Touch : BaseHandle
27     {
28         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
29
30         internal Touch(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Touch_SWIGUpcast(cPtr), cMemoryOwn)
31         {
32             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
33         }
34
35         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Touch obj)
36         {
37             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
38         }
39
40         /// <summary>
41         /// Dispose.
42         /// </summary>
43         /// <since_tizen> 3 </since_tizen>
44         protected override void Dispose(DisposeTypes type)
45         {
46             if(disposed)
47             {
48                 return;
49             }
50
51             if(type == DisposeTypes.Explicit)
52             {
53                 //Called by User
54                 //Release your own managed resources here.
55                 //You should release all of your own disposable objects here.
56             }
57
58             //Release your own unmanaged resources here.
59             //You should not access any managed member here except static instance.
60             //because the execution order of Finalizes is non-deterministic.
61
62             if (swigCPtr.Handle != global::System.IntPtr.Zero)
63             {
64                 if (swigCMemOwn)
65                 {
66                     swigCMemOwn = false;
67                     NDalicPINVOKE.delete_Touch(swigCPtr);
68                 }
69                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
70             }
71
72             base.Dispose(type);
73         }
74
75
76         internal static Touch GetTouchFromPtr(global::System.IntPtr cPtr)
77         {
78             Touch ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Touch;
79             if (ret == null)
80             {
81                 ret = new Touch(cPtr, false);
82             }
83
84             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
85             return ret;
86         }
87
88         /// <summary>
89         /// An uninitialized touch instance.<br />
90         /// Calling member functions with an uninitialized touch handle is not allowed.<br />
91         /// </summary>
92         /// <since_tizen> 3 </since_tizen>
93         public Touch() : this(NDalicPINVOKE.new_Touch__SWIG_0(), true)
94         {
95             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
96         }
97
98         internal Touch(Touch other) : this(NDalicPINVOKE.new_Touch__SWIG_1(Touch.getCPtr(other)), true)
99         {
100             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
101         }
102
103         /// <summary>
104         /// Returns the time (in ms) that the touch event occurred.
105         /// </summary>
106         /// <returns>The time (in ms) that the touch event occurred.</returns>
107         /// <since_tizen> 3 </since_tizen>
108         public uint GetTime()
109         {
110             uint ret = NDalicPINVOKE.Touch_GetTime(swigCPtr);
111             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
112             return ret;
113         }
114
115         /// <summary>
116         /// Returns the total number of points in this TouchData.
117         /// </summary>
118         /// <returns>The total number of points.</returns>
119         /// <since_tizen> 3 </since_tizen>
120         public uint GetPointCount()
121         {
122             uint ret = NDalicPINVOKE.Touch_GetPointCount(swigCPtr);
123             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
124             return ret;
125         }
126
127         /// <summary>
128         /// Returns the ID of the device used for the point specified.<br />
129         /// Each point has a unique device ID, which specifies the device used for that
130         /// point. This is returned by this method.<br />
131         /// If a point is greater than GetPointCount(), then this method will return -1.<br />
132         /// </summary>
133         /// <param name="point">The point required.</param>
134         /// <returns>The device ID of this point.</returns>
135         /// <since_tizen> 3 </since_tizen>
136         public int GetDeviceId(uint point)
137         {
138             int ret = NDalicPINVOKE.Touch_GetDeviceId(swigCPtr, point);
139             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
140             return ret;
141         }
142
143         /// <summary>
144         /// Retrieves the state of the point specified.<br />
145         /// If a point is greater than GetPointCount(), then this method will return PointState.Finished.<br />
146         /// </summary>
147         /// <param name="point">The point required.</param>
148         /// <returns>The state of the point specified.</returns>
149         /// <since_tizen> 3 </since_tizen>
150         public PointStateType GetState(uint point)
151         {
152             PointStateType ret = (PointStateType)NDalicPINVOKE.Touch_GetState(swigCPtr, point);
153             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
154             return ret;
155         }
156
157         /// <summary>
158         /// Retrieves the actor that was underneath the point specified.<br />
159         /// If a point is greater than GetPointCount(), then this method will return an empty handle.<br />
160         /// </summary>
161         /// <param name="point">The point required.</param>
162         /// <returns>The actor that was underneath the point specified.</returns>
163         /// <since_tizen> 3 </since_tizen>
164         public View GetHitView(uint point)
165         {
166             global::System.IntPtr cPtr = NDalicPINVOKE.Touch_GetHitActor(swigCPtr, point);
167             View ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View;
168
169             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
170             return ret;
171         }
172
173         /// <summary>
174         /// Retrieves the coordinates relative to the top-left of the hit actor at the point specified.<br />
175         /// The top-left of an actor is (0.0, 0.0, 0.5).<br />
176         /// If you require the local coordinates of another actor (for example, the parent of the hit actor),
177         /// then you should use Actor::ScreenToLocal().<br />
178         /// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.<br />
179         /// </summary>
180         /// <param name="point">The point required.</param>
181         /// <returns>The coordinates relative to the top-left of the hit actor of the point specified.</returns>
182         /// <since_tizen> 3 </since_tizen>
183         public Vector2 GetLocalPosition(uint point)
184         {
185             Vector2 ret = new Vector2(NDalicPINVOKE.Touch_GetLocalPosition(swigCPtr, point), false);
186             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
187             return ret;
188         }
189
190         /// <summary>
191         /// Retrieves the coordinates relative to the top-left of the screen of the point specified.<br />
192         /// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.<br />
193         /// </summary>
194         /// <param name="point">The point required.</param>
195         /// <returns>The coordinates relative to the top-left of the screen of the point specified.</returns>
196         /// <since_tizen> 3 </since_tizen>
197         public Vector2 GetScreenPosition(uint point)
198         {
199             Vector2 ret = new Vector2(NDalicPINVOKE.Touch_GetScreenPosition(swigCPtr, point), false);
200             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
201             return ret;
202         }
203
204         /// <summary>
205         /// Retrieves the radius of the press point.<br />
206         /// This is the average of both the horizontal and vertical radii of the press point.<br />
207         /// If point is greater than GetPointCount(), then this method will return 0.0f.<br />
208         /// </summary>
209         /// <param name="point">The point required.</param>
210         /// <returns>The radius of the press point.</returns>
211         /// <since_tizen> 3 </since_tizen>
212         public float GetRadius(uint point)
213         {
214             float ret = NDalicPINVOKE.Touch_GetRadius(swigCPtr, point);
215             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
216             return ret;
217         }
218
219         /// <summary>
220         /// Retrieves both the horizontal and the vertical radii of the press point.<br />
221         /// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.<br />
222         /// </summary>
223         /// <param name="point">The point required.</param>
224         /// <returns>The horizontal and vertical radii of the press point.</returns>
225         /// <since_tizen> 3 </since_tizen>
226         public Vector2 GetEllipseRadius(uint point)
227         {
228             Vector2 ret = new Vector2(NDalicPINVOKE.Touch_GetEllipseRadius(swigCPtr, point), false);
229             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
230             return ret;
231         }
232
233         /// <summary>
234         /// Retrieves the touch pressure.<br />
235         /// The pressure range starts at 0.0f.<br />
236         /// Normal pressure is defined as 1.0f.<br />
237         /// A value between 0.0f and 1.0f means light pressure has been applied.<br />
238         /// A value greater than 1.0f means more pressure than normal has been applied.<br />
239         /// If point is greater than GetPointCount(), then this method will return 1.0f.<br />
240         /// </summary>
241         /// <param name="point">The point required.</param>
242         /// <returns>The touch pressure.</returns>
243         /// <since_tizen> 3 </since_tizen>
244         public float GetPressure(uint point)
245         {
246             float ret = NDalicPINVOKE.Touch_GetPressure(swigCPtr, point);
247             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
248             return ret;
249         }
250
251         internal Degree GetAngle(uint point)
252         {
253             Degree ret = new Degree(NDalicPINVOKE.Touch_GetAngle(swigCPtr, point), true);
254             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
255             return ret;
256         }
257
258     }
259 }