Added support for animating the background color of a view.
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / AlphaFunction.cs
1 // Copyright (c) 2017 Samsung Electronics Co., Ltd.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 //
16 // This File has been auto-generated by SWIG and then modified using DALi Ruby Scripts
17 // Some have been manually changed
18
19 namespace Tizen.NUI
20 {
21
22     /// <summary>
23     /// Alpha functions are used in animations to specify the rate of change of the animation parameter over time.<br>
24     /// Understanding an animation as a parametric function over time, the alpha function is applied to the parameter of
25     /// the animation before computing the final animation value.
26     /// </summary>
27     public class AlphaFunction : global::System.IDisposable
28     {
29         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
30         protected bool swigCMemOwn;
31
32         internal AlphaFunction(global::System.IntPtr cPtr, bool cMemoryOwn)
33         {
34             swigCMemOwn = cMemoryOwn;
35             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
36         }
37
38         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(AlphaFunction obj)
39         {
40             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
41         }
42
43         //NUI Dispose Pattern written by Jinwoo Nam(jjw.nam)
44
45         //A Flag to check who called Dispose(). (By User or DisposeQueue)
46         private bool isDisposeQueued = false;
47         //A Flat to check if it is already disposed.
48         protected bool disposed = false;
49
50         ~AlphaFunction()
51         {
52             if(!isDisposeQueued)
53             {
54                 isDisposeQueued = true;
55                 DisposeQueue.Instance.Add(this);
56             }
57         }
58         /// <summary>
59         /// To make AlphaFunction instance be disposed.
60         /// </summary>
61         public void Dispose()
62         {
63             //Throw excpetion if Dispose() is called in separate thread.
64             if (!Window.IsInstalled())
65             {
66                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
67             }
68
69             if (isDisposeQueued)
70             {
71                 Dispose(DisposeTypes.Implicit);
72             }
73             else
74             {
75                 Dispose(DisposeTypes.Explicit);
76                 System.GC.SuppressFinalize(this);
77             }
78         }
79
80         protected virtual void Dispose(DisposeTypes type)
81         {
82             if (disposed)
83             {
84                 return;
85             }
86
87             if(type == DisposeTypes.Explicit)
88             {
89                 //Called by User
90                 //Release your own managed resources here.
91                 //You should release all of your own disposable objects here.
92             }
93
94             //Release your own unmanaged resources here.
95             //You should not access any managed member here except static instance.
96             //because the execution order of Finalizes is non-deterministic.
97
98             if (swigCPtr.Handle != global::System.IntPtr.Zero)
99             {
100                 if (swigCMemOwn)
101                 {
102                     swigCMemOwn = false;
103                     NDalicPINVOKE.delete_AlphaFunction(swigCPtr);
104                 }
105                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
106             }
107             disposed = true;
108         }
109
110         /// <summary>
111         /// Constructor.<br>
112         /// Creates an alpha function object with user defined alpha function.<br>
113         /// </summary>
114         /// <param name="func">User defined fuction. It must be a method formatted as float alphafunction(float progress)</param>
115         public AlphaFunction(System.Delegate func) : this(NDalicPINVOKE.new_AlphaFunction__SWIG_2(SWIGTYPE_p_f_float__float.getCPtr(new SWIGTYPE_p_f_float__float(System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(func), true))), true)
116         {
117             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
118         }
119
120         /// <summary>
121         /// Default constructor.<br>
122         /// Creates an alpha function object with the default built-in alpha function.<br>
123         /// </summary>
124         public AlphaFunction() : this(NDalicPINVOKE.new_AlphaFunction__SWIG_0(), true)
125         {
126             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
127         }
128
129         /// <summary>
130         /// Constructor.<br>
131         /// Creates an alpha function object with the built-in alpha function passed as a parameter to the constructor.<br>
132         /// </summary>
133         /// <param name="function">One of the built-in alpha functions</param>
134         public AlphaFunction(AlphaFunction.BuiltinFunctions function) : this(NDalicPINVOKE.new_AlphaFunction__SWIG_1((int)function), true)
135         {
136             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
137         }
138
139         internal AlphaFunction(SWIGTYPE_p_f_float__float function) : this(NDalicPINVOKE.new_AlphaFunction__SWIG_2(SWIGTYPE_p_f_float__float.getCPtr(function)), true)
140         {
141             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
142         }
143
144         /// <summary>
145         /// Constructor.<br>
146         /// Creates a bezier alpha function.The bezier will have the first point at(0,0) and the end point at(1,1).<br>
147         /// </summary>
148         /// <remarks>The x components of the control points will be clamped to the range[0, 1] to prevent non monotonic curves.</remarks>
149         /// <param name="controlPoint0">A Vector2 which will be used as the first control point of the curve</param>
150         /// <param name="controlPoint1">A Vector2 which will be used as the second control point of the curve</param>
151         public AlphaFunction(Vector2 controlPoint0, Vector2 controlPoint1) : this(NDalicPINVOKE.new_AlphaFunction__SWIG_3(Vector2.getCPtr(controlPoint0), Vector2.getCPtr(controlPoint1)), true)
152         {
153             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
154         }
155
156         /// <summary>
157         /// Retrives the control points of the alpha function.<br>
158         /// </summary>
159         /// <param name="controlPoint0">A Vector2 which is used as the first control point of the curve</param>
160         /// <param name="controlPoint1">A Vector2 which is used as the second control point of the curve</param>
161         public void GetBezierControlPoints(out Vector2 controlPoint0, out Vector2 controlPoint1)
162         {
163             Vector4 ret = new Vector4(NDalicPINVOKE.AlphaFunction_GetBezierControlPoints(swigCPtr), true);
164             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
165
166             controlPoint0 = new Vector2(ret.X, ret.Y);
167             controlPoint1 = new Vector2(ret.Z, ret.W);
168         }
169
170         internal SWIGTYPE_p_f_float__float GetCustomFunction()
171         {
172             global::System.IntPtr cPtr = NDalicPINVOKE.AlphaFunction_GetCustomFunction(swigCPtr);
173             SWIGTYPE_p_f_float__float ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_f_float__float(cPtr, false);
174             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
175             return ret;
176         }
177
178         /// <summary>
179         /// Returns the built-in function used by the alpha function.<br>
180         /// In case no built-in function has been specified, it will return AlphaFunction::DEFAULT.<br>
181         /// </summary>
182         /// <returns>One of the built-in alpha functions.</returns>
183         public AlphaFunction.BuiltinFunctions GetBuiltinFunction()
184         {
185             AlphaFunction.BuiltinFunctions ret = (AlphaFunction.BuiltinFunctions)NDalicPINVOKE.AlphaFunction_GetBuiltinFunction(swigCPtr);
186             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
187             return ret;
188         }
189
190         /// <summary>
191         ///  Returns the functioning mode of the alpha function
192         /// </summary>
193         /// <returns>The functioning mode of the alpha function</returns>
194         public AlphaFunction.Modes GetMode()
195         {
196             AlphaFunction.Modes ret = (AlphaFunction.Modes)NDalicPINVOKE.AlphaFunction_GetMode(swigCPtr);
197             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
198             return ret;
199         }
200
201         /// <summary>
202         /// This specifies the various types of BuiltinFunctions
203         /// </summary>
204         public enum BuiltinFunctions
205         {
206             /// <summary>
207             /// Linear
208             /// </summary>
209             Default,
210             /// <summary>
211             /// No transformation
212             /// </summary>
213             Linear,
214             /// <summary>
215             /// Reverse linear
216             /// </summary>
217             Reverse,
218             /// <summary>
219             /// Speeds up and comes to a sudden stop (Square)
220             /// </summary>
221             EaseInSquare,
222             /// <summary>
223             /// Sudden start and slows to a gradual stop (Square)
224             /// </summary>
225             EaseOutSquare,
226             /// <summary>
227             /// Speeds up and comes to a sudden stop (Cubic)
228             /// </summary>
229             EaseIn,
230             /// <summary>
231             /// Sudden start and slows to a gradual stop (Cubic)
232             /// </summary>
233             EaseOut,
234             /// <summary>
235             /// Speeds up and slows to a gradual stop (Cubic)
236             /// </summary>
237             EaseInOut,
238             /// <summary>
239             /// Speeds up and comes to a sudden stop (sinusoidal)
240             /// </summary>
241             EaseInSine,
242             /// <summary>
243             /// Sudden start and slows to a gradual stop (sinusoidal)
244             /// </summary>
245             EaseOutSine,
246             /// <summary>
247             /// Speeds up and slows to a gradual stop (sinusoidal)
248             /// </summary>
249             EaseInOutSine,
250             /// <summary>
251             /// Sudden start, loses momentum and returns to start position
252             /// </summary>
253             Bounce,
254             /// <summary>
255             /// Single revolution
256             /// </summary>
257             Sin,
258             /// <summary>
259             /// Sudden start, exceed end position and return to a gradual stop
260             /// </summary>
261             EaseOutBack,
262             Count
263         }
264
265         /// <summary>
266         /// This specifies which mode is set for AlphaFuction
267         /// </summary>
268         public enum Modes
269         {
270             /// <summary>
271             /// The user has used a built-in function.
272             /// </summary>
273             BuiltinFunction,
274
275             /// <summary>
276             /// The user has provided a custom function
277             /// </summary>
278             CustomFunction,
279             /// <summary>
280             /// The user has provided the control points of a bezier curve
281             /// </summary>
282             Bezier
283         }
284
285         internal static string BuiltinToPropertyKey(BuiltinFunctions? alphaFunction)
286         {
287             string propertyKey = null;
288             if (alphaFunction != null)
289             {
290                 switch (alphaFunction)
291                 {
292                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.Linear:
293                     {
294                         propertyKey = "LINEAR";
295                         break;
296                     }
297                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.Reverse:
298                     {
299                         propertyKey = "REVERSE";
300                         break;
301                     }
302                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseInSquare:
303                     {
304                         propertyKey = "EASE_IN_SQUARE";
305                         break;
306                     }
307                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseOutSquare:
308                     {
309                         propertyKey = "EASE_OUT_SQUARE";
310                         break;
311                     }
312                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseIn:
313                     {
314                         propertyKey = "EASE_IN";
315                         break;
316                     }
317                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseOut:
318                     {
319                         propertyKey = "EASE_OUT";
320                         break;
321                     }
322                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseInOut:
323                     {
324                         propertyKey = "EASE_IN_OUT";
325                         break;
326                     }
327                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseInSine:
328                     {
329                         propertyKey = "EASE_IN_SINE";
330                         break;
331                     }
332                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseOutSine:
333                     {
334                         propertyKey = "EASE_OUT_SINE";
335                         break;
336                     }
337                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseInOutSine:
338                     {
339                         propertyKey = "EASE_IN_OUT_SINE";
340                         break;
341                     }
342                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.Bounce:
343                     {
344                         propertyKey = "BOUNCE";
345                         break;
346                     }
347                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.Sin:
348                     {
349                         propertyKey = "SIN";
350                         break;
351                     }
352                     case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseOutBack:
353                     {
354                         propertyKey = "EASE_OUT_BACK";
355                         break;
356                     }
357                     default:
358                     {
359                         propertyKey = "DEFAULT";
360                         break;
361                     }
362                 }
363             }
364             return propertyKey;
365         }
366     }
367 }