Release 4.0.0-preview1-00301
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Gesture.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     /// Base structure for different gestures that an application can receive.<br />
23     /// A Gesture is an event that is produced from a combination of several touch events
24     /// in a particular order or within a certain time frame (for example, pinch).<br />
25     /// </summary>
26     public class Gesture : global::System.IDisposable
27     {
28         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
29         /// <summary>
30         /// swigCMemOwn.
31         /// </summary>
32         protected bool swigCMemOwn;
33
34         internal Gesture(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(Gesture 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         protected bool disposed = false;
51
52         /// <summary>
53         /// Dispose.
54         /// </summary>
55         /// <since_tizen> 3 </since_tizen>
56         ~Gesture()
57         {
58             if(!isDisposeQueued)
59             {
60                 isDisposeQueued = true;
61                 DisposeQueue.Instance.Add(this);
62             }
63         }
64
65         /// <summary>
66         /// Dispose.
67         /// </summary>
68         /// <since_tizen> 3 </since_tizen>
69         public void Dispose()
70         {
71             //Throw excpetion if Dispose() is called in separate thread.
72             if (!Window.IsInstalled())
73             {
74                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
75             }
76
77             if (isDisposeQueued)
78             {
79                 Dispose(DisposeTypes.Implicit);
80             }
81             else
82             {
83                 Dispose(DisposeTypes.Explicit);
84                 System.GC.SuppressFinalize(this);
85             }
86         }
87
88         /// <summary>
89         /// Dispose.
90         /// </summary>
91         /// <since_tizen> 3 </since_tizen>
92         protected virtual void Dispose(DisposeTypes type)
93         {
94             if (disposed)
95             {
96                 return;
97             }
98
99             if(type == DisposeTypes.Explicit)
100             {
101                 //Called by User
102                 //Release your own managed resources here.
103                 //You should release all of your own disposable objects here.
104             }
105
106             //Release your own unmanaged resources here.
107             //You should not access any managed member here except static instance.
108             //because the execution order of Finalizes is non-deterministic.
109
110             if (swigCPtr.Handle != global::System.IntPtr.Zero)
111             {
112                 if (swigCMemOwn)
113                 {
114                     swigCMemOwn = false;
115                     NDalicPINVOKE.delete_Gesture(swigCPtr);
116                 }
117                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
118             }
119             disposed = true;
120         }
121
122
123         /// <summary>
124         /// The gesture type.
125         /// </summary>
126         /// <since_tizen> 3 </since_tizen>
127         public Gesture.GestureType Type
128         {
129             get
130             {
131                 return type;
132             }
133         }
134
135         /// <summary>
136         /// The gesture state.
137         /// </summary>
138         /// <since_tizen> 3 </since_tizen>
139         public Gesture.StateType State
140         {
141             get
142             {
143                 return state;
144             }
145         }
146
147         /// <summary>
148         /// The time the gesture took place.
149         /// </summary>
150         /// <since_tizen> 3 </since_tizen>
151         public uint Time
152         {
153             get
154             {
155                 return time;
156             }
157         }
158
159         /// <summary>
160         /// The Copy constructor.
161         /// </summary>
162         /// <param name="rhs">A reference to the copied handle</param>
163         /// <since_tizen> 3 </since_tizen>
164         public Gesture(Gesture rhs) : this(NDalicPINVOKE.new_Gesture(Gesture.getCPtr(rhs)), true)
165         {
166             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
167         }
168
169         private Gesture.GestureType type
170         {
171             set
172             {
173                 NDalicPINVOKE.Gesture_type_set(swigCPtr, (int)value);
174                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
175             }
176             get
177             {
178                 Gesture.GestureType ret = (Gesture.GestureType)NDalicPINVOKE.Gesture_type_get(swigCPtr);
179                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
180                 return ret;
181             }
182         }
183
184         private Gesture.StateType state
185         {
186             set
187             {
188                 NDalicPINVOKE.Gesture_state_set(swigCPtr, (int)value);
189                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
190             }
191             get
192             {
193                 Gesture.StateType ret = (Gesture.StateType)NDalicPINVOKE.Gesture_state_get(swigCPtr);
194                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
195                 return ret;
196             }
197         }
198
199         private uint time
200         {
201             set
202             {
203                 NDalicPINVOKE.Gesture_time_set(swigCPtr, value);
204                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
205             }
206             get
207             {
208                 uint ret = NDalicPINVOKE.Gesture_time_get(swigCPtr);
209                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
210                 return ret;
211             }
212         }
213
214         /// <summary>
215         /// Enumeration for type of gesture.
216         /// </summary>
217         /// <since_tizen> 3 </since_tizen>
218         public enum GestureType
219         {
220             /// <summary>
221             /// When two touch points move away or towards each other.
222             /// </summary>
223             /// <since_tizen> 3 </since_tizen>
224             Pinch = 1 << 0,
225             /// <summary>
226             /// When the user drags their finger(s) in a particular direction.
227             /// </summary>
228             /// <since_tizen> 3 </since_tizen>
229             Pan = 1 << 1,
230             /// <summary>
231             /// When the user taps the screen.
232             /// </summary>
233             /// <since_tizen> 3 </since_tizen>
234             Tap = 1 << 2,
235             /// <summary>
236             ///  When the user continues to touch the same area on the screen for the device configured time.
237             /// </summary>
238             /// <since_tizen> 3 </since_tizen>
239             LongPress = 1 << 3
240         }
241
242         /// <summary>
243         /// Enumeration for state of the gesture.
244         /// </summary>
245         /// <since_tizen> 3 </since_tizen>
246         public enum StateType
247         {
248             /// <summary>
249             /// There is no state associated with this gesture.
250             /// </summary>
251             /// <since_tizen> 3 </since_tizen>
252             Clear,
253             /// <summary>
254             /// The touched points on the screen have moved enough to be considered a gesture.
255             /// </summary>
256             /// <since_tizen> 3 </since_tizen>
257             Started,
258             /// <summary>
259             /// The gesture is continuing.
260             /// </summary>
261             /// <since_tizen> 3 </since_tizen>
262             Continuing,
263             /// <summary>
264             /// The user has lifted a finger or touched an additional point on the screen.
265             /// </summary>
266             /// <since_tizen> 3 </since_tizen>
267             Finished,
268             /// <summary>
269             /// The gesture has been cancelled.
270             /// </summary>
271             /// <since_tizen> 3 </since_tizen>
272             Cancelled,
273             /// <summary>
274             ///  A gesture is possible.
275             /// </summary>
276             /// <since_tizen> 3 </since_tizen>
277             Possible
278         }
279
280     }
281
282 }