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.
115 /// <since_tizen> 3 </since_tizen>
125 /// Returns the ID of the device used for the point specified.<br>
126 /// Each point has a unique device ID which specifies the device used for that
127 /// point. This is returned by this method.<br>
129 /// <param name="point">The point required.</param>
130 /// <returns>The device ID of this point.</returns>
131 /// <since_tizen> 3 </since_tizen>
132 public int GetDeviceId(uint point)
134 if (point < points.Count)
136 return points[(int)point].DeviceId;
142 /// Retrieves the state of the point specified.
144 /// <param name="point">The point required.</param>
145 /// <returns>The state of the point specified.</returns>
146 /// <since_tizen> 3 </since_tizen>
147 public PointStateType GetState(uint point)
149 if (point < points.Count)
151 return (Tizen.NUI.PointStateType)(points[(int)point].State);
153 return PointStateType.Finished;
157 /// Retrieves the view that was underneath the point specified.
159 /// <param name="point">The point required.</param>
160 /// <returns>The view that was underneath the point specified.</returns>
161 /// <since_tizen> 3 </since_tizen>
162 public View GetHitView(uint point)
164 if (point < points.Count)
166 return points[(int)point].HitView;
170 // Return a native empty handle
171 View view = new View();
178 /// Retrieves the coordinates relative to the top-left of the hit-view at the point specified.
180 /// <param name="point">The point required.</param>
181 /// <returns>The coordinates relative to the top-left of the hit-view of the point specified.</returns>
182 /// <since_tizen> 3 </since_tizen>
183 public Vector2 GetLocalPosition(uint point)
185 if (point < points.Count)
187 return points[(int)point].Local;
189 return new Vector2(0.0f, 0.0f);
193 /// Retrieves the coordinates relative to the top-left of the screen of the point specified.
195 /// <param name="point">The point required.</param>
196 /// <returns>The coordinates relative to the top-left of the screen of the point specified.</returns>
197 /// <since_tizen> 3 </since_tizen>
198 public Vector2 GetScreenPosition(uint point)
200 if (point < points.Count)
202 return points[(int)point].Screen;
204 return new Vector2(0.0f, 0.0f);
208 /// The default constructor.
210 /// <since_tizen> 3 </since_tizen>
211 public Hover() : this(NDalicPINVOKE.new_Hover__SWIG_0(), true)
213 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
219 /// <param name="time">The time the event occurred.</param>
220 internal Hover(uint time) : this(NDalicPINVOKE.new_Hover__SWIG_1(time), true)
222 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
225 private TouchPointContainer points
229 NDalicPINVOKE.Hover_points_set(swigCPtr, TouchPointContainer.getCPtr(value));
230 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
234 global::System.IntPtr cPtr = NDalicPINVOKE.Hover_points_get(swigCPtr);
235 TouchPointContainer ret = (cPtr == global::System.IntPtr.Zero) ? null : new TouchPointContainer(cPtr, false);
236 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
245 NDalicPINVOKE.Hover_time_set(swigCPtr, value);
246 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
250 uint ret = NDalicPINVOKE.Hover_time_get(swigCPtr);
251 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
257 /// Returns the total number of points.
259 /// <returns>Total number of points.</returns>
260 /// <since_tizen> 3 </since_tizen>
261 public uint GetPointCount()
263 uint ret = NDalicPINVOKE.Hover_GetPointCount(swigCPtr);
264 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
268 internal TouchPoint GetPoint(uint point)
270 TouchPoint ret = new TouchPoint(NDalicPINVOKE.Hover_GetPoint(swigCPtr, point), false);
271 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();