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 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
96 delegate void CallbackDelegate(IntPtr appPtr); // void, void delgate
98 private Dali.Application _application;
100 public Example(Dali.Application application)
102 _application = application;
103 Console.WriteLine( "InitSignal connection count = " + _application.InitSignal().GetConnectionCount() );
105 _application.Initialized += Initialize;
106 Console.WriteLine( "InitSignal connection count = " + _application.InitSignal().GetConnectionCount() );
109 public void Initialize(object source, NUIApplicationInitEventArgs e)
111 NavigationPropertiesTests();
115 CustomViewPropertyTest();
117 Handle handle = new Handle();
118 int myPropertyIndex = handle.RegisterProperty("myProperty", new Property.Value(10.0f), Property.AccessMode.READ_WRITE);
119 float myProperty = 0.0f;
120 handle.GetProperty(myPropertyIndex).Get(ref myProperty);
121 Console.WriteLine( "myProperty value: " + myProperty );
123 int myPropertyIndex2 = handle.RegisterProperty("myProperty2", new Property.Value(new Size(5.0f, 5.0f)), Property.AccessMode.READ_WRITE);
124 Size myProperty2 = new Size(0.0f, 0.0f);
125 handle.GetProperty(myPropertyIndex2).Get(myProperty2);
126 Console.WriteLine( "myProperty2 value: " + myProperty2.W + ", " + myProperty2.H );
128 Actor actor = new Actor();
129 actor.Size = new Position(200.0f, 200.0f, 0.0f);
130 actor.Name = "MyActor";
132 Console.WriteLine("Actor id: {0}", actor.GetId());
133 Console.WriteLine("Actor size: " + actor.Size.X + ", " + actor.Size.Y);
134 Console.WriteLine("Actor name: " + actor.Name);
136 Stage stage = Stage.GetCurrent();
137 stage.BackgroundColor = Color.White;
138 Size stageSize = stage.Size;
139 Console.WriteLine("Stage size: " + stageSize.W + ", " + stageSize.H);
142 TextLabel text = new TextLabel("Hello Mono World");
143 text.ParentOrigin = NDalic.ParentOriginCenter;
144 text.AnchorPoint = NDalic.AnchorPointCenter;
145 text.HorizontalAlignment = "CENTER";
148 Console.WriteLine( "Text label text: " + text.Text );
150 Console.WriteLine( "Text label point size: " + text.PointSize );
151 text.PointSize = 32.0f;
152 Console.WriteLine( "Text label new point size: " + text.PointSize );
154 RectanglePaddingClassTest();
156 Console.WriteLine( " *************************" );
157 Size Size = new Size(100, 50);
158 Console.WriteLine( " Created " + Size );
159 Console.WriteLine( " Size x = " + Size.W + ", y = " + Size.H );
160 Size += new Size(20, 20);
161 Console.WriteLine( " Size x = " + Size.W + ", y = " + Size.H );
164 Console.WriteLine( " Size width = " + Size.W + ", height = " + Size.H );
166 Console.WriteLine( " *************************" );
167 Position Position = new Position(20, 100, 50);
168 Console.WriteLine( " Created " + Position );
169 Console.WriteLine( " Position x = " + Position.X + ", y = " + Position.Y + ", z = " + Position.Z );
170 Position += new Position(20, 20, 20);
171 Console.WriteLine( " Position x = " + Position.X + ", y = " + Position.Y + ", z = " + Position.Z );
175 Console.WriteLine( " Position width = " + Position.X + ", height = " + Position.Y + ", depth = " + Position.Z );
176 Position parentOrigin = new Dali.Position(NDalic.ParentOriginBottomRight);
177 Console.WriteLine( " parentOrigin x = " + parentOrigin.X + ", y = " + parentOrigin.Y + ", z = " + parentOrigin.Z );
179 Console.WriteLine( " *************************" );
180 Color color = new Color(20, 100, 50, 200);
181 Console.WriteLine( " Created " + color );
182 Console.WriteLine( " Color R = " + color.R + ", G = " + color.G + ", B = " + color.B + ", A = " + color.A );
183 color += new Color(20, 20, 20, 20);
184 Console.WriteLine( " Color R = " + color.R + ", G = " + color.G + ", B = " + color.B + ", A = " + color.A );
189 Console.WriteLine( " Color r = " + color.R + ", g = " + color.G + ", b = " + color.B + ", a = " + color.A );
194 public void RectanglePaddingClassTest()
196 using (Rectangle r1 = new Rectangle(2, 5, 20, 30))
198 Console.WriteLine( " Created " + r1 );
199 Console.WriteLine( " IsEmpty() = " + r1.IsEmpty() );
200 Console.WriteLine( " Left = " + r1.Left() );
201 Console.WriteLine( " Right = " + r1.Right() );
202 Console.WriteLine( " Top = " + r1.Top() );
203 Console.WriteLine( " Bottom = " + r1.Bottom() );
204 Console.WriteLine( " Area = " + r1.Area() );
207 Console.WriteLine( " *************************" );
209 using (Rectangle r2 = new Rectangle(2, 5, 20, 30))
211 Console.WriteLine( " Created " + r2 );
213 Console.WriteLine( " IsEmpty() = " + r2.IsEmpty() );
214 Console.WriteLine( " Left = " + r2.Left() );
215 Console.WriteLine( " Right = " + r2.Right() );
216 Console.WriteLine( " Top = " + r2.Top() );
217 Console.WriteLine( " Bottom = " + r2.Bottom() );
218 Console.WriteLine( " Area = " + r2.Area() );
221 Console.WriteLine( " *************************" );
223 Rectangle r3 = new Rectangle(10, 10, 20, 20);
224 Rectangle r4 = new Rectangle(10, 10, 20, 20);
228 Console.WriteLine("r3 == r4");
232 Console.WriteLine("r3 != r4");
235 r4 = new Rectangle(12, 10, 20, 20);
239 Console.WriteLine("r3 == r4");
243 Console.WriteLine("r3 != r4");
246 PaddingType p1 = new PaddingType(10.5f, 10.7f, 20.8f, 20.8f);
247 PaddingType p2 = new PaddingType(10.5f, 10.7f, 20.8f, 20.8f);
251 Console.WriteLine("p1 == p2");
255 Console.WriteLine("p1 != p2");
258 p2 = new PaddingType(12.0f, 10.7f, 20.2f, 20.0f);
262 Console.WriteLine("p1 == p2");
266 Console.WriteLine("p1 != p2");
270 public void NavigationPropertiesTests()
272 View view = new View();
273 View leftView, rightView, upView, downView, tmpView;
275 leftView = new View();
276 leftView.Name = "leftView";
277 rightView = new View();
278 rightView.Name = "rightView";
280 upView.Name = "upView";
281 downView = new View();
282 downView.Name = "downView";
284 Stage.Instance.Add(leftView);
285 Stage.Instance.Add(rightView);
286 Stage.Instance.Add(upView);
287 Stage.Instance.Add(downView);
289 view.LeftFocusableView = leftView;
290 tmpView = view.LeftFocusableView;
291 if (string.Compare(tmpView.Name, "leftView") == 0)
293 Console.WriteLine("Passed: LeftFocusedView = " + tmpView.Name);
297 Console.WriteLine("Failed: LeftFocusedView = " + tmpView.Name);
300 view.RightFocusableView = rightView;
301 tmpView = view.RightFocusableView;
302 if (string.Compare(tmpView.Name, "rightView") == 0)
304 Console.WriteLine("Passed: RightFocusedView = " + tmpView.Name);
308 Console.WriteLine("Failed: RightFocusedView = " + tmpView.Name);
311 Stage.Instance.Add(view);
313 view.UpFocusableView = upView;
314 tmpView = view.UpFocusableView;
315 if (string.Compare(tmpView.Name, "upView") == 0)
317 Console.WriteLine("Passed: UpFocusedView = " + tmpView.Name);
321 Console.WriteLine("Failed: UpFocusedView = " + tmpView.Name);
324 view.DownFocusableView = downView;
325 tmpView = view.DownFocusableView;
326 if (string.Compare(tmpView.Name, "downView") == 0)
328 Console.WriteLine("Passed: DownFocusedView = " + tmpView.Name);
332 Console.WriteLine("Failed: DownFocusedView = " + tmpView.Name);
335 Stage.Instance.Remove(leftView);
336 tmpView = view.LeftFocusableView;
339 Console.WriteLine("Passed: NULL LeftFocusedView");
343 Console.WriteLine("Failed: LeftFocusedView = " + tmpView.Name);
347 public void OperatorTests()
349 Actor actor = new Actor();
350 Actor differentActor = new Actor();
351 Actor actorSame = actor;
352 Actor nullActor = null;
354 // test the true operator
357 Console.WriteLine ("BaseHandle Operator true (actor) : test passed ");
361 Console.WriteLine ("BaseHandle Operator true (actor): test failed ");
364 Actor parent = actor.GetParent ();
368 Console.WriteLine ("Handle with Empty body :failed ");
372 Console.WriteLine ("Valid with Empty body :passed ");
375 actor.Add( differentActor );
377 // here we test two different C# objects, which on the native side have the same body/ ref-object
378 if ( actor == differentActor.GetParent() )
380 Console.WriteLine ("actor == differentActor.GetParent() :passed ");
384 Console.WriteLine ("actor == differentActor.GetParent() :failed ");
387 if ( differentActor == differentActor.GetParent() )
389 Console.WriteLine ("differentActor == differentActor.GetParent() :failed ");
393 Console.WriteLine ("differentActor == differentActor.GetParent() :passed ");
398 Console.WriteLine ("BaseHandle Operator true (nullActor) : test failed ");
402 Console.WriteLine ("BaseHandle Operator true (nullActor): test passed ");
408 Console.WriteLine ("BaseHandle Operator !(actor) : test failed ");
412 Console.WriteLine ("BaseHandle Operator !(actor): test passed ");
417 Console.WriteLine ("BaseHandle Operator !(nullActor) : test passed ");
421 Console.WriteLine ("BaseHandle Operator !(nullActor): test failed ");
424 // Note: operator false only used inside & operator
425 // test equality operator ==
426 if ( actor == actorSame )
428 Console.WriteLine ("BaseHandle Operator (actor == actorSame) : test passed");
432 Console.WriteLine ("BaseHandle Operator (actor == actorSame) : test failed");
435 if ( actor == differentActor )
437 Console.WriteLine ("BaseHandle Operator (actor == differentActor) : test failed");
441 Console.WriteLine ("BaseHandle Operator (actor == differentActor) : test passed");
444 if ( actor == nullActor )
446 Console.WriteLine ("BaseHandle Operator (actor == nullActor) : test failed");
450 Console.WriteLine ("BaseHandle Operator (actor == nullActor) : test passed");
453 if ( nullActor == nullActor )
455 Console.WriteLine ("BaseHandle Operator (nullActor == nullActor) : test passed");
459 Console.WriteLine ("BaseHandle Operator (nullActor == nullActor) : test failed");
463 if ( actor || actorSame )
465 Console.WriteLine ("BaseHandle Operator (actor || actorSame) : test passed");
469 Console.WriteLine ("BaseHandle Operator (actor || actorSame) : test failed");
472 if ( actor || nullActor )
474 Console.WriteLine ("BaseHandle Operator (actor || nullActor) : test passed");
478 Console.WriteLine ("BaseHandle Operator (actor || nullActor) : test failed");
481 if ( nullActor || nullActor )
483 Console.WriteLine ("BaseHandle Operator (nullActor || nullActor) : test failed");
487 Console.WriteLine ("BaseHandle Operator (nullActor || nullActor) : test passed");
491 if ( actor && actorSame )
493 Console.WriteLine ("BaseHandle Operator (actor && actorSame) : test passed");
497 Console.WriteLine ("BaseHandle Operator (actor && actorSame) : test failed");
500 if ( actor && nullActor )
502 Console.WriteLine ("BaseHandle Operator (actor && nullActor) : test failed");
506 Console.WriteLine ("BaseHandle Operator (actor && nullActor) : test passed");
509 if ( nullActor && nullActor )
511 Console.WriteLine ("BaseHandle Operator (nullActor && nullActor) : test failed");
515 Console.WriteLine ("BaseHandle Operator (nullActor && nullActor) : test passed");
519 public void CustomViewPropertyTest()
521 // Create a Spin control
522 Spin spin = new Spin();
524 // Background property
525 Property.Map background = new Property.Map();
526 background.Add( Dali.Constants.Visual.Property.Type, new Property.Value((int)Dali.Constants.Visual.Type.Color) )
527 .Add( Dali.Constants.ColorVisualProperty.MixColor, new Property.Value(Color.Red) );
528 spin.Background = background;
530 background = spin.Background;
531 Vector4 backgroundColor = new Vector4();
532 background.Find(Dali.Constants.ColorVisualProperty.MixColor).Get(backgroundColor);
533 if( backgroundColor == Color.Red )
535 Console.WriteLine ("Custom View Background property : test passed");
539 Console.WriteLine ("Custom View Background property : test failed");
542 // BackgroundColor property
543 spin.BackgroundColor = Color.Yellow;
544 if(spin.BackgroundColor == Color.Yellow)
546 Console.WriteLine ("Custom View BackgroundColor property : test passed");
550 Console.WriteLine ("Custom View BackgroundColor property : test failed");
553 // BackgroundImage property
554 spin.BackgroundImage = "background-image.jpg";
555 if(spin.BackgroundImage == "background-image.jpg")
557 Console.WriteLine ("Custom View BackgroundImage property : test passed");
561 Console.WriteLine ("Custom View BackgroundImage property : test failed");
564 // StyleName property
565 spin.StyleName = "MyCustomStyle";
566 if(spin.StyleName == "MyCustomStyle")
568 Console.WriteLine ("Custom View StyleName property : test passed");
572 Console.WriteLine ("Custom View StyleName property : test failed");
576 public void ViewDownCastTest()
578 View container = new View();
579 container.Position = new Position(-800.0f, -800.0f, 0.0f);
580 Stage.GetCurrent().Add(container);
582 // Test downcast for native control
583 TextLabel myLabel = new TextLabel();
584 myLabel.Name = "MyLabelName";
585 myLabel.Text = "MyText";
587 Console.WriteLine("myLabel.Name = " + myLabel.Name + ", Text = " + myLabel.Text);
589 container.Add(myLabel);
591 Actor myLabelActor = container.FindChildByName("MyLabelName");
594 TextLabel newLabel = View.DownCast<TextLabel>(myLabelActor);
597 Console.WriteLine("Downcast to TextLabel successful: newLabel Name = " + newLabel.Name + ", Text = " + newLabel.Text);
601 Console.WriteLine("Downcast to TextLabel failed!");
605 // Test downcast for class directly inherited from View
606 MyView myView = new MyView();
607 myView.Name = "MyViewName";
608 myView.MyOwnName = "MyOwnViewName";
609 myView._myCurrentValue = 5;
611 Console.WriteLine("myView.Name = " + myView.Name + ", MyOwnName = " + myView.MyOwnName + ", myCurrentValue = " + myView._myCurrentValue);
613 container.Add(myView);
615 Actor myViewActor = container.FindChildByName("MyViewName");
618 MyView newView = View.DownCast<MyView>(myViewActor);
621 Console.WriteLine("Downcast to MyView successful: newView Name = " + newView.Name + ", MyOwnName = " + newView.MyOwnName + ", myCurrentValue = " + newView._myCurrentValue);
625 Console.WriteLine("Downcast to MyView failed!");
629 // Test downcast for class directly inherited from native control
630 MyButton myButton = new MyButton();
631 myButton.Name = "MyButtonName";
632 myButton.MyOwnName = "MyOwnViewName";
633 myButton.LabelText = "MyLabelText";
634 myButton._myCurrentValue = 5;
636 Console.WriteLine("myButton.Name = " + myButton.Name + ", MyOwnName = " + myButton.MyOwnName + ", LabelText = " + myButton.LabelText + ", myCurrentValue = " + myButton._myCurrentValue);
638 container.Add(myButton);
640 Actor myButtonActor = container.FindChildByName("MyButtonName");
643 MyButton newButton = View.DownCast<MyButton>(myButtonActor);
646 Console.WriteLine("Downcast to MyButton successful: newButton Name = " + newButton.Name + ", MyOwnName = " + newButton.MyOwnName + ", LabelText = " + myButton.LabelText + ", myCurrentValue = " + newButton._myCurrentValue);
650 Console.WriteLine("Downcast to MyButton failed!");
654 // Test downcast for a CustomView
655 Spin spin = new Spin();
656 spin.Name = "SpinName";
657 spin.MaxValue = 8888;
659 Console.WriteLine("spin.Name = " + spin.Name + ", MaxValue = " + spin.MaxValue);
663 Actor spinActor = container.FindChildByName("SpinName");
666 Spin newSpin = View.DownCast<Spin>(spinActor);
669 Console.WriteLine("Downcast to Spin successful: newSpin Name = " + newSpin.Name + ", MaxValue = " + newSpin.MaxValue);
673 Console.WriteLine("Downcast to Spin failed!");
677 // Test downcast for class inherited from a CustomView
678 MySpin mySpin = new MySpin();
679 mySpin.Name = "MySpinName";
680 mySpin.MyOwnName = "MyOwnSpinName";
681 mySpin.MaxValue = 8888;
682 mySpin._myCurrentValue = 5;
684 Console.WriteLine("mySpin.Name = " + mySpin.Name + ", MyOwnName = " + mySpin.MyOwnName + ", MaxValue = " + mySpin.MaxValue + ", currentValue = " + mySpin._myCurrentValue);
686 container.Add(mySpin);
688 Actor mySpinActor = container.FindChildByName("MySpinName");
691 MySpin newSpin = View.DownCast<MySpin>(mySpinActor);
694 Console.WriteLine("Downcast to MySpin successful: newSpin Name = " + newSpin.Name + ", MyOwnName = " + newSpin.MyOwnName + ", MaxValue = " + newSpin.MaxValue + ", currentValue = " + newSpin._myCurrentValue);
698 Console.WriteLine("Downcast to MySpin failed!");
703 public void MainLoop()
705 _application.MainLoop ();
709 /// The main entry point for the application.
712 static void Main(string[] args)
714 Console.WriteLine ("Hello Mono World");
716 Example example = new Example(Application.NewApplication());