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