Added support for animating the background color of a view.
authorDavid Steele <david.steele@samsung.com>
Thu, 15 Jun 2017 17:48:04 +0000 (18:48 +0100)
committerDavid Steele <david.steele@samsung.com>
Mon, 19 Jun 2017 11:19:07 +0000 (12:19 +0100)
The View background is animated using a new API AnimateBackgroundColor
via the CreateTransition method, which has been left protected for the moment
(It's only supposed to be used by custom view implementations).

Change-Id: I5853a9fecbac06f2aff3846f27769f944c7a9d77
Signed-off-by: David Steele <david.steele@samsung.com>
src/Tizen.NUI/src/internal/ManualPINVOKE.cs
src/Tizen.NUI/src/public/AlphaFunction.cs
src/Tizen.NUI/src/public/BaseComponents/View.cs

index 5669090c3ab199604c45d9e7f5cbc0c16c7cc067..fe3c65ca61a571707060b44d7aa344445da739e6 100755 (executable)
@@ -178,6 +178,9 @@ namespace Tizen.NUI
         [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_ViewWrapperImpl_CreateTransition")]
         public static extern global::System.IntPtr ViewWrapperImpl_CreateTransition(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
 
+        [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_View_CreateTransition")]
+        public static extern global::System.IntPtr View_CreateTransition(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
         [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_ViewWrapperImpl_EmitKeyInputFocusSignal")]
         public static extern void ViewWrapperImpl_EmitKeyInputFocusSignal(global::System.Runtime.InteropServices.HandleRef jarg1, bool jarg2);
 
index dde903e22e2cfdceee9e91c6b48531b54ef8b53d..834d163f889a94e0d8a13672e9037a7c48f5f1fe 100755 (executable)
@@ -282,6 +282,86 @@ namespace Tizen.NUI
             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;
+        }
     }
-
 }
index 3e85455d14903486d86771a45f45d11a196a9a6c..35e4a64222dadb0a995e55a39e832c9774aaa976 100755 (executable)
@@ -40,7 +40,7 @@ namespace Tizen.NUI.BaseComponents
             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
         }
 
-        //you can override it to clean-up your own resources.
+        // you can override it to clean-up your own resources.
         protected override void Dispose(DisposeTypes type)
         {
             if(disposed)
@@ -753,7 +753,6 @@ namespace Tizen.NUI.BaseComponents
             internal static readonly int CLIPPING_MODE = NDalicPINVOKE.Actor_Property_CLIPPING_MODE_get();
         }
 
-
         /// <summary>
         /// Describes the direction to move the focus towards.
         /// </summary>
@@ -1003,6 +1002,68 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        /// <summary>
+        /// Create an Animation to animate the background color visual. If there is no
+        /// background visual, creates one with transparent black as it's mixColor.
+        /// </summary>
+        public Animation AnimateBackgroundColor( object destinationValue,
+                                                 int startTime,
+                                                 int endTime,
+                                                 AlphaFunction.BuiltinFunctions? alphaFunction = null,
+                                                 object initialValue = null)
+        {
+            Tizen.NUI.PropertyMap background = Background;
+
+            if( background.Empty() )
+            {
+                // If there is no background yet, ensure there is a transparent
+                // color visual
+                BackgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.0f);
+                background = Background;
+            }
+            return AnimateColor( "background", destinationValue, startTime, endTime, alphaFunction, initialValue );
+        }
+
+        /// <summary>
+        /// Create an Animation to animate the mixColor of the named visual.
+        /// </summary>
+        public Animation AnimateColor( string targetVisual, object destinationColor, int startTime, int endTime, AlphaFunction.BuiltinFunctions? alphaFunction = null, object initialColor = null )
+        {
+            Animation animation = null;
+            {
+                PropertyMap _animator = new PropertyMap();
+                if( alphaFunction != null )
+                {
+                    _animator.Add("alphaFunction", new PropertyValue( AlphaFunction.BuiltinToPropertyKey(alphaFunction) ) );
+                }
+
+                PropertyMap _timePeriod = new PropertyMap();
+                _timePeriod.Add( "duration", new PropertyValue((endTime-startTime)/1000.0f) );
+                _timePeriod.Add( "delay", new PropertyValue( startTime/1000.0f ) );
+                _animator.Add( "timePeriod", new PropertyValue( _timePeriod ) );
+
+                PropertyMap _transition = new PropertyMap();
+                _transition.Add( "animator", new PropertyValue( _animator ) );
+                _transition.Add( "target", new PropertyValue( targetVisual ) );
+                _transition.Add( "property", new PropertyValue( "mixColor" ) );
+
+                if( initialColor != null )
+                {
+                    PropertyValue initValue = PropertyValue.CreateFromObject( initialColor );
+                    _transition.Add( "initialValue", initValue );
+                }
+
+                PropertyValue destValue = PropertyValue.CreateFromObject( destinationColor );
+                _transition.Add( "targetValue", destValue );
+                TransitionData _transitionData = new TransitionData( _transition );
+
+                animation = new Animation( NDalicManualPINVOKE.View_CreateTransition(swigCPtr, TransitionData.getCPtr(_transitionData)), true );
+                if (NDalicPINVOKE.SWIGPendingException.Pending)
+                    throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            }
+            return animation;
+        }
+
         /// <summary>
         /// mutually exclusive with BACKGROUND_COLOR & BACKGROUND,  type Map.
         /// </summary>
@@ -1028,15 +1089,12 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
-        /// <summary>
-        /// mutually exclusive with BACKGROUND_COLOR & BACKGROUND_IMAGE, type Map or string for URL.
-        /// </summary>
         public Tizen.NUI.PropertyMap Background
         {
             get
             {
                 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
-                GetProperty(View.Property.BACKGROUND).Get(temp);
+                GetProperty( View.Property.BACKGROUND ).Get(temp);
                 return temp;
             }
             set
@@ -1045,6 +1103,7 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+
         /// <summary>
         /// The current state of the view.
         /// </summary>