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"; //for tizen
34 //private const string _resPath = "./res"; //for ubuntu
36 private Animation _animation1;
37 private bool _transitionInProgress = false;
38 private int cnt1, cnt2;
40 private SVGVisual svgVisual;
41 private AnimatedImageVisual gifVisual;
42 private ImageVisual _icon;
44 protected override void OnCreate()
50 public void Initialize()
52 Window window = Window.Instance;
53 window.BackgroundColor = Color.White;
55 TableView titleLayout = new TableView(2, 1);
56 titleLayout.Name = ("TitleLayout");
57 titleLayout.PivotPoint = PivotPoint.TopLeft;
58 titleLayout.Position2D = new Position2D(10, 10);
59 titleLayout.Size2D = new Size2D((int)(window.Size.Width * 0.9f), (int)(window.Size.Height * 0.9f));
60 titleLayout.SetCellPadding(new Size2D(10, 10));
61 titleLayout.BackgroundColor = Color.Cyan;
62 window.Add(titleLayout);
64 _title = new TextLabel("Visual Transition / SVG / AGIF Example");
65 _title.Name = ("Title");
66 _title.SetStyleName("Title");
67 _title.WidthResizePolicy = ResizePolicyType.FillToParent;
68 _title.HeightResizePolicy = ResizePolicyType.UseNaturalSize;
69 _title.HorizontalAlignment = HorizontalAlignment.Center;
70 titleLayout.AddChild(_title, new TableView.CellPosition(0, 0));
71 titleLayout.SetFitHeight(0);
73 TableView contentLayout = new TableView(3, 2);
74 contentLayout.Name = ("ContentLayout");
75 contentLayout.WidthResizePolicy = ResizePolicyType.FillToParent;
76 contentLayout.HeightResizePolicy = ResizePolicyType.FillToParent;
77 contentLayout.PivotPoint = PivotPoint.TopLeft;
78 contentLayout.SetCellPadding(new Size2D(10, 10));
79 contentLayout.BackgroundColor = Color.Magenta;
80 titleLayout.AddChild(contentLayout, new TableView.CellPosition(1, 0));
82 //////////////////////////////////////////////////////////////////////
83 // Create a conttent view
84 _contentView = new VisualView();
85 _contentView.WidthResizePolicy = ResizePolicyType.SizeRelativeToParent;
86 _contentView.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
87 //_contentView.Size2D = new Size2D(250, 250);
88 _contentView.BackgroundImage = _resPath + "/images/background-blocks.jpg";
90 _icon = new ImageVisual();
91 _icon.URL = _resPath + "/images/application-icon-0.png";
93 _icon.Size = new Size2D(50, 50);
94 _icon.SizePolicy = VisualTransformPolicyType.Absolute;
95 _icon.Position = new Position2D(5, 5);
96 _icon.PositionPolicy = VisualTransformPolicyType.Absolute;
97 _icon.Origin = Visual.AlignType.TopBegin;
98 _icon.AnchorPoint = Visual.AlignType.TopBegin;
99 _icon.MixColor = new Color(0, 1, 0, 0.5f);
100 _icon.Opacity = 0.5f;
101 _contentView.AddVisual("icon_visual1", _icon);
103 contentLayout.AddChild(_contentView, new TableView.CellPosition(0, 0));
105 _shadowButton = new PushButton();
106 _shadowButton.LabelText = "Toggle Transition";
107 _shadowButton.Name = ("ToggleTransition");
108 _shadowButton.ParentOrigin = ParentOrigin.Center;
109 _shadowButton.PivotPoint = PivotPoint.Center;
110 _shadowButton.Clicked += (obj, ev) =>
113 StartTransition(_active);
116 _shadowButton.WidthResizePolicy = ResizePolicyType.FillToParent;
117 _shadowButton.HeightResizePolicy = ResizePolicyType.FillToParent;
118 contentLayout.AddChild(_shadowButton, new TableView.CellPosition(0, 1));
120 //////////////////////////////////////////////////////////////////////
121 // make NPatch visual test
122 NPatchVisual npatch1 = new NPatchVisual();
123 npatch1.URL = _resPath + "/images/gallery-2.jpg";
124 npatch1.Size = new Size2D(400, 400);
125 npatch1.SizePolicy = VisualTransformPolicyType.Absolute;
126 npatch1.Position = new Position2D(400, 0);
127 npatch1.PositionPolicy = VisualTransformPolicyType.Absolute;
128 npatch1.Origin = Visual.AlignType.TopBegin;
129 npatch1.AnchorPoint = Visual.AlignType.TopBegin;
130 npatch1.Border = new Rectangle(100, 100, 100, 100);
131 npatch1.DepthIndex = 2;
132 npatch1.MixColor = new Color(1, 0, 0, 1);
133 npatch1.Opacity = 0.5f;
134 _contentView.AddVisual("npatchImageVisual1", npatch1);
136 //////////////////////////////////////////////////////////////////////
137 // make SVG visual test
138 VisualView VisualView1 = new VisualView();
139 VisualView1.WidthResizePolicy = ResizePolicyType.FillToParent;
140 VisualView1.HeightResizePolicy = ResizePolicyType.FillToParent;
141 VisualView1.BackgroundColor = Color.Black;
142 contentLayout.AddChild(VisualView1, new TableView.CellPosition(1, 0));
144 svgVisual = new SVGVisual();
145 svgVisual.URL = _resPath + "/images/Kid1.svg";
146 svgVisual.Size = new Size2D(300, 300);
147 svgVisual.SizePolicy = VisualTransformPolicyType.Absolute;
148 svgVisual.Position = new Position2D(0, 0);
149 svgVisual.PositionPolicy = VisualTransformPolicyType.Absolute;
150 svgVisual.Origin = Visual.AlignType.TopBegin;
151 svgVisual.AnchorPoint = Visual.AlignType.TopBegin;
152 VisualView1.AddVisual("svg_visual1", svgVisual);
154 PushButton svgButton = new PushButton();
155 svgButton.LabelText = "SVG Visual Test";
156 svgButton.Name = ("svg_visual_test");
157 svgButton.PivotPoint = PivotPoint.Center;
158 svgButton.WidthResizePolicy = ResizePolicyType.FillToParent;
159 svgButton.HeightResizePolicy = ResizePolicyType.FillToParent;
160 svgButton.Clicked += (obj, ev) =>
165 svgVisual.URL = _resPath + "/images/World.svg";
169 svgVisual.URL = _resPath + "/images/Mail.svg";
171 Tizen.Log.Debug("NUI", "svg button clicked!");
174 contentLayout.AddChild(svgButton, new TableView.CellPosition(1, 1));
176 //////////////////////////////////////////////////////////////////////
177 // make AnimatedImage visual test
178 VisualView VisualView2 = new VisualView();
179 VisualView2.WidthResizePolicy = ResizePolicyType.FillToParent;
180 VisualView2.HeightResizePolicy = ResizePolicyType.FillToParent;
181 VisualView2.BackgroundColor = Color.Blue;
182 contentLayout.AddChild(VisualView2, new TableView.CellPosition(2, 0));
184 gifVisual = new AnimatedImageVisual();
185 gifVisual.URL = _resPath + "/images/dog-anim.gif";
186 gifVisual.Size = new Size2D(200, 200);
187 gifVisual.SizePolicy = VisualTransformPolicyType.Absolute;
188 gifVisual.Position = new Position2D(0, 0);
189 gifVisual.PositionPolicy = VisualTransformPolicyType.Absolute;
190 gifVisual.Origin = Visual.AlignType.TopBegin;
191 gifVisual.AnchorPoint = Visual.AlignType.TopBegin;
192 VisualView2.AddVisual("gif_visual", gifVisual);
194 PushButton gifButton = new PushButton();
195 gifButton.LabelText = "AnimatedImage Visual Test";
196 gifButton.Name = ("gif_visual_test");
197 gifButton.PivotPoint = PivotPoint.Center;
198 gifButton.WidthResizePolicy = ResizePolicyType.FillToParent;
199 gifButton.HeightResizePolicy = ResizePolicyType.FillToParent;
200 gifButton.Clicked += (obj, ev) =>
202 Tizen.Log.Debug("NUI", "gif button clicked!");
204 int gifNum = cnt2 % 15;
205 gifVisual.URL = _resPath + "/images/anim-gif/" + gifNum + ".gif";
206 gifButton.LabelText = "file:" + gifNum + ".gif";
209 contentLayout.AddChild(gifButton, new TableView.CellPosition(2, 1));
212 private void StartTransition(bool activate)
217 _animation1.Finished += OnTransitionFinished1;
222 _contentView.AnimateVisualAdd(_icon, "Size", new Size2D(150, 150), 0, 1000, AlphaFunction.BuiltinFunctions.Linear);
223 _contentView.AnimateVisualAdd(_icon, "Position", new Position2D(40, 40), 0, 1000);
224 _animation1 = _contentView.AnimateVisualAddFinish();
228 _contentView.AnimateVisualAdd(_icon, "Size", new Position2D(50, 50), 0, 1000, AlphaFunction.BuiltinFunctions.Linear);
229 _contentView.AnimateVisualAdd(_icon, "Position", new Position2D(5, 5), 0, 1000);
230 _animation1 = _contentView.AnimateVisualAddFinish();
235 _animation1.Finished += OnTransitionFinished1;
236 _transitionInProgress = true;
240 private void OnTransitionFinished1(object sender, EventArgs e)
242 _transitionInProgress = false;
245 _animation1.Finished += OnTransitionFinished1;
252 /// The main entry point for the application.
255 static void _Main(string[] args)
257 Example example = new Example();