Release 4.0.0-preview1-00301
[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 namespace Tizen.NUI
19 {
20     using Tizen.NUI.BaseComponents;
21     /// <summary>
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 />
25     /// </summary>
26     public class Hover : global::System.IDisposable
27     {
28         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
29         /// <summary>
30         /// swigCMemOwn
31         /// </summary>
32         /// <since_tizen> 3 </since_tizen>
33         protected bool swigCMemOwn;
34
35         internal Hover(global::System.IntPtr cPtr, bool cMemoryOwn)
36         {
37             swigCMemOwn = cMemoryOwn;
38             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
39         }
40
41         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Hover obj)
42         {
43             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
44         }
45
46         //A Flag to check who called Dispose(). (By User or DisposeQueue)
47         private bool isDisposeQueued = false;
48         /// <summary>
49         /// A Flat to check if it is already disposed.
50         /// </summary>
51         /// <since_tizen> 3 </since_tizen>
52         protected bool disposed = false;
53
54         /// <summary>
55         /// Dispose.
56         /// </summary>
57         /// <since_tizen> 3 </since_tizen>
58         ~Hover()
59         {
60             if(!isDisposeQueued)
61             {
62                 isDisposeQueued = true;
63                 DisposeQueue.Instance.Add(this);
64             }
65         }
66
67         /// <summary>
68         /// Dispose.
69         /// </summary>
70         /// <since_tizen> 3 </since_tizen>
71         public void Dispose()
72         {
73             //Throw excpetion if Dispose() is called in separate thread.
74             if (!Window.IsInstalled())
75             {
76                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
77             }
78
79             if (isDisposeQueued)
80             {
81                 Dispose(DisposeTypes.Implicit);
82             }
83             else
84             {
85                 Dispose(DisposeTypes.Explicit);
86                 System.GC.SuppressFinalize(this);
87             }
88         }
89
90         /// <summary>
91         /// Dispose.
92         /// </summary>
93         /// <since_tizen> 3 </since_tizen>
94         protected virtual void Dispose(DisposeTypes type)
95         {
96             if (disposed)
97             {
98                 return;
99             }
100
101             if(type == DisposeTypes.Explicit)
102             {
103                 //Called by User
104                 //Release your own managed resources here.
105                 //You should release all of your own disposable objects here.
106             }
107
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.
111
112             if (swigCPtr.Handle != global::System.IntPtr.Zero)
113             {
114                 if (swigCMemOwn)
115                 {
116                     swigCMemOwn = false;
117                     NDalicPINVOKE.delete_Hover(swigCPtr);
118                 }
119                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
120             }
121             disposed = true;
122         }
123
124
125         internal static Hover GetHoverFromPtr(global::System.IntPtr cPtr)
126         {
127             Hover ret = new Hover(cPtr, false);
128             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
129             return ret;
130         }
131
132         /// <summary>
133         /// The time (in ms) that the hover event occurred.
134         /// </summary>
135         /// <since_tizen> 3 </since_tizen>
136         public uint Time
137         {
138             get
139             {
140                 return time;
141             }
142         }
143
144         /// <summary>
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 />
148         /// </summary>
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)
153         {
154             if (point < points.Count)
155             {
156                 return points[(int)point].DeviceId;
157             }
158             return -1;
159         }
160
161         /// <summary>
162         /// Retrieves the state of the point specified.
163         /// </summary>
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)
168         {
169             if (point < points.Count)
170             {
171                 return (Tizen.NUI.PointStateType)(points[(int)point].State);
172             }
173             return PointStateType.Finished;
174         }
175
176         /// <summary>
177         /// Retrieves the view that was underneath the point specified.
178         /// </summary>
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)
183         {
184             if (point < points.Count)
185             {
186                 return points[(int)point].HitView;
187             }
188             else
189             {
190                 // Return a native empty handle
191                 View view = new View();
192                 view.Reset();
193                 return view;
194             }
195         }
196
197         /// <summary>
198         /// Retrieves the coordinates relative to the top-left of the hit-view at the point specified.
199         /// </summary>
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)
204         {
205             if (point < points.Count)
206             {
207                 return points[(int)point].Local;
208             }
209             return new Vector2(0.0f, 0.0f);
210         }
211
212         /// <summary>
213         /// Retrieves the coordinates relative to the top-left of the screen of the point specified.
214         /// </summary>
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)
219         {
220             if (point < points.Count)
221             {
222                 return points[(int)point].Screen;
223             }
224             return new Vector2(0.0f, 0.0f);
225         }
226
227         /// <summary>
228         /// The default constructor.
229         /// </summary>
230         /// <since_tizen> 3 </since_tizen>
231         public Hover() : this(NDalicPINVOKE.new_Hover__SWIG_0(), true)
232         {
233             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
234         }
235
236         /// <summary>
237         /// The constructor.
238         /// </summary>
239         /// <param name="time">The time the event occurred.</param>
240         internal Hover(uint time) : this(NDalicPINVOKE.new_Hover__SWIG_1(time), true)
241         {
242             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
243         }
244
245         private TouchPointContainer points
246         {
247             set
248             {
249                 NDalicPINVOKE.Hover_points_set(swigCPtr, TouchPointContainer.getCPtr(value));
250                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
251             }
252             get
253             {
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();
257                 return ret;
258             }
259         }
260
261         private uint time
262         {
263             set
264             {
265                 NDalicPINVOKE.Hover_time_set(swigCPtr, value);
266                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
267             }
268             get
269             {
270                 uint ret = NDalicPINVOKE.Hover_time_get(swigCPtr);
271                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
272                 return ret;
273             }
274         }
275
276         /// <summary>
277         /// Returns the total number of points.
278         /// </summary>
279         /// <returns>Total number of points.</returns>
280         /// <since_tizen> 3 </since_tizen>
281         public uint GetPointCount()
282         {
283             uint ret = NDalicPINVOKE.Hover_GetPointCount(swigCPtr);
284             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
285             return ret;
286         }
287
288         internal TouchPoint GetPoint(uint point)
289         {
290             TouchPoint ret = new TouchPoint(NDalicPINVOKE.Hover_GetPoint(swigCPtr, point), false);
291             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
292             return ret;
293         }
294
295     }
296
297 }