Visual example, NUIApplication, Size/Position
[platform/core/csapi/nui.git] / NUISamples / NUISamples.TizenTV / examples / hello-test.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 Tizen.NUI;
20
21 namespace HelloTestExample
22 {
23     class Example : NUIApplication
24     {
25         private void LOG(string _str)
26         {
27             Tizen.Log.Debug("NUI", _str);
28             //Console.WriteLine("[NUI]" + _str);
29         }
30
31         private Animation _animation;
32         private TextLabel _text;
33         private Stage _stage;
34
35         public Example() : base()
36         {
37         }
38
39         public Example(string stylesheet) : base(stylesheet)
40         {
41         }
42
43         public Example(string stylesheet, Application.WindowMode windowMode) : base(stylesheet, windowMode)
44         {
45         }
46
47         private void Initialize()
48         {
49             LOG("Customized Application Initialize event handler");
50             _stage = Stage.Instance;
51             _stage.Touch += OnStageTouched;
52
53             // Add a _text label to the stage
54             _text = new TextLabel("Hello NUI World");
55             _text.ParentOrigin = ParentOrigin.Center;
56             _text.AnchorPoint = AnchorPoint.Center;
57             _text.HorizontalAlignment = "CENTER";
58             _text.PointSize = 32.0f;
59             _text.TextColor = Color.Magenta;
60             _stage.GetDefaultLayer().Add(_text);
61         }
62
63         // Callback for _animation finished signal handling
64         public void AnimationFinished(object sender, EventArgs e)
65         {
66             LOG("AnimationFinished()!");
67             if (_animation)
68             {
69                 LOG("Duration= " + _animation.Duration);
70                 LOG("EndAction= " + _animation.EndAction);
71             }
72
73             LOG("[4]_text PositionX =" + _text.PositionX + "  SizeHeight=" + _text.SizeHeight);
74         }
75
76         // Callback for stage touched signal handling
77         public void OnStageTouched(object sender, Stage.TouchEventArgs e)
78         {
79             // Only animate the _text label when touch down happens
80             if (e.Touch.GetState(0) == PointStateType.Down)
81             {
82                 LOG("Customized Stage Touch event handler");
83                 // Create a new _animation
84                 if (_animation)
85                 {
86                     //_animation.Stop(Dali.Constants.Animation.EndAction.Stop);
87                     _animation.Reset();
88                 }
89
90                 _animation = new Animation
91                 {
92                     Duration = 2000
93                 };
94
95                 LOG("[1]_text PositionX =" + _text.PositionX + "  SizeHeight=" + _text.SizeHeight);
96
97                 _animation.AnimateTo(_text, "PositionX", _text.PositionX + 200.0f);
98                 _animation.AnimateTo(_text, "SizeHeight", _text.SizeHeight + 200.0f);
99
100                 LOG("[2]_text PositionX =" + _text.PositionX + "  SizeHeight=" + _text.SizeHeight);
101
102                 _animation.AnimateTo(_text, "Orientation", new Rotation(new Radian(new Degree(180.0f)), Vector3.XAxis), 0, 500);
103                 _animation.AnimateTo(_text, "Orientation", new Rotation(new Radian(new Degree(0.0f)), Vector3.XAxis), 500, 1000);
104
105                 //_animation.AnimateBy(_text, "ScaleX", 3.0f, 1000, 1500);
106                 //_animation.AnimateBy(_text, "ScaleY", 4.0f, 1250, 2000);
107                 _animation.EndAction = Animation.EndActions.Discard;
108
109                 // Connect the signal callback for animaiton finished signal
110                 _animation.Finished += AnimationFinished;
111
112                 
113                 // Play the _animation
114                 _animation.Play();
115
116                 LOG("[3]_text PositionX =" + _text.PositionX + "  SizeHeight=" + _text.SizeHeight);
117
118             }
119         }
120
121         protected override void OnCreate()
122         {
123             base.OnCreate();
124             Initialize();
125         }
126
127         [STAThread]
128         static void Main(string[] args)
129         {
130             Example example = new Example();
131             example.Run(args);
132         }
133     }
134 }