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