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;
23 namespace MyCSharpExample
27 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
28 delegate void CallbackDelegate(IntPtr appPtr); // void, void delgate
30 private Dali.Application _application;
32 public Example(Dali.Application application)
34 Console.WriteLine( "DBG : Example Constructor.... " );
35 _application = application;
36 Console.WriteLine( "InitSignal connection count = " + _application.InitSignal().GetConnectionCount() );
38 _application.Initialized += Initialize;
39 Console.WriteLine( "InitSignal connection count = " + _application.InitSignal().GetConnectionCount() );
42 public void Initialize(object source, AUIApplicationInitEventArgs e)
45 Console.WriteLine( "DBG : Initializing.... " );
48 Handle handle = new Handle();
49 Console.WriteLine( "DBG : Initializing.... "+ handle );
50 int myPropertyIndex = handle.RegisterProperty("myProperty", new Property.Value(10.0f), Property.AccessMode.READ_WRITE);
51 float myProperty = 0.0f;
52 handle.GetProperty(myPropertyIndex).Get(ref myProperty);
53 Console.WriteLine( "myProperty value: " + myProperty );
55 Size s = new Size(5.0f, 5.0f);
56 Property.Value val = new Property.Value(s);
57 int myPropertyIndex2 = handle.RegisterProperty("myProperty2", val, Property.AccessMode.READ_WRITE);
58 Size myProperty2 = new Size(0.0f, 0.0f);
59 handle.GetProperty(myPropertyIndex2).Get(myProperty2);
60 Console.WriteLine( "myProperty2 value: " + myProperty2.W + ", " + myProperty2.H );
62 Actor actor = new Actor();
63 actor.Size = new Position(200.0f, 200.0f, 0.0f);
64 actor.Name = "MyActor";
65 actor.Color = new Color(Colors.Green);
66 Console.WriteLine("Actor id: {0}", actor.GetId());
67 Console.WriteLine( "DBG : Initializing.... "+ actor.Size.X );
69 Console.WriteLine("Actor size: " + actor.Size.X + ", " + actor.Size.Y);
70 Console.WriteLine("Actor name: " + actor.Name);
72 Stage stage = Stage.GetCurrent();
73 stage.BackgroundColor = new Dali.CSharp.Color(Dali.CSharp.Colors.Blue) ;
75 Size stageSize = stage.Size;
76 Console.WriteLine("Stage size: " + stageSize.W + ", " + stageSize.H);
79 TextLabel text = new TextLabel("Hello Mono World");
80 text.ParentOrigin = new Position(NDalic.ParentOriginCenter);
81 text.AnchorPoint = new Position(NDalic.AnchorPointCenter);
82 text.HorizontalAlignment = "CENTER";
85 Console.WriteLine( "Text label text: " + text.Text );
87 Console.WriteLine( "Text label point size: " + text.PointSize );
88 text.PointSize = 32.0f;
89 Console.WriteLine( "Text label new point size: " + text.PointSize );
91 using (RectInteger ri = new RectInteger(02,05,20,30))
93 Console.WriteLine( " Created " + ri );
94 Console.WriteLine( " IsEmpty() = " + ri.IsEmpty() );
95 Console.WriteLine( " Left = " + ri.Left() );
96 Console.WriteLine( " Right = " + ri.Right() );
97 Console.WriteLine( " Top = " + ri.Top() );
98 Console.WriteLine( " Bottom = " + ri.Bottom() );
99 Console.WriteLine( " Area = " + ri.Area() );
101 Console.WriteLine( " *************************" );
102 using (RectInteger ri2 = new RectInteger(02,05,20,30))
104 Console.WriteLine( " Created " + ri2 );
106 Console.WriteLine( " IsEmpty() = " + ri2.IsEmpty() );
107 Console.WriteLine( " Left = " + ri2.Left() );
108 Console.WriteLine( " Right = " + ri2.Right() );
109 Console.WriteLine( " Top = " + ri2.Top() );
110 Console.WriteLine( " Bottom = " + ri2.Bottom() );
111 Console.WriteLine( " Area = " + ri2.Area() );
113 Console.WriteLine( " *************************" );
114 using (RectDouble rd = new RectDouble(02,05,20.5,30.5))
116 Console.WriteLine( " Created " + rd );
117 Console.WriteLine( " IsEmpty() = " + rd.IsEmpty() );
118 Console.WriteLine( " Left = " + rd.Left() );
119 Console.WriteLine( " Right = " + rd.Right() );
120 Console.WriteLine( " Top = " + rd.Top() );
121 Console.WriteLine( " Bottom = " + rd.Bottom() );
122 Console.WriteLine( " Area = " + rd.Area() );
124 Console.WriteLine( " *************************" );
125 RectDouble rd2 = new RectDouble();
130 Console.WriteLine( " Created " + rd2 );
131 Console.WriteLine( " IsEmpty() = " + rd2.IsEmpty() );
132 Console.WriteLine( " Left = " + rd2.Left() );
133 Console.WriteLine( " Right = " + rd2.Right() );
134 Console.WriteLine( " Top = " + rd2.Top() );
135 Console.WriteLine( " Bottom = " + rd2.Bottom() );
136 Console.WriteLine( " Area = " + rd2.Area() );
138 Console.WriteLine( " *************************" );
139 Size size = new Size(100, 50);
140 Console.WriteLine( " Created " + size );
141 Console.WriteLine( " Size width = " + size.W + ", height = " + size.H );
142 size += new Size(20, 20);
143 Console.WriteLine( " Size W = " + size.W + ", H = " + size.H );
146 Console.WriteLine( " Size width = " + size.W + ", height = " + size.H );
147 size += new Size(15, 15);
148 Console.WriteLine( " Size width = " + size.W + ", height = " + size.H );
150 Console.WriteLine( " *************************" );
151 Dali.CSharp.Position position = new Dali.CSharp.Position(20, 100, 50);
152 Console.WriteLine( " Created " + position );
153 Console.WriteLine( " Position x = " + position.X + ", y = " + position.Y + ", z = " + position.Z );
154 position += new Dali.CSharp.Position(20, 20, 20);
155 Console.WriteLine( " Position x = " + position.X + ", y = " + position.Y + ", z = " + position.Y );
159 Console.WriteLine( " Position width = " + position.X + ", height = " + position.Y + ", depth = " + position.Z );
160 Dali.CSharp.Position parentOrigin = new Dali.CSharp.Position(NDalic.ParentOriginBottomRight);
161 Console.WriteLine( " parentOrigin x = " + parentOrigin.X + ", y = " + parentOrigin.Y + ", z = " + parentOrigin.Z );
163 Console.WriteLine( " *************************" );
164 Dali.CSharp.Color color = new Dali.CSharp.Color(20, 100, 50, 200);
165 Console.WriteLine( " Created " + color );
166 Console.WriteLine( " Color x = " + color.R + ", y = " + color.G + ", z = " + color.B + ", w = " + color.A );
167 color += new Dali.CSharp.Color(20, 20, 20, 20);
168 Console.WriteLine( " Color x = " + color.R + ", y = " + color.G + ", z = " + color.B + ", w = " + color.A );
173 Console.WriteLine( " Color x = " + color.R + ", y = " + color.G + ", z = " + color.B + ", w = " + color.A );
177 public void OperatorTests()
179 Actor actor = new Actor();
180 Actor differentActor = new Actor();
181 Actor actorSame = actor;
182 Actor nullActor = null;
184 // test the true operator
187 Console.WriteLine ("BaseHandle Operator true (actor) : test passed ");
191 Console.WriteLine ("BaseHandle Operator true (actor): test failed ");
194 Actor parent = actor.GetParent ();
198 Console.WriteLine ("Handle with Empty body :failed ");
202 Console.WriteLine ("Valid with Empty body :passed ");
205 actor.Add( differentActor );
206 // here we test two different C# objects, which on the native side have the same body/ ref-object
207 if ( actor == differentActor.GetParent() )
209 Console.WriteLine ("actor == differentActor.GetParent() :passed ");
213 Console.WriteLine ("actor == differentActor.GetParent() :failed ");
216 if ( differentActor == differentActor.GetParent() )
218 Console.WriteLine ("differentActor == differentActor.GetParent() :failed ");
222 Console.WriteLine ("differentActor == differentActor.GetParent() :passed ");
228 Console.WriteLine ("BaseHandle Operator true (nullActor) : test failed ");
232 Console.WriteLine ("BaseHandle Operator true (nullActor): test passed ");
238 Console.WriteLine ("BaseHandle Operator !(actor) : test failed ");
242 Console.WriteLine ("BaseHandle Operator !(actor): test passed ");
247 Console.WriteLine ("BaseHandle Operator !(nullActor) : test passed ");
251 Console.WriteLine ("BaseHandle Operator !(nullActor): test failed ");
254 // Note: operator false only used inside & operator
255 // test equality operator ==
256 if ( actor == actorSame )
258 Console.WriteLine ("BaseHandle Operator (actor == actorSame) : test passed");
262 Console.WriteLine ("BaseHandle Operator (actor == actorSame) : test failed");
265 if ( actor == differentActor )
267 Console.WriteLine ("BaseHandle Operator (actor == differentActor) : test failed");
271 Console.WriteLine ("BaseHandle Operator (actor == differentActor) : test passed");
274 if ( actor == nullActor )
276 Console.WriteLine ("BaseHandle Operator (actor == nullActor) : test failed");
280 Console.WriteLine ("BaseHandle Operator (actor == nullActor) : test passed");
283 if ( nullActor == nullActor )
285 Console.WriteLine ("BaseHandle Operator (nullActor == nullActor) : test passed");
289 Console.WriteLine ("BaseHandle Operator (nullActor == nullActor) : test failed");
293 if ( actor || actorSame )
295 Console.WriteLine ("BaseHandle Operator (actor || actorSame) : test passed");
299 Console.WriteLine ("BaseHandle Operator (actor || actorSame) : test failed");
302 if ( actor || nullActor )
304 Console.WriteLine ("BaseHandle Operator (actor || nullActor) : test passed");
308 Console.WriteLine ("BaseHandle Operator (actor || nullActor) : test failed");
311 if ( nullActor || nullActor )
313 Console.WriteLine ("BaseHandle Operator (nullActor || nullActor) : test failed");
317 Console.WriteLine ("BaseHandle Operator (nullActor || nullActor) : test passed");
322 if ( actor && actorSame )
324 Console.WriteLine ("BaseHandle Operator (actor && actorSame) : test passed");
328 Console.WriteLine ("BaseHandle Operator (actor && actorSame) : test failed");
331 if ( actor && nullActor )
333 Console.WriteLine ("BaseHandle Operator (actor && nullActor) : test failed");
337 Console.WriteLine ("BaseHandle Operator (actor && nullActor) : test passed");
340 if ( nullActor && nullActor )
342 Console.WriteLine ("BaseHandle Operator (nullActor && nullActor) : test failed");
346 Console.WriteLine ("BaseHandle Operator (nullActor && nullActor) : test passed");
351 public void MainLoop()
353 _application.MainLoop ();
357 /// The main entry point for the application.
360 static void Main(string[] args)
362 Console.WriteLine ("Hello Mono World");
364 Example example = new Example(Application.NewApplication());