[Tizen] Fixed many issues.
[platform/core/csapi/tizenfx.git] / NUISamples / NUISamples / NUISamples.TizenTV / examples / hello-world.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
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             window.Resized += (obj, e) =>
59             {
60                 Tizen.Log.Debug("NUI", "Height: " + e.WindowSize.Height);
61                 Tizen.Log.Debug("NUI", "Width: " + e.WindowSize.Width);
62             };
63
64             TextLabel pixelLabel = new TextLabel("Test Pixel Size 32.0f");
65             pixelLabel.Position2D = new Position2D(10, 10);
66             pixelLabel.PixelSize = 32.0f;
67             window.Add(pixelLabel);
68
69             TextLabel pointLabel = new TextLabel("Test Point Size 32.0f");
70             pointLabel.Position2D = new Position2D(10, 100);
71             pointLabel.PointSize = 32.0f;
72             window.Add(pointLabel);
73
74             TextLabel ellipsis = new TextLabel("Ellipsis of TextLabel is enabled.");
75             ellipsis.Size2D = new Size2D(100, 100);
76             ellipsis.Position2D = new Position2D(10, 250);
77             ellipsis.PointSize = 20.0f;
78             ellipsis.Ellipsis = true;
79             window.Add(ellipsis);
80
81             TextLabel autoScrollStopMode = new TextLabel("AutoScrollStopMode is finish-loop.");
82             autoScrollStopMode.Size2D = new Size2D(400, 100);
83             autoScrollStopMode.Position2D = new Position2D(10, 400);
84             autoScrollStopMode.PointSize = 15.0f;
85             autoScrollStopMode.AutoScrollStopMode = AutoScrollStopMode.FinishLoop;
86             //autoScrollStopMode.AutoScrollLoopDelay = 10.0f;
87             autoScrollStopMode.EnableAutoScroll = true;
88             window.Add(autoScrollStopMode);
89
90             _text = new TextLabel("Hello NUI World");
91             _text.ParentOrigin = ParentOrigin.Center;
92             _text.PivotPoint = PivotPoint.Center;
93             _text.HorizontalAlignment = HorizontalAlignment.Center;
94             _text.PointSize = 32.0f;
95             _text.TextColor = Color.Magenta;
96             window.Add(_text);
97
98             _view = new View();
99             _view.Size2D = new Size2D(100, 100);
100             _view.SizeWidth = 50;
101             Tizen.Log.Debug("NUI", "[1]_view SizeWidth=" + _view.SizeWidth);
102
103             _animation = new Animation
104             {
105                 Duration = 2000
106             };
107             _animation.AnimateTo(_text, "Orientation", new Rotation(new Radian(new Degree(180.0f)), PositionAxis.X), 0, 500);
108             _animation.AnimateTo(_text, "Orientation", new Rotation(new Radian(new Degree(0.0f)), PositionAxis.X), 500, 1000);
109             _animation.AnimateBy(_text, "ScaleX", 3, 1000, 1500);
110             _animation.AnimateBy(_text, "ScaleY", 4.0f, 1500, 2000);
111             _animation.EndAction = Animation.EndActions.Discard;
112             _animation.Finished += AnimationFinished;
113
114             _view.SizeWidth = 50;
115             Tizen.Log.Debug("NUI", "[2]_view SizeWidth=" + _view.SizeWidth);
116         }
117
118         public void AnimationFinished(object sender, EventArgs e)
119         {
120             Tizen.Log.Debug("NUI", "AnimationFinished()! cnt=" + (cnt));
121             if (_animation)
122             {
123                 Tizen.Log.Debug("NUI", "Duration= " + _animation.Duration + "EndAction= " + _animation.EndAction);
124             }
125             _view.SizeWidth = 50;
126             Tizen.Log.Debug("NUI", "[3]_view SizeWidth=" + _view.SizeWidth);
127         }
128
129         public void OnWindowKeyEvent(object sender, Window.KeyEventArgs e)
130         {
131             if (e.Key.State == Key.StateType.Down)
132             {
133                 if (e.Key.KeyPressedName == "Up")
134                 {
135                     if (_animation)
136                     {
137                         _animation.Finished += AnimationFinished;
138                         cnt++;
139                         Tizen.Log.Debug("NUI", "AnimationFinished added!");
140                     }
141                 }
142                 else if (e.Key.KeyPressedName == "Down")
143                 {
144                     if (_animation)
145                     {
146                         _animation.Finished -= AnimationFinished;
147                         cnt--;
148                         Tizen.Log.Debug("NUI", "AnimationFinished removed!");
149                     }
150                 }
151             }
152         }
153
154         public void OnWindowTouched(object sender, Window.TouchEventArgs e)
155         {
156             if (e.Touch.GetState(0) == PointStateType.Down)
157             {
158                 if (_animation)
159                 {
160                     //_animation.Stop(Dali.Constants.Animation.EndAction.Stop);
161                     //_animation.Reset();
162                 }
163                 _animation.Play();
164             }
165         }
166
167         [STAThread]
168         static void _Main(string[] args)
169         {
170             //Tizen.Log.Debug("NUI", "Main() called!");
171             Example example = new Example();
172             example.Run(args);
173         }
174     }
175 }