Release 4.0.0-preview1-00301
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / TouchPoint.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     using Tizen.NUI.BaseComponents;
22     internal class TouchPoint : global::System.IDisposable
23     {
24         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
25         protected bool swigCMemOwn;
26
27         internal TouchPoint(global::System.IntPtr cPtr, bool cMemoryOwn)
28         {
29             swigCMemOwn = cMemoryOwn;
30             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
31         }
32
33         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TouchPoint obj)
34         {
35             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
36         }
37
38         //A Flag to check who called Dispose(). (By User or DisposeQueue)
39         private bool isDisposeQueued = false;
40         //A Flat to check if it is already disposed.
41         protected bool disposed = false;
42
43
44         ~TouchPoint()
45         {
46             if (!isDisposeQueued)
47             {
48                 isDisposeQueued = true;
49                 DisposeQueue.Instance.Add(this);
50             }
51         }
52
53         public void Dispose()
54         {
55             //Throw excpetion if Dispose() is called in separate thread.
56             if (!Window.IsInstalled())
57             {
58                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
59             }
60
61             if (isDisposeQueued)
62             {
63                 Dispose(DisposeTypes.Implicit);
64             }
65             else
66             {
67                 Dispose(DisposeTypes.Explicit);
68                 System.GC.SuppressFinalize(this);
69             }
70         }
71
72         protected virtual void Dispose(DisposeTypes type)
73         {
74             if (disposed)
75             {
76                 return;
77             }
78
79             if (type == DisposeTypes.Explicit)
80             {
81                 //Called by User
82                 //Release your own managed resources here.
83                 //You should release all of your own disposable objects here.
84
85             }
86
87             //Release your own unmanaged resources here.
88             //You should not access any managed member here except static instance.
89             //because the execution order of Finalizes is non-deterministic.
90
91             if (swigCPtr.Handle != global::System.IntPtr.Zero)
92             {
93                 if (swigCMemOwn)
94                 {
95                     swigCMemOwn = false;
96                     NDalicPINVOKE.delete_TouchPoint(swigCPtr);
97                 }
98                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
99             }
100
101             disposed = true;
102         }
103
104
105         public TouchPoint(int id, TouchPoint.StateType state, float screenX, float screenY) : this(NDalicPINVOKE.new_TouchPoint__SWIG_0(id, (int)state, screenX, screenY), true)
106         {
107             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
108         }
109
110         public TouchPoint(int id, TouchPoint.StateType state, float screenX, float screenY, float localX, float localY) : this(NDalicPINVOKE.new_TouchPoint__SWIG_1(id, (int)state, screenX, screenY, localX, localY), true)
111         {
112             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
113         }
114
115         public int DeviceId
116         {
117             set
118             {
119                 NDalicPINVOKE.TouchPoint_deviceId_set(swigCPtr, value);
120                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
121             }
122             get
123             {
124                 int ret = NDalicPINVOKE.TouchPoint_deviceId_get(swigCPtr);
125                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
126                 return ret;
127             }
128         }
129
130         public TouchPoint.StateType State
131         {
132             set
133             {
134                 NDalicPINVOKE.TouchPoint_state_set(swigCPtr, (int)value);
135                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
136             }
137             get
138             {
139                 TouchPoint.StateType ret = (TouchPoint.StateType)NDalicPINVOKE.TouchPoint_state_get(swigCPtr);
140                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
141                 return ret;
142             }
143         }
144
145         public View HitView
146         {
147             set
148             {
149                 NDalicPINVOKE.TouchPoint_hitActor_set(swigCPtr, View.getCPtr(value));
150                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
151             }
152             get
153             {
154                 global::System.IntPtr cPtr = NDalicPINVOKE.TouchPoint_hitActor_get(swigCPtr);
155                 View ret = (cPtr == global::System.IntPtr.Zero) ? null : Registry.GetManagedBaseHandleFromNativePtr(cPtr) as View;
156                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
157                 return ret;
158             }
159         }
160
161         public Vector2 Local
162         {
163             set
164             {
165                 NDalicPINVOKE.TouchPoint_local_set(swigCPtr, Vector2.getCPtr(value));
166                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
167             }
168             get
169             {
170                 global::System.IntPtr cPtr = NDalicPINVOKE.TouchPoint_local_get(swigCPtr);
171                 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
172                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
173                 return ret;
174             }
175         }
176
177         public Vector2 Screen
178         {
179             set
180             {
181                 NDalicPINVOKE.TouchPoint_screen_set(swigCPtr, Vector2.getCPtr(value));
182                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
183             }
184             get
185             {
186                 global::System.IntPtr cPtr = NDalicPINVOKE.TouchPoint_screen_get(swigCPtr);
187                 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
188                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
189                 return ret;
190             }
191         }
192
193         public enum StateType
194         {
195             Started,
196             Finished,
197             Down = Started,
198             Up = Finished,
199             Motion,
200             Leave,
201             Stationary,
202             Interrupted,
203             Last
204         }
205
206     }
207
208 }