Revert "[Tizen] fix LineWrap GET error"
[platform/core/csapi/nui.git] / NUISamples / NUISamples / NUISamples.TizenTV / examples / visual-animation-test.cs
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 using System;
19 using System.Runtime.InteropServices;
20 using Tizen.NUI;
21 using Tizen.NUI.UIComponents;
22 using Tizen.NUI.BaseComponents;
23 using Tizen.NUI.Constants;
24
25 namespace VisaulAnimationExample
26 {
27     class Example : NUIApplication
28     {
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
35
36         private Animation _animation1;
37         private bool _transitionInProgress = false;
38         private int cnt1, cnt2;
39
40         private SVGVisual svgVisual;
41         private AnimatedImageVisual gifVisual;
42         private ImageVisual _icon;
43
44         protected override void OnCreate()
45         {
46             base.OnCreate();
47             Initialize();
48         }
49
50         public void Initialize()
51         {
52             Window window = Window.Instance;
53             window.BackgroundColor = Color.White;
54
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);
63
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);
72
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));
81
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";
89
90             _icon = new ImageVisual();
91             _icon.URL = _resPath + "/images/application-icon-0.png";
92             _icon.DepthIndex = 1;
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);
102
103             contentLayout.AddChild(_contentView, new TableView.CellPosition(0, 0));
104
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) =>
111             {
112                 _active = !_active;
113                 StartTransition(_active);
114                 return true;
115             };
116             _shadowButton.WidthResizePolicy = ResizePolicyType.FillToParent;
117             _shadowButton.HeightResizePolicy = ResizePolicyType.FillToParent;
118             contentLayout.AddChild(_shadowButton, new TableView.CellPosition(0, 1));
119
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);
135
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));
143
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);
153
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) =>
161             {
162                 cnt1++;
163                 if (cnt1 % 2 == 0)
164                 {
165                     svgVisual.URL = _resPath + "/images/World.svg";
166                 }
167                 else
168                 {
169                     svgVisual.URL = _resPath + "/images/Mail.svg";
170                 }
171                 Tizen.Log.Debug("NUI", "svg button clicked!");
172                 return true;
173             };
174             contentLayout.AddChild(svgButton, new TableView.CellPosition(1, 1));
175
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));
183
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);
193
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) =>
201             {
202                 Tizen.Log.Debug("NUI", "gif button clicked!");
203                 cnt2++;
204                 int gifNum = cnt2 % 15;
205                 gifVisual.URL = _resPath + "/images/anim-gif/" + gifNum + ".gif";
206                 gifButton.LabelText = "file:" + gifNum + ".gif";
207                 return true;
208             };
209             contentLayout.AddChild(gifButton, new TableView.CellPosition(2, 1));
210         }
211
212         private void StartTransition(bool activate)
213         {
214             if (_animation1)
215             {
216                 _animation1.Stop();
217                 _animation1.Finished += OnTransitionFinished1;
218             }
219
220             if (activate)
221             {
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();
225             }
226             else
227             {
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();
231             }
232
233             if (_animation1)
234             {
235                 _animation1.Finished += OnTransitionFinished1;
236                 _transitionInProgress = true;
237                 _animation1.Play();
238             }
239         }
240         private void OnTransitionFinished1(object sender, EventArgs e)
241         {
242             _transitionInProgress = false;
243             if (_animation1)
244             {
245                 _animation1.Finished += OnTransitionFinished1;
246                 _animation1.Reset();
247             }
248         }
249
250
251         /// <summary>
252         /// The main entry point for the application.
253         /// </summary>
254         [STAThread]
255         static void _Main(string[] args)
256         {
257             Example example = new Example();
258             example.Run(args);
259         }
260
261
262     }
263 }