Convert AlphaFunction from string type to enum and AnimatorVisual to VisualAnimator
authorxb.teng <xb.teng@samsung.com>
Wed, 26 Apr 2017 20:14:48 +0000 (04:14 +0800)
committerxb.teng <xb.teng@samsung.com>
Wed, 26 Apr 2017 21:41:08 +0000 (05:41 +0800)
Change-Id: I46003dc0df432c61375d296760c55d06bbc4e8c2
Signed-off-by: xb.teng <xb.teng@samsung.com>
NUISamples/NUISamples/NUISamples.TizenTV/NUISamples.TizenTV.csproj
NUISamples/NUISamples/NUISamples.TizenTV/examples/Main.cs
NUISamples/NUISamples/NUISamples.TizenTV/examples/visual-animation-test.cs
NUISamples/NUISamples/NUISamples.TizenTV/examples/visual-animation-test2.cs [new file with mode: 0755]
NUISamples/NUISamples/NUISamples.TizenTV/examples/visuals-using-custom-view/visuals-using-custom-view.cs
src/Tizen.NUI/src/public/BaseComponents/VisualView.cs
src/Tizen.NUI/src/public/NUIConstants.cs
src/Tizen.NUI/src/public/VisualMaps.cs

index 9cc619f..7526a1e 100755 (executable)
@@ -73,6 +73,7 @@
     <Compile Include="examples\user-alphafunction.cs" />\r
     <Compile Include="examples\view-navi-property.cs" />\r
     <Compile Include="examples\visual-animation-test.cs" />\r
+    <Compile Include="examples\visual-animation-test2.cs" />\r
     <Compile Include="examples\visual-view-test2.cs" />\r
     <Compile Include="examples\visual-view-test.cs" />\r
     <Compile Include="examples\visual-view-test3.cs" />\r
index 53c4891..a1f8a6f 100755 (executable)
@@ -29,9 +29,10 @@ namespace NUISamples.TizenTV.examples
             //new DaliTest.Example().Run(args);                         //o
             //new RelativeVectorTest.Example().Run(args);
             //new VisaulAnimationExample.Example().Run(args);
+            new VisaulAnimationExample.Example2().Run(args);
             //new VisualViewTest.Example().Run(args);                   //o
             //new VisualViewTest2.VisualSample().Run(args);
-            new VisualViewTest3.Example().Run(args);                   //o
+            //new VisualViewTest3.Example().Run(args);                   //o
             //new VisualsUsingCustomView.VisualsExample().Run(args);    //o
             //new FirstScreen.FirstScreenApp().Run(args);               //o
             //new PositionUsesAnchorPointTest.Example().Run(args);
index 1c937e2..448ea75 100755 (executable)
@@ -143,7 +143,6 @@ namespace VisaulAnimationExample
             npatch1.Opacity = 0.5f;
             _contentView.AddVisual("npatchImageVisual1", npatch1);
 
-
             //////////////////////////////////////////////////////////////////////
             // make SVG visual test
             VisualView VisualView1 = new VisualView();
@@ -223,8 +222,6 @@ namespace VisaulAnimationExample
                 return true;
             };
             contentLayout.AddChild(gifButton, new TableView.CellPosition(2, 1));
-
-
         }
 
         private void StartTransition(bool activate)
@@ -237,25 +234,25 @@ namespace VisaulAnimationExample
 
             if (activate)
             {
-                AnimatorVisual grow = new AnimatorVisual();
-                grow.AlphaFunction = "LINEAR";
+                VisualAnimator grow = new VisualAnimator();
+                grow.AlphaFunction = AlphaFunction.BuiltinFunctions.Linear;
                 grow.StartTime = 0;
                 grow.EndTime = 1000;
                 grow.Target = "icon_visual1";
                 grow.PropertyIndex = "Size";
                 grow.DestinationValue = new Size2D(200, 200);
-                _animation = _contentView.AnimateVisual(grow);
+                _animation = _contentView.VisualAnimate(grow);
             }
             else
             {
-                AnimatorVisual shrink = new AnimatorVisual();
-                shrink.AlphaFunction = "LINEAR";
+                VisualAnimator shrink = new VisualAnimator();
+                shrink.AlphaFunction = AlphaFunction.BuiltinFunctions.Linear;
                 shrink.StartTime = 0;
                 shrink.EndTime = 1000;
                 shrink.Target = "icon_visual1";
                 shrink.PropertyIndex = "Size";
                 shrink.DestinationValue = new Size2D(50, 50);
-                _animation = _contentView.AnimateVisual(shrink);
+                _animation = _contentView.VisualAnimate(shrink);
             }
 
             if (_animation)
diff --git a/NUISamples/NUISamples/NUISamples.TizenTV/examples/visual-animation-test2.cs b/NUISamples/NUISamples/NUISamples.TizenTV/examples/visual-animation-test2.cs
new file mode 100755 (executable)
index 0000000..e3eaf44
--- /dev/null
@@ -0,0 +1,292 @@
+/*
+ * 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.
+ *
+ */
+
+using System;
+using System.Runtime.InteropServices;
+using Tizen.NUI;
+using Tizen.NUI.UIComponents;
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Constants;
+
+namespace VisaulAnimationExample
+{
+    class Example2 : NUIApplication
+    {
+        private VisualView _contentView1;
+        private VisualView _contentView2;
+        private VisualView _contentView3;
+        private TextLabel _title;
+        private PushButton _shadowButton1;
+        private PushButton _shadowButton2;
+        private PushButton _shadowButton3;
+        private bool _active1 = false;
+        private bool _active2 = false;
+        private bool _active3 = false;
+        private const string _resPath = "/home/owner/apps_rw/NUISamples.TizenTV/res";
+
+        private Animation _animation;
+        private bool _transitionInProgress = false;
+
+        public Example2() : base()
+        {
+        }
+
+        public Example2(string stylesheet) : base(stylesheet)
+        {
+        }
+
+        public Example2(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
+        {
+        }
+
+        protected override void OnCreate()
+        {
+            base.OnCreate();
+            Initialize();
+        }
+
+        public void Initialize()
+        {
+            Stage stage = Stage.Instance;
+            stage.BackgroundColor = Color.White;
+
+            TableView titleLayout = new TableView(2, 1);
+            titleLayout.Name = ("TitleLayout");
+            titleLayout.AnchorPoint = AnchorPoint.TopLeft;
+            titleLayout.Position2D = new Position2D(10, 10);
+            titleLayout.Size2D = new Size2D((int)(stage.Size.Width * 0.9f), (int)(stage.Size.Height * 0.9f));
+            titleLayout.SetCellPadding(new Size2D(10, 10));
+            titleLayout.BackgroundColor = Color.Cyan;
+            stage.GetDefaultLayer().Add(titleLayout);
+
+            _title = new TextLabel("Visual Transition Example");
+            _title.Name = ("Title");
+            _title.SetStyleName("Title");
+            _title.WidthResizePolicy = ResizePolicyType.FillToParent;
+            _title.HeightResizePolicy = ResizePolicyType.UseNaturalSize;
+            _title.HorizontalAlignment = HorizontalAlignment.Center;
+            titleLayout.AddChild(_title, new TableView.CellPosition(0, 0));
+            titleLayout.SetFitHeight(0);
+
+            TableView contentLayout = new TableView(3, 2);
+            contentLayout.Name = ("ContentLayout");
+            contentLayout.WidthResizePolicy = ResizePolicyType.FillToParent;
+            contentLayout.HeightResizePolicy = ResizePolicyType.FillToParent;
+            contentLayout.AnchorPoint = AnchorPoint.TopLeft;
+            contentLayout.SetCellPadding(new Size2D(10, 10));
+            contentLayout.BackgroundColor = Color.Magenta;
+            titleLayout.AddChild(contentLayout, new TableView.CellPosition(1, 0));
+
+            //////////////////////////////////////////////////////////////////////
+            // make visual position animation
+            _contentView1 = new VisualView();
+            _contentView1.WidthResizePolicy = ResizePolicyType.SizeRelativeToParent;
+            _contentView1.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
+            //_contentView.Size2D = new Size2D(250, 250);
+            _contentView1.BackgroundImage = _resPath + "/images/background-blocks.jpg";
+
+            ImageVisual _icon = new ImageVisual();
+            _icon.URL = _resPath + "/images/application-icon-0.png";
+            _icon.DepthIndex = 1;
+            _icon.Size = new Size2D(50, 50);
+            _icon.SizePolicy = VisualTransformPolicyType.Absolute;
+            _icon.Position = new Position2D(5, 5);
+            _icon.PositionPolicy = VisualTransformPolicyType.Absolute;
+            _icon.Origin = Visual.AlignType.TopBegin;
+            _icon.AnchorPoint = Visual.AlignType.TopBegin;
+            _icon.MixColor = new Color(0, 1, 0, 0.5f);
+            _icon.Opacity = 0.5f;
+            _contentView1.AddVisual("icon_visual1", _icon);
+
+            contentLayout.AddChild(_contentView1, new TableView.CellPosition(0, 0));
+
+            _shadowButton1 = new PushButton();
+            _shadowButton1.LabelText = "Toggle Transition Position";
+            _shadowButton1.Name = ("ToggleTransition");
+            _shadowButton1.ParentOrigin = ParentOrigin.Center;
+            _shadowButton1.AnchorPoint = AnchorPoint.Center;
+            _shadowButton1.Clicked += (obj, ev) =>
+            {
+                _active1 = !_active1;
+                StartTransition(_contentView1, "icon_visual1", "Offset", _active1);
+                return true;
+            };
+            _shadowButton1.WidthResizePolicy = ResizePolicyType.FillToParent;
+            _shadowButton1.HeightResizePolicy = ResizePolicyType.FillToParent;
+            contentLayout.AddChild(_shadowButton1, new TableView.CellPosition(0, 1));
+
+            //////////////////////////////////////////////////////////////////////
+            // make visual opacity animation
+            _contentView2 = new VisualView();
+            _contentView2.WidthResizePolicy = ResizePolicyType.SizeRelativeToParent;
+            _contentView2.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
+            //_contentView.Size2D = new Size2D(250, 250);
+            _contentView2.BackgroundImage = _resPath + "/images/background-blocks.jpg";
+
+            ImageVisual _icon2 = new ImageVisual();
+            _icon2.URL = _resPath + "/images/application-icon-0.png";
+            _icon2.DepthIndex = 1;
+            _icon2.Size = new Size2D(50, 50);
+            _icon2.SizePolicy = VisualTransformPolicyType.Absolute;
+            _icon2.Position = new Position2D(5, 5);
+            _icon2.PositionPolicy = VisualTransformPolicyType.Absolute;
+            _icon2.Origin = Visual.AlignType.TopBegin;
+            _icon2.AnchorPoint = Visual.AlignType.TopBegin;
+            _icon2.MixColor = new Color(0, 1, 0, 0.5f);
+            _icon2.Opacity = 0.5f;
+            _contentView2.AddVisual("icon_visual2", _icon2);
+
+            contentLayout.AddChild(_contentView2, new TableView.CellPosition(1, 0));
+
+            _shadowButton2 = new PushButton();
+            _shadowButton2.LabelText = "Toggle Transition Opacity";
+            _shadowButton2.Name = ("ToggleTransition");
+            _shadowButton2.ParentOrigin = ParentOrigin.Center;
+            _shadowButton2.AnchorPoint = AnchorPoint.Center;
+            _shadowButton2.Clicked += (obj, ev) =>
+            {
+                _active2 = !_active2;
+                StartTransition(_contentView2, "icon_visual2", "Opacity", _active2);
+                return true;
+            };
+            _shadowButton2.WidthResizePolicy = ResizePolicyType.FillToParent;
+            _shadowButton2.HeightResizePolicy = ResizePolicyType.FillToParent;
+            contentLayout.AddChild(_shadowButton2, new TableView.CellPosition(1, 1));
+
+            //////////////////////////////////////////////////////////////////////
+            // make AnimatedImage visual test
+            _contentView3 = new VisualView();
+            _contentView3.WidthResizePolicy = ResizePolicyType.SizeRelativeToParent;
+            _contentView3.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
+            //_contentView.Size2D = new Size2D(250, 250);
+            _contentView3.BackgroundImage = _resPath + "/images/background-blocks.jpg";
+
+            ImageVisual _icon3 = new ImageVisual();
+            _icon3.URL = _resPath + "/images/application-icon-0.png";
+            _icon3.DepthIndex = 1;
+            _icon3.Size = new Size2D(50, 50);
+            _icon3.SizePolicy = VisualTransformPolicyType.Absolute;
+            _icon3.Position = new Position2D(5, 5);
+            _icon3.PositionPolicy = VisualTransformPolicyType.Absolute;
+            _icon3.Origin = Visual.AlignType.TopBegin;
+            _icon3.AnchorPoint = Visual.AlignType.TopBegin;
+            _icon3.MixColor = new Color(0, 1, 0, 0.5f);
+            _icon3.Opacity = 0.5f;
+            _contentView3.AddVisual("icon_visual3", _icon3);
+
+            contentLayout.AddChild(_contentView3, new TableView.CellPosition(2, 0));
+
+            _shadowButton3 = new PushButton();
+            _shadowButton3.LabelText = "Toggle Transition MixColor";
+            _shadowButton3.Name = ("ToggleTransition");
+            _shadowButton3.ParentOrigin = ParentOrigin.Center;
+            _shadowButton3.AnchorPoint = AnchorPoint.Center;
+            _shadowButton3.Clicked += (obj, ev) =>
+            {
+                _active3 = !_active3;
+                StartTransition(_contentView3, "icon_visual3", "MixColor", _active3);
+                return true;
+            };
+            _shadowButton3.WidthResizePolicy = ResizePolicyType.FillToParent;
+            _shadowButton3.HeightResizePolicy = ResizePolicyType.FillToParent;
+            contentLayout.AddChild(_shadowButton3, new TableView.CellPosition(2, 1));
+        }
+
+        private void StartTransition(VisualView view, string target, string property, bool activate)
+        {
+            if (_animation)
+            {
+                _animation.Stop();
+                _animation.Finished += OnTransitionFinished;
+            }
+
+            if (activate)
+            {
+                VisualAnimator state1 = new VisualAnimator();
+                state1.AlphaFunction = AlphaFunction.BuiltinFunctions.Linear;
+                state1.StartTime = 0;
+                state1.EndTime = 1000;
+                state1.Target = target;
+                state1.PropertyIndex = property;
+                if (property == "Offset")
+                {
+                    state1.DestinationValue = new Position2D(20, 20);
+                }
+                else if (property == "Opacity")
+                {
+                    state1.DestinationValue = 0.0f;
+                }
+                else if (property == "MixColor")
+                {
+                    state1.DestinationValue = Color.Green;
+                }
+                _animation = view.VisualAnimate(state1);
+            }
+            else
+            {
+                VisualAnimator state2 = new VisualAnimator();
+                state2.AlphaFunction = AlphaFunction.BuiltinFunctions.Linear;
+                state2.StartTime = 0;
+                state2.EndTime = 1000;
+                state2.Target = target;
+                state2.PropertyIndex = property;
+                if (property == "Offset")
+                {
+                    state2.DestinationValue = new Position2D(5, 5);
+                }
+                else if (property == "Opacity")
+                {
+                    state2.DestinationValue = 1.0f;
+                }
+                else if (property == "MixColor")
+                {
+                    state2.DestinationValue = Color.Red;
+                }
+                _animation = view.VisualAnimate(state2);
+            }
+
+            if (_animation)
+            {
+                _animation.Finished += OnTransitionFinished;
+                _transitionInProgress = true;
+                _animation.Play();
+            }
+        }
+        private void OnTransitionFinished(object sender, EventArgs e)
+        {
+            _transitionInProgress = false;
+            if (_animation)
+            {
+                _animation.Finished += OnTransitionFinished;
+                _animation.Reset();
+            }
+        }
+
+
+        /// <summary>
+        /// The main entry point for the application.
+        /// </summary>
+        [STAThread]
+        static void _Main(string[] args)
+        {
+            Example example = new Example();
+            example.Run(args);
+        }
+
+
+    }
+}
index fa5dd0f..cb5cdbf 100755 (executable)
@@ -84,7 +84,7 @@ namespace VisualsUsingCustomView
                 contactView.Shape = contact.Shape;
                 contentLayout.Add(contactView);
             }
-            }
+        }
 
         /// <summary>
         /// The main entry point for the application.
@@ -92,9 +92,8 @@ namespace VisualsUsingCustomView
         [STAThread]
         static void _Main(string[] args)
         {
-            
             VisualsExample visualsExample = new VisualsExample();
             visualsExample.Run(args);
         }
     }
-}
\ No newline at end of file
+}
index faadd52..d816d7d 100755 (executable)
@@ -208,7 +208,7 @@ namespace Tizen.NUI.BaseComponents
         /// </summary>
         /// <param name="visualMap">property map to define visual animation</param>
         /// <returns>Animation instance</returns>
-        public Animation AnimateVisual(AnimatorVisual visualMap)
+        public Animation VisualAnimate(VisualAnimator visualMap)
         {
             foreach (var item in _visualDictionary.ToList())
             {
index 31c4ec3..f0b7ecb 100755 (executable)
@@ -205,7 +205,7 @@ namespace Tizen.NUI
         LastViewBehaviourFlag
     }
 
-        public enum DeviceClassType
+    public enum DeviceClassType
     {
         None,
         Seat,
index dcd2a06..959dd07 100755 (executable)
@@ -1981,9 +1981,9 @@ namespace Tizen.NUI
     /// <summary>
     /// A class encapsulating the property map of a visual transition(Animator).
     /// </summary>
-    public class AnimatorVisual : VisualMap
+    public class VisualAnimator : VisualMap
     {
-        public AnimatorVisual() : base()
+        public VisualAnimator() : base()
         {
         }
 
@@ -1994,15 +1994,117 @@ namespace Tizen.NUI
         private string _propertyIndex = null;
         private object _destinationValue = null;
 
-        public string AlphaFunction
+        public AlphaFunction.BuiltinFunctions AlphaFunction
         {
             get
             {
-                return _alphaFunction;
+                switch (_alphaFunction)
+                {
+                    case "LINEAR":
+                        return Tizen.NUI.AlphaFunction.BuiltinFunctions.Linear;
+                    case "REVERSE":
+                        return Tizen.NUI.AlphaFunction.BuiltinFunctions.Reverse;
+                    case "EASE_IN_SQUARE":
+                        return Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseInSquare;
+                    case "EASE_OUT_SQUARE":
+                        return Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseOutSquare;
+                    case "EASE_IN":
+                        return Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseIn;
+                    case "EASE_OUT":
+                        return Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseOut;
+                    case "EASE_IN_OUT":
+                        return Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseInOut;
+                    case "EASE_IN_SINE":
+                        return Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseInSine;
+                    case "EASE_OUT_SINE":
+                        return Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseOutSine;
+                    case "EASE_IN_OUT_SINE":
+                        return Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseInOutSine;
+                    case "BOUNCE":
+                        return Tizen.NUI.AlphaFunction.BuiltinFunctions.Bounce;
+                    case "SIN":
+                        return Tizen.NUI.AlphaFunction.BuiltinFunctions.Sin;
+                    case "EASE_OUT_BACK":
+                        return Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseOutBack;
+                    default:
+                        return Tizen.NUI.AlphaFunction.BuiltinFunctions.Default;
+                }
             }
             set
             {
-                _alphaFunction = value;
+                switch (value)
+                {
+                    case Tizen.NUI.AlphaFunction.BuiltinFunctions.Linear:
+                    {
+                        _alphaFunction = "LINEAR";
+                        break;
+                    }
+                    case Tizen.NUI.AlphaFunction.BuiltinFunctions.Reverse:
+                    {
+                        _alphaFunction = "REVERSE";
+                        break;
+                    }
+                    case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseInSquare:
+                    {
+                        _alphaFunction = "EASE_IN_SQUARE";
+                        break;
+                    }
+                    case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseOutSquare:
+                    {
+                        _alphaFunction = "EASE_OUT_SQUARE";
+                        break;
+                    }
+                    case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseIn:
+                    {
+                        _alphaFunction = "EASE_IN";
+                        break;
+                    }
+                    case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseOut:
+                    {
+                        _alphaFunction = "EASE_OUT";
+                        break;
+                    }
+                    case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseInOut:
+                    {
+                        _alphaFunction = "EASE_IN_OUT";
+                        break;
+                    }
+                    case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseInSine:
+                    {
+                        _alphaFunction = "EASE_IN_SINE";
+                        break;
+                    }
+                    case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseOutSine:
+                    {
+                        _alphaFunction = "EASE_OUT_SINE";
+                        break;
+                    }
+                    case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseInOutSine:
+                    {
+                        _alphaFunction = "EASE_IN_OUT_SINE";
+                        break;
+                    }
+                    case Tizen.NUI.AlphaFunction.BuiltinFunctions.Bounce:
+                    {
+                        _alphaFunction = "BOUNCE";
+                        break;
+                    }
+                    case Tizen.NUI.AlphaFunction.BuiltinFunctions.Sin:
+                    {
+                        _alphaFunction = "SIN";
+                        break;
+                    }
+                    case Tizen.NUI.AlphaFunction.BuiltinFunctions.EaseOutBack:
+                    {
+                        _alphaFunction = "EASE_OUT_BACK";
+                        break;
+                    }
+                    default:
+                    {
+                        _alphaFunction = "DEFAULT";
+                        break;
+                    }
+                }
             }
         }