manual nui merge 0.2.38
[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 /// <summary>
21 /// Position2D is a two dimensional vector.
22 /// </summary>
23 public class Position2D : global::System.IDisposable {
24   private global::System.Runtime.InteropServices.HandleRef swigCPtr;
25   protected bool swigCMemOwn;
26
27   internal Position2D(global::System.IntPtr cPtr, bool cMemoryOwn) {
28     swigCMemOwn = cMemoryOwn;
29     swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
30   }
31
32   internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Position2D obj) {
33     return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
34   }
35
36   ~Position2D() {
37     DisposeQueue.Instance.Add(this);
38   }
39
40   public virtual void Dispose() {
41     if (!Window.IsInstalled()) {
42       DisposeQueue.Instance.Add(this);
43       return;
44     }
45
46     lock(this) {
47       if (swigCPtr.Handle != global::System.IntPtr.Zero) {
48         if (swigCMemOwn) {
49           swigCMemOwn = false;
50           NDalicPINVOKE.delete_Vector2(swigCPtr);
51         }
52         swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
53       }
54       global::System.GC.SuppressFinalize(this);
55     }
56   }
57
58   /// <summary>
59   /// Addition operator.
60   /// </summary>
61   /// <param name="arg1">Vector to add</param>
62   /// <param name="arg2">Vector to add</param>
63   /// <returns>A vector containing the result of the addition</returns>
64   public static Position2D operator+(Position2D arg1, Position2D arg2) {
65     return arg1.Add(arg2);
66   }
67
68   /// <summary>
69   /// Subtraction operator.
70   /// </summary>
71   /// <param name="arg1">Vector to subtract</param>
72   /// <param name="arg2">Vector to subtract</param>
73   /// <returns>A vector containing the result of the subtraction</returns>
74   public static Position2D operator-(Position2D arg1, Position2D arg2) {
75     return arg1.Subtract(arg2);
76   }
77
78   /// <summary>
79   /// Unary negation operator.
80   /// </summary>
81   /// <param name="arg1">Vector to netate</param>
82   /// <returns>A vector containing the negation</returns>
83   public static Position2D operator-(Position2D arg1) {
84     return arg1.Subtract();
85   }
86
87   /// <summary>
88   /// Multiplication operator.
89   /// </summary>
90   /// <param name="arg1">Vector to multiply</param>
91   /// <param name="arg2">Vector to multiply</param>
92   /// <returns>A vector containing the result of the multiplication</returns>
93   public static Position2D operator*(Position2D arg1, Position2D arg2) {
94     return arg1.Multiply(arg2);
95   }
96
97   /// <summary>
98   /// Multiplication operator.
99   /// </summary>
100   /// <param name="arg1">Vector to multiply</param>
101   /// <param name="arg2">The int value to scale the vector</param>
102   /// <returns>A vector containing the result of the multiplication</returns>
103   public static Position2D operator*(Position2D arg1, int arg2) {
104     return arg1.Multiply(arg2);
105   }
106
107   /// <summary>
108   /// Division operator.
109   /// </summary>
110   /// <param name="arg1">Vector to divide</param>
111   /// <param name="arg2">Vector to divide</param>
112   /// <returns>A vector containing the result of the division</returns>
113   public static Position2D operator/(Position2D arg1, Position2D arg2) {
114     return arg1.Divide(arg2);
115   }
116
117   /// <summary>
118   /// Division operator.
119   /// </summary>
120   /// <param name="arg1">Vector to divide</param>
121   /// <param name="arg2">The int value to scale the vector by</param>
122   /// <returns>A vector containing the result of the division</returns>
123   public static Position2D operator/(Position2D arg1, int arg2) {
124     return arg1.Divide(arg2);
125   }
126
127   /// <summary>
128   /// Const array subscript operator overload. Should be 0, or 1.
129   /// </summary>
130   /// <param name="index">Subscript index</param>
131   /// <returns>The float at the given index</returns>
132   public float this[uint index]
133   {
134     get
135     {
136       return ValueOfIndex(index);
137     }
138   }
139
140   internal static Position2D GetPosition2DFromPtr(global::System.IntPtr cPtr) {
141     Position2D ret = new Position2D(cPtr, false);
142     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
143     return ret;
144   }
145
146   /// <summary>
147   /// Constructor
148   /// </summary>
149   public Position2D() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true) {
150     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
151   }
152
153   /// <summary>
154   /// Constructor
155   /// </summary>
156   /// <param name="x">x component</param>
157   /// <param name="y">y component</param>
158   public Position2D(int x, int y) : this(NDalicPINVOKE.new_Vector2__SWIG_1((float)x, (float)y), true) {
159     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
160   }
161
162   /// <summary>
163   /// Constructor
164   /// </summary>
165   /// <param name="position">Position to create this vector from</param>
166   public Position2D(Position position) : this(NDalicPINVOKE.new_Vector2__SWIG_3(Position.getCPtr(position)), true) {
167     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
168   }
169
170   private Position2D Add(Position2D rhs) {
171     Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Add(swigCPtr, Position2D.getCPtr(rhs)), true);
172     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
173     return ret;
174   }
175
176   private Position2D Subtract(Position2D rhs) {
177     Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
178     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
179     return ret;
180   }
181
182
183   private Position2D Multiply(Position2D rhs) {
184     Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
185     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
186     return ret;
187   }
188
189   private Position2D Multiply(int rhs) {
190     Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
191     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
192     return ret;
193   }
194
195
196   private Position2D Divide(Position2D rhs) {
197     Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Position2D.getCPtr(rhs)), true);
198     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
199     return ret;
200   }
201
202   private Position2D Divide(int rhs) {
203     Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
204     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
205     return ret;
206   }
207
208   private Position2D Subtract() {
209     Position2D ret = new Position2D(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
210     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
211     return ret;
212   }
213
214   /// <summary>
215   /// Compare if rhs is equal to.
216   /// </summary>
217   /// <param name="rhs">The vector to compare</param>
218   /// <returns>Returns true if the two vectors are equal, otherwise false</returns>
219   public bool EqualTo(Position2D rhs) {
220     bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Position2D.getCPtr(rhs));
221     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
222     return ret;
223   }
224
225   /// <summary>
226   /// Compare if rhs is not equal to.
227   /// </summary>
228   /// <param name="rhs">The vector to compare</param>
229   /// <returns>Returns true if the two vectors are not equal, otherwise false</returns>
230   public bool NotEqualTo(Position2D rhs) {
231     bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Position2D.getCPtr(rhs));
232     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
233     return ret;
234   }
235
236   private int ValueOfIndex(uint index) {
237     int ret = (int)NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
238     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
239     return ret;
240   }
241
242   /// <summary>
243   /// x component.
244   /// </summary>
245   public int X {
246     set {
247       NDalicPINVOKE.Vector2_X_set(swigCPtr, (float)value);
248       if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
249     }
250     get {
251       float ret = NDalicPINVOKE.Vector2_X_get(swigCPtr);
252       if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
253       return (int)ret;
254     }
255   }
256
257   /// <summary>
258   /// y component.
259   /// </summary>
260   public int Y {
261     set {
262       NDalicPINVOKE.Vector2_Y_set(swigCPtr, (float)value);
263       if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
264     }
265     get {
266       float ret = NDalicPINVOKE.Vector2_Y_get(swigCPtr);
267       if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
268       return (int)ret;
269     }
270   }
271
272   /// <summary>
273   /// Convert a position2D instance to a vector2 instance.
274   /// </summary>
275   public static implicit operator Vector2(Position2D position2d)
276   {
277     return new Vector2((float)position2d.X, (float)position2d.Y);
278   }
279
280   /// <summary>
281   /// Convert a vector2 instance to a position2D instance.
282   /// </summary>
283   public static implicit operator Position2D(Vector2 vec)
284   {
285     return new Position2D((int)vec.X, (int)vec.Y);
286   }
287
288 }
289
290 }
291
292