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.
64 /// <returns>The total number of points.</returns>
65 /// <since_tizen> 3 </since_tizen>
66 public uint GetPointCount()
68 uint ret = Interop.Touch.GetPointCount(SwigCPtr);
69 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
74 /// Returns the ID of the device used for the point specified.<br />
75 /// Each point has a unique device ID, which specifies the device used for that
76 /// point. This is returned by this method.<br />
77 /// If a point is greater than GetPointCount(), then this method will return -1.<br />
79 /// <param name="point">The point required.</param>
80 /// <returns>The device ID of this point.</returns>
81 /// <since_tizen> 3 </since_tizen>
82 public int GetDeviceId(uint point)
84 int ret = Interop.Touch.GetDeviceId(SwigCPtr, point);
85 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
90 /// Retrieves the state of the point specified.<br />
91 /// If a point is greater than GetPointCount(), then this method will return PointState.Finished.<br />
93 /// <param name="point">The point required.</param>
94 /// <returns>The state of the point specified.</returns>
95 /// <since_tizen> 3 </since_tizen>
96 public PointStateType GetState(uint point)
98 PointStateType ret = (PointStateType)Interop.Touch.GetState(SwigCPtr, point);
99 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
104 /// Retrieves the actor that was underneath the point specified.<br />
105 /// If a point is greater than GetPointCount(), then this method will return an empty handle.<br />
107 /// <param name="point">The point required.</param>
108 /// <returns>The actor that was underneath the point specified.</returns>
109 /// <since_tizen> 3 </since_tizen>
110 public View GetHitView(uint point)
112 //to fix memory leak issue, match the handle count with native side.
113 global::System.IntPtr cPtr = Interop.Touch.GetHitActor(SwigCPtr, point);
114 View ret = this.GetInstanceSafely<View>(cPtr);
115 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
120 /// Retrieves the coordinates relative to the top-left of the hit actor at the point specified.<br />
121 /// The top-left of an actor is (0.0, 0.0, 0.5).<br />
122 /// If you require the local coordinates of another actor (for example, the parent of the hit actor),
123 /// then you should use Actor::ScreenToLocal().<br />
124 /// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.<br />
126 /// <param name="point">The point required.</param>
127 /// <returns>The coordinates relative to the top-left of the hit actor of the point specified.</returns>
128 /// <since_tizen> 3 </since_tizen>
129 public Vector2 GetLocalPosition(uint point)
131 Vector2 ret = new Vector2(Interop.Touch.GetLocalPosition(SwigCPtr, point), false);
132 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
137 /// Retrieves the coordinates relative to the top-left of the screen of the point specified.<br />
138 /// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.<br />
140 /// <param name="point">The point required.</param>
141 /// <returns>The coordinates relative to the top-left of the screen of the point specified.</returns>
142 /// <since_tizen> 3 </since_tizen>
143 public Vector2 GetScreenPosition(uint point)
145 Vector2 ret = new Vector2(Interop.Touch.GetScreenPosition(SwigCPtr, point), false);
146 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
151 /// Retrieves the radius of the press point.<br />
152 /// This is the average of both the horizontal and vertical radii of the press point.<br />
153 /// If point is greater than GetPointCount(), then this method will return 0.0f.<br />
155 /// <param name="point">The point required.</param>
156 /// <returns>The radius of the press point.</returns>
157 /// <since_tizen> 3 </since_tizen>
158 public float GetRadius(uint point)
160 float ret = Interop.Touch.GetRadius(SwigCPtr, point);
161 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
166 /// Retrieves both the horizontal and the vertical radii of the press point.<br />
167 /// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.<br />
169 /// <param name="point">The point required.</param>
170 /// <returns>The horizontal and vertical radii of the press point.</returns>
171 /// <since_tizen> 3 </since_tizen>
172 public Vector2 GetEllipseRadius(uint point)
174 Vector2 ret = new Vector2(Interop.Touch.GetEllipseRadius(SwigCPtr, point), false);
175 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
180 /// Retrieves the touch pressure.<br />
181 /// The pressure range starts at 0.0f.<br />
182 /// Normal pressure is defined as 1.0f.<br />
183 /// A value between 0.0f and 1.0f means light pressure has been applied.<br />
184 /// A value greater than 1.0f means more pressure than normal has been applied.<br />
185 /// If point is greater than GetPointCount(), then this method will return 1.0f.<br />
187 /// <param name="point">The point required.</param>
188 /// <returns>The touch pressure.</returns>
189 /// <since_tizen> 3 </since_tizen>
190 public float GetPressure(uint point)
192 float ret = Interop.Touch.GetPressure(SwigCPtr, point);
193 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
198 /// Get mouse device's button value (for example, right or left button)
200 /// <param name="point">The point required.</param>
201 /// <returns></returns>
202 /// <since_tizen> 5 </since_tizen>
203 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
204 [EditorBrowsable(EditorBrowsableState.Never)]
205 public MouseButton GetMouseButton(uint point)
207 int ret = Interop.Touch.GetMouseButton(SwigCPtr, point);
208 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
209 return (MouseButton)ret;
212 internal static Touch GetTouchFromPtr(global::System.IntPtr cPtr)
214 Touch ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Touch;
217 ret = new Touch(cPtr, false);
220 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
224 /// This will be public opened in tizen_next after ACR done. Before ACR, need to be hidden as inhouse API.
225 [EditorBrowsable(EditorBrowsableState.Never)]
226 public Degree GetAngle(uint point)
228 Degree ret = new Degree(Interop.Touch.GetAngle(SwigCPtr, point), true);
229 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
233 /// This will not be public opened.
234 [EditorBrowsable(EditorBrowsableState.Never)]
235 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
237 Interop.Touch.DeleteTouch(swigCPtr);
242 /// Mouse device button type.
244 /// <since_tizen> 5 </since_tizen>
245 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
246 [EditorBrowsable(EditorBrowsableState.Never)]
247 public enum MouseButton
250 /// No mouse button event or invalid data.
252 /// <since_tizen> 5 </since_tizen>
255 /// Primary(Left) mouse button.
257 /// <since_tizen> 5 </since_tizen>
260 /// Secondary(Right) mouse button.
262 /// <since_tizen> 5 </since_tizen>
265 /// Center(Wheel) mouse button.
267 /// <since_tizen> 5 </since_tizen>