1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
19 using Tizen.NUI.BaseComponents;
21 /// Hover events are a collection of points at a specific moment in time.<br>
22 /// When a multi event occurs, each point represents the points that are currently being
23 /// hovered or the points where a hover has stopped.<br>
25 public class Hover : global::System.IDisposable
27 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
28 protected bool swigCMemOwn;
30 internal Hover(global::System.IntPtr cPtr, bool cMemoryOwn)
32 swigCMemOwn = cMemoryOwn;
33 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
36 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Hover obj)
38 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
41 //A Flag to check who called Dispose(). (By User or DisposeQueue)
42 private bool isDisposeQueued = false;
43 //A Flat to check if it is already disposed.
44 protected bool disposed = false;
50 isDisposeQueued = true;
51 DisposeQueue.Instance.Add(this);
57 //Throw excpetion if Dispose() is called in separate thread.
58 if (!Window.IsInstalled())
60 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
65 Dispose(DisposeTypes.Implicit);
69 Dispose(DisposeTypes.Explicit);
70 System.GC.SuppressFinalize(this);
74 protected virtual void Dispose(DisposeTypes type)
81 if(type == DisposeTypes.Explicit)
84 //Release your own managed resources here.
85 //You should release all of your own disposable objects here.
88 //Release your own unmanaged resources here.
89 //You should not access any managed member here except static instance.
90 //because the execution order of Finalizes is non-deterministic.
92 if (swigCPtr.Handle != global::System.IntPtr.Zero)
97 NDalicPINVOKE.delete_Hover(swigCPtr);
99 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
105 internal static Hover GetHoverFromPtr(global::System.IntPtr cPtr)
107 Hover ret = new Hover(cPtr, false);
108 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
113 /// The time (in ms) that the hover event occurred.
124 /// Returns the ID of the device used for the Point specified.<br>
125 /// Each point has a unique device ID which specifies the device used for that
126 /// point. This is returned by this method.<br>
128 /// <param name="point">The point required</param>
129 /// <returns>The Device ID of this poin</returns>
130 public int GetDeviceId(uint point)
132 if (point < points.Count)
134 return points[(int)point].DeviceId;
140 /// Retrieves the State of the point specified.
142 /// <param name="point">The point required</param>
143 /// <returns>The state of the point specified</returns>
144 public PointStateType GetState(uint point)
146 if (point < points.Count)
148 return (Tizen.NUI.PointStateType)(points[(int)point].State);
150 return PointStateType.Finished;
154 /// Retrieves the view that was underneath the point specified.
156 /// <param name="point">The point required</param>
157 /// <returns>The view that was underneath the point specified</returns>
158 public View GetHitView(uint point)
160 if (point < points.Count)
162 return points[(int)point].HitView;
166 // Return a native empty handle
167 View view = new View();
174 /// Retrieves the co-ordinates relative to the top-left of the hit-view at the point specified.
176 /// <param name="point">The point required</param>
177 /// <returns>The co-ordinates relative to the top-left of the hit-view of the point specified</returns>
178 public Vector2 GetLocalPosition(uint point)
180 if (point < points.Count)
182 return points[(int)point].Local;
184 return new Vector2(0.0f, 0.0f);
188 /// Retrieves the co-ordinates relative to the top-left of the screen of the point specified.
190 /// <param name="point">The point required</param>
191 /// <returns>The co-ordinates relative to the top-left of the screen of the point specified</returns>
192 public Vector2 GetScreenPosition(uint point)
194 if (point < points.Count)
196 return points[(int)point].Screen;
198 return new Vector2(0.0f, 0.0f);
202 /// Default constructor.
204 public Hover() : this(NDalicPINVOKE.new_Hover__SWIG_0(), true)
206 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
212 /// <param name="time">The time the event occurred</param>
213 internal Hover(uint time) : this(NDalicPINVOKE.new_Hover__SWIG_1(time), true)
215 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
218 private TouchPointContainer points
222 NDalicPINVOKE.Hover_points_set(swigCPtr, TouchPointContainer.getCPtr(value));
223 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
227 global::System.IntPtr cPtr = NDalicPINVOKE.Hover_points_get(swigCPtr);
228 TouchPointContainer ret = (cPtr == global::System.IntPtr.Zero) ? null : new TouchPointContainer(cPtr, false);
229 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
238 NDalicPINVOKE.Hover_time_set(swigCPtr, value);
239 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
243 uint ret = NDalicPINVOKE.Hover_time_get(swigCPtr);
244 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
250 /// Returns the total number of points.
252 /// <returns>Total number of Points</returns>
253 public uint GetPointCount()
255 uint ret = NDalicPINVOKE.Hover_GetPointCount(swigCPtr);
256 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
260 internal TouchPoint GetPoint(uint point)
262 TouchPoint ret = new TouchPoint(NDalicPINVOKE.Hover_GetPoint(swigCPtr, point), false);
263 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();