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.SizeRelativeToParent;
93 _contentView.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
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 _icon.MixColor = new Color(0, 1, 0, 0.5f);
107 _icon.Opacity = 0.5f;
108 _contentView.AddVisual("icon_visual1", _icon);
110 contentLayout.AddChild(_contentView, new TableView.CellPosition(0, 0));
112 _shadowButton = new PushButton();
113 _shadowButton.LabelText = "Toggle Transition";
114 _shadowButton.Name = ("ToggleTransition");
115 _shadowButton.ParentOrigin = ParentOrigin.Center;
116 _shadowButton.AnchorPoint = AnchorPoint.Center;
117 _shadowButton.Clicked += (obj, ev) =>
120 StartTransition(_active);
123 _shadowButton.WidthResizePolicy = ResizePolicyType.FillToParent;
124 _shadowButton.HeightResizePolicy = ResizePolicyType.FillToParent;
125 contentLayout.AddChild(_shadowButton, new TableView.CellPosition(0, 1));
127 //////////////////////////////////////////////////////////////////////
128 // make NPatch visual test
129 NPatchVisual npatch1 = new NPatchVisual();
130 npatch1.URL = _resPath + "/images/gallery-2.jpg";
131 npatch1.Size = new Size2D(400, 400);
132 npatch1.SizePolicy = new Vector2(1, 1);
133 npatch1.Position = new Position2D(400, 0);
134 npatch1.PositionPolicy = new Vector2(1, 1);
135 npatch1.Origin = Visual.AlignType.TopBegin;
136 npatch1.AnchorPoint = Visual.AlignType.TopBegin;
137 npatch1.Border = new Rectangle(100, 100, 100, 100);
138 npatch1.DepthIndex = 2;
139 npatch1.MixColor = new Color(1, 0, 0, 1);
140 npatch1.Opacity = 0.5f;
141 _contentView.AddVisual("npatchImageVisual1", npatch1);
144 //////////////////////////////////////////////////////////////////////
145 // make SVG visual test
146 VisualView VisualView1 = new VisualView();
147 VisualView1.WidthResizePolicy = ResizePolicyType.FillToParent;
148 VisualView1.HeightResizePolicy = ResizePolicyType.FillToParent;
149 VisualView1.BackgroundColor = Color.Black;
150 contentLayout.AddChild(VisualView1, new TableView.CellPosition(1, 0));
152 svgVisual = new SVGVisual();
153 svgVisual.URL = _resPath + "/images/Kid1.svg";
154 svgVisual.Size = new Size2D(300, 300);
155 svgVisual.SizePolicy = new Vector2(1, 1);
156 svgVisual.Position = new Position2D(0, 0);
157 svgVisual.PositionPolicy = new Vector2(1, 1);
158 svgVisual.Origin = Visual.AlignType.TopBegin;
159 svgVisual.AnchorPoint = Visual.AlignType.TopBegin;
160 VisualView1.AddVisual("svg_visual1", svgVisual);
162 PushButton svgButton = new PushButton();
163 svgButton.LabelText = "SVG Visual Test";
164 svgButton.Name = ("svg_visual_test");
165 svgButton.AnchorPoint = AnchorPoint.Center;
166 svgButton.WidthResizePolicy = ResizePolicyType.FillToParent;
167 svgButton.HeightResizePolicy = ResizePolicyType.FillToParent;
168 svgButton.Clicked += (obj, ev) =>
173 svgVisual.URL = _resPath + "/images/World.svg";
177 svgVisual.URL = _resPath + "/images/Mail.svg";
179 Tizen.Log.Debug("NUI", "svg button clicked!");
182 contentLayout.AddChild(svgButton, new TableView.CellPosition(1, 1));
184 //////////////////////////////////////////////////////////////////////
185 // make AnimatedImage visual test
186 VisualView VisualView2 = new VisualView();
187 VisualView2.WidthResizePolicy = ResizePolicyType.FillToParent;
188 VisualView2.HeightResizePolicy = ResizePolicyType.FillToParent;
189 VisualView2.BackgroundColor = Color.Blue;
190 contentLayout.AddChild(VisualView2, new TableView.CellPosition(2, 0));
192 gifVisual = new AnimatedImageVisual();
193 gifVisual.URL = _resPath + "/images/dog-anim.gif";
194 gifVisual.Size = new Size2D(200, 200);
195 gifVisual.SizePolicy = new Vector2(1, 1);
196 gifVisual.Position = new Position2D(0, 0);
197 gifVisual.PositionPolicy = new Vector2(1, 1);
198 gifVisual.Origin = Visual.AlignType.TopBegin;
199 gifVisual.AnchorPoint = Visual.AlignType.TopBegin;
200 VisualView2.AddVisual("gif_visual", gifVisual);
202 PushButton gifButton = new PushButton();
203 gifButton.LabelText = "AnimatedImage Visual Test";
204 gifButton.Name = ("gif_visual_test");
205 gifButton.AnchorPoint = AnchorPoint.Center;
206 gifButton.WidthResizePolicy = ResizePolicyType.FillToParent;
207 gifButton.HeightResizePolicy = ResizePolicyType.FillToParent;
208 gifButton.Clicked += (obj, ev) =>
210 Tizen.Log.Debug("NUI", "gif button clicked!");
214 gifVisual.URL = _resPath + "/images/dali-logo-anim.gif";
218 gifVisual.URL = _resPath + "/images/echo.gif";
222 contentLayout.AddChild(gifButton, new TableView.CellPosition(2, 1));
227 private void StartTransition(bool activate)
232 _animation.Finished += OnTransitionFinished;
237 AnimatorVisual grow = new AnimatorVisual();
238 grow.AlphaFunction = "LINEAR";
241 grow.Target = "icon_visual1";
242 grow.PropertyIndex = "Size";
243 grow.DestinationValue = new Size2D(200, 200);
244 _animation = _contentView.AnimateVisual(grow);
248 AnimatorVisual shrink = new AnimatorVisual();
249 shrink.AlphaFunction = "LINEAR";
250 shrink.StartTime = 0;
251 shrink.EndTime = 1000;
252 shrink.Target = "icon_visual1";
253 shrink.PropertyIndex = "Size";
254 shrink.DestinationValue = new Size2D(50, 50);
255 _animation = _contentView.AnimateVisual(shrink);
260 _animation.Finished += OnTransitionFinished;
261 _transitionInProgress = true;
265 private void OnTransitionFinished(object sender, EventArgs e)
267 _transitionInProgress = false;
270 _animation.Finished += OnTransitionFinished;
277 /// The main entry point for the application.
280 static void _Main(string[] args)
282 Example example = new Example();