DALi C# binding - Write pure C# Color & Position classes and use typemaps to do the...
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / examples / hello-world.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 using Dali.CSharp;
22
23 namespace MyCSharpExample
24 {
25     class Example
26     {
27         private Dali.Application _application;
28
29         private Animation _animation;
30         private TextLabel _text;
31
32         public Example(Dali.Application application)
33         {
34             _application = application;
35             _application.Initialized += Initialize;
36         }
37
38         public void Initialize(object source, AUIApplicationInitEventArgs e)
39         {
40             Console.WriteLine("Customized Application Initialize event handler");
41             Stage stage = Stage.GetCurrent();
42             stage.BackgroundColor = new Dali.CSharp.Color(Dali.CSharp.Colors.Red);
43
44             stage.Touched += OnStageTouched;
45
46             // Add a _text label to the stage
47             _text = new TextLabel("Hello Mono World");
48             _text.ParentOrigin = new Position(NDalic.ParentOriginCenter);
49             _text.AnchorPoint = new Position(NDalic.AnchorPointCenter);
50             _text.HorizontalAlignment = "CENTER";
51             _text.PointSize = 32.0f;
52
53             stage.Add(_text);
54         }
55
56         // Callback for _animation finished signal handling
57         public void AnimationFinished(object source, Animation.FinishedEventArgs e)
58         {
59             Console.WriteLine("Customized Animation Finished Event handler");
60             Console.WriteLine("Animation finished: duration = " + e.Animation.Duration);
61             Console.WriteLine("End Action = " + e.Animation.GetEndAction());
62         }
63
64         // Callback for stage touched signal handling
65         public void OnStageTouched(object source, Stage.TouchEventArgs e)
66         {
67             //TouchData touchData = TouchData.GetTouchDataFromPtr( data );
68
69             // Only animate the _text label when touch down happens
70             if( e.TouchData.GetState(0) == PointStateType.DOWN )
71             {
72                 Console.WriteLine("Customized Stage Touch event handler");
73                 // Create a new _animation
74                 if( _animation )
75                 {
76                     _animation.Reset();
77                 }
78
79                 _animation = new Animation(1.0f); // 1 second of duration
80
81                 _animation.AnimateTo(_text, Animation.Orientation, new Quaternion( new Radian( new Degree( 180.0f ) ), Vector3.XAXIS ), new AlphaFunction(Dali.Constants.AlphaFunction.BuiltinFunction.Linear), new TimePeriod(0.0f, 0.5f));
82
83                 _animation.AnimateTo(_text, Animation.Orientation, new Quaternion( new Radian( new Degree( 0.0f ) ), Vector3.XAXIS ), new AlphaFunction(Dali.Constants.AlphaFunction.BuiltinFunction.Linear), new TimePeriod(0.5f, 0.5f));
84
85                 // Connect the signal callback for animaiton finished signal
86                 _animation.Finished += AnimationFinished;
87
88                 // Play the _animation
89                 _animation.Play();
90
91                 Console.WriteLine("Looping:" + _animation.Looping);
92             }
93         }
94
95         public void MainLoop()
96         {
97             _application.MainLoop ();
98         }
99
100         /// <summary>
101         /// The main entry point for the application.
102         /// </summary>
103
104         [STAThread]
105         static void Main(string[] args)
106         {
107             Console.WriteLine ("Hello Mono World");
108
109             Example example = new Example(Application.NewApplication());
110             example.MainLoop ();
111         }
112     }
113 }