Merge "Fix PageFactory to take in Texture rather than Image" 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, AUIApplicationInitEventArgs 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.x + ", " + myProperty2.y );
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 =  new Color("white") ;
66
67       Size stageSize = stage.Size;
68       Console.WriteLine("Stage size: " + stageSize.x + ", " + stageSize.y);
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.x + ", y = " + Size.y );
134       Size += new Size(20, 20);
135       Console.WriteLine( "    Size x =  " + Size[0] + ", y = " + Size[1] );
136       Size.x += 10;
137       Size.y += 10;
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] );
141
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] );
148       Position.x += 10;
149       Position.y += 10;
150       Position.z += 10;
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 );
154
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] );
161       Color.x += 10;
162       Color.y += 10;
163       Color.z += 10;
164       Color.w += 10;
165       Console.WriteLine( "    Color r =  " + Color.r + ", g = " + Color.g + ", b = " + Color.b + ", a = " + Color.a );
166     }
167
168
169   public void OperatorTests()
170   {
171     Actor actor = new Actor();
172     Actor differentActor = new Actor();
173     Actor actorSame = actor;
174     Actor nullActor = null;
175
176       // test the true operator
177     if ( actor )
178     {
179       Console.WriteLine ("BaseHandle Operator true (actor) : test passed ");
180     }
181     else
182     {
183       Console.WriteLine ("BaseHandle Operator true (actor): test failed ");
184     }
185
186     Actor parent = actor.GetParent ();
187
188     if ( parent )
189     {
190       Console.WriteLine ("Handle with Empty body  :failed ");
191     }
192     else
193     {
194       Console.WriteLine ("Valid with Empty body  :passed ");
195     }
196
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() )
200     {
201        Console.WriteLine ("actor == differentActor.GetParent() :passed ");
202     }
203     else
204     {
205       Console.WriteLine ("actor == differentActor.GetParent() :failed ");
206     }
207
208     if ( differentActor == differentActor.GetParent() )
209     {
210        Console.WriteLine ("differentActor == differentActor.GetParent() :failed ");
211     }
212     else
213     {
214       Console.WriteLine ("differentActor == differentActor.GetParent() :passed ");
215     }
216
217
218     if ( nullActor )
219     {
220       Console.WriteLine ("BaseHandle Operator true (nullActor) : test failed ");
221     }
222     else
223     {
224       Console.WriteLine ("BaseHandle Operator true (nullActor): test passed ");
225     }
226
227     // ! operator
228     if ( !actor )
229     {
230       Console.WriteLine ("BaseHandle Operator !(actor) : test failed ");
231     }
232     else
233     {
234       Console.WriteLine ("BaseHandle Operator !(actor): test passed ");
235     }
236
237     if ( !nullActor )
238     {
239       Console.WriteLine ("BaseHandle Operator !(nullActor) : test passed ");
240     }
241     else
242     {
243       Console.WriteLine ("BaseHandle Operator !(nullActor): test failed ");
244     }
245
246     // Note: operator false only used inside & operator
247     // test equality operator ==
248     if ( actor == actorSame )
249     {
250       Console.WriteLine ("BaseHandle Operator  (actor == actorSame) : test passed");
251     }
252     else
253     {
254       Console.WriteLine ("BaseHandle Operator  (actor == actorSame) : test failed");
255     }
256
257     if ( actor == differentActor )
258     {
259       Console.WriteLine ("BaseHandle Operator (actor == differentActor) : test failed");
260     }
261     else
262     {
263       Console.WriteLine ("BaseHandle Operator (actor == differentActor) : test passed");
264     }
265
266     if ( actor == nullActor )
267     {
268       Console.WriteLine ("BaseHandle Operator (actor == nullActor) : test failed");
269     }
270     else
271     {
272       Console.WriteLine ("BaseHandle Operator (actor == nullActor) : test passed");
273     }
274
275     if ( nullActor == nullActor )
276     {
277       Console.WriteLine ("BaseHandle Operator (nullActor == nullActor) : test passed");
278     }
279     else
280     {
281       Console.WriteLine ("BaseHandle Operator (nullActor == nullActor) : test failed");
282     }
283
284     // test || operator
285     if ( actor || actorSame )
286     {
287       Console.WriteLine ("BaseHandle Operator (actor || actorSame) : test passed");
288     }
289     else
290     {
291       Console.WriteLine ("BaseHandle Operator (actor || actorSame) : test failed");
292     }
293
294     if ( actor || nullActor )
295     {
296       Console.WriteLine ("BaseHandle Operator (actor || nullActor) : test passed");
297     }
298     else
299     {
300       Console.WriteLine ("BaseHandle Operator (actor || nullActor) : test failed");
301     }
302
303     if ( nullActor || nullActor )
304     {
305       Console.WriteLine ("BaseHandle Operator (nullActor || nullActor) : test failed");
306     }
307     else
308     {
309       Console.WriteLine ("BaseHandle Operator (nullActor || nullActor) : test passed");
310     }
311
312
313     // test && operator
314     if ( actor && actorSame )
315     {
316       Console.WriteLine ("BaseHandle Operator (actor && actorSame) : test passed");
317     }
318     else
319     {
320       Console.WriteLine ("BaseHandle Operator (actor && actorSame) : test failed");
321     }
322
323     if ( actor && nullActor )
324     {
325       Console.WriteLine ("BaseHandle Operator (actor && nullActor) : test failed");
326     }
327     else
328     {
329       Console.WriteLine ("BaseHandle Operator (actor && nullActor) : test passed");
330     }
331
332     if ( nullActor && nullActor )
333     {
334       Console.WriteLine ("BaseHandle Operator (nullActor && nullActor) : test failed");
335     }
336     else
337     {
338       Console.WriteLine ("BaseHandle Operator (nullActor && nullActor) : test passed");
339     }
340
341   }
342
343     public void MainLoop()
344     {
345       _application.MainLoop ();
346     }
347
348     /// <summary>
349     /// The main entry point for the application.
350     /// </summary>
351     [STAThread]
352       static void Main(string[] args)
353       {
354         Console.WriteLine ("Hello Mono World");
355
356         Example example = new Example(Application.NewApplication());
357         example.MainLoop ();
358       }
359   }
360 }