[NUI] Remove duplicate getCPtr from Disposable/View subclasses (#3544)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Animation / AlphaFunction.cs
1 /*
2  * Copyright(c) 2019 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 using System.ComponentModel;
19
20 namespace Tizen.NUI
21 {
22
23     /// <summary>
24     /// Alpha functions are used in animations to specify the rate of change of the animation parameter over time.<br />
25     /// Understanding an animation as a parametric function over time, the alpha function is applied to the parameter of
26     /// the animation before computing the final animation value.
27     /// </summary>
28     /// <since_tizen> 3 </since_tizen>
29     public class AlphaFunction : Disposable
30     {
31
32         /// <summary>
33         /// The constructor.<br />
34         /// Creates an alpha function object with the user-defined alpha function.<br />
35         /// </summary>
36         /// <param name="func">User defined function. It must be a method formatted as float alphafunction(float progress)</param>
37         /// <since_tizen> 3 </since_tizen>
38         public AlphaFunction(global::System.Delegate func) : this(Interop.AlphaFunction.NewAlphaFunction(SWIGTYPE_p_f_float__float.getCPtr(new SWIGTYPE_p_f_float__float(System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(func)))), true)
39         {
40             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
41         }
42
43         /// <summary>
44         /// The default constructor.<br />
45         /// Creates an alpha function object with the default built-in alpha function.<br />
46         /// </summary>
47         /// <since_tizen> 3 </since_tizen>
48         public AlphaFunction() : this(Interop.AlphaFunction.NewAlphaFunction(), true)
49         {
50             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
51         }
52
53         /// <summary>
54         /// The constructor.<br />
55         /// Creates an alpha function object with the built-in alpha function passed as a parameter to the constructor.<br />
56         /// </summary>
57         /// <param name="function">One of the built-in alpha functions.</param>
58         /// <since_tizen> 3 </since_tizen>
59         public AlphaFunction(AlphaFunction.BuiltinFunctions function) : this(Interop.AlphaFunction.NewAlphaFunction((int)function), true)
60         {
61             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
62         }
63
64         /// <summary>
65         /// The constructor.<br />
66         /// Creates a bezier alpha function. The bezier will have the first point at (0,0) and the end point at (1,1).<br />
67         /// </summary>
68         /// <remarks>The x components of the control points will be clamped to the range [0, 1] to prevent non-monotonic curves.</remarks>
69         /// <param name="controlPoint0">A Vector2 which will be used as the first control point of the curve.</param>
70         /// <param name="controlPoint1">A Vector2 which will be used as the second control point of the curve.</param>
71         /// <since_tizen> 3 </since_tizen>
72         public AlphaFunction(Vector2 controlPoint0, Vector2 controlPoint1) : this(Interop.AlphaFunction.NewAlphaFunction(Vector2.getCPtr(controlPoint0), Vector2.getCPtr(controlPoint1)), true)
73         {
74             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
75         }
76
77         internal AlphaFunction(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
78         {
79         }
80
81         // Not used : This will be remained by 2021-05-30 to check side effect. After 2021-05-30 this will be removed cleanly
82         // internal AlphaFunction(SWIGTYPE_p_f_float__float function) : this(Interop.AlphaFunction.NewAlphaFunction(SWIGTYPE_p_f_float__float.getCPtr(function)), true)
83         // {
84         //     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
85         // }
86
87         /// <summary>
88         /// This specifies the various types of BuiltinFunctions.
89         /// </summary>
90         /// <since_tizen> 3 </since_tizen>
91         [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names")]
92         public enum BuiltinFunctions
93         {
94             /// <summary>
95             /// Linear.
96             /// </summary>
97             [Description("DEFAULT")]
98             Default,
99             /// <summary>
100             /// No transformation.
101             /// </summary>
102             [Description("LINEAR")]
103             Linear,
104             /// <summary>
105             /// Reverse linear.
106             /// </summary>
107             [Description("REVERSE")]
108             Reverse,
109             /// <summary>
110             /// Speeds up and comes to a sudden stop (square).
111             /// </summary>
112             [Description("EASE_IN_SQUARE")]
113             EaseInSquare,
114             /// <summary>
115             /// Sudden start and slows to a gradual stop (square).
116             /// </summary>
117             [Description("EASE_OUT_SQUARE")]
118             EaseOutSquare,
119             /// <summary>
120             /// Speeds up and comes to a sudden stop (cubic).
121             /// </summary>
122             [Description("EASE_IN")]
123             EaseIn,
124             /// <summary>
125             /// Sudden start and slows to a gradual stop (cubic).
126             /// </summary>
127             [Description("EASE_OUT")]
128             EaseOut,
129             /// <summary>
130             /// Speeds up and slows to a gradual stop (cubic).
131             /// </summary>
132             [Description("EASE_IN_OUT")]
133             EaseInOut,
134             /// <summary>
135             /// Speeds up and comes to a sudden stop (sinusoidal).
136             /// </summary>
137             [Description("EASE_IN_SINE")]
138             EaseInSine,
139             /// <summary>
140             /// Sudden start and slows to a gradual stop (sinusoidal).
141             /// </summary>
142             [Description("EASE_OUT_SINE")]
143             EaseOutSine,
144             /// <summary>
145             /// Speeds up and slows to a gradual stop (sinusoidal).
146             /// </summary>
147             [Description("EASE_IN_OUT_SINE")]
148             EaseInOutSine,
149             /// <summary>
150             /// Sudden start, loses momentum and returns to start position.
151             /// </summary>
152             [Description("BOUNCE")]
153             Bounce,
154             /// <summary>
155             /// Single revolution.
156             /// </summary>
157             [Description("SIN")]
158             Sin,
159             /// <summary>
160             /// Sudden start, exceed end position and return to a gradual stop.
161             /// </summary>
162             [Description("EASE_OUT_BACK")]
163             EaseOutBack,
164             /// <summary>
165             /// The count of the BuiltinFunctions enum.
166             /// </summary>
167             Count
168         }
169
170         /// <summary>
171         /// This specifies which mode is set for AlphaFunction.
172         /// </summary>
173         /// <since_tizen> 3 </since_tizen>
174         [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names")]
175         public enum Modes
176         {
177             /// <summary>
178             /// The user has used a built-in function.
179             /// </summary>
180             BuiltinFunction,
181
182             /// <summary>
183             /// The user has provided a custom function.
184             /// </summary>
185             CustomFunction,
186             /// <summary>
187             /// The user has provided the control points of a bezier curve.
188             /// </summary>
189             Bezier
190         }
191
192         /// <summary>
193         /// Retrieves the control points of the alpha function.<br />
194         /// </summary>
195         /// <param name="controlPoint0">A Vector2 which will be used as the first control point of the curve.</param>
196         /// <param name="controlPoint1">A Vector2 which will be used as the second control point of the curve.</param>
197         /// <since_tizen> 3 </since_tizen>
198         public void GetBezierControlPoints(out Vector2 controlPoint0, out Vector2 controlPoint1)
199         {
200             Vector4 ret = new Vector4(Interop.AlphaFunction.GetBezierControlPoints(SwigCPtr), true);
201             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
202
203             controlPoint0 = new Vector2(ret.X, ret.Y);
204             controlPoint1 = new Vector2(ret.Z, ret.W);
205         }
206
207         /// <summary>
208         /// Returns the built-in function used by the alpha function.<br />
209         /// In case no built-in function has been specified, it will return AlphaFunction::DEFAULT.<br />
210         /// </summary>
211         /// <returns>One of the built-in alpha functions.</returns>
212         /// <since_tizen> 3 </since_tizen>
213         public AlphaFunction.BuiltinFunctions GetBuiltinFunction()
214         {
215             AlphaFunction.BuiltinFunctions ret = (AlphaFunction.BuiltinFunctions)Interop.AlphaFunction.GetBuiltinFunction(SwigCPtr);
216             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
217             return ret;
218         }
219
220         /// <summary>
221         ///  Returns the functioning mode of the alpha function.
222         /// </summary>
223         /// <returns>The functioning mode of the alpha function.</returns>
224         /// <since_tizen> 3 </since_tizen>
225         public AlphaFunction.Modes GetMode()
226         {
227             AlphaFunction.Modes ret = (AlphaFunction.Modes)Interop.AlphaFunction.GetMode(SwigCPtr);
228             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
229             return ret;
230         }
231
232         internal static string BuiltinToPropertyKey(BuiltinFunctions? alphaFunction)
233         {
234             string propertyKey = null;
235             if (alphaFunction != null)
236             {
237                 switch (alphaFunction)
238                 {
239                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.Linear:
240                         {
241                             propertyKey = "LINEAR";
242                             break;
243                         }
244                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.Reverse:
245                         {
246                             propertyKey = "REVERSE";
247                             break;
248                         }
249                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseInSquare:
250                         {
251                             propertyKey = "EASE_IN_SQUARE";
252                             break;
253                         }
254                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseOutSquare:
255                         {
256                             propertyKey = "EASE_OUT_SQUARE";
257                             break;
258                         }
259                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseIn:
260                         {
261                             propertyKey = "EASE_IN";
262                             break;
263                         }
264                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseOut:
265                         {
266                             propertyKey = "EASE_OUT";
267                             break;
268                         }
269                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseInOut:
270                         {
271                             propertyKey = "EASE_IN_OUT";
272                             break;
273                         }
274                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseInSine:
275                         {
276                             propertyKey = "EASE_IN_SINE";
277                             break;
278                         }
279                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseOutSine:
280                         {
281                             propertyKey = "EASE_OUT_SINE";
282                             break;
283                         }
284                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseInOutSine:
285                         {
286                             propertyKey = "EASE_IN_OUT_SINE";
287                             break;
288                         }
289                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.Bounce:
290                         {
291                             propertyKey = "BOUNCE";
292                             break;
293                         }
294                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.Sin:
295                         {
296                             propertyKey = "SIN";
297                             break;
298                         }
299                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseOutBack:
300                         {
301                             propertyKey = "EASE_OUT_BACK";
302                             break;
303                         }
304                     default:
305                         {
306                             propertyKey = "DEFAULT";
307                             break;
308                         }
309                 }
310             }
311             return propertyKey;
312         }
313
314         // Not used : This will be remained by 2021-05-30 to check side effect. After 2021-05-30 this will be removed cleanly
315         // internal SWIGTYPE_p_f_float__float GetCustomFunction()
316         // {
317         //     global::System.IntPtr cPtr = Interop.AlphaFunction.GetCustomFunction(SwigCPtr);
318         //     SWIGTYPE_p_f_float__float ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_f_float__float(cPtr);
319         //     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
320         //     return ret;
321         // }
322
323         /// This will not be public opened.
324         [EditorBrowsable(EditorBrowsableState.Never)]
325         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
326         {
327             Interop.AlphaFunction.DeleteAlphaFunction(swigCPtr);
328         }
329     }
330 }