Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / PanGestureDetector.cs
1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16
17 namespace Tizen.NUI
18 {
19
20     using System;
21     using System.Runtime.InteropServices;
22     using Tizen.NUI.BaseComponents;
23
24
25     internal class PanGestureDetector : GestureDetector
26     {
27         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
28
29         internal PanGestureDetector(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.PanGestureDetector_SWIGUpcast(cPtr), cMemoryOwn)
30         {
31             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
32         }
33
34         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PanGestureDetector obj)
35         {
36             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
37         }
38
39         protected override void Dispose(DisposeTypes type)
40         {
41             if (disposed)
42             {
43                 return;
44             }
45
46             if (type == DisposeTypes.Explicit)
47             {
48                 //Called by User
49                 //Release your own managed resources here.
50                 //You should release all of your own disposable objects here.
51
52             }
53
54             //Release your own unmanaged resources here.
55             //You should not access any managed member here except static instance.
56             //because the execution order of Finalizes is non-deterministic.
57
58             if (swigCPtr.Handle != global::System.IntPtr.Zero)
59             {
60                 if (swigCMemOwn)
61                 {
62                     swigCMemOwn = false;
63                     NDalicPINVOKE.delete_PanGestureDetector(swigCPtr);
64                 }
65                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
66             }
67
68             base.Dispose(type);
69         }
70
71
72
73         public class DetectedEventArgs : EventArgs
74         {
75             private View _view;
76             private PanGesture _panGesture;
77
78             public View View
79             {
80                 get
81                 {
82                     return _view;
83                 }
84                 set
85                 {
86                     _view = value;
87                 }
88             }
89
90             public PanGesture PanGesture
91             {
92                 get
93                 {
94                     return _panGesture;
95                 }
96                 set
97                 {
98                     _panGesture = value;
99                 }
100             }
101         }
102
103         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
104         private delegate void DetectedCallbackDelegate(IntPtr actor, IntPtr panGesture);
105         private DaliEventHandler<object, DetectedEventArgs> _panGestureEventHandler;
106         private DetectedCallbackDelegate _panGestureCallbackDelegate;
107
108
109         public event DaliEventHandler<object, DetectedEventArgs> Detected
110         {
111             add
112             {
113                 lock (this)
114                 {
115                     // Restricted to only one listener
116                     if (_panGestureEventHandler == null)
117                     {
118                         _panGestureEventHandler += value;
119
120                         _panGestureCallbackDelegate = new DetectedCallbackDelegate(OnPanGestureDetected);
121                         this.DetectedSignal().Connect(_panGestureCallbackDelegate);
122                     }
123                 }
124             }
125
126             remove
127             {
128                 lock (this)
129                 {
130                     if (_panGestureEventHandler != null)
131                     {
132                         this.DetectedSignal().Disconnect(_panGestureCallbackDelegate);
133                     }
134
135                     _panGestureEventHandler -= value;
136                 }
137             }
138         }
139
140         private void OnPanGestureDetected(IntPtr actor, IntPtr panGesture)
141         {
142             DetectedEventArgs e = new DetectedEventArgs();
143
144             // Populate all members of "e" (PanGestureEventArgs) with real data
145             e.View = Registry.GetManagedBaseHandleFromNativePtr(actor) as View;
146             e.PanGesture = Tizen.NUI.PanGesture.GetPanGestureFromPtr(panGesture);
147
148             if (_panGestureEventHandler != null)
149             {
150                 //here we send all data to user event handlers
151                 _panGestureEventHandler(this, e);
152             }
153
154         }
155
156
157         public static PanGestureDetector GetPanGestureDetectorFromPtr(global::System.IntPtr cPtr)
158         {
159             PanGestureDetector ret = new PanGestureDetector(cPtr, false);
160             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
161             return ret;
162         }
163
164
165         public class Property : global::System.IDisposable
166         {
167             private global::System.Runtime.InteropServices.HandleRef swigCPtr;
168             protected bool swigCMemOwn;
169
170             internal Property(global::System.IntPtr cPtr, bool cMemoryOwn)
171             {
172                 swigCMemOwn = cMemoryOwn;
173                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
174             }
175
176             internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Property obj)
177             {
178                 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
179             }
180
181             //A Flag to check who called Dispose(). (By User or DisposeQueue)
182             private bool isDisposeQueued = false;
183             //A Flat to check if it is already disposed.
184             protected bool disposed = false;
185
186
187             ~Property()
188             {
189                 if (!isDisposeQueued)
190                 {
191                     isDisposeQueued = true;
192                     DisposeQueue.Instance.Add(this);
193                 }
194             }
195
196             public void Dispose()
197             {
198                 //Throw excpetion if Dispose() is called in separate thread.
199                 if (!Window.IsInstalled())
200                 {
201                     throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
202                 }
203
204                 if (isDisposeQueued)
205                 {
206                     Dispose(DisposeTypes.Implicit);
207                 }
208                 else
209                 {
210                     Dispose(DisposeTypes.Explicit);
211                     System.GC.SuppressFinalize(this);
212                 }
213             }
214
215             protected virtual void Dispose(DisposeTypes type)
216             {
217                 if (disposed)
218                 {
219                     return;
220                 }
221
222                 if (type == DisposeTypes.Explicit)
223                 {
224                     //Called by User
225                     //Release your own managed resources here.
226                     //You should release all of your own disposable objects here.
227
228                 }
229
230                 //Release your own unmanaged resources here.
231                 //You should not access any managed member here except static instance.
232                 //because the execution order of Finalizes is non-deterministic.
233
234                 if (swigCPtr.Handle != global::System.IntPtr.Zero)
235                 {
236                     if (swigCMemOwn)
237                     {
238                         swigCMemOwn = false;
239                         NDalicPINVOKE.delete_PanGestureDetector_Property(swigCPtr);
240                     }
241                     swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
242                 }
243
244                 disposed = true;
245             }
246
247             public Property() : this(NDalicPINVOKE.new_PanGestureDetector_Property(), true)
248             {
249                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
250             }
251
252             public static readonly int SCREEN_POSITION = NDalicPINVOKE.PanGestureDetector_Property_SCREEN_POSITION_get();
253             public static readonly int SCREEN_DISPLACEMENT = NDalicPINVOKE.PanGestureDetector_Property_SCREEN_DISPLACEMENT_get();
254             public static readonly int SCREEN_VELOCITY = NDalicPINVOKE.PanGestureDetector_Property_SCREEN_VELOCITY_get();
255             public static readonly int LOCAL_POSITION = NDalicPINVOKE.PanGestureDetector_Property_LOCAL_POSITION_get();
256             public static readonly int LOCAL_DISPLACEMENT = NDalicPINVOKE.PanGestureDetector_Property_LOCAL_DISPLACEMENT_get();
257             public static readonly int LOCAL_VELOCITY = NDalicPINVOKE.PanGestureDetector_Property_LOCAL_VELOCITY_get();
258             public static readonly int PANNING = NDalicPINVOKE.PanGestureDetector_Property_PANNING_get();
259
260         }
261
262         public static Radian DIRECTION_LEFT
263         {
264             get
265             {
266                 global::System.IntPtr cPtr = NDalicPINVOKE.PanGestureDetector_DIRECTION_LEFT_get();
267                 Radian ret = (cPtr == global::System.IntPtr.Zero) ? null : new Radian(cPtr, false);
268                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
269                 return ret;
270             }
271         }
272
273         public static Radian DIRECTION_RIGHT
274         {
275             get
276             {
277                 global::System.IntPtr cPtr = NDalicPINVOKE.PanGestureDetector_DIRECTION_RIGHT_get();
278                 Radian ret = (cPtr == global::System.IntPtr.Zero) ? null : new Radian(cPtr, false);
279                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
280                 return ret;
281             }
282         }
283
284         public static Radian DIRECTION_UP
285         {
286             get
287             {
288                 global::System.IntPtr cPtr = NDalicPINVOKE.PanGestureDetector_DIRECTION_UP_get();
289                 Radian ret = (cPtr == global::System.IntPtr.Zero) ? null : new Radian(cPtr, false);
290                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
291                 return ret;
292             }
293         }
294
295         public static Radian DIRECTION_DOWN
296         {
297             get
298             {
299                 global::System.IntPtr cPtr = NDalicPINVOKE.PanGestureDetector_DIRECTION_DOWN_get();
300                 Radian ret = (cPtr == global::System.IntPtr.Zero) ? null : new Radian(cPtr, false);
301                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
302                 return ret;
303             }
304         }
305
306         public static Radian DIRECTION_HORIZONTAL
307         {
308             get
309             {
310                 global::System.IntPtr cPtr = NDalicPINVOKE.PanGestureDetector_DIRECTION_HORIZONTAL_get();
311                 Radian ret = (cPtr == global::System.IntPtr.Zero) ? null : new Radian(cPtr, false);
312                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
313                 return ret;
314             }
315         }
316
317         public static Radian DIRECTION_VERTICAL
318         {
319             get
320             {
321                 global::System.IntPtr cPtr = NDalicPINVOKE.PanGestureDetector_DIRECTION_VERTICAL_get();
322                 Radian ret = (cPtr == global::System.IntPtr.Zero) ? null : new Radian(cPtr, false);
323                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
324                 return ret;
325             }
326         }
327
328         public static Radian DEFAULT_THRESHOLD
329         {
330             get
331             {
332                 global::System.IntPtr cPtr = NDalicPINVOKE.PanGestureDetector_DEFAULT_THRESHOLD_get();
333                 Radian ret = (cPtr == global::System.IntPtr.Zero) ? null : new Radian(cPtr, false);
334                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
335                 return ret;
336             }
337         }
338
339         public PanGestureDetector() : this(NDalicPINVOKE.PanGestureDetector_New(), true)
340         {
341             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
342
343         }
344         public new static PanGestureDetector DownCast(BaseHandle handle)
345         {
346             PanGestureDetector ret =  Registry.GetManagedBaseHandleFromNativePtr(handle) as PanGestureDetector;
347             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
348             return ret;
349         }
350
351         public PanGestureDetector(PanGestureDetector handle) : this(NDalicPINVOKE.new_PanGestureDetector__SWIG_1(PanGestureDetector.getCPtr(handle)), true)
352         {
353             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
354         }
355
356         public PanGestureDetector Assign(PanGestureDetector rhs)
357         {
358             PanGestureDetector ret = new PanGestureDetector(NDalicPINVOKE.PanGestureDetector_Assign(swigCPtr, PanGestureDetector.getCPtr(rhs)), false);
359             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
360             return ret;
361         }
362
363         public void SetMinimumTouchesRequired(uint minimum)
364         {
365             NDalicPINVOKE.PanGestureDetector_SetMinimumTouchesRequired(swigCPtr, minimum);
366             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
367         }
368
369         public void SetMaximumTouchesRequired(uint maximum)
370         {
371             NDalicPINVOKE.PanGestureDetector_SetMaximumTouchesRequired(swigCPtr, maximum);
372             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
373         }
374
375         public uint GetMinimumTouchesRequired()
376         {
377             uint ret = NDalicPINVOKE.PanGestureDetector_GetMinimumTouchesRequired(swigCPtr);
378             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
379             return ret;
380         }
381
382         public uint GetMaximumTouchesRequired()
383         {
384             uint ret = NDalicPINVOKE.PanGestureDetector_GetMaximumTouchesRequired(swigCPtr);
385             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
386             return ret;
387         }
388
389         public void AddAngle(Radian angle, Radian threshold)
390         {
391             NDalicPINVOKE.PanGestureDetector_AddAngle__SWIG_0(swigCPtr, Radian.getCPtr(angle), Radian.getCPtr(threshold));
392             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
393         }
394
395         public void AddAngle(Radian angle)
396         {
397             NDalicPINVOKE.PanGestureDetector_AddAngle__SWIG_1(swigCPtr, Radian.getCPtr(angle));
398             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
399         }
400
401         public void AddDirection(Radian direction, Radian threshold)
402         {
403             NDalicPINVOKE.PanGestureDetector_AddDirection__SWIG_0(swigCPtr, Radian.getCPtr(direction), Radian.getCPtr(threshold));
404             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
405         }
406
407         public void AddDirection(Radian direction)
408         {
409             NDalicPINVOKE.PanGestureDetector_AddDirection__SWIG_1(swigCPtr, Radian.getCPtr(direction));
410             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
411         }
412
413         public uint GetAngleCount()
414         {
415             uint ret = NDalicPINVOKE.PanGestureDetector_GetAngleCount(swigCPtr);
416             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
417             return ret;
418         }
419
420         internal AngleThresholdPair GetAngle(uint index)
421         {
422             AngleThresholdPair ret = new AngleThresholdPair(NDalicPINVOKE.PanGestureDetector_GetAngle(swigCPtr, index), true);
423             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
424             return ret;
425         }
426
427         public void ClearAngles()
428         {
429             NDalicPINVOKE.PanGestureDetector_ClearAngles(swigCPtr);
430             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
431         }
432
433         public void RemoveAngle(Radian angle)
434         {
435             NDalicPINVOKE.PanGestureDetector_RemoveAngle(swigCPtr, Radian.getCPtr(angle));
436             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
437         }
438
439         public void RemoveDirection(Radian direction)
440         {
441             NDalicPINVOKE.PanGestureDetector_RemoveDirection(swigCPtr, Radian.getCPtr(direction));
442             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
443         }
444
445         internal PanGestureDetectedSignal DetectedSignal()
446         {
447             PanGestureDetectedSignal ret = new PanGestureDetectedSignal(NDalicPINVOKE.PanGestureDetector_DetectedSignal(swigCPtr), false);
448             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
449             return ret;
450         }
451
452         public static void SetPanGestureProperties(PanGesture pan)
453         {
454             NDalicPINVOKE.PanGestureDetector_SetPanGestureProperties(PanGesture.getCPtr(pan));
455             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
456         }
457
458         public Vector2 ScreenPosition
459         {
460             get
461             {
462                 Vector2 temp = new Vector2(0.0f, 0.0f);
463                 Tizen.NUI.Object.GetProperty(swigCPtr, PanGestureDetector.Property.SCREEN_POSITION).Get(temp);
464                 return temp;
465             }
466         }
467         public Vector2 ScreenDisplacement
468         {
469             get
470             {
471                 Vector2 temp = new Vector2(0.0f, 0.0f);
472                 Tizen.NUI.Object.GetProperty(swigCPtr, PanGestureDetector.Property.SCREEN_DISPLACEMENT).Get(temp);
473                 return temp;
474             }
475         }
476         public Vector2 ScreenVelocity
477         {
478             get
479             {
480                 Vector2 temp = new Vector2(0.0f, 0.0f);
481                 Tizen.NUI.Object.GetProperty(swigCPtr, PanGestureDetector.Property.SCREEN_VELOCITY).Get(temp);
482                 return temp;
483             }
484         }
485         public Vector2 LocalPosition
486         {
487             get
488             {
489                 Vector2 temp = new Vector2(0.0f, 0.0f);
490                 Tizen.NUI.Object.GetProperty(swigCPtr, PanGestureDetector.Property.LOCAL_POSITION).Get(temp);
491                 return temp;
492             }
493         }
494         public Vector2 LocalDisplacement
495         {
496             get
497             {
498                 Vector2 temp = new Vector2(0.0f, 0.0f);
499                 Tizen.NUI.Object.GetProperty(swigCPtr, PanGestureDetector.Property.LOCAL_DISPLACEMENT).Get(temp);
500                 return temp;
501             }
502         }
503         public Vector2 LocalVelocity
504         {
505             get
506             {
507                 Vector2 temp = new Vector2(0.0f, 0.0f);
508                 Tizen.NUI.Object.GetProperty(swigCPtr, PanGestureDetector.Property.LOCAL_VELOCITY).Get(temp);
509                 return temp;
510             }
511         }
512         public bool Panning
513         {
514             get
515             {
516                 bool temp = false;
517                 Tizen.NUI.Object.GetProperty(swigCPtr, PanGestureDetector.Property.PANNING).Get(out temp);
518                 return temp;
519             }
520         }
521     }
522
523 }