From 989914e2743aeaf732cf156f9ae106159a1302fa Mon Sep 17 00:00:00 2001 From: "xb.teng" Date: Thu, 1 Jun 2017 23:31:27 +0800 Subject: [PATCH] Make visual view to support group animation Change-Id: I81ef0bbad419c594483737ce35527c0bc8028eda --- .../NUISamples.TizenTV/NUISamples.TizenTV.csproj | 1 + .../NUISamples/NUISamples.TizenTV/examples/Main.cs | 5 +- .../examples/visual-animation-test.cs | 31 +-- .../examples/visual-animation-test3.cs | 232 +++++++++++++++++++++ .../src/public/BaseComponents/VisualView.cs | 146 ++++++++++++- 5 files changed, 386 insertions(+), 29 deletions(-) create mode 100755 NUISamples/NUISamples/NUISamples.TizenTV/examples/visual-animation-test3.cs diff --git a/NUISamples/NUISamples/NUISamples.TizenTV/NUISamples.TizenTV.csproj b/NUISamples/NUISamples/NUISamples.TizenTV/NUISamples.TizenTV.csproj index 8c34bf8..db68db3 100755 --- a/NUISamples/NUISamples/NUISamples.TizenTV/NUISamples.TizenTV.csproj +++ b/NUISamples/NUISamples/NUISamples.TizenTV/NUISamples.TizenTV.csproj @@ -79,6 +79,7 @@ + diff --git a/NUISamples/NUISamples/NUISamples.TizenTV/examples/Main.cs b/NUISamples/NUISamples/NUISamples.TizenTV/examples/Main.cs index 26c77d7..78fd748 100755 --- a/NUISamples/NUISamples/NUISamples.TizenTV/examples/Main.cs +++ b/NUISamples/NUISamples/NUISamples.TizenTV/examples/Main.cs @@ -30,7 +30,8 @@ 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 VisaulAnimationExample.Example2().Run(args); //o + new VisaulAnimationExample.Example3().Run(args); //o //new VisualViewTest.Example().Run(args); //o //new VisualViewTest2.VisualSample().Run(args); //new VisualViewTest3.Example().Run(args); //o @@ -38,7 +39,7 @@ namespace NUISamples.TizenTV.examples //new FirstScreen.FirstScreenApp().Run(args); //o //new PositionUsesAnchorPointTest.Example().Run(args); // new VisualsExampleTest.Example().Run(args); //o - new TizenSTVUIApplication15.Program().Run(args); + //new TizenSTVUIApplication15.Program().Run(args); } } } diff --git a/NUISamples/NUISamples/NUISamples.TizenTV/examples/visual-animation-test.cs b/NUISamples/NUISamples/NUISamples.TizenTV/examples/visual-animation-test.cs index c2f172b..adf14e2 100755 --- a/NUISamples/NUISamples/NUISamples.TizenTV/examples/visual-animation-test.cs +++ b/NUISamples/NUISamples/NUISamples.TizenTV/examples/visual-animation-test.cs @@ -33,7 +33,6 @@ namespace VisaulAnimationExample private const string _resPath = "/home/owner/apps_rw/NUISamples.TizenTV/res"; private Animation _animation1; - private Animation _animation2; private bool _transitionInProgress = false; private int cnt1, cnt2; @@ -233,21 +232,18 @@ namespace VisaulAnimationExample _animation1.Stop(); _animation1.Finished += OnTransitionFinished1; } - if (_animation2) - { - _animation2.Stop(); - _animation2.Finished += OnTransitionFinished2; - } if (activate) { - _animation1 = _contentView.AnimateVisual(_icon, "Size", new Size2D(150, 150), 0, 1000, AlphaFunction.BuiltinFunctions.Linear); - _animation2 = _contentView.AnimateVisual(_icon, "Position", new Position2D(40, 40), 0, 1000); + _contentView.AnimateVisualAdd(_icon, "Size", new Size2D(150, 150), 0, 1000, AlphaFunction.BuiltinFunctions.Linear); + _contentView.AnimateVisualAdd(_icon, "Position", new Position2D(40, 40), 0, 1000); + _animation1 = _contentView.AnimateVisualAddFinish(); } else { - _animation1 = _contentView.AnimateVisual(_icon, "Size", new Position2D(50, 50), 0, 1000, AlphaFunction.BuiltinFunctions.Linear); - _animation2 = _contentView.AnimateVisual(_icon, "Position", new Position2D(5, 5), 0, 1000); + _contentView.AnimateVisualAdd(_icon, "Size", new Position2D(50, 50), 0, 1000, AlphaFunction.BuiltinFunctions.Linear); + _contentView.AnimateVisualAdd(_icon, "Position", new Position2D(5, 5), 0, 1000); + _animation1 = _contentView.AnimateVisualAddFinish(); } if (_animation1) @@ -256,12 +252,6 @@ namespace VisaulAnimationExample _transitionInProgress = true; _animation1.Play(); } - if (_animation2) - { - _animation2.Finished += OnTransitionFinished2; - _transitionInProgress = true; - _animation2.Play(); - } } private void OnTransitionFinished1(object sender, EventArgs e) { @@ -272,15 +262,6 @@ namespace VisaulAnimationExample _animation1.Reset(); } } - private void OnTransitionFinished2(object sender, EventArgs e) - { - _transitionInProgress = false; - if (_animation2) - { - _animation2.Finished += OnTransitionFinished2; - _animation2.Reset(); - } - } /// diff --git a/NUISamples/NUISamples/NUISamples.TizenTV/examples/visual-animation-test3.cs b/NUISamples/NUISamples/NUISamples.TizenTV/examples/visual-animation-test3.cs new file mode 100755 index 0000000..8a34dd8 --- /dev/null +++ b/NUISamples/NUISamples/NUISamples.TizenTV/examples/visual-animation-test3.cs @@ -0,0 +1,232 @@ +/* + * 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 Example3 : 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 ImageVisual _icon; + private ImageVisual _icon2; + private ImageVisual _icon3; + private ImageVisual _icon4; + private bool _transitionInProgress = false; + + public Example3() : base() + { + } + + public Example3(string stylesheet) : base(stylesheet) + { + } + + public Example3(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode) + { + } + + protected override void OnCreate() + { + base.OnCreate(); + Initialize(); + } + + public void Initialize() + { + Window window = Window.Instance; + window.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)(window.Size.Width * 0.9f), (int)(window.Size.Height * 0.9f)); + titleLayout.SetCellPadding(new Size2D(10, 10)); + titleLayout.BackgroundColor = Color.Cyan; + window.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(2, 1); + 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"; + + _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); + + _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(200, 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; + _contentView1.AddVisual("icon_visual2", _icon2); + + _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, 200); + _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; + _contentView1.AddVisual("icon_visual3", _icon3); + + _icon4 = new ImageVisual(); + _icon4.URL = _resPath + "/images/application-icon-0.png"; + _icon4.DepthIndex = 1; + _icon4.Size = new Size2D(50, 50); + _icon4.SizePolicy = VisualTransformPolicyType.Absolute; + _icon4.Position = new Position2D(200, 200); + _icon4.PositionPolicy = VisualTransformPolicyType.Absolute; + _icon4.Origin = Visual.AlignType.TopBegin; + _icon4.AnchorPoint = Visual.AlignType.TopBegin; + _icon4.MixColor = new Color(0, 1, 0, 0.5f); + _icon4.Opacity = 0.5f; + _contentView1.AddVisual("icon_visual4", _icon4); + + 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, _active1); + return true; + }; + _shadowButton1.WidthResizePolicy = ResizePolicyType.FillToParent; + _shadowButton1.HeightResizePolicy = ResizePolicyType.UseNaturalSize; + contentLayout.AddChild(_shadowButton1, new TableView.CellPosition(1, 0)); + contentLayout.SetFitHeight(1); + } + + private void StartTransition(VisualView view, bool activate) + { + if (_animation) + { + _animation.Stop(); + _animation.Finished += OnTransitionFinished; + } + + if (activate) + { + view.AnimateVisualAdd(_icon, "Position", new Position2D(80, 80), 0, 2000, AlphaFunction.BuiltinFunctions.Linear, new Position2D(5, 5)); + view.AnimateVisualAdd(_icon2, "Opacity", 0.0f, 0, 2000, AlphaFunction.BuiltinFunctions.Linear); + view.AnimateVisualAdd(_icon3, "MixColor", Color.Green, 0, 2000, AlphaFunction.BuiltinFunctions.Linear); + view.AnimateVisualAdd(_icon4, "Size", new Size2D(150, 150), 0, 2000, AlphaFunction.BuiltinFunctions.Linear); + _animation = view.AnimateVisualAddFinish(); + } + else + { + view.AnimateVisualAdd(_icon, "Position", new Position2D(5, 5), 0, 2000, AlphaFunction.BuiltinFunctions.Linear, new Position2D(80, 80)); + view.AnimateVisualAdd(_icon2, "Opacity", 1.0f, 0, 2000); + view.AnimateVisualAdd(_icon3, "MixColor", Color.Red, 0, 2000); + view.AnimateVisualAdd(_icon4, "Size", new Size2D(50, 50), 0, 2000, AlphaFunction.BuiltinFunctions.Linear); + _animation = view.AnimateVisualAddFinish(); + } + + if (_animation) + { + _animation.Finished += OnTransitionFinished; + _animation.EndAction = Animation.EndActions.StopFinal; + _transitionInProgress = true; + _animation.Play(); + } + } + + private void OnTransitionFinished(object sender, EventArgs e) + { + _transitionInProgress = false; + if (_animation) + { + _animation.Finished += OnTransitionFinished; + _animation.Reset(); + } + } + + /// + /// The main entry point for the application. + /// + [STAThread] + static void _Main(string[] args) + { + Example3 example = new Example3(); + example.Run(args); + } + + + } +} diff --git a/src/Tizen.NUI/src/public/BaseComponents/VisualView.cs b/src/Tizen.NUI/src/public/BaseComponents/VisualView.cs index 935e496..260fcd8 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/VisualView.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/VisualView.cs @@ -42,6 +42,7 @@ namespace Tizen.NUI.BaseComponents //private LinkedList _visualList = null; private Dictionary _visualDictionary = null; private Dictionary _tranformDictionary = null; + private PropertyArray _animateArray = null; static CustomView CreateInstance() { @@ -68,6 +69,7 @@ namespace Tizen.NUI.BaseComponents //Initialize empty _visualDictionary = new Dictionary(); _tranformDictionary = new Dictionary(); + _animateArray = new PropertyArray(); } /// @@ -212,6 +214,7 @@ namespace Tizen.NUI.BaseComponents /// The start time of visual animation. /// The end time of visual animation. /// The alpha function of visual animation + /// The initial property value of visual animation /// Animation instance public Animation AnimateVisual(VisualMap target, string property, object destinationValue, int startTime, int endTime, AlphaFunction.BuiltinFunctions? alphaFunction = null, object initialValue = null) { @@ -330,6 +333,147 @@ namespace Tizen.NUI.BaseComponents return null; } + /// + /// Add group visual animation (transition) map with the input parameters. + /// + /// The visual map to animation. + /// The property of visual to animation. + /// The destination value of property after animation. + /// The start time of visual animation. + /// The end time of visual animation. + /// The alpha function of visual animation + /// The initial property value of visual animation + public void AnimateVisualAdd(VisualMap target, string property, object destinationValue, int startTime, int endTime, AlphaFunction.BuiltinFunctions? alphaFunction = null, object initialValue = null) + { + string _alphaFunction = null; + if (alphaFunction != null) + { + switch (alphaFunction) + { + 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; + } + } + } + + foreach (var item in _visualDictionary.ToList()) + { + if (item.Value.Name == target.Name) + { + PropertyMap _animator = new PropertyMap(); + if ( _alphaFunction != null) {_animator.Add("alphaFunction", new PropertyValue(_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)); + + string _str1 = property.Substring(0, 1); + string _str2 = property.Substring(1); + string _str = _str1.ToLower() + _str2; + if (_str == "position") {_str = "offset";} + + PropertyValue destVal = PropertyValue.CreateFromObject(destinationValue); + + PropertyMap _transition = new PropertyMap(); + _transition.Add("target", new PropertyValue(target.Name)); + _transition.Add("property", new PropertyValue(_str)); + if (initialValue != null) + { + PropertyValue initVal = PropertyValue.CreateFromObject(initialValue); + _transition.Add("initialValue", new PropertyValue(initVal)); + } + _transition.Add("targetValue", destVal); + _transition.Add("animator", new PropertyValue(_animator)); + + _animateArray.Add(new PropertyValue(_transition)); + } + } + } + + /// + /// Finish to add Visual animation (transition) map and create transition animation. + /// + /// Animation instance + public Animation AnimateVisualAddFinish() + { + if ( _animateArray == null || _animateArray.Empty()) + { + Tizen.Log.Fatal("NUI", "animate visual property array is empty!"); + return null; + } + TransitionData _transitionData = new TransitionData(_animateArray); + + return this.CreateTransition(_transitionData); + } + //temporary fix to pass TCT public Animation VisualAnimate(Tizen.NUI.VisualAnimator visualMap) @@ -346,7 +490,5 @@ namespace Tizen.NUI.BaseComponents } //temporary fix to pass TCT - - } } -- 2.7.4