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