Hide Size, and use Size2D instead.
[platform/core/csapi/tizenfx.git] / src / 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         //NUI Dispose Pattern written by Jinwoo Nam(jjw.nam) 
41
42         //A Flag to check who called Dispose(). (By User or DisposeQueue)
43         private bool isDisposeQueued = false;
44         //A Flat to check if it is already disposed.
45         protected bool disposed = false;
46
47         ~Size2D()
48         {
49             if(!isDisposeQueued)
50             {
51                 isDisposeQueued = true;
52                 DisposeQueue.Instance.Add(this);
53             }
54         }
55
56         /// <summary>
57         /// Dispose
58         /// </summary>
59         public void Dispose()
60         {
61             //Throw excpetion if Dispose() is called in separate thread.
62             if (!Window.IsInstalled())
63             {
64                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
65             }
66
67             if (isDisposeQueued)
68             {
69                 Dispose(DisposeTypes.Implicit);
70             }
71             else
72             {
73                 Dispose(DisposeTypes.Explicit);
74                 System.GC.SuppressFinalize(this);
75             }
76         }
77
78         protected virtual void Dispose(DisposeTypes type)
79         {
80             if (disposed)
81             {
82                 return;
83             }
84
85             if(type == DisposeTypes.Explicit)
86             {
87                 //Called by User
88                 //Release your own managed resources here.
89                 //You should release all of your own disposable objects here.
90             }
91
92             //Release your own unmanaged resources here.
93             //You should not access any managed member here except static instance.
94             //because the execution order of Finalizes is non-deterministic.
95
96             if (swigCPtr.Handle != global::System.IntPtr.Zero)
97             {
98                 if (swigCMemOwn)
99                 {
100                     swigCMemOwn = false;
101                     NDalicPINVOKE.delete_Vector2(swigCPtr);
102                 }
103                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
104             }
105             disposed = true;
106         }
107
108         /// <summary>
109         /// Addition operator for A+B
110         /// </summary>
111         /// <param name="arg1">Size, A</param>
112         /// <param name="arg2">Size to assign, B</param>
113         /// <returns>A Size containing the result of the addition</returns>
114         public static Size2D operator +(Size2D arg1, Size2D arg2)
115         {
116             return arg1.Add(arg2);
117         }
118
119         /// <summary>
120         /// Subtraction operator for A-B
121         /// </summary>
122         /// <param name="arg1">Size, A</param>
123         /// <param name="arg2">Size to subtract, B</param>
124         /// <returns>A Size containing the result of the subtraction</returns>
125         public static Size2D operator -(Size2D arg1, Size2D arg2)
126         {
127             return arg1.Subtract(arg2);
128         }
129
130         /// <summary>
131         /// Unary negation operator.
132         /// </summary>
133         /// <param name="arg1">Size for unary negation</param>
134         /// <returns>A Size containg the negation</returns>
135         public static Size2D operator -(Size2D arg1)
136         {
137             return arg1.Subtract();
138         }
139
140         /// <summary>
141         /// Multiplication operator.
142         /// </summary>
143         /// <param name="arg1">Size for multiplication</param>
144         /// <param name="arg2">The Size to multipl</param>
145         /// <returns>A Size containing the result of the multiplication</returns>
146         public static Size2D operator *(Size2D arg1, Size2D arg2)
147         {
148             return arg1.Multiply(arg2);
149         }
150
151         /// <summary>
152         /// Multiplication operator.
153         /// </summary>
154         /// <param name="arg1">Size for multiplication</param>
155         /// <param name="arg2">The int value to scale the Size</param>
156         /// <returns>A Size containing the result of the scaling</returns>
157
158         public static Size2D operator *(Size2D arg1, int arg2)
159         {
160             return arg1.Multiply(arg2);
161         }
162
163         /// <summary>
164         /// Division operator.
165         /// </summary>
166         /// <param name="arg1">Size for division</param>
167         /// <param name="arg2">The Size to divide</param>
168         /// <returns>A Size containing the result of the division></returns>
169         public static Size2D operator /(Size2D arg1, Size2D arg2)
170         {
171             return arg1.Divide(arg2);
172         }
173
174         /// <summary>
175         /// Division operator.
176         /// </summary>
177         /// <param name="arg1">Size for division</param>
178         /// <param name="arg2">The int value to scale the Size by</param>
179         /// <returns>A Size containing the result of the scaling</returns>
180         public static Size2D operator /(Size2D arg1, int arg2)
181         {
182             return arg1.Divide(arg2);
183         }
184
185         /// <summary>
186         /// Array subscript operator.
187         /// </summary>
188         /// <param name="index">Subscript index</param>
189         /// <returns>The float at the given index</returns>
190         public float this[uint index]
191         {
192             get
193             {
194                 return ValueOfIndex(index);
195             }
196         }
197
198         /// <summary>
199         /// Get Size from pointer.
200         /// </summary>
201         /// <param name="cPtr">Pointer of the Size</param>
202         /// <returns>Size</returns>
203         internal static Size2D GetSize2DFromPtr(global::System.IntPtr cPtr)
204         {
205             Size2D ret = new Size2D(cPtr, false);
206             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
207             return ret;
208         }
209
210         /// <summary>
211         /// Constructor.
212         /// </summary>
213         public Size2D() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
214         {
215             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
216         }
217
218         /// <summary>
219         /// Constructor.
220         /// </summary>
221         /// <param name="x">x (or width) component</param>
222         /// <param name="y">y (or height) component</param>
223         public Size2D(int x, int y) : this(NDalicPINVOKE.new_Vector2__SWIG_1((float)x, (float)y), true)
224         {
225             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
226         }
227
228         private Size2D Add(Size2D rhs)
229         {
230             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Add(swigCPtr, Size2D.getCPtr(rhs)), true);
231             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
232             return ret;
233         }
234
235         private Size2D Subtract(Size2D rhs)
236         {
237             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
238             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
239             return ret;
240         }
241
242
243         private Size2D Multiply(Size2D rhs)
244         {
245             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
246             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
247             return ret;
248         }
249
250         private Size2D Multiply(int rhs)
251         {
252             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
253             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
254             return ret;
255         }
256
257
258         private Size2D Divide(Size2D rhs)
259         {
260             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
261             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
262             return ret;
263         }
264
265         private Size2D Divide(int rhs)
266         {
267             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
268             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
269             return ret;
270         }
271
272         private Size2D Subtract()
273         {
274             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
275             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
276             return ret;
277         }
278
279         /// <summary>
280         /// Check equality.<br>
281         /// Utilizes appropriate machine epsilon values.<br>
282         /// </summary>
283         /// <param name="rhs">The Size to test against</param>
284         /// <returns>True if the Sizes are equal</returns>
285         public bool EqualTo(Size2D rhs)
286         {
287             bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Size2D.getCPtr(rhs));
288             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
289             return ret;
290         }
291
292         /// <summary>
293         /// Check inequality.<br>
294         /// Utilizes appropriate machine epsilon values.<br>
295         /// </summary>
296         /// <param name="rhs">The Size to test against</param>
297         /// <returns>True if the Sizes are not equal</returns>
298         public bool NotEqualTo(Size2D rhs)
299         {
300             bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Size2D.getCPtr(rhs));
301             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
302             return ret;
303         }
304
305         private int ValueOfIndex(uint index)
306         {
307             int ret = (int)NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
308             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
309             return ret;
310         }
311
312         /// <summary>
313         /// Property for width component of Size
314         /// </summary>
315         public int Width
316         {
317             set
318             {
319                 NDalicPINVOKE.Vector2_Width_set(swigCPtr, (float)value);
320                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
321             }
322             get
323             {
324                 float ret = NDalicPINVOKE.Vector2_Width_get(swigCPtr);
325                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
326                 return (int)ret;
327             }
328         }
329
330         /// <summary>
331         /// Property for height component of Size
332         /// </summary>
333         public int Height
334         {
335             set
336             {
337                 NDalicPINVOKE.Vector2_Height_set(swigCPtr, (float)value);
338                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
339             }
340             get
341             {
342                 float ret = NDalicPINVOKE.Vector2_Height_get(swigCPtr);
343                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
344                 return (int)ret;
345             }
346         }
347
348         /// <summary>
349         /// Type cast operator, Size2D to Vector2.
350         /// </summary>
351         /// <param name="size">Object of Size2D type</param>
352         public static implicit operator Vector2(Size2D size)
353         {
354             return new Vector2((float)size.Width, (float)size.Height);
355         }
356
357         /// <summary>
358         /// Type cast operator, Vector2 to Size2D type.
359         /// </summary>
360         /// <param name="vec">Object of Vector2 type</param>
361         public static implicit operator Size2D(Vector2 vec)
362         {
363             return new Size2D((int)vec.X, (int)vec.Y);
364         }
365
366     }
367
368 }
369