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