This patch is for refining dali application to support tizen c# application.
[platform/core/uifw/dali-toolkit.git] / plugins / dali-swig / examples / hello-test.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 Tizen.Applications;
22
23 //------------------------------------------------------------------------------
24 // <manual-generated />
25 //
26 // This file can only run on Tizen target. You should compile it with DaliApplication.cs, and
27 // add tizen c# application related library as reference.
28 //------------------------------------------------------------------------------
29 namespace MyCSharpExample
30 {
31     class Example : DaliApplication
32     {
33         protected override void OnCreate()
34         {
35             base.OnCreate();
36             Initialize();
37         }
38
39         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
40         delegate void CallbackDelegate(IntPtr data);
41
42         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
43         delegate void TouchCallbackDelegate(IntPtr data);
44
45         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
46         delegate void AnimationCallbackDelegate(IntPtr data);
47
48         private Animation _animation;
49         private TextLabel _text;
50
51         public Example():base()
52         {
53         }
54
55         private void Initialize()
56         {
57             // Connect the signal callback for stage touched signal
58             TouchCallbackDelegate stageTouchedCallback = new TouchCallbackDelegate(OnStageTouched);
59             stage.TouchSignal().Connect(stageTouchedCallback);
60
61             // Add a _text label to the stage
62             _text = new TextLabel("Hello Mono World");
63             _text.ParentOrigin = NDalic.ParentOriginCenter;
64             _text.AnchorPoint = NDalic.AnchorPointCenter;
65             _text.HorizontalAlignment = "CENTER";
66             _text.PointSize = 32.0f;
67
68             stage.Add(_text);
69         }
70
71         // Callback for _animation finished signal handling
72         private void AnimationFinished(IntPtr data)
73         {
74             Animation _animation = Animation.GetAnimationFromPtr( data );
75             Console.WriteLine("Animation finished: duration = " + _animation.GetDuration());
76         }
77
78         // Callback for stage touched signal handling
79         private void OnStageTouched(IntPtr data)
80         {
81             TouchData touchData = TouchData.GetTouchDataFromPtr( data );
82
83             // Only animate the _text label when touch down happens
84             if (touchData.GetState(0) == PointStateType.DOWN)
85             {
86                 // Create a new _animation
87                 if (_animation)
88                 {
89                     _animation.Reset();
90                 }
91
92                 _animation = new Animation(1.0f); // 1 second of duration
93
94                 _animation.AnimateTo(new Property(_text, Actor.Property.ORIENTATION), new Property.Value(new Quaternion(new Radian(new Degree(180.0f)), Vector3.XAXIS)), new AlphaFunction(AlphaFunction.BuiltinFunction.LINEAR), new TimePeriod(0.0f, 0.5f));
95                 _animation.AnimateTo(new Property(_text, Actor.Property.ORIENTATION), new Property.Value(new Quaternion(new Radian(new Degree(0.0f)), Vector3.XAXIS)), new AlphaFunction(AlphaFunction.BuiltinFunction.LINEAR), new TimePeriod(0.5f, 0.5f));
96
97                 // Connect the signal callback for animaiton finished signal
98                 AnimationCallbackDelegate animFinishedDelegate = new AnimationCallbackDelegate(AnimationFinished);
99                 _animation.FinishedSignal().Connect(animFinishedDelegate);
100
101                 // Play the _animation
102                 _animation.Play();
103             }
104         }
105
106         /// <summary>
107         /// The main entry point for the application.
108         /// </summary>
109
110         [STAThread]
111         static void Main(string[] args)
112         {
113             Console.WriteLine("Hello mono world.");
114             Example example = new Example();
115             example.Run(args);
116         }
117     }
118 }