2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.Runtime.InteropServices;
21 using Tizen.NUI.UIComponents;
22 using Tizen.NUI.BaseComponents;
23 using Tizen.NUI.Constants;
25 namespace VisaulAnimationExample
27 class Example3 : NUIApplication
29 private VisualView _contentView1;
30 private VisualView _contentView2;
31 private VisualView _contentView3;
32 private TextLabel _title;
33 private PushButton _shadowButton1;
34 private PushButton _shadowButton2;
35 private PushButton _shadowButton3;
36 private bool _active1 = false;
37 private bool _active2 = false;
38 private bool _active3 = false;
39 //private const string _resPath = "/home/owner/apps_rw/NUISamples.TizenTV/res";
40 private const string _resPath = "./res"; //for ubuntu
42 private Animation _animation;
43 private ImageVisual _icon;
44 private ImageVisual _icon2;
45 private ImageVisual _icon3;
46 private ImageVisual _icon4;
47 private bool _transitionInProgress = false;
49 public Example3() : base()
53 public Example3(string stylesheet) : base(stylesheet)
57 public Example3(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
61 protected override void OnCreate()
67 public void Initialize()
69 Window window = Window.Instance;
70 window.BackgroundColor = Color.White;
72 TableView titleLayout = new TableView(2, 1);
73 titleLayout.Name = ("TitleLayout");
74 titleLayout.PivotPoint = PivotPoint.TopLeft;
75 titleLayout.Position2D = new Position2D(10, 10);
76 titleLayout.Size2D = new Size2D((int)(window.Size.Width * 0.9f), (int)(window.Size.Height * 0.9f));
77 titleLayout.SetCellPadding(new Size2D(10, 10));
78 titleLayout.BackgroundColor = Color.Cyan;
79 window.Add(titleLayout);
81 _title = new TextLabel("Visual Transition Example");
82 _title.Name = ("Title");
83 _title.SetStyleName("Title");
84 _title.WidthResizePolicy = ResizePolicyType.FillToParent;
85 _title.HeightResizePolicy = ResizePolicyType.UseNaturalSize;
86 _title.HorizontalAlignment = HorizontalAlignment.Center;
87 titleLayout.AddChild(_title, new TableView.CellPosition(0, 0));
88 titleLayout.SetFitHeight(0);
90 TableView contentLayout = new TableView(2, 1);
91 contentLayout.Name = ("ContentLayout");
92 contentLayout.WidthResizePolicy = ResizePolicyType.FillToParent;
93 contentLayout.HeightResizePolicy = ResizePolicyType.FillToParent;
94 contentLayout.PivotPoint = PivotPoint.TopLeft;
95 contentLayout.SetCellPadding(new Size2D(10, 10));
96 contentLayout.BackgroundColor = Color.Magenta;
97 titleLayout.AddChild(contentLayout, new TableView.CellPosition(1, 0));
99 // make visual position animation
100 _contentView1 = new VisualView();
101 _contentView1.WidthResizePolicy = ResizePolicyType.SizeRelativeToParent;
102 _contentView1.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
103 //_contentView.Size2D = new Size2D(250, 250);
104 _contentView1.BackgroundImage = _resPath + "/images/background-blocks.jpg";
106 _icon = new ImageVisual();
107 _icon.URL = _resPath + "/images/application-icon-0.png";
108 _icon.DepthIndex = 1;
109 _icon.Size = new Size2D(50, 50);
110 _icon.SizePolicy = VisualTransformPolicyType.Absolute;
111 _icon.Position = new Position2D(5, 5);
112 _icon.PositionPolicy = VisualTransformPolicyType.Absolute;
113 _icon.Origin = Visual.AlignType.TopBegin;
114 _icon.AnchorPoint = Visual.AlignType.TopBegin;
115 _icon.MixColor = new Color(0, 1, 0, 0.5f);
116 _icon.Opacity = 0.5f;
117 _contentView1.AddVisual("icon_visual1", _icon);
119 _icon2 = new ImageVisual();
120 _icon2.URL = _resPath + "/images/application-icon-0.png";
121 _icon2.DepthIndex = 1;
122 _icon2.Size = new Size2D(50, 50);
123 _icon2.SizePolicy = VisualTransformPolicyType.Absolute;
124 _icon2.Position = new Position2D(200, 5);
125 _icon2.PositionPolicy = VisualTransformPolicyType.Absolute;
126 _icon2.Origin = Visual.AlignType.TopBegin;
127 _icon2.AnchorPoint = Visual.AlignType.TopBegin;
128 _icon2.MixColor = new Color(0, 1, 0, 0.5f);
129 _icon2.Opacity = 0.5f;
130 _contentView1.AddVisual("icon_visual2", _icon2);
132 _icon3 = new ImageVisual();
133 _icon3.URL = _resPath + "/images/application-icon-0.png";
134 _icon3.DepthIndex = 1;
135 _icon3.Size = new Size2D(50, 50);
136 _icon3.SizePolicy = VisualTransformPolicyType.Absolute;
137 _icon3.Position = new Position2D(5, 200);
138 _icon3.PositionPolicy = VisualTransformPolicyType.Absolute;
139 _icon3.Origin = Visual.AlignType.TopBegin;
140 _icon3.AnchorPoint = Visual.AlignType.TopBegin;
141 _icon3.MixColor = new Color(0, 1, 0, 0.5f);
142 _icon3.Opacity = 0.5f;
143 _contentView1.AddVisual("icon_visual3", _icon3);
145 _icon4 = new ImageVisual();
146 _icon4.URL = _resPath + "/images/application-icon-0.png";
147 _icon4.DepthIndex = 1;
148 _icon4.Size = new Size2D(50, 50);
149 _icon4.SizePolicy = VisualTransformPolicyType.Absolute;
150 _icon4.Position = new Position2D(200, 200);
151 _icon4.PositionPolicy = VisualTransformPolicyType.Absolute;
152 _icon4.Origin = Visual.AlignType.TopBegin;
153 _icon4.AnchorPoint = Visual.AlignType.TopBegin;
154 _icon4.MixColor = new Color(0, 1, 0, 0.5f);
155 _icon4.Opacity = 0.5f;
156 _contentView1.AddVisual("icon_visual4", _icon4);
158 contentLayout.AddChild(_contentView1, new TableView.CellPosition(0, 0));
160 _shadowButton1 = new PushButton();
161 _shadowButton1.LabelText = "Toggle Transition Position";
162 _shadowButton1.Name = ("ToggleTransition");
163 _shadowButton1.ParentOrigin = ParentOrigin.Center;
164 _shadowButton1.PivotPoint = PivotPoint.Center;
165 _shadowButton1.Clicked += (obj, ev) =>
167 _active1 = !_active1;
168 StartTransition(_contentView1, _active1);
171 _shadowButton1.WidthResizePolicy = ResizePolicyType.FillToParent;
172 _shadowButton1.HeightResizePolicy = ResizePolicyType.UseNaturalSize;
173 contentLayout.AddChild(_shadowButton1, new TableView.CellPosition(1, 0));
174 contentLayout.SetFitHeight(1);
177 private void StartTransition(VisualView view, bool activate)
182 _animation.Finished += OnTransitionFinished;
187 view.AnimateVisualAdd(_icon, "Position", new Position2D(80, 80), 0, 2000, AlphaFunction.BuiltinFunctions.Linear, new Position2D(5, 5));
188 view.AnimateVisualAdd(_icon2, "Opacity", 0.0f, 0, 2000, AlphaFunction.BuiltinFunctions.Linear);
189 view.AnimateVisualAdd(_icon3, "MixColor", Color.Green, 0, 2000, AlphaFunction.BuiltinFunctions.Linear);
190 view.AnimateVisualAdd(_icon4, "Size", new Size2D(150, 150), 0, 2000, AlphaFunction.BuiltinFunctions.Linear);
191 _animation = view.AnimateVisualAddFinish();
195 view.AnimateVisualAdd(_icon, "Position", new Position2D(5, 5), 0, 2000, AlphaFunction.BuiltinFunctions.Linear, new Position2D(80, 80));
196 view.AnimateVisualAdd(_icon2, "Opacity", 1.0f, 0, 2000);
197 view.AnimateVisualAdd(_icon3, "MixColor", Color.Red, 0, 2000);
198 view.AnimateVisualAdd(_icon4, "Size", new Size2D(50, 50), 0, 2000, AlphaFunction.BuiltinFunctions.Linear);
199 _animation = view.AnimateVisualAddFinish();
204 _animation.Finished += OnTransitionFinished;
205 _animation.EndAction = Animation.EndActions.StopFinal;
206 _transitionInProgress = true;
211 private void OnTransitionFinished(object sender, EventArgs e)
213 _transitionInProgress = false;
216 _animation.Finished += OnTransitionFinished;
222 /// The main entry point for the application.
225 static void _Main(string[] args)
227 Example3 example = new Example3();