1865101f462400a1400de8d058e5926514447395
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Hover.cs
1 /*
2  * Copyright(c) 2017 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 using Tizen.NUI.BaseComponents;
19
20 namespace Tizen.NUI
21 {
22     /// <summary>
23     /// Hover events are a collection of points at a specific moment in time.<br />
24     /// When a multi-event occurs, each point represents the points that are currently being
25     /// hovered or the points where a hover has stopped.<br />
26     /// </summary>
27     /// <since_tizen> 3 </since_tizen>
28     public class Hover : global::System.IDisposable
29     {
30         /// <summary>
31         /// swigCMemOwn
32         /// </summary>
33         /// <since_tizen> 3 </since_tizen>
34         protected bool swigCMemOwn;
35
36         /// <summary>
37         /// A Flat to check if it is already disposed.
38         /// </summary>
39         /// <since_tizen> 3 </since_tizen>
40         protected bool disposed = false;
41
42         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
43
44         //A Flag to check who called Dispose(). (By User or DisposeQueue)
45         private bool isDisposeQueued = false;
46
47         /// <summary>
48         /// The default constructor.
49         /// </summary>
50         /// <since_tizen> 3 </since_tizen>
51         public Hover() : this(Interop.Hover.new_Hover__SWIG_0(), true)
52         {
53             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
54         }
55
56         /// <summary>
57         /// The constructor.
58         /// </summary>
59         /// <param name="time">The time the event occurred.</param>
60         internal Hover(uint time) : this(Interop.Hover.new_Hover__SWIG_1(time), true)
61         {
62             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
63         }
64
65         internal Hover(global::System.IntPtr cPtr, bool cMemoryOwn)
66         {
67             swigCMemOwn = cMemoryOwn;
68             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
69         }
70
71         /// <summary>
72         /// Dispose.
73         /// </summary>
74         /// <since_tizen> 3 </since_tizen>
75         ~Hover()
76         {
77             if(!isDisposeQueued)
78             {
79                 isDisposeQueued = true;
80                 DisposeQueue.Instance.Add(this);
81             }
82         }
83
84         /// <summary>
85         /// The time (in ms) that the hover event occurred.
86         /// </summary>
87         /// <since_tizen> 3 </since_tizen>
88         public uint Time
89         {
90             get
91             {
92                 return time;
93             }
94         }
95
96         private TouchPointContainer points
97         {
98             set
99             {
100                 Interop.Hover.Hover_points_set(swigCPtr, TouchPointContainer.getCPtr(value));
101                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
102             }
103             get
104             {
105                 global::System.IntPtr cPtr = Interop.Hover.Hover_points_get(swigCPtr);
106                 TouchPointContainer ret = (cPtr == global::System.IntPtr.Zero) ? null : new TouchPointContainer(cPtr, false);
107                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
108                 return ret;
109             }
110         }
111
112         private uint time
113         {
114             set
115             {
116                 Interop.Hover.Hover_time_set(swigCPtr, value);
117                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
118             }
119             get
120             {
121                 uint ret = Interop.Hover.Hover_time_get(swigCPtr);
122                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
123                 return ret;
124             }
125         }
126
127         /// <summary>
128         /// Returns the ID of the device used for the point specified.<br />
129         /// Each point has a unique device ID which specifies the device used for that
130         /// point. This is returned by this method.<br />
131         /// </summary>
132         /// <param name="point">The point required.</param>
133         /// <returns>The device ID of this point.</returns>
134         /// <since_tizen> 3 </since_tizen>
135         public int GetDeviceId(uint point)
136         {
137             if (point < points.Count)
138             {
139                 return points[(int)point].DeviceId;
140             }
141             return -1;
142         }
143
144         /// <summary>
145         /// Retrieves the state of the point specified.
146         /// </summary>
147         /// <param name="point">The point required.</param>
148         /// <returns>The state of the point specified.</returns>
149         /// <since_tizen> 3 </since_tizen>
150         public PointStateType GetState(uint point)
151         {
152             if (point < points.Count)
153             {
154                 return (Tizen.NUI.PointStateType)(points[(int)point].State);
155             }
156             return PointStateType.Finished;
157         }
158
159         /// <summary>
160         /// Retrieves the view that was underneath the point specified.
161         /// </summary>
162         /// <param name="point">The point required.</param>
163         /// <returns>The view that was underneath the point specified.</returns>
164         /// <since_tizen> 3 </since_tizen>
165         public View GetHitView(uint point)
166         {
167             if (point < points.Count)
168             {
169                 return points[(int)point].HitView;
170             }
171             else
172             {
173                 // Return a native empty handle
174                 View view = new View();
175                 view.Reset();
176                 return view;
177             }
178         }
179
180         /// <summary>
181         /// Retrieves the coordinates relative to the top-left of the hit-view at the point specified.
182         /// </summary>
183         /// <param name="point">The point required.</param>
184         /// <returns>The coordinates relative to the top-left of the hit-view of the point specified.</returns>
185         /// <since_tizen> 3 </since_tizen>
186         public Vector2 GetLocalPosition(uint point)
187         {
188             if (point < points.Count)
189             {
190                 return points[(int)point].Local;
191             }
192             return new Vector2(0.0f, 0.0f);
193         }
194
195         /// <summary>
196         /// Retrieves the coordinates relative to the top-left of the screen of the point specified.
197         /// </summary>
198         /// <param name="point">The point required.</param>
199         /// <returns>The coordinates relative to the top-left of the screen of the point specified.</returns>
200         /// <since_tizen> 3 </since_tizen>
201         public Vector2 GetScreenPosition(uint point)
202         {
203             if (point < points.Count)
204             {
205                 return points[(int)point].Screen;
206             }
207             return new Vector2(0.0f, 0.0f);
208         }
209
210         /// <summary>
211         /// Returns the total number of points.
212         /// </summary>
213         /// <returns>Total number of points.</returns>
214         /// <since_tizen> 3 </since_tizen>
215         public uint GetPointCount()
216         {
217             uint ret = Interop.Hover.Hover_GetPointCount(swigCPtr);
218             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
219             return ret;
220         }
221
222         /// <summary>
223         /// Dispose.
224         /// </summary>
225         /// <since_tizen> 3 </since_tizen>
226         public void Dispose()
227         {
228             //Throw excpetion if Dispose() is called in separate thread.
229             if (!Window.IsInstalled())
230             {
231                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
232             }
233
234             if (isDisposeQueued)
235             {
236                 Dispose(DisposeTypes.Implicit);
237             }
238             else
239             {
240                 Dispose(DisposeTypes.Explicit);
241                 System.GC.SuppressFinalize(this);
242             }
243         }
244
245         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Hover obj)
246         {
247             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
248         }
249
250         internal static Hover GetHoverFromPtr(global::System.IntPtr cPtr)
251         {
252             Hover ret = new Hover(cPtr, false);
253             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
254             return ret;
255         }
256
257         internal TouchPoint GetPoint(uint point)
258         {
259             TouchPoint ret = new TouchPoint(Interop.Hover.Hover_GetPoint(swigCPtr, point), false);
260             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
261             return ret;
262         }
263
264         /// <summary>
265         /// Dispose.
266         /// </summary>
267         /// <since_tizen> 3 </since_tizen>
268         protected virtual void Dispose(DisposeTypes type)
269         {
270             if (disposed)
271             {
272                 return;
273             }
274
275             if (type == DisposeTypes.Explicit)
276             {
277                 //Called by User
278                 //Release your own managed resources here.
279                 //You should release all of your own disposable objects here.
280             }
281
282             //Release your own unmanaged resources here.
283             //You should not access any managed member here except static instance.
284             //because the execution order of Finalizes is non-deterministic.
285
286             if (swigCPtr.Handle != global::System.IntPtr.Zero)
287             {
288                 if (swigCMemOwn)
289                 {
290                     swigCMemOwn = false;
291                     Interop.Hover.delete_Hover(swigCPtr);
292                 }
293                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
294             }
295             disposed = true;
296         }
297     }
298 }