9af16c1cf81b7cfd8c07b8002a385845da948557
[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.Constants;
23 using Tizen.NUI.Extension.Test;
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             Stage stage = Stage.Instance;
55             stage.BackgroundColor = Color.White;
56             stage.Touch += OnStageTouched;
57             stage.Key += OnStageKeyEvent;
58
59             _text = new TextLabel("Hello NUI World");
60             _text.ParentOrigin = ParentOrigin.Center;
61             _text.AnchorPoint = AnchorPoint.Center;
62             _text.HorizontalAlignment = HorizontalAlignment.HorizontalAlignCenter;
63             _text.PointSize = 32.0f;
64             _text.TextColor = Color.Magenta;
65             stage.GetDefaultLayer().Add(_text);
66
67             _view = new View();
68             _view.Size = new Size(100, 100, 100);
69             _view.SizeWidth = 50;
70             Tizen.Log.Debug("NUI", "[1]_view SizeWidth=" + _view.SizeWidth);
71
72             _animation = new Animation
73             {
74                 Duration = 2000
75             };
76             _animation.AnimateTo(_text, "Orientation", new Rotation(new Radian(new Degree(180.0f)), PositionAxis.X), 0, 500);
77             _animation.AnimateTo(_text, "Orientation", new Rotation(new Radian(new Degree(0.0f)), PositionAxis.X), 500, 1000);
78             _animation.AnimateBy(_text, "ScaleX", 3, 1000, 1500);
79             _animation.AnimateBy(_text, "ScaleY", 4.0f, 1500, 2000);
80             _animation.EndAction = Animation.EndActions.Discard;
81             _animation.Finished += AnimationFinished;
82
83             _view.SizeWidth = 50;
84             Tizen.Log.Debug("NUI", "[2]_view SizeWidth=" + _view.SizeWidth);
85
86             ActorTest _actorExt = new ActorTest();
87             Actor _actor1 = _actorExt.CreateActor();
88             if(_actor1) Tizen.Log.Debug("NUI", "FriendAssembly Test _actor1 name = " + _actor1.Name);
89             else Tizen.Log.Debug("NUI", "FriendAssembly Test _actor1 is NULL!");
90
91         }
92
93         public void AnimationFinished(object sender, EventArgs e)
94         {
95             Tizen.Log.Debug("NUI", "AnimationFinished()! cnt=" + (cnt));
96             if (_animation)
97             {
98                 Tizen.Log.Debug("NUI", "Duration= " + _animation.Duration + "EndAction= " + _animation.EndAction);
99             }
100             _view.SizeWidth = 50;
101             Tizen.Log.Debug("NUI", "[3]_view SizeWidth=" + _view.SizeWidth);
102         }
103
104         public void OnStageKeyEvent(object sender, Stage.KeyEventArgs e)
105         {
106             if (e.Key.State == Key.StateType.Down)
107             {
108                 if (e.Key.KeyPressedName == "Up")
109                 {
110                     if (_animation)
111                     {
112                         _animation.Finished += AnimationFinished;
113                         cnt++;
114                         Tizen.Log.Debug("NUI", "AnimationFinished added!");
115                     }
116                 }
117                 else if (e.Key.KeyPressedName == "Down")
118                 {
119                     if (_animation)
120                     {
121                         _animation.Finished -= AnimationFinished;
122                         cnt--;
123                         Tizen.Log.Debug("NUI", "AnimationFinished removed!");
124                     }
125                 }
126             }
127         }
128
129         public void OnStageTouched(object sender, Stage.TouchEventArgs e)
130         {
131             if (e.Touch.GetState(0) == PointStateType.Down)
132             {
133                 if (_animation)
134                 {
135                     //_animation.Stop(Dali.Constants.Animation.EndAction.Stop);
136                     //_animation.Reset();
137                 }
138                 _animation.Play();
139             }
140         }
141
142         [STAThread]
143         static void _Main(string[] args)
144         {
145             //Tizen.Log.Debug("NUI", "Main() called!");
146             Example example = new Example();
147             example.Run(args);
148         }
149     }
150 }