d93f35257f4112f3fe7dbc89bcf6d23a3b287878
[platform/core/csapi/nui.git] / Tizen.NUI / src / public / Size2D.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     /// A two dimensional size
23     /// </summary>
24     public class Size2D : global::System.IDisposable
25     {
26         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
27         protected bool swigCMemOwn;
28
29         internal Size2D(global::System.IntPtr cPtr, bool cMemoryOwn)
30         {
31             swigCMemOwn = cMemoryOwn;
32             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
33         }
34
35         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Size2D obj)
36         {
37             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
38         }
39
40         ~Size2D()
41         {
42             DisposeQueue.Instance.Add(this);
43         }
44
45         /// <summary>
46         /// Dispose
47         /// </summary>
48         public virtual void Dispose()
49         {
50             if (!Stage.IsInstalled())
51             {
52                 DisposeQueue.Instance.Add(this);
53                 return;
54             }
55
56             lock (this)
57             {
58                 if (swigCPtr.Handle != global::System.IntPtr.Zero)
59                 {
60                     if (swigCMemOwn)
61                     {
62                         swigCMemOwn = false;
63                         NDalicPINVOKE.delete_Vector2(swigCPtr);
64                     }
65                     swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
66                 }
67                 global::System.GC.SuppressFinalize(this);
68             }
69         }
70
71         /// <summary>
72         /// Addition operator for A+B
73         /// </summary>
74         /// <param name="arg1">Size, A</param>
75         /// <param name="arg2">Size to assign, B</param>
76         /// <returns>A Size containing the result of the addition</returns>
77         public static Size2D operator +(Size2D arg1, Size2D arg2)
78         {
79             return arg1.Add(arg2);
80         }
81
82         /// <summary>
83         /// Subtraction operator for A-B
84         /// </summary>
85         /// <param name="arg1">Size, A</param>
86         /// <param name="arg2">Size to subtract, B</param>
87         /// <returns>A Size containing the result of the subtraction</returns>
88         public static Size2D operator -(Size2D arg1, Size2D arg2)
89         {
90             return arg1.Subtract(arg2);
91         }
92
93         /// <summary>
94         /// Unary negation operator.
95         /// </summary>
96         /// <param name="arg1">Size for unary negation</param>
97         /// <returns>A Size containg the negation</returns>
98         public static Size2D operator -(Size2D arg1)
99         {
100             return arg1.Subtract();
101         }
102
103         /// <summary>
104         /// Multiplication operator.
105         /// </summary>
106         /// <param name="arg1">Size for multiplication</param>
107         /// <param name="arg2">The Size to multipl</param>
108         /// <returns>A Size containing the result of the multiplication</returns>
109         public static Size2D operator *(Size2D arg1, Size2D arg2)
110         {
111             return arg1.Multiply(arg2);
112         }
113
114         /// <summary>
115         /// Multiplication operator.
116         /// </summary>
117         /// <param name="arg1">Size for multiplication</param>
118         /// <param name="arg2">The int value to scale the Size</param>
119         /// <returns>A Size containing the result of the scaling</returns>
120
121         public static Size2D operator *(Size2D arg1, int arg2)
122         {
123             return arg1.Multiply(arg2);
124         }
125
126         /// <summary>
127         /// Division operator.
128         /// </summary>
129         /// <param name="arg1">Size for division</param>
130         /// <param name="arg2">The Size to divide</param>
131         /// <returns>A Size containing the result of the division></returns>
132         public static Size2D operator /(Size2D arg1, Size2D arg2)
133         {
134             return arg1.Divide(arg2);
135         }
136
137         /// <summary>
138         /// Division operator.
139         /// </summary>
140         /// <param name="arg1">Size for division</param>
141         /// <param name="arg2">The int value to scale the Size by</param>
142         /// <returns>A Size containing the result of the scaling</returns>
143         public static Size2D operator /(Size2D arg1, int arg2)
144         {
145             return arg1.Divide(arg2);
146         }
147
148         /// <summary>
149         /// Array subscript operator.
150         /// </summary>
151         /// <param name="index">Subscript index</param>
152         /// <returns>The float at the given index</returns>
153         public float this[uint index]
154         {
155             get
156             {
157                 return ValueOfIndex(index);
158             }
159         }
160
161         /// <summary>
162         /// Get Size from pointer.
163         /// </summary>
164         /// <param name="cPtr">Pointer of the Size</param>
165         /// <returns>Size</returns>
166         public static Size2D GetSize2DFromPtr(global::System.IntPtr cPtr)
167         {
168             Size2D ret = new Size2D(cPtr, false);
169             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
170             return ret;
171         }
172
173         /// <summary>
174         /// Constructor.
175         /// </summary>
176         public Size2D() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
177         {
178             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
179         }
180
181         /// <summary>
182         /// Constructor.
183         /// </summary>
184         /// <param name="x">x (or width) component</param>
185         /// <param name="y">y (or height) component</param>
186         public Size2D(int x, int y) : this(NDalicPINVOKE.new_Vector2__SWIG_1((float)x, (float)y), true)
187         {
188             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
189         }
190
191         /// <summary>
192         /// Constructor.
193         /// </summary>
194         /// <param name="size">Size with x (width), y (height), and z (depth)</param>
195         public Size2D(Size size) : this(NDalicPINVOKE.new_Vector2__SWIG_3(Size.getCPtr(size)), true)
196         {
197             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
198         }
199
200         private Size2D Add(Size2D rhs)
201         {
202             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Add(swigCPtr, Size2D.getCPtr(rhs)), true);
203             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
204             return ret;
205         }
206
207         private Size2D Subtract(Size2D rhs)
208         {
209             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
210             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
211             return ret;
212         }
213
214
215         private Size2D Multiply(Size2D rhs)
216         {
217             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
218             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
219             return ret;
220         }
221
222         private Size2D Multiply(int rhs)
223         {
224             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
225             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
226             return ret;
227         }
228
229
230         private Size2D Divide(Size2D rhs)
231         {
232             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
233             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
234             return ret;
235         }
236
237         private Size2D Divide(int rhs)
238         {
239             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
240             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
241             return ret;
242         }
243
244         private Size2D Subtract()
245         {
246             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
247             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
248             return ret;
249         }
250
251         /// <summary>
252         /// Check equality.
253         /// Utilizes appropriate machine epsilon values.
254         /// </summary>
255         /// <param name="rhs">The Size to test against</param>
256         /// <returns>True if the Sizes are equal</returns>
257         public bool EqualTo(Size2D rhs)
258         {
259             bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Size2D.getCPtr(rhs));
260             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
261             return ret;
262         }
263
264         /// <summary>
265         /// Check inequality.
266         /// Utilizes appropriate machine epsilon values.
267         /// </summary>
268         /// <param name="rhs">The Size to test against</param>
269         /// <returns>True if the Sizes are not equal</returns>
270         public bool NotEqualTo(Size2D rhs)
271         {
272             bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Size2D.getCPtr(rhs));
273             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
274             return ret;
275         }
276
277         private int ValueOfIndex(uint index)
278         {
279             int ret = (int)NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
280             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
281             return ret;
282         }
283
284         /// <summary>
285         /// Property for width component of Size
286         /// </summary>
287         public int Width
288         {
289             set
290             {
291                 NDalicPINVOKE.Vector2_Width_set(swigCPtr, (float)value);
292                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
293             }
294             get
295             {
296                 float ret = NDalicPINVOKE.Vector2_Width_get(swigCPtr);
297                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
298                 return (int)ret;
299             }
300         }
301
302         /// <summary>
303         /// Property for height component of Size
304         /// </summary>
305         public int Height
306         {
307             set
308             {
309                 NDalicPINVOKE.Vector2_Height_set(swigCPtr, (float)value);
310                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
311             }
312             get
313             {
314                 float ret = NDalicPINVOKE.Vector2_Height_get(swigCPtr);
315                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
316                 return (int)ret;
317             }
318         }
319
320         /// <summary>
321         /// Type cast operator, Size2D to Vector2.
322         /// </summary>
323         /// <param name="size">Object of Size2D type</param>
324         public static implicit operator Vector2(Size2D size)
325         {
326             return new Vector2((float)size.Width, (float)size.Height);
327         }
328
329         /// <summary>
330         /// Type cast operator, Vector2 to Size2D type.
331         /// </summary>
332         /// <param name="vec">Object of Vector2 type</param>
333         public static implicit operator Size2D(Vector2 vec)
334         {
335             return new Size2D((int)vec.X, (int)vec.Y);
336         }
337
338     }
339
340 }
341