Manual merge for nui v0.2.35.
[platform/core/csapi/nui.git] / NUISamples / NUISamples / NUISamples.TizenTV / examples / test1.cs
1 // Copyright (c) 2017 Samsung Electronics Co., Ltd.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15
16 using System;
17 using Tizen.NUI;
18 using Tizen.NUI.UIComponents;
19 using System.Collections.Generic;
20
21
22 // 1) sibling order test
23 namespace Test1
24 {
25     class Example : NUIApplication
26     {
27         public Example() : base()
28         {
29         }
30
31         public Example(string stylesheet) : base(stylesheet)
32         {
33         }
34
35         public Example(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
36         {
37         }
38
39         protected override void OnCreate()
40         {
41             base.OnCreate();
42             Initialize();
43         }
44
45         Stage _stage;
46         StyleManager _style;
47
48         public void Initialize()
49         {
50             _stage = Stage.Instance;
51             _stage.BackgroundColor = Color.White;
52
53             // 1) sibling order test
54             SiblingTest();
55             // 2) text visual test
56             dali_VisualBase_Creation_test();
57
58             // 3) visual creation test
59             VisualTest2();
60
61             _style = StyleManager.Get();
62             //_style.StyleChanged += _style_StyleChanged;
63             _style.StyleChanged += (obj, e) =>
64             {
65                 Tizen.Log.Debug("NUI", "in stylechanged.. C#side..\n");
66                 //flag = true;
67             };
68
69             _style.ApplyTheme("/home/owner/apps_rw/NUISamples.TizenTV/res/json/date-picker-theme.json");
70             Tizen.Log.Debug("NUI", "#### 1) first change!");
71
72
73             AnimatePath_1();
74         }
75
76         private void _style_StyleChanged(object sender, StyleManager.StyleChangedEventArgs e)
77         {
78             Tizen.Log.Debug("NUI", "style changed event handler comes");
79         }
80
81         public void SiblingTest()
82         {
83             View _prev = null;
84             Position2D _myPos = new Position2D(100, 100);
85             List<View> list_view = new List<View>();
86             TextLabel _txt = new TextLabel();
87
88             for (int i = 0; i < 10; i++)
89             {
90                 View _view0 = new PushButton();
91                 PushButton _view = _view0 as PushButton;
92
93                 _view.Name = "sibling" + i;
94                 _view.MinimumSize = new Size2D(100, 50);
95                 _view.LabelText = "sibling" + i;
96                 _view.ParentOrigin = ParentOrigin.TopLeft;
97                 _view.AnchorPoint = AnchorPoint.TopLeft;
98                 _view.Position2D = _myPos + new Position2D(20 * i, 10 * i);
99                 _view.Clicked += (sender, ee) =>
100                 {
101                     View curr = sender as View;
102                     Tizen.Log.Debug("NUI", "clicked curr view name=" + curr.Name + "  sibling=" + curr.SiblingOrder);
103                     curr.RaiseToTop();
104                     if (_prev)
105                     {
106                         _prev.LowerToBottom();
107                         Tizen.Log.Debug("NUI", "raise on top is called!curr sibling=" + curr.SiblingOrder + " prev name=" + _prev.Name + " sibling=" + _prev.SiblingOrder);
108                     }
109                     _prev = curr;
110                     _txt.Text = "on top: " + curr.Name + ", sibling order=" + curr.SiblingOrder;
111
112                     _style.ApplyTheme("/home/owner/apps_rw/NUISamples.TizenTV/res/json/style-example-theme-one.json");
113                     Tizen.Log.Debug("NUI", "#### 2) second change!");
114
115                     return true;
116                 };
117                 list_view.Add(_view);
118             }
119
120             for (int i = 0; i < 10; i++)
121             {
122                 _stage.GetDefaultLayer().Add(list_view[i]);
123                 Tizen.Log.Debug("NUI", list_view[i].Name + "'s sibling order=" + list_view[i].SiblingOrder);
124             }
125
126             _txt.ParentOrigin = ParentOrigin.TopLeft;
127             _txt.AnchorPoint = AnchorPoint.TopLeft;
128             _txt.Text = "on top: sibling#, sibling order=?";
129             _txt.Position2D = _myPos + new Position2D(-50, 200);
130             _txt.TextColor = Color.Blue;
131             _stage.GetDefaultLayer().Add(_txt);
132
133         }
134
135         public class VisualTest : CustomView
136         {
137             private int TextVisualPropertyIndex = -1;
138             private VisualBase _textVisual;
139             private string _string;
140
141             public VisualTest() : base(typeof(VisualTest).Name, CustomViewBehaviour.RequiresKeyboardNavigationSupport)
142             {
143             }
144             public string TextVisual
145             {
146                 get
147                 {
148                     return _string;
149                 }
150                 set
151                 {
152                     _string = value;
153
154                     TextVisualPropertyIndex = RegisterProperty("textvisualtest", new PropertyValue("textvisualtest"), PropertyAccessMode.ReadWrite);
155
156                     PropertyMap textVisual = new PropertyMap();
157                     textVisual.Add(Visual.Property.Type, new PropertyValue((int)Visual.Type.Text))
158                         .Add(TextVisualProperty.Text, new PropertyValue(_string))
159                         .Add(TextVisualProperty.TextColor, new PropertyValue(Color.Blue))
160                         .Add(TextVisualProperty.PointSize, new PropertyValue(10))
161                         .Add(TextVisualProperty.HorizontalAlignment, new PropertyValue("CENTER"))
162                         .Add(TextVisualProperty.VerticalAlignment, new PropertyValue("CENTER"));
163                     _textVisual = VisualFactory.Get().CreateVisual(textVisual);
164                     RegisterVisual(TextVisualPropertyIndex, _textVisual);
165                     _textVisual.DepthIndex = TextVisualPropertyIndex;
166                 }
167             }
168         }
169
170         //when use belowing testcase, Time is out and this case is BLOCK
171         public void dali_VisualBase_Creation_test()
172         {
173             try
174             {
175                 Tizen.Log.Debug("NUI", "##### start! ######");
176
177                 VisualTest _visualTest = new VisualTest();
178                 _visualTest.TextVisual = "Hello NUI Text Visual!";
179                 _visualTest.ParentOrigin = ParentOrigin.TopLeft;
180                 _visualTest.AnchorPoint = AnchorPoint.TopLeft;
181                 _visualTest.Size2D = new Size2D(600, 200);
182                 _visualTest.Position2D = new Position2D(50, 400);
183                 _visualTest.BackgroundColor = Color.Yellow;
184                 _stage.GetDefaultLayer().Add(_visualTest);
185             }
186             catch (Exception e)
187             {
188                 Tizen.Log.Error("NUI", "##### Caught Exception" + e.ToString());
189                 throw new System.InvalidOperationException("visual test error!!!");
190             }
191         }
192
193         public void VisualTest2()
194         {
195             try
196             {
197                 Tizen.Log.Debug("NUI", "##### VisualTest2() start! ######");
198
199                 VisualFactory visualfactory = VisualFactory.Instance;
200                 PropertyMap textMap1 = new PropertyMap();
201                 textMap1.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Text));
202                 textMap1.Insert(TextVisualProperty.Text, new PropertyValue("Hello"));
203                 textMap1.Insert(TextVisualProperty.PointSize, new PropertyValue(10.0f));
204
205                 PropertyMap textMap2 = new PropertyMap();
206                 VisualBase textVisual1 = visualfactory.CreateVisual(textMap1);
207                 textVisual1.Creation = textMap2;
208             }
209             catch (Exception e)
210             {
211                 Tizen.Log.Error("NUI", "Caught Exception" + e.ToString());
212                 throw new System.InvalidOperationException("visual test2 error!!!");
213                 //LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
214                 //Assert.IsTrue(e is ArgumentException, "Argument Exception Not Recieved");
215             }
216         }
217
218         //[Property("AUTHOR", "Feng Jin, feng16.jin@samsung.com")]
219         public void AnimatePath_1()
220         {
221             Tizen.Log.Debug("NUI", "#### 1) animate path test !");
222             /* TEST CODE */
223             View view = new View();
224             view.ParentOrigin = ParentOrigin.TopLeft;
225             view.AnchorPoint = AnchorPoint.TopLeft;
226             view.MinimumSize = new Size2D(100, 100);
227             view.BackgroundColor = Color.Red;
228             _stage.GetDefaultLayer().Add(view);
229
230             Position position0 = new Position(200.0f, 200.0f, 0.0f);
231             Position position1 = new Position(300.0f, 300.0f, 0.0f);
232             Position position2 = new Position(400.0f, 400.0f, 0.0f);
233
234             Path path = new Path();
235             path.AddPoint(position0);
236             path.AddPoint(position1);
237             path.AddPoint(position2);
238             //Control points for first segment
239             path.AddControlPoint(new Vector3(39.0f, 90.0f, 0.0f));
240             path.AddControlPoint(new Vector3(56.0f, 119.0f, 0.0f));
241             //Control points for second segment
242             path.AddControlPoint(new Vector3(78.0f, 120.0f, 0.0f));
243             path.AddControlPoint(new Vector3(93.0f, 104.0f, 0.0f));
244
245             Animation animation = new Animation();
246             animation.AnimatePath(view, path, Vector3.XAxis, 0, 5000, new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear));
247             animation.Play();
248             Vector3 position = new Vector3();
249             Vector3 tangent = new Vector3();
250
251             path.Sample(0.0f, position, tangent);
252             Rotation rotation = new Rotation(new Radian(new Degree(0.0f)), tangent);
253             Tizen.Log.Debug("NUI", "################  progress = 0! ");
254             Tizen.Log.Debug("NUI", "position=(" + position.X + "," + position.Y + "," + position.Z + ")");
255             Tizen.Log.Debug("NUI", "view position=(" + view.Position.X + "," + view.Position.Y + "," + view.Position.Z + ")");
256             Tizen.Log.Debug("NUI", "view position=(" + view.PositionX + "," + view.PositionY + "," + view.PositionZ + ")");
257             Tizen.Log.Debug("NUI", "view cur position=(" + view.CurrentPosition.X + "," + view.CurrentPosition.Y + "," + view.CurrentPosition.Z + ")");
258             Tizen.Log.Debug("NUI", "tangent=(" + tangent.X + "," + tangent.Y + "," + tangent.Z + ")");
259             Tizen.Log.Debug("NUI", "angle between=" + Rotation.AngleBetween(view.Orientation, rotation) + "  view orientation length=" + view.Orientation.Length() + "  rotation length=" + rotation.Length());
260             //Assert.AreEqual(position.X, view.PositionX, "The actor's PositionX of is not correct");
261             //Assert.AreEqual(position.Y, actor.PositionY, "The actor's PositionY of is not correct");
262             //Assert.AreEqual(position.Z, actor.PositionZ, "The actor's PositionZ of is not correct");
263             //Assert.IsTrue(rotation.Equals(actor.Orientation));
264             //await Task.Delay(250);
265             path.Sample(0.25f, position, tangent);
266             rotation = new Rotation(new Radian(new Degree(0.0f)), tangent);
267             Tizen.Log.Debug("NUI", "################  progress = 0.25! ");
268             Tizen.Log.Debug("NUI", "position=(" + position.X + "," + position.Y + "," + position.Z + ")");
269             Tizen.Log.Debug("NUI", "view position=(" + view.Position.X + "," + view.Position.Y + "," + view.Position.Z + ")");
270             Tizen.Log.Debug("NUI", "view position=(" + view.PositionX + "," + view.PositionY + "," + view.PositionZ + ")");
271             Tizen.Log.Debug("NUI", "view cur position=(" + view.CurrentPosition.X + "," + view.CurrentPosition.Y + "," + view.CurrentPosition.Z + ")");
272             Tizen.Log.Debug("NUI", "tangent=(" + tangent.X + "," + tangent.Y + "," + tangent.Z + ")");
273             Tizen.Log.Debug("NUI", "angle between=" + Rotation.AngleBetween(view.Orientation, rotation) + "  view orientation length=" + view.Orientation.Length() + "  rotation length=" + rotation.Length());
274             //Assert.AreEqual(position.X, actor.PositionX, "The PositionX of actor is not correct");
275             //Assert.AreEqual(position.Y, actor.PositionY, "The PositionY of actor is not correct");
276             //Assert.AreEqual(position.Z, actor.PositionZ, "The PositionZ of actor is not correct");
277             //Assert.IsTrue(rotation.Equals(actor.Orientation));
278             //await Task.Delay(500);
279             path.Sample(0.75f, position, tangent);
280             rotation = new Rotation(new Radian(new Degree(0.0f)), tangent);
281             Tizen.Log.Debug("NUI", "################  progress = 0.75! ");
282             Tizen.Log.Debug("NUI", "position=(" + position.X + "," + position.Y + "," + position.Z + ")");
283             Tizen.Log.Debug("NUI", "view position=(" + view.Position.X + "," + view.Position.Y + "," + view.Position.Z + ")");
284             Tizen.Log.Debug("NUI", "view position=(" + view.PositionX + "," + view.PositionY + "," + view.PositionZ + ")");
285             Tizen.Log.Debug("NUI", "view cur position=(" + view.CurrentPosition.X + "," + view.CurrentPosition.Y + "," + view.CurrentPosition.Z + ")");
286             Tizen.Log.Debug("NUI", "tangent=(" + tangent.X + "," + tangent.Y + "," + tangent.Z + ")");
287             Tizen.Log.Debug("NUI", "angle between=" + Rotation.AngleBetween(view.Orientation, rotation) + "  view orientation length=" + view.Orientation.Length() + "  rotation length=" + rotation.Length());
288             //Assert.AreEqual(position.X, actor.PositionX, "The PositionX of actor is not correct here");
289             //Assert.AreEqual(position.Y, actor.PositionY, "The PositionY of actor is not correct here");
290             //Assert.AreEqual(position.Z, actor.PositionZ, "The PositionZ of actor is not correct here");
291             //Assert.IsTrue(rotation.Equals(actor.Orientation));
292
293             path.Sample(1.0f, position, tangent);
294             rotation = new Rotation(new Radian(new Degree(0.0f)), tangent);
295             Tizen.Log.Debug("NUI", "################  progress = 1.0! ");
296             Tizen.Log.Debug("NUI", "position=(" + position.X + "," + position.Y + "," + position.Z + ")");
297             Tizen.Log.Debug("NUI", "view position=(" + view.Position.X + "," + view.Position.Y + "," + view.Position.Z + ")");
298             Tizen.Log.Debug("NUI", "view position=(" + view.PositionX + "," + view.PositionY + "," + view.PositionZ + ")");
299             Tizen.Log.Debug("NUI", "view cur position=(" + view.CurrentPosition.X + "," + view.CurrentPosition.Y + "," + view.CurrentPosition.Z + ")");
300             Tizen.Log.Debug("NUI", "tangent=(" + tangent.X + "," + tangent.Y + "," + tangent.Z + ")");
301             Tizen.Log.Debug("NUI", "angle between=" + Rotation.AngleBetween(view.Orientation, rotation) + "  view orientation length=" + view.Orientation.Length() + "  rotation length=" + rotation.Length());
302
303
304             Tizen.Log.Debug("NUI", "#### 2) animate path test end!");
305         }
306
307
308
309
310         static void _Main(string[] args)
311         {
312             Example example = new Example();
313             example.Run(args);
314         }
315     }
316 }