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