Merge "Fix for Text::Controller." into devel/master
[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     // Callback for _animation finished signal handling
55     public void AnimationFinished(object sender, EventArgs e)
56     {
57       Console.WriteLine("AnimationFinished()!");
58       if(_animation)
59       {
60         Console.WriteLine("Duration= " + _animation.Duration);
61         Console.WriteLine("EndAction= " + _animation.EndAction);
62       }
63     }
64
65     // Callback for stage touched signal handling
66     public void OnStageTouched(object sender, Stage.TouchEventArgs e)
67     {
68       // Only animate the _text label when touch down happens
69       if( e.Touch.GetState(0) == PointStateType.DOWN )
70       {
71         Console.WriteLine("Customized Stage Touch event handler");
72         // Create a new _animation
73         if( _animation )
74         {
75           //_animation.Stop(Dali.Constants.Animation.EndAction.Stop);
76           _animation.Reset();
77         }
78
79         _animation = new Animation {
80           Duration = 2000,
81           StartTime = 0,
82           EndTime = 500,
83           TargetProperty = "Orientation",
84           Destination = new Rotation( new Radian( new Degree( 180.0f ) ), Vect3.Xaxis)
85         };
86         _animation.AnimateTo(_text);
87
88         _animation.StartTime = 500;
89         _animation.EndTime = 1000;
90         _animation.TargetProperty = "Orientation";
91         _animation.Destination = new Rotation( new Radian( new Degree( 0.0f ) ), Vect3.Xaxis );
92         _animation.AnimateTo(_text);
93
94         _animation.StartTime = 1000;
95         _animation.EndTime = 1500;
96         _animation.TargetProperty = "ScaleX";
97         _animation.Destination = 3.0f;
98         _animation.AnimateBy(_text);
99
100         _animation.StartTime = 1500;
101         _animation.EndTime = 2000;
102         _animation.TargetProperty = "ScaleY";
103         _animation.Destination = 4.0f;
104         _animation.AnimateBy(_text);
105
106         _animation.EndAction = Animation.EndActions.Discard;
107
108         // Connect the signal callback for animaiton finished signal
109         _animation.Finished += AnimationFinished;
110
111         // Play the _animation
112         _animation.Play();
113
114       }
115     }
116
117     public void MainLoop()
118     {
119       _application.MainLoop ();
120     }
121
122     /// <summary>
123     /// The main entry point for the application.
124     /// </summary>
125     [STAThread]
126     static void Main(string[] args)
127     {
128       Console.WriteLine ("Main() called!");
129
130       Example example = new Example(Application.NewApplication());
131       example.MainLoop ();
132     }
133   }
134 }