[NUI] Merge branch 'devel/nui'
[platform/core/csapi/tizenfx.git] / NUIsamples / NUIsamples / src / examples / hello-test.cs
1 /*
2  * Copyright (c) 2017 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 Tizen.NUI;
21 using Tizen.NUI.UIComponents;
22 using Tizen.NUI.BaseComponents;
23 using Tizen.NUI.Constants;
24 //using Tizen.Applications;
25
26 //------------------------------------------------------------------------------
27 // <manual-generated />
28 //
29 // This file can only run on Tizen target. You should compile it with DaliApplication.cs, and
30 // add tizen c# application related library as reference.
31 //------------------------------------------------------------------------------
32 namespace HelloTest
33 {
34     class Example : NUIApplication
35     {
36         private Animation _animation;
37         private TextLabel _text;
38         private Window _window;
39
40         public Example():base()
41         {
42         }
43
44         public Example(string stylesheet):base(stylesheet)
45         {
46         }
47
48         public Example(string stylesheet, WindowMode windowMode):base(stylesheet, windowMode)
49         {
50         }
51
52         protected override void OnCreate()
53         {
54             base.OnCreate();
55             Initialize();
56         }
57
58         private void Initialize()
59         {
60             // Connect the signal callback for window touched signal
61             _window = Window.Instance;
62             _window.TouchEvent += OnWindowTouched;
63
64             // Add a _text label to the window
65             _text = new TextLabel("Hello Mono World");
66             _text.ParentOrigin = ParentOrigin.Center;
67             _text.PivotPoint = PivotPoint.Center;
68             _text.HorizontalAlignment = HorizontalAlignment.Center;
69             _text.PointSize = 32.0f;
70
71             _window.Add(_text);
72         }
73
74         // Callback for _animation finished signal handling
75         private void AnimationFinished(object sender, EventArgs e)
76         {
77             if (_animation)
78             {
79                 Tizen.Log.Debug("NUI", "Duration= " + _animation.Duration);
80                 Tizen.Log.Debug("NUI", "EndAction= " + _animation.EndAction);
81             }
82         }
83
84         // Callback for window touched signal handling
85         private void OnWindowTouched(object sender, Window.TouchEventArgs e)
86         {
87             // Only animate the _text label when touch down happens
88             if (e.Touch.GetState(0) == PointStateType.Down)
89             {
90                 // Create a new _animation
91                 if (_animation)
92                 {
93                     _animation.Reset();
94                 }
95
96                 _animation = new Animation(1000); // 1 second of duration
97
98                 _animation.AnimateTo(_text, "Orientation", new Rotation(new Radian(new Degree(180.0f)), Vector3.XAxis), 0, 500);
99                 _animation.AnimateTo(_text, "Orientation", new Rotation(new Radian(new Degree(0.0f)), Vector3.XAxis), 500, 1000);
100                 _animation.EndAction = Animation.EndActions.Discard;
101
102                 // Connect the signal callback for animaiton finished signal
103                 _animation.Finished += AnimationFinished;
104
105                 // Play the _animation
106                 _animation.Play();
107             }
108         }
109
110         /// <summary>
111         /// The main entry point for the application.
112         /// </summary>
113
114         [STAThread]
115         static void _Main(string[] args)
116         {
117             Tizen.Log.Debug("NUI", "Hello mono world.");
118             //Example example = new Example();
119             //Example example = new Example("stylesheet");
120             Example example = new Example("stylesheet", WindowMode.Transparent);
121             example.Run(args);
122         }
123     }
124 }