2 * Copyright (c) 2016 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;
68 Size stageSize = stage.Size;
69 Console.WriteLine("Stage size: " + stageSize.W + ", " + stageSize.H);
72 TextLabel text = new TextLabel("Hello Mono World");
73 text.ParentOrigin = NDalic.ParentOriginCenter;
74 text.AnchorPoint = NDalic.AnchorPointCenter;
75 text.HorizontalAlignment = "CENTER";
78 Console.WriteLine( "Text label text: " + text.Text );
80 Console.WriteLine( "Text label point size: " + text.PointSize );
81 text.PointSize = 32.0f;
82 Console.WriteLine( "Text label new point size: " + text.PointSize );
84 using (RectInteger ri = new RectInteger(02,05,20,30))
86 Console.WriteLine( " Created " + ri );
87 Console.WriteLine( " IsEmpty() = " + ri.IsEmpty() );
88 Console.WriteLine( " Left = " + ri.Left() );
89 Console.WriteLine( " Right = " + ri.Right() );
90 Console.WriteLine( " Top = " + ri.Top() );
91 Console.WriteLine( " Bottom = " + ri.Bottom() );
92 Console.WriteLine( " Area = " + ri.Area() );
94 Console.WriteLine( " *************************" );
95 using (RectInteger ri2 = new RectInteger(02,05,20,30))
97 Console.WriteLine( " Created " + ri2 );
99 Console.WriteLine( " IsEmpty() = " + ri2.IsEmpty() );
100 Console.WriteLine( " Left = " + ri2.Left() );
101 Console.WriteLine( " Right = " + ri2.Right() );
102 Console.WriteLine( " Top = " + ri2.Top() );
103 Console.WriteLine( " Bottom = " + ri2.Bottom() );
104 Console.WriteLine( " Area = " + ri2.Area() );
106 Console.WriteLine( " *************************" );
107 using (RectDouble rd = new RectDouble(02,05,20.5,30.5))
109 Console.WriteLine( " Created " + rd );
110 Console.WriteLine( " IsEmpty() = " + rd.IsEmpty() );
111 Console.WriteLine( " Left = " + rd.Left() );
112 Console.WriteLine( " Right = " + rd.Right() );
113 Console.WriteLine( " Top = " + rd.Top() );
114 Console.WriteLine( " Bottom = " + rd.Bottom() );
115 Console.WriteLine( " Area = " + rd.Area() );
117 Console.WriteLine( " *************************" );
118 RectDouble rd2 = new RectDouble();
123 Console.WriteLine( " Created " + rd2 );
124 Console.WriteLine( " IsEmpty() = " + rd2.IsEmpty() );
125 Console.WriteLine( " Left = " + rd2.Left() );
126 Console.WriteLine( " Right = " + rd2.Right() );
127 Console.WriteLine( " Top = " + rd2.Top() );
128 Console.WriteLine( " Bottom = " + rd2.Bottom() );
129 Console.WriteLine( " Area = " + rd2.Area() );
131 Console.WriteLine( " *************************" );
132 Size Size = new Size(100, 50);
133 Console.WriteLine( " Created " + Size );
134 Console.WriteLine( " Size x = " + Size.W + ", y = " + Size.H );
135 Size += new Size(20, 20);
136 Console.WriteLine( " Size x = " + Size.W + ", y = " + Size.H );
139 Console.WriteLine( " Size width = " + Size.W + ", height = " + Size.H );
141 Console.WriteLine( " *************************" );
142 Position Position = new Position(20, 100, 50);
143 Console.WriteLine( " Created " + Position );
144 Console.WriteLine( " Position x = " + Position.X + ", y = " + Position.Y + ", z = " + Position.Z );
145 Position += new Position(20, 20, 20);
146 Console.WriteLine( " Position x = " + Position.X + ", y = " + Position.Y + ", z = " + Position.Z );
150 Console.WriteLine( " Position width = " + Position.X + ", height = " + Position.Y + ", depth = " + Position.Z );
151 Position parentOrigin = new Dali.Position(NDalic.ParentOriginBottomRight);
152 Console.WriteLine( " parentOrigin x = " + parentOrigin.X + ", y = " + parentOrigin.Y + ", z = " + parentOrigin.Z );
154 Console.WriteLine( " *************************" );
155 Color color = new Color(20, 100, 50, 200);
156 Console.WriteLine( " Created " + color );
157 Console.WriteLine( " Color R = " + color.R + ", G = " + color.G + ", B = " + color.B + ", A = " + color.A );
158 color += new Color(20, 20, 20, 20);
159 Console.WriteLine( " Color R = " + color.R + ", G = " + color.G + ", B = " + color.B + ", A = " + color.A );
164 Console.WriteLine( " Color r = " + color.R + ", g = " + color.G + ", b = " + color.B + ", a = " + color.A );
168 public void OperatorTests()
170 Actor actor = new Actor();
171 Actor differentActor = new Actor();
172 Actor actorSame = actor;
173 Actor nullActor = null;
175 // test the true operator
178 Console.WriteLine ("BaseHandle Operator true (actor) : test passed ");
182 Console.WriteLine ("BaseHandle Operator true (actor): test failed ");
185 Actor parent = actor.GetParent ();
189 Console.WriteLine ("Handle with Empty body :failed ");
193 Console.WriteLine ("Valid with Empty body :passed ");
196 actor.Add( differentActor );
197 // here we test two different C# objects, which on the native side have the same body/ ref-object
198 if ( actor == differentActor.GetParent() )
200 Console.WriteLine ("actor == differentActor.GetParent() :passed ");
204 Console.WriteLine ("actor == differentActor.GetParent() :failed ");
207 if ( differentActor == differentActor.GetParent() )
209 Console.WriteLine ("differentActor == differentActor.GetParent() :failed ");
213 Console.WriteLine ("differentActor == differentActor.GetParent() :passed ");
219 Console.WriteLine ("BaseHandle Operator true (nullActor) : test failed ");
223 Console.WriteLine ("BaseHandle Operator true (nullActor): test passed ");
229 Console.WriteLine ("BaseHandle Operator !(actor) : test failed ");
233 Console.WriteLine ("BaseHandle Operator !(actor): test passed ");
238 Console.WriteLine ("BaseHandle Operator !(nullActor) : test passed ");
242 Console.WriteLine ("BaseHandle Operator !(nullActor): test failed ");
245 // Note: operator false only used inside & operator
246 // test equality operator ==
247 if ( actor == actorSame )
249 Console.WriteLine ("BaseHandle Operator (actor == actorSame) : test passed");
253 Console.WriteLine ("BaseHandle Operator (actor == actorSame) : test failed");
256 if ( actor == differentActor )
258 Console.WriteLine ("BaseHandle Operator (actor == differentActor) : test failed");
262 Console.WriteLine ("BaseHandle Operator (actor == differentActor) : test passed");
265 if ( actor == nullActor )
267 Console.WriteLine ("BaseHandle Operator (actor == nullActor) : test failed");
271 Console.WriteLine ("BaseHandle Operator (actor == nullActor) : test passed");
274 if ( nullActor == nullActor )
276 Console.WriteLine ("BaseHandle Operator (nullActor == nullActor) : test passed");
280 Console.WriteLine ("BaseHandle Operator (nullActor == nullActor) : test failed");
284 if ( actor || actorSame )
286 Console.WriteLine ("BaseHandle Operator (actor || actorSame) : test passed");
290 Console.WriteLine ("BaseHandle Operator (actor || actorSame) : test failed");
293 if ( actor || nullActor )
295 Console.WriteLine ("BaseHandle Operator (actor || nullActor) : test passed");
299 Console.WriteLine ("BaseHandle Operator (actor || nullActor) : test failed");
302 if ( nullActor || nullActor )
304 Console.WriteLine ("BaseHandle Operator (nullActor || nullActor) : test failed");
308 Console.WriteLine ("BaseHandle Operator (nullActor || nullActor) : test passed");
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 failed");
328 Console.WriteLine ("BaseHandle Operator (actor && nullActor) : test passed");
331 if ( nullActor && nullActor )
333 Console.WriteLine ("BaseHandle Operator (nullActor && nullActor) : test failed");
337 Console.WriteLine ("BaseHandle Operator (nullActor && nullActor) : test passed");
342 public void CustomViewPropertyTest()
344 // Create a Spin control
345 Spin spin = new Spin();
347 // Background property
348 Property.Map background = new Property.Map();
349 background.Add( Dali.Constants.Visual.Property.Type, new Property.Value((int)Dali.Constants.Visual.Type.Color) )
350 .Add( Dali.Constants.ColorVisualProperty.MixColor, new Property.Value(Color.Red) );
351 spin.Background = background;
353 background = spin.Background;
354 Vector4 backgroundColor = new Vector4();
355 background.Find(Dali.Constants.ColorVisualProperty.MixColor).Get(backgroundColor);
356 if( backgroundColor == Color.Red )
358 Console.WriteLine ("Custom View Background property : test passed");
362 Console.WriteLine ("Custom View Background property : test failed");
365 // BackgroundColor property
366 spin.BackgroundColor = Color.Yellow;
367 if(spin.BackgroundColor == Color.Yellow)
369 Console.WriteLine ("Custom View BackgroundColor property : test passed");
373 Console.WriteLine ("Custom View BackgroundColor property : test failed");
376 // StyleName property
377 spin.StyleName = "MyCustomStyle";
378 if(spin.StyleName == "MyCustomStyle")
380 Console.WriteLine ("Custom View StyleName property : test passed");
384 Console.WriteLine ("Custom View StyleName property : test failed");
388 public void MainLoop()
390 _application.MainLoop ();
394 /// The main entry point for the application.
397 static void Main(string[] args)
399 Console.WriteLine ("Hello Mono World");
401 Example example = new Example(Application.NewApplication());