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