Release 4.0.0-preview1-00235
[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         public uint Time
116         {
117             get
118             {
119                 return time;
120             }
121         }
122
123         /// <summary>
124         /// Returns the ID of the device used for the point specified.<br>
125         /// Each point has a unique device ID which specifies the device used for that
126         /// point. This is returned by this method.<br>
127         /// </summary>
128         /// <param name="point">The point required.</param>
129         /// <returns>The device ID of this point.</returns>
130         public int GetDeviceId(uint point)
131         {
132             if (point < points.Count)
133             {
134                 return points[(int)point].DeviceId;
135             }
136             return -1;
137         }
138
139         /// <summary>
140         /// Retrieves the state of the point specified.
141         /// </summary>
142         /// <param name="point">The point required.</param>
143         /// <returns>The state of the point specified.</returns>
144         public PointStateType GetState(uint point)
145         {
146             if (point < points.Count)
147             {
148                 return (Tizen.NUI.PointStateType)(points[(int)point].State);
149             }
150             return PointStateType.Finished;
151         }
152
153         /// <summary>
154         /// Retrieves the view that was underneath the point specified.
155         /// </summary>
156         /// <param name="point">The point required.</param>
157         /// <returns>The view that was underneath the point specified.</returns>
158         public View GetHitView(uint point)
159         {
160             if (point < points.Count)
161             {
162                 return points[(int)point].HitView;
163             }
164             else
165             {
166                 // Return a native empty handle
167                 View view = new View();
168                 view.Reset();
169                 return view;
170             }
171         }
172
173         /// <summary>
174         /// Retrieves the coordinates relative to the top-left of the hit-view at the point specified.
175         /// </summary>
176         /// <param name="point">The point required.</param>
177         /// <returns>The coordinates relative to the top-left of the hit-view of the point specified.</returns>
178         public Vector2 GetLocalPosition(uint point)
179         {
180             if (point < points.Count)
181             {
182                 return points[(int)point].Local;
183             }
184             return new Vector2(0.0f, 0.0f);
185         }
186
187         /// <summary>
188         /// Retrieves the coordinates relative to the top-left of the screen of the point specified.
189         /// </summary>
190         /// <param name="point">The point required.</param>
191         /// <returns>The coordinates relative to the top-left of the screen of the point specified.</returns>
192         public Vector2 GetScreenPosition(uint point)
193         {
194             if (point < points.Count)
195             {
196                 return points[(int)point].Screen;
197             }
198             return new Vector2(0.0f, 0.0f);
199         }
200
201         /// <summary>
202         /// The default constructor.
203         /// </summary>
204         public Hover() : this(NDalicPINVOKE.new_Hover__SWIG_0(), true)
205         {
206             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
207         }
208
209         /// <summary>
210         /// The constructor.
211         /// </summary>
212         /// <param name="time">The time the event occurred.</param>
213         internal Hover(uint time) : this(NDalicPINVOKE.new_Hover__SWIG_1(time), true)
214         {
215             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
216         }
217
218         private TouchPointContainer points
219         {
220             set
221             {
222                 NDalicPINVOKE.Hover_points_set(swigCPtr, TouchPointContainer.getCPtr(value));
223                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
224             }
225             get
226             {
227                 global::System.IntPtr cPtr = NDalicPINVOKE.Hover_points_get(swigCPtr);
228                 TouchPointContainer ret = (cPtr == global::System.IntPtr.Zero) ? null : new TouchPointContainer(cPtr, false);
229                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
230                 return ret;
231             }
232         }
233
234         private uint time
235         {
236             set
237             {
238                 NDalicPINVOKE.Hover_time_set(swigCPtr, value);
239                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
240             }
241             get
242             {
243                 uint ret = NDalicPINVOKE.Hover_time_get(swigCPtr);
244                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
245                 return ret;
246             }
247         }
248
249         /// <summary>
250         /// Returns the total number of points.
251         /// </summary>
252         /// <returns>Total number of points.</returns>
253         public uint GetPointCount()
254         {
255             uint ret = NDalicPINVOKE.Hover_GetPointCount(swigCPtr);
256             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
257             return ret;
258         }
259
260         internal TouchPoint GetPoint(uint point)
261         {
262             TouchPoint ret = new TouchPoint(NDalicPINVOKE.Hover_GetPoint(swigCPtr, point), false);
263             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
264             return ret;
265         }
266
267     }
268
269 }