Merge "Remove batching." 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       OperatorTests();
43
44       CustomViewPropertyTest();
45
46       Handle handle = new Handle();
47       int myPropertyIndex = handle.RegisterProperty("myProperty", new Property.Value(10.0f), Property.AccessMode.READ_WRITE);
48       float myProperty = 0.0f;
49       handle.GetProperty(myPropertyIndex).Get(ref myProperty);
50       Console.WriteLine( "myProperty value: " + myProperty );
51
52       int myPropertyIndex2 = handle.RegisterProperty("myProperty2", new Property.Value(new Size(5.0f, 5.0f)), Property.AccessMode.READ_WRITE);
53       Size myProperty2 = new Size(0.0f, 0.0f);
54       handle.GetProperty(myPropertyIndex2).Get(myProperty2);
55       Console.WriteLine( "myProperty2 value: " + myProperty2.W + ", " + myProperty2.H );
56
57       Actor actor = new Actor();
58       actor.Size = new Position(200.0f, 200.0f, 0.0f);
59       actor.Name = "MyActor";
60       actor.Color = new Color(1.0f, 0.0f, 1.0f, 0.8f);
61       Console.WriteLine("Actor id: {0}", actor.GetId());
62       Console.WriteLine("Actor size: " + actor.Size.X + ", " + actor.Size.Y);
63       Console.WriteLine("Actor name: " + actor.Name);
64
65       Stage stage = Stage.GetCurrent();
66       stage.BackgroundColor = Color.White;
67
68       Size stageSize = stage.Size;
69       Console.WriteLine("Stage size: " + stageSize.W + ", " + stageSize.H);
70       stage.Add(actor);
71
72       TextLabel text = new TextLabel("Hello Mono World");
73       text.ParentOrigin = NDalic.ParentOriginCenter;
74       text.AnchorPoint = NDalic.AnchorPointCenter;
75       text.HorizontalAlignment = "CENTER";
76       stage.Add(text);
77
78       Console.WriteLine( "Text label text:  " + text.Text );
79
80       Console.WriteLine( "Text label point size:  " + text.PointSize );
81       text.PointSize = 32.0f;
82       Console.WriteLine( "Text label new point size:  " + text.PointSize );
83
84       using (RectInteger ri = new RectInteger(02,05,20,30))
85       {
86         Console.WriteLine( "    Created " + ri );
87         Console.WriteLine( "    IsEmpty() =  " + ri.IsEmpty() );
88         Console.WriteLine( "    Left =  " + ri.Left() );
89         Console.WriteLine( "    Right =  " + ri.Right() );
90         Console.WriteLine( "    Top  = " + ri.Top() );
91         Console.WriteLine( "    Bottom  = " + ri.Bottom() );
92         Console.WriteLine( "    Area  = " + ri.Area() );
93       }
94       Console.WriteLine( " *************************" );
95       using (RectInteger ri2 = new RectInteger(02,05,20,30))
96       {
97         Console.WriteLine( "    Created " + ri2 );
98         ri2.Set(1,1,40,40);
99         Console.WriteLine( "    IsEmpty() =  " + ri2.IsEmpty() );
100         Console.WriteLine( "    Left =  " + ri2.Left() );
101         Console.WriteLine( "    Right =  " + ri2.Right() );
102         Console.WriteLine( "    Top  = " + ri2.Top() );
103         Console.WriteLine( "    Bottom  = " + ri2.Bottom() );
104         Console.WriteLine( "    Area  = " + ri2.Area() );
105       }
106       Console.WriteLine( " *************************" );
107       using (RectDouble rd = new RectDouble(02,05,20.5,30.5))
108       {
109         Console.WriteLine( "    Created " + rd );
110         Console.WriteLine( "    IsEmpty() =  " + rd.IsEmpty() );
111         Console.WriteLine( "    Left =  " + rd.Left() );
112         Console.WriteLine( "    Right =  " + rd.Right() );
113         Console.WriteLine( "    Top  = " + rd.Top() );
114         Console.WriteLine( "    Bottom  = " + rd.Bottom() );
115         Console.WriteLine( "    Area  = " + rd.Area() );
116       }
117       Console.WriteLine( " *************************" );
118       RectDouble rd2 = new RectDouble();
119       rd2.x = 10;
120       rd2.y = 10;
121       rd2.width = 20;
122       rd2.height = 20;
123       Console.WriteLine( "    Created " + rd2 );
124       Console.WriteLine( "    IsEmpty() =  " + rd2.IsEmpty() );
125       Console.WriteLine( "    Left =  " + rd2.Left() );
126       Console.WriteLine( "    Right =  " + rd2.Right() );
127       Console.WriteLine( "    Top  = " + rd2.Top() );
128       Console.WriteLine( "    Bottom  = " + rd2.Bottom() );
129       Console.WriteLine( "    Area  = " + rd2.Area() );
130
131       Console.WriteLine( " *************************" );
132       Size Size = new Size(100, 50);
133       Console.WriteLine( "    Created " + Size );
134       Console.WriteLine( "    Size x =  " + Size.W + ", y = " + Size.H );
135       Size += new Size(20, 20);
136       Console.WriteLine( "    Size x =  " + Size.W + ", y = " + Size.H );
137       Size.W += 10;
138       Size.H += 10;
139       Console.WriteLine( "    Size width =  " + Size.W + ", height = " + Size.H );
140
141       Console.WriteLine( " *************************" );
142       Position Position = new Position(20, 100, 50);
143       Console.WriteLine( "    Created " + Position );
144       Console.WriteLine( "    Position x =  " + Position.X + ", y = " + Position.Y + ", z = " + Position.Z );
145       Position += new Position(20, 20, 20);
146       Console.WriteLine( "    Position x =  " + Position.X + ", y = " + Position.Y + ", z = " + Position.Z );
147       Position.X += 10;
148       Position.Y += 10;
149       Position.Z += 10;
150       Console.WriteLine( "    Position width =  " + Position.X + ", height = " + Position.Y + ", depth = " + Position.Z );
151       Position parentOrigin = new Dali.Position(NDalic.ParentOriginBottomRight);
152       Console.WriteLine( "    parentOrigin x =  " + parentOrigin.X + ", y = " + parentOrigin.Y + ", z = " + parentOrigin.Z );
153
154       Console.WriteLine( " *************************" );
155       Color color = new Color(20, 100, 50, 200);
156       Console.WriteLine( "    Created " + color );
157       Console.WriteLine( "    Color R =  " + color.R + ", G = " + color.G + ", B = " + color.B + ", A = " + color.A );
158       color += new Color(20, 20, 20, 20);
159       Console.WriteLine( "    Color R =  " + color.R + ", G = " + color.G + ", B = " + color.B + ", A = " + color.A );
160       color.R += 10;
161       color.G += 10;
162       color.B += 10;
163       color.A += 10;
164       Console.WriteLine( "    Color r =  " + color.R + ", g = " + color.G + ", b = " + color.B + ", a = " + color.A );
165     }
166
167
168   public void OperatorTests()
169   {
170     Actor actor = new Actor();
171     Actor differentActor = new Actor();
172     Actor actorSame = actor;
173     Actor nullActor = null;
174
175       // test the true operator
176     if ( actor )
177     {
178       Console.WriteLine ("BaseHandle Operator true (actor) : test passed ");
179     }
180     else
181     {
182       Console.WriteLine ("BaseHandle Operator true (actor): test failed ");
183     }
184
185     Actor parent = actor.GetParent ();
186
187     if ( parent )
188     {
189       Console.WriteLine ("Handle with Empty body  :failed ");
190     }
191     else
192     {
193       Console.WriteLine ("Valid with Empty body  :passed ");
194     }
195
196     actor.Add( differentActor );
197     // here we test two different C# objects, which on the native side have the same body/ ref-object
198     if ( actor == differentActor.GetParent() )
199     {
200        Console.WriteLine ("actor == differentActor.GetParent() :passed ");
201     }
202     else
203     {
204       Console.WriteLine ("actor == differentActor.GetParent() :failed ");
205     }
206
207     if ( differentActor == differentActor.GetParent() )
208     {
209        Console.WriteLine ("differentActor == differentActor.GetParent() :failed ");
210     }
211     else
212     {
213       Console.WriteLine ("differentActor == differentActor.GetParent() :passed ");
214     }
215
216
217     if ( nullActor )
218     {
219       Console.WriteLine ("BaseHandle Operator true (nullActor) : test failed ");
220     }
221     else
222     {
223       Console.WriteLine ("BaseHandle Operator true (nullActor): test passed ");
224     }
225
226     // ! operator
227     if ( !actor )
228     {
229       Console.WriteLine ("BaseHandle Operator !(actor) : test failed ");
230     }
231     else
232     {
233       Console.WriteLine ("BaseHandle Operator !(actor): test passed ");
234     }
235
236     if ( !nullActor )
237     {
238       Console.WriteLine ("BaseHandle Operator !(nullActor) : test passed ");
239     }
240     else
241     {
242       Console.WriteLine ("BaseHandle Operator !(nullActor): test failed ");
243     }
244
245     // Note: operator false only used inside & operator
246     // test equality operator ==
247     if ( actor == actorSame )
248     {
249       Console.WriteLine ("BaseHandle Operator  (actor == actorSame) : test passed");
250     }
251     else
252     {
253       Console.WriteLine ("BaseHandle Operator  (actor == actorSame) : test failed");
254     }
255
256     if ( actor == differentActor )
257     {
258       Console.WriteLine ("BaseHandle Operator (actor == differentActor) : test failed");
259     }
260     else
261     {
262       Console.WriteLine ("BaseHandle Operator (actor == differentActor) : test passed");
263     }
264
265     if ( actor == nullActor )
266     {
267       Console.WriteLine ("BaseHandle Operator (actor == nullActor) : test failed");
268     }
269     else
270     {
271       Console.WriteLine ("BaseHandle Operator (actor == nullActor) : test passed");
272     }
273
274     if ( nullActor == nullActor )
275     {
276       Console.WriteLine ("BaseHandle Operator (nullActor == nullActor) : test passed");
277     }
278     else
279     {
280       Console.WriteLine ("BaseHandle Operator (nullActor == nullActor) : test failed");
281     }
282
283     // test || operator
284     if ( actor || actorSame )
285     {
286       Console.WriteLine ("BaseHandle Operator (actor || actorSame) : test passed");
287     }
288     else
289     {
290       Console.WriteLine ("BaseHandle Operator (actor || actorSame) : test failed");
291     }
292
293     if ( actor || nullActor )
294     {
295       Console.WriteLine ("BaseHandle Operator (actor || nullActor) : test passed");
296     }
297     else
298     {
299       Console.WriteLine ("BaseHandle Operator (actor || nullActor) : test failed");
300     }
301
302     if ( nullActor || nullActor )
303     {
304       Console.WriteLine ("BaseHandle Operator (nullActor || nullActor) : test failed");
305     }
306     else
307     {
308       Console.WriteLine ("BaseHandle Operator (nullActor || nullActor) : test passed");
309     }
310
311
312     // test && operator
313     if ( actor && actorSame )
314     {
315       Console.WriteLine ("BaseHandle Operator (actor && actorSame) : test passed");
316     }
317     else
318     {
319       Console.WriteLine ("BaseHandle Operator (actor && actorSame) : test failed");
320     }
321
322     if ( actor && nullActor )
323     {
324       Console.WriteLine ("BaseHandle Operator (actor && nullActor) : test failed");
325     }
326     else
327     {
328       Console.WriteLine ("BaseHandle Operator (actor && nullActor) : test passed");
329     }
330
331     if ( nullActor && nullActor )
332     {
333       Console.WriteLine ("BaseHandle Operator (nullActor && nullActor) : test failed");
334     }
335     else
336     {
337       Console.WriteLine ("BaseHandle Operator (nullActor && nullActor) : test passed");
338     }
339
340   }
341
342     public void CustomViewPropertyTest()
343     {
344         // Create a Spin control
345         Spin spin = new Spin();
346
347         // Background property
348         Property.Map background = new Property.Map();
349         background.Add( Dali.Constants.Visual.Property.Type, new Property.Value((int)Dali.Constants.Visual.Type.Color) )
350                   .Add( Dali.Constants.ColorVisualProperty.MixColor, new Property.Value(Color.Red) );
351         spin.Background = background;
352
353         background = spin.Background;
354         Vector4 backgroundColor = new Vector4();
355         background.Find(Dali.Constants.ColorVisualProperty.MixColor).Get(backgroundColor);
356         if( backgroundColor == Color.Red )
357         {
358             Console.WriteLine ("Custom View Background property : test passed");
359         }
360         else
361         {
362             Console.WriteLine ("Custom View Background property : test failed");
363         }
364
365         // BackgroundColor property
366         spin.BackgroundColor = Color.Yellow;
367         if(spin.BackgroundColor == Color.Yellow)
368         {
369             Console.WriteLine ("Custom View BackgroundColor property : test passed");
370         }
371         else
372         {
373             Console.WriteLine ("Custom View BackgroundColor property : test failed");
374         }
375
376         // StyleName property
377         spin.StyleName = "MyCustomStyle";
378         if(spin.StyleName == "MyCustomStyle")
379         {
380             Console.WriteLine ("Custom View StyleName property : test passed");
381         }
382         else
383         {
384             Console.WriteLine ("Custom View StyleName property : test failed");
385         }
386     }
387
388     public void MainLoop()
389     {
390       _application.MainLoop ();
391     }
392
393     /// <summary>
394     /// The main entry point for the application.
395     /// </summary>
396     [STAThread]
397       static void Main(string[] args)
398       {
399         Console.WriteLine ("Hello Mono World");
400
401         Example example = new Example(Application.NewApplication());
402         example.MainLoop ();
403       }
404   }
405 }