DALi Version 1.2.9
[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 += new Dali.AUIApplicationInitEventHandler(Initialize);
37       Console.WriteLine( "InitSignal connection count = " + _application.InitSignal().GetConnectionCount() );
38     }
39
40     public void Initialize(object source, AUIApplicationInitEventArgs e)
41     {
42       Handle handle = new Handle();
43       int myPropertyIndex = handle.RegisterProperty("myProperty", new Property.Value(10.0f), Property.AccessMode.READ_WRITE);
44       float myProperty = 0.0f;
45       handle.GetProperty(myPropertyIndex).Get(ref myProperty);
46       Console.WriteLine( "myProperty value: " + myProperty );
47
48       int myPropertyIndex2 = handle.RegisterProperty("myProperty2", new Property.Value(new Vector2(5.0f, 5.0f)), Property.AccessMode.READ_WRITE);
49       Vector2 myProperty2 = new Vector2(0.0f, 0.0f);
50       handle.GetProperty(myPropertyIndex2).Get(myProperty2);
51       Console.WriteLine( "myProperty2 value: " + myProperty2.x + ", " + myProperty2.y );
52
53       Actor actor = new Actor();
54       actor.Size = new Vector3(200.0f, 200.0f, 0.0f);
55       actor.Name = "MyActor";
56       actor.Color = new Vector4(1.0f, 0.0f, 1.0f, 0.8f);
57       Console.WriteLine("Actor id: {0}", actor.GetId());
58       Console.WriteLine("Actor size: " + actor.Size.x + ", " + actor.Size.y);
59       Console.WriteLine("Actor name: " + actor.Name);
60
61       Stage stage = Stage.GetCurrent();
62       stage.SetBackgroundColor( NDalic.WHITE );
63
64       Vector2 stageSize = stage.GetSize();
65       Console.WriteLine("Stage size: " + stageSize.x + ", " + stageSize.y);
66       stage.Add(actor);
67
68       TextLabel text = new TextLabel("Hello Mono World");
69       text.ParentOrigin = NDalic.ParentOriginCenter;
70       text.AnchorPoint = NDalic.AnchorPointCenter;
71       text.HorizontalAlignment = "CENTER";
72       stage.Add(text);
73
74       Console.WriteLine( "Text label text:  " + text.Text );
75
76       Console.WriteLine( "Text label point size:  " + text.PointSize );
77       text.PointSize = 32.0f;
78       Console.WriteLine( "Text label new point size:  " + text.PointSize );
79
80       using (RectInteger ri = new RectInteger(02,05,20,30))
81       {
82         Console.WriteLine( "    Created " + ri );
83         Console.WriteLine( "    IsEmpty() =  " + ri.IsEmpty() );
84         Console.WriteLine( "    Left =  " + ri.Left() );
85         Console.WriteLine( "    Right =  " + ri.Right() );
86         Console.WriteLine( "    Top  = " + ri.Top() );
87         Console.WriteLine( "    Bottom  = " + ri.Bottom() );
88         Console.WriteLine( "    Area  = " + ri.Area() );
89       }
90       Console.WriteLine( " *************************" );
91       using (RectInteger ri2 = new RectInteger(02,05,20,30))
92       {
93         Console.WriteLine( "    Created " + ri2 );
94         ri2.Set(1,1,40,40);
95         Console.WriteLine( "    IsEmpty() =  " + ri2.IsEmpty() );
96         Console.WriteLine( "    Left =  " + ri2.Left() );
97         Console.WriteLine( "    Right =  " + ri2.Right() );
98         Console.WriteLine( "    Top  = " + ri2.Top() );
99         Console.WriteLine( "    Bottom  = " + ri2.Bottom() );
100         Console.WriteLine( "    Area  = " + ri2.Area() );
101       }
102       Console.WriteLine( " *************************" );
103       using (RectDouble rd = new RectDouble(02,05,20.5,30.5))
104       {
105         Console.WriteLine( "    Created " + rd );
106         Console.WriteLine( "    IsEmpty() =  " + rd.IsEmpty() );
107         Console.WriteLine( "    Left =  " + rd.Left() );
108         Console.WriteLine( "    Right =  " + rd.Right() );
109         Console.WriteLine( "    Top  = " + rd.Top() );
110         Console.WriteLine( "    Bottom  = " + rd.Bottom() );
111         Console.WriteLine( "    Area  = " + rd.Area() );
112       }
113       Console.WriteLine( " *************************" );
114       RectDouble rd2 = new RectDouble();
115       rd2.x = 10;
116       rd2.y = 10;
117       rd2.width = 20;
118       rd2.height = 20;
119       Console.WriteLine( "    Created " + rd2 );
120       Console.WriteLine( "    IsEmpty() =  " + rd2.IsEmpty() );
121       Console.WriteLine( "    Left =  " + rd2.Left() );
122       Console.WriteLine( "    Right =  " + rd2.Right() );
123       Console.WriteLine( "    Top  = " + rd2.Top() );
124       Console.WriteLine( "    Bottom  = " + rd2.Bottom() );
125       Console.WriteLine( "    Area  = " + rd2.Area() );
126
127       Console.WriteLine( " *************************" );
128       Vector2 vector2 = new Vector2(100, 50);
129       Console.WriteLine( "    Created " + vector2 );
130       Console.WriteLine( "    Vector2 x =  " + vector2.x + ", y = " + vector2.y );
131       vector2 += new Vector2(20, 20);
132       Console.WriteLine( "    Vector2 x =  " + vector2[0] + ", y = " + vector2[1] );
133       vector2.x += 10;
134       vector2.y += 10;
135       Console.WriteLine( "    Vector2 width =  " + vector2.width + ", height = " + vector2.height );
136       vector2 += new Vector2(15, 15);
137       Console.WriteLine( "    Vector2 width =  " + vector2[0] + ", height = " + vector2[1] );
138
139       Console.WriteLine( " *************************" );
140       Vector3 vector3 = new Vector3(20, 100, 50);
141       Console.WriteLine( "    Created " + vector3 );
142       Console.WriteLine( "    Vector3 x =  " + vector3.x + ", y = " + vector3.y + ", z = " + vector3.z );
143       vector3 += new Vector3(20, 20, 20);
144       Console.WriteLine( "    Vector3 x =  " + vector3[0] + ", y = " + vector3[1] + ", z = " + vector3[2] );
145       vector3.x += 10;
146       vector3.y += 10;
147       vector3.z += 10;
148       Console.WriteLine( "    Vector3 width =  " + vector3.width + ", height = " + vector3.height + ", depth = " + vector3.depth );
149       Vector3 parentOrigin = NDalic.ParentOriginBottomRight;
150       Console.WriteLine( "    parentOrigin x =  " + parentOrigin.x + ", y = " + parentOrigin.y + ", z = " + parentOrigin.z );
151
152       Console.WriteLine( " *************************" );
153       Vector4 vector4 = new Vector4(20, 100, 50, 200);
154       Console.WriteLine( "    Created " + vector4 );
155       Console.WriteLine( "    Vector4 x =  " + vector4.x + ", y = " + vector4.y + ", z = " + vector4.z + ", w = " + vector4.w );
156       vector4 += new Vector4(20, 20, 20, 20);
157       Console.WriteLine( "    Vector4 x =  " + vector4[0] + ", y = " + vector4[1] + ", z = " + vector4[2] + ", w = " + vector4[3] );
158       vector4.x += 10;
159       vector4.y += 10;
160       vector4.z += 10;
161       vector4.w += 10;
162       Console.WriteLine( "    Vector4 r =  " + vector4.r + ", g = " + vector4.g + ", b = " + vector4.b + ", a = " + vector4.a );
163     }
164
165     public void MainLoop()
166     {
167       _application.MainLoop ();
168     }
169
170     /// <summary>
171     /// The main entry point for the application.
172     /// </summary>
173     [STAThread]
174       static void Main(string[] args)
175       {
176         Console.WriteLine ("Hello Mono World");
177
178         Example example = new Example(Application.NewApplication());
179         example.MainLoop ();
180       }
181   }
182 }