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, AUIApplicationInitEventArgs e)
45 Handle handle = new Handle();
46 int myPropertyIndex = handle.RegisterProperty("myProperty", new Property.Value(10.0f), Property.AccessMode.READ_WRITE);
47 float myProperty = 0.0f;
48 handle.GetProperty(myPropertyIndex).Get(ref myProperty);
49 Console.WriteLine( "myProperty value: " + myProperty );
51 int myPropertyIndex2 = handle.RegisterProperty("myProperty2", new Property.Value(new Size(5.0f, 5.0f)), Property.AccessMode.READ_WRITE);
52 Size myProperty2 = new Size(0.0f, 0.0f);
53 handle.GetProperty(myPropertyIndex2).Get(myProperty2);
54 Console.WriteLine( "myProperty2 value: " + myProperty2.x + ", " + myProperty2.y );
56 Actor actor = new Actor();
57 actor.Size = new Position(200.0f, 200.0f, 0.0f);
58 actor.Name = "MyActor";
59 actor.Color = new Color(1.0f, 0.0f, 1.0f, 0.8f);
60 Console.WriteLine("Actor id: {0}", actor.GetId());
61 Console.WriteLine("Actor size: " + actor.Size.x + ", " + actor.Size.y);
62 Console.WriteLine("Actor name: " + actor.Name);
64 Stage stage = Stage.GetCurrent();
65 stage.BackgroundColor = new Color("white") ;
67 Size stageSize = stage.Size;
68 Console.WriteLine("Stage size: " + stageSize.x + ", " + stageSize.y);
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 using (RectInteger ri = new RectInteger(02,05,20,30))
85 Console.WriteLine( " Created " + ri );
86 Console.WriteLine( " IsEmpty() = " + ri.IsEmpty() );
87 Console.WriteLine( " Left = " + ri.Left() );
88 Console.WriteLine( " Right = " + ri.Right() );
89 Console.WriteLine( " Top = " + ri.Top() );
90 Console.WriteLine( " Bottom = " + ri.Bottom() );
91 Console.WriteLine( " Area = " + ri.Area() );
93 Console.WriteLine( " *************************" );
94 using (RectInteger ri2 = new RectInteger(02,05,20,30))
96 Console.WriteLine( " Created " + ri2 );
98 Console.WriteLine( " IsEmpty() = " + ri2.IsEmpty() );
99 Console.WriteLine( " Left = " + ri2.Left() );
100 Console.WriteLine( " Right = " + ri2.Right() );
101 Console.WriteLine( " Top = " + ri2.Top() );
102 Console.WriteLine( " Bottom = " + ri2.Bottom() );
103 Console.WriteLine( " Area = " + ri2.Area() );
105 Console.WriteLine( " *************************" );
106 using (RectDouble rd = new RectDouble(02,05,20.5,30.5))
108 Console.WriteLine( " Created " + rd );
109 Console.WriteLine( " IsEmpty() = " + rd.IsEmpty() );
110 Console.WriteLine( " Left = " + rd.Left() );
111 Console.WriteLine( " Right = " + rd.Right() );
112 Console.WriteLine( " Top = " + rd.Top() );
113 Console.WriteLine( " Bottom = " + rd.Bottom() );
114 Console.WriteLine( " Area = " + rd.Area() );
116 Console.WriteLine( " *************************" );
117 RectDouble rd2 = new RectDouble();
122 Console.WriteLine( " Created " + rd2 );
123 Console.WriteLine( " IsEmpty() = " + rd2.IsEmpty() );
124 Console.WriteLine( " Left = " + rd2.Left() );
125 Console.WriteLine( " Right = " + rd2.Right() );
126 Console.WriteLine( " Top = " + rd2.Top() );
127 Console.WriteLine( " Bottom = " + rd2.Bottom() );
128 Console.WriteLine( " Area = " + rd2.Area() );
130 Console.WriteLine( " *************************" );
131 Size Size = new Size(100, 50);
132 Console.WriteLine( " Created " + Size );
133 Console.WriteLine( " Size x = " + Size.x + ", y = " + Size.y );
134 Size += new Size(20, 20);
135 Console.WriteLine( " Size x = " + Size[0] + ", y = " + Size[1] );
138 Console.WriteLine( " Size width = " + Size.width + ", height = " + Size.height );
139 Size += new Size(15, 15);
140 Console.WriteLine( " Size width = " + Size[0] + ", height = " + Size[1] );
142 Console.WriteLine( " *************************" );
143 Position Position = new Position(20, 100, 50);
144 Console.WriteLine( " Created " + Position );
145 Console.WriteLine( " Position x = " + Position.x + ", y = " + Position.y + ", z = " + Position.z );
146 Position += new Position(20, 20, 20);
147 Console.WriteLine( " Position x = " + Position[0] + ", y = " + Position[1] + ", z = " + Position[2] );
151 Console.WriteLine( " Position width = " + Position.width + ", height = " + Position.height + ", depth = " + Position.depth );
152 Position parentOrigin = new Dali.Position(NDalic.ParentOriginBottomRight);
153 Console.WriteLine( " parentOrigin x = " + parentOrigin.x + ", y = " + parentOrigin.y + ", z = " + parentOrigin.z );
155 Console.WriteLine( " *************************" );
156 Color Color = new Color(20, 100, 50, 200);
157 Console.WriteLine( " Created " + Color );
158 Console.WriteLine( " Color x = " + Color.x + ", y = " + Color.y + ", z = " + Color.z + ", w = " + Color.w );
159 Color += new Color(20, 20, 20, 20);
160 Console.WriteLine( " Color x = " + Color[0] + ", y = " + Color[1] + ", z = " + Color[2] + ", w = " + Color[3] );
165 Console.WriteLine( " Color r = " + Color.r + ", g = " + Color.g + ", b = " + Color.b + ", a = " + Color.a );
169 public void OperatorTests()
171 Actor actor = new Actor();
172 Actor differentActor = new Actor();
173 Actor actorSame = actor;
174 Actor nullActor = null;
176 // test the true operator
179 Console.WriteLine ("BaseHandle Operator true (actor) : test passed ");
183 Console.WriteLine ("BaseHandle Operator true (actor): test failed ");
186 Actor parent = actor.GetParent ();
190 Console.WriteLine ("Handle with Empty body :failed ");
194 Console.WriteLine ("Valid with Empty body :passed ");
197 actor.Add( differentActor );
198 // here we test two different C# objects, which on the native side have the same body/ ref-object
199 if ( actor == differentActor.GetParent() )
201 Console.WriteLine ("actor == differentActor.GetParent() :passed ");
205 Console.WriteLine ("actor == differentActor.GetParent() :failed ");
208 if ( differentActor == differentActor.GetParent() )
210 Console.WriteLine ("differentActor == differentActor.GetParent() :failed ");
214 Console.WriteLine ("differentActor == differentActor.GetParent() :passed ");
220 Console.WriteLine ("BaseHandle Operator true (nullActor) : test failed ");
224 Console.WriteLine ("BaseHandle Operator true (nullActor): test passed ");
230 Console.WriteLine ("BaseHandle Operator !(actor) : test failed ");
234 Console.WriteLine ("BaseHandle Operator !(actor): test passed ");
239 Console.WriteLine ("BaseHandle Operator !(nullActor) : test passed ");
243 Console.WriteLine ("BaseHandle Operator !(nullActor): test failed ");
246 // Note: operator false only used inside & operator
247 // test equality operator ==
248 if ( actor == actorSame )
250 Console.WriteLine ("BaseHandle Operator (actor == actorSame) : test passed");
254 Console.WriteLine ("BaseHandle Operator (actor == actorSame) : test failed");
257 if ( actor == differentActor )
259 Console.WriteLine ("BaseHandle Operator (actor == differentActor) : test failed");
263 Console.WriteLine ("BaseHandle Operator (actor == differentActor) : test passed");
266 if ( actor == nullActor )
268 Console.WriteLine ("BaseHandle Operator (actor == nullActor) : test failed");
272 Console.WriteLine ("BaseHandle Operator (actor == nullActor) : test passed");
275 if ( nullActor == nullActor )
277 Console.WriteLine ("BaseHandle Operator (nullActor == nullActor) : test passed");
281 Console.WriteLine ("BaseHandle Operator (nullActor == nullActor) : test failed");
285 if ( actor || actorSame )
287 Console.WriteLine ("BaseHandle Operator (actor || actorSame) : test passed");
291 Console.WriteLine ("BaseHandle Operator (actor || actorSame) : test failed");
294 if ( actor || nullActor )
296 Console.WriteLine ("BaseHandle Operator (actor || nullActor) : test passed");
300 Console.WriteLine ("BaseHandle Operator (actor || nullActor) : test failed");
303 if ( nullActor || nullActor )
305 Console.WriteLine ("BaseHandle Operator (nullActor || nullActor) : test failed");
309 Console.WriteLine ("BaseHandle Operator (nullActor || nullActor) : test passed");
314 if ( actor && actorSame )
316 Console.WriteLine ("BaseHandle Operator (actor && actorSame) : test passed");
320 Console.WriteLine ("BaseHandle Operator (actor && actorSame) : test failed");
323 if ( actor && nullActor )
325 Console.WriteLine ("BaseHandle Operator (actor && nullActor) : test failed");
329 Console.WriteLine ("BaseHandle Operator (actor && nullActor) : test passed");
332 if ( nullActor && nullActor )
334 Console.WriteLine ("BaseHandle Operator (nullActor && nullActor) : test failed");
338 Console.WriteLine ("BaseHandle Operator (nullActor && nullActor) : test passed");
343 public void MainLoop()
345 _application.MainLoop ();
349 /// The main entry point for the application.
352 static void Main(string[] args)
354 Console.WriteLine ("Hello Mono World");
356 Example example = new Example(Application.NewApplication());