d775fbeb5abc424a1f54b6e48cac56a557248ca8
[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.Constants;
22
23 namespace MyCSharpExample
24 {
25   class Example
26   {
27     private Dali.Application _application;
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, NUIApplicationInitEventArgs e)
38     {
39       Console.WriteLine("Customized Application Initialize event handler");
40       Stage stage = Stage.Instance;
41       stage.BackgroundColor = Color.White;
42       stage.Touch += OnStageTouched;
43
44       // Add a _text label to the stage
45       _text = new TextLabel("Hello Mono World");
46       _text.ParentOrigin = ParentOrigin.Center;
47       _text.AnchorPoint = AnchorPoint.Center;
48       _text.HorizontalAlignment = "CENTER";
49       _text.PointSize = 32.0f;
50       _text.TextColor = Color.Magenta;
51       stage.Add(_text);
52
53     }
54
55     // Callback for _animation finished signal handling
56     public void AnimationFinished(object sender, EventArgs e)
57     {
58       Console.WriteLine("AnimationFinished()!");
59       if(_animation)
60       {
61         Console.WriteLine("Duration= " + _animation.Duration);
62         Console.WriteLine("EndAction= " + _animation.EndAction);
63       }
64     }
65
66     // Callback for stage touched signal handling
67     public void OnStageTouched(object sender, Stage.TouchEventArgs e)
68     {
69       // Only animate the _text label when touch down happens
70       if( e.Touch.GetState(0) == PointStateType.DOWN )
71       {
72         Console.WriteLine("Customized Stage Touch event handler");
73         // Create a new _animation
74         if( _animation )
75         {
76           //_animation.Stop(Dali.Constants.Animation.EndAction.Stop);
77           _animation.Reset();
78         }
79
80         _animation = new Animation {
81           Duration = 2000,
82           StartTime = 0,
83           EndTime = 500,
84           TargetProperty = "Orientation",
85           Destination = new Rotation( new Radian( new Degree( 180.0f ) ), Vect3.Xaxis)
86         };
87         _animation.AnimateTo(_text);
88
89         _animation.StartTime = 500;
90         _animation.EndTime = 1000;
91         _animation.TargetProperty = "Orientation";
92         _animation.Destination = new Rotation( new Radian( new Degree( 0.0f ) ), Vect3.Xaxis );
93         _animation.AnimateTo(_text);
94
95         _animation.StartTime = 1000;
96         _animation.EndTime = 1500;
97         _animation.TargetProperty = "ScaleX";
98         _animation.Destination = 3.0f;
99         _animation.AnimateBy(_text);
100
101         _animation.StartTime = 1500;
102         _animation.EndTime = 2000;
103         _animation.TargetProperty = "ScaleY";
104         _animation.Destination = 4.0f;
105         _animation.AnimateBy(_text);
106
107         _animation.EndAction = Animation.EndActions.Discard;
108
109         // Connect the signal callback for animaiton finished signal
110         _animation.Finished += AnimationFinished;
111
112         // Play the _animation
113         _animation.Play();
114
115       }
116     }
117
118     public void MainLoop()
119     {
120       _application.MainLoop ();
121     }
122
123     /// <summary>
124     /// The main entry point for the application.
125     /// </summary>
126     [STAThread]
127     static void Main(string[] args)
128     {
129       Console.WriteLine ("Main() called!");
130
131       Example example = new Example(Application.NewApplication());
132       example.MainLoop ();
133     }
134   }
135 }