2 * Copyright(c) 2021 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.
19 using System.ComponentModel;
20 using System.Runtime.InteropServices;
25 /// TransitionSet is used to control lifetime of multiple Transitions.
26 /// For the one page transition, may multiple transitions are played coincidently.
27 /// Every transitions added on a TransitionSet have same play lifetime. And emit a single Finished signal.
29 internal class TransitionSet : BaseHandle
31 private TransitionSetFinishedEventCallbackType transitionSetFinishedEventCallback;
32 private System.IntPtr finishedCallbackOfNative;
35 /// Creates an initialized transitionSet.<br />
37 /// <remarks>DurationmSeconds must be greater than zero.</remarks>
38 public TransitionSet() : this(Interop.TransitionSet.New(), true)
40 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
43 internal TransitionSet(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
45 transitionSetFinishedEventCallback = OnFinished;
46 finishedCallbackOfNative = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(transitionSetFinishedEventCallback);
49 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
50 private delegate void TransitionSetFinishedEventCallbackType(IntPtr data);
52 private event EventHandler transitionSetFinishedEventHandler;
55 * @brief Event for the finished signal which can be used to subscribe or unsubscribe the event handler.
56 * The finished signal is emitted when an transitionSet's transitionSets have finished.
58 public event EventHandler Finished
62 if (transitionSetFinishedEventHandler == null && disposed == false)
64 TransitionSetFinishedSignal finishedSignal = FinishedSignal();
65 finishedSignal.Connect(finishedCallbackOfNative);
66 finishedSignal.Dispose();
68 transitionSetFinishedEventHandler += value;
72 transitionSetFinishedEventHandler -= value;
74 TransitionSetFinishedSignal finishedSignal = FinishedSignal();
75 if (transitionSetFinishedEventHandler == null && finishedSignal.Empty() == false)
77 finishedSignal.Disconnect(finishedCallbackOfNative);
79 finishedSignal.Dispose();
84 /// Downcasts a handle to transitionSet handle.<br />
85 /// If handle points to an transitionSet object, the downcast produces a valid handle.<br />
86 /// If not, the returned handle is left uninitialized.<br />
88 /// <param name="handle">Handle to an object.</param>
89 /// <returns>Handle to an transitionSet object or an uninitialized handle.</returns>
90 /// <exception cref="ArgumentNullException"> Thrown when handle is null. </exception>
91 internal static TransitionSet DownCast(BaseHandle handle)
95 throw new ArgumentNullException(nameof(handle));
97 TransitionSet ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as TransitionSet;
98 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
102 public void AddTransition(TransitionItemBase transition)
104 if (transition is TransitionGroupItem)
106 TransitionGroupItem transitionGroup = transition as TransitionGroupItem;
107 for (int index = 0; index < transitionGroup.TransitionCount; ++index)
109 this.AddTransition(transitionGroup.GetTransitionAt(index));
114 Interop.TransitionSet.AddTransition(SwigCPtr, transition.SwigCPtr);
115 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
119 public TransitionItemBase GetTransitionAt(uint index)
121 IntPtr cPtr = Interop.TransitionSet.GetTransitionAt(SwigCPtr, index);
122 TransitionItemBase ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as TransitionItemBase;
125 Interop.BaseHandle.DeleteBaseHandle(new HandleRef(this, cPtr));
129 ret = new TransitionItemBase(cPtr, true);
131 NDalicPINVOKE.ThrowExceptionIfExists();
135 public uint GetTransitionCount()
137 uint ret = Interop.TransitionSet.GetTransitionCount(SwigCPtr);
138 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
143 /// Plays the transitionSet.
147 Interop.TransitionSet.Play(SwigCPtr);
148 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
151 internal TransitionSet(TransitionSet handle) : this(Interop.TransitionSet.NewTransitionSet(TransitionSet.getCPtr(handle)), true)
153 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
156 internal TransitionSet Assign(TransitionSet rhs)
158 TransitionSet ret = new TransitionSet(Interop.TransitionSet.Assign(SwigCPtr, TransitionSet.getCPtr(rhs)), false);
159 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
163 internal TransitionSetFinishedSignal FinishedSignal()
165 TransitionSetFinishedSignal ret = new TransitionSetFinishedSignal(Interop.TransitionSet.FinishedSignal(SwigCPtr), false);
166 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
171 /// To make transitionSet instance be disposed.
173 protected override void Dispose(DisposeTypes type)
180 if (transitionSetFinishedEventHandler != null)
182 TransitionSetFinishedSignal finishedSignal = FinishedSignal();
183 finishedSignal?.Disconnect(finishedCallbackOfNative);
184 finishedSignal?.Dispose();
185 transitionSetFinishedEventHandler = null;
191 /// This will not be public opened.
192 [EditorBrowsable(EditorBrowsableState.Never)]
193 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
195 if (swigCPtr.Handle == IntPtr.Zero || Disposed)
197 Tizen.Log.Fatal("NUI", $"[ERROR] TransitionSet ReleaseSwigCPtr()! IntPtr=0x{swigCPtr.Handle:X} Disposed={Disposed}");
200 Interop.TransitionSet.Delete(swigCPtr);
203 private void OnFinished(IntPtr data)
205 if (transitionSetFinishedEventHandler != null)
207 //here we send all data to user event handlers
208 transitionSetFinishedEventHandler(this, null);