1 // Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Collections.Generic;
21 // 1) sibling order test
24 class Example : NUIApplication
26 public Example() : base()
30 public Example(string stylesheet) : base(stylesheet)
34 public Example(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
38 protected override void OnCreate()
47 public void Initialize()
49 _stage = Stage.Instance;
50 _stage.BackgroundColor = Color.White;
52 // 1) sibling order test
54 // 2) text visual test
55 dali_VisualBase_Creation_test();
57 // 3) visual creation test
60 _style = StyleManager.Get();
61 //_style.StyleChanged += _style_StyleChanged;
62 _style.StyleChanged += (obj, e) =>
\r
64 Tizen.Log.Debug("NUI", "in stylechanged.. C#side..\n");
\r
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
75 private void _style_StyleChanged(object sender, StyleManager.StyleChangedEventArgs e)
\r
77 Tizen.Log.Debug("NUI", "style changed event handler comes");
\r
80 public void SiblingTest()
83 Position2D _myPos = new Position2D(100, 100);
84 List<View> list_view = new List<View>();
85 TextLabel _txt = new TextLabel();
87 for (int i = 0; i < 10; i++)
89 View _view0 = new PushButton();
90 PushButton _view = _view0 as PushButton;
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) =>
100 View curr = sender as View;
101 Tizen.Log.Debug("NUI", "clicked curr view name=" + curr.Name + " sibling=" + curr.SiblingOrder);
105 _prev.LowerToBottom();
106 Tizen.Log.Debug("NUI", "raise on top is called!curr sibling=" + curr.SiblingOrder + " prev name=" + _prev.Name + " sibling=" + _prev.SiblingOrder);
109 _txt.Text = "on top: " + curr.Name + ", sibling order=" + curr.SiblingOrder;
\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
116 list_view.Add(_view);
119 for (int i = 0; i < 10; i++)
121 _stage.GetDefaultLayer().Add(list_view[i]);
122 Tizen.Log.Debug("NUI", list_view[i].Name + "'s sibling order=" + list_view[i].SiblingOrder);
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
134 public class VisualTest : CustomView
\r
136 private int TextVisualPropertyIndex = -1;
\r
137 private VisualBase _textVisual;
\r
138 private string _string;
\r
140 public VisualTest() : base(typeof(VisualTest).Name, CustomViewBehaviour.RequiresKeyboardNavigationSupport)
\r
143 public string TextVisual
\r
153 TextVisualPropertyIndex = RegisterProperty("textvisualtest", new PropertyValue("textvisualtest"), PropertyAccessMode.ReadWrite);
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
169 //when use belowing testcase, Time is out and this case is BLOCK
\r
170 public void dali_VisualBase_Creation_test()
\r
174 Tizen.Log.Debug("NUI", "##### start! ######");
\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
185 catch (Exception e)
\r
187 Tizen.Log.Error("NUI", "##### Caught Exception" + e.ToString());
\r
188 throw new System.InvalidOperationException("visual test error!!!");
\r
192 public void VisualTest2()
196 Tizen.Log.Debug("NUI", "##### VisualTest2() start! ######");
\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
204 PropertyMap textMap2 = new PropertyMap();
\r
205 VisualBase textVisual1 = visualfactory.CreateVisual(textMap1);
\r
206 textVisual1.Creation = textMap2;
\r
208 catch (Exception e)
\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
217 //[Property("AUTHOR", "Feng Jin, feng16.jin@samsung.com")]
\r
218 public void AnimatePath_1()
\r
220 Tizen.Log.Debug("NUI", "#### 1) animate path test !");
\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
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
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
244 Animation animation = new Animation();
\r
245 animation.AnimatePath(view, path, Vector3.XAxis, 0, 5000, new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear));
\r
247 Vector3 position = new Vector3();
\r
248 Vector3 tangent = new Vector3();
\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
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
303 Tizen.Log.Debug("NUI", "#### 2) animate path test end!");
\r
309 static void _Main(string[] args)
311 Example example = new Example();