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;
33 internal Touch(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Touch_SWIGUpcast(cPtr), cMemoryOwn)
35 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
38 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Touch obj)
40 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
46 /// <since_tizen> 3 </since_tizen>
47 protected override void Dispose(DisposeTypes type)
54 if (type == DisposeTypes.Explicit)
57 //Release your own managed resources here.
58 //You should release all of your own disposable objects here.
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.
65 if (swigCPtr.Handle != global::System.IntPtr.Zero)
70 NDalicPINVOKE.delete_Touch(swigCPtr);
72 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
79 internal static Touch GetTouchFromPtr(global::System.IntPtr cPtr)
81 Touch ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Touch;
84 ret = new Touch(cPtr, false);
87 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
92 /// An uninitialized touch instance.<br />
93 /// Calling member functions with an uninitialized touch handle is not allowed.<br />
95 /// <since_tizen> 3 </since_tizen>
96 public Touch() : this(NDalicPINVOKE.new_Touch__SWIG_0(), true)
98 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
101 internal Touch(Touch other) : this(NDalicPINVOKE.new_Touch__SWIG_1(Touch.getCPtr(other)), true)
103 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
107 /// Returns the time (in ms) that the touch event occurred.
109 /// <returns>The time (in ms) that the touch event occurred.</returns>
110 /// <since_tizen> 3 </since_tizen>
111 public uint GetTime()
113 uint ret = NDalicPINVOKE.Touch_GetTime(swigCPtr);
114 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
119 /// Returns the total number of points in this TouchData.
121 /// <returns>The total number of points.</returns>
122 /// <since_tizen> 3 </since_tizen>
123 public uint GetPointCount()
125 uint ret = NDalicPINVOKE.Touch_GetPointCount(swigCPtr);
126 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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 />
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)
141 int ret = NDalicPINVOKE.Touch_GetDeviceId(swigCPtr, point);
142 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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 />
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)
155 PointStateType ret = (PointStateType)NDalicPINVOKE.Touch_GetState(swigCPtr, point);
156 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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 />
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)
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);
176 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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 />
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)
192 Vector2 ret = new Vector2(NDalicPINVOKE.Touch_GetLocalPosition(swigCPtr, point), false);
193 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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 />
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)
206 Vector2 ret = new Vector2(NDalicPINVOKE.Touch_GetScreenPosition(swigCPtr, point), false);
207 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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 />
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)
221 float ret = NDalicPINVOKE.Touch_GetRadius(swigCPtr, point);
222 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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 />
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)
235 Vector2 ret = new Vector2(NDalicPINVOKE.Touch_GetEllipseRadius(swigCPtr, point), false);
236 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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 />
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)
253 float ret = NDalicPINVOKE.Touch_GetPressure(swigCPtr, point);
254 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
258 internal Degree GetAngle(uint point)
260 Degree ret = new Degree(NDalicPINVOKE.Touch_GetAngle(swigCPtr, point), true);
261 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
266 /// Get mouse device's button value (for example, right or left button)
268 /// <param name="point">The point required.</param>
269 /// <returns></returns>
270 /// <since_tizen> 5 </since_tizen>
271 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
272 [EditorBrowsable(EditorBrowsableState.Never)]
273 public MouseButton GetMouseButton(uint point)
275 int ret = NDalicManualPINVOKE.Touch_GetMouseButton(swigCPtr, point);
276 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
277 return (MouseButton)ret;
283 /// Mouse device button type.
285 /// <since_tizen> 5 </since_tizen>
286 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
287 [EditorBrowsable(EditorBrowsableState.Never)]
288 public enum MouseButton
291 /// No mouse button event or invalid data.
293 /// <since_tizen> 5 </since_tizen>
296 /// Primary(Left) mouse button.
298 /// <since_tizen> 5 </since_tizen>
301 /// Secondary(Right) mouse button.
303 /// <since_tizen> 5 </since_tizen>
306 /// Center(Wheel) mouse button.
308 /// <since_tizen> 5 </since_tizen>