[NUI] TCSACR-226 code change (#1032)
[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 : Disposable
29     {
30         /// <summary>
31         /// swigCMemOwn
32         /// </summary>
33         /// <since_tizen> 3 </since_tizen>
34         protected bool swigCMemOwn;
35
36         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
37
38         /// <summary>
39         /// The default constructor.
40         /// </summary>
41         /// <since_tizen> 3 </since_tizen>
42         public Hover() : this(Interop.Hover.new_Hover__SWIG_0(), true)
43         {
44             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
45         }
46
47         /// <summary>
48         /// The constructor.
49         /// </summary>
50         /// <param name="time">The time the event occurred.</param>
51         internal Hover(uint time) : this(Interop.Hover.new_Hover__SWIG_1(time), true)
52         {
53             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
54         }
55
56         internal Hover(global::System.IntPtr cPtr, bool cMemoryOwn)
57         {
58             swigCMemOwn = cMemoryOwn;
59             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
60         }
61
62         /// <summary>
63         /// The time (in ms) that the hover event occurred.
64         /// </summary>
65         /// <since_tizen> 3 </since_tizen>
66         public uint Time
67         {
68             get
69             {
70                 return time;
71             }
72         }
73
74         private TouchPointContainer points
75         {
76             set
77             {
78                 Interop.Hover.Hover_points_set(swigCPtr, TouchPointContainer.getCPtr(value));
79                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
80             }
81             get
82             {
83                 global::System.IntPtr cPtr = Interop.Hover.Hover_points_get(swigCPtr);
84                 TouchPointContainer ret = (cPtr == global::System.IntPtr.Zero) ? null : new TouchPointContainer(cPtr, false);
85                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
86                 return ret;
87             }
88         }
89
90         private uint time
91         {
92             set
93             {
94                 Interop.Hover.Hover_time_set(swigCPtr, value);
95                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
96             }
97             get
98             {
99                 uint ret = Interop.Hover.Hover_time_get(swigCPtr);
100                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
101                 return ret;
102             }
103         }
104
105         /// <summary>
106         /// Returns the ID of the device used for the point specified.<br />
107         /// Each point has a unique device ID which specifies the device used for that
108         /// point. This is returned by this method.<br />
109         /// </summary>
110         /// <param name="point">The point required.</param>
111         /// <returns>The device ID of this point.</returns>
112         /// <since_tizen> 3 </since_tizen>
113         public int GetDeviceId(uint point)
114         {
115             if (point < points.Count)
116             {
117                 return points[(int)point].DeviceId;
118             }
119             return -1;
120         }
121
122         /// <summary>
123         /// Retrieves the state of the point specified.
124         /// </summary>
125         /// <param name="point">The point required.</param>
126         /// <returns>The state of the point specified.</returns>
127         /// <since_tizen> 3 </since_tizen>
128         public PointStateType GetState(uint point)
129         {
130             if (point < points.Count)
131             {
132                 return (Tizen.NUI.PointStateType)(points[(int)point].State);
133             }
134             return PointStateType.Finished;
135         }
136
137         /// <summary>
138         /// Retrieves the view that was underneath the point specified.
139         /// </summary>
140         /// <param name="point">The point required.</param>
141         /// <returns>The view that was underneath the point specified.</returns>
142         /// <since_tizen> 3 </since_tizen>
143         public View GetHitView(uint point)
144         {
145             if (point < points.Count)
146             {
147                 return points[(int)point].HitView;
148             }
149             else
150             {
151                 // Return a native empty handle
152                 View view = new View();
153                 view.Reset();
154                 return view;
155             }
156         }
157
158         /// <summary>
159         /// Retrieves the coordinates relative to the top-left of the hit-view at the point specified.
160         /// </summary>
161         /// <param name="point">The point required.</param>
162         /// <returns>The coordinates relative to the top-left of the hit-view of the point specified.</returns>
163         /// <since_tizen> 3 </since_tizen>
164         public Vector2 GetLocalPosition(uint point)
165         {
166             if (point < points.Count)
167             {
168                 return points[(int)point].Local;
169             }
170             return new Vector2(0.0f, 0.0f);
171         }
172
173         /// <summary>
174         /// Retrieves the coordinates relative to the top-left of the screen of the point specified.
175         /// </summary>
176         /// <param name="point">The point required.</param>
177         /// <returns>The coordinates relative to the top-left of the screen of the point specified.</returns>
178         /// <since_tizen> 3 </since_tizen>
179         public Vector2 GetScreenPosition(uint point)
180         {
181             if (point < points.Count)
182             {
183                 return points[(int)point].Screen;
184             }
185             return new Vector2(0.0f, 0.0f);
186         }
187
188         /// <summary>
189         /// Returns the total number of points.
190         /// </summary>
191         /// <returns>Total number of points.</returns>
192         /// <since_tizen> 3 </since_tizen>
193         public uint GetPointCount()
194         {
195             uint ret = Interop.Hover.Hover_GetPointCount(swigCPtr);
196             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
197             return ret;
198         }
199
200         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Hover obj)
201         {
202             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
203         }
204
205         internal static Hover GetHoverFromPtr(global::System.IntPtr cPtr)
206         {
207             Hover ret = new Hover(cPtr, false);
208             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
209             return ret;
210         }
211
212         internal TouchPoint GetPoint(uint point)
213         {
214             TouchPoint ret = new TouchPoint(Interop.Hover.Hover_GetPoint(swigCPtr, point), false);
215             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
216             return ret;
217         }
218
219         /// <summary>
220         /// Dispose.
221         /// </summary>
222         /// <since_tizen> 3 </since_tizen>
223         protected override void Dispose(DisposeTypes type)
224         {
225             if (disposed)
226             {
227                 return;
228             }
229
230             //Release your own unmanaged resources here.
231             //You should not access any managed member here except static instance.
232             //because the execution order of Finalizes is non-deterministic.
233
234             if (swigCPtr.Handle != global::System.IntPtr.Zero)
235             {
236                 if (swigCMemOwn)
237                 {
238                     swigCMemOwn = false;
239                     Interop.Hover.delete_Hover(swigCPtr);
240                 }
241                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
242             }
243             base.Dispose(type);
244         }
245     }
246 }