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