1d6ed3be1518d2287671f3cf8e60ce4fe83efd23
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / BorderWindowTest.cs
1
2 using System;
3 using Tizen.NUI;
4 using Tizen.NUI.BaseComponents;
5 using Tizen.NUI.Components;
6 using System.Collections.Generic;
7
8
9 namespace Tizen.NUI.Samples
10 {
11   public class BorderWindowTest : IExample
12   {
13     private Window win;
14     private Window subWindowOne = null;
15     private Window subWindowTwo = null;
16     private static readonly string imagePath = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "/images/Dali/CubeTransitionEffect/";
17
18
19     class CustomBorder : DefaultBorder
20     {
21       private static readonly string ResourcePath = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
22       private static readonly string MinimalizeIcon = ResourcePath + "/images/minimalize.png";
23       private static readonly string MaximalizeIcon = ResourcePath + "/images/maximalize.png";
24       private static readonly string RestoreIcon = ResourcePath + "/images/smallwindow.png";
25       private static readonly string CloseIcon = ResourcePath + "/images/close.png";
26       private static readonly string LeftCornerIcon = ResourcePath + "/images/leftCorner.png";
27       private static readonly string RightCornerIcon = ResourcePath + "/images/rightCorner.png";
28
29       private int width = 500;
30       private bool hide = false;
31       private View borderView;
32       private TextLabel title;
33
34       private ImageView minimalizeIcon;
35       private ImageView maximalizeIcon;
36       private ImageView closeIcon;
37       private ImageView leftCornerIcon;
38       private ImageView rightCornerIcon;
39
40       private Rectangle preWinPositonSize;
41
42       public CustomBorder() : base()
43       {
44         BorderHeight = 50;
45         OverlayMode = true;
46         BorderLineThickness = 0;
47       }
48
49       public override bool CreateTopBorderView(View topView)
50       {
51         if (topView == null)
52         {
53           return false;
54         }
55         topView.Layout = new LinearLayout()
56         {
57           LinearOrientation = LinearLayout.Orientation.Horizontal, 
58           LinearAlignment = LinearLayout.Alignment.CenterVertical,
59           CellPadding = new Size2D(20, 20),
60         };
61         title = new TextLabel()
62         {
63           Text = "CustomBorder",
64         };
65         
66         var button = new Button()
67         {
68           Text = "AlwaysOnTop",
69         };
70         button.Clicked += (s, e) =>
71         {
72           BorderWindow.EnableFloatingMode(true);
73         };
74         topView.Add(title);
75         topView.Add(button);
76         return true;
77       }
78
79       public override bool CreateBottomBorderView(View bottomView)
80       {
81         if (bottomView == null)
82         {
83             return false;
84         }
85         bottomView.Layout = new RelativeLayout();
86
87         minimalizeIcon = new ImageView()
88         {
89             ResourceUrl = MinimalizeIcon,
90         };
91
92         maximalizeIcon = new ImageView()
93         {
94             ResourceUrl = MaximalizeIcon,
95         };
96
97         closeIcon = new ImageView()
98         {
99             ResourceUrl = CloseIcon,
100         };
101
102         leftCornerIcon = new ImageView()
103         {
104             ResourceUrl = LeftCornerIcon,
105         };
106
107         rightCornerIcon = new ImageView()
108         {
109           ResourceUrl = RightCornerIcon,
110         };
111
112         RelativeLayout.SetRightTarget(minimalizeIcon, maximalizeIcon);
113         RelativeLayout.SetRightRelativeOffset(minimalizeIcon, 0.0f);
114         RelativeLayout.SetHorizontalAlignment(minimalizeIcon, RelativeLayout.Alignment.End);
115         RelativeLayout.SetRightTarget(maximalizeIcon, closeIcon);
116         RelativeLayout.SetRightRelativeOffset(maximalizeIcon, 0.0f);
117         RelativeLayout.SetHorizontalAlignment(maximalizeIcon, RelativeLayout.Alignment.End);
118         RelativeLayout.SetRightTarget(closeIcon, rightCornerIcon);
119         RelativeLayout.SetRightRelativeOffset(closeIcon, 0.0f);
120         RelativeLayout.SetHorizontalAlignment(closeIcon, RelativeLayout.Alignment.End);
121         RelativeLayout.SetRightRelativeOffset(rightCornerIcon, 1.0f);
122         RelativeLayout.SetHorizontalAlignment(rightCornerIcon, RelativeLayout.Alignment.End);
123         bottomView.Add(leftCornerIcon);
124         bottomView.Add(minimalizeIcon);
125         bottomView.Add(maximalizeIcon);
126         bottomView.Add(closeIcon);
127         bottomView.Add(rightCornerIcon);
128
129
130         minimalizeIcon.TouchEvent += OnMinimizeIconTouched;
131         maximalizeIcon.TouchEvent += OnMaximizeIconTouched;
132         closeIcon.TouchEvent += OnCloseIconTouched;
133         leftCornerIcon.TouchEvent += OnLeftBottomCornerIconTouched;
134         rightCornerIcon.TouchEvent += OnRightBottomCornerIconTouched;
135         return true;
136       }
137
138       public override void CreateBorderView(View borderView)
139       {
140           this.borderView = borderView;
141           borderView.CornerRadius = new Vector4(0.03f, 0.03f, 0.03f, 0.03f);
142           borderView.CornerRadiusPolicy = VisualTransformPolicyType.Relative;
143           borderView.BackgroundColor = new Color(1, 1, 1, 0.3f);
144       }
145
146       public override void OnCreated(View borderView)
147       {
148         base.OnCreated(borderView);
149         UpdateIcons();
150       }
151
152       public override bool OnCloseIconTouched(object sender, View.TouchEventArgs e)
153       {
154         base.OnCloseIconTouched(sender, e);
155         return true;
156       }
157
158       public override bool OnMinimizeIconTouched(object sender, View.TouchEventArgs e)
159       {
160         if (e.Touch.GetState(0) == PointStateType.Up)
161         {
162           if (BorderWindow.IsMaximized() == true)
163           {
164             BorderWindow.Maximize(false);
165           }
166           preWinPositonSize = BorderWindow.WindowPositionSize;
167           BorderWindow.WindowPositionSize = new Rectangle(preWinPositonSize.X, preWinPositonSize.Y, 500, 0);
168         }
169         return true;
170       }
171
172       public override void OnRequestResize()
173       {
174         if (borderView != null)
175         {
176           borderView.BackgroundColor = new Color(0, 1, 0, 0.3f); // 보더의 배경을 변경할 수 있습니다.
177         }
178       }
179
180       public override void OnResized(int width, int height)
181       {
182         if (borderView != null)
183         {
184           if (this.width > width && hide == false)
185           {
186             title.Hide();
187             hide = true;
188           }
189           else if (this.width < width && hide == true)
190           {
191             title.Show();
192             hide = false;
193           }
194           borderView.BackgroundColor = new Color(1, 1, 1, 0.3f); //  리사이즈가 끝나면 보더의 색깔은 원래대로 돌려놓습니다.
195           base.OnResized(width, height);
196           UpdateIcons();
197         }
198       }
199
200       private void UpdateIcons()
201       {
202         if (BorderWindow != null && borderView != null)
203         {
204             if (BorderWindow.IsMaximized() == true)
205             {
206                 if (maximalizeIcon != null)
207                 {
208                     maximalizeIcon.ResourceUrl = RestoreIcon;
209                 }
210             }
211             else
212             {
213                 if (maximalizeIcon != null)
214                 {
215                     maximalizeIcon.ResourceUrl = MaximalizeIcon;
216                 }
217             }
218         }
219       }
220
221     }
222
223     void CreateSubWindowOne()
224     {
225       if (subWindowOne == null)
226       {
227         subWindowOne = new Window("subwin1", null, new Rectangle(20, 20, 800, 800), false);
228
229         var root = new ImageView()
230         {
231           WidthResizePolicy = ResizePolicyType.FillToParent,
232           HeightResizePolicy = ResizePolicyType.FillToParent,
233           ResourceUrl = imagePath + "gallery-large-9.jpg",
234           CornerRadius = new Vector4(0.03f, 0.03f, 0.03f, 0.03f),
235           CornerRadiusPolicy = VisualTransformPolicyType.Relative,
236         };
237         subWindowOne.Add(root);
238
239         TextLabel text = new TextLabel("Hello Tizen NUI World");
240         text.HorizontalAlignment = HorizontalAlignment.Center;
241         text.VerticalAlignment = VerticalAlignment.Center;
242         text.TextColor = Color.CornflowerBlue;
243         text.HeightResizePolicy = ResizePolicyType.FillToParent;
244         text.WidthResizePolicy = ResizePolicyType.FillToParent;
245         root.Add(text);
246
247         Animation animation = new Animation(2000);
248         animation.AnimateTo(text, "Orientation", new Rotation(new Radian(new Degree(180.0f)), PositionAxis.X), 0, 500);
249         animation.AnimateTo(text, "Orientation", new Rotation(new Radian(new Degree(0.0f)), PositionAxis.X), 500, 1000);
250         animation.Looping = true;
251         animation.Play();
252       }
253       else
254       {
255         subWindowOne.Minimize(false);
256       }
257     }
258
259     void CreateSubWindowTwo()
260     {
261       if (subWindowTwo == null)
262       {
263         IBorderInterface customBorder = new CustomBorder();
264         subWindowTwo = new Window("subwin1", customBorder, new Rectangle(60, 20, 800, 800), false);
265         subWindowTwo.EnableFloatingMode(true);
266
267         var root = new View(){
268           Layout = new LinearLayout()
269           {
270               LinearAlignment = LinearLayout.Alignment.CenterHorizontal,
271           },
272           WidthResizePolicy = ResizePolicyType.FillToParent,
273           HeightResizePolicy = ResizePolicyType.FillToParent,
274           BackgroundColor = Color.Brown,
275         };
276
277         var image = new ImageView()
278         {
279           Size = new Size(300, 300),
280           ResourceUrl = imagePath + "gallery-large-5.jpg",
281           CornerRadius = new Vector4(0.03f, 0.03f, 0, 0),
282           CornerRadiusPolicy = VisualTransformPolicyType.Relative,
283         };
284         root.Add(image);
285         subWindowTwo.Add(root);
286       }
287       else
288       {
289         subWindowTwo.Minimize(false);
290       }
291     }
292
293
294
295     void Initialize()
296     {
297         win = NUIApplication.GetDefaultWindow();
298
299         var root = new ImageView()
300         {
301           WidthResizePolicy = ResizePolicyType.FillToParent,
302           HeightResizePolicy = ResizePolicyType.FillToParent,
303           ResourceUrl = imagePath + "gallery-large-14.jpg",
304           Layout = new LinearLayout()
305           {
306               LinearAlignment = LinearLayout.Alignment.CenterHorizontal,
307               LinearOrientation = LinearLayout.Orientation.Horizontal,
308               CellPadding = new Size(10, 10),
309           }
310         };
311         win.Add(root);
312
313
314         var appFunctionList = new View()
315         {
316           PositionUsesPivotPoint = true,
317           PivotPoint = PivotPoint.BottomLeft,
318           ParentOrigin = ParentOrigin.BottomLeft,
319           BackgroundColor = new Color(0, 1, 1, 0.5f),
320           Size = new Size(500, 200),
321           CornerRadius = 0.3f,
322           CornerRadiusPolicy = VisualTransformPolicyType.Relative,
323           Layout = new LinearLayout()
324           {
325               LinearAlignment = LinearLayout.Alignment.CenterHorizontal,
326               LinearOrientation = LinearLayout.Orientation.Horizontal,
327               CellPadding = new Size(10, 10),
328               Padding = new Extents(10, 10, 10 , 10),
329           }
330         };
331         root.Add(appFunctionList);
332
333         var defaultBorder = new View()
334         {
335           Size = new Size(150, 180),
336           Layout = new LinearLayout()
337           {
338               LinearAlignment = LinearLayout.Alignment.Center,
339               LinearOrientation = LinearLayout.Orientation.Vertical,
340           }
341         };
342
343         var imageViewA = new ImageView()
344         {
345           Size = new Size(150, 150),
346           ResourceUrl = imagePath + "gallery-large-9.jpg",
347           CornerRadius = 0.3f,
348           CornerRadiusPolicy = VisualTransformPolicyType.Relative,
349         };
350
351         var textViewA = new TextLabel()
352         {
353           Text = "Default",
354         };
355
356         defaultBorder.Add(imageViewA);
357         defaultBorder.Add(textViewA);
358         appFunctionList.Add(defaultBorder);
359         defaultBorder.TouchEvent += (s, e) =>
360         {
361           if (e.Touch.GetState(0) == PointStateType.Up)
362           {
363             CreateSubWindowOne();
364           }
365           return true;
366         };
367
368         var customBorder = new View()
369         {
370           Size = new Size(150, 180),
371           Layout = new LinearLayout()
372           {
373               LinearAlignment = LinearLayout.Alignment.Center,
374               LinearOrientation = LinearLayout.Orientation.Vertical,
375           }
376         };
377
378         var imageViewB = new ImageView()
379         {
380           Size = new Size(150, 150),
381           ResourceUrl = imagePath + "gallery-large-5.jpg",
382           CornerRadius = 0.3f,
383           CornerRadiusPolicy = VisualTransformPolicyType.Relative,
384         };
385         var textViewB = new TextLabel()
386         {
387           Text = "Custom",
388         };
389
390         customBorder.Add(imageViewB);
391         customBorder.Add(textViewB);
392         appFunctionList.Add(customBorder);
393         customBorder.TouchEvent += (s, e) =>
394         {
395           if (e.Touch.GetState(0) == PointStateType.Up)
396           {
397             CreateSubWindowTwo();
398           }
399           return true;
400         };
401     }
402
403     public void Activate()
404     {
405       Initialize();
406     }
407
408     public void Deactivate()
409     {
410     }
411
412
413   }
414 }