/* * Copyright(c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ namespace Tizen.NUI { /// /// Alpha functions are used in animations to specify the rate of change of the animation parameter over time.
/// Understanding an animation as a parametric function over time, the alpha function is applied to the parameter of /// the animation before computing the final animation value. ///
public class AlphaFunction : global::System.IDisposable { private global::System.Runtime.InteropServices.HandleRef swigCPtr; /// swigCMemOwn. /// 3 protected bool swigCMemOwn; internal AlphaFunction(global::System.IntPtr cPtr, bool cMemoryOwn) { swigCMemOwn = cMemoryOwn; swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); } internal static global::System.Runtime.InteropServices.HandleRef getCPtr(AlphaFunction obj) { return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; } //A Flag to check who called Dispose(). (By User or DisposeQueue) private bool isDisposeQueued = false; /// /// A Flat to check if it is already disposed. /// /// 3 protected bool disposed = false; /// /// Dispose. /// /// 3 ~AlphaFunction() { if(!isDisposeQueued) { isDisposeQueued = true; DisposeQueue.Instance.Add(this); } } /// /// To make the AlphaFunction instance be disposed. /// /// 3 public void Dispose() { //Throw excpetion if Dispose() is called in separate thread. if (!Window.IsInstalled()) { throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread."); } if (isDisposeQueued) { Dispose(DisposeTypes.Implicit); } else { Dispose(DisposeTypes.Explicit); System.GC.SuppressFinalize(this); } } /// /// To make the AlphaFunction instance be disposed. /// /// 3 protected virtual void Dispose(DisposeTypes type) { if (disposed) { return; } if(type == DisposeTypes.Explicit) { //Called by User //Release your own managed resources here. //You should release all of your own disposable objects here. } //Release your own unmanaged resources here. //You should not access any managed member here except static instance. //because the execution order of Finalizes is non-deterministic. if (swigCPtr.Handle != global::System.IntPtr.Zero) { if (swigCMemOwn) { swigCMemOwn = false; NDalicPINVOKE.delete_AlphaFunction(swigCPtr); } swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); } disposed = true; } /// /// The constructor.
/// Creates an alpha function object with the user-defined alpha function.
///
/// User defined fuction. It must be a method formatted as float alphafunction(float progress) /// 3 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) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// The default constructor.
/// Creates an alpha function object with the default built-in alpha function.
///
/// 3 public AlphaFunction() : this(NDalicPINVOKE.new_AlphaFunction__SWIG_0(), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// The constructor.
/// Creates an alpha function object with the built-in alpha function passed as a parameter to the constructor.
///
/// One of the built-in alpha functions. /// 3 public AlphaFunction(AlphaFunction.BuiltinFunctions function) : this(NDalicPINVOKE.new_AlphaFunction__SWIG_1((int)function), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } internal AlphaFunction(SWIGTYPE_p_f_float__float function) : this(NDalicPINVOKE.new_AlphaFunction__SWIG_2(SWIGTYPE_p_f_float__float.getCPtr(function)), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// The constructor.
/// Creates a bezier alpha function. The bezier will have the first point at (0,0) and the end point at (1,1).
///
/// The x components of the control points will be clamped to the range [0, 1] to prevent non-monotonic curves. /// A Vector2 which will be used as the first control point of the curve. /// A Vector2 which will be used as the second control point of the curve. /// 3 public AlphaFunction(Vector2 controlPoint0, Vector2 controlPoint1) : this(NDalicPINVOKE.new_AlphaFunction__SWIG_3(Vector2.getCPtr(controlPoint0), Vector2.getCPtr(controlPoint1)), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// Retrives the control points of the alpha function.
///
/// A Vector2 which will be used as the first control point of the curve. /// A Vector2 which will be used as the second control point of the curve. /// 3 public void GetBezierControlPoints(out Vector2 controlPoint0, out Vector2 controlPoint1) { Vector4 ret = new Vector4(NDalicPINVOKE.AlphaFunction_GetBezierControlPoints(swigCPtr), true); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); controlPoint0 = new Vector2(ret.X, ret.Y); controlPoint1 = new Vector2(ret.Z, ret.W); } internal SWIGTYPE_p_f_float__float GetCustomFunction() { global::System.IntPtr cPtr = NDalicPINVOKE.AlphaFunction_GetCustomFunction(swigCPtr); SWIGTYPE_p_f_float__float ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_f_float__float(cPtr, false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Returns the built-in function used by the alpha function.
/// In case no built-in function has been specified, it will return AlphaFunction::DEFAULT.
///
/// One of the built-in alpha functions. /// 3 public AlphaFunction.BuiltinFunctions GetBuiltinFunction() { AlphaFunction.BuiltinFunctions ret = (AlphaFunction.BuiltinFunctions)NDalicPINVOKE.AlphaFunction_GetBuiltinFunction(swigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Returns the functioning mode of the alpha function. /// /// The functioning mode of the alpha function. /// 3 public AlphaFunction.Modes GetMode() { AlphaFunction.Modes ret = (AlphaFunction.Modes)NDalicPINVOKE.AlphaFunction_GetMode(swigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// This specifies the various types of BuiltinFunctions. /// /// 3 public enum BuiltinFunctions { /// /// Linear. /// Default, /// /// No transformation. /// Linear, /// /// Reverse linear. /// Reverse, /// /// Speeds up and comes to a sudden stop (square). /// EaseInSquare, /// /// Sudden start and slows to a gradual stop (square). /// EaseOutSquare, /// /// Speeds up and comes to a sudden stop (cubic). /// EaseIn, /// /// Sudden start and slows to a gradual stop (cubic). /// EaseOut, /// /// Speeds up and slows to a gradual stop (cubic). /// EaseInOut, /// /// Speeds up and comes to a sudden stop (sinusoidal). /// EaseInSine, /// /// Sudden start and slows to a gradual stop (sinusoidal). /// EaseOutSine, /// /// Speeds up and slows to a gradual stop (sinusoidal). /// EaseInOutSine, /// /// Sudden start, loses momentum and returns to start position. /// Bounce, /// /// Single revolution. /// Sin, /// /// Sudden start, exceed end position and return to a gradual stop. /// EaseOutBack, /// /// The count of the BuiltinFunctions enum. /// Count } /// /// This specifies which mode is set for AlphaFunction. /// /// 3 public enum Modes { /// /// The user has used a built-in function. /// BuiltinFunction, /// /// The user has provided a custom function. /// CustomFunction, /// /// The user has provided the control points of a bezier curve. /// Bezier } internal static string BuiltinToPropertyKey(BuiltinFunctions? alphaFunction) { string propertyKey = null; if (alphaFunction != null) { switch (alphaFunction) { case Tizen.NUI.AlphaFunction.BuiltinFunctions.Linear: { propertyKey = "LINEAR"; break; } case Tizen.NUI.AlphaFunction.BuiltinFunctions.Reverse: { propertyKey = "REVERSE"; break; } case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseInSquare: { propertyKey = "EASE_IN_SQUARE"; break; } case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseOutSquare: { propertyKey = "EASE_OUT_SQUARE"; break; } case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseIn: { propertyKey = "EASE_IN"; break; } case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseOut: { propertyKey = "EASE_OUT"; break; } case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseInOut: { propertyKey = "EASE_IN_OUT"; break; } case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseInSine: { propertyKey = "EASE_IN_SINE"; break; } case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseOutSine: { propertyKey = "EASE_OUT_SINE"; break; } case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseInOutSine: { propertyKey = "EASE_IN_OUT_SINE"; break; } case Tizen.NUI.AlphaFunction.BuiltinFunctions.Bounce: { propertyKey = "BOUNCE"; break; } case Tizen.NUI.AlphaFunction.BuiltinFunctions.Sin: { propertyKey = "SIN"; break; } case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseOutBack: { propertyKey = "EASE_OUT_BACK"; break; } default: { propertyKey = "DEFAULT"; break; } } } return propertyKey; } } }