2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.Runtime.InteropServices;
22 namespace MyCSharpExample
26 private string _myOwnName;
27 public int _myCurrentValue;
34 public string MyOwnName
47 class MyButton : PushButton
49 private string _myOwnName;
50 public int _myCurrentValue;
57 public string MyOwnName
72 private string _myOwnName;
73 public int _myCurrentValue;
80 public string MyOwnName
95 private Dali.Application _application;
97 public Example(Dali.Application application)
99 _application = application;
100 Console.WriteLine("1) InitSignal connection count = " + _application.InitSignal().GetConnectionCount());
102 _application.Initialized += Initialize;
103 Console.WriteLine("2) InitSignal connection count = " + _application.InitSignal().GetConnectionCount());
106 public void Initialize(object source, NUIApplicationInitEventArgs e)
109 NavigationPropertiesTests();
115 CustomViewPropertyTest();
121 RectanglePaddingClassTest();
131 public void NavigationPropertiesTests()
133 Console.WriteLine("");
134 Console.WriteLine("### [1] NavigationPropertiesTests START");
136 View view = new View();
137 View leftView, rightView, upView, downView, tmpView;
139 leftView = new View();
140 leftView.Name = "leftView";
141 rightView = new View();
142 rightView.Name = "rightView";
144 upView.Name = "upView";
145 downView = new View();
146 downView.Name = "downView";
148 Stage.Instance.Add(leftView);
149 Stage.Instance.Add(rightView);
150 Stage.Instance.Add(upView);
151 Stage.Instance.Add(downView);
153 view.LeftFocusableView = leftView;
154 tmpView = view.LeftFocusableView;
155 if (string.Compare(tmpView.Name, "leftView") == 0)
157 Console.WriteLine("Passed: LeftFocusedView = " + tmpView.Name);
161 Console.WriteLine("Failed: LeftFocusedView = " + tmpView.Name);
164 view.RightFocusableView = rightView;
165 tmpView = view.RightFocusableView;
166 if (string.Compare(tmpView.Name, "rightView") == 0)
168 Console.WriteLine("Passed: RightFocusedView = " + tmpView.Name);
172 Console.WriteLine("Failed: RightFocusedView = " + tmpView.Name);
175 Stage.Instance.Add(view);
177 view.UpFocusableView = upView;
178 tmpView = view.UpFocusableView;
179 if (string.Compare(tmpView.Name, "upView") == 0)
181 Console.WriteLine("Passed: UpFocusedView = " + tmpView.Name);
185 Console.WriteLine("Failed: UpFocusedView = " + tmpView.Name);
188 view.DownFocusableView = downView;
189 tmpView = view.DownFocusableView;
190 if (string.Compare(tmpView.Name, "downView") == 0)
192 Console.WriteLine("Passed: DownFocusedView = " + tmpView.Name);
196 Console.WriteLine("Failed: DownFocusedView = " + tmpView.Name);
199 Stage.Instance.Remove(leftView);
200 tmpView = view.LeftFocusableView;
203 Console.WriteLine("Passed: NULL LeftFocusedView");
207 Console.WriteLine("Failed: LeftFocusedView = " + tmpView.Name);
210 Console.WriteLine("### [1] NavigationPropertiesTests END");
213 public void OperatorTests()
215 Console.WriteLine("");
216 Console.WriteLine("### [2] OperatorTests START");
217 Actor actor = new Actor();
218 Actor differentActor = new Actor();
219 Actor actorSame = actor;
220 Actor nullActor = null;
222 // test the true operator
225 Console.WriteLine("BaseHandle Operator true (actor) : test passed ");
229 Console.WriteLine("BaseHandle Operator true (actor): test failed ");
232 Actor parent = actor.GetParent();
236 Console.WriteLine("Handle with Empty body :failed ");
240 Console.WriteLine("Valid with Empty body :passed ");
243 actor.Add(differentActor);
245 // here we test two different C# objects, which on the native side have the same body/ ref-object
246 if (actor == differentActor.GetParent())
248 Console.WriteLine("actor == differentActor.GetParent() :passed ");
252 Console.WriteLine("actor == differentActor.GetParent() :failed ");
255 if (differentActor == differentActor.GetParent())
257 Console.WriteLine("differentActor == differentActor.GetParent() :failed ");
261 Console.WriteLine("differentActor == differentActor.GetParent() :passed ");
266 Console.WriteLine("BaseHandle Operator true (nullActor) : test failed ");
270 Console.WriteLine("BaseHandle Operator true (nullActor): test passed ");
276 Console.WriteLine("BaseHandle Operator !(actor) : test failed ");
280 Console.WriteLine("BaseHandle Operator !(actor): test passed ");
285 Console.WriteLine("BaseHandle Operator !(nullActor) : test passed ");
289 Console.WriteLine("BaseHandle Operator !(nullActor): test failed ");
292 // Note: operator false only used inside & operator
293 // test equality operator ==
294 if (actor == actorSame)
296 Console.WriteLine("BaseHandle Operator (actor == actorSame) : test passed");
300 Console.WriteLine("BaseHandle Operator (actor == actorSame) : test failed");
303 if (actor == differentActor)
305 Console.WriteLine("BaseHandle Operator (actor == differentActor) : test failed");
309 Console.WriteLine("BaseHandle Operator (actor == differentActor) : test passed");
312 if (actor == nullActor)
314 Console.WriteLine("BaseHandle Operator (actor == nullActor) : test failed");
318 Console.WriteLine("BaseHandle Operator (actor == nullActor) : test passed");
321 if (nullActor == nullActor)
323 Console.WriteLine("BaseHandle Operator (nullActor == nullActor) : test passed");
327 Console.WriteLine("BaseHandle Operator (nullActor == nullActor) : test failed");
331 if (actor || actorSame)
333 Console.WriteLine("BaseHandle Operator (actor || actorSame) : test passed");
337 Console.WriteLine("BaseHandle Operator (actor || actorSame) : test failed");
340 if (actor || nullActor)
342 Console.WriteLine("BaseHandle Operator (actor || nullActor) : test passed");
346 Console.WriteLine("BaseHandle Operator (actor || nullActor) : test failed");
349 if (nullActor || nullActor)
351 Console.WriteLine("BaseHandle Operator (nullActor || nullActor) : test failed");
355 Console.WriteLine("BaseHandle Operator (nullActor || nullActor) : test passed");
359 if (actor && actorSame)
361 Console.WriteLine("BaseHandle Operator (actor && actorSame) : test passed");
365 Console.WriteLine("BaseHandle Operator (actor && actorSame) : test failed");
368 if (actor && nullActor)
370 Console.WriteLine("BaseHandle Operator (actor && nullActor) : test failed");
374 Console.WriteLine("BaseHandle Operator (actor && nullActor) : test passed");
377 if (nullActor && nullActor)
379 Console.WriteLine("BaseHandle Operator (nullActor && nullActor) : test failed");
383 Console.WriteLine("BaseHandle Operator (nullActor && nullActor) : test passed");
386 Console.WriteLine("### [2] OperatorTests END");
390 public void CustomViewPropertyTest()
392 Console.WriteLine("");
393 Console.WriteLine("### [3] CustomViewPropertyTest START");
395 // Create a Spin control
396 Spin spin = new Spin();
398 // Background property
399 Property.Map background = new Property.Map();
400 background.Add(Dali.Constants.Visual.Property.Type, new Property.Value((int)Dali.Constants.Visual.Type.Color))
401 .Add(Dali.Constants.ColorVisualProperty.MixColor, new Property.Value(Color.Red));
402 spin.Background = background;
404 background = spin.Background;
405 Vector4 backgroundColor = new Vector4();
406 background.Find(Dali.Constants.ColorVisualProperty.MixColor).Get(backgroundColor);
407 if (backgroundColor == Color.Red)
409 Console.WriteLine("Custom View Background property : test passed");
413 Console.WriteLine("Custom View Background property : test failed");
416 // BackgroundColor property
417 spin.BackgroundColor = Color.Yellow;
418 if (spin.BackgroundColor == Color.Yellow)
420 Console.WriteLine("Custom View BackgroundColor property : test passed");
424 Console.WriteLine("Custom View BackgroundColor property : test failed");
427 // BackgroundImage property
428 spin.BackgroundImage = "background-image.jpg";
429 if (spin.BackgroundImage == "background-image.jpg")
431 Console.WriteLine("Custom View BackgroundImage property : test passed");
435 Console.WriteLine("Custom View BackgroundImage property : test failed");
438 // StyleName property
439 spin.StyleName = "MyCustomStyle";
440 if (spin.StyleName == "MyCustomStyle")
442 Console.WriteLine("Custom View StyleName property : test passed");
446 Console.WriteLine("Custom View StyleName property : test failed");
449 Console.WriteLine("### [3] CustomViewPropertyTest END");
454 public void ActorHandleTest()
456 Console.WriteLine("");
457 Console.WriteLine("### [4] ActorHandleTest START");
459 Handle handle = new Handle();
460 int myPropertyIndex = handle.RegisterProperty("myProperty", new Property.Value(10.0f), Property.AccessMode.READ_WRITE);
461 float myProperty = 0.0f;
462 handle.GetProperty(myPropertyIndex).Get(ref myProperty);
463 Console.WriteLine("myProperty value: " + myProperty);
465 int myPropertyIndex2 = handle.RegisterProperty("myProperty2", new Property.Value(new Size(5.0f, 5.0f)), Property.AccessMode.READ_WRITE);
466 Size myProperty2 = new Size(0.0f, 0.0f);
467 handle.GetProperty(myPropertyIndex2).Get(myProperty2);
468 Console.WriteLine("myProperty2 value: " + myProperty2.W + ", " + myProperty2.H);
470 Actor actor = new Actor();
471 actor.Size = new Position(200.0f, 200.0f, 0.0f);
472 actor.Name = "MyActor";
473 Console.WriteLine("Actor id: {0}", actor.GetId());
474 Console.WriteLine("Actor size: " + actor.Size.X + ", " + actor.Size.Y);
475 Console.WriteLine("Actor name: " + actor.Name);
477 Stage stage = Stage.GetCurrent();
478 stage.BackgroundColor = Color.White;
479 Size stageSize = stage.Size;
480 Console.WriteLine("Stage size: " + stageSize.W + ", " + stageSize.H);
483 TextLabel text = new TextLabel("Hello World");
484 text.ParentOrigin = NDalic.ParentOriginCenter;
485 text.AnchorPoint = NDalic.AnchorPointCenter;
486 text.HorizontalAlignment = "CENTER";
489 Console.WriteLine("Text label text: " + text.Text);
491 Console.WriteLine("Text label point size: " + text.PointSize);
492 text.PointSize = 32.0f;
493 Console.WriteLine("Text label new point size: " + text.PointSize);
495 Console.WriteLine("### [4] ActorHandleTest END");
501 public void RectanglePaddingClassTest()
503 Console.WriteLine("");
504 Console.WriteLine("### [5] RectanglePaddingClassTest START");
506 using (Rectangle r1 = new Rectangle(2, 5, 20, 30))
508 Console.WriteLine(" Created " + r1);
509 Console.WriteLine(" IsEmpty() = " + r1.IsEmpty());
510 Console.WriteLine(" Left = " + r1.Left());
511 Console.WriteLine(" Right = " + r1.Right());
512 Console.WriteLine(" Top = " + r1.Top());
513 Console.WriteLine(" Bottom = " + r1.Bottom());
514 Console.WriteLine(" Area = " + r1.Area());
517 Console.WriteLine(" *************************");
519 using (Rectangle r2 = new Rectangle(2, 5, 20, 30))
521 Console.WriteLine(" Created " + r2);
522 r2.Set(1, 1, 40, 40);
523 Console.WriteLine(" IsEmpty() = " + r2.IsEmpty());
524 Console.WriteLine(" Left = " + r2.Left());
525 Console.WriteLine(" Right = " + r2.Right());
526 Console.WriteLine(" Top = " + r2.Top());
527 Console.WriteLine(" Bottom = " + r2.Bottom());
528 Console.WriteLine(" Area = " + r2.Area());
531 Console.WriteLine(" *************************");
533 Rectangle r3 = new Rectangle(10, 10, 20, 20);
534 Rectangle r4 = new Rectangle(10, 10, 20, 20);
538 Console.WriteLine("r3 == r4");
542 Console.WriteLine("r3 != r4");
545 r4 = new Rectangle(12, 10, 20, 20);
549 Console.WriteLine("r3 == r4");
553 Console.WriteLine("r3 != r4");
556 PaddingType p1 = new PaddingType(10.5f, 10.7f, 20.8f, 20.8f);
557 PaddingType p2 = new PaddingType(10.5f, 10.7f, 20.8f, 20.8f);
561 Console.WriteLine("p1 == p2");
565 Console.WriteLine("p1 != p2");
568 p2 = new PaddingType(12.0f, 10.7f, 20.2f, 20.0f);
572 Console.WriteLine("p1 == p2");
576 Console.WriteLine("p1 != p2");
578 Console.WriteLine("### [5] RectanglePaddingClassTest END");
583 public void SizePositionTest()
585 Console.WriteLine("");
586 Console.WriteLine("### [6] SizePositionTest START");
588 Size Size = new Size(100, 50);
589 Console.WriteLine(" Created " + Size);
590 Console.WriteLine(" Size x = " + Size.W + ", y = " + Size.H);
591 Size += new Size(20, 20);
592 Console.WriteLine(" Size x = " + Size.W + ", y = " + Size.H);
595 Console.WriteLine(" Size width = " + Size.W + ", height = " + Size.H);
597 Console.WriteLine(" *************************");
598 Position Position = new Position(20, 100, 50);
599 Console.WriteLine(" Created " + Position);
600 Console.WriteLine(" Position x = " + Position.X + ", y = " + Position.Y + ", z = " + Position.Z);
601 Position += new Position(20, 20, 20);
602 Console.WriteLine(" Position x = " + Position.X + ", y = " + Position.Y + ", z = " + Position.Z);
606 Console.WriteLine(" Position width = " + Position.X + ", height = " + Position.Y + ", depth = " + Position.Z);
607 Position parentOrigin = new Dali.Position(NDalic.ParentOriginBottomRight);
608 Console.WriteLine(" parentOrigin x = " + parentOrigin.X + ", y = " + parentOrigin.Y + ", z = " + parentOrigin.Z);
610 Console.WriteLine(" *************************");
611 Color color = new Color(20, 100, 50, 200);
612 Console.WriteLine(" Created " + color);
613 Console.WriteLine(" Color R = " + color.R + ", G = " + color.G + ", B = " + color.B + ", A = " + color.A);
614 color += new Color(20, 20, 20, 20);
615 Console.WriteLine(" Color R = " + color.R + ", G = " + color.G + ", B = " + color.B + ", A = " + color.A);
620 Console.WriteLine(" Color r = " + color.R + ", g = " + color.G + ", b = " + color.B + ", a = " + color.A);
622 Console.WriteLine("### [6] SizePositionTest END");
626 public void ViewDownCastTest()
628 Console.WriteLine("");
629 Console.WriteLine("### [7] ViewDownCastTest START");
631 View container = new View();
632 container.Position = new Position(-800.0f, -800.0f, 0.0f);
633 Stage.GetCurrent().Add(container);
635 // Test downcast for native control
636 TextLabel myLabel = new TextLabel();
637 myLabel.Name = "MyLabelName";
638 myLabel.Text = "MyText";
640 Console.WriteLine("myLabel.Name = " + myLabel.Name + ", Text = " + myLabel.Text);
642 container.Add(myLabel);
644 Actor myLabelActor = container.FindChildByName("MyLabelName");
647 TextLabel newLabel = View.DownCast<TextLabel>(myLabelActor);
650 Console.WriteLine("Downcast to TextLabel successful: newLabel Name = " + newLabel.Name + ", Text = " + newLabel.Text);
654 Console.WriteLine("Downcast to TextLabel failed!");
658 // Test downcast for class directly inherited from View
659 MyView myView = new MyView();
660 myView.Name = "MyViewName";
661 myView.MyOwnName = "MyOwnViewName";
662 myView._myCurrentValue = 5;
664 Console.WriteLine("myView.Name = " + myView.Name + ", MyOwnName = " + myView.MyOwnName + ", myCurrentValue = " + myView._myCurrentValue);
666 container.Add(myView);
668 Actor myViewActor = container.FindChildByName("MyViewName");
671 MyView newView = View.DownCast<MyView>(myViewActor);
674 Console.WriteLine("Downcast to MyView successful: newView Name = " + newView.Name + ", MyOwnName = " + newView.MyOwnName + ", myCurrentValue = " + newView._myCurrentValue);
678 Console.WriteLine("Downcast to MyView failed!");
682 // Test downcast for class directly inherited from native control
683 MyButton myButton = new MyButton();
684 myButton.Name = "MyButtonName";
685 myButton.MyOwnName = "MyOwnViewName";
686 myButton.LabelText = "MyLabelText";
687 myButton._myCurrentValue = 5;
689 Console.WriteLine("myButton.Name = " + myButton.Name + ", MyOwnName = " + myButton.MyOwnName + ", LabelText = " + myButton.LabelText + ", myCurrentValue = " + myButton._myCurrentValue);
691 container.Add(myButton);
693 Actor myButtonActor = container.FindChildByName("MyButtonName");
696 MyButton newButton = View.DownCast<MyButton>(myButtonActor);
699 Console.WriteLine("Downcast to MyButton successful: newButton Name = " + newButton.Name + ", MyOwnName = " + newButton.MyOwnName + ", LabelText = " + myButton.LabelText + ", myCurrentValue = " + newButton._myCurrentValue);
703 Console.WriteLine("Downcast to MyButton failed!");
707 // Test downcast for a CustomView
708 Spin spin = new Spin();
709 spin.Name = "SpinName";
710 spin.MaxValue = 8888;
712 Console.WriteLine("spin.Name = " + spin.Name + ", MaxValue = " + spin.MaxValue);
716 Actor spinActor = container.FindChildByName("SpinName");
719 Spin newSpin = View.DownCast<Spin>(spinActor);
722 Console.WriteLine("Downcast to Spin successful: newSpin Name = " + newSpin.Name + ", MaxValue = " + newSpin.MaxValue);
726 Console.WriteLine("Downcast to Spin failed!");
730 // Test downcast for class inherited from a CustomView
731 MySpin mySpin = new MySpin();
732 mySpin.Name = "MySpinName";
733 mySpin.MyOwnName = "MyOwnSpinName";
734 mySpin.MaxValue = 8888;
735 mySpin._myCurrentValue = 5;
737 Console.WriteLine("mySpin.Name = " + mySpin.Name + ", MyOwnName = " + mySpin.MyOwnName + ", MaxValue = " + mySpin.MaxValue + ", currentValue = " + mySpin._myCurrentValue);
739 container.Add(mySpin);
741 Actor mySpinActor = container.FindChildByName("MySpinName");
744 MySpin newSpin = View.DownCast<MySpin>(mySpinActor);
747 Console.WriteLine("Downcast to MySpin successful: newSpin Name = " + newSpin.Name + ", MyOwnName = " + newSpin.MyOwnName + ", MaxValue = " + newSpin.MaxValue + ", currentValue = " + newSpin._myCurrentValue);
751 Console.WriteLine("Downcast to MySpin failed!");
755 Console.WriteLine("### [7] ViewDownCastTest END");
758 public void MainLoop()
760 _application.MainLoop();
764 /// The main entry point for the application.
767 static void Main(string[] args)
769 Console.WriteLine("Hello World");
771 Example example = new Example(Application.NewApplication());