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 public class Hover : global::System.IDisposable
28 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
32 /// <since_tizen> 3 </since_tizen>
33 protected bool swigCMemOwn;
35 internal Hover(global::System.IntPtr cPtr, bool cMemoryOwn)
37 swigCMemOwn = cMemoryOwn;
38 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
41 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Hover obj)
43 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
46 //A Flag to check who called Dispose(). (By User or DisposeQueue)
47 private bool isDisposeQueued = false;
49 /// A Flat to check if it is already disposed.
51 /// <since_tizen> 3 </since_tizen>
52 protected bool disposed = false;
57 /// <since_tizen> 3 </since_tizen>
62 isDisposeQueued = true;
63 DisposeQueue.Instance.Add(this);
70 /// <since_tizen> 3 </since_tizen>
73 //Throw excpetion if Dispose() is called in separate thread.
74 if (!Window.IsInstalled())
76 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
81 Dispose(DisposeTypes.Implicit);
85 Dispose(DisposeTypes.Explicit);
86 System.GC.SuppressFinalize(this);
93 /// <since_tizen> 3 </since_tizen>
94 protected virtual void Dispose(DisposeTypes type)
101 if(type == DisposeTypes.Explicit)
104 //Release your own managed resources here.
105 //You should release all of your own disposable objects here.
108 //Release your own unmanaged resources here.
109 //You should not access any managed member here except static instance.
110 //because the execution order of Finalizes is non-deterministic.
112 if (swigCPtr.Handle != global::System.IntPtr.Zero)
117 NDalicPINVOKE.delete_Hover(swigCPtr);
119 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
125 internal static Hover GetHoverFromPtr(global::System.IntPtr cPtr)
127 Hover ret = new Hover(cPtr, false);
128 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
133 /// The time (in ms) that the hover event occurred.
135 /// <since_tizen> 3 </since_tizen>
145 /// Returns the ID of the device used for the point specified.<br />
146 /// Each point has a unique device ID which specifies the device used for that
147 /// point. This is returned by this method.<br />
149 /// <param name="point">The point required.</param>
150 /// <returns>The device ID of this point.</returns>
151 /// <since_tizen> 3 </since_tizen>
152 public int GetDeviceId(uint point)
154 if (point < points.Count)
156 return points[(int)point].DeviceId;
162 /// Retrieves the state of the point specified.
164 /// <param name="point">The point required.</param>
165 /// <returns>The state of the point specified.</returns>
166 /// <since_tizen> 3 </since_tizen>
167 public PointStateType GetState(uint point)
169 if (point < points.Count)
171 return (Tizen.NUI.PointStateType)(points[(int)point].State);
173 return PointStateType.Finished;
177 /// Retrieves the view that was underneath the point specified.
179 /// <param name="point">The point required.</param>
180 /// <returns>The view that was underneath the point specified.</returns>
181 /// <since_tizen> 3 </since_tizen>
182 public View GetHitView(uint point)
184 if (point < points.Count)
186 return points[(int)point].HitView;
190 // Return a native empty handle
191 View view = new View();
198 /// Retrieves the coordinates relative to the top-left of the hit-view at the point specified.
200 /// <param name="point">The point required.</param>
201 /// <returns>The coordinates relative to the top-left of the hit-view of the point specified.</returns>
202 /// <since_tizen> 3 </since_tizen>
203 public Vector2 GetLocalPosition(uint point)
205 if (point < points.Count)
207 return points[(int)point].Local;
209 return new Vector2(0.0f, 0.0f);
213 /// Retrieves the coordinates relative to the top-left of the screen of the point specified.
215 /// <param name="point">The point required.</param>
216 /// <returns>The coordinates relative to the top-left of the screen of the point specified.</returns>
217 /// <since_tizen> 3 </since_tizen>
218 public Vector2 GetScreenPosition(uint point)
220 if (point < points.Count)
222 return points[(int)point].Screen;
224 return new Vector2(0.0f, 0.0f);
228 /// The default constructor.
230 /// <since_tizen> 3 </since_tizen>
231 public Hover() : this(NDalicPINVOKE.new_Hover__SWIG_0(), true)
233 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
239 /// <param name="time">The time the event occurred.</param>
240 internal Hover(uint time) : this(NDalicPINVOKE.new_Hover__SWIG_1(time), true)
242 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
245 private TouchPointContainer points
249 NDalicPINVOKE.Hover_points_set(swigCPtr, TouchPointContainer.getCPtr(value));
250 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
254 global::System.IntPtr cPtr = NDalicPINVOKE.Hover_points_get(swigCPtr);
255 TouchPointContainer ret = (cPtr == global::System.IntPtr.Zero) ? null : new TouchPointContainer(cPtr, false);
256 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
265 NDalicPINVOKE.Hover_time_set(swigCPtr, value);
266 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
270 uint ret = NDalicPINVOKE.Hover_time_get(swigCPtr);
271 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
277 /// Returns the total number of points.
279 /// <returns>Total number of points.</returns>
280 /// <since_tizen> 3 </since_tizen>
281 public uint GetPointCount()
283 uint ret = NDalicPINVOKE.Hover_GetPointCount(swigCPtr);
284 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
288 internal TouchPoint GetPoint(uint point)
290 TouchPoint ret = new TouchPoint(NDalicPINVOKE.Hover_GetPoint(swigCPtr, point), false);
291 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();