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