/* * Copyright(c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ using System.ComponentModel; using System.Runtime.InteropServices; using Tizen.NUI.BaseComponents; namespace Tizen.NUI { /// /// Touch events are a collection of points at a specific moment in time.
/// When a multi-touch event occurs, each point represents the points that are currently being /// touched or the points where a touch has stopped.
///
/// 3 public class Touch : BaseHandle { private global::System.Runtime.InteropServices.HandleRef swigCPtr; internal Touch(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Touch_SWIGUpcast(cPtr), cMemoryOwn) { swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); } internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Touch obj) { return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; } /// /// Dispose. /// /// 3 protected override void Dispose(DisposeTypes type) { if (disposed) { return; } if (type == DisposeTypes.Explicit) { //Called by User //Release your own managed resources here. //You should release all of your own disposable objects here. } //Release your own unmanaged resources here. //You should not access any managed member here except static instance. //because the execution order of Finalizes is non-deterministic. if (swigCPtr.Handle != global::System.IntPtr.Zero) { if (swigCMemOwn) { swigCMemOwn = false; NDalicPINVOKE.delete_Touch(swigCPtr); } swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); } base.Dispose(type); } internal static Touch GetTouchFromPtr(global::System.IntPtr cPtr) { Touch ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Touch; if (ret == null) { ret = new Touch(cPtr, false); } if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// An uninitialized touch instance.
/// Calling member functions with an uninitialized touch handle is not allowed.
///
/// 3 public Touch() : this(NDalicPINVOKE.new_Touch__SWIG_0(), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } internal Touch(Touch other) : this(NDalicPINVOKE.new_Touch__SWIG_1(Touch.getCPtr(other)), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Returns the time (in ms) that the touch event occurred. /// /// The time (in ms) that the touch event occurred. /// 3 public uint GetTime() { uint ret = NDalicPINVOKE.Touch_GetTime(swigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Returns the total number of points in this TouchData. /// /// The total number of points. /// 3 public uint GetPointCount() { uint ret = NDalicPINVOKE.Touch_GetPointCount(swigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Returns the ID of the device used for the point specified.
/// Each point has a unique device ID, which specifies the device used for that /// point. This is returned by this method.
/// If a point is greater than GetPointCount(), then this method will return -1.
///
/// The point required. /// The device ID of this point. /// 3 public int GetDeviceId(uint point) { int ret = NDalicPINVOKE.Touch_GetDeviceId(swigCPtr, point); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Retrieves the state of the point specified.
/// If a point is greater than GetPointCount(), then this method will return PointState.Finished.
///
/// The point required. /// The state of the point specified. /// 3 public PointStateType GetState(uint point) { PointStateType ret = (PointStateType)NDalicPINVOKE.Touch_GetState(swigCPtr, point); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Retrieves the actor that was underneath the point specified.
/// If a point is greater than GetPointCount(), then this method will return an empty handle.
///
/// The point required. /// The actor that was underneath the point specified. /// 3 public View GetHitView(uint point) { //to fix memory leak issue, match the handle count with native side. global::System.IntPtr cPtr = NDalicPINVOKE.Touch_GetHitActor(swigCPtr, point); HandleRef CPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); View ret = Registry.GetManagedBaseHandleFromNativePtr(CPtr.Handle) as View; NDalicPINVOKE.delete_BaseHandle(CPtr); CPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Retrieves the coordinates relative to the top-left of the hit actor at the point specified.
/// The top-left of an actor is (0.0, 0.0, 0.5).
/// If you require the local coordinates of another actor (for example, the parent of the hit actor), /// then you should use Actor::ScreenToLocal().
/// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.
///
/// The point required. /// The coordinates relative to the top-left of the hit actor of the point specified. /// 3 public Vector2 GetLocalPosition(uint point) { Vector2 ret = new Vector2(NDalicPINVOKE.Touch_GetLocalPosition(swigCPtr, point), false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Retrieves the coordinates relative to the top-left of the screen of the point specified.
/// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.
///
/// The point required. /// The coordinates relative to the top-left of the screen of the point specified. /// 3 public Vector2 GetScreenPosition(uint point) { Vector2 ret = new Vector2(NDalicPINVOKE.Touch_GetScreenPosition(swigCPtr, point), false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Retrieves the radius of the press point.
/// This is the average of both the horizontal and vertical radii of the press point.
/// If point is greater than GetPointCount(), then this method will return 0.0f.
///
/// The point required. /// The radius of the press point. /// 3 public float GetRadius(uint point) { float ret = NDalicPINVOKE.Touch_GetRadius(swigCPtr, point); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Retrieves both the horizontal and the vertical radii of the press point.
/// If a point is greater than GetPointCount(), then this method will return Vector2.Zero.
///
/// The point required. /// The horizontal and vertical radii of the press point. /// 3 public Vector2 GetEllipseRadius(uint point) { Vector2 ret = new Vector2(NDalicPINVOKE.Touch_GetEllipseRadius(swigCPtr, point), false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Retrieves the touch pressure.
/// The pressure range starts at 0.0f.
/// Normal pressure is defined as 1.0f.
/// A value between 0.0f and 1.0f means light pressure has been applied.
/// A value greater than 1.0f means more pressure than normal has been applied.
/// If point is greater than GetPointCount(), then this method will return 1.0f.
///
/// The point required. /// The touch pressure. /// 3 public float GetPressure(uint point) { float ret = NDalicPINVOKE.Touch_GetPressure(swigCPtr, point); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } internal Degree GetAngle(uint point) { Degree ret = new Degree(NDalicPINVOKE.Touch_GetAngle(swigCPtr, point), true); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Get mouse device's button value (ex: right/left button) /// /// The point required /// /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] public MouseButtonType GetMouseButton(uint point) { int ret = NDalicManualPINVOKE.Touch_GetMouseButton(swigCPtr, point); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return (MouseButtonType)ret; } } /// /// Mouse device button type /// /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] public enum MouseButtonType { /// /// No mouse button event or invalid data /// Invalid = -1, /// /// Left mouse button /// LeftButton = 1, /// /// Center(Wheel) mouse button /// CenterButton = 2, /// /// Right mouse button /// RightButton = 3, /// /// Reserved mouse button for different mouse devices /// Reserved = 4, } }