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