[NUI] View Transition with page switching
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Transition / TransitionItemBase.cs
1 /*
2  * Copyright(c) 2021 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     using System;
21     using System.ComponentModel;
22     using Tizen.NUI.BaseComponents;
23
24     internal class TransitionItemBase : BaseHandle
25     {
26         /// <summary>
27         /// Creates an initialized TransitionItemBase.<br />
28         /// </summary>
29         public TransitionItemBase(View target, bool isEntering, TimePeriod timePeriod, AlphaFunction alphaFunction) : this(Interop.TransitionItemBase.New(/*target.SwigCPtr, isEntering, timePeriod.SwigCPtr*/), true)
30         {
31             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
32             AlphaFunction = alphaFunction;
33         }
34
35         internal TransitionItemBase(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
36         {
37         }
38
39         /// <summary>
40         /// Gets or sets the duration in milliseconds of the transition.
41         /// </summary>
42         public int Duration
43         {
44             set
45             {
46                 Interop.TransitionItemBase.SetDuration(SwigCPtr, MilliSecondsToSeconds(value));
47                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
48             }
49             get
50             {
51                 float ret = Interop.TransitionItemBase.GetDuration(SwigCPtr);
52                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
53                 return SecondsToMilliSeconds(ret);
54             }
55         }
56
57         /// <summary>
58         /// Gets or sets the delay in milliseconds of the transition.
59         /// </summary>
60         public int Delay
61         {
62             set
63             {
64                 Interop.TransitionItemBase.SetDelay(SwigCPtr, MilliSecondsToSeconds(value));
65                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
66             }
67             get
68             {
69                 float ret = Interop.TransitionItemBase.GetDelay(SwigCPtr);
70                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
71                 return SecondsToMilliSeconds(ret);
72             }
73         }
74
75         /// <summary>
76         /// Gets or sets the TimePeriod
77         /// </summary>
78         public TimePeriod TimePeriod
79         {
80             set
81             {
82                 Interop.TransitionItemBase.SetTimePeriod(SwigCPtr, value.SwigCPtr);
83                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
84             }
85         }
86
87         /// <summary>
88         /// Gets or sets the AlphaFunction
89         /// </summary>
90         public AlphaFunction AlphaFunction
91         {
92             set
93             {
94                 Interop.TransitionItemBase.SetAlphaFunction(SwigCPtr, value.SwigCPtr);
95                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
96             }
97             get
98             {
99                 AlphaFunction ret = new AlphaFunction(Interop.TransitionItemBase.GetAlphaFunction(SwigCPtr), true);
100                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
101                 return ret;
102             }
103         }
104
105         /// <summary>
106         /// Gets or sets whether the View moves with child or not.
107         /// </summary>
108         public bool TransitionWithChild
109         {
110             set
111             {
112                 Interop.TransitionItemBase.TransitionWithChild(SwigCPtr, value);
113                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
114             }
115         }
116
117         /// <summary>
118         /// Downcasts a handle to TransitionItemBase handle.<br />
119         /// If handle points to an TransitionItemBase object, the downcast produces a valid handle.<br />
120         /// If not, the returned handle is left uninitialized.<br />
121         /// </summary>
122         /// <param name="handle">Handle to an object.</param>
123         /// <returns>Handle to an TransitionItemBase object or an uninitialized handle.</returns>
124         /// <exception cref="ArgumentNullException"> Thrown when handle is null. </exception>
125         public static TransitionItemBase DownCast(BaseHandle handle)
126         {
127             if (handle == null)
128             {
129                 throw new ArgumentNullException(nameof(handle));
130             }
131             TransitionItemBase ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as TransitionItemBase;
132             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
133             return ret;
134         }
135
136         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TransitionItemBase obj)
137         {
138             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
139         }
140
141         internal TransitionItemBase(TransitionItemBase handle) : this(Interop.TransitionItemBase.NewTransitionItemBase(TransitionItemBase.getCPtr(handle)), true)
142         {
143             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
144         }
145
146         internal TransitionItemBase Assign(TransitionItemBase rhs)
147         {
148             TransitionItemBase ret = new TransitionItemBase(Interop.TransitionItemBase.Assign(SwigCPtr, TransitionItemBase.getCPtr(rhs)), false);
149             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
150             return ret;
151         }
152
153         /// <summary>
154         /// To make TransitionItemBase instance be disposed.
155         /// </summary>
156         protected override void Dispose(DisposeTypes type)
157         {
158             if (disposed)
159             {
160                 return;
161             }
162             base.Dispose(type);
163         }
164
165         /// This will not be public opened.
166         [EditorBrowsable(EditorBrowsableState.Never)]
167         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
168         {
169             if (swigCPtr.Handle == IntPtr.Zero || this.HasBody() == false)
170             {
171                 Tizen.Log.Fatal("NUI", $"[ERROR] TransitionItemBase ReleaseSwigCPtr()! IntPtr=0x{swigCPtr.Handle:X} HasBody={this.HasBody()}");
172                 return;
173             }
174             Interop.TransitionItemBase.Delete(swigCPtr);
175         }
176
177         private float MilliSecondsToSeconds(int millisec)
178         {
179             return (float)millisec / 1000.0f;
180         }
181
182         private int SecondsToMilliSeconds(float sec)
183         {
184             return (int)(sec * 1000);
185         }
186     }
187 }