370b52e2c7980fb7aababbddcb9ff531e503d3bd
[platform/core/csapi/nui.git] / NUISamples / NUISamples.TizenTV / 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 Tizen.NUI;
21
22 namespace HelloWorldTest
23 {
24     class Example : NUIApplication
25     {
26         private Animation _animation;
27         private TextLabel _text;
28         private int cnt;
29         private View _view;
30
31         public Example() : base()
32         {
33         }
34
35         public Example(string stylesheet) : base(stylesheet)
36         {
37         }
38
39         public Example(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
40         {
41         }
42
43         protected override void OnCreate()
44         {
45             base.OnCreate();
46             Initialize();
47         }
48
49         public void Initialize()
50         {
51             Stage stage = Stage.Instance;
52             stage.BackgroundColor = Color.White;
53             stage.Touch += OnStageTouched;
54             stage.Key += OnStageKeyEvent;
55
56             _text = new TextLabel("Hello NUI World");
57             _text.ParentOrigin = ParentOrigin.Center;
58             _text.AnchorPoint = AnchorPoint.Center;
59             _text.HorizontalAlignment = "CENTER";
60             _text.PointSize = 32.0f;
61             _text.TextColor = Color.Magenta;
62             stage.GetDefaultLayer().Add(_text);
63
64             _view = new View();
65             _view.Size = new Size(100, 100, 100);
66             _view.SizeWidth = 50;
67             Tizen.Log.Debug("NUI", "[1]_view SizeWidth=" + _view.SizeWidth);
68
69             _animation = new Animation
70             {
71                 Duration = 2000
72             };
73             _animation.AnimateTo(_text, "Orientation", new Rotation(new Radian(new Degree(180.0f)), PositionAxis.X), 0, 500);
74             _animation.AnimateTo(_text, "Orientation", new Rotation(new Radian(new Degree(0.0f)), PositionAxis.X), 500, 1000);
75             _animation.AnimateBy(_text, "ScaleX", 3.0f, 1000, 1500);
76             _animation.AnimateBy(_text, "ScaleY", 4.0f, 1500, 2000);
77             _animation.EndAction = Animation.EndActions.Discard;
78             _animation.Finished += AnimationFinished;
79
80             _view.SizeWidth = 50;
81             Tizen.Log.Debug("NUI", "[2]_view SizeWidth=" + _view.SizeWidth);
82         }
83
84         public void AnimationFinished(object sender, EventArgs e)
85         {
86             Tizen.Log.Debug("NUI", "AnimationFinished()! cnt=" + (cnt));
87             if (_animation)
88             {
89                 Tizen.Log.Debug("NUI", "Duration= " + _animation.Duration + "EndAction= " + _animation.EndAction);
90             }
91             _view.SizeWidth = 50;
92             Tizen.Log.Debug("NUI", "[3]_view SizeWidth=" + _view.SizeWidth);
93         }
94
95         public void OnStageKeyEvent(object sender, Stage.KeyEventArgs e)
96         {
97             if (e.Key.State == Key.StateType.Down)
98             {
99                 if (e.Key.KeyPressedName == "Up")
100                 {
101                     if (_animation)
102                     {
103                         _animation.Finished += AnimationFinished;
104                         cnt++;
105                         Tizen.Log.Debug("NUI", "AnimationFinished added!");
106                     }
107                 }
108                 else if (e.Key.KeyPressedName == "Down")
109                 {
110                     if (_animation)
111                     {
112                         _animation.Finished -= AnimationFinished;
113                         cnt--;
114                         Tizen.Log.Debug("NUI", "AnimationFinished removed!");
115                     }
116                 }
117             }
118         }
119
120         public void OnStageTouched(object sender, Stage.TouchEventArgs e)
121         {
122             if (e.Touch.GetState(0) == PointStateType.Down)
123             {
124                 if (_animation)
125                 {
126                     //_animation.Stop(Dali.Constants.Animation.EndAction.Stop);
127                     //_animation.Reset();
128                 }
129                 _animation.Play();
130             }
131         }
132
133         [STAThread]
134         static void _Main(string[] args)
135         {
136             //Console.WriteLine("Main() called!");
137             Example example = new Example();
138             example.Run(args);
139         }
140     }
141 }