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