Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Size.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 using System;
19
20 namespace Tizen.NUI
21 {
22
23     [Obsolete("Please do not use! This will be changed to internal class")]
24     public class Size : global::System.IDisposable
25     {
26         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
27         protected bool swigCMemOwn;
28
29         internal Size(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(Size obj)
36         {
37             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
38         }
39
40         //A Flag to check who called Dispose(). (By User or DisposeQueue)
41         private bool isDisposeQueued = false;
42         //A Flat to check if it is already disposed.
43         protected bool disposed = false;
44
45         /// <summary>
46         /// Dispose
47         /// </summary>
48         ~Size()
49         {
50             if (!isDisposeQueued)
51             {
52                 isDisposeQueued = true;
53                 DisposeQueue.Instance.Add(this);
54             }
55         }
56
57         public void Dispose()
58         {
59             //Throw excpetion if Dispose() is called in separate thread.
60             if (!Window.IsInstalled())
61             {
62                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
63             }
64
65             if (isDisposeQueued)
66             {
67                 Dispose(DisposeTypes.Implicit);
68             }
69             else
70             {
71                 Dispose(DisposeTypes.Explicit);
72                 System.GC.SuppressFinalize(this);
73             }
74         }
75
76         protected virtual void Dispose(DisposeTypes type)
77         {
78             if (disposed)
79             {
80                 return;
81             }
82
83             if (type == DisposeTypes.Explicit)
84             {
85                 //Called by User
86                 //Release your own managed resources here.
87                 //You should release all of your own disposable objects here.
88
89             }
90
91             //Release your own unmanaged resources here.
92             //You should not access any managed member here except static instance.
93             //because the execution order of Finalizes is non-deterministic.
94
95             if (swigCPtr.Handle != global::System.IntPtr.Zero)
96             {
97                 if (swigCMemOwn)
98                 {
99                     swigCMemOwn = false;
100                     NDalicPINVOKE.delete_Vector3(swigCPtr);
101                 }
102                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
103             }
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 Size operator +(Size arg1, Size 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 Size operator -(Size arg1, Size 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 Size operator -(Size 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 Size operator *(Size arg1, Size 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 float value to scale the Size</param>
156         /// <returns>A Size containing the result of the scaling</returns>
157         public static Size operator *(Size arg1, float arg2)
158         {
159             return arg1.Multiply(arg2);
160         }
161
162         /// <summary>
163         /// Division operator.
164         /// </summary>
165         /// <param name="arg1">Size for division</param>
166         /// <param name="arg2">The Size to divide</param>
167         /// <returns>A Size containing the result of the division></returns>
168         public static Size operator /(Size arg1, Size arg2)
169         {
170             return arg1.Divide(arg2);
171         }
172
173         /// <summary>
174         /// Division operator.
175         /// </summary>
176         /// <param name="arg1">Size for division</param>
177         /// <param name="arg2">The float value to scale the Size by</param>
178         /// <returns>A Size containing the result of the scaling</returns>
179         public static Size operator /(Size arg1, float arg2)
180         {
181             return arg1.Divide(arg2);
182         }
183
184         /// <summary>
185         /// Array subscript operator.
186         /// </summary>
187         /// <param name="index">Subscript index</param>
188         /// <returns>The float at the given index</returns>
189         public float this[uint index]
190         {
191             get
192             {
193                 return ValueOfIndex(index);
194             }
195         }
196
197         internal static Size GetSizeFromPtr(global::System.IntPtr cPtr)
198         {
199             Size ret = new Size(cPtr, false);
200             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
201             return ret;
202         }
203
204         /// <summary>
205         /// Constructor.
206         /// </summary>
207         public Size() : this(NDalicPINVOKE.new_Vector3__SWIG_0(), true)
208         {
209             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
210         }
211
212         /// <summary>
213         /// Constructor.
214         /// </summary>
215         /// <param name="x">x (or width) component</param>
216         /// <param name="y">y (or height) component</param>
217         /// <param name="z">z (or depth) component</param>
218         public Size(float x, float y, float z) : this(NDalicPINVOKE.new_Vector3__SWIG_1(x, y, z), true)
219         {
220             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
221         }
222
223         /// <summary>
224         /// Constructor.
225         /// </summary>
226         /// <param name="size2d">Size2D with x (width) and y (height)</param>
227         public Size(Size2D size2d) : this(NDalicPINVOKE.new_Vector3__SWIG_3(Size2D.getCPtr(size2d)), true)
228         {
229             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
230         }
231
232         /// <summary>
233         /// Zero constant, (0.0f, 0.0f, 0.0f).
234         /// </summary>
235         public static Size Zero
236         {
237             get
238             {
239                 global::System.IntPtr cPtr = NDalicPINVOKE.Vector3_ZERO_get();
240                 Size ret = (cPtr == global::System.IntPtr.Zero) ? null : new Size(cPtr, false);
241                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
242                 return ret;
243             }
244         }
245
246         private Size Add(Size rhs)
247         {
248             Size ret = new Size(NDalicPINVOKE.Vector3_Add(swigCPtr, Size.getCPtr(rhs)), true);
249             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
250             return ret;
251         }
252
253         private Size Subtract(Size rhs)
254         {
255             Size ret = new Size(NDalicPINVOKE.Vector3_Subtract__SWIG_0(swigCPtr, Size.getCPtr(rhs)), true);
256             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
257             return ret;
258         }
259
260         private Size Multiply(Size rhs)
261         {
262             Size ret = new Size(NDalicPINVOKE.Vector3_Multiply__SWIG_0(swigCPtr, Size.getCPtr(rhs)), true);
263             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
264             return ret;
265         }
266
267         private Size Multiply(float rhs)
268         {
269             Size ret = new Size(NDalicPINVOKE.Vector3_Multiply__SWIG_1(swigCPtr, rhs), true);
270             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
271             return ret;
272         }
273
274         private Size Divide(Size rhs)
275         {
276             Size ret = new Size(NDalicPINVOKE.Vector3_Divide__SWIG_0(swigCPtr, Size.getCPtr(rhs)), true);
277             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
278             return ret;
279         }
280
281         private Size Divide(float rhs)
282         {
283             Size ret = new Size(NDalicPINVOKE.Vector3_Divide__SWIG_1(swigCPtr, rhs), true);
284             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
285             return ret;
286         }
287
288         private Size Subtract()
289         {
290             Size ret = new Size(NDalicPINVOKE.Vector3_Subtract__SWIG_1(swigCPtr), true);
291             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
292             return ret;
293         }
294
295         private float ValueOfIndex(uint index)
296         {
297             float ret = NDalicPINVOKE.Vector3_ValueOfIndex__SWIG_0(swigCPtr, index);
298             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
299             return ret;
300         }
301
302         /// <summary>
303         /// Check equality.<br>
304         /// Utilizes appropriate machine epsilon values.<br>
305         /// </summary>
306         /// <param name="rhs">The Size to test against</param>
307         /// <returns>True if the Sizes are equal</returns>
308         public bool EqualTo(Size rhs)
309         {
310             bool ret = NDalicPINVOKE.Vector3_EqualTo(swigCPtr, Size.getCPtr(rhs));
311             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
312             return ret;
313         }
314
315         /// <summary>
316         /// Check inequality.<br>
317         /// Utilizes appropriate machine epsilon values.<br>
318         /// </summary>
319         /// <param name="rhs">The Size to test against</param>
320         /// <returns>True if the Sizes are not equal</returns>
321         public bool NotEqualTo(Size rhs)
322         {
323             bool ret = NDalicPINVOKE.Vector3_NotEqualTo(swigCPtr, Size.getCPtr(rhs));
324             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
325             return ret;
326         }
327
328         /// <summary>
329         /// Width property for width component of Siz
330         /// </summary>
331         public float Width
332         {
333             set
334             {
335                 NDalicPINVOKE.Vector3_Width_set(swigCPtr, value);
336                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
337             }
338             get
339             {
340                 float ret = NDalicPINVOKE.Vector3_Width_get(swigCPtr);
341                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
342                 return ret;
343             }
344         }
345
346         /// <summary>
347         /// Height property for height component of Size
348         /// </summary>
349         public float Height
350         {
351             set
352             {
353                 NDalicPINVOKE.Vector3_Height_set(swigCPtr, value);
354                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
355             }
356             get
357             {
358                 float ret = NDalicPINVOKE.Vector3_Height_get(swigCPtr);
359                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
360                 return ret;
361             }
362         }
363
364         /// <summary>
365         /// Depth property for depth component of Size
366         /// </summary>
367         public float Depth
368         {
369             set
370             {
371                 NDalicPINVOKE.Vector3_Depth_set(swigCPtr, value);
372                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
373             }
374             get
375             {
376                 float ret = NDalicPINVOKE.Vector3_Depth_get(swigCPtr);
377                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
378                 return ret;
379             }
380         }
381
382         /// <summary>
383         /// Type cast operator, Size to Vector3.
384         /// </summary>
385         /// <param name="size">Object of Size type</param>
386         public static implicit operator Vector3(Size size)
387         {
388             return new Vector3(size.Width, size.Height, size.Depth);
389         }
390
391         /// <summary>
392         /// Type cast operator, Vector3 to Size type.
393         /// </summary>
394         /// <param name="vec">Object of Vector3 type</param>
395         public static implicit operator Size(Vector3 vec)
396         {
397             return new Size(vec.Width, vec.Height, vec.Depth);
398         }
399
400     }
401
402 }
403