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 Example2 : 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";
41 private Animation _animation;
42 private bool _transitionInProgress = false;
44 public Example2() : base()
48 public Example2(string stylesheet) : base(stylesheet)
52 public Example2(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
56 protected override void OnCreate()
62 public void Initialize()
64 Window window = Window.Instance;
65 window.BackgroundColor = Color.White;
67 TableView titleLayout = new TableView(2, 1);
68 titleLayout.Name = ("TitleLayout");
69 titleLayout.AnchorPoint = AnchorPoint.TopLeft;
70 titleLayout.Position2D = new Position2D(10, 10);
71 titleLayout.Size2D = new Size2D((int)(window.Size.Width * 0.9f), (int)(window.Size.Height * 0.9f));
72 titleLayout.SetCellPadding(new Size2D(10, 10));
73 titleLayout.BackgroundColor = Color.Cyan;
74 window.GetDefaultLayer().Add(titleLayout);
76 _title = new TextLabel("Visual Transition Example");
77 _title.Name = ("Title");
78 _title.SetStyleName("Title");
79 _title.WidthResizePolicy = ResizePolicyType.FillToParent;
80 _title.HeightResizePolicy = ResizePolicyType.UseNaturalSize;
81 _title.HorizontalAlignment = HorizontalAlignment.Center;
82 titleLayout.AddChild(_title, new TableView.CellPosition(0, 0));
83 titleLayout.SetFitHeight(0);
85 TableView contentLayout = new TableView(3, 2);
86 contentLayout.Name = ("ContentLayout");
87 contentLayout.WidthResizePolicy = ResizePolicyType.FillToParent;
88 contentLayout.HeightResizePolicy = ResizePolicyType.FillToParent;
89 contentLayout.AnchorPoint = AnchorPoint.TopLeft;
90 contentLayout.SetCellPadding(new Size2D(10, 10));
91 contentLayout.BackgroundColor = Color.Magenta;
92 titleLayout.AddChild(contentLayout, new TableView.CellPosition(1, 0));
94 //////////////////////////////////////////////////////////////////////
95 // make visual position animation
96 _contentView1 = new VisualView();
97 _contentView1.WidthResizePolicy = ResizePolicyType.SizeRelativeToParent;
98 _contentView1.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
99 //_contentView.Size2D = new Size2D(250, 250);
100 _contentView1.BackgroundImage = _resPath + "/images/background-blocks.jpg";
102 ImageVisual _icon = new ImageVisual();
103 _icon.URL = _resPath + "/images/application-icon-0.png";
104 _icon.DepthIndex = 1;
105 _icon.Size = new Size2D(50, 50);
106 _icon.SizePolicy = VisualTransformPolicyType.Absolute;
107 _icon.Position = new Position2D(5, 5);
108 _icon.PositionPolicy = VisualTransformPolicyType.Absolute;
109 _icon.Origin = Visual.AlignType.TopBegin;
110 _icon.AnchorPoint = Visual.AlignType.TopBegin;
111 _icon.MixColor = new Color(0, 1, 0, 0.5f);
112 _icon.Opacity = 0.5f;
113 _contentView1.AddVisual("icon_visual1", _icon);
115 contentLayout.AddChild(_contentView1, new TableView.CellPosition(0, 0));
117 _shadowButton1 = new PushButton();
118 _shadowButton1.LabelText = "Toggle Transition Position";
119 _shadowButton1.Name = ("ToggleTransition");
120 _shadowButton1.ParentOrigin = ParentOrigin.Center;
121 _shadowButton1.AnchorPoint = AnchorPoint.Center;
122 _shadowButton1.Clicked += (obj, ev) =>
124 _active1 = !_active1;
125 StartTransition(_contentView1, "icon_visual1", "Offset", _active1);
128 _shadowButton1.WidthResizePolicy = ResizePolicyType.FillToParent;
129 _shadowButton1.HeightResizePolicy = ResizePolicyType.FillToParent;
130 contentLayout.AddChild(_shadowButton1, new TableView.CellPosition(0, 1));
132 //////////////////////////////////////////////////////////////////////
133 // make visual opacity animation
134 _contentView2 = new VisualView();
135 _contentView2.WidthResizePolicy = ResizePolicyType.SizeRelativeToParent;
136 _contentView2.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
137 //_contentView.Size2D = new Size2D(250, 250);
138 _contentView2.BackgroundImage = _resPath + "/images/background-blocks.jpg";
140 ImageVisual _icon2 = new ImageVisual();
141 _icon2.URL = _resPath + "/images/application-icon-0.png";
142 _icon2.DepthIndex = 1;
143 _icon2.Size = new Size2D(50, 50);
144 _icon2.SizePolicy = VisualTransformPolicyType.Absolute;
145 _icon2.Position = new Position2D(5, 5);
146 _icon2.PositionPolicy = VisualTransformPolicyType.Absolute;
147 _icon2.Origin = Visual.AlignType.TopBegin;
148 _icon2.AnchorPoint = Visual.AlignType.TopBegin;
149 _icon2.MixColor = new Color(0, 1, 0, 0.5f);
150 _icon2.Opacity = 0.5f;
151 _contentView2.AddVisual("icon_visual2", _icon2);
153 contentLayout.AddChild(_contentView2, new TableView.CellPosition(1, 0));
155 _shadowButton2 = new PushButton();
156 _shadowButton2.LabelText = "Toggle Transition Opacity";
157 _shadowButton2.Name = ("ToggleTransition");
158 _shadowButton2.ParentOrigin = ParentOrigin.Center;
159 _shadowButton2.AnchorPoint = AnchorPoint.Center;
160 _shadowButton2.Clicked += (obj, ev) =>
162 _active2 = !_active2;
163 StartTransition(_contentView2, "icon_visual2", "Opacity", _active2);
166 _shadowButton2.WidthResizePolicy = ResizePolicyType.FillToParent;
167 _shadowButton2.HeightResizePolicy = ResizePolicyType.FillToParent;
168 contentLayout.AddChild(_shadowButton2, new TableView.CellPosition(1, 1));
170 //////////////////////////////////////////////////////////////////////
171 // make AnimatedImage visual test
172 _contentView3 = new VisualView();
173 _contentView3.WidthResizePolicy = ResizePolicyType.SizeRelativeToParent;
174 _contentView3.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
175 //_contentView.Size2D = new Size2D(250, 250);
176 _contentView3.BackgroundImage = _resPath + "/images/background-blocks.jpg";
178 ImageVisual _icon3 = new ImageVisual();
179 _icon3.URL = _resPath + "/images/application-icon-0.png";
180 _icon3.DepthIndex = 1;
181 _icon3.Size = new Size2D(50, 50);
182 _icon3.SizePolicy = VisualTransformPolicyType.Absolute;
183 _icon3.Position = new Position2D(5, 5);
184 _icon3.PositionPolicy = VisualTransformPolicyType.Absolute;
185 _icon3.Origin = Visual.AlignType.TopBegin;
186 _icon3.AnchorPoint = Visual.AlignType.TopBegin;
187 _icon3.MixColor = new Color(0, 1, 0, 0.5f);
188 _icon3.Opacity = 0.5f;
189 _contentView3.AddVisual("icon_visual3", _icon3);
191 contentLayout.AddChild(_contentView3, new TableView.CellPosition(2, 0));
193 _shadowButton3 = new PushButton();
194 _shadowButton3.LabelText = "Toggle Transition MixColor";
195 _shadowButton3.Name = ("ToggleTransition");
196 _shadowButton3.ParentOrigin = ParentOrigin.Center;
197 _shadowButton3.AnchorPoint = AnchorPoint.Center;
198 _shadowButton3.Clicked += (obj, ev) =>
200 _active3 = !_active3;
201 StartTransition(_contentView3, "icon_visual3", "MixColor", _active3);
204 _shadowButton3.WidthResizePolicy = ResizePolicyType.FillToParent;
205 _shadowButton3.HeightResizePolicy = ResizePolicyType.FillToParent;
206 contentLayout.AddChild(_shadowButton3, new TableView.CellPosition(2, 1));
209 private void StartTransition(VisualView view, string target, string property, bool activate)
214 _animation.Finished += OnTransitionFinished;
219 VisualAnimator state1 = new VisualAnimator();
220 state1.AlphaFunction = AlphaFunction.BuiltinFunctions.Linear;
221 state1.StartTime = 0;
222 state1.EndTime = 1000;
223 state1.Target = target;
224 state1.PropertyIndex = property;
225 if (property == "Offset")
227 state1.DestinationValue = new Position2D(20, 20);
229 else if (property == "Opacity")
231 state1.DestinationValue = 0.0f;
233 else if (property == "MixColor")
235 state1.DestinationValue = Color.Green;
237 _animation = view.VisualAnimate(state1);
241 VisualAnimator state2 = new VisualAnimator();
242 state2.AlphaFunction = AlphaFunction.BuiltinFunctions.Linear;
243 state2.StartTime = 0;
244 state2.EndTime = 1000;
245 state2.Target = target;
246 state2.PropertyIndex = property;
247 if (property == "Offset")
249 state2.DestinationValue = new Position2D(5, 5);
251 else if (property == "Opacity")
253 state2.DestinationValue = 1.0f;
255 else if (property == "MixColor")
257 state2.DestinationValue = Color.Red;
259 _animation = view.VisualAnimate(state2);
264 _animation.Finished += OnTransitionFinished;
265 _transitionInProgress = true;
269 private void OnTransitionFinished(object sender, EventArgs e)
271 _transitionInProgress = false;
274 _animation.Finished += OnTransitionFinished;
281 /// The main entry point for the application.
284 static void _Main(string[] args)
286 Example example = new Example();