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.Constants;
24 namespace VisaulAnimationExample
26 class Example : NUIApplication
28 private VisualView _contentView;
29 private TextLabel _title;
30 private PushButton _shadowButton;
31 private bool _active = false;
32 private const string _resPath = "/home/owner/apps_rw/NUISamples.TizenTV/res";
34 private Animation _animation;
35 private bool _transitionInProgress = false;
36 private int cnt1, cnt2;
38 private SVGVisual svgVisual;
39 private AnimatedImageVisual gifVisual;
41 public Example() : base()
45 public Example(string stylesheet) : base(stylesheet)
49 public Example(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
53 protected override void OnCreate()
59 public void Initialize()
61 Stage stage = Stage.Instance;
62 stage.BackgroundColor = Color.White;
64 TableView titleLayout = new TableView(2, 1);
65 titleLayout.Name = ("TitleLayout");
66 titleLayout.AnchorPoint = AnchorPoint.TopLeft;
67 titleLayout.Position2D = new Position2D(10, 10);
68 titleLayout.Size2D = new Size2D((int)(stage.Size.Width * 0.9f), (int)(stage.Size.Height * 0.9f));
69 titleLayout.SetCellPadding(new Size2D(10, 10));
70 titleLayout.BackgroundColor = Color.Cyan;
71 stage.GetDefaultLayer().Add(titleLayout);
73 _title = new TextLabel("Visual Transition / SVG / AGIF Example");
74 _title.Name = ("Title");
75 _title.SetStyleName("Title");
76 _title.WidthResizePolicy = ResizePolicyType.FillToParent;
77 _title.HeightResizePolicy = ResizePolicyType.UseNaturalSize;
78 _title.HorizontalAlignment = HorizontalAlignment.HorizontalAlignCenter;
79 titleLayout.AddChild(_title, new TableView.CellPosition(0, 0));
80 titleLayout.SetFitHeight(0);
82 TableView contentLayout = new TableView(3, 2);
83 contentLayout.Name = ("ContentLayout");
84 contentLayout.WidthResizePolicy = ResizePolicyType.FillToParent;
85 contentLayout.HeightResizePolicy = ResizePolicyType.FillToParent;
86 contentLayout.AnchorPoint = AnchorPoint.TopLeft;
87 contentLayout.SetCellPadding(new Size2D(10, 10));
88 contentLayout.BackgroundColor = Color.Magenta;
89 titleLayout.AddChild(contentLayout, new TableView.CellPosition(1, 0));
91 //////////////////////////////////////////////////////////////////////
92 // Create a conttent view
93 _contentView = new VisualView();
94 _contentView.WidthResizePolicy = ResizePolicyType.SizeRelativeToParent;
95 _contentView.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
96 //_contentView.Size2D = new Size2D(250, 250);
97 _contentView.BackgroundImage = _resPath + "/images/background-blocks.jpg";
99 ImageVisual _icon = new ImageVisual();
100 _icon.URL = _resPath + "/images/application-icon-0.png";
101 _icon.DepthIndex = 1;
102 _icon.Size = new Size2D(50, 50);
103 _icon.SizePolicy = new Vector2(1, 1);
104 _icon.Position = new Position2D(5, 5);
105 _icon.PositionPolicy = new Vector2(1, 1);
106 _icon.Origin = Visual.AlignType.TopBegin;
107 _icon.AnchorPoint = Visual.AlignType.TopBegin;
108 _icon.MixColor = new Color(0, 1, 0, 0.5f);
109 _icon.Opacity = 0.5f;
110 _contentView.AddVisual("icon_visual1", _icon);
112 contentLayout.AddChild(_contentView, new TableView.CellPosition(0, 0));
114 _shadowButton = new PushButton();
115 _shadowButton.LabelText = "Toggle Transition";
116 _shadowButton.Name = ("ToggleTransition");
117 _shadowButton.ParentOrigin = ParentOrigin.Center;
118 _shadowButton.AnchorPoint = AnchorPoint.Center;
119 _shadowButton.Clicked += (obj, ev) =>
122 StartTransition(_active);
125 _shadowButton.WidthResizePolicy = ResizePolicyType.FillToParent;
126 _shadowButton.HeightResizePolicy = ResizePolicyType.FillToParent;
127 contentLayout.AddChild(_shadowButton, new TableView.CellPosition(0, 1));
129 //////////////////////////////////////////////////////////////////////
130 // make NPatch visual test
131 NPatchVisual npatch1 = new NPatchVisual();
132 npatch1.URL = _resPath + "/images/gallery-2.jpg";
133 npatch1.Size = new Size2D(400, 400);
134 npatch1.SizePolicy = new Vector2(1, 1);
135 npatch1.Position = new Position2D(400, 0);
136 npatch1.PositionPolicy = new Vector2(1, 1);
137 npatch1.Origin = Visual.AlignType.TopBegin;
138 npatch1.AnchorPoint = Visual.AlignType.TopBegin;
139 npatch1.Border = new Rectangle(100, 100, 100, 100);
140 npatch1.DepthIndex = 2;
141 npatch1.MixColor = new Color(1, 0, 0, 1);
142 npatch1.Opacity = 0.5f;
143 _contentView.AddVisual("npatchImageVisual1", npatch1);
146 //////////////////////////////////////////////////////////////////////
147 // make SVG visual test
148 VisualView VisualView1 = new VisualView();
149 VisualView1.WidthResizePolicy = ResizePolicyType.FillToParent;
150 VisualView1.HeightResizePolicy = ResizePolicyType.FillToParent;
151 VisualView1.BackgroundColor = Color.Black;
152 contentLayout.AddChild(VisualView1, new TableView.CellPosition(1, 0));
154 svgVisual = new SVGVisual();
155 svgVisual.URL = _resPath + "/images/Kid1.svg";
156 svgVisual.Size = new Size2D(300, 300);
157 svgVisual.SizePolicy = new Vector2(1, 1);
158 svgVisual.Position = new Position2D(0, 0);
159 svgVisual.PositionPolicy = new Vector2(1, 1);
160 svgVisual.Origin = Visual.AlignType.TopBegin;
161 svgVisual.AnchorPoint = Visual.AlignType.TopBegin;
162 VisualView1.AddVisual("svg_visual1", svgVisual);
164 PushButton svgButton = new PushButton();
165 svgButton.LabelText = "SVG Visual Test";
166 svgButton.Name = ("svg_visual_test");
167 svgButton.AnchorPoint = AnchorPoint.Center;
168 svgButton.WidthResizePolicy = ResizePolicyType.FillToParent;
169 svgButton.HeightResizePolicy = ResizePolicyType.FillToParent;
170 svgButton.Clicked += (obj, ev) =>
175 svgVisual.URL = _resPath + "/images/World.svg";
179 svgVisual.URL = _resPath + "/images/Mail.svg";
181 Tizen.Log.Debug("NUI", "svg button clicked!");
184 contentLayout.AddChild(svgButton, new TableView.CellPosition(1, 1));
186 //////////////////////////////////////////////////////////////////////
187 // make AnimatedImage visual test
188 VisualView VisualView2 = new VisualView();
189 VisualView2.WidthResizePolicy = ResizePolicyType.FillToParent;
190 VisualView2.HeightResizePolicy = ResizePolicyType.FillToParent;
191 VisualView2.BackgroundColor = Color.Blue;
192 contentLayout.AddChild(VisualView2, new TableView.CellPosition(2, 0));
194 gifVisual = new AnimatedImageVisual();
195 gifVisual.URL = _resPath + "/images/dog-anim.gif";
196 gifVisual.Size = new Size2D(200, 200);
197 gifVisual.SizePolicy = new Vector2(1, 1);
198 gifVisual.Position = new Position2D(0, 0);
199 gifVisual.PositionPolicy = new Vector2(1, 1);
200 gifVisual.Origin = Visual.AlignType.TopBegin;
201 gifVisual.AnchorPoint = Visual.AlignType.TopBegin;
202 VisualView2.AddVisual("gif_visual", gifVisual);
204 PushButton gifButton = new PushButton();
205 gifButton.LabelText = "AnimatedImage Visual Test";
206 gifButton.Name = ("gif_visual_test");
207 gifButton.AnchorPoint = AnchorPoint.Center;
208 gifButton.WidthResizePolicy = ResizePolicyType.FillToParent;
209 gifButton.HeightResizePolicy = ResizePolicyType.FillToParent;
210 gifButton.Clicked += (obj, ev) =>
212 Tizen.Log.Debug("NUI", "gif button clicked!");
216 gifVisual.URL = _resPath + "/images/dali-logo-anim.gif";
220 gifVisual.URL = _resPath + "/images/echo.gif";
224 contentLayout.AddChild(gifButton, new TableView.CellPosition(2, 1));
229 private void StartTransition(bool activate)
234 _animation.Finished += OnTransitionFinished;
239 AnimatorVisual grow = new AnimatorVisual();
240 grow.AlphaFunction = "LINEAR";
243 grow.Target = "icon_visual1";
244 grow.PropertyIndex = "Size";
245 grow.DestinationValue = new Size2D(200, 200);
246 _animation = _contentView.AnimateVisual(grow);
250 AnimatorVisual shrink = new AnimatorVisual();
251 shrink.AlphaFunction = "LINEAR";
252 shrink.StartTime = 0;
253 shrink.EndTime = 1000;
254 shrink.Target = "icon_visual1";
255 shrink.PropertyIndex = "Size";
256 shrink.DestinationValue = new Size2D(50, 50);
257 _animation = _contentView.AnimateVisual(shrink);
262 _animation.Finished += OnTransitionFinished;
263 _transitionInProgress = true;
267 private void OnTransitionFinished(object sender, EventArgs e)
269 _transitionInProgress = false;
272 _animation.Finished += OnTransitionFinished;
279 /// The main entry point for the application.
282 static void _Main(string[] args)
284 Example example = new Example();