Fix the Styling issue with Custom View.
[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         public Example(string stylesheet):base(stylesheet)
56         {
57         }
58
59         public Example(string stylesheet, Dali.Application.WINDOW_MODE windowMode):base(stylesheet, windowMode)
60         {
61         }
62
63         private void Initialize()
64         {
65             // Connect the signal callback for stage touched signal
66             TouchCallbackDelegate stageTouchedCallback = new TouchCallbackDelegate(OnStageTouched);
67             stage.TouchSignal().Connect(stageTouchedCallback);
68
69             // Add a _text label to the stage
70             _text = new TextLabel("Hello Mono World");
71             _text.ParentOrigin = NDalic.ParentOriginCenter;
72             _text.AnchorPoint = NDalic.AnchorPointCenter;
73             _text.HorizontalAlignment = "CENTER";
74             _text.PointSize = 32.0f;
75
76             stage.Add(_text);
77         }
78
79         // Callback for _animation finished signal handling
80         private void AnimationFinished(IntPtr data)
81         {
82             Animation _animation = Animation.GetAnimationFromPtr( data );
83             Console.WriteLine("Animation finished: duration = " + _animation.GetDuration());
84         }
85
86         // Callback for stage touched signal handling
87         private void OnStageTouched(IntPtr data)
88         {
89             TouchData touchData = TouchData.GetTouchDataFromPtr( data );
90
91             // Only animate the _text label when touch down happens
92             if (touchData.GetState(0) == PointStateType.DOWN)
93             {
94                 // Create a new _animation
95                 if (_animation)
96                 {
97                     _animation.Reset();
98                 }
99
100                 _animation = new Animation(1.0f); // 1 second of duration
101
102                 _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));
103                 _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));
104
105                 // Connect the signal callback for animaiton finished signal
106                 AnimationCallbackDelegate animFinishedDelegate = new AnimationCallbackDelegate(AnimationFinished);
107                 _animation.FinishedSignal().Connect(animFinishedDelegate);
108
109                 // Play the _animation
110                 _animation.Play();
111             }
112         }
113
114         /// <summary>
115         /// The main entry point for the application.
116         /// </summary>
117
118         [STAThread]
119         static void Main(string[] args)
120         {
121             Console.WriteLine("Hello mono world.");
122             //Example example = new Example();
123             //Example example = new Example("stylesheet");
124             Example example = new Example("stylesheet", Dali.Application.WINDOW_MODE.TRANSPARENT);
125             example.Run(args);
126         }
127     }
128 }