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