2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Runtime.InteropServices;
19 using Tizen.NUI.BaseComponents;
20 using System.ComponentModel;
25 /// This class emits a signals when a pan gesture occurs.<br />
27 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
28 [EditorBrowsable(EditorBrowsableState.Never)]
29 public class PanGestureDetector : GestureDetector
32 /// Creates an initialized PanGestureDetector.
34 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
35 [EditorBrowsable(EditorBrowsableState.Never)]
36 public PanGestureDetector() : this(Interop.PanGestureDetector.New(), true)
38 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
43 /// The copy constructor.
45 /// <param name="handle">A reference to the copied handle</param>
46 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
47 [EditorBrowsable(EditorBrowsableState.Never)]
48 public PanGestureDetector(PanGestureDetector handle) : this(Interop.PanGestureDetector.NewPanGestureDetector(PanGestureDetector.getCPtr(handle)), true)
50 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
53 internal PanGestureDetector(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.PanGestureDetector.Upcast(cPtr), cMemoryOwn)
57 private DaliEventHandler<object, DetectedEventArgs> _detectedEventHandler;
58 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
59 private delegate void DetectedCallbackType(IntPtr actor, IntPtr panGesture);
60 private DetectedCallbackType _detectedCallback;
61 private PanGestureDetectedSignal detectedSignal;
64 /// This signal is emitted when the specified pan is detected on the attached view.
66 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
67 [EditorBrowsable(EditorBrowsableState.Never)]
68 public event DaliEventHandler<object, DetectedEventArgs> Detected
72 if (_detectedEventHandler == null)
74 _detectedCallback = OnPanGestureDetected;
75 detectedSignal = DetectedSignal();
76 detectedSignal.Connect(_detectedCallback);
79 _detectedEventHandler += value;
84 _detectedEventHandler -= value;
86 if (_detectedEventHandler == null && detectedSignal?.Empty() == false)
88 detectedSignal.Disconnect(_detectedCallback);
89 detectedSignal.Dispose();
90 detectedSignal = null;
96 /// For a left pan (-PI Radians).
98 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
99 [EditorBrowsable(EditorBrowsableState.Never)]
100 public static Radian DirectionLeft
104 global::System.IntPtr cPtr = Interop.PanGestureDetector.DirectionLeftGet();
105 Radian ret = (cPtr == global::System.IntPtr.Zero) ? null : new Radian(cPtr, false);
106 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
112 /// For a right pan (0 Radians).
114 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
115 [EditorBrowsable(EditorBrowsableState.Never)]
116 public static Radian DirectionRight
120 global::System.IntPtr cPtr = Interop.PanGestureDetector.DirectionRightGet();
121 Radian ret = (cPtr == global::System.IntPtr.Zero) ? null : new Radian(cPtr, false);
122 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
128 /// For an up pan (-0.5 * PI Radians).
130 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
131 [EditorBrowsable(EditorBrowsableState.Never)]
132 public static Radian DirectionUp
136 global::System.IntPtr cPtr = Interop.PanGestureDetector.DirectionUpGet();
137 Radian ret = (cPtr == global::System.IntPtr.Zero) ? null : new Radian(cPtr, false);
138 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
144 /// For a down pan (0.5 * PI Radians).
146 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
147 [EditorBrowsable(EditorBrowsableState.Never)]
148 public static Radian DirectionDown
152 global::System.IntPtr cPtr = Interop.PanGestureDetector.DirectionDownGet();
153 Radian ret = (cPtr == global::System.IntPtr.Zero) ? null : new Radian(cPtr, false);
154 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
160 /// For a left and right pan (PI Radians). Useful for AddDirection().
162 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
163 [EditorBrowsable(EditorBrowsableState.Never)]
164 public static Radian DirectionHorizontal
168 global::System.IntPtr cPtr = Interop.PanGestureDetector.DirectionHorizontalGet();
169 Radian ret = (cPtr == global::System.IntPtr.Zero) ? null : new Radian(cPtr, false);
170 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
176 /// For an up and down pan (-0.5 * PI Radians). Useful for AddDirection().
178 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
179 [EditorBrowsable(EditorBrowsableState.Never)]
180 public static Radian DirectionVertical
184 global::System.IntPtr cPtr = Interop.PanGestureDetector.DirectionVerticalGet();
185 Radian ret = (cPtr == global::System.IntPtr.Zero) ? null : new Radian(cPtr, false);
186 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
192 /// The default threshold is PI * 0.25 radians (or 45 degrees).
194 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
195 [EditorBrowsable(EditorBrowsableState.Never)]
196 public static Radian DefaultThreshold
200 global::System.IntPtr cPtr = Interop.PanGestureDetector.DefaultThresholdGet();
201 Radian ret = (cPtr == global::System.IntPtr.Zero) ? null : new Radian(cPtr, false);
202 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
208 /// Retrieves the screen position.
210 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
211 [EditorBrowsable(EditorBrowsableState.Never)]
212 public Vector2 ScreenPosition
216 Vector2 temp = new Vector2(0.0f, 0.0f);
217 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
223 /// Retrieves the screen displacement.
225 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
226 [EditorBrowsable(EditorBrowsableState.Never)]
227 public Vector2 ScreenDisplacement
231 Vector2 temp = new Vector2(0.0f, 0.0f);
232 var pValue = Tizen.NUI.Object.GetProperty(SwigCPtr, PanGestureDetector.Property.ScreenDisplacement);
240 /// Retrieves the screen velocity.
242 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
243 [EditorBrowsable(EditorBrowsableState.Never)]
244 public Vector2 ScreenVelocity
248 Vector2 temp = new Vector2(0.0f, 0.0f);
249 var pValue = Tizen.NUI.Object.GetProperty(SwigCPtr, PanGestureDetector.Property.ScreenVelocity);
257 /// Retrieves the local position.
259 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
260 [EditorBrowsable(EditorBrowsableState.Never)]
261 public Vector2 LocalPosition
265 Vector2 temp = new Vector2(0.0f, 0.0f);
266 var pValue = Tizen.NUI.Object.GetProperty(SwigCPtr, PanGestureDetector.Property.LocalPosition);
274 /// Retrieves the local displacement
276 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
277 [EditorBrowsable(EditorBrowsableState.Never)]
278 public Vector2 LocalDisplacement
282 Vector2 temp = new Vector2(0.0f, 0.0f);
283 var pValue = Tizen.NUI.Object.GetProperty(SwigCPtr, PanGestureDetector.Property.LocalDisplacement);
291 /// Retrieves the local velocity.
293 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
294 [EditorBrowsable(EditorBrowsableState.Never)]
295 public Vector2 LocalVelocity
299 Vector2 temp = new Vector2(0.0f, 0.0f);
300 var pValue = Tizen.NUI.Object.GetProperty(SwigCPtr, PanGestureDetector.Property.LocalVelocity);
308 /// Retrieves the panning flag.
310 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
311 [EditorBrowsable(EditorBrowsableState.Never)]
317 var pValue = Tizen.NUI.Object.GetProperty(SwigCPtr, PanGestureDetector.Property.PANNING);
318 pValue.Get(out temp);
325 /// This is the minimum number of touches required for the pan gesture to be detected.
327 /// <param name="minimum">Minimum touches required</param>
328 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
329 [EditorBrowsable(EditorBrowsableState.Never)]
330 public void SetMinimumTouchesRequired(uint minimum)
332 Interop.PanGestureDetector.SetMinimumTouchesRequired(SwigCPtr, minimum);
333 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
337 /// This is the maximum number of touches required for the pan gesture to be detected.
339 /// <param name="maximum">Maximum touches required</param>
340 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
341 [EditorBrowsable(EditorBrowsableState.Never)]
342 public void SetMaximumTouchesRequired(uint maximum)
344 Interop.PanGestureDetector.SetMaximumTouchesRequired(SwigCPtr, maximum);
345 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
349 /// Retrieves the minimum number of touches required for the pan gesture to be detected.
351 /// <returns>The minimum touches required</returns>
352 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
353 [EditorBrowsable(EditorBrowsableState.Never)]
354 public uint GetMinimumTouchesRequired()
356 uint ret = Interop.PanGestureDetector.GetMinimumTouchesRequired(SwigCPtr);
357 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
362 /// Retrieves the maximum number of touches required for the pan gesture to be detected.
364 /// <returns>The maximum touches required</returns>
365 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
366 [EditorBrowsable(EditorBrowsableState.Never)]
367 public uint GetMaximumTouchesRequired()
369 uint ret = Interop.PanGestureDetector.GetMaximumTouchesRequired(SwigCPtr);
370 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
375 /// The pan gesture is only emitted if the pan occurs in the direction specified by this method with a +/- threshold allowance.<br />
376 /// If an angle of 0.0 degrees is specified and the threshold is 45 degrees then the acceptable direction range is from -45 to 45 degrees.<br />
377 /// The angle added using this API is only checked when the gesture first starts, after that, this detector will emit the gesture regardless of what angle the pan is moving.
378 /// The user can add as many angles as they require.
380 /// <param name="angle">The angle that pan should be allowed</param>
381 /// <param name="threshold">The threshold around that angle</param>
382 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
383 [EditorBrowsable(EditorBrowsableState.Never)]
384 public void AddAngle(Radian angle, Radian threshold)
386 Interop.PanGestureDetector.AddAngle(SwigCPtr, Radian.getCPtr(angle), Radian.getCPtr(threshold));
387 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
391 /// The pan gesture is only emitted if the pan occurs in the direction specified by this method with a +/- threshold allowance. The default threshold (PI * 0.25) is used.<br />
392 /// The angle added using this API is only checked when the gesture first starts, after that, this detector will emit the gesture regardless of what angle the pan is moving.<br />
393 /// The user can add as many angles as they require.<br />
395 /// <param name="angle">The angle that pan should be allowed</param>
396 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
397 [EditorBrowsable(EditorBrowsableState.Never)]
398 public void AddAngle(Radian angle)
400 Interop.PanGestureDetector.AddAngle(SwigCPtr, Radian.getCPtr(angle));
401 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
405 /// A helper method for adding bi-directional angles where the pan should take place.<br />
406 /// In other words, if 0 is requested, then PI will also be added so that we have both left and right scrolling.<br />
408 /// <param name="direction">The direction of panning required</param>
409 /// <param name="threshold">The threshold</param>
410 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
411 [EditorBrowsable(EditorBrowsableState.Never)]
412 public void AddDirection(Radian direction, Radian threshold)
414 Interop.PanGestureDetector.AddDirection(SwigCPtr, Radian.getCPtr(direction), Radian.getCPtr(threshold));
415 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
419 /// A helper method for adding bi-directional angles where the pan should take place.
420 /// In other words, if 0 is requested, then PI will also be added so that we have both left and right scrolling.<br />
421 /// The default threshold (PI * 0.25) is used.
423 /// <param name="direction">The direction of panning required</param>
424 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
425 [EditorBrowsable(EditorBrowsableState.Never)]
426 public void AddDirection(Radian direction)
428 Interop.PanGestureDetector.AddDirection(SwigCPtr, Radian.getCPtr(direction));
429 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
433 /// Returns the count of angles that this pan gesture detector emits a signal.
435 /// <returns>The gesture detector has been initialized.</returns>
436 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
437 [EditorBrowsable(EditorBrowsableState.Never)]
438 public uint GetAngleCount()
440 uint ret = Interop.PanGestureDetector.GetAngleCount(SwigCPtr);
441 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
446 /// Clears any directional angles that are used by the gesture detector.
448 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
449 [EditorBrowsable(EditorBrowsableState.Never)]
450 public void ClearAngles()
452 Interop.PanGestureDetector.ClearAngles(SwigCPtr);
453 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
457 /// Removes the angle specified from the container. This will only remove the first instance of the angle found from the container.
459 /// <param name="angle">The angle to remove</param>
460 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
461 [EditorBrowsable(EditorBrowsableState.Never)]
462 public void RemoveAngle(Radian angle)
464 Interop.PanGestureDetector.RemoveAngle(SwigCPtr, Radian.getCPtr(angle));
465 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
469 /// Removes the two angles that make up the direction from the container.
471 /// <param name="direction">The direction to remove</param>
472 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
473 [EditorBrowsable(EditorBrowsableState.Never)]
474 public void RemoveDirection(Radian direction)
476 Interop.PanGestureDetector.RemoveDirection(SwigCPtr, Radian.getCPtr(direction));
477 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
481 /// Allows setting of the pan properties that are returned in constraints.
483 /// <param name="pan">The pan gesture to set</param>
484 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
485 [EditorBrowsable(EditorBrowsableState.Never)]
486 public static void SetPanGestureProperties(PanGesture pan)
488 Interop.PanGestureDetector.SetPanGestureProperties(PanGesture.getCPtr(pan));
489 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
492 internal static PanGestureDetector GetPanGestureDetectorFromPtr(global::System.IntPtr cPtr)
494 PanGestureDetector ret = new PanGestureDetector(cPtr, false);
495 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
499 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PanGestureDetector obj)
501 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
504 internal new static PanGestureDetector DownCast(BaseHandle handle)
506 PanGestureDetector ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as PanGestureDetector;
507 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
511 internal AngleThresholdPair GetAngle(uint index)
513 AngleThresholdPair ret = new AngleThresholdPair(Interop.PanGestureDetector.GetAngle(SwigCPtr, index), true);
514 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
518 internal PanGestureDetector Assign(PanGestureDetector rhs)
520 PanGestureDetector ret = new PanGestureDetector(Interop.PanGestureDetector.Assign(SwigCPtr, PanGestureDetector.getCPtr(rhs)), false);
521 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
525 internal PanGestureDetectedSignal DetectedSignal()
527 PanGestureDetectedSignal ret = new PanGestureDetectedSignal(Interop.PanGestureDetector.DetectedSignal(SwigCPtr), false);
528 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
532 /// This will not be public opened.
533 [EditorBrowsable(EditorBrowsableState.Never)]
534 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
536 if (_detectedCallback != null)
538 detectedSignal?.Disconnect(_detectedCallback);
539 detectedSignal?.Dispose();
542 Interop.PanGestureDetector.DeletePanGestureDetector(swigCPtr);
545 private void OnPanGestureDetected(IntPtr actor, IntPtr panGesture)
547 DetectedEventArgs e = new DetectedEventArgs();
549 // Populate all members of "e" (PanGestureEventArgs) with real data
550 e.View = Registry.GetManagedBaseHandleFromNativePtr(actor) as View;
553 e.View = Registry.GetManagedBaseHandleFromRefObject(actor) as View;
556 e.PanGesture = Tizen.NUI.PanGesture.GetPanGestureFromPtr(panGesture);
558 if (_detectedEventHandler != null)
560 _detectedEventHandler(this, e);
565 /// Event arguments that are passed via the PanGestureEvent signal.
567 /// <since_tizen> 5 </since_tizen>
568 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
569 [EditorBrowsable(EditorBrowsableState.Never)]
570 public class DetectedEventArgs : EventArgs
573 private PanGesture _panGesture;
576 /// The attached view.
578 /// <since_tizen> 5 </since_tizen>
579 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
580 [EditorBrowsable(EditorBrowsableState.Never)]
596 /// <since_tizen> 5 </since_tizen>
597 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
598 [EditorBrowsable(EditorBrowsableState.Never)]
599 public PanGesture PanGesture
612 internal class Property
614 internal static readonly int ScreenPosition = Interop.PanGestureDetector.ScreenPositionGet();
615 internal static readonly int ScreenDisplacement = Interop.PanGestureDetector.ScreenDisplacementGet();
616 internal static readonly int ScreenVelocity = Interop.PanGestureDetector.ScreenVelocityGet();
617 internal static readonly int LocalPosition = Interop.PanGestureDetector.LocalPositionGet();
618 internal static readonly int LocalDisplacement = Interop.PanGestureDetector.LocalDisplacementGet();
619 internal static readonly int LocalVelocity = Interop.PanGestureDetector.LocalVelocityGet();
620 internal static readonly int PANNING = Interop.PanGestureDetector.PanningGet();