[NUI] Refactor dispose pattern to reduce duplication (#1112)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / 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 fuction. It must be a method formatted as float alphafunction(float progress)</param>
37         /// <since_tizen> 3 </since_tizen>
38         public AlphaFunction(System.Delegate func) : this(Interop.AlphaFunction.new_AlphaFunction__SWIG_2(SWIGTYPE_p_f_float__float.getCPtr(new SWIGTYPE_p_f_float__float(System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(func), true))), 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.new_AlphaFunction__SWIG_0(), 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.new_AlphaFunction__SWIG_1((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.new_AlphaFunction__SWIG_3(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         internal AlphaFunction(SWIGTYPE_p_f_float__float function) : this(Interop.AlphaFunction.new_AlphaFunction__SWIG_2(SWIGTYPE_p_f_float__float.getCPtr(function)), true)
82         {
83             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
84         }
85
86         /// <summary>
87         /// This specifies the various types of BuiltinFunctions.
88         /// </summary>
89         /// <since_tizen> 3 </since_tizen>
90         public enum BuiltinFunctions
91         {
92             /// <summary>
93             /// Linear.
94             /// </summary>
95             [Description("DEFAULT")]
96             Default,
97             /// <summary>
98             /// No transformation.
99             /// </summary>
100             [Description("LINEAR")]
101             Linear,
102             /// <summary>
103             /// Reverse linear.
104             /// </summary>
105             [Description("REVERSE")]
106             Reverse,
107             /// <summary>
108             /// Speeds up and comes to a sudden stop (square).
109             /// </summary>
110             [Description("EASE_IN_SQUARE")]
111             EaseInSquare,
112             /// <summary>
113             /// Sudden start and slows to a gradual stop (square).
114             /// </summary>
115             [Description("EASE_OUT_SQUARE")]
116             EaseOutSquare,
117             /// <summary>
118             /// Speeds up and comes to a sudden stop (cubic).
119             /// </summary>
120             [Description("EASE_IN")]
121             EaseIn,
122             /// <summary>
123             /// Sudden start and slows to a gradual stop (cubic).
124             /// </summary>
125             [Description("EASE_OUT")]
126             EaseOut,
127             /// <summary>
128             /// Speeds up and slows to a gradual stop (cubic).
129             /// </summary>
130             [Description("EASE_IN_OUT")]
131             EaseInOut,
132             /// <summary>
133             /// Speeds up and comes to a sudden stop (sinusoidal).
134             /// </summary>
135             [Description("EASE_IN_SINE")]
136             EaseInSine,
137             /// <summary>
138             /// Sudden start and slows to a gradual stop (sinusoidal).
139             /// </summary>
140             [Description("EASE_OUT_SINE")]
141             EaseOutSine,
142             /// <summary>
143             /// Speeds up and slows to a gradual stop (sinusoidal).
144             /// </summary>
145             [Description("EASE_IN_OUT_SINE")]
146             EaseInOutSine,
147             /// <summary>
148             /// Sudden start, loses momentum and returns to start position.
149             /// </summary>
150             [Description("BOUNCE")]
151             Bounce,
152             /// <summary>
153             /// Single revolution.
154             /// </summary>
155             [Description("SIN")]
156             Sin,
157             /// <summary>
158             /// Sudden start, exceed end position and return to a gradual stop.
159             /// </summary>
160             [Description("EASE_OUT_BACK")]
161             EaseOutBack,
162             /// <summary>
163             /// The count of the BuiltinFunctions enum.
164             /// </summary>
165             Count
166         }
167
168         /// <summary>
169         /// This specifies which mode is set for AlphaFunction.
170         /// </summary>
171         /// <since_tizen> 3 </since_tizen>
172         public enum Modes
173         {
174             /// <summary>
175             /// The user has used a built-in function.
176             /// </summary>
177             BuiltinFunction,
178
179             /// <summary>
180             /// The user has provided a custom function.
181             /// </summary>
182             CustomFunction,
183             /// <summary>
184             /// The user has provided the control points of a bezier curve.
185             /// </summary>
186             Bezier
187         }
188
189         /// <summary>
190         /// Retrives the control points of the alpha function.<br />
191         /// </summary>
192         /// <param name="controlPoint0">A Vector2 which will be used as the first control point of the curve.</param>
193         /// <param name="controlPoint1">A Vector2 which will be used as the second control point of the curve.</param>
194         /// <since_tizen> 3 </since_tizen>
195         public void GetBezierControlPoints(out Vector2 controlPoint0, out Vector2 controlPoint1)
196         {
197             Vector4 ret = new Vector4(Interop.AlphaFunction.AlphaFunction_GetBezierControlPoints(swigCPtr), true);
198             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
199
200             controlPoint0 = new Vector2(ret.X, ret.Y);
201             controlPoint1 = new Vector2(ret.Z, ret.W);
202         }
203
204         /// <summary>
205         /// Returns the built-in function used by the alpha function.<br />
206         /// In case no built-in function has been specified, it will return AlphaFunction::DEFAULT.<br />
207         /// </summary>
208         /// <returns>One of the built-in alpha functions.</returns>
209         /// <since_tizen> 3 </since_tizen>
210         public AlphaFunction.BuiltinFunctions GetBuiltinFunction()
211         {
212             AlphaFunction.BuiltinFunctions ret = (AlphaFunction.BuiltinFunctions)Interop.AlphaFunction.AlphaFunction_GetBuiltinFunction(swigCPtr);
213             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
214             return ret;
215         }
216
217         /// <summary>
218         ///  Returns the functioning mode of the alpha function.
219         /// </summary>
220         /// <returns>The functioning mode of the alpha function.</returns>
221         /// <since_tizen> 3 </since_tizen>
222         public AlphaFunction.Modes GetMode()
223         {
224             AlphaFunction.Modes ret = (AlphaFunction.Modes)Interop.AlphaFunction.AlphaFunction_GetMode(swigCPtr);
225             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
226             return ret;
227         }
228
229         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(AlphaFunction obj)
230         {
231             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
232         }
233
234         internal static string BuiltinToPropertyKey(BuiltinFunctions? alphaFunction)
235         {
236             string propertyKey = null;
237             if (alphaFunction != null)
238             {
239                 switch (alphaFunction)
240                 {
241                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.Linear:
242                         {
243                             propertyKey = "LINEAR";
244                             break;
245                         }
246                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.Reverse:
247                         {
248                             propertyKey = "REVERSE";
249                             break;
250                         }
251                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseInSquare:
252                         {
253                             propertyKey = "EASE_IN_SQUARE";
254                             break;
255                         }
256                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseOutSquare:
257                         {
258                             propertyKey = "EASE_OUT_SQUARE";
259                             break;
260                         }
261                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseIn:
262                         {
263                             propertyKey = "EASE_IN";
264                             break;
265                         }
266                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseOut:
267                         {
268                             propertyKey = "EASE_OUT";
269                             break;
270                         }
271                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseInOut:
272                         {
273                             propertyKey = "EASE_IN_OUT";
274                             break;
275                         }
276                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseInSine:
277                         {
278                             propertyKey = "EASE_IN_SINE";
279                             break;
280                         }
281                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseOutSine:
282                         {
283                             propertyKey = "EASE_OUT_SINE";
284                             break;
285                         }
286                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseInOutSine:
287                         {
288                             propertyKey = "EASE_IN_OUT_SINE";
289                             break;
290                         }
291                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.Bounce:
292                         {
293                             propertyKey = "BOUNCE";
294                             break;
295                         }
296                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.Sin:
297                         {
298                             propertyKey = "SIN";
299                             break;
300                         }
301                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseOutBack:
302                         {
303                             propertyKey = "EASE_OUT_BACK";
304                             break;
305                         }
306                     default:
307                         {
308                             propertyKey = "DEFAULT";
309                             break;
310                         }
311                 }
312             }
313             return propertyKey;
314         }
315
316         internal SWIGTYPE_p_f_float__float GetCustomFunction()
317         {
318             global::System.IntPtr cPtr = Interop.AlphaFunction.AlphaFunction_GetCustomFunction(swigCPtr);
319             SWIGTYPE_p_f_float__float ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_f_float__float(cPtr, false);
320             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
321             return ret;
322         }
323
324         /// This will not be public opened.
325         [EditorBrowsable(EditorBrowsableState.Never)]
326         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
327         {
328             Interop.AlphaFunction.delete_AlphaFunction(swigCPtr);
329         }
330     }
331 }