fixup! Adding the MISSING Animation constructor to accept duration in milli seconds
[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
22 namespace MyCSharpExample
23 {
24     class Example
25     {
26         private Dali.Application _application;
27
28         private Animation _animation;
29         private TextLabel _text;
30
31         public Example(Dali.Application application)
32         {
33             _application = application;
34             _application.Initialized += Initialize;
35         }
36
37         public void Initialize(object source, AUIApplicationInitEventArgs e)
38         {
39             Console.WriteLine("Customized Application Initialize event handler");
40             Stage stage = Stage.GetCurrent();
41             stage.BackgroundColor = NDalic.WHITE;
42
43             stage.Touched += OnStageTouched;
44
45             // Add a _text label to the stage
46             _text = new TextLabel("Hello Mono World");
47             _text.ParentOrigin = NDalic.ParentOriginCenter;
48             _text.AnchorPoint = NDalic.AnchorPointCenter;
49             _text.HorizontalAlignment = "CENTER";
50             _text.PointSize = 32.0f;
51
52             stage.Add(_text);
53         }
54
55         // Callback for _animation finished signal handling
56         public void AnimationFinished(object source, Animation.FinishedEventArgs e)
57         {
58             Console.WriteLine("Customized Animation Finished Event handler");
59             Console.WriteLine("Animation finished: duration = " + e.Animation.Duration);
60             Console.WriteLine("End Action = " + e.Animation.GetEndAction());
61         }
62
63         // Callback for stage touched signal handling
64         public void OnStageTouched(object source, Stage.TouchEventArgs e)
65         {
66             //TouchData touchData = TouchData.GetTouchDataFromPtr( data );
67
68             // Only animate the _text label when touch down happens
69             if( e.TouchData.GetState(0) == PointStateType.DOWN )
70             {
71                 Console.WriteLine("Customized Stage Touch event handler");
72                 // Create a new _animation
73                 if( _animation )
74                 {
75                     _animation.Reset();
76                 }
77
78                 _animation = new Animation(1.0f); // 1 second of duration
79
80                 _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));
81
82                 _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));
83
84                 // Connect the signal callback for animaiton finished signal
85                 _animation.Finished += AnimationFinished;
86
87                 // Play the _animation
88                 _animation.Play();
89
90                 Console.WriteLine("Looping:" + _animation.Looping);
91             }
92         }
93
94         public void MainLoop()
95         {
96             _application.MainLoop ();
97         }
98
99         /// <summary>
100         /// The main entry point for the application.
101         /// </summary>
102
103         [STAThread]
104         static void Main(string[] args)
105         {
106             Console.WriteLine ("Hello Mono World");
107
108             Example example = new Example(Application.NewApplication());
109             example.MainLoop ();
110         }
111     }
112 }