Merge "Dali C#: Common Interface Define related changes" into devel/master
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / examples / dali-test.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 using System;
19 using System.Runtime.InteropServices;
20 using Dali;
21
22 namespace MyCSharpExample
23 {
24   class Example
25   {
26     [UnmanagedFunctionPointer(CallingConvention.StdCall)]
27     delegate void CallbackDelegate(IntPtr appPtr); // void, void delgate
28
29     private Dali.Application _application;
30
31     public Example(Dali.Application application)
32     {
33       _application = application;
34       Console.WriteLine( "InitSignal connection count = " + _application.InitSignal().GetConnectionCount() );
35
36       _application.Initialized += Initialize;
37       Console.WriteLine( "InitSignal connection count = " + _application.InitSignal().GetConnectionCount() );
38     }
39
40     public void Initialize(object source, NUIApplicationInitEventArgs e)
41     {
42
43       OperatorTests();
44
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 );
50
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 );
55
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);
63
64       Stage stage = Stage.GetCurrent();
65       stage.BackgroundColor = Color.White;
66
67       Size stageSize = stage.Size;
68       Console.WriteLine("Stage size: " + stageSize.W + ", " + stageSize.H);
69       stage.Add(actor);
70
71       TextLabel text = new TextLabel("Hello Mono World");
72       text.ParentOrigin = NDalic.ParentOriginCenter;
73       text.AnchorPoint = NDalic.AnchorPointCenter;
74       text.HorizontalAlignment = "CENTER";
75       stage.Add(text);
76
77       Console.WriteLine( "Text label text:  " + text.Text );
78
79       Console.WriteLine( "Text label point size:  " + text.PointSize );
80       text.PointSize = 32.0f;
81       Console.WriteLine( "Text label new point size:  " + text.PointSize );
82
83       using (RectInteger ri = new RectInteger(02,05,20,30))
84       {
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() );
92       }
93       Console.WriteLine( " *************************" );
94       using (RectInteger ri2 = new RectInteger(02,05,20,30))
95       {
96         Console.WriteLine( "    Created " + ri2 );
97         ri2.Set(1,1,40,40);
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() );
104       }
105       Console.WriteLine( " *************************" );
106       using (RectDouble rd = new RectDouble(02,05,20.5,30.5))
107       {
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() );
115       }
116       Console.WriteLine( " *************************" );
117       RectDouble rd2 = new RectDouble();
118       rd2.x = 10;
119       rd2.y = 10;
120       rd2.width = 20;
121       rd2.height = 20;
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() );
129
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 );
136       Size.W += 10;
137       Size.H += 10;
138       Console.WriteLine( "    Size width =  " + Size.W + ", height = " + Size.H );
139
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 );
146       Position.X += 10;
147       Position.Y += 10;
148       Position.Z += 10;
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 );
152
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 );
159       color.R += 10;
160       color.G += 10;
161       color.B += 10;
162       color.A += 10;
163       Console.WriteLine( "    Color r =  " + color.R + ", g = " + color.G + ", b = " + color.B + ", a = " + color.A );
164     }
165
166
167   public void OperatorTests()
168   {
169     Actor actor = new Actor();
170     Actor differentActor = new Actor();
171     Actor actorSame = actor;
172     Actor nullActor = null;
173
174       // test the true operator
175     if ( actor )
176     {
177       Console.WriteLine ("BaseHandle Operator true (actor) : test passed ");
178     }
179     else
180     {
181       Console.WriteLine ("BaseHandle Operator true (actor): test failed ");
182     }
183
184     Actor parent = actor.GetParent ();
185
186     if ( parent )
187     {
188       Console.WriteLine ("Handle with Empty body  :failed ");
189     }
190     else
191     {
192       Console.WriteLine ("Valid with Empty body  :passed ");
193     }
194
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() )
198     {
199        Console.WriteLine ("actor == differentActor.GetParent() :passed ");
200     }
201     else
202     {
203       Console.WriteLine ("actor == differentActor.GetParent() :failed ");
204     }
205
206     if ( differentActor == differentActor.GetParent() )
207     {
208        Console.WriteLine ("differentActor == differentActor.GetParent() :failed ");
209     }
210     else
211     {
212       Console.WriteLine ("differentActor == differentActor.GetParent() :passed ");
213     }
214
215
216     if ( nullActor )
217     {
218       Console.WriteLine ("BaseHandle Operator true (nullActor) : test failed ");
219     }
220     else
221     {
222       Console.WriteLine ("BaseHandle Operator true (nullActor): test passed ");
223     }
224
225     // ! operator
226     if ( !actor )
227     {
228       Console.WriteLine ("BaseHandle Operator !(actor) : test failed ");
229     }
230     else
231     {
232       Console.WriteLine ("BaseHandle Operator !(actor): test passed ");
233     }
234
235     if ( !nullActor )
236     {
237       Console.WriteLine ("BaseHandle Operator !(nullActor) : test passed ");
238     }
239     else
240     {
241       Console.WriteLine ("BaseHandle Operator !(nullActor): test failed ");
242     }
243
244     // Note: operator false only used inside & operator
245     // test equality operator ==
246     if ( actor == actorSame )
247     {
248       Console.WriteLine ("BaseHandle Operator  (actor == actorSame) : test passed");
249     }
250     else
251     {
252       Console.WriteLine ("BaseHandle Operator  (actor == actorSame) : test failed");
253     }
254
255     if ( actor == differentActor )
256     {
257       Console.WriteLine ("BaseHandle Operator (actor == differentActor) : test failed");
258     }
259     else
260     {
261       Console.WriteLine ("BaseHandle Operator (actor == differentActor) : test passed");
262     }
263
264     if ( actor == nullActor )
265     {
266       Console.WriteLine ("BaseHandle Operator (actor == nullActor) : test failed");
267     }
268     else
269     {
270       Console.WriteLine ("BaseHandle Operator (actor == nullActor) : test passed");
271     }
272
273     if ( nullActor == nullActor )
274     {
275       Console.WriteLine ("BaseHandle Operator (nullActor == nullActor) : test passed");
276     }
277     else
278     {
279       Console.WriteLine ("BaseHandle Operator (nullActor == nullActor) : test failed");
280     }
281
282     // test || operator
283     if ( actor || actorSame )
284     {
285       Console.WriteLine ("BaseHandle Operator (actor || actorSame) : test passed");
286     }
287     else
288     {
289       Console.WriteLine ("BaseHandle Operator (actor || actorSame) : test failed");
290     }
291
292     if ( actor || nullActor )
293     {
294       Console.WriteLine ("BaseHandle Operator (actor || nullActor) : test passed");
295     }
296     else
297     {
298       Console.WriteLine ("BaseHandle Operator (actor || nullActor) : test failed");
299     }
300
301     if ( nullActor || nullActor )
302     {
303       Console.WriteLine ("BaseHandle Operator (nullActor || nullActor) : test failed");
304     }
305     else
306     {
307       Console.WriteLine ("BaseHandle Operator (nullActor || nullActor) : test passed");
308     }
309
310
311     // test && operator
312     if ( actor && actorSame )
313     {
314       Console.WriteLine ("BaseHandle Operator (actor && actorSame) : test passed");
315     }
316     else
317     {
318       Console.WriteLine ("BaseHandle Operator (actor && actorSame) : test failed");
319     }
320
321     if ( actor && nullActor )
322     {
323       Console.WriteLine ("BaseHandle Operator (actor && nullActor) : test failed");
324     }
325     else
326     {
327       Console.WriteLine ("BaseHandle Operator (actor && nullActor) : test passed");
328     }
329
330     if ( nullActor && nullActor )
331     {
332       Console.WriteLine ("BaseHandle Operator (nullActor && nullActor) : test failed");
333     }
334     else
335     {
336       Console.WriteLine ("BaseHandle Operator (nullActor && nullActor) : test passed");
337     }
338
339   }
340
341     public void MainLoop()
342     {
343       _application.MainLoop ();
344     }
345
346     /// <summary>
347     /// The main entry point for the application.
348     /// </summary>
349     [STAThread]
350       static void Main(string[] args)
351       {
352         Console.WriteLine ("Hello Mono World");
353
354         Example example = new Example(Application.NewApplication());
355         example.MainLoop ();
356       }
357   }
358 }