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 Example : NUIApplication
29 private VisualView _contentView;
30 private TextLabel _title;
31 private PushButton _shadowButton;
32 private bool _active = false;
33 private const string _resPath = "/home/owner/apps_rw/NUISamples.TizenTV/res";
35 private Animation _animation;
36 private bool _transitionInProgress = false;
37 private int cnt1, cnt2;
39 private SVGVisual svgVisual;
40 private AnimatedImageVisual gifVisual;
42 public Example() : base()
46 public Example(string stylesheet) : base(stylesheet)
50 public Example(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
54 protected override void OnCreate()
60 public void Initialize()
62 Window window = Window.Instance;
63 window.BackgroundColor = Color.White;
65 TableView titleLayout = new TableView(2, 1);
66 titleLayout.Name = ("TitleLayout");
67 titleLayout.AnchorPoint = AnchorPoint.TopLeft;
68 titleLayout.Position2D = new Position2D(10, 10);
69 titleLayout.Size2D = new Size2D((int)(window.Size.Width * 0.9f), (int)(window.Size.Height * 0.9f));
70 titleLayout.SetCellPadding(new Size2D(10, 10));
71 titleLayout.BackgroundColor = Color.Cyan;
72 window.GetDefaultLayer().Add(titleLayout);
74 _title = new TextLabel("Visual Transition / SVG / AGIF Example");
75 _title.Name = ("Title");
76 _title.SetStyleName("Title");
77 _title.WidthResizePolicy = ResizePolicyType.FillToParent;
78 _title.HeightResizePolicy = ResizePolicyType.UseNaturalSize;
79 _title.HorizontalAlignment = HorizontalAlignment.Center;
80 titleLayout.AddChild(_title, new TableView.CellPosition(0, 0));
81 titleLayout.SetFitHeight(0);
83 TableView contentLayout = new TableView(3, 2);
84 contentLayout.Name = ("ContentLayout");
85 contentLayout.WidthResizePolicy = ResizePolicyType.FillToParent;
86 contentLayout.HeightResizePolicy = ResizePolicyType.FillToParent;
87 contentLayout.AnchorPoint = AnchorPoint.TopLeft;
88 contentLayout.SetCellPadding(new Size2D(10, 10));
89 contentLayout.BackgroundColor = Color.Magenta;
90 titleLayout.AddChild(contentLayout, new TableView.CellPosition(1, 0));
92 //////////////////////////////////////////////////////////////////////
93 // Create a conttent view
94 _contentView = new VisualView();
95 _contentView.WidthResizePolicy = ResizePolicyType.SizeRelativeToParent;
96 _contentView.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
97 //_contentView.Size2D = new Size2D(250, 250);
98 _contentView.BackgroundImage = _resPath + "/images/background-blocks.jpg";
100 ImageVisual _icon = new ImageVisual();
101 _icon.URL = _resPath + "/images/application-icon-0.png";
102 _icon.DepthIndex = 1;
103 _icon.Size = new Size2D(50, 50);
104 _icon.SizePolicy = VisualTransformPolicyType.Absolute;
105 _icon.Position = new Position2D(5, 5);
106 _icon.PositionPolicy = VisualTransformPolicyType.Absolute;
107 _icon.Origin = Visual.AlignType.TopBegin;
108 _icon.AnchorPoint = Visual.AlignType.TopBegin;
109 _icon.MixColor = new Color(0, 1, 0, 0.5f);
110 _icon.Opacity = 0.5f;
111 _contentView.AddVisual("icon_visual1", _icon);
113 contentLayout.AddChild(_contentView, new TableView.CellPosition(0, 0));
115 _shadowButton = new PushButton();
116 _shadowButton.LabelText = "Toggle Transition";
117 _shadowButton.Name = ("ToggleTransition");
118 _shadowButton.ParentOrigin = ParentOrigin.Center;
119 _shadowButton.AnchorPoint = AnchorPoint.Center;
120 _shadowButton.Clicked += (obj, ev) =>
123 StartTransition(_active);
126 _shadowButton.WidthResizePolicy = ResizePolicyType.FillToParent;
127 _shadowButton.HeightResizePolicy = ResizePolicyType.FillToParent;
128 contentLayout.AddChild(_shadowButton, new TableView.CellPosition(0, 1));
130 //////////////////////////////////////////////////////////////////////
131 // make NPatch visual test
132 NPatchVisual npatch1 = new NPatchVisual();
133 npatch1.URL = _resPath + "/images/gallery-2.jpg";
134 npatch1.Size = new Size2D(400, 400);
135 npatch1.SizePolicy = VisualTransformPolicyType.Absolute;
136 npatch1.Position = new Position2D(400, 0);
137 npatch1.PositionPolicy = VisualTransformPolicyType.Absolute;
138 npatch1.Origin = Visual.AlignType.TopBegin;
139 npatch1.AnchorPoint = Visual.AlignType.TopBegin;
140 npatch1.Border = new Rectangle(100, 100, 100, 100);
141 npatch1.DepthIndex = 2;
142 npatch1.MixColor = new Color(1, 0, 0, 1);
143 npatch1.Opacity = 0.5f;
144 _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 = VisualTransformPolicyType.Absolute;
158 svgVisual.Position = new Position2D(0, 0);
159 svgVisual.PositionPolicy = VisualTransformPolicyType.Absolute;
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 = VisualTransformPolicyType.Absolute;
198 gifVisual.Position = new Position2D(0, 0);
199 gifVisual.PositionPolicy = VisualTransformPolicyType.Absolute;
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));
227 private void StartTransition(bool activate)
232 _animation.Finished += OnTransitionFinished;
237 VisualAnimator grow = new VisualAnimator();
238 grow.AlphaFunction = AlphaFunction.BuiltinFunctions.Linear;
241 grow.Target = "icon_visual1";
242 grow.PropertyIndex = "Size";
243 grow.DestinationValue = new Size2D(200, 200);
244 _animation = _contentView.VisualAnimate(grow);
248 VisualAnimator shrink = new VisualAnimator();
249 shrink.AlphaFunction = AlphaFunction.BuiltinFunctions.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.VisualAnimate(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();