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