a042de16f823c844dd188ac5761a9b445e249004
[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     public class Size2D : global::System.IDisposable
22     {
23         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
24         protected bool swigCMemOwn;
25
26         internal Size2D(global::System.IntPtr cPtr, bool cMemoryOwn)
27         {
28             swigCMemOwn = cMemoryOwn;
29             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
30         }
31
32         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Size2D obj)
33         {
34             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
35         }
36
37         ~Size2D()
38         {
39             DisposeQueue.Instance.Add(this);
40         }
41
42         public virtual void Dispose()
43         {
44             if (!Stage.IsInstalled())
45             {
46                 DisposeQueue.Instance.Add(this);
47                 return;
48             }
49
50             lock (this)
51             {
52                 if (swigCPtr.Handle != global::System.IntPtr.Zero)
53                 {
54                     if (swigCMemOwn)
55                     {
56                         swigCMemOwn = false;
57                         NDalicPINVOKE.delete_Vector2(swigCPtr);
58                     }
59                     swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
60                 }
61                 global::System.GC.SuppressFinalize(this);
62             }
63         }
64
65
66         public static Size2D operator +(Size2D arg1, Size2D arg2)
67         {
68             return arg1.Add(arg2);
69         }
70
71         public static Size2D operator -(Size2D arg1, Size2D arg2)
72         {
73             return arg1.Subtract(arg2);
74         }
75
76         public static Size2D operator -(Size2D arg1)
77         {
78             return arg1.Subtract();
79         }
80
81         public static Size2D operator *(Size2D arg1, Size2D arg2)
82         {
83             return arg1.Multiply(arg2);
84         }
85
86         public static Size2D operator *(Size2D arg1, int arg2)
87         {
88             return arg1.Multiply(arg2);
89         }
90
91         public static Size2D operator /(Size2D arg1, Size2D arg2)
92         {
93             return arg1.Divide(arg2);
94         }
95
96         public static Size2D operator /(Size2D arg1, int arg2)
97         {
98             return arg1.Divide(arg2);
99         }
100
101         public float this[uint index]
102         {
103             get
104             {
105                 return ValueOfIndex(index);
106             }
107         }
108
109         public static Size2D GetSize2DFromPtr(global::System.IntPtr cPtr)
110         {
111             Size2D ret = new Size2D(cPtr, false);
112             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
113             return ret;
114         }
115
116
117         public Size2D() : this(NDalicPINVOKE.new_Vector2__SWIG_0(), true)
118         {
119             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
120         }
121
122         public Size2D(int x, int y) : this(NDalicPINVOKE.new_Vector2__SWIG_1((float)x, (float)y), true)
123         {
124             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
125         }
126
127         public Size2D(Size size) : this(NDalicPINVOKE.new_Vector2__SWIG_3(Size.getCPtr(size)), true)
128         {
129             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
130         }
131
132         private Size2D Add(Size2D rhs)
133         {
134             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Add(swigCPtr, Size2D.getCPtr(rhs)), true);
135             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
136             return ret;
137         }
138
139         private Size2D Subtract(Size2D rhs)
140         {
141             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
142             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
143             return ret;
144         }
145
146
147         private Size2D Multiply(Size2D rhs)
148         {
149             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
150             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
151             return ret;
152         }
153
154         private Size2D Multiply(int rhs)
155         {
156             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Multiply__SWIG_1(swigCPtr, (float)rhs), true);
157             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
158             return ret;
159         }
160
161
162         private Size2D Divide(Size2D rhs)
163         {
164             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_0(swigCPtr, Size2D.getCPtr(rhs)), true);
165             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
166             return ret;
167         }
168
169         private Size2D Divide(int rhs)
170         {
171             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Divide__SWIG_1(swigCPtr, (float)rhs), true);
172             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
173             return ret;
174         }
175
176         private Size2D Subtract()
177         {
178             Size2D ret = new Size2D(NDalicPINVOKE.Vector2_Subtract__SWIG_1(swigCPtr), true);
179             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
180             return ret;
181         }
182
183         public bool EqualTo(Size2D rhs)
184         {
185             bool ret = NDalicPINVOKE.Vector2_EqualTo(swigCPtr, Size2D.getCPtr(rhs));
186             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
187             return ret;
188         }
189
190         public bool NotEqualTo(Size2D rhs)
191         {
192             bool ret = NDalicPINVOKE.Vector2_NotEqualTo(swigCPtr, Size2D.getCPtr(rhs));
193             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
194             return ret;
195         }
196
197         private int ValueOfIndex(uint index)
198         {
199             int ret = (int)NDalicPINVOKE.Vector2_ValueOfIndex__SWIG_0(swigCPtr, index);
200             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
201             return ret;
202         }
203
204
205         public int Width
206         {
207             set
208             {
209                 NDalicPINVOKE.Vector2_Width_set(swigCPtr, (float)value);
210                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
211             }
212             get
213             {
214                 float ret = NDalicPINVOKE.Vector2_Width_get(swigCPtr);
215                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
216                 return (int)ret;
217             }
218         }
219
220         public int Height
221         {
222             set
223             {
224                 NDalicPINVOKE.Vector2_Height_set(swigCPtr, (float)value);
225                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
226             }
227             get
228             {
229                 float ret = NDalicPINVOKE.Vector2_Height_get(swigCPtr);
230                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
231                 return (int)ret;
232             }
233         }
234
235         public static implicit operator Vector2(Size2D size)
236         {
237             return new Vector2((float)size.Width, (float)size.Height);
238         }
239
240         public static implicit operator Size2D(Vector2 vec)
241         {
242             return new Size2D((int)vec.X, (int)vec.Y);
243         }
244
245     }
246
247 }
248