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)
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.W + ", " + myProperty2.H );
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 = 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 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.W + ", y = " + Size.H );
134 Size += new Size(20, 20);
135 Console.WriteLine( " Size x = " + Size.W + ", y = " + Size.H );
138 Console.WriteLine( " Size width = " + Size.W + ", height = " + Size.H );
140 Console.WriteLine( " *************************" );
141 Position Position = new Position(20, 100, 50);
142 Console.WriteLine( " Created " + Position );
143 Console.WriteLine( " Position x = " + Position.X + ", y = " + Position.Y + ", z = " + Position.Z );
144 Position += new Position(20, 20, 20);
145 Console.WriteLine( " Position x = " + Position.X + ", y = " + Position.Y + ", z = " + Position.Z );
149 Console.WriteLine( " Position width = " + Position.X + ", height = " + Position.Y + ", depth = " + Position.Z );
150 Position parentOrigin = new Dali.Position(NDalic.ParentOriginBottomRight);
151 Console.WriteLine( " parentOrigin x = " + parentOrigin.X + ", y = " + parentOrigin.Y + ", z = " + parentOrigin.Z );
153 Console.WriteLine( " *************************" );
154 Color color = new Color(20, 100, 50, 200);
155 Console.WriteLine( " Created " + color );
156 Console.WriteLine( " Color R = " + color.R + ", G = " + color.G + ", B = " + color.B + ", A = " + color.A );
157 color += new Color(20, 20, 20, 20);
158 Console.WriteLine( " Color R = " + color.R + ", G = " + color.G + ", B = " + color.B + ", A = " + color.A );
163 Console.WriteLine( " Color r = " + color.R + ", g = " + color.G + ", b = " + color.B + ", a = " + color.A );
167 public void OperatorTests()
169 Actor actor = new Actor();
170 Actor differentActor = new Actor();
171 Actor actorSame = actor;
172 Actor nullActor = null;
174 // test the true operator
177 Console.WriteLine ("BaseHandle Operator true (actor) : test passed ");
181 Console.WriteLine ("BaseHandle Operator true (actor): test failed ");
184 Actor parent = actor.GetParent ();
188 Console.WriteLine ("Handle with Empty body :failed ");
192 Console.WriteLine ("Valid with Empty body :passed ");
195 actor.Add( differentActor );
196 // here we test two different C# objects, which on the native side have the same body/ ref-object
197 if ( actor == differentActor.GetParent() )
199 Console.WriteLine ("actor == differentActor.GetParent() :passed ");
203 Console.WriteLine ("actor == differentActor.GetParent() :failed ");
206 if ( differentActor == differentActor.GetParent() )
208 Console.WriteLine ("differentActor == differentActor.GetParent() :failed ");
212 Console.WriteLine ("differentActor == differentActor.GetParent() :passed ");
218 Console.WriteLine ("BaseHandle Operator true (nullActor) : test failed ");
222 Console.WriteLine ("BaseHandle Operator true (nullActor): test passed ");
228 Console.WriteLine ("BaseHandle Operator !(actor) : test failed ");
232 Console.WriteLine ("BaseHandle Operator !(actor): test passed ");
237 Console.WriteLine ("BaseHandle Operator !(nullActor) : test passed ");
241 Console.WriteLine ("BaseHandle Operator !(nullActor): test failed ");
244 // Note: operator false only used inside & operator
245 // test equality operator ==
246 if ( actor == actorSame )
248 Console.WriteLine ("BaseHandle Operator (actor == actorSame) : test passed");
252 Console.WriteLine ("BaseHandle Operator (actor == actorSame) : test failed");
255 if ( actor == differentActor )
257 Console.WriteLine ("BaseHandle Operator (actor == differentActor) : test failed");
261 Console.WriteLine ("BaseHandle Operator (actor == differentActor) : test passed");
264 if ( actor == nullActor )
266 Console.WriteLine ("BaseHandle Operator (actor == nullActor) : test failed");
270 Console.WriteLine ("BaseHandle Operator (actor == nullActor) : test passed");
273 if ( nullActor == nullActor )
275 Console.WriteLine ("BaseHandle Operator (nullActor == nullActor) : test passed");
279 Console.WriteLine ("BaseHandle Operator (nullActor == nullActor) : test failed");
283 if ( actor || actorSame )
285 Console.WriteLine ("BaseHandle Operator (actor || actorSame) : test passed");
289 Console.WriteLine ("BaseHandle Operator (actor || actorSame) : test failed");
292 if ( actor || nullActor )
294 Console.WriteLine ("BaseHandle Operator (actor || nullActor) : test passed");
298 Console.WriteLine ("BaseHandle Operator (actor || nullActor) : test failed");
301 if ( nullActor || nullActor )
303 Console.WriteLine ("BaseHandle Operator (nullActor || nullActor) : test failed");
307 Console.WriteLine ("BaseHandle Operator (nullActor || nullActor) : test passed");
312 if ( actor && actorSame )
314 Console.WriteLine ("BaseHandle Operator (actor && actorSame) : test passed");
318 Console.WriteLine ("BaseHandle Operator (actor && actorSame) : test failed");
321 if ( actor && nullActor )
323 Console.WriteLine ("BaseHandle Operator (actor && nullActor) : test failed");
327 Console.WriteLine ("BaseHandle Operator (actor && nullActor) : test passed");
330 if ( nullActor && nullActor )
332 Console.WriteLine ("BaseHandle Operator (nullActor && nullActor) : test failed");
336 Console.WriteLine ("BaseHandle Operator (nullActor && nullActor) : test passed");
341 public void MainLoop()
343 _application.MainLoop ();
347 /// The main entry point for the application.
350 static void Main(string[] args)
352 Console.WriteLine ("Hello Mono World");
354 Example example = new Example(Application.NewApplication());