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 Tizen.NUI.UIComponents;
19 using Tizen.NUI.BaseComponents;
20 using System.Collections.Generic;
23 // 1) sibling order test
26 class Example : NUIApplication
28 public Example() : base()
32 public Example(string stylesheet) : base(stylesheet)
36 public Example(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
40 protected override void OnCreate()
49 public void Initialize()
51 _window = Window.Instance;
52 _window.BackgroundColor = Color.White;
54 // 1) sibling order test
56 // 2) text visual test
57 dali_VisualBase_Creation_test();
59 // 3) visual creation test
62 _style = StyleManager.Get();
63 //_style.StyleChanged += _style_StyleChanged;
64 _style.StyleChanged += (obj, e) =>
66 Tizen.Log.Debug("NUI", "in stylechanged.. C#side..\n");
70 _style.ApplyTheme("/home/owner/apps_rw/NUISamples.TizenTV/res/json/date-picker-theme.json");
71 Tizen.Log.Debug("NUI", "#### 1) first change!");
77 private void _style_StyleChanged(object sender, StyleManager.StyleChangedEventArgs e)
79 Tizen.Log.Debug("NUI", "style changed event handler comes");
82 public void SiblingTest()
85 Position2D _myPos = new Position2D(100, 100);
86 List<View> list_view = new List<View>();
87 TextLabel _txt = new TextLabel();
89 for (int i = 0; i < 10; i++)
91 View _view0 = new PushButton();
92 PushButton _view = _view0 as PushButton;
94 _view.Name = "sibling" + i;
95 _view.MinimumSize = new Size2D(100, 50);
96 _view.LabelText = "sibling" + i;
97 _view.ParentOrigin = ParentOrigin.TopLeft;
98 _view.PivotPoint = PivotPoint.TopLeft;
99 _view.Position2D = _myPos + new Position2D(20 * i, 10 * i);
100 _view.Clicked += (sender, ee) =>
102 View curr = sender as View;
103 Tizen.Log.Debug("NUI", "clicked curr view name=" + curr.Name + " sibling=" + curr.SiblingOrder);
107 _prev.LowerToBottom();
108 Tizen.Log.Debug("NUI", "raise on top is called!curr sibling=" + curr.SiblingOrder + " prev name=" + _prev.Name + " sibling=" + _prev.SiblingOrder);
111 _txt.Text = "on top: " + curr.Name + ", sibling order=" + curr.SiblingOrder;
113 _style.ApplyTheme("/home/owner/apps_rw/NUISamples.TizenTV/res/json/style-example-theme-one.json");
114 Tizen.Log.Debug("NUI", "#### 2) second change!");
118 list_view.Add(_view);
121 for (int i = 0; i < 10; i++)
123 _window.Add(list_view[i]);
124 Tizen.Log.Debug("NUI", list_view[i].Name + "'s sibling order=" + list_view[i].SiblingOrder);
127 _txt.ParentOrigin = ParentOrigin.TopLeft;
128 _txt.PivotPoint = PivotPoint.TopLeft;
129 _txt.Text = "on top: sibling#, sibling order=?";
130 _txt.Position2D = _myPos + new Position2D(-50, 200);
131 _txt.TextColor = Color.Blue;
136 public class VisualTest : CustomView
138 private int TextVisualPropertyIndex = -1;
139 private VisualBase _textVisual;
140 private string _string;
142 public VisualTest() : base(typeof(VisualTest).Name, CustomViewBehaviour.RequiresKeyboardNavigationSupport)
145 public string TextVisual
155 TextVisualPropertyIndex = RegisterProperty("textvisualtest", new PropertyValue("textvisualtest"), PropertyAccessMode.ReadWrite);
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.Instance.CreateVisual(textVisual);
165 RegisterVisual(TextVisualPropertyIndex, _textVisual);
166 _textVisual.DepthIndex = TextVisualPropertyIndex;
171 //when use belowing testcase, Time is out and this case is BLOCK
172 public void dali_VisualBase_Creation_test()
176 Tizen.Log.Debug("NUI", "##### start! ######");
178 VisualTest _visualTest = new VisualTest();
179 _visualTest.TextVisual = "Hello NUI Text Visual!";
180 _visualTest.ParentOrigin = ParentOrigin.TopLeft;
181 _visualTest.PivotPoint = PivotPoint.TopLeft;
182 _visualTest.Size2D = new Size2D(600, 200);
183 _visualTest.Position2D = new Position2D(50, 400);
184 _visualTest.BackgroundColor = Color.Yellow;
185 _window.Add(_visualTest);
189 Tizen.Log.Error("NUI", "##### Caught Exception" + e.ToString());
190 throw new System.InvalidOperationException("visual test error!!!");
194 public void VisualTest2()
198 Tizen.Log.Debug("NUI", "##### VisualTest2() start! ######");
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));
206 PropertyMap textMap2 = new PropertyMap();
207 VisualBase textVisual1 = visualfactory.CreateVisual(textMap1);
208 textVisual1.Creation = textMap2;
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");
219 //[Property("AUTHOR", "Feng Jin, feng16.jin@samsung.com")]
220 public void AnimatePath_1()
222 Tizen.Log.Debug("NUI", "#### 1) animate path test !");
224 View view = new View();
225 view.ParentOrigin = ParentOrigin.TopLeft;
226 view.PivotPoint = PivotPoint.TopLeft;
227 view.MinimumSize = new Size2D(100, 100);
228 view.BackgroundColor = Color.Red;
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);
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));
246 Animation animation = new Animation();
247 animation.AnimatePath(view, path, Vector3.XAxis, 0, 5000, new AlphaFunction(AlphaFunction.BuiltinFunctions.Linear));
249 Vector3 position = new Vector3();
250 Vector3 tangent = new Vector3();
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));
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());
305 Tizen.Log.Debug("NUI", "#### 2) animate path test end!");
311 static void _Main(string[] args)
313 Example example = new Example();