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