[NUI] Add GetMouseButton in Touch (#302)
[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 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         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
32
33         internal Touch(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Touch_SWIGUpcast(cPtr), cMemoryOwn)
34         {
35             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
36         }
37
38         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Touch obj)
39         {
40             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
41         }
42
43         /// <summary>
44         /// Dispose.
45         /// </summary>
46         /// <since_tizen> 3 </since_tizen>
47         protected override void Dispose(DisposeTypes type)
48         {
49             if (disposed)
50             {
51                 return;
52             }
53
54             if (type == DisposeTypes.Explicit)
55             {
56                 //Called by User
57                 //Release your own managed resources here.
58                 //You should release all of your own disposable objects here.
59             }
60
61             //Release your own unmanaged resources here.
62             //You should not access any managed member here except static instance.
63             //because the execution order of Finalizes is non-deterministic.
64
65             if (swigCPtr.Handle != global::System.IntPtr.Zero)
66             {
67                 if (swigCMemOwn)
68                 {
69                     swigCMemOwn = false;
70                     NDalicPINVOKE.delete_Touch(swigCPtr);
71                 }
72                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
73             }
74
75             base.Dispose(type);
76         }
77
78
79         internal static Touch GetTouchFromPtr(global::System.IntPtr cPtr)
80         {
81             Touch ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Touch;
82             if (ret == null)
83             {
84                 ret = new Touch(cPtr, false);
85             }
86
87             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
88             return ret;
89         }
90
91         /// <summary>
92         /// An uninitialized touch instance.<br />
93         /// Calling member functions with an uninitialized touch handle is not allowed.<br />
94         /// </summary>
95         /// <since_tizen> 3 </since_tizen>
96         public Touch() : this(NDalicPINVOKE.new_Touch__SWIG_0(), true)
97         {
98             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
99         }
100
101         internal Touch(Touch other) : this(NDalicPINVOKE.new_Touch__SWIG_1(Touch.getCPtr(other)), true)
102         {
103             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
104         }
105
106         /// <summary>
107         /// Returns the time (in ms) that the touch event occurred.
108         /// </summary>
109         /// <returns>The time (in ms) that the touch event occurred.</returns>
110         /// <since_tizen> 3 </since_tizen>
111         public uint GetTime()
112         {
113             uint ret = NDalicPINVOKE.Touch_GetTime(swigCPtr);
114             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
115             return ret;
116         }
117
118         /// <summary>
119         /// Returns the total number of points in this TouchData.
120         /// </summary>
121         /// <returns>The total number of points.</returns>
122         /// <since_tizen> 3 </since_tizen>
123         public uint GetPointCount()
124         {
125             uint ret = NDalicPINVOKE.Touch_GetPointCount(swigCPtr);
126             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
127             return ret;
128         }
129
130         /// <summary>
131         /// Returns the ID of the device used for the point specified.<br />
132         /// Each point has a unique device ID, which specifies the device used for that
133         /// point. This is returned by this method.<br />
134         /// If a point is greater than GetPointCount(), then this method will return -1.<br />
135         /// </summary>
136         /// <param name="point">The point required.</param>
137         /// <returns>The device ID of this point.</returns>
138         /// <since_tizen> 3 </since_tizen>
139         public int GetDeviceId(uint point)
140         {
141             int ret = NDalicPINVOKE.Touch_GetDeviceId(swigCPtr, point);
142             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
143             return ret;
144         }
145
146         /// <summary>
147         /// Retrieves the state of the point specified.<br />
148         /// If a point is greater than GetPointCount(), then this method will return PointState.Finished.<br />
149         /// </summary>
150         /// <param name="point">The point required.</param>
151         /// <returns>The state of the point specified.</returns>
152         /// <since_tizen> 3 </since_tizen>
153         public PointStateType GetState(uint point)
154         {
155             PointStateType ret = (PointStateType)NDalicPINVOKE.Touch_GetState(swigCPtr, point);
156             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
157             return ret;
158         }
159
160         /// <summary>
161         /// Retrieves the actor that was underneath the point specified.<br />
162         /// If a point is greater than GetPointCount(), then this method will return an empty handle.<br />
163         /// </summary>
164         /// <param name="point">The point required.</param>
165         /// <returns>The actor that was underneath the point specified.</returns>
166         /// <since_tizen> 3 </since_tizen>
167         public View GetHitView(uint point)
168         {
169             //to fix memory leak issue, match the handle count with native side.
170             global::System.IntPtr cPtr = NDalicPINVOKE.Touch_GetHitActor(swigCPtr, point);
171             HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
172             View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View;
173             NDalicPINVOKE.delete_BaseHandle(CPtr);
174             CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
175
176             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
177             return ret;
178         }
179
180         /// <summary>
181         /// Retrieves the coordinates relative to the top-left of the hit actor at the point specified.<br />
182         /// The top-left of an actor is (0.0, 0.0, 0.5).<br />
183         /// If you require the local coordinates of another actor (for example, the parent of the hit actor),
184         /// then you should use Actor::ScreenToLocal().<br />
185         /// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.<br />
186         /// </summary>
187         /// <param name="point">The point required.</param>
188         /// <returns>The coordinates relative to the top-left of the hit actor of the point specified.</returns>
189         /// <since_tizen> 3 </since_tizen>
190         public Vector2 GetLocalPosition(uint point)
191         {
192             Vector2 ret = new Vector2(NDalicPINVOKE.Touch_GetLocalPosition(swigCPtr, point), false);
193             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
194             return ret;
195         }
196
197         /// <summary>
198         /// Retrieves the coordinates relative to the top-left of the screen of the point specified.<br />
199         /// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.<br />
200         /// </summary>
201         /// <param name="point">The point required.</param>
202         /// <returns>The coordinates relative to the top-left of the screen of the point specified.</returns>
203         /// <since_tizen> 3 </since_tizen>
204         public Vector2 GetScreenPosition(uint point)
205         {
206             Vector2 ret = new Vector2(NDalicPINVOKE.Touch_GetScreenPosition(swigCPtr, point), false);
207             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
208             return ret;
209         }
210
211         /// <summary>
212         /// Retrieves the radius of the press point.<br />
213         /// This is the average of both the horizontal and vertical radii of the press point.<br />
214         /// If point is greater than GetPointCount(), then this method will return 0.0f.<br />
215         /// </summary>
216         /// <param name="point">The point required.</param>
217         /// <returns>The radius of the press point.</returns>
218         /// <since_tizen> 3 </since_tizen>
219         public float GetRadius(uint point)
220         {
221             float ret = NDalicPINVOKE.Touch_GetRadius(swigCPtr, point);
222             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
223             return ret;
224         }
225
226         /// <summary>
227         /// Retrieves both the horizontal and the vertical radii of the press point.<br />
228         /// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.<br />
229         /// </summary>
230         /// <param name="point">The point required.</param>
231         /// <returns>The horizontal and vertical radii of the press point.</returns>
232         /// <since_tizen> 3 </since_tizen>
233         public Vector2 GetEllipseRadius(uint point)
234         {
235             Vector2 ret = new Vector2(NDalicPINVOKE.Touch_GetEllipseRadius(swigCPtr, point), false);
236             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
237             return ret;
238         }
239
240         /// <summary>
241         /// Retrieves the touch pressure.<br />
242         /// The pressure range starts at 0.0f.<br />
243         /// Normal pressure is defined as 1.0f.<br />
244         /// A value between 0.0f and 1.0f means light pressure has been applied.<br />
245         /// A value greater than 1.0f means more pressure than normal has been applied.<br />
246         /// If point is greater than GetPointCount(), then this method will return 1.0f.<br />
247         /// </summary>
248         /// <param name="point">The point required.</param>
249         /// <returns>The touch pressure.</returns>
250         /// <since_tizen> 3 </since_tizen>
251         public float GetPressure(uint point)
252         {
253             float ret = NDalicPINVOKE.Touch_GetPressure(swigCPtr, point);
254             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
255             return ret;
256         }
257
258         internal Degree GetAngle(uint point)
259         {
260             Degree ret = new Degree(NDalicPINVOKE.Touch_GetAngle(swigCPtr, point), true);
261             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
262             return ret;
263         }
264         /// <summary>
265         /// Get mouse device's button value (ex: right/left button)
266         /// </summary>
267         /// <param name="point">The point required</param>
268         /// <returns></returns>
269         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
270         [EditorBrowsable(EditorBrowsableState.Never)]
271         public MouseButtonType GetMouseButton(uint point)
272         {
273             int ret = NDalicManualPINVOKE.Touch_GetMouseButton(swigCPtr, point);
274             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
275             return (MouseButtonType)ret;
276         }
277     }
278
279     /// <summary>
280     /// Mouse device button type
281     /// </summary>
282     /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
283     [EditorBrowsable(EditorBrowsableState.Never)]
284     public enum MouseButtonType
285     {
286         /// <summary>
287         /// No mouse button event or invalid data
288         /// </summary>
289         Invalid = -1,
290         /// <summary>
291         /// Left mouse button
292         /// </summary>
293         LeftButton = 1,
294         /// <summary>
295         /// Center(Wheel) mouse button
296         /// </summary>
297         CenterButton = 2,
298         /// <summary>
299         /// Right mouse button
300         /// </summary>
301         RightButton = 3,
302         /// <summary>
303         /// Reserved mouse button for different mouse devices
304         /// </summary>
305         Reserved = 4,
306     }
307
308 }