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 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
27 delegate void CallbackDelegate(IntPtr appPtr); // void, void delgate
29 private Dali.Application _application;
31 public Example(Dali.Application application)
33 _application = application;
34 Console.WriteLine( "InitSignal connection count = " + _application.InitSignal().GetConnectionCount() );
36 _application.Initialized += Initialize;
37 Console.WriteLine( "InitSignal connection count = " + _application.InitSignal().GetConnectionCount() );
40 public void Initialize(object source, NUIApplicationInitEventArgs e)
44 CustomViewPropertyTest();
46 Handle handle = new Handle();
47 int myPropertyIndex = handle.RegisterProperty("myProperty", new Property.Value(10.0f), Property.AccessMode.READ_WRITE);
48 float myProperty = 0.0f;
49 handle.GetProperty(myPropertyIndex).Get(ref myProperty);
50 Console.WriteLine( "myProperty value: " + myProperty );
52 int myPropertyIndex2 = handle.RegisterProperty("myProperty2", new Property.Value(new Size(5.0f, 5.0f)), Property.AccessMode.READ_WRITE);
53 Size myProperty2 = new Size(0.0f, 0.0f);
54 handle.GetProperty(myPropertyIndex2).Get(myProperty2);
55 Console.WriteLine( "myProperty2 value: " + myProperty2.W + ", " + myProperty2.H );
57 Actor actor = new Actor();
58 actor.Size = new Position(200.0f, 200.0f, 0.0f);
59 actor.Name = "MyActor";
60 actor.Color = new Color(1.0f, 0.0f, 1.0f, 0.8f);
61 Console.WriteLine("Actor id: {0}", actor.GetId());
62 Console.WriteLine("Actor size: " + actor.Size.X + ", " + actor.Size.Y);
63 Console.WriteLine("Actor name: " + actor.Name);
65 Stage stage = Stage.GetCurrent();
66 stage.BackgroundColor = Color.White;
67 Size stageSize = stage.Size;
68 Console.WriteLine("Stage size: " + stageSize.W + ", " + stageSize.H);
71 TextLabel text = new TextLabel("Hello Mono World");
72 text.ParentOrigin = NDalic.ParentOriginCenter;
73 text.AnchorPoint = NDalic.AnchorPointCenter;
74 text.HorizontalAlignment = "CENTER";
77 Console.WriteLine( "Text label text: " + text.Text );
79 Console.WriteLine( "Text label point size: " + text.PointSize );
80 text.PointSize = 32.0f;
81 Console.WriteLine( "Text label new point size: " + text.PointSize );
83 RectanglePaddingClassTest();
85 Console.WriteLine( " *************************" );
86 Size Size = new Size(100, 50);
87 Console.WriteLine( " Created " + Size );
88 Console.WriteLine( " Size x = " + Size.W + ", y = " + Size.H );
89 Size += new Size(20, 20);
90 Console.WriteLine( " Size x = " + Size.W + ", y = " + Size.H );
93 Console.WriteLine( " Size width = " + Size.W + ", height = " + Size.H );
95 Console.WriteLine( " *************************" );
96 Position Position = new Position(20, 100, 50);
97 Console.WriteLine( " Created " + Position );
98 Console.WriteLine( " Position x = " + Position.X + ", y = " + Position.Y + ", z = " + Position.Z );
99 Position += new Position(20, 20, 20);
100 Console.WriteLine( " Position x = " + Position.X + ", y = " + Position.Y + ", z = " + Position.Z );
104 Console.WriteLine( " Position width = " + Position.X + ", height = " + Position.Y + ", depth = " + Position.Z );
105 Position parentOrigin = new Dali.Position(NDalic.ParentOriginBottomRight);
106 Console.WriteLine( " parentOrigin x = " + parentOrigin.X + ", y = " + parentOrigin.Y + ", z = " + parentOrigin.Z );
108 Console.WriteLine( " *************************" );
109 Color color = new Color(20, 100, 50, 200);
110 Console.WriteLine( " Created " + color );
111 Console.WriteLine( " Color R = " + color.R + ", G = " + color.G + ", B = " + color.B + ", A = " + color.A );
112 color += new Color(20, 20, 20, 20);
113 Console.WriteLine( " Color R = " + color.R + ", G = " + color.G + ", B = " + color.B + ", A = " + color.A );
118 Console.WriteLine( " Color r = " + color.R + ", g = " + color.G + ", b = " + color.B + ", a = " + color.A );
121 public void RectanglePaddingClassTest()
123 using (Rectangle r1 = new Rectangle(2, 5, 20, 30))
125 Console.WriteLine( " Created " + r1 );
126 Console.WriteLine( " IsEmpty() = " + r1.IsEmpty() );
127 Console.WriteLine( " Left = " + r1.Left() );
128 Console.WriteLine( " Right = " + r1.Right() );
129 Console.WriteLine( " Top = " + r1.Top() );
130 Console.WriteLine( " Bottom = " + r1.Bottom() );
131 Console.WriteLine( " Area = " + r1.Area() );
134 Console.WriteLine( " *************************" );
136 using (Rectangle r2 = new Rectangle(2, 5, 20, 30))
138 Console.WriteLine( " Created " + r2 );
140 Console.WriteLine( " IsEmpty() = " + r2.IsEmpty() );
141 Console.WriteLine( " Left = " + r2.Left() );
142 Console.WriteLine( " Right = " + r2.Right() );
143 Console.WriteLine( " Top = " + r2.Top() );
144 Console.WriteLine( " Bottom = " + r2.Bottom() );
145 Console.WriteLine( " Area = " + r2.Area() );
148 Console.WriteLine( " *************************" );
150 Rectangle r3 = new Rectangle(10, 10, 20, 20);
151 Rectangle r4 = new Rectangle(10, 10, 20, 20);
155 Console.WriteLine("r3 == r4");
159 Console.WriteLine("r3 != r4");
162 r4 = new Rectangle(12, 10, 20, 20);
166 Console.WriteLine("r3 == r4");
170 Console.WriteLine("r3 != r4");
173 PaddingType p1 = new PaddingType(10.5f, 10.7f, 20.8f, 20.8f);
174 PaddingType p2 = new PaddingType(10.5f, 10.7f, 20.8f, 20.8f);
178 Console.WriteLine("p1 == p2");
182 Console.WriteLine("p1 != p2");
185 p2 = new PaddingType(12.0f, 10.7f, 20.2f, 20.0f);
189 Console.WriteLine("p1 == p2");
193 Console.WriteLine("p1 != p2");
197 public void OperatorTests()
199 Actor actor = new Actor();
200 Actor differentActor = new Actor();
201 Actor actorSame = actor;
202 Actor nullActor = null;
204 // test the true operator
207 Console.WriteLine ("BaseHandle Operator true (actor) : test passed ");
211 Console.WriteLine ("BaseHandle Operator true (actor): test failed ");
214 Actor parent = actor.GetParent ();
218 Console.WriteLine ("Handle with Empty body :failed ");
222 Console.WriteLine ("Valid with Empty body :passed ");
225 actor.Add( differentActor );
227 // here we test two different C# objects, which on the native side have the same body/ ref-object
228 if ( actor == differentActor.GetParent() )
230 Console.WriteLine ("actor == differentActor.GetParent() :passed ");
234 Console.WriteLine ("actor == differentActor.GetParent() :failed ");
237 if ( differentActor == differentActor.GetParent() )
239 Console.WriteLine ("differentActor == differentActor.GetParent() :failed ");
243 Console.WriteLine ("differentActor == differentActor.GetParent() :passed ");
248 Console.WriteLine ("BaseHandle Operator true (nullActor) : test failed ");
252 Console.WriteLine ("BaseHandle Operator true (nullActor): test passed ");
258 Console.WriteLine ("BaseHandle Operator !(actor) : test failed ");
262 Console.WriteLine ("BaseHandle Operator !(actor): test passed ");
267 Console.WriteLine ("BaseHandle Operator !(nullActor) : test passed ");
271 Console.WriteLine ("BaseHandle Operator !(nullActor): test failed ");
274 // Note: operator false only used inside & operator
275 // test equality operator ==
276 if ( actor == actorSame )
278 Console.WriteLine ("BaseHandle Operator (actor == actorSame) : test passed");
282 Console.WriteLine ("BaseHandle Operator (actor == actorSame) : test failed");
285 if ( actor == differentActor )
287 Console.WriteLine ("BaseHandle Operator (actor == differentActor) : test failed");
291 Console.WriteLine ("BaseHandle Operator (actor == differentActor) : test passed");
294 if ( actor == nullActor )
296 Console.WriteLine ("BaseHandle Operator (actor == nullActor) : test failed");
300 Console.WriteLine ("BaseHandle Operator (actor == nullActor) : test passed");
303 if ( nullActor == nullActor )
305 Console.WriteLine ("BaseHandle Operator (nullActor == nullActor) : test passed");
309 Console.WriteLine ("BaseHandle Operator (nullActor == nullActor) : test failed");
313 if ( actor || actorSame )
315 Console.WriteLine ("BaseHandle Operator (actor || actorSame) : test passed");
319 Console.WriteLine ("BaseHandle Operator (actor || actorSame) : test failed");
322 if ( actor || nullActor )
324 Console.WriteLine ("BaseHandle Operator (actor || nullActor) : test passed");
328 Console.WriteLine ("BaseHandle Operator (actor || nullActor) : test failed");
331 if ( nullActor || nullActor )
333 Console.WriteLine ("BaseHandle Operator (nullActor || nullActor) : test failed");
337 Console.WriteLine ("BaseHandle Operator (nullActor || nullActor) : test passed");
341 if ( actor && actorSame )
343 Console.WriteLine ("BaseHandle Operator (actor && actorSame) : test passed");
347 Console.WriteLine ("BaseHandle Operator (actor && actorSame) : test failed");
350 if ( actor && nullActor )
352 Console.WriteLine ("BaseHandle Operator (actor && nullActor) : test failed");
356 Console.WriteLine ("BaseHandle Operator (actor && nullActor) : test passed");
359 if ( nullActor && nullActor )
361 Console.WriteLine ("BaseHandle Operator (nullActor && nullActor) : test failed");
365 Console.WriteLine ("BaseHandle Operator (nullActor && nullActor) : test passed");
369 public void CustomViewPropertyTest()
371 // Create a Spin control
372 Spin spin = new Spin();
374 // Background property
375 Property.Map background = new Property.Map();
376 background.Add( Dali.Constants.Visual.Property.Type, new Property.Value((int)Dali.Constants.Visual.Type.Color) )
377 .Add( Dali.Constants.ColorVisualProperty.MixColor, new Property.Value(Color.Red) );
378 spin.Background = background;
380 background = spin.Background;
381 Vector4 backgroundColor = new Vector4();
382 background.Find(Dali.Constants.ColorVisualProperty.MixColor).Get(backgroundColor);
383 if( backgroundColor == Color.Red )
385 Console.WriteLine ("Custom View Background property : test passed");
389 Console.WriteLine ("Custom View Background property : test failed");
392 // BackgroundColor property
393 spin.BackgroundColor = Color.Yellow;
394 if(spin.BackgroundColor == Color.Yellow)
396 Console.WriteLine ("Custom View BackgroundColor property : test passed");
400 Console.WriteLine ("Custom View BackgroundColor property : test failed");
403 // StyleName property
404 spin.StyleName = "MyCustomStyle";
405 if(spin.StyleName == "MyCustomStyle")
407 Console.WriteLine ("Custom View StyleName property : test passed");
411 Console.WriteLine ("Custom View StyleName property : test failed");
415 public void MainLoop()
417 _application.MainLoop ();
421 /// The main entry point for the application.
424 static void Main(string[] args)
426 Console.WriteLine ("Hello Mono World");
428 Example example = new Example(Application.NewApplication());