601f58fc3fdd53c9d9bfc0a3281f51c293d3b16f
[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
63                     //Unreference this instance from Registry.
64                     Registry.Unregister(this);
65
66                     NDalicPINVOKE.delete_Touch(swigCPtr);
67                 }
68                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
69             }
70
71             base.Dispose(type);
72         }
73
74
75         internal static Touch GetTouchFromPtr(global::System.IntPtr cPtr)
76         {
77             Touch ret = new Touch(cPtr, false);
78             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
79             return ret;
80         }
81
82         /// <summary>
83         /// An uninitialized Touch instance.<br>
84         /// Calling member functions with an uninitialized Touch handle is not allowed.<br>
85         /// </summary>
86         public Touch() : this(NDalicPINVOKE.new_Touch__SWIG_0(), true)
87         {
88             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
89         }
90
91         internal Touch(Touch other) : this(NDalicPINVOKE.new_Touch__SWIG_1(Touch.getCPtr(other)), true)
92         {
93             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
94         }
95
96         /// <summary>
97         /// Returns the time (in ms) that the touch event occurred.
98         /// </summary>
99         /// <returns>The time (in ms) that the touch event occurred</returns>
100         public uint GetTime()
101         {
102             uint ret = NDalicPINVOKE.Touch_GetTime(swigCPtr);
103             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
104             return ret;
105         }
106
107         /// <summary>
108         /// Returns the total number of points in this TouchData.
109         /// </summary>
110         /// <returns>Total number of Points</returns>
111         public uint GetPointCount()
112         {
113             uint ret = NDalicPINVOKE.Touch_GetPointCount(swigCPtr);
114             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
115             return ret;
116         }
117
118         /// <summary>
119         /// Returns the ID of the device used for the Point specified.<br>
120         /// Each point has a unique device ID which specifies the device used for that
121         /// point. This is returned by this method.<br>
122         /// If point is greater than GetPointCount() then this method will return -1.<br>
123         /// </summary>
124         /// <param name="point">The point required</param>
125         /// <returns>The Device ID of this point</returns>
126         public int GetDeviceId(uint point)
127         {
128             int ret = NDalicPINVOKE.Touch_GetDeviceId(swigCPtr, point);
129             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
130             return ret;
131         }
132
133         /// <summary>
134         /// Retrieves the State of the point specified.<br>
135         /// If point is greater than GetPointCount() then this method will return PointState.Finished.<br>
136         /// </summary>
137         /// <param name="point">The point required</param>
138         /// <returns>The state of the point specified</returns>
139         public PointStateType GetState(uint point)
140         {
141             PointStateType ret = (PointStateType)NDalicPINVOKE.Touch_GetState(swigCPtr, point);
142             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
143             return ret;
144         }
145
146         /// <summary>
147         /// Retrieves the actor that was underneath the point specified.<br>
148         /// If point is greater than GetPointCount() then this method will return an empty handle.<br>
149         /// </summary>
150         /// <param name="point">The point required</param>
151         /// <returns>The actor that was underneath the point specified</returns>
152         public View GetHitView(uint point)
153         {
154             View ret = new View(NDalicPINVOKE.Touch_GetHitActor(swigCPtr, point), true);
155             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
156             return ret;
157         }
158
159         /// <summary>
160         /// Retrieves the co-ordinates relative to the top-left of the hit-actor at the point specified.<br>
161         /// The top-left of an actor is (0.0, 0.0, 0.5).<br>
162         /// If you require the local coordinates of another actor (e.g the parent of the hit actor),
163         /// then you should use Actor::ScreenToLocal().<br>
164         /// If point is greater than GetPointCount() then this method will return Vector2.Zero.<br>
165         /// </summary>
166         /// <param name="point">The point required</param>
167         /// <returns>The co-ordinates relative to the top-left of the hit-actor of the point specified</returns>
168         public Vector2 GetLocalPosition(uint point)
169         {
170             Vector2 ret = new Vector2(NDalicPINVOKE.Touch_GetLocalPosition(swigCPtr, point), false);
171             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
172             return ret;
173         }
174
175         /// <summary>
176         /// Retrieves the co-ordinates relative to the top-left of the screen of the point specified.<br>
177         /// If point is greater than GetPointCount() then this method will return Vector2.Zero.<br>
178         /// </summary>
179         /// <param name="point">The point required</param>
180         /// <returns>The co-ordinates relative to the top-left of the screen of the point specified</returns>
181         public Vector2 GetScreenPosition(uint point)
182         {
183             Vector2 ret = new Vector2(NDalicPINVOKE.Touch_GetScreenPosition(swigCPtr, point), false);
184             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
185             return ret;
186         }
187
188         /// <summary>
189         /// Retrieves the radius of the press point.<br>
190         /// This is the average of both the horizontal and vertical radii of the press point.<br>
191         /// If point is greater than GetPointCount() then this method will return 0.0f.<br>
192         /// </summary>
193         /// <param name="point">The point required</param>
194         /// <returns>The radius of the press point</returns>
195         public float GetRadius(uint point)
196         {
197             float ret = NDalicPINVOKE.Touch_GetRadius(swigCPtr, point);
198             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
199             return ret;
200         }
201
202         /// <summary>
203         /// Retrieves BOTH the horizontal and the vertical radii of the press point.<br>
204         /// If point is greater than GetPointCount() then this method will return Vector2.Zero.<br>
205         /// </summary>
206         /// <param name="point">The point required</param>
207         /// <returns>The horizontal and vertical radii of the press point</returns>
208         public Vector2 GetEllipseRadius(uint point)
209         {
210             Vector2 ret = new Vector2(NDalicPINVOKE.Touch_GetEllipseRadius(swigCPtr, point), false);
211             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
212             return ret;
213         }
214
215         /// <summary>
216         /// Retrieves the touch pressure.<br>
217         /// The pressure range starts at 0.0f.<br>
218         /// Normal pressure is defined as 1.0f.<br>
219         /// A value between 0.0f and 1.0f means light pressure has been applied.<br>
220         /// A value greater than 1.0f means more pressure than normal has been applied.<br>
221         /// If point is greater than GetPointCount() then this method will return 1.0f.<br>
222         /// </summary>
223         /// <param name="point">point The point required</param>
224         /// <returns>The touch pressure</returns>
225         public float GetPressure(uint point)
226         {
227             float ret = NDalicPINVOKE.Touch_GetPressure(swigCPtr, point);
228             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
229             return ret;
230         }
231
232         internal Degree GetAngle(uint point)
233         {
234             Degree ret = new Degree(NDalicPINVOKE.Touch_GetAngle(swigCPtr, point), true);
235             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
236             return ret;
237         }
238
239     }
240 }