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>
NUISamples/NUISamples/NUISamples.TizenTV/examples/visuals-using-custom-view/ContactData.cs
NUISamples/NUISamples/NUISamples.TizenTV/examples/visuals-using-custom-view/ContactView.cs
NUISamples/NUISamples/NUISamples.TizenTV/examples/visuals-using-custom-view/visuals-using-custom-view.cs
NUISamples/NUISamples/NUISamples.TizenTV/res/images/mask.png [new file with mode: 0644]
src/Tizen.NUI/src/internal/ManualPINVOKE.cs
src/Tizen.NUI/src/public/AlphaFunction.cs
src/Tizen.NUI/src/public/BaseComponents/View.cs

index 20b535b..9a3b9a8 100644 (file)
@@ -24,23 +24,28 @@ namespace VisualsUsingCustomView
     // The collection of contacts
     static class ContactsList
     {
-        private const string resources = "/home/owner/apps_rw/NUISamples.TizenTV/res";
+        private const string resources = "/home/SERILOCAL/david.steele/Git/Tizen/nui/NUISamples/NUISamples/NUISamples.TizenTV/res";
 
         public static readonly ContactItem[] s_contactData = new ContactItem[]
         {
             new ContactItem ("Emmett Yates", resources + "/images/gallery-small-43.jpg",
+                             resources + "/images/mask.png",
                              new Color((73.0f/255.0f),(182.0f/255.0f), (245.0f/255.0f), 1.0f),
                              (int)PrimitiveVisualShapeType.Cone),
             new ContactItem ("Leslie Wong", resources+ "/images/gallery-2.jpg",
+                             resources + "/images/mask.png",
                              new Color((51.0f/255.0f), (51.0f/255.0f), (102.0f/255.0f), 1.0f),
                              (int)PrimitiveVisualShapeType.Sphere),
             new ContactItem ("Walter Jensen", resources+ "/images/gallery-0.jpg",
+                             resources + "/images/mask.png",
                              new Color((151.0f/255.0f), (214.0f/255.0f), (240.0f/255.0f), 1.0f),
                              (int)PrimitiveVisualShapeType.Cylinder),
             new ContactItem ("Dan Haynes", resources+"/images/gallery-1.jpg",
+                             resources + "/images/mask.png",
                              new Color((102.0f/255.0f), (251.0f/255.0f), (102.0f/255.0f), 1.0f),
                              (int)PrimitiveVisualShapeType.ConicalFrustrum),
             new ContactItem ("Mable Hodges", resources+"/images/gallery-3.jpg",
+                             resources + "/images/mask.png",
                              new Color((255.0f/255.0f), (102.0f/255.0f), (102.0f/255.0f), 1.0f),
                              (int)PrimitiveVisualShapeType.Cube)
         };
@@ -53,11 +58,13 @@ namespace VisualsUsingCustomView
         private string _imageURL;
         private Color _color;
         private int _shape;
+        private string _maskURL;
 
-        public ContactItem(string name, string imageURL, Color color, int shape)
+        public ContactItem(string name, string imageURL, string maskURL, Color color, int shape)
         {
             _name = name;
             _imageURL = imageURL;
+            _maskURL = maskURL;
             _color = color;
             _shape = shape;
         }
@@ -73,6 +80,17 @@ namespace VisualsUsingCustomView
                 _imageURL = value;
             }
         }
+        public string MaskURL
+        {
+            get
+            {
+                return _maskURL;
+            }
+            set
+            {
+                _maskURL = value;
+            }
+        }
 
         public string Name
         {
@@ -110,4 +128,4 @@ namespace VisualsUsingCustomView
             }
         }
     }
-}
\ No newline at end of file
+}
index 6711b2a..d33faae 100644 (file)
@@ -28,23 +28,42 @@ namespace VisualsUsingCustomView
 {
     public class ContactView : CustomView
     {
-        private const int ColorVisualPropertyIndex = 0;
-        private const int PrimitiveVisualPropertyIndex = 1;
-        private const int ImageVisualPropertyIndex = 2;
-        private const int TextVisualPropertyIndex = 3;
+        private const int PROPERTY_REGISTRATION_START_INDEX = 10001000;
+        private const int ColorVisualPropertyIndex = PROPERTY_REGISTRATION_START_INDEX+1 ;
+        private const int PrimitiveVisualPropertyIndex = PROPERTY_REGISTRATION_START_INDEX+2;
+        private const int ImageVisualPropertyIndex = PROPERTY_REGISTRATION_START_INDEX+3;
+        private const int TextVisualPropertyIndex = PROPERTY_REGISTRATION_START_INDEX+4;
         private VisualBase _imageVisual;
         private VisualBase _colorVisual;
         private VisualBase _primitiveVisual;
         private VisualBase _textVisual;
         private int _shape;
         private string _imageURL;
+        private string _maskURL;
         private string _name;
         private Color _color;
 
+        static CustomView CreateInstance()
+        {
+            return new ContactView();
+        }
+
+        static ContactView()
+        {
+            ViewRegistry.Instance.Register( CreateInstance, typeof(ContactView));
+        }
+
         public ContactView() : base(typeof(ContactView).Name, CustomViewBehaviour.RequiresKeyboardNavigationSupport)
         {
         }
 
+        public string MaskURL
+        {
+            get { return _maskURL; }
+            set { _maskURL=value; }
+        }
+
+        [ScriptableProperty()]
         public string ImageURL
         {
             get
@@ -58,15 +77,18 @@ namespace VisualsUsingCustomView
                 // Create and Register Image Visual
                 PropertyMap imageVisual = new PropertyMap();
                 imageVisual.Add( Visual.Property.Type, new PropertyValue( (int)Visual.Type.Image ))
-                    .Add( ImageVisualProperty.URL, new PropertyValue( _imageURL ));
+                    .Add( ImageVisualProperty.URL, new PropertyValue( _imageURL ) )
+                    .Add( ImageVisualProperty.AlphaMaskURL, new PropertyValue( _maskURL ));
                 _imageVisual =  VisualFactory.Get().CreateVisual( imageVisual );
-                RegisterVisual( ImageVisualPropertyIndex, _imageVisual );
+
+                RegisterVisual( GetPropertyIndex("ImageURL"), _imageVisual );
 
                 // Set the depth index for Image visual
                 _imageVisual.DepthIndex = ImageVisualPropertyIndex;
             }
         }
 
+        [ScriptableProperty()]
         public string Name
         {
             get
@@ -86,13 +108,15 @@ namespace VisualsUsingCustomView
                     .Add( TextVisualProperty.HorizontalAlignment, new PropertyValue("CENTER"))
                     .Add( TextVisualProperty.VerticalAlignment, new PropertyValue("CENTER"));
                 _textVisual =  VisualFactory.Get().CreateVisual( textVisual );
-                RegisterVisual( TextVisualPropertyIndex, _textVisual );
+
+                RegisterVisual( GetPropertyIndex("Name"), _textVisual );
 
                 // Set the depth index for Text visual
                 _textVisual.DepthIndex = TextVisualPropertyIndex;
             }
         }
 
+        [ScriptableProperty()]
         public Color Color
         {
             get
@@ -102,19 +126,11 @@ namespace VisualsUsingCustomView
             set
             {
                 _color = value;
-
-                // Create and Register Color Visual
-                PropertyMap colorVisual = new PropertyMap();
-                colorVisual.Add( Visual.Property.Type, new PropertyValue( (int)Visual.Type.Color ))
-                    .Add( ColorVisualProperty.MixColor, new PropertyValue( _color ));
-                _colorVisual =  VisualFactory.Get().CreateVisual( colorVisual );
-                RegisterVisual( ColorVisualPropertyIndex, _colorVisual );
-
-                // Set the depth index for Color visual
-                _colorVisual.DepthIndex = ColorVisualPropertyIndex;
+                BackgroundColor = value;
             }
         }
 
+        [ScriptableProperty()]
         public int Shape
         {
             get
@@ -134,7 +150,7 @@ namespace VisualsUsingCustomView
                     .Add( PrimitiveVisualProperty.ScaleDimensions, new PropertyValue(new Vector3(1.0f,1.0f,0.3f)))
                     .Add( PrimitiveVisualProperty.MixColor, new PropertyValue(new Vector4((245.0f/255.0f), (188.0f/255.0f), (73.0f/255.0f), 1.0f)));
                 _primitiveVisual =  VisualFactory.Get().CreateVisual( primitiveVisual );
-                RegisterVisual( PrimitiveVisualPropertyIndex, _primitiveVisual );
+                RegisterVisual( GetPropertyIndex("Shape"), _primitiveVisual );
 
                 // Set the depth index for Primitive visual
                 _primitiveVisual.DepthIndex = PrimitiveVisualPropertyIndex;
@@ -151,7 +167,11 @@ namespace VisualsUsingCustomView
         {
             // Change the Color visual of ContactView with some random color
             Random random = new Random();
-            Color = new Color((random.Next(0, 256) / 255.0f), (random.Next(0, 256) / 255.0f), (random.Next(0, 256) / 255.0f), 1.0f);
+            float nextRed   = (random.Next(0, 256) / 255.0f);
+            float nextGreen = (random.Next(0, 256) / 255.0f);
+            float nextBlue  = (random.Next(0, 256) / 255.0f);
+            Animation anim = AnimateBackgroundColor( new Color( nextRed, nextGreen, nextBlue, 1.0f), 0, 2000 );
+            anim.Play();
         }
 
         public override void OnRelayout(Vector2 size, RelayoutContainer container)
@@ -185,16 +205,6 @@ namespace VisualsUsingCustomView
                 .Add((int)VisualTransformPropertyType.Origin, new PropertyValue((int)Visual.AlignType.CenterBegin))
                 .Add((int)VisualTransformPropertyType.AnchorPoint, new PropertyValue((int)Visual.AlignType.CenterBegin));
             _primitiveVisual.SetTransformAndSize(primitiveVisualTransform, size);
-
-            // Configure the transform and size of Color visual. This is also the default value.
-            PropertyMap colorVisualTransform = new PropertyMap();
-            colorVisualTransform.Add( (int)VisualTransformPropertyType.Offset, new PropertyValue(new Vector2(0.0f,0.0f)))
-                .Add((int)VisualTransformPropertyType.OffsetPolicy, new PropertyValue(new Vector2((int)VisualTransformPolicyType.Relative, (int)VisualTransformPolicyType.Relative)))
-                .Add((int)VisualTransformPropertyType.SizePolicy, new PropertyValue(new Vector2((int)VisualTransformPolicyType.Relative, (int)VisualTransformPolicyType.Relative)))
-                .Add( (int)VisualTransformPropertyType.Size, new PropertyValue(new Vector2(1.0f, 1.0f)) )
-                .Add( (int)VisualTransformPropertyType.Origin, new PropertyValue((int)Visual.AlignType.TopBegin) )
-                .Add( (int)VisualTransformPropertyType.AnchorPoint, new PropertyValue((int)Visual.AlignType.TopBegin) );
-            _colorVisual.SetTransformAndSize(colorVisualTransform, size);
         }
     }
-}
\ No newline at end of file
+}
index 8998e58..2143e5c 100644 (file)
@@ -52,9 +52,9 @@ namespace VisualsUsingCustomView
             contentLayout.Name = "ContentLayout";
             //contentLayout.WidthResizePolicy = ResizePolicyType.FillToParent;
             //contentLayout.HeightResizePolicy = ResizePolicyType.FillToParent;
-            contentLayout.PivotPoint = PivotPoint.Center;
-            contentLayout.ParentOrigin = ParentOrigin.Center;
-            contentLayout.Size = new Vector3(window.Size.Width, window.Size.Height, 0.0f);
+            contentLayout.PivotPoint = PivotPoint.TopLeft;
+            contentLayout.ParentOrigin = ParentOrigin.TopLeft;
+            contentLayout.Size2D = new Vector2(window.Size.Width, window.Size.Height);
             contentLayout.SetCellPadding(new Size2D(5, 5));
             contentLayout.BackgroundColor = new Color(0.949f, 0.949f, 0.949f, 1.0f);
 
@@ -79,6 +79,7 @@ namespace VisualsUsingCustomView
 
                 // Configure visuals of ContactView via properties
                 contactView.Name = contact.Name;
+                contactView.MaskURL = contact.MaskURL;
                 contactView.ImageURL = contact.ImageURL;
                 contactView.Color = contact.Color;
                 contactView.Shape = contact.Shape;
@@ -90,7 +91,7 @@ namespace VisualsUsingCustomView
         /// The main entry point for the application.
         /// </summary>
         [STAThread]
-        static void _Main(string[] args)
+        static void Main(string[] args)
         {
             VisualsExample visualsExample = new VisualsExample();
             visualsExample.Run(args);
diff --git a/NUISamples/NUISamples/NUISamples.TizenTV/res/images/mask.png b/NUISamples/NUISamples/NUISamples.TizenTV/res/images/mask.png
new file mode 100644 (file)
index 0000000..b3e423c
Binary files /dev/null and b/NUISamples/NUISamples/NUISamples.TizenTV/res/images/mask.png differ
index 5669090..fe3c65c 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 dde903e..834d163 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 3e85455..35e4a64 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>
@@ -1004,6 +1003,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>
         public string BackgroundImage
@@ -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>