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 /// It tries to detect when the user moves two touch points towards or away from each other.
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 PinchGestureDetector : GestureDetector
32 /// Creates an initialized PinchGestureDetector.
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 PinchGestureDetector() : this(Interop.PinchGesture.PinchGestureDetectorNew(), 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 PinchGestureDetector(PinchGestureDetector handle) : this(Interop.PinchGesture.NewPinchGestureDetector(PinchGestureDetector.getCPtr(handle)), true)
50 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
53 internal PinchGestureDetector(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.PinchGesture.PinchGestureDetectorUpcast(cPtr), cMemoryOwn)
57 private DaliEventHandler<object, DetectedEventArgs> _detectedEventHandler;
58 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
59 private delegate void DetectedCallbackType(IntPtr actor, IntPtr pinchGesture);
60 private DetectedCallbackType _detectedCallback;
61 private PinchGestureDetectedSignal detectedSignal;
64 /// This signal is emitted when the specified pinch 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 = OnPinchGestureDetected;
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 internal static PinchGestureDetector GetPinchGestureDetectorFromPtr(global::System.IntPtr cPtr)
98 PinchGestureDetector ret = new PinchGestureDetector(cPtr, false);
99 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
103 internal new static PinchGestureDetector DownCast(BaseHandle handle)
105 PinchGestureDetector ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as PinchGestureDetector;
106 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
110 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PinchGestureDetector obj)
112 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
115 internal PinchGestureDetector Assign(PinchGestureDetector rhs)
117 PinchGestureDetector ret = new PinchGestureDetector(Interop.PinchGesture.PinchGestureDetectorAssign(SwigCPtr, PinchGestureDetector.getCPtr(rhs)), false);
118 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
122 internal PinchGestureDetectedSignal DetectedSignal()
124 PinchGestureDetectedSignal ret = new PinchGestureDetectedSignal(Interop.PinchGesture.PinchGestureDetectorDetectedSignal(SwigCPtr), false);
125 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
129 /// This will not be public opened.
130 [EditorBrowsable(EditorBrowsableState.Never)]
131 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
133 if (_detectedCallback != null)
135 detectedSignal?.Disconnect(_detectedCallback);
136 detectedSignal?.Dispose();
139 Interop.PinchGesture.DeletePinchGestureDetector(swigCPtr);
142 private void OnPinchGestureDetected(IntPtr actor, IntPtr pinchGesture)
144 DetectedEventArgs e = new DetectedEventArgs();
146 // Populate all members of "e" (DetectedEventArgs) with real data.
147 e.View = Registry.GetManagedBaseHandleFromNativePtr(actor) as View;
150 e.View = Registry.GetManagedBaseHandleFromRefObject(actor) as View;
153 e.PinchGesture = Tizen.NUI.PinchGesture.GetPinchGestureFromPtr(pinchGesture);
155 if (_detectedEventHandler != null)
157 //Here we send all data to user event handlers.
158 _detectedEventHandler(this, e);
163 /// Event arguments that passed via the PinchGestureEvent signal.
165 /// <since_tizen> 5 </since_tizen>
166 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
167 [EditorBrowsable(EditorBrowsableState.Never)]
168 public class DetectedEventArgs : EventArgs
171 private PinchGesture _pinchGesture;
174 /// The attached view.
176 /// <since_tizen> 5 </since_tizen>
177 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
178 [EditorBrowsable(EditorBrowsableState.Never)]
192 /// The PinchGesture.
194 /// <since_tizen> 5 </since_tizen>
195 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
196 [EditorBrowsable(EditorBrowsableState.Never)]
197 public PinchGesture PinchGesture
201 return _pinchGesture;
205 _pinchGesture = value;