2 * Copyright(c) 2021 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 Tizen.NUI.BaseComponents;
23 /// Touch events are a collection of points at a specific moment in time.<br />
24 /// When a multi-touch event occurs, each point represents the points that are currently being
25 /// touched or the points where a touch has stopped.<br />
27 /// <since_tizen> 3 </since_tizen>
28 public class Touch : BaseHandle
31 /// An uninitialized touch instance.<br />
32 /// Calling member functions with an uninitialized touch handle is not allowed.<br />
34 /// <since_tizen> 3 </since_tizen>
35 public Touch() : this(Interop.Touch.NewTouch(), true)
37 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
40 internal Touch(Touch other) : this(Interop.Touch.NewTouch(Touch.getCPtr(other)), true)
42 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
45 internal Touch(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.Touch.Upcast(cPtr), cMemoryOwn)
50 /// Returns the time (in ms) that the touch event occurred.
52 /// <returns>The time (in ms) that the touch event occurred.</returns>
53 /// <since_tizen> 3 </since_tizen>
56 uint ret = Interop.Touch.GetTime(SwigCPtr);
57 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
62 /// Returns the total number of points in this TouchData.
63 /// Point means the touched point.
64 /// If there is one touch point, the point index is 0.
65 /// If there are two touch points, the point index has 0 and 1.
67 /// <returns>The total number of points.</returns>
68 /// <since_tizen> 3 </since_tizen>
69 public uint GetPointCount()
71 uint ret = Interop.Touch.GetPointCount(SwigCPtr);
72 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
77 /// Returns the ID of the device used for the point specified.<br />
78 /// Each point has a unique device ID, which specifies the device used for that
79 /// point. This is returned by this method.<br />
80 /// If a point is greater than GetPointCount(), then this method will return -1.<br />
82 /// <param name="point">The index of a touch point</param>
83 /// <returns>The device ID of this point.</returns>
84 /// <since_tizen> 3 </since_tizen>
85 public int GetDeviceId(uint point)
87 int ret = Interop.Touch.GetDeviceId(SwigCPtr, point);
88 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
93 /// Retrieves the state of the point specified.<br />
94 /// If a point is greater than GetPointCount(), then this method will return PointState.Finished.<br />
96 /// <param name="point">The index of a touch point.</param>
97 /// <returns>The state of the point specified.</returns>
98 /// <since_tizen> 3 </since_tizen>
99 public PointStateType GetState(uint point)
101 PointStateType ret = (PointStateType)Interop.Touch.GetState(SwigCPtr, point);
102 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
107 /// Retrieves the view that was underneath the point specified.<br />
108 /// If a point is greater than GetPointCount(), then this method will return an empty handle.<br />
110 /// <param name="point">The index of a touch point.</param>
111 /// <returns>The view that was underneath the point specified.</returns>
112 /// <since_tizen> 3 </since_tizen>
113 public View GetHitView(uint point)
115 //to fix memory leak issue, match the handle count with native side.
116 global::System.IntPtr cPtr = Interop.Touch.GetHitActor(SwigCPtr, point);
117 View ret = this.GetInstanceSafely<View>(cPtr);
118 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
123 /// Retrieves the coordinates relative to the top-left of the hit view at the point specified.<br />
124 /// The top-left of an view is (0.0, 0.0, 0.5).<br />
125 /// If you require the local coordinates of another view (for example, the parent of the hit view),
126 /// then you should use ScreenToLocal().<br />
127 /// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.<br />
129 /// <param name="point">The index of a touch point.</param>
130 /// <returns>The coordinates relative to the top-left of the hit view of the point specified.</returns>
131 /// <since_tizen> 3 </since_tizen>
132 public Vector2 GetLocalPosition(uint point)
134 Vector2 ret = new Vector2(Interop.Touch.GetLocalPosition(SwigCPtr, point), false);
135 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
140 /// Retrieves the coordinates relative to the top-left of the screen of the point specified.<br />
141 /// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.<br />
143 /// <param name="point">The index of a touch point.</param>
144 /// <returns>The coordinates relative to the top-left of the screen of the point specified.</returns>
145 /// <since_tizen> 3 </since_tizen>
146 public Vector2 GetScreenPosition(uint point)
148 Vector2 ret = new Vector2(Interop.Touch.GetScreenPosition(SwigCPtr, point), false);
149 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
154 /// Retrieves the radius of the press point.<br />
155 /// This is the average of both the horizontal and vertical radii of the press point.<br />
156 /// If point is greater than GetPointCount(), then this method will return 0.0f.<br />
158 /// <param name="point">The index of a touch point.</param>
159 /// <returns>The radius of the press point.</returns>
160 /// <since_tizen> 3 </since_tizen>
161 public float GetRadius(uint point)
163 float ret = Interop.Touch.GetRadius(SwigCPtr, point);
164 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
169 /// Retrieves both the horizontal and the vertical radii of the press point.<br />
170 /// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.<br />
172 /// <param name="point">The index of a touch point.</param>
173 /// <returns>The horizontal and vertical radii of the press point.</returns>
174 /// <since_tizen> 3 </since_tizen>
175 public Vector2 GetEllipseRadius(uint point)
177 Vector2 ret = new Vector2(Interop.Touch.GetEllipseRadius(SwigCPtr, point), false);
178 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
183 /// Retrieves the touch pressure.<br />
184 /// The pressure range starts at 0.0f.<br />
185 /// Normal pressure is defined as 1.0f.<br />
186 /// A value between 0.0f and 1.0f means light pressure has been applied.<br />
187 /// A value greater than 1.0f means more pressure than normal has been applied.<br />
188 /// If point is greater than GetPointCount(), then this method will return 1.0f.<br />
190 /// <param name="point">The index of a touch point.</param>
191 /// <returns>The touch pressure.</returns>
192 /// <since_tizen> 3 </since_tizen>
193 public float GetPressure(uint point)
195 float ret = Interop.Touch.GetPressure(SwigCPtr, point);
196 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
201 /// Get mouse device's button value (for example, right or left button)
203 /// <param name="point">The index of a touch point.</param>
204 /// <returns></returns>
205 /// <since_tizen> 5 </since_tizen>
206 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
207 [EditorBrowsable(EditorBrowsableState.Never)]
208 public MouseButton GetMouseButton(uint point)
210 int ret = Interop.Touch.GetMouseButton(SwigCPtr, point);
211 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
212 return (MouseButton)ret;
216 /// Gets the device class type from which the mouse/touch event is originated.
218 /// <param name="point">The index of a touch point.</param>
219 [EditorBrowsable(EditorBrowsableState.Never)]
220 public DeviceClassType GetDeviceClass(uint point)
222 int ret = Interop.Touch.GetDeviceClass(SwigCPtr, point);
223 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
224 return (DeviceClassType)ret;
228 /// Gets the subclass type of the device from which the mouse/touch event is originated.
230 /// <param name="point">The index of a touch point.</param>
231 [EditorBrowsable(EditorBrowsableState.Never)]
232 public DeviceSubClassType GetDeviceSubClass(uint point)
234 int ret = Interop.Touch.GetDeviceSubClass(SwigCPtr, point);
235 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
236 return (DeviceSubClassType)ret;
240 internal static Touch GetTouchFromPtr(global::System.IntPtr cPtr)
242 Touch ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Touch;
245 ret = new Touch(cPtr, false);
248 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
252 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
253 [EditorBrowsable(EditorBrowsableState.Never)]
254 public Degree GetAngle(uint point)
256 Degree ret = new Degree(Interop.Touch.GetAngle(SwigCPtr, point), true);
257 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
261 /// This will not be public opened.
262 [EditorBrowsable(EditorBrowsableState.Never)]
263 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
265 Interop.Touch.DeleteTouch(swigCPtr);
270 /// Mouse device button type.
272 /// <since_tizen> 5 </since_tizen>
273 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
274 [EditorBrowsable(EditorBrowsableState.Never)]
275 public enum MouseButton
278 /// No mouse button event or invalid data.
280 /// <since_tizen> 5 </since_tizen>
283 /// Primary(Left) mouse button.
285 /// <since_tizen> 5 </since_tizen>
288 /// Secondary(Right) mouse button.
290 /// <since_tizen> 5 </since_tizen>
293 /// Center(Wheel) mouse button.
295 /// <since_tizen> 5 </since_tizen>