2 * Copyright(c) 2017 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.
20 using Tizen.NUI.BaseComponents;
22 /// Hover events are a collection of points at a specific moment in time.<br />
23 /// When a multi-event occurs, each point represents the points that are currently being
24 /// hovered or the points where a hover has stopped.<br />
26 /// <since_tizen> 3 </since_tizen>
27 public class Hover : global::System.IDisposable
29 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
33 /// <since_tizen> 3 </since_tizen>
34 protected bool swigCMemOwn;
36 internal Hover(global::System.IntPtr cPtr, bool cMemoryOwn)
38 swigCMemOwn = cMemoryOwn;
39 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
42 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Hover obj)
44 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
47 //A Flag to check who called Dispose(). (By User or DisposeQueue)
48 private bool isDisposeQueued = false;
50 /// A Flat to check if it is already disposed.
52 /// <since_tizen> 3 </since_tizen>
53 protected bool disposed = false;
58 /// <since_tizen> 3 </since_tizen>
63 isDisposeQueued = true;
64 DisposeQueue.Instance.Add(this);
71 /// <since_tizen> 3 </since_tizen>
74 //Throw excpetion if Dispose() is called in separate thread.
75 if (!Window.IsInstalled())
77 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
82 Dispose(DisposeTypes.Implicit);
86 Dispose(DisposeTypes.Explicit);
87 System.GC.SuppressFinalize(this);
94 /// <since_tizen> 3 </since_tizen>
95 protected virtual void Dispose(DisposeTypes type)
102 if(type == DisposeTypes.Explicit)
105 //Release your own managed resources here.
106 //You should release all of your own disposable objects here.
109 //Release your own unmanaged resources here.
110 //You should not access any managed member here except static instance.
111 //because the execution order of Finalizes is non-deterministic.
113 if (swigCPtr.Handle != global::System.IntPtr.Zero)
118 NDalicPINVOKE.delete_Hover(swigCPtr);
120 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
126 internal static Hover GetHoverFromPtr(global::System.IntPtr cPtr)
128 Hover ret = new Hover(cPtr, false);
129 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
134 /// The time (in ms) that the hover event occurred.
136 /// <since_tizen> 3 </since_tizen>
146 /// Returns the ID of the device used for the point specified.<br />
147 /// Each point has a unique device ID which specifies the device used for that
148 /// point. This is returned by this method.<br />
150 /// <param name="point">The point required.</param>
151 /// <returns>The device ID of this point.</returns>
152 /// <since_tizen> 3 </since_tizen>
153 public int GetDeviceId(uint point)
155 if (point < points.Count)
157 return points[(int)point].DeviceId;
163 /// Retrieves the state of the point specified.
165 /// <param name="point">The point required.</param>
166 /// <returns>The state of the point specified.</returns>
167 /// <since_tizen> 3 </since_tizen>
168 public PointStateType GetState(uint point)
170 if (point < points.Count)
172 return (Tizen.NUI.PointStateType)(points[(int)point].State);
174 return PointStateType.Finished;
178 /// Retrieves the view that was underneath the point specified.
180 /// <param name="point">The point required.</param>
181 /// <returns>The view that was underneath the point specified.</returns>
182 /// <since_tizen> 3 </since_tizen>
183 public View GetHitView(uint point)
185 if (point < points.Count)
187 return points[(int)point].HitView;
191 // Return a native empty handle
192 View view = new View();
199 /// Retrieves the coordinates relative to the top-left of the hit-view at the point specified.
201 /// <param name="point">The point required.</param>
202 /// <returns>The coordinates relative to the top-left of the hit-view of the point specified.</returns>
203 /// <since_tizen> 3 </since_tizen>
204 public Vector2 GetLocalPosition(uint point)
206 if (point < points.Count)
208 return points[(int)point].Local;
210 return new Vector2(0.0f, 0.0f);
214 /// Retrieves the coordinates relative to the top-left of the screen of the point specified.
216 /// <param name="point">The point required.</param>
217 /// <returns>The coordinates relative to the top-left of the screen of the point specified.</returns>
218 /// <since_tizen> 3 </since_tizen>
219 public Vector2 GetScreenPosition(uint point)
221 if (point < points.Count)
223 return points[(int)point].Screen;
225 return new Vector2(0.0f, 0.0f);
229 /// The default constructor.
231 /// <since_tizen> 3 </since_tizen>
232 public Hover() : this(NDalicPINVOKE.new_Hover__SWIG_0(), true)
234 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
240 /// <param name="time">The time the event occurred.</param>
241 internal Hover(uint time) : this(NDalicPINVOKE.new_Hover__SWIG_1(time), true)
243 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
246 private TouchPointContainer points
250 NDalicPINVOKE.Hover_points_set(swigCPtr, TouchPointContainer.getCPtr(value));
251 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
255 global::System.IntPtr cPtr = NDalicPINVOKE.Hover_points_get(swigCPtr);
256 TouchPointContainer ret = (cPtr == global::System.IntPtr.Zero) ? null : new TouchPointContainer(cPtr, false);
257 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
266 NDalicPINVOKE.Hover_time_set(swigCPtr, value);
267 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
271 uint ret = NDalicPINVOKE.Hover_time_get(swigCPtr);
272 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
278 /// Returns the total number of points.
280 /// <returns>Total number of points.</returns>
281 /// <since_tizen> 3 </since_tizen>
282 public uint GetPointCount()
284 uint ret = NDalicPINVOKE.Hover_GetPointCount(swigCPtr);
285 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
289 internal TouchPoint GetPoint(uint point)
291 TouchPoint ret = new TouchPoint(NDalicPINVOKE.Hover_GetPoint(swigCPtr, point), false);
292 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();