Merge "Add C# binding for VideoView.Underlay property."
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Position2D.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
21     /// <summary>
22     /// Position2D is a two-dimensional vector.
23     /// </summary>
24     public class Position2D : global::System.IDisposable
25     {
26         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
27         /// <summary>
28         /// swigCMemOwn
29         /// </summary>
30         /// <since_tizen> 3 </since_tizen>
31         protected bool swigCMemOwn;
32
33         internal Position2D(global::System.IntPtr cPtr, bool cMemoryOwn)
34         {
35             swigCMemOwn = cMemoryOwn;
36             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
37         }
38
39         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Position2D obj)
40         {
41             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
42         }
43
44         //A Flag to check who called Dispose(). (By User or DisposeQueue)
45         private bool isDisposeQueued = false;
46         /// <summary>
47         /// <since_tizen> 3 </since_tizen>
48         /// A Flat to check if it is already disposed.
49         /// </summary>
50         protected bool disposed = false;
51
52         /// <summary>
53         /// Dispose.
54         /// </summary>
55         /// <since_tizen> 3 </since_tizen>
56         ~Position2D()
57         {
58             if (!isDisposeQueued)
59             {
60                 isDisposeQueued = true;
61                 DisposeQueue.Instance.Add(this);
62             }
63         }
64
65         /// <summary>
66         /// Dispose.
67         /// </summary>
68         /// <since_tizen> 3 </since_tizen>
69         public void Dispose()
70         {
71             //Throw excpetion if Dispose() is called in separate thread.
72             if (!Window.IsInstalled())
73             {
74                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
75             }
76
77             if (isDisposeQueued)
78             {
79                 Dispose(DisposeTypes.Implicit);
80             }
81             else
82             {
83                 Dispose(DisposeTypes.Explicit);
84                 System.GC.SuppressFinalize(this);
85             }
86         }
87
88         /// <summary>
89         /// Dispose.
90         /// </summary>
91         /// <param name="type">The dispose type.</param>
92         /// <since_tizen> 3 </since_tizen>
93         protected virtual void Dispose(DisposeTypes type)
94         {
95             if (disposed)
96             {
97                 return;
98             }
99
100             if (type == DisposeTypes.Explicit)
101             {
102                 //Called by User
103                 //Release your own managed resources here.
104                 //You should release all of your own disposable objects here.
105             }
106
107             //Release your own unmanaged resources here.
108             //You should not access any managed member here except static instance.
109             //because the execution order of Finalizes is non-deterministic.
110
111             if (swigCPtr.Handle != global::System.IntPtr.Zero)
112             {
113                 if (swigCMemOwn)
114                 {
115                     swigCMemOwn = false;
116                     NDalicPINVOKE.delete_Vector2(swigCPtr);
117                 }
118                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
119             }
120             disposed = true;
121         }
122
123         /// <summary>
124         /// The addition operator.
125         /// </summary>
126         /// <param name="arg1">The vector to add.</param>
127         /// <param name="arg2">The vector to add.</param>
128         /// <returns>The vector containing the result of the addition.</returns>
129         /// <since_tizen> 3 </since_tizen>
130         public static Position2D operator +(Position2D arg1, Position2D arg2)
131         {
132             return arg1.Add(arg2);
133         }
134
135         /// <summary>
136         /// The subtraction operator.
137         /// </summary>
138         /// <param name="arg1">The vector to subtract.</param>
139         /// <param name="arg2">The vector to subtract.</param>
140         /// <returns>The vector containing the result of the subtraction.</returns>
141         /// <since_tizen> 3 </since_tizen>
142         public static Position2D operator -(Position2D arg1, Position2D arg2)
143         {
144             return arg1.Subtract(arg2);
145         }
146
147         /// <summary>
148         /// The unary negation operator.
149         /// </summary>
150         /// <param name="arg1">The vector to negate.</param>
151         /// <returns>The vector containing the negation.</returns>
152         /// <since_tizen> 3 </since_tizen>
153         public static Position2D operator -(Position2D arg1)
154         {
155             return arg1.Subtract();
156         }
157
158         /// <summary>
159         /// The multiplication operator.
160         /// </summary>
161         /// <param name="arg1">The vector to multiply.</param>
162         /// <param name="arg2">The vector to multiply.</param>
163         /// <returns>The vector containing the result of the multiplication.</returns>
164         /// <since_tizen> 3 </since_tizen>
165         public static Position2D operator *(Position2D arg1, Position2D arg2)
166         {
167             return arg1.Multiply(arg2);
168         }
169
170         /// <summary>
171         /// The multiplication operator.
172         /// </summary>
173         /// <param name="arg1">The vector to multiply.</param>
174         /// <param name="arg2">The integer value to scale the vector.</param>
175         /// <returns>The vector containing the result of the multiplication.</returns>
176         /// <since_tizen> 3 </since_tizen>
177         public static Position2D operator *(Position2D arg1, int arg2)
178         {
179             return arg1.Multiply(arg2);
180         }
181
182         /// <summary>
183         /// The division operator.
184         /// </summary>
185         /// <param name="arg1">The vector to divide.</param>
186         /// <param name="arg2">The vector to divide.</param>
187         /// <returns>The vector containing the result of the division.</returns>
188         /// <since_tizen> 3 </since_tizen>
189         public static Position2D operator /(Position2D arg1, Position2D arg2)
190         {
191             return arg1.Divide(arg2);
192         }
193
194         /// <summary>
195         /// The division operator.
196         /// </summary>
197         /// <param name="arg1">The vector to divide.</param>
198         /// <param name="arg2">The integer value to scale the vector by.</param>
199         /// <returns>The vector containing the result of the division.</returns>
200         /// <since_tizen> 3 </since_tizen>
201         public static Position2D operator /(Position2D arg1, int arg2)
202         {
203             return arg1.Divide(arg2);
204         }
205
206         /// <summary>
207         /// The const array subscript operator overload. Should be 0, or 1.
208         /// </summary>
209         /// <param name="index">The subscript index.</param>
210         /// <returns>The float at the given index.</returns>
211         /// <since_tizen> 3 </since_tizen>
212         public float this[uint index]
213         {
214             get
215             {
216                 return ValueOfIndex(index);
217             }
218         }
219
220         internal static Position2D GetPosition2DFromPtr(global::System.IntPtr cPtr)
221         {
222             Position2D ret = new Position2D(cPtr, false);
223             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
224             return ret;
225         }
226
227         /// <summary>
228         /// The constructor.
229         /// </summary>
230         /// <since_tizen> 3 </since_tizen>
231         public Position2D() : this(NDalicPINVOKE.new_Vector2__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="x">x component</param>
240         /// <param name="y">y component</param>
241         /// <since_tizen> 3 </since_tizen>
242         public Position2D(int x, int y) : this(NDalicPINVOKE.new_Vector2__SWIG_1((float)x, (float)y), true)
243         {
244             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
245         }
246
247         /// <summary>
248         /// The constructor.
249         /// </summary>
250         /// <param name="position">Position to create this vector from</param>
251         /// <since_tizen> 3 </since_tizen>
252         public Position2D(Position position) : this(NDalicPINVOKE.new_Vector2__SWIG_3(Position.getCPtr(position)), true)
253         {
254             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
255         }
256
257         private Position2D Add(Position2D rhs)
258         {
259             Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Add(swigCPtr, Position2D.getCPtr(rhs)), true);
260             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
261             return ret;
262         }
263
264         private Position2D Subtract(Position2D rhs)
265         {
266             Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
267             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
268             return ret;
269         }
270
271
272         private Position2D Multiply(Position2D rhs)
273         {
274             Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
275             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
276             return ret;
277         }
278
279         private Position2D Multiply(int rhs)
280         {
281             Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
282             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
283             return ret;
284         }
285
286
287         private Position2D Divide(Position2D rhs)
288         {
289             Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
290             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
291             return ret;
292         }
293
294         private Position2D Divide(int rhs)
295         {
296             Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
297             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
298             return ret;
299         }
300
301         private Position2D Subtract()
302         {
303             Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
304             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
305             return ret;
306         }
307
308         /// <summary>
309         /// Compares if the rhs is equal to.
310         /// </summary>
311         /// <param name="rhs">The vector to compare</param>
312         /// <returns>Returns true if the two vectors are equal, otherwise false</returns>
313         /// <since_tizen> 3 </since_tizen>
314         public bool EqualTo(Position2D rhs)
315         {
316             bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Position2D.getCPtr(rhs));
317             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
318             return ret;
319         }
320
321         /// <summary>
322         /// Compares if the rhs is not equal to.
323         /// </summary>
324         /// <param name="rhs">The vector to compare.</param>
325         /// <returns>Returns true if the two vectors are not equal, otherwise false.</returns>
326         /// <since_tizen> 3 </since_tizen>
327         public bool NotEqualTo(Position2D rhs)
328         {
329             bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Position2D.getCPtr(rhs));
330             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
331             return ret;
332         }
333
334         private int ValueOfIndex(uint index)
335         {
336             int ret = (int)NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
337             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
338             return ret;
339         }
340
341         /// <summary>
342         /// The x component.
343         /// </summary>
344         /// <since_tizen> 3 </since_tizen>
345         public int X
346         {
347             set
348             {
349                 NDalicPINVOKE.Vector2_X_set(swigCPtr, (float)value);
350                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
351             }
352             get
353             {
354                 float ret = NDalicPINVOKE.Vector2_X_get(swigCPtr);
355                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
356                 return (int)ret;
357             }
358         }
359
360         /// <summary>
361         /// The y component.
362         /// </summary>
363         /// <since_tizen> 3 </since_tizen>
364         public int Y
365         {
366             set
367             {
368                 NDalicPINVOKE.Vector2_Y_set(swigCPtr, (float)value);
369                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
370             }
371             get
372             {
373                 float ret = NDalicPINVOKE.Vector2_Y_get(swigCPtr);
374                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
375                 return (int)ret;
376             }
377         }
378
379         /// <summary>
380         /// Converts a Position2D instance to a Vector2 instance.
381         /// </summary>
382         /// <param name="position2d">An object of the Position2D type.</param>
383         /// <returns>return an object of the Vector2 type</returns>
384         /// <since_tizen> 3 </since_tizen>
385         public static implicit operator Vector2(Position2D position2d)
386         {
387             return new Vector2((float)position2d.X, (float)position2d.Y);
388         }
389
390         /// <summary>
391         /// Converts a Vector2 instance to a Position2D instance.
392         /// </summary>
393         /// <param name="vec">An object of the Vector2 type.</param>
394         /// <returns>return an object of the Position2D type</returns>
395         /// <since_tizen> 3 </since_tizen>
396         public static implicit operator Position2D(Vector2 vec)
397         {
398             return new Position2D((int)vec.X, (int)vec.Y);
399         }
400
401         /// <summary>
402         /// Converts a Position2D instance to a Uint16Pair instance.
403         /// </summary>
404         /// <param name="position2d">An object of the Position2D type.</param>
405         /// <returns>return an object of the Uint16Pair type</returns>
406         /// <since_tizen> 4 </since_tizen>
407         public static implicit operator Uint16Pair(Position2D position2d)
408         {
409             return new Uint16Pair((uint)position2d.X, (uint)position2d.Y);
410         }
411
412         /// <summary>
413         /// Converts a Uint16Pair instance to a Position2D instance.
414         /// </summary>
415         /// <param name="pair">An object of the Uint16Pair type.</param>
416         /// <returns>return an object of the Position2D type</returns>
417         /// <since_tizen> 4 </since_tizen>
418         public static implicit operator Position2D(Uint16Pair pair)
419         {
420             return new Position2D((int)pair.GetX(), (int)pair.GetY());
421         }
422
423     }
424
425 }
426