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)
113 CustomViewPropertyTest();
115 Handle handle = new Handle();
116 int myPropertyIndex = handle.RegisterProperty("myProperty", new Property.Value(10.0f), Property.AccessMode.READ_WRITE);
117 float myProperty = 0.0f;
118 handle.GetProperty(myPropertyIndex).Get(ref myProperty);
119 Console.WriteLine( "myProperty value: " + myProperty );
121 int myPropertyIndex2 = handle.RegisterProperty("myProperty2", new Property.Value(new Size(5.0f, 5.0f)), Property.AccessMode.READ_WRITE);
122 Size myProperty2 = new Size(0.0f, 0.0f);
123 handle.GetProperty(myPropertyIndex2).Get(myProperty2);
124 Console.WriteLine( "myProperty2 value: " + myProperty2.W + ", " + myProperty2.H );
126 Actor actor = new Actor();
127 actor.Size = new Position(200.0f, 200.0f, 0.0f);
128 actor.Name = "MyActor";
129 actor.Color = new Color(1.0f, 0.0f, 1.0f, 0.8f);
130 Console.WriteLine("Actor id: {0}", actor.GetId());
131 Console.WriteLine("Actor size: " + actor.Size.X + ", " + actor.Size.Y);
132 Console.WriteLine("Actor name: " + actor.Name);
134 Stage stage = Stage.GetCurrent();
135 stage.BackgroundColor = Color.White;
136 Size stageSize = stage.Size;
137 Console.WriteLine("Stage size: " + stageSize.W + ", " + stageSize.H);
140 TextLabel text = new TextLabel("Hello Mono World");
141 text.ParentOrigin = NDalic.ParentOriginCenter;
142 text.AnchorPoint = NDalic.AnchorPointCenter;
143 text.HorizontalAlignment = "CENTER";
146 Console.WriteLine( "Text label text: " + text.Text );
148 Console.WriteLine( "Text label point size: " + text.PointSize );
149 text.PointSize = 32.0f;
150 Console.WriteLine( "Text label new point size: " + text.PointSize );
152 RectanglePaddingClassTest();
154 Console.WriteLine( " *************************" );
155 Size Size = new Size(100, 50);
156 Console.WriteLine( " Created " + Size );
157 Console.WriteLine( " Size x = " + Size.W + ", y = " + Size.H );
158 Size += new Size(20, 20);
159 Console.WriteLine( " Size x = " + Size.W + ", y = " + Size.H );
162 Console.WriteLine( " Size width = " + Size.W + ", height = " + Size.H );
164 Console.WriteLine( " *************************" );
165 Position Position = new Position(20, 100, 50);
166 Console.WriteLine( " Created " + Position );
167 Console.WriteLine( " Position x = " + Position.X + ", y = " + Position.Y + ", z = " + Position.Z );
168 Position += new Position(20, 20, 20);
169 Console.WriteLine( " Position x = " + Position.X + ", y = " + Position.Y + ", z = " + Position.Z );
173 Console.WriteLine( " Position width = " + Position.X + ", height = " + Position.Y + ", depth = " + Position.Z );
174 Position parentOrigin = new Dali.Position(NDalic.ParentOriginBottomRight);
175 Console.WriteLine( " parentOrigin x = " + parentOrigin.X + ", y = " + parentOrigin.Y + ", z = " + parentOrigin.Z );
177 Console.WriteLine( " *************************" );
178 Color color = new Color(20, 100, 50, 200);
179 Console.WriteLine( " Created " + color );
180 Console.WriteLine( " Color R = " + color.R + ", G = " + color.G + ", B = " + color.B + ", A = " + color.A );
181 color += new Color(20, 20, 20, 20);
182 Console.WriteLine( " Color R = " + color.R + ", G = " + color.G + ", B = " + color.B + ", A = " + color.A );
187 Console.WriteLine( " Color r = " + color.R + ", g = " + color.G + ", b = " + color.B + ", a = " + color.A );
192 public void RectanglePaddingClassTest()
194 using (Rectangle r1 = new Rectangle(2, 5, 20, 30))
196 Console.WriteLine( " Created " + r1 );
197 Console.WriteLine( " IsEmpty() = " + r1.IsEmpty() );
198 Console.WriteLine( " Left = " + r1.Left() );
199 Console.WriteLine( " Right = " + r1.Right() );
200 Console.WriteLine( " Top = " + r1.Top() );
201 Console.WriteLine( " Bottom = " + r1.Bottom() );
202 Console.WriteLine( " Area = " + r1.Area() );
205 Console.WriteLine( " *************************" );
207 using (Rectangle r2 = new Rectangle(2, 5, 20, 30))
209 Console.WriteLine( " Created " + r2 );
211 Console.WriteLine( " IsEmpty() = " + r2.IsEmpty() );
212 Console.WriteLine( " Left = " + r2.Left() );
213 Console.WriteLine( " Right = " + r2.Right() );
214 Console.WriteLine( " Top = " + r2.Top() );
215 Console.WriteLine( " Bottom = " + r2.Bottom() );
216 Console.WriteLine( " Area = " + r2.Area() );
219 Console.WriteLine( " *************************" );
221 Rectangle r3 = new Rectangle(10, 10, 20, 20);
222 Rectangle r4 = new Rectangle(10, 10, 20, 20);
226 Console.WriteLine("r3 == r4");
230 Console.WriteLine("r3 != r4");
233 r4 = new Rectangle(12, 10, 20, 20);
237 Console.WriteLine("r3 == r4");
241 Console.WriteLine("r3 != r4");
244 PaddingType p1 = new PaddingType(10.5f, 10.7f, 20.8f, 20.8f);
245 PaddingType p2 = new PaddingType(10.5f, 10.7f, 20.8f, 20.8f);
249 Console.WriteLine("p1 == p2");
253 Console.WriteLine("p1 != p2");
256 p2 = new PaddingType(12.0f, 10.7f, 20.2f, 20.0f);
260 Console.WriteLine("p1 == p2");
264 Console.WriteLine("p1 != p2");
268 public void OperatorTests()
270 Actor actor = new Actor();
271 Actor differentActor = new Actor();
272 Actor actorSame = actor;
273 Actor nullActor = null;
275 // test the true operator
278 Console.WriteLine ("BaseHandle Operator true (actor) : test passed ");
282 Console.WriteLine ("BaseHandle Operator true (actor): test failed ");
285 Actor parent = actor.GetParent ();
289 Console.WriteLine ("Handle with Empty body :failed ");
293 Console.WriteLine ("Valid with Empty body :passed ");
296 actor.Add( differentActor );
298 // here we test two different C# objects, which on the native side have the same body/ ref-object
299 if ( actor == differentActor.GetParent() )
301 Console.WriteLine ("actor == differentActor.GetParent() :passed ");
305 Console.WriteLine ("actor == differentActor.GetParent() :failed ");
308 if ( differentActor == differentActor.GetParent() )
310 Console.WriteLine ("differentActor == differentActor.GetParent() :failed ");
314 Console.WriteLine ("differentActor == differentActor.GetParent() :passed ");
319 Console.WriteLine ("BaseHandle Operator true (nullActor) : test failed ");
323 Console.WriteLine ("BaseHandle Operator true (nullActor): test passed ");
329 Console.WriteLine ("BaseHandle Operator !(actor) : test failed ");
333 Console.WriteLine ("BaseHandle Operator !(actor): test passed ");
338 Console.WriteLine ("BaseHandle Operator !(nullActor) : test passed ");
342 Console.WriteLine ("BaseHandle Operator !(nullActor): test failed ");
345 // Note: operator false only used inside & operator
346 // test equality operator ==
347 if ( actor == actorSame )
349 Console.WriteLine ("BaseHandle Operator (actor == actorSame) : test passed");
353 Console.WriteLine ("BaseHandle Operator (actor == actorSame) : test failed");
356 if ( actor == differentActor )
358 Console.WriteLine ("BaseHandle Operator (actor == differentActor) : test failed");
362 Console.WriteLine ("BaseHandle Operator (actor == differentActor) : test passed");
365 if ( actor == nullActor )
367 Console.WriteLine ("BaseHandle Operator (actor == nullActor) : test failed");
371 Console.WriteLine ("BaseHandle Operator (actor == nullActor) : test passed");
374 if ( nullActor == nullActor )
376 Console.WriteLine ("BaseHandle Operator (nullActor == nullActor) : test passed");
380 Console.WriteLine ("BaseHandle Operator (nullActor == nullActor) : test failed");
384 if ( actor || actorSame )
386 Console.WriteLine ("BaseHandle Operator (actor || actorSame) : test passed");
390 Console.WriteLine ("BaseHandle Operator (actor || actorSame) : test failed");
393 if ( actor || nullActor )
395 Console.WriteLine ("BaseHandle Operator (actor || nullActor) : test passed");
399 Console.WriteLine ("BaseHandle Operator (actor || nullActor) : test failed");
402 if ( nullActor || nullActor )
404 Console.WriteLine ("BaseHandle Operator (nullActor || nullActor) : test failed");
408 Console.WriteLine ("BaseHandle Operator (nullActor || nullActor) : test passed");
412 if ( actor && actorSame )
414 Console.WriteLine ("BaseHandle Operator (actor && actorSame) : test passed");
418 Console.WriteLine ("BaseHandle Operator (actor && actorSame) : test failed");
421 if ( actor && nullActor )
423 Console.WriteLine ("BaseHandle Operator (actor && nullActor) : test failed");
427 Console.WriteLine ("BaseHandle Operator (actor && nullActor) : test passed");
430 if ( nullActor && nullActor )
432 Console.WriteLine ("BaseHandle Operator (nullActor && nullActor) : test failed");
436 Console.WriteLine ("BaseHandle Operator (nullActor && nullActor) : test passed");
440 public void CustomViewPropertyTest()
442 // Create a Spin control
443 Spin spin = new Spin();
445 // Background property
446 Property.Map background = new Property.Map();
447 background.Add( Dali.Constants.Visual.Property.Type, new Property.Value((int)Dali.Constants.Visual.Type.Color) )
448 .Add( Dali.Constants.ColorVisualProperty.MixColor, new Property.Value(Color.Red) );
449 spin.Background = background;
451 background = spin.Background;
452 Vector4 backgroundColor = new Vector4();
453 background.Find(Dali.Constants.ColorVisualProperty.MixColor).Get(backgroundColor);
454 if( backgroundColor == Color.Red )
456 Console.WriteLine ("Custom View Background property : test passed");
460 Console.WriteLine ("Custom View Background property : test failed");
463 // BackgroundColor property
464 spin.BackgroundColor = Color.Yellow;
465 if(spin.BackgroundColor == Color.Yellow)
467 Console.WriteLine ("Custom View BackgroundColor property : test passed");
471 Console.WriteLine ("Custom View BackgroundColor property : test failed");
474 // BackgroundImage property
475 spin.BackgroundImage = "background-image.jpg";
476 if(spin.BackgroundImage == "background-image.jpg")
478 Console.WriteLine ("Custom View BackgroundImage property : test passed");
482 Console.WriteLine ("Custom View BackgroundImage property : test failed");
485 // StyleName property
486 spin.StyleName = "MyCustomStyle";
487 if(spin.StyleName == "MyCustomStyle")
489 Console.WriteLine ("Custom View StyleName property : test passed");
493 Console.WriteLine ("Custom View StyleName property : test failed");
497 public void ViewDownCastTest()
499 View container = new View();
500 container.Position = new Position(-800.0f, -800.0f, 0.0f);
501 Stage.GetCurrent().Add(container);
503 // Test downcast for native control
504 TextLabel myLabel = new TextLabel();
505 myLabel.Name = "MyLabelName";
506 myLabel.Text = "MyText";
508 Console.WriteLine("myLabel.Name = " + myLabel.Name + ", Text = " + myLabel.Text);
510 container.Add(myLabel);
512 Actor myLabelActor = container.FindChildByName("MyLabelName");
515 TextLabel newLabel = View.DownCast<TextLabel>(myLabelActor);
518 Console.WriteLine("Downcast to TextLabel successful: newLabel Name = " + newLabel.Name + ", Text = " + newLabel.Text);
522 Console.WriteLine("Downcast to TextLabel failed!");
526 // Test downcast for class directly inherited from View
527 MyView myView = new MyView();
528 myView.Name = "MyViewName";
529 myView.MyOwnName = "MyOwnViewName";
530 myView._myCurrentValue = 5;
532 Console.WriteLine("myView.Name = " + myView.Name + ", MyOwnName = " + myView.MyOwnName + ", myCurrentValue = " + myView._myCurrentValue);
534 container.Add(myView);
536 Actor myViewActor = container.FindChildByName("MyViewName");
539 MyView newView = View.DownCast<MyView>(myViewActor);
542 Console.WriteLine("Downcast to MyView successful: newView Name = " + newView.Name + ", MyOwnName = " + newView.MyOwnName + ", myCurrentValue = " + newView._myCurrentValue);
546 Console.WriteLine("Downcast to MyView failed!");
550 // Test downcast for class directly inherited from native control
551 MyButton myButton = new MyButton();
552 myButton.Name = "MyButtonName";
553 myButton.MyOwnName = "MyOwnViewName";
554 myButton.LabelText = "MyLabelText";
555 myButton._myCurrentValue = 5;
557 Console.WriteLine("myButton.Name = " + myButton.Name + ", MyOwnName = " + myButton.MyOwnName + ", LabelText = " + myButton.LabelText + ", myCurrentValue = " + myButton._myCurrentValue);
559 container.Add(myButton);
561 Actor myButtonActor = container.FindChildByName("MyButtonName");
564 MyButton newButton = View.DownCast<MyButton>(myButtonActor);
567 Console.WriteLine("Downcast to MyButton successful: newButton Name = " + newButton.Name + ", MyOwnName = " + newButton.MyOwnName + ", LabelText = " + myButton.LabelText + ", myCurrentValue = " + newButton._myCurrentValue);
571 Console.WriteLine("Downcast to MyButton failed!");
575 // Test downcast for a CustomView
576 Spin spin = new Spin();
577 spin.Name = "SpinName";
578 spin.MaxValue = 8888;
580 Console.WriteLine("spin.Name = " + spin.Name + ", MaxValue = " + spin.MaxValue);
584 Actor spinActor = container.FindChildByName("SpinName");
587 Spin newSpin = View.DownCast<Spin>(spinActor);
590 Console.WriteLine("Downcast to Spin successful: newSpin Name = " + newSpin.Name + ", MaxValue = " + newSpin.MaxValue);
594 Console.WriteLine("Downcast to Spin failed!");
598 // Test downcast for class inherited from a CustomView
599 MySpin mySpin = new MySpin();
600 mySpin.Name = "MySpinName";
601 mySpin.MyOwnName = "MyOwnSpinName";
602 mySpin.MaxValue = 8888;
603 mySpin._myCurrentValue = 5;
605 Console.WriteLine("mySpin.Name = " + mySpin.Name + ", MyOwnName = " + mySpin.MyOwnName + ", MaxValue = " + mySpin.MaxValue + ", currentValue = " + mySpin._myCurrentValue);
607 container.Add(mySpin);
609 Actor mySpinActor = container.FindChildByName("MySpinName");
612 MySpin newSpin = View.DownCast<MySpin>(mySpinActor);
615 Console.WriteLine("Downcast to MySpin successful: newSpin Name = " + newSpin.Name + ", MyOwnName = " + newSpin.MyOwnName + ", MaxValue = " + newSpin.MaxValue + ", currentValue = " + newSpin._myCurrentValue);
619 Console.WriteLine("Downcast to MySpin failed!");
624 public void MainLoop()
626 _application.MainLoop ();
630 /// The main entry point for the application.
633 static void Main(string[] args)
635 Console.WriteLine ("Hello Mono World");
637 Example example = new Example(Application.NewApplication());