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;
21 using Tizen.NUI.Constants;
27 private string _myOwnName;
28 public int _myCurrentValue;
35 public string MyOwnName
48 class MyButton : PushButton
50 private string _myOwnName;
51 public int _myCurrentValue;
58 public string MyOwnName
73 private string _myOwnName;
74 public int _myCurrentValue;
81 public string MyOwnName
94 class Example : NUIApplication
96 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
97 delegate void CallbackDelegate(IntPtr appPtr); // void, void delgate
99 public Example() : base()
103 public Example(string stylesheet) : base(stylesheet)
107 public Example(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
111 protected override void OnCreate()
117 public void Initialize()
119 NavigationPropertiesTests();
123 CustomViewPropertyTest();
125 Handle handle = new Handle();
126 int myPropertyIndex = handle.RegisterProperty("myProperty", new PropertyValue(10.0f), PropertyAccessMode.ReadWrite);
127 float myProperty = 0.0f;
128 handle.GetProperty(myPropertyIndex).Get(ref myProperty);
129 Console.WriteLine( "myProperty value: " + myProperty );
131 int myPropertyIndex2 = handle.RegisterProperty("myProperty2", new PropertyValue(new Size(5.0f, 5.0f, 0.0f)), PropertyAccessMode.ReadWrite);
132 Size myProperty2 = new Size(0.0f, 0.0f, 0.0f);
133 handle.GetProperty(myPropertyIndex2).Get(myProperty2);
134 Console.WriteLine( "myProperty2 value: " + myProperty2.Width + ", " + myProperty2.Height );
136 Actor actor = new Actor();
137 actor.Size = new Size(200.0f, 200.0f, 0.0f);
138 actor.Name = "MyActor";
139 actor.MixColor = new Color(1.0f, 0.0f, 1.0f, 0.8f);
140 Console.WriteLine("Actor size: " + actor.Size.Width + ", " + actor.Size.Height);
141 Console.WriteLine("Actor name: " + actor.Name);
143 Stage stage = Stage.Instance;
144 stage.BackgroundColor = Color.White;
145 Size stageSize = new Size(stage.Size.Width, stage.Size.Height, 0.0f);
146 Console.WriteLine("Stage size: " + stageSize.Width + ", " + stageSize.Height);
147 stage.GetDefaultLayer().Add(actor);
149 TextLabel text = new TextLabel("Hello Mono World");
150 text.ParentOrigin = ParentOrigin.Center;
151 text.AnchorPoint = AnchorPoint.Center;
152 text.HorizontalAlignment = "CENTER";
153 stage.GetDefaultLayer().Add(text);
155 Console.WriteLine( "Text label text: " + text.Text );
157 Console.WriteLine( "Text label point size: " + text.PointSize );
158 text.PointSize = 32.0f;
159 Console.WriteLine( "Text label new point size: " + text.PointSize );
161 RectanglePaddingClassTest();
163 Console.WriteLine( " *************************" );
164 Size Size = new Size(100, 50, 0);
165 Console.WriteLine( " Created " + Size );
166 Console.WriteLine( " Size x = " + Size.Width + ", y = " + Size.Height );
167 Size += new Size(20, 20, 0);
168 Console.WriteLine( " Size x = " + Size.Width + ", y = " + Size.Height );
171 Console.WriteLine( " Size width = " + Size.Width + ", height = " + Size.Height );
173 Console.WriteLine( " *************************" );
174 Position Position = new Position(20, 100, 50);
175 Console.WriteLine( " Created " + Position );
176 Console.WriteLine( " Position x = " + Position.X + ", y = " + Position.Y + ", z = " + Position.Z );
177 Position += new Position(20, 20, 20);
178 Console.WriteLine( " Position x = " + Position.X + ", y = " + Position.Y + ", z = " + Position.Z );
182 Console.WriteLine( " Position width = " + Position.X + ", height = " + Position.Y + ", depth = " + Position.Z );
184 Console.WriteLine( " *************************" );
185 Color color = new Color(20, 100, 50, 200);
186 Console.WriteLine( " Created " + color );
187 Console.WriteLine( " Color R = " + color.R + ", G = " + color.G + ", B = " + color.B + ", A = " + color.A );
188 color += new Color(20, 20, 20, 20);
189 Console.WriteLine( " Color R = " + color.R + ", G = " + color.G + ", B = " + color.B + ", A = " + color.A );
194 Console.WriteLine( " Color r = " + color.R + ", g = " + color.G + ", b = " + color.B + ", a = " + color.A );
199 public void RectanglePaddingClassTest()
201 using (Rectangle r1 = new Rectangle(2, 5, 20, 30))
203 Console.WriteLine( " Created " + r1 );
204 Console.WriteLine( " IsEmpty() = " + r1.IsEmpty() );
205 Console.WriteLine( " Left = " + r1.Left() );
206 Console.WriteLine( " Right = " + r1.Right() );
207 Console.WriteLine( " Top = " + r1.Top() );
208 Console.WriteLine( " Bottom = " + r1.Bottom() );
209 Console.WriteLine( " Area = " + r1.Area() );
212 Console.WriteLine( " *************************" );
214 using (Rectangle r2 = new Rectangle(2, 5, 20, 30))
216 Console.WriteLine( " Created " + r2 );
218 Console.WriteLine( " IsEmpty() = " + r2.IsEmpty() );
219 Console.WriteLine( " Left = " + r2.Left() );
220 Console.WriteLine( " Right = " + r2.Right() );
221 Console.WriteLine( " Top = " + r2.Top() );
222 Console.WriteLine( " Bottom = " + r2.Bottom() );
223 Console.WriteLine( " Area = " + r2.Area() );
226 Console.WriteLine( " *************************" );
228 Rectangle r3 = new Rectangle(10, 10, 20, 20);
229 Rectangle r4 = new Rectangle(10, 10, 20, 20);
233 Console.WriteLine("r3 == r4");
237 Console.WriteLine("r3 != r4");
240 r4 = new Rectangle(12, 10, 20, 20);
244 Console.WriteLine("r3 == r4");
248 Console.WriteLine("r3 != r4");
251 PaddingType p1 = new PaddingType(10.5f, 10.7f, 20.8f, 20.8f);
252 PaddingType p2 = new PaddingType(10.5f, 10.7f, 20.8f, 20.8f);
256 Console.WriteLine("p1 == p2");
260 Console.WriteLine("p1 != p2");
263 p2 = new PaddingType(12.0f, 10.7f, 20.2f, 20.0f);
267 Console.WriteLine("p1 == p2");
271 Console.WriteLine("p1 != p2");
275 public void NavigationPropertiesTests()
277 View view = new View();
278 View leftView, rightView, upView, downView, tmpView;
280 leftView = new View();
281 leftView.Name = "leftView";
282 rightView = new View();
283 rightView.Name = "rightView";
285 upView.Name = "upView";
286 downView = new View();
287 downView.Name = "downView";
289 Stage.Instance.GetDefaultLayer().Add(leftView);
290 Stage.Instance.GetDefaultLayer().Add(rightView);
291 Stage.Instance.GetDefaultLayer().Add(upView);
292 Stage.Instance.GetDefaultLayer().Add(downView);
294 view.LeftFocusableView = leftView;
295 tmpView = view.LeftFocusableView;
296 if (string.Compare(tmpView.Name, "leftView") == 0)
298 Console.WriteLine("Passed: LeftFocusedView = " + tmpView.Name);
302 Console.WriteLine("Failed: LeftFocusedView = " + tmpView.Name);
305 view.RightFocusableView = rightView;
306 tmpView = view.RightFocusableView;
307 if (string.Compare(tmpView.Name, "rightView") == 0)
309 Console.WriteLine("Passed: RightFocusedView = " + tmpView.Name);
313 Console.WriteLine("Failed: RightFocusedView = " + tmpView.Name);
316 Stage.Instance.GetDefaultLayer().Add(view);
318 view.UpFocusableView = upView;
319 tmpView = view.UpFocusableView;
320 if (string.Compare(tmpView.Name, "upView") == 0)
322 Console.WriteLine("Passed: UpFocusedView = " + tmpView.Name);
326 Console.WriteLine("Failed: UpFocusedView = " + tmpView.Name);
329 view.DownFocusableView = downView;
330 tmpView = view.DownFocusableView;
331 if (string.Compare(tmpView.Name, "downView") == 0)
333 Console.WriteLine("Passed: DownFocusedView = " + tmpView.Name);
337 Console.WriteLine("Failed: DownFocusedView = " + tmpView.Name);
340 Stage.Instance.GetDefaultLayer().Remove(leftView);
341 tmpView = view.LeftFocusableView;
344 Console.WriteLine("Passed: NULL LeftFocusedView");
348 Console.WriteLine("Failed: LeftFocusedView = " + tmpView.Name);
352 public void OperatorTests()
354 Actor actor = new Actor();
355 Actor differentActor = new Actor();
356 Actor actorSame = actor;
357 Actor nullActor = null;
359 // test the true operator
362 Console.WriteLine ("BaseHandle Operator true (actor) : test passed ");
366 Console.WriteLine ("BaseHandle Operator true (actor): test failed ");
369 Actor parent = actor.Parent;
373 Console.WriteLine ("Handle with Empty body :failed ");
377 Console.WriteLine ("Valid with Empty body :passed ");
380 actor.Add( differentActor );
382 // here we test two different C# objects, which on the native side have the same body/ ref-object
383 if ( actor == differentActor.Parent )
385 Console.WriteLine ("actor == differentActor.GetParent() :passed ");
389 Console.WriteLine ("actor == differentActor.GetParent() :failed ");
392 if ( differentActor == differentActor.Parent )
394 Console.WriteLine ("differentActor == differentActor.GetParent() :failed ");
398 Console.WriteLine ("differentActor == differentActor.GetParent() :passed ");
403 Console.WriteLine ("BaseHandle Operator true (nullActor) : test failed ");
407 Console.WriteLine ("BaseHandle Operator true (nullActor): test passed ");
413 Console.WriteLine ("BaseHandle Operator !(actor) : test failed ");
417 Console.WriteLine ("BaseHandle Operator !(actor): test passed ");
422 Console.WriteLine ("BaseHandle Operator !(nullActor) : test passed ");
426 Console.WriteLine ("BaseHandle Operator !(nullActor): test failed ");
429 // Note: operator false only used inside & operator
430 // test equality operator ==
431 if ( actor == actorSame )
433 Console.WriteLine ("BaseHandle Operator (actor == actorSame) : test passed");
437 Console.WriteLine ("BaseHandle Operator (actor == actorSame) : test failed");
440 if ( actor == differentActor )
442 Console.WriteLine ("BaseHandle Operator (actor == differentActor) : test failed");
446 Console.WriteLine ("BaseHandle Operator (actor == differentActor) : test passed");
449 if ( actor == nullActor )
451 Console.WriteLine ("BaseHandle Operator (actor == nullActor) : test failed");
455 Console.WriteLine ("BaseHandle Operator (actor == nullActor) : test passed");
458 if ( nullActor == nullActor )
460 Console.WriteLine ("BaseHandle Operator (nullActor == nullActor) : test passed");
464 Console.WriteLine ("BaseHandle Operator (nullActor == nullActor) : test failed");
468 if ( actor || actorSame )
470 Console.WriteLine ("BaseHandle Operator (actor || actorSame) : test passed");
474 Console.WriteLine ("BaseHandle Operator (actor || actorSame) : test failed");
477 if ( actor || nullActor )
479 Console.WriteLine ("BaseHandle Operator (actor || nullActor) : test passed");
483 Console.WriteLine ("BaseHandle Operator (actor || nullActor) : test failed");
486 if ( nullActor || nullActor )
488 Console.WriteLine ("BaseHandle Operator (nullActor || nullActor) : test failed");
492 Console.WriteLine ("BaseHandle Operator (nullActor || nullActor) : test passed");
496 if ( actor && actorSame )
498 Console.WriteLine ("BaseHandle Operator (actor && actorSame) : test passed");
502 Console.WriteLine ("BaseHandle Operator (actor && actorSame) : test failed");
505 if ( actor && nullActor )
507 Console.WriteLine ("BaseHandle Operator (actor && nullActor) : test failed");
511 Console.WriteLine ("BaseHandle Operator (actor && nullActor) : test passed");
514 if ( nullActor && nullActor )
516 Console.WriteLine ("BaseHandle Operator (nullActor && nullActor) : test failed");
520 Console.WriteLine ("BaseHandle Operator (nullActor && nullActor) : test passed");
524 public void CustomViewPropertyTest()
526 // Create a Spin control
527 Spin spin = new Spin();
529 // Background property
530 PropertyMap background = new PropertyMap();
531 background.Add( Visual.Property.Type, new PropertyValue((int)Visual.Type.Color) )
532 .Add( ColorVisualProperty.MixColor, new PropertyValue(Color.Red) );
533 spin.Background = background;
535 background = spin.Background;
536 Color backgroundColor = new Color();
537 background.Find(ColorVisualProperty.MixColor).Get(backgroundColor);
538 if( backgroundColor == Color.Red )
540 Console.WriteLine ("Custom View Background property : test passed");
544 Console.WriteLine ("Custom View Background property : test failed");
547 // BackgroundColor property
548 spin.BackgroundColor = Color.Yellow;
549 if(spin.BackgroundColor == Color.Yellow)
551 Console.WriteLine ("Custom View BackgroundColor property : test passed");
555 Console.WriteLine ("Custom View BackgroundColor property : test failed");
558 // BackgroundImage property
559 spin.BackgroundImage = "background-image.jpg";
560 if(spin.BackgroundImage == "background-image.jpg")
562 Console.WriteLine ("Custom View BackgroundImage property : test passed");
566 Console.WriteLine ("Custom View BackgroundImage property : test failed");
569 // StyleName property
570 spin.StyleName = "MyCustomStyle";
571 if(spin.StyleName == "MyCustomStyle")
573 Console.WriteLine ("Custom View StyleName property : test passed");
577 Console.WriteLine ("Custom View StyleName property : test failed");
581 public void ViewDownCastTest()
583 View container = new View();
584 container.Position = new Position(-800.0f, -800.0f, 0.0f);
585 Stage.Instance.GetDefaultLayer().Add(container);
587 // Test downcast for native control
588 TextLabel myLabel = new TextLabel();
589 myLabel.Name = "MyLabelName";
590 myLabel.Text = "MyText";
592 Console.WriteLine("myLabel.Name = " + myLabel.Name + ", Text = " + myLabel.Text);
594 container.Add(myLabel);
596 Actor myLabelActor = container.FindChildByName("MyLabelName");
599 TextLabel newLabel = View.DownCast<TextLabel>(myLabelActor);
602 Console.WriteLine("Downcast to TextLabel successful: newLabel Name = " + newLabel.Name + ", Text = " + newLabel.Text);
606 Console.WriteLine("Downcast to TextLabel failed!");
610 // Test downcast for class directly inherited from View
611 MyView myView = new MyView();
612 myView.Name = "MyViewName";
613 myView.MyOwnName = "MyOwnViewName";
614 myView._myCurrentValue = 5;
616 Console.WriteLine("myView.Name = " + myView.Name + ", MyOwnName = " + myView.MyOwnName + ", myCurrentValue = " + myView._myCurrentValue);
618 container.Add(myView);
620 Actor myViewActor = container.FindChildByName("MyViewName");
623 MyView newView = View.DownCast<MyView>(myViewActor);
626 Console.WriteLine("Downcast to MyView successful: newView Name = " + newView.Name + ", MyOwnName = " + newView.MyOwnName + ", myCurrentValue = " + newView._myCurrentValue);
630 Console.WriteLine("Downcast to MyView failed!");
634 // Test downcast for class directly inherited from native control
635 MyButton myButton = new MyButton();
636 myButton.Name = "MyButtonName";
637 myButton.MyOwnName = "MyOwnViewName";
638 myButton.LabelText = "MyLabelText";
639 myButton._myCurrentValue = 5;
641 Console.WriteLine("myButton.Name = " + myButton.Name + ", MyOwnName = " + myButton.MyOwnName + ", LabelText = " + myButton.LabelText + ", myCurrentValue = " + myButton._myCurrentValue);
643 container.Add(myButton);
645 Actor myButtonActor = container.FindChildByName("MyButtonName");
648 MyButton newButton = View.DownCast<MyButton>(myButtonActor);
651 Console.WriteLine("Downcast to MyButton successful: newButton Name = " + newButton.Name + ", MyOwnName = " + newButton.MyOwnName + ", LabelText = " + myButton.LabelText + ", myCurrentValue = " + newButton._myCurrentValue);
655 Console.WriteLine("Downcast to MyButton failed!");
659 // Test downcast for a CustomView
660 Spin spin = new Spin();
661 spin.Name = "SpinName";
662 spin.MaxValue = 8888;
664 Console.WriteLine("spin.Name = " + spin.Name + ", MaxValue = " + spin.MaxValue);
668 Actor spinActor = container.FindChildByName("SpinName");
671 Spin newSpin = View.DownCast<Spin>(spinActor);
674 Console.WriteLine("Downcast to Spin successful: newSpin Name = " + newSpin.Name + ", MaxValue = " + newSpin.MaxValue);
678 Console.WriteLine("Downcast to Spin failed!");
682 // Test downcast for class inherited from a CustomView
683 MySpin mySpin = new MySpin();
684 mySpin.Name = "MySpinName";
685 mySpin.MyOwnName = "MyOwnSpinName";
686 mySpin.MaxValue = 8888;
687 mySpin._myCurrentValue = 5;
689 Console.WriteLine("mySpin.Name = " + mySpin.Name + ", MyOwnName = " + mySpin.MyOwnName + ", MaxValue = " + mySpin.MaxValue + ", currentValue = " + mySpin._myCurrentValue);
691 container.Add(mySpin);
693 Actor mySpinActor = container.FindChildByName("MySpinName");
696 MySpin newSpin = View.DownCast<MySpin>(mySpinActor);
699 Console.WriteLine("Downcast to MySpin successful: newSpin Name = " + newSpin.Name + ", MyOwnName = " + newSpin.MyOwnName + ", MaxValue = " + newSpin.MaxValue + ", currentValue = " + newSpin._myCurrentValue);
703 Console.WriteLine("Downcast to MySpin failed!");
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();