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