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;
22 namespace VisaulAnimationExample
24 class Example : NUIApplication
26 private VisualView _contentView;
27 private TextLabel _title;
28 private PushButton _shadowButton;
29 private bool _active = false;
30 private const string _resPath = "/home/owner/apps_rw/NUISamples.TizenTV/res";
32 private Animation _animation;
33 private bool _transitionInProgress = false;
34 private int cnt1, cnt2;
36 private SVGVisual svgVisual;
37 private AnimatedImageVisual gifVisual;
39 public Example() : base()
43 public Example(string stylesheet) : base(stylesheet)
47 public Example(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
51 protected override void OnCreate()
57 public void Initialize()
59 Stage stage = Stage.Instance;
60 stage.BackgroundColor = Color.White;
62 TableView titleLayout = new TableView(2, 1);
63 titleLayout.Name = ("TitleLayout");
64 titleLayout.AnchorPoint = AnchorPoint.TopLeft;
65 titleLayout.Position2D = new Position2D(10, 10);
66 titleLayout.Size2D = new Size2D((int)(stage.Size.Width * 0.9f), (int)(stage.Size.Height * 0.9f));
67 titleLayout.SetCellPadding(new Size2D(10, 10));
68 titleLayout.BackgroundColor = Color.Cyan;
69 stage.GetDefaultLayer().Add(titleLayout);
71 _title = new TextLabel("Visual Transition / SVG / AGIF Example");
72 _title.Name = ("Title");
73 _title.SetStyleName("Title");
74 _title.WidthResizePolicy = ResizePolicyType.FillToParent;
75 _title.HeightResizePolicy = ResizePolicyType.UseNaturalSize;
76 _title.HorizontalAlignment = "CENTER";
77 titleLayout.AddChild(_title, new TableView.CellPosition(0, 0));
78 titleLayout.SetFitHeight(0);
80 TableView contentLayout = new TableView(3, 2);
81 contentLayout.Name = ("ContentLayout");
82 contentLayout.WidthResizePolicy = ResizePolicyType.FillToParent;
83 contentLayout.HeightResizePolicy = ResizePolicyType.FillToParent;
84 contentLayout.AnchorPoint = AnchorPoint.TopLeft;
85 contentLayout.SetCellPadding(new Size2D(10, 10));
86 contentLayout.BackgroundColor = Color.Magenta;
87 titleLayout.AddChild(contentLayout, new TableView.CellPosition(1, 0));
89 //////////////////////////////////////////////////////////////////////
90 // Create a conttent view
91 _contentView = new VisualView();
92 _contentView.WidthResizePolicy = ResizePolicyType.Fixed;
93 _contentView.HeightResizePolicy = ResizePolicyType.Fixed;
94 _contentView.Size2D = new Size2D(250, 250);
95 _contentView.BackgroundImage = _resPath + "/images/background-blocks.jpg";
97 ImageVisual _icon = new ImageVisual();
98 _icon.URL = _resPath + "/images/application-icon-0.png";
100 _icon.Size = new Size2D(50, 50);
101 _icon.SizePolicy = new Vector2(1, 1);
102 _icon.Position = new Position2D(5, 5);
103 _icon.PositionPolicy = new Vector2(1, 1);
104 _icon.Origin = Visual.AlignType.TopBegin;
105 _icon.AnchorPoint = Visual.AlignType.TopBegin;
106 _contentView.AddVisual("icon_visual1", _icon);
108 contentLayout.AddChild(_contentView, new TableView.CellPosition(0, 0));
110 _shadowButton = new PushButton();
111 _shadowButton.LabelText = "Toggle Transition";
112 _shadowButton.Name = ("ToggleTransition");
113 _shadowButton.ParentOrigin = ParentOrigin.Center;
114 _shadowButton.AnchorPoint = AnchorPoint.Center;
115 _shadowButton.Clicked += (obj, ev) =>
118 StartTransition(_active);
121 _shadowButton.WidthResizePolicy = ResizePolicyType.FillToParent;
122 _shadowButton.HeightResizePolicy = ResizePolicyType.FillToParent;
123 contentLayout.AddChild(_shadowButton, new TableView.CellPosition(0, 1));
125 //////////////////////////////////////////////////////////////////////
126 // make SVG visual test
127 VisualView VisualView1 = new VisualView();
128 VisualView1.WidthResizePolicy = ResizePolicyType.FillToParent;
129 VisualView1.HeightResizePolicy = ResizePolicyType.FillToParent;
130 VisualView1.BackgroundColor = Color.Black;
131 contentLayout.AddChild(VisualView1, new TableView.CellPosition(1, 0));
133 svgVisual = new SVGVisual();
134 svgVisual.URL = _resPath + "/images/Kid1.svg";
135 svgVisual.Size = new Size2D(300, 300);
136 svgVisual.SizePolicy = new Vector2(1, 1);
137 svgVisual.Position = new Position2D(0, 0);
138 svgVisual.PositionPolicy = new Vector2(1, 1);
139 svgVisual.Origin = Visual.AlignType.TopBegin;
140 svgVisual.AnchorPoint = Visual.AlignType.TopBegin;
141 VisualView1.AddVisual("svg_visual1", svgVisual);
143 PushButton svgButton = new PushButton();
144 svgButton.LabelText = "SVG Visual Test";
145 svgButton.Name = ("svg_visual_test");
146 svgButton.AnchorPoint = AnchorPoint.Center;
147 svgButton.WidthResizePolicy = ResizePolicyType.FillToParent;
148 svgButton.HeightResizePolicy = ResizePolicyType.FillToParent;
149 svgButton.Clicked += (obj, ev) =>
154 svgVisual.URL = _resPath + "/images/World.svg";
158 svgVisual.URL = _resPath + "/images/Mail.svg";
160 Tizen.Log.Debug("NUI", "svg button clicked!");
163 contentLayout.AddChild(svgButton, new TableView.CellPosition(1, 1));
165 //////////////////////////////////////////////////////////////////////
166 // make AnimatedImage visual test
167 VisualView VisualView2 = new VisualView();
168 VisualView2.WidthResizePolicy = ResizePolicyType.FillToParent;
169 VisualView2.HeightResizePolicy = ResizePolicyType.FillToParent;
170 VisualView2.BackgroundColor = Color.Blue;
171 contentLayout.AddChild(VisualView2, new TableView.CellPosition(2, 0));
173 gifVisual = new AnimatedImageVisual();
174 gifVisual.URL = _resPath + "/images/echo.gif";
175 gifVisual.Size = new Size2D(200, 200);
176 gifVisual.SizePolicy = new Vector2(1, 1);
177 gifVisual.Position = new Position2D(0, 0);
178 gifVisual.PositionPolicy = new Vector2(1, 1);
179 gifVisual.Origin = Visual.AlignType.TopBegin;
180 gifVisual.AnchorPoint = Visual.AlignType.TopBegin;
181 VisualView2.AddVisual("gif_visual", gifVisual);
183 PushButton gifButton = new PushButton();
184 gifButton.LabelText = "AnimatedImage Visual Test";
185 gifButton.Name = ("gif_visual_test");
186 gifButton.AnchorPoint = AnchorPoint.Center;
187 gifButton.WidthResizePolicy = ResizePolicyType.FillToParent;
188 gifButton.HeightResizePolicy = ResizePolicyType.FillToParent;
189 gifButton.Clicked += (obj, ev) =>
191 Tizen.Log.Debug("NUI", "gif button clicked!");
195 gifVisual.URL = _resPath + "/images/dali-logo-anim.gif";
199 gifVisual.URL = _resPath + "/images/dog-anim.gif";
203 contentLayout.AddChild(gifButton, new TableView.CellPosition(2, 1));
208 private void StartTransition(bool activate)
213 _animation.Finished += OnTransitionFinished;
218 AnimatorVisual grow = new AnimatorVisual();
219 grow.AlphaFunction = "LINEAR";
222 grow.Target = "icon_visual1";
223 grow.PropertyIndex = "Size";
224 grow.DestinationValue = new Size2D(200, 200);
225 _animation = _contentView.AnimateVisual(grow);
229 AnimatorVisual shrink = new AnimatorVisual();
230 shrink.AlphaFunction = "LINEAR";
231 shrink.StartTime = 0;
232 shrink.EndTime = 1000;
233 shrink.Target = "icon_visual1";
234 shrink.PropertyIndex = "Size";
235 shrink.DestinationValue = new Size2D(50, 50);
236 _animation = _contentView.AnimateVisual(shrink);
241 _animation.Finished += OnTransitionFinished;
242 _transitionInProgress = true;
246 private void OnTransitionFinished(object sender, EventArgs e)
248 _transitionInProgress = false;
251 _animation.Finished += OnTransitionFinished;
258 /// The main entry point for the application.
261 static void _Main(string[] args)
263 Example example = new Example();