2 * Copyright(c) 2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 using System.ComponentModel;
18 using System.Runtime.InteropServices;
19 using Tizen.NUI.BaseComponents;
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 />
28 /// <since_tizen> 3 </since_tizen>
29 public class Touch : BaseHandle
31 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
34 /// An uninitialized touch instance.<br />
35 /// Calling member functions with an uninitialized touch handle is not allowed.<br />
37 /// <since_tizen> 3 </since_tizen>
38 public Touch() : this(Interop.Touch.new_Touch__SWIG_0(), true)
40 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
43 internal Touch(Touch other) : this(Interop.Touch.new_Touch__SWIG_1(Touch.getCPtr(other)), true)
45 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
48 internal Touch(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.Touch.Touch_SWIGUpcast(cPtr), cMemoryOwn)
50 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
54 /// Returns the time (in ms) that the touch event occurred.
56 /// <returns>The time (in ms) that the touch event occurred.</returns>
57 /// <since_tizen> 3 </since_tizen>
60 uint ret = Interop.Touch.Touch_GetTime(swigCPtr);
61 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
66 /// Returns the total number of points in this TouchData.
68 /// <returns>The total number of points.</returns>
69 /// <since_tizen> 3 </since_tizen>
70 public uint GetPointCount()
72 uint ret = Interop.Touch.Touch_GetPointCount(swigCPtr);
73 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
78 /// Returns the ID of the device used for the point specified.<br />
79 /// Each point has a unique device ID, which specifies the device used for that
80 /// point. This is returned by this method.<br />
81 /// If a point is greater than GetPointCount(), then this method will return -1.<br />
83 /// <param name="point">The point required.</param>
84 /// <returns>The device ID of this point.</returns>
85 /// <since_tizen> 3 </since_tizen>
86 public int GetDeviceId(uint point)
88 int ret = Interop.Touch.Touch_GetDeviceId(swigCPtr, point);
89 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
94 /// Retrieves the state of the point specified.<br />
95 /// If a point is greater than GetPointCount(), then this method will return PointState.Finished.<br />
97 /// <param name="point">The point required.</param>
98 /// <returns>The state of the point specified.</returns>
99 /// <since_tizen> 3 </since_tizen>
100 public PointStateType GetState(uint point)
102 PointStateType ret = (PointStateType)Interop.Touch.Touch_GetState(swigCPtr, point);
103 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
108 /// Retrieves the actor that was underneath the point specified.<br />
109 /// If a point is greater than GetPointCount(), then this method will return an empty handle.<br />
111 /// <param name="point">The point required.</param>
112 /// <returns>The actor that was underneath the point specified.</returns>
113 /// <since_tizen> 3 </since_tizen>
114 public View GetHitView(uint point)
116 //to fix memory leak issue, match the handle count with native side.
117 global::System.IntPtr cPtr = Interop.Touch.Touch_GetHitActor(swigCPtr, point);
118 HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
119 View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View;
120 Interop.BaseHandle.delete_BaseHandle(CPtr);
121 CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
123 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
128 /// Retrieves the coordinates relative to the top-left of the hit actor at the point specified.<br />
129 /// The top-left of an actor is (0.0, 0.0, 0.5).<br />
130 /// If you require the local coordinates of another actor (for example, the parent of the hit actor),
131 /// then you should use Actor::ScreenToLocal().<br />
132 /// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.<br />
134 /// <param name="point">The point required.</param>
135 /// <returns>The coordinates relative to the top-left of the hit actor of the point specified.</returns>
136 /// <since_tizen> 3 </since_tizen>
137 public Vector2 GetLocalPosition(uint point)
139 Vector2 ret = new Vector2(Interop.Touch.Touch_GetLocalPosition(swigCPtr, point), false);
140 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
145 /// Retrieves the coordinates relative to the top-left of the screen of the point specified.<br />
146 /// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.<br />
148 /// <param name="point">The point required.</param>
149 /// <returns>The coordinates relative to the top-left of the screen of the point specified.</returns>
150 /// <since_tizen> 3 </since_tizen>
151 public Vector2 GetScreenPosition(uint point)
153 Vector2 ret = new Vector2(Interop.Touch.Touch_GetScreenPosition(swigCPtr, point), false);
154 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
159 /// Retrieves the radius of the press point.<br />
160 /// This is the average of both the horizontal and vertical radii of the press point.<br />
161 /// If point is greater than GetPointCount(), then this method will return 0.0f.<br />
163 /// <param name="point">The point required.</param>
164 /// <returns>The radius of the press point.</returns>
165 /// <since_tizen> 3 </since_tizen>
166 public float GetRadius(uint point)
168 float ret = Interop.Touch.Touch_GetRadius(swigCPtr, point);
169 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
174 /// Retrieves both the horizontal and the vertical radii of the press point.<br />
175 /// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.<br />
177 /// <param name="point">The point required.</param>
178 /// <returns>The horizontal and vertical radii of the press point.</returns>
179 /// <since_tizen> 3 </since_tizen>
180 public Vector2 GetEllipseRadius(uint point)
182 Vector2 ret = new Vector2(Interop.Touch.Touch_GetEllipseRadius(swigCPtr, point), false);
183 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
188 /// Retrieves the touch pressure.<br />
189 /// The pressure range starts at 0.0f.<br />
190 /// Normal pressure is defined as 1.0f.<br />
191 /// A value between 0.0f and 1.0f means light pressure has been applied.<br />
192 /// A value greater than 1.0f means more pressure than normal has been applied.<br />
193 /// If point is greater than GetPointCount(), then this method will return 1.0f.<br />
195 /// <param name="point">The point required.</param>
196 /// <returns>The touch pressure.</returns>
197 /// <since_tizen> 3 </since_tizen>
198 public float GetPressure(uint point)
200 float ret = Interop.Touch.Touch_GetPressure(swigCPtr, point);
201 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
206 /// Get mouse device's button value (for example, right or left button)
208 /// <param name="point">The point required.</param>
209 /// <returns></returns>
210 /// <since_tizen> 5 </since_tizen>
211 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
212 [EditorBrowsable(EditorBrowsableState.Never)]
213 public MouseButton GetMouseButton(uint point)
215 int ret = Interop.Touch.Touch_GetMouseButton(swigCPtr, point);
216 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
217 return (MouseButton)ret;
220 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Touch obj)
222 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
225 internal static Touch GetTouchFromPtr(global::System.IntPtr cPtr)
227 Touch ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Touch;
230 ret = new Touch(cPtr, false);
233 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
237 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
238 [EditorBrowsable(EditorBrowsableState.Never)]
239 public Degree GetAngle(uint point)
241 Degree ret = new Degree(Interop.Touch.Touch_GetAngle(swigCPtr, point), true);
242 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
249 /// <since_tizen> 3 </since_tizen>
250 protected override void Dispose(DisposeTypes type)
257 //Release your own unmanaged resources here.
258 //You should not access any managed member here except static instance.
259 //because the execution order of Finalizes is non-deterministic.
261 if (swigCPtr.Handle != global::System.IntPtr.Zero)
266 Interop.Touch.delete_Touch(swigCPtr);
268 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
276 /// Mouse device button type.
278 /// <since_tizen> 5 </since_tizen>
279 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
280 [EditorBrowsable(EditorBrowsableState.Never)]
281 public enum MouseButton
284 /// No mouse button event or invalid data.
286 /// <since_tizen> 5 </since_tizen>
289 /// Primary(Left) mouse button.
291 /// <since_tizen> 5 </since_tizen>
294 /// Secondary(Right) mouse button.
296 /// <since_tizen> 5 </since_tizen>
299 /// Center(Wheel) mouse button.
301 /// <since_tizen> 5 </since_tizen>