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