[NUI] Sync with dalihub & API5 branch (#631)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Degree.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     /// An angle in degrees.<br />
23     /// This reduces ambiguity when using methods which accept angles in degrees or radians.<br />
24     /// </summary>
25     /// <since_tizen> 3 </since_tizen>
26     public class Degree : global::System.IDisposable
27     {
28
29         /// <summary>
30         /// swigCMemOwn.
31         /// </summary>
32         /// <since_tizen> 3 </since_tizen>
33         protected bool swigCMemOwn;
34
35         /// <summary>
36         /// A Flat to check if it is already disposed.
37         /// </summary>
38         /// <since_tizen> 3 </since_tizen>
39         protected bool disposed = false;
40
41         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
42
43         //A Flag to check who called Dispose(). (By User or DisposeQueue)
44         private bool isDisposeQueued = false;
45
46         /// <summary>
47         /// The constructor.
48         /// </summary>
49         /// <since_tizen> 3 </since_tizen>
50         public Degree() : this(NDalicPINVOKE.new_Degree__SWIG_0(), true)
51         {
52             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
53         }
54
55         /// <summary>
56         /// Creates an angle in degrees.
57         /// </summary>
58         /// <param name="value">The initial value in degrees.</param>
59         /// <since_tizen> 3 </since_tizen>
60         public Degree(float value) : this(NDalicPINVOKE.new_Degree__SWIG_1(value), true)
61         {
62             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
63         }
64
65         /// <summary>
66         /// Creates an angle in degrees from a radian.
67         /// </summary>
68         /// <param name="value">The initial value in radians.</param>
69         /// <since_tizen> 3 </since_tizen>
70         public Degree(Radian value) : this(NDalicPINVOKE.new_Degree__SWIG_2(Radian.getCPtr(value)), true)
71         {
72             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
73         }
74
75         internal Degree(global::System.IntPtr cPtr, bool cMemoryOwn)
76         {
77             swigCMemOwn = cMemoryOwn;
78             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
79         }
80
81         /// <summary>
82         /// Dispose.
83         /// </summary>
84         /// <since_tizen> 3 </since_tizen>
85         ~Degree()
86         {
87             if (!isDisposeQueued)
88             {
89                 isDisposeQueued = true;
90                 DisposeQueue.Instance.Add(this);
91             }
92         }
93
94         /// <summary>
95         /// The value of degree.
96         /// </summary>
97         /// <since_tizen> 3 </since_tizen>
98         public float Value
99         {
100             set
101             {
102                 NDalicPINVOKE.Degree_degree_set(swigCPtr, value);
103                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
104             }
105             get
106             {
107                 float ret = NDalicPINVOKE.Degree_degree_get(swigCPtr);
108                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
109                 return ret;
110             }
111         }
112
113         /// <summary>
114         /// Dispose.
115         /// </summary>
116         /// <since_tizen> 3 </since_tizen>
117         public void Dispose()
118         {
119             //Throw excpetion if Dispose() is called in separate thread.
120             if (!Window.IsInstalled())
121             {
122                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
123             }
124
125             if (isDisposeQueued)
126             {
127                 Dispose(DisposeTypes.Implicit);
128             }
129             else
130             {
131                 Dispose(DisposeTypes.Explicit);
132                 System.GC.SuppressFinalize(this);
133             }
134         }
135
136         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Degree obj)
137         {
138             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
139         }
140
141         /// <summary>
142         /// Dispose.
143         /// </summary>
144         /// <since_tizen> 3 </since_tizen>
145         protected virtual void Dispose(DisposeTypes type)
146         {
147             if (disposed)
148             {
149                 return;
150             }
151
152             if(type == DisposeTypes.Explicit)
153             {
154                 //Called by User
155                 //Release your own managed resources here.
156                 //You should release all of your own disposable objects here.
157             }
158
159             //Release your own unmanaged resources here.
160             //You should not access any managed member here except static instance.
161             //because the execution order of Finalizes is non-deterministic.
162
163             if (swigCPtr.Handle != global::System.IntPtr.Zero)
164             {
165                 if (swigCMemOwn)
166                 {
167                     swigCMemOwn = false;
168                     NDalicPINVOKE.delete_Degree(swigCPtr);
169                 }
170                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
171             }
172             disposed = true;
173         }
174
175     }
176
177 }