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