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