2 * Copyright(c) 2019 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
33 /// An uninitialized touch instance.<br />
34 /// Calling member functions with an uninitialized touch handle is not allowed.<br />
36 /// <since_tizen> 3 </since_tizen>
37 public Touch() : this(Interop.Touch.new_Touch__SWIG_0(), true)
39 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
42 internal Touch(Touch other) : this(Interop.Touch.new_Touch__SWIG_1(Touch.getCPtr(other)), true)
44 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
47 internal Touch(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.Touch.Touch_SWIGUpcast(cPtr), cMemoryOwn)
52 /// Returns the time (in ms) that the touch event occurred.
54 /// <returns>The time (in ms) that the touch event occurred.</returns>
55 /// <since_tizen> 3 </since_tizen>
58 uint ret = Interop.Touch.Touch_GetTime(swigCPtr);
59 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
64 /// Returns the total number of points in this TouchData.
66 /// <returns>The total number of points.</returns>
67 /// <since_tizen> 3 </since_tizen>
68 public uint GetPointCount()
70 uint ret = Interop.Touch.Touch_GetPointCount(swigCPtr);
71 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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 />
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)
86 int ret = Interop.Touch.Touch_GetDeviceId(swigCPtr, point);
87 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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 />
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)
100 PointStateType ret = (PointStateType)Interop.Touch.Touch_GetState(swigCPtr, point);
101 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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 />
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)
114 //to fix memory leak issue, match the handle count with native side.
115 global::System.IntPtr cPtr = Interop.Touch.Touch_GetHitActor(swigCPtr, point);
116 View ret = this.GetInstanceSafely<View>(cPtr);
117 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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 />
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)
133 Vector2 ret = new Vector2(Interop.Touch.Touch_GetLocalPosition(swigCPtr, point), false);
134 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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 />
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)
147 Vector2 ret = new Vector2(Interop.Touch.Touch_GetScreenPosition(swigCPtr, point), false);
148 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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 />
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)
162 float ret = Interop.Touch.Touch_GetRadius(swigCPtr, point);
163 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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 />
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)
176 Vector2 ret = new Vector2(Interop.Touch.Touch_GetEllipseRadius(swigCPtr, point), false);
177 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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 />
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)
194 float ret = Interop.Touch.Touch_GetPressure(swigCPtr, point);
195 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
200 /// Get mouse device's button value (for example, right or left button)
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)
209 int ret = Interop.Touch.Touch_GetMouseButton(swigCPtr, point);
210 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
211 return (MouseButton)ret;
214 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Touch obj)
216 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
219 internal static Touch GetTouchFromPtr(global::System.IntPtr cPtr)
221 Touch ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Touch;
224 ret = new Touch(cPtr, false);
227 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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)
235 Degree ret = new Degree(Interop.Touch.Touch_GetAngle(swigCPtr, point), true);
236 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
240 /// This will not be public opened.
241 [EditorBrowsable(EditorBrowsableState.Never)]
242 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
244 Interop.Touch.delete_Touch(swigCPtr);
249 /// Mouse device button type.
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
257 /// No mouse button event or invalid data.
259 /// <since_tizen> 5 </since_tizen>
262 /// Primary(Left) mouse button.
264 /// <since_tizen> 5 </since_tizen>
267 /// Secondary(Right) mouse button.
269 /// <since_tizen> 5 </since_tizen>
272 /// Center(Wheel) mouse button.
274 /// <since_tizen> 5 </since_tizen>