Dali C#: Common Interface Define related changes
[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, AUIApplicationInitEventArgs e)
38     {
39       Console.WriteLine("Customized Application Initialize event handler");
40       Stage stage = Stage.GetCurrent();
41       stage.BackgroundColor = Color.Cyan;
42       stage.TouchEvent += OnStageTouched;
43       stage.WheelEvent += OnStageWheelMoved;
44       stage.KeyEvent += OnStageKeyPressed;
45       stage.EventProcessingFinished += OnStageEventProcessingFinished;
46
47       // Add a _text label to the stage
48       _text = new TextLabel("Hello Mono World");
49       _text.ParentOrigin = ParentOrigin.Center;
50       _text.AnchorPoint = AnchorPoint.Center;
51       _text.HorizontalAlignment = "CENTER";
52       _text.PointSize = 32.0f;
53       _text.TextColor = Color.Magenta;
54       stage.Add(_text);
55     }
56
57     // Callback for _animation finished signal handling
58     public void AnimationFinished(object sender, EventArgs e)
59     {
60         Console.WriteLine("AnimationFinished()!");
61     }
62
63     // Callback for _animation finished signal handling
64     public void AnimationFinished2(object sender, EventArgs e)
65     {
66       Console.WriteLine("AnimationFinished2()!");
67       if(_animation)
68       {
69         Console.WriteLine("Duration= " + _animation.Duration);
70         Console.WriteLine("EndAction= " + _animation.EndAction);
71       }
72     }
73
74     public void OnStageEventProcessingFinished(object sender, EventArgs e)
75     {
76       Console.WriteLine("OnStageEventProcessingFinished()!");
77       if( e != null)
78       {
79         Console.WriteLine("e != null !");
80       }
81     }
82
83     public void OnStageKeyPressed(object sender, Stage.KeyEventArgs e)
84     {
85       Console.WriteLine("OnStageKeyEventOccured()!");
86       Console.WriteLine("keyPressedName=" + e.KeyEvent.keyPressedName);
87       Console.WriteLine("state=" + e.KeyEvent.state);
88     }
89
90     public void OnStageWheelMoved(object sender, Stage.WheelEventArgs e)
91     {
92       Console.WriteLine("OnStageWheelEventOccured()!");
93       Console.WriteLine("direction=" + e.WheelEvent.direction);
94       Console.WriteLine("type=" + e.WheelEvent.type);
95     }
96
97     // Callback for stage touched signal handling
98     public void OnStageTouched(object sender, Stage.TouchEventArgs e)
99     {
100       // Only animate the _text label when touch down happens
101       if( e.TouchData.GetState(0) == PointStateType.DOWN )
102       {
103         Console.WriteLine("Customized Stage Touch event handler");
104         // Create a new _animation
105         if( _animation )
106         {
107           //_animation.Stop(Dali.Constants.Animation.EndAction.Stop);
108           _animation.Reset();
109         }
110
111         _animation = new Animation {
112           Duration = 2000,
113           StartTime = 0,
114           EndTime = 500,
115           TargetPoperty = "Orientation",
116           Destination = new Quaternion( new Radian( new Degree( 180.0f ) ), Vect3.Xaxis)
117         };
118         _animation.AnimateTo(_text);
119
120         _animation.StartTime = 500;
121         _animation.EndTime = 1000;
122         _animation.TargetPoperty = "Orientation";
123         _animation.Destination = new Quaternion( new Radian( new Degree( 0.0f ) ), Vect3.Xaxis );
124         _animation.AnimateTo(_text);
125
126         _animation.StartTime = 1000;
127         _animation.EndTime = 1500;
128         _animation.TargetPoperty = "ScaleX";
129         _animation.Destination = 3.0f;
130         _animation.AnimateBy(_text);
131
132         _animation.StartTime = 1500;
133         _animation.EndTime = 2000;
134         _animation.TargetPoperty = "ScaleY";
135         _animation.Destination = 4.0f;
136         _animation.AnimateBy(_text);
137
138         _animation.EndAction = Dali.Constants.Animation.EndAction.Discard;
139
140         // Connect the signal callback for animaiton finished signal
141         _animation.Finished += AnimationFinished;
142         _animation.Finished += AnimationFinished2;
143
144         // Play the _animation
145         _animation.Play();
146
147       }
148     }
149
150     public void MainLoop()
151     {
152       _application.MainLoop ();
153     }
154
155     /// <summary>
156     /// The main entry point for the application.
157     /// </summary>
158     [STAThread]
159     static void Main(string[] args)
160     {
161       Console.WriteLine ("Main() called!");
162
163       Example example = new Example(Application.NewApplication());
164       example.MainLoop ();
165     }
166   }
167 }