[NUI] Reduce code duplication - refactor dispose codes (#1010)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Matrix.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     internal class Matrix : Disposable
21     {
22         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
23         protected bool swigCMemOwn;
24
25         internal Matrix(global::System.IntPtr cPtr, bool cMemoryOwn)
26         {
27             swigCMemOwn = cMemoryOwn;
28             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
29         }
30
31         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Matrix obj)
32         {
33             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
34         }
35
36         protected override void Dispose(DisposeTypes type)
37         {
38             if (disposed)
39             {
40                 return;
41             }
42
43             //Release your own unmanaged resources here.
44             //You should not access any managed member here except static instance.
45             //because the execution order of Finalizes is non-deterministic.
46
47             if (swigCPtr.Handle != global::System.IntPtr.Zero)
48             {
49                 if (swigCMemOwn)
50                 {
51                     swigCMemOwn = false;
52                     Interop.Matrix.delete_Matrix(swigCPtr);
53                 }
54                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
55             }
56
57             base.Dispose(type);
58         }
59
60
61         public static Vector4 operator *(Matrix arg1, Vector4 arg2)
62         {
63             return arg1.Multiply(arg2);
64         }
65
66         public Matrix() : this(Interop.Matrix.new_Matrix__SWIG_0(), true)
67         {
68             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
69         }
70
71         public Matrix(bool initialize) : this(Interop.Matrix.new_Matrix__SWIG_1(initialize), true)
72         {
73             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
74         }
75
76         public Matrix(float[] array) : this(Interop.Matrix.new_Matrix__SWIG_2(array), true)
77         {
78             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
79         }
80
81         public Matrix(Rotation rotation) : this(Interop.Matrix.new_Matrix__SWIG_3(Rotation.getCPtr(rotation)), true)
82         {
83             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
84         }
85
86         public Matrix(Matrix matrix) : this(Interop.Matrix.new_Matrix__SWIG_4(Matrix.getCPtr(matrix)), true)
87         {
88             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
89         }
90
91         public Matrix Assign(Matrix matrix)
92         {
93             Matrix ret = new Matrix(Interop.Matrix.Matrix_Assign(swigCPtr, Matrix.getCPtr(matrix)), false);
94             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
95             return ret;
96         }
97
98         public static Matrix IDENTITY
99         {
100             get
101             {
102                 global::System.IntPtr cPtr = Interop.Matrix.Matrix_IDENTITY_get();
103                 Matrix ret = (cPtr == global::System.IntPtr.Zero) ? null : new Matrix(cPtr, false);
104                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
105                 return ret;
106             }
107         }
108
109         public void SetIdentity()
110         {
111             Interop.Matrix.Matrix_SetIdentity(swigCPtr);
112             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
113         }
114
115         public void SetIdentityAndScale(Vector3 scale)
116         {
117             Interop.Matrix.Matrix_SetIdentityAndScale(swigCPtr, Vector3.getCPtr(scale));
118             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
119         }
120
121         public void InvertTransform(Matrix result)
122         {
123             Interop.Matrix.Matrix_InvertTransform(swigCPtr, Matrix.getCPtr(result));
124             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
125         }
126
127         public bool Invert()
128         {
129             bool ret = Interop.Matrix.Matrix_Invert(swigCPtr);
130             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
131             return ret;
132         }
133
134         public void Transpose()
135         {
136             Interop.Matrix.Matrix_Transpose(swigCPtr);
137             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
138         }
139
140         public Vector3 GetXAxis()
141         {
142             Vector3 ret = new Vector3(Interop.Matrix.Matrix_GetXAxis(swigCPtr), true);
143             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
144             return ret;
145         }
146
147         public Vector3 GetYAxis()
148         {
149             Vector3 ret = new Vector3(Interop.Matrix.Matrix_GetYAxis(swigCPtr), true);
150             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
151             return ret;
152         }
153
154         public Vector3 GetZAxis()
155         {
156             Vector3 ret = new Vector3(Interop.Matrix.Matrix_GetZAxis(swigCPtr), true);
157             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
158             return ret;
159         }
160
161         public void SetXAxis(Vector3 axis)
162         {
163             Interop.Matrix.Matrix_SetXAxis(swigCPtr, Vector3.getCPtr(axis));
164             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
165         }
166
167         public void SetYAxis(Vector3 axis)
168         {
169             Interop.Matrix.Matrix_SetYAxis(swigCPtr, Vector3.getCPtr(axis));
170             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
171         }
172
173         public void SetZAxis(Vector3 axis)
174         {
175             Interop.Matrix.Matrix_SetZAxis(swigCPtr, Vector3.getCPtr(axis));
176             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
177         }
178
179         public Vector4 GetTranslation()
180         {
181             Vector4 ret = new Vector4(Interop.Matrix.Matrix_GetTranslation(swigCPtr), false);
182             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
183             return ret;
184         }
185
186         public Vector3 GetTranslation3()
187         {
188             Vector3 ret = new Vector3(Interop.Matrix.Matrix_GetTranslation3(swigCPtr), false);
189             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
190             return ret;
191         }
192
193         public void SetTranslation(Vector4 translation)
194         {
195             Interop.Matrix.Matrix_SetTranslation__SWIG_0(swigCPtr, Vector4.getCPtr(translation));
196             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
197         }
198
199         public void SetTranslation(Vector3 translation)
200         {
201             Interop.Matrix.Matrix_SetTranslation__SWIG_1(swigCPtr, Vector3.getCPtr(translation));
202             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
203         }
204
205         public void OrthoNormalize()
206         {
207             Interop.Matrix.Matrix_OrthoNormalize(swigCPtr);
208             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
209         }
210
211         public SWIGTYPE_p_float AsFloat()
212         {
213             global::System.IntPtr cPtr = Interop.Matrix.Matrix_AsFloat__SWIG_0(swigCPtr);
214             SWIGTYPE_p_float ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_float(cPtr, false);
215             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
216             return ret;
217         }
218
219         public static void Multiply(Matrix result, Matrix lhs, Matrix rhs)
220         {
221             Interop.Matrix.Matrix_Multiply__SWIG_0(Matrix.getCPtr(result), Matrix.getCPtr(lhs), Matrix.getCPtr(rhs));
222             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
223         }
224
225         public static void Multiply(Matrix result, Matrix lhs, Rotation rhs)
226         {
227             Interop.Matrix.Matrix_Multiply__SWIG_1(Matrix.getCPtr(result), Matrix.getCPtr(lhs), Rotation.getCPtr(rhs));
228             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
229         }
230
231         public Vector4 Multiply(Vector4 rhs)
232         {
233             Vector4 ret = new Vector4(Interop.Matrix.Matrix_Multiply__SWIG_2(swigCPtr, Vector4.getCPtr(rhs)), true);
234             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
235             return ret;
236         }
237
238         public bool EqualTo(Matrix rhs)
239         {
240             bool ret = Interop.Matrix.Matrix_EqualTo(swigCPtr, Matrix.getCPtr(rhs));
241             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
242             return ret;
243         }
244
245         public bool NotEqualTo(Matrix rhs)
246         {
247             bool ret = Interop.Matrix.Matrix_NotEqualTo(swigCPtr, Matrix.getCPtr(rhs));
248             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
249             return ret;
250         }
251
252         public void SetTransformComponents(Vector3 scale, Rotation rotation, Vector3 translation)
253         {
254             Interop.Matrix.Matrix_SetTransformComponents(swigCPtr, Vector3.getCPtr(scale), Rotation.getCPtr(rotation), Vector3.getCPtr(translation));
255             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
256         }
257
258         public void SetInverseTransformComponents(Vector3 scale, Rotation rotation, Vector3 translation)
259         {
260             Interop.Matrix.Matrix_SetInverseTransformComponents__SWIG_0(swigCPtr, Vector3.getCPtr(scale), Rotation.getCPtr(rotation), Vector3.getCPtr(translation));
261             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
262         }
263
264         public void SetInverseTransformComponents(Vector3 xAxis, Vector3 yAxis, Vector3 zAxis, Vector3 translation)
265         {
266             Interop.Matrix.Matrix_SetInverseTransformComponents__SWIG_1(swigCPtr, Vector3.getCPtr(xAxis), Vector3.getCPtr(yAxis), Vector3.getCPtr(zAxis), Vector3.getCPtr(translation));
267             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
268         }
269
270         public void GetTransformComponents(Vector3 position, Rotation rotation, Vector3 scale)
271         {
272             Interop.Matrix.Matrix_GetTransformComponents(swigCPtr, Vector3.getCPtr(position), Rotation.getCPtr(rotation), Vector3.getCPtr(scale));
273             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
274         }
275     }
276 }