Revert "[Tizen] fix LineWrap GET error"
[platform/core/csapi/nui.git] / NUISamples / NUISamples / NUISamples.TizenTV / examples / visual-animation-test2.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 Example2 : NUIApplication
28     {
29         private VisualView _contentView1;
30         private VisualView _contentView2;
31         private VisualView _contentView3;
32         private TextLabel _title;
33         private PushButton _shadowButton1;
34         private PushButton _shadowButton2;
35         private PushButton _shadowButton3;
36         private bool _active1 = false;
37         private bool _active2 = false;
38         private bool _active3 = false;
39         private const string _resPath = "/home/owner/apps_rw/NUISamples.TizenTV/res";
40
41         private Animation _animation;
42         private bool _transitionInProgress = false;
43
44         public Example2() : base()
45         {
46         }
47
48         public Example2(string stylesheet) : base(stylesheet)
49         {
50         }
51
52         public Example2(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
53         {
54         }
55
56         protected override void OnCreate()
57         {
58             base.OnCreate();
59             Initialize();
60         }
61
62         public void Initialize()
63         {
64             Window window = Window.Instance;
65             window.BackgroundColor = Color.White;
66
67             TableView titleLayout = new TableView(2, 1);
68             titleLayout.Name = ("TitleLayout");
69             titleLayout.PivotPoint = PivotPoint.TopLeft;
70             titleLayout.Position2D = new Position2D(10, 10);
71             titleLayout.Size2D = new Size2D((int)(window.Size.Width * 0.9f), (int)(window.Size.Height * 0.9f));
72             titleLayout.SetCellPadding(new Size2D(10, 10));
73             titleLayout.BackgroundColor = Color.Cyan;
74             window.Add(titleLayout);
75
76             _title = new TextLabel("Visual Transition Example");
77             _title.Name = ("Title");
78             _title.SetStyleName("Title");
79             _title.WidthResizePolicy = ResizePolicyType.FillToParent;
80             _title.HeightResizePolicy = ResizePolicyType.UseNaturalSize;
81             _title.HorizontalAlignment = HorizontalAlignment.Center;
82             titleLayout.AddChild(_title, new TableView.CellPosition(0, 0));
83             titleLayout.SetFitHeight(0);
84
85             TableView contentLayout = new TableView(3, 2);
86             contentLayout.Name = ("ContentLayout");
87             contentLayout.WidthResizePolicy = ResizePolicyType.FillToParent;
88             contentLayout.HeightResizePolicy = ResizePolicyType.FillToParent;
89             contentLayout.PivotPoint = PivotPoint.TopLeft;
90             contentLayout.SetCellPadding(new Size2D(10, 10));
91             contentLayout.BackgroundColor = Color.Magenta;
92             titleLayout.AddChild(contentLayout, new TableView.CellPosition(1, 0));
93
94             //////////////////////////////////////////////////////////////////////
95             // make visual position animation
96             _contentView1 = new VisualView();
97             _contentView1.WidthResizePolicy = ResizePolicyType.SizeRelativeToParent;
98             _contentView1.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
99             //_contentView.Size2D = new Size2D(250, 250);
100             _contentView1.BackgroundImage = _resPath + "/images/background-blocks.jpg";
101
102             ImageVisual _icon = new ImageVisual();
103             _icon.URL = _resPath + "/images/application-icon-0.png";
104             _icon.DepthIndex = 1;
105             _icon.Size = new Size2D(50, 50);
106             _icon.SizePolicy = VisualTransformPolicyType.Absolute;
107             _icon.Position = new Position2D(5, 5);
108             _icon.PositionPolicy = VisualTransformPolicyType.Absolute;
109             _icon.Origin = Visual.AlignType.TopBegin;
110             _icon.AnchorPoint = Visual.AlignType.TopBegin;
111             _icon.MixColor = new Color(0, 1, 0, 0.5f);
112             _icon.Opacity = 0.5f;
113             _contentView1.AddVisual("icon_visual1", _icon);
114
115             contentLayout.AddChild(_contentView1, new TableView.CellPosition(0, 0));
116
117             _shadowButton1 = new PushButton();
118             _shadowButton1.LabelText = "Toggle Transition Position";
119             _shadowButton1.Name = ("ToggleTransition");
120             _shadowButton1.ParentOrigin = ParentOrigin.Center;
121             _shadowButton1.PivotPoint = PivotPoint.Center;
122             _shadowButton1.Clicked += (obj, ev) =>
123             {
124                 _active1 = !_active1;
125                 StartTransition(_contentView1, _icon, "Position", _active1);
126                 return true;
127             };
128             _shadowButton1.WidthResizePolicy = ResizePolicyType.FillToParent;
129             _shadowButton1.HeightResizePolicy = ResizePolicyType.FillToParent;
130             contentLayout.AddChild(_shadowButton1, new TableView.CellPosition(0, 1));
131
132             //////////////////////////////////////////////////////////////////////
133             // make visual opacity animation
134             _contentView2 = new VisualView();
135             _contentView2.WidthResizePolicy = ResizePolicyType.SizeRelativeToParent;
136             _contentView2.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
137             //_contentView.Size2D = new Size2D(250, 250);
138             _contentView2.BackgroundImage = _resPath + "/images/background-blocks.jpg";
139
140             ImageVisual _icon2 = new ImageVisual();
141             _icon2.URL = _resPath + "/images/application-icon-0.png";
142             _icon2.DepthIndex = 1;
143             _icon2.Size = new Size2D(50, 50);
144             _icon2.SizePolicy = VisualTransformPolicyType.Absolute;
145             _icon2.Position = new Position2D(5, 5);
146             _icon2.PositionPolicy = VisualTransformPolicyType.Absolute;
147             _icon2.Origin = Visual.AlignType.TopBegin;
148             _icon2.AnchorPoint = Visual.AlignType.TopBegin;
149             _icon2.MixColor = new Color(0, 1, 0, 0.5f);
150             _icon2.Opacity = 0.5f;
151             _contentView2.AddVisual("icon_visual2", _icon2);
152
153             contentLayout.AddChild(_contentView2, new TableView.CellPosition(1, 0));
154
155             _shadowButton2 = new PushButton();
156             _shadowButton2.LabelText = "Toggle Transition Opacity";
157             _shadowButton2.Name = ("ToggleTransition");
158             _shadowButton2.ParentOrigin = ParentOrigin.Center;
159             _shadowButton2.PivotPoint = PivotPoint.Center;
160             _shadowButton2.Clicked += (obj, ev) =>
161             {
162                 _active2 = !_active2;
163                 StartTransition(_contentView2, _icon2, "Opacity", _active2);
164                 return true;
165             };
166             _shadowButton2.WidthResizePolicy = ResizePolicyType.FillToParent;
167             _shadowButton2.HeightResizePolicy = ResizePolicyType.FillToParent;
168             contentLayout.AddChild(_shadowButton2, new TableView.CellPosition(1, 1));
169
170             //////////////////////////////////////////////////////////////////////
171             // make AnimatedImage visual test
172             _contentView3 = new VisualView();
173             _contentView3.WidthResizePolicy = ResizePolicyType.SizeRelativeToParent;
174             _contentView3.HeightResizePolicy = ResizePolicyType.SizeRelativeToParent;
175             //_contentView.Size2D = new Size2D(250, 250);
176             _contentView3.BackgroundImage = _resPath + "/images/background-blocks.jpg";
177
178             ImageVisual _icon3 = new ImageVisual();
179             _icon3.URL = _resPath + "/images/application-icon-0.png";
180             _icon3.DepthIndex = 1;
181             _icon3.Size = new Size2D(50, 50);
182             _icon3.SizePolicy = VisualTransformPolicyType.Absolute;
183             _icon3.Position = new Position2D(5, 5);
184             _icon3.PositionPolicy = VisualTransformPolicyType.Absolute;
185             _icon3.Origin = Visual.AlignType.TopBegin;
186             _icon3.AnchorPoint = Visual.AlignType.TopBegin;
187             _icon3.MixColor = new Color(0, 1, 0, 0.5f);
188             _icon3.Opacity = 0.5f;
189             _contentView3.AddVisual("icon_visual3", _icon3);
190
191             contentLayout.AddChild(_contentView3, new TableView.CellPosition(2, 0));
192
193             _shadowButton3 = new PushButton();
194             _shadowButton3.LabelText = "Toggle Transition MixColor";
195             _shadowButton3.Name = ("ToggleTransition");
196             _shadowButton3.ParentOrigin = ParentOrigin.Center;
197             _shadowButton3.PivotPoint = PivotPoint.Center;
198             _shadowButton3.Clicked += (obj, ev) =>
199             {
200                 _active3 = !_active3;
201                 StartTransition(_contentView3, _icon3, "MixColor", _active3);
202                 return true;
203             };
204             _shadowButton3.WidthResizePolicy = ResizePolicyType.FillToParent;
205             _shadowButton3.HeightResizePolicy = ResizePolicyType.FillToParent;
206             contentLayout.AddChild(_shadowButton3, new TableView.CellPosition(2, 1));
207         }
208
209         private void StartTransition(VisualView view, VisualMap target, string property, bool activate)
210         {
211             if (_animation)
212             {
213                 _animation.Stop();
214                 _animation.Finished += OnTransitionFinished;
215             }
216
217             if (activate)
218             {
219                 if (property == "Position")
220                 {
221                     _animation = view.AnimateVisual(target, property, new Position2D(20, 20), 0, 1000, AlphaFunction.BuiltinFunctions.Linear, new Position2D(40, 40));
222                 }
223                 else if (property == "Opacity")
224                 {
225                     _animation = view.AnimateVisual(target, property, 0.0f, 0, 1000, AlphaFunction.BuiltinFunctions.Linear);
226                 }
227                 else if (property == "MixColor")
228                 {
229                     _animation = view.AnimateVisual(target, property, Color.Green, 0, 1000, AlphaFunction.BuiltinFunctions.Linear);
230                 }
231             }
232             else
233             {
234                 if (property == "Position")
235                 {
236                     _animation = view.AnimateVisual(target, property, new Position2D(5, 5), 0, 1000);
237                 }
238                 else if (property == "Opacity")
239                 {
240                     _animation = view.AnimateVisual(target, property, 1.0f, 0, 1000);
241                 }
242                 else if (property == "MixColor")
243                 {
244                     _animation = view.AnimateVisual(target, property, Color.Red, 0, 1000);
245                 }
246             }
247
248             if (_animation)
249             {
250                 _animation.Finished += OnTransitionFinished;
251                 _transitionInProgress = true;
252                 _animation.Play();
253             }
254         }
255         private void OnTransitionFinished(object sender, EventArgs e)
256         {
257             _transitionInProgress = false;
258             if (_animation)
259             {
260                 _animation.Finished += OnTransitionFinished;
261                 _animation.Reset();
262             }
263         }
264
265
266         /// <summary>
267         /// The main entry point for the application.
268         /// </summary>
269         [STAThread]
270         static void _Main(string[] args)
271         {
272             Example example = new Example();
273             example.Run(args);
274         }
275
276
277     }
278 }