[NUI] Supports to set/get full screen sized window
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / WindowTest.cs
1
2 using global::System;
3 using Tizen.NUI;
4 using Tizen.NUI.BaseComponents;
5 using Tizen.System;
6 using System.Collections.Generic;
7 using NUnit.Framework;
8
9 namespace Tizen.NUI.Samples
10 {
11     using log = Tizen.Log;
12     public class WindowTest : IExample
13     {
14         string tag = "NUITEST";
15         Window mainWin;
16         int screenWidth;
17         int screenHeight;
18
19         int addingInput;
20         Timer tm;
21         bool manualRotation;
22         int rotationCount;
23
24         private const string KEY_NUM_1 = "1";
25         private const string KEY_NUM_2 = "2";
26         private const string KEY_NUM_3 = "3";
27         private const string KEY_NUM_4 = "4";
28         private const string KEY_NUM_5 = "5";
29         private const string KEY_NUM_6 = "6";
30         private const string KEY_NUM_7 = "7";
31         private const string KEY_NUM_8 = "8";
32         private const string KEY_NUM_9 = "9";
33         private const string KEY_NUM_0 = "0";
34
35
36         void Initialize()
37         {
38             mainWin = NUIApplication.GetDefaultWindow();
39             mainWin.KeyEvent += OnKeyEvent;
40             mainWin.TouchEvent += WinTouchEvent;
41             mainWin.BackgroundColor = Color.Cyan;
42
43             Information.TryGetValue<int>("http://tizen.org/feature/screen.width", out screenWidth);
44             Information.TryGetValue<int>("http://tizen.org/feature/screen.height", out screenHeight);
45             log.Fatal(tag, $"Initialize= screenWidth {screenWidth}, screenHeight {screenHeight} ");
46             Rectangle inputRegion = new Rectangle(0,0,screenWidth,screenHeight/2);
47             mainWin.IncludeInputRegion(inputRegion);
48
49             addingInput = 0;
50
51             TextLabel text = new TextLabel("NUI Window Test");
52             text.HorizontalAlignment = HorizontalAlignment.Center;
53             text.VerticalAlignment = VerticalAlignment.Center;
54             text.TextColor = Color.Blue;
55             text.PointSize = 12.0f;
56             text.HeightResizePolicy = ResizePolicyType.FillToParent;
57             text.WidthResizePolicy = ResizePolicyType.FillToParent;
58             mainWin.Add(text);
59
60             List<Window.WindowOrientation> list = new List<Window.WindowOrientation>();
61
62             list.Add(Window.WindowOrientation.Landscape);
63             list.Add(Window.WindowOrientation.LandscapeInverse);
64             list.Add(Window.WindowOrientation.NoOrientationPreference);
65             list.Add(Window.WindowOrientation.Portrait);
66             list.Add(Window.WindowOrientation.PortraitInverse);
67
68             mainWin.SetAvailableOrientations(list);
69
70             Animation animation = new Animation(2000);
71             animation.AnimateTo(text, "Orientation", new Rotation(new Radian(new Degree(180.0f)), PositionAxis.X), 0, 500);
72             animation.AnimateTo(text, "Orientation", new Rotation(new Radian(new Degree(0.0f)), PositionAxis.X), 500, 1000);
73             animation.Looping = true;
74             animation.Play();
75
76             manualRotation = false;
77             rotationCount = 0;
78
79             tm = new Timer(100);
80             tm.Tick += Tm_Tick;
81             tm.Start();
82         }
83
84         private bool Tm_Tick(object source, Timer.TickEventArgs e)
85         {
86             bool rotating = mainWin.IsWindowRotating();
87             log.Fatal(tag, $"window is Rotating: {rotating}");
88             if(rotating && manualRotation)
89             {
90                 rotationCount++;
91                 if(rotationCount > 100)
92                 {
93                   log.Fatal(tag, $"call SendRotationCompletedAcknowledgement");
94                   mainWin.SendRotationCompletedAcknowledgement();
95                   rotationCount = 0;
96                 }
97             }
98             return true;
99         }
100
101         private void WinTouchEvent(object sender, Window.TouchEventArgs e)
102         {
103             if (e.Touch.GetState(0) == PointStateType.Down)
104             {
105                 Vector2 touchpoint = e.Touch.GetScreenPosition(0);
106                 log.Fatal(tag, $"WinTouchEvent={touchpoint.X}, {touchpoint.Y}");
107                 int xPosition = 0;
108                 if(addingInput == 0)
109                 {
110                     if(touchpoint.Y > (screenHeight/2 - 50))
111                     {
112                         int yPostion = screenHeight/2 + 1;
113                         int height = screenHeight/2;
114                         log.Fatal(tag, $"WinTouchEvent= Include {xPosition},{yPostion} {screenWidth}x{height} ");
115                         mainWin.IncludeInputRegion(new Rectangle(xPosition,yPostion,screenWidth,height));
116                         addingInput = 1;
117                     }
118                 }
119                 else
120                 {
121                     if(touchpoint.Y > (screenHeight - 50))
122                     {
123                         int yPostion = screenHeight/2 + 1;
124                         int height = screenHeight/2;
125                         log.Fatal(tag, $"WinTouchEvent= Exclude {xPosition},{yPostion} {screenWidth}x{height} ");
126                         mainWin.ExcludeInputRegion(new Rectangle(xPosition, yPostion, screenWidth, height));
127                         addingInput = 0;
128                     }
129                 }
130             }
131         }
132
133         public void OnKeyEvent(object sender, Window.KeyEventArgs e)
134         {
135             if (e.Key.State == Key.StateType.Down)
136             {
137                 log.Fatal(tag, $"key down! key={e.Key.KeyPressedName}");
138
139                 switch (e.Key.KeyPressedName)
140                 {
141                     case "XF86Back":
142                     case "Escape":
143                         //Exit();
144                         break;
145
146                     case KEY_NUM_1:
147                         log.Fatal(tag, $"pressed Key Num 1!");
148                         break;
149
150                     case KEY_NUM_2:
151                         mainWin.Maximize(true);
152                         break;
153
154                     case KEY_NUM_3:
155                         if(mainWin.IsMaximized())
156                         {
157                             mainWin.Maximize(false);
158                         }
159                         break;
160                     case KEY_NUM_4:
161                         mainWin.SetMaximumSize(new Size2D(700, 700));
162                         break;
163                     case KEY_NUM_5:
164                         mainWin.SetMimimumSize(new Size2D(100, 100));
165                         break;
166                     case KEY_NUM_6:
167                         if(manualRotation == false)
168                         {
169                             manualRotation = true;
170                             log.Fatal(tag, $"Enable manual rotation");
171                         }
172                         else
173                         {
174                             manualRotation = false;
175                             log.Fatal(tag, $"Disable manual rotation");
176                         }
177                         mainWin.SetNeedsRotationCompletedAcknowledgement(manualRotation);
178                         break;
179                     case KEY_NUM_7:
180                         mainWin.SetMimimumSize(new Size2D(100, 100));
181                         break;
182                     case KEY_NUM_8:
183                         if(mainWin.GetFullScreen() == false)
184                         {
185                             mainWin.SetFullScreen(true);
186                         }
187                         else
188                         {
189                             mainWin.SetFullScreen(false);
190                         }
191                         break;
192
193                     default:
194                         log.Fatal(tag, $"no test!");
195                         break;
196                 }
197             }
198         }
199
200         public void Activate() { Initialize(); }
201         public void Deactivate() { }
202     }
203 }