Release 4.0.0-preview1-00271
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Hover.cs
1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
2 *
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
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
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.
14 *
15 */
16
17 namespace Tizen.NUI
18 {
19     using Tizen.NUI.BaseComponents;
20     /// <summary>
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>
24     /// </summary>
25     public class Hover : global::System.IDisposable
26     {
27         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
28         protected bool swigCMemOwn;
29
30         internal Hover(global::System.IntPtr cPtr, bool cMemoryOwn)
31         {
32             swigCMemOwn = cMemoryOwn;
33             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
34         }
35
36         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Hover obj)
37         {
38             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
39         }
40
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;
45
46         ~Hover()
47         {
48             if(!isDisposeQueued)
49             {
50                 isDisposeQueued = true;
51                 DisposeQueue.Instance.Add(this);
52             }
53         }
54
55         public void Dispose()
56         {
57             //Throw excpetion if Dispose() is called in separate thread.
58             if (!Window.IsInstalled())
59             {
60                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
61             }
62
63             if (isDisposeQueued)
64             {
65                 Dispose(DisposeTypes.Implicit);
66             }
67             else
68             {
69                 Dispose(DisposeTypes.Explicit);
70                 System.GC.SuppressFinalize(this);
71             }
72         }
73
74         protected virtual void Dispose(DisposeTypes type)
75         {
76             if (disposed)
77             {
78                 return;
79             }
80
81             if(type == DisposeTypes.Explicit)
82             {
83                 //Called by User
84                 //Release your own managed resources here.
85                 //You should release all of your own disposable objects here.
86             }
87
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.
91
92             if (swigCPtr.Handle != global::System.IntPtr.Zero)
93             {
94                 if (swigCMemOwn)
95                 {
96                     swigCMemOwn = false;
97                     NDalicPINVOKE.delete_Hover(swigCPtr);
98                 }
99                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
100             }
101             disposed = true;
102         }
103
104
105         internal static Hover GetHoverFromPtr(global::System.IntPtr cPtr)
106         {
107             Hover ret = new Hover(cPtr, false);
108             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
109             return ret;
110         }
111
112         /// <summary>
113         /// The time (in ms) that the hover event occurred.
114         /// </summary>
115         /// <since_tizen> 3 </since_tizen>
116         public uint Time
117         {
118             get
119             {
120                 return time;
121             }
122         }
123
124         /// <summary>
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>
128         /// </summary>
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)
133         {
134             if (point < points.Count)
135             {
136                 return points[(int)point].DeviceId;
137             }
138             return -1;
139         }
140
141         /// <summary>
142         /// Retrieves the state of the point specified.
143         /// </summary>
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)
148         {
149             if (point < points.Count)
150             {
151                 return (Tizen.NUI.PointStateType)(points[(int)point].State);
152             }
153             return PointStateType.Finished;
154         }
155
156         /// <summary>
157         /// Retrieves the view that was underneath the point specified.
158         /// </summary>
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)
163         {
164             if (point < points.Count)
165             {
166                 return points[(int)point].HitView;
167             }
168             else
169             {
170                 // Return a native empty handle
171                 View view = new View();
172                 view.Reset();
173                 return view;
174             }
175         }
176
177         /// <summary>
178         /// Retrieves the coordinates relative to the top-left of the hit-view at the point specified.
179         /// </summary>
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)
184         {
185             if (point < points.Count)
186             {
187                 return points[(int)point].Local;
188             }
189             return new Vector2(0.0f, 0.0f);
190         }
191
192         /// <summary>
193         /// Retrieves the coordinates relative to the top-left of the screen of the point specified.
194         /// </summary>
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)
199         {
200             if (point < points.Count)
201             {
202                 return points[(int)point].Screen;
203             }
204             return new Vector2(0.0f, 0.0f);
205         }
206
207         /// <summary>
208         /// The default constructor.
209         /// </summary>
210         /// <since_tizen> 3 </since_tizen>
211         public Hover() : this(NDalicPINVOKE.new_Hover__SWIG_0(), true)
212         {
213             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
214         }
215
216         /// <summary>
217         /// The constructor.
218         /// </summary>
219         /// <param name="time">The time the event occurred.</param>
220         internal Hover(uint time) : this(NDalicPINVOKE.new_Hover__SWIG_1(time), true)
221         {
222             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
223         }
224
225         private TouchPointContainer points
226         {
227             set
228             {
229                 NDalicPINVOKE.Hover_points_set(swigCPtr, TouchPointContainer.getCPtr(value));
230                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
231             }
232             get
233             {
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();
237                 return ret;
238             }
239         }
240
241         private uint time
242         {
243             set
244             {
245                 NDalicPINVOKE.Hover_time_set(swigCPtr, value);
246                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
247             }
248             get
249             {
250                 uint ret = NDalicPINVOKE.Hover_time_get(swigCPtr);
251                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
252                 return ret;
253             }
254         }
255
256         /// <summary>
257         /// Returns the total number of points.
258         /// </summary>
259         /// <returns>Total number of points.</returns>
260         /// <since_tizen> 3 </since_tizen>
261         public uint GetPointCount()
262         {
263             uint ret = NDalicPINVOKE.Hover_GetPointCount(swigCPtr);
264             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
265             return ret;
266         }
267
268         internal TouchPoint GetPoint(uint point)
269         {
270             TouchPoint ret = new TouchPoint(NDalicPINVOKE.Hover_GetPoint(swigCPtr, point), false);
271             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
272             return ret;
273         }
274
275     }
276
277 }