[NUI] Merge branch 'devel/nui'
[platform/core/csapi/tizenfx.git] / NUIsamples / NUIsamples / src / examples / visual-view-test3.cs
1 /*
2  * Copyright (c) 2017 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.Constants;
22 using Tizen.NUI.BaseComponents;
23
24 namespace VisualViewTest3
25 {
26     // An example of Visual View control.
27     class Example : NUIApplication
28     {
29         private VisualView _visualView = null;
30         private const string resources = "/home/owner/apps_rw/NUISamples.TizenTV/res";
31         private Window _window;
32
33         public Example() : base()
34         {
35         }
36
37         public Example(string stylesheet) : base(stylesheet)
38         {
39         }
40
41         public Example(string stylesheet, WindowMode windowMode) : base(stylesheet, windowMode)
42         {
43         }
44
45         protected override void OnCreate()
46         {
47             base.OnCreate();
48             Initialize();
49         }
50
51         private ImageVisual imageVisualMap1;
52         private ImageVisual imageVisualMap2;
53         private int cnt;
54
55         public void Initialize()
56         {
57             Window window = Window.Instance;
58
59             /* Create a visual view. */
60             _visualView = new VisualView();
61             _visualView.ParentOrigin = ParentOrigin.TopLeft;
62             _visualView.PivotPoint = PivotPoint.TopLeft;
63             _visualView.Size2D = new Size2D(window.Size.Width, window.Size.Height);
64
65             /* color visual */
66             ColorVisual colorVisualMap1 = new ColorVisual();
67             colorVisualMap1.Color = Color.Green;
68             _visualView.Background = colorVisualMap1.OutputVisualMap;
69
70             window.Add(_visualView);
71
72             /* image visual 1. No transform setting case. */
73             imageVisualMap1 = new ImageVisual();
74             imageVisualMap1.URL = resources + "/images/image-1.jpg";
75             imageVisualMap1.DepthIndex = 1;
76             //_visualView.AddVisual("imageVisual1", imageVisualMap1);
77
78             /* image visual 2. Using RelativePosition and SizePolicyWidth setting case. */
79             imageVisualMap2 = new ImageVisual();
80             imageVisualMap2.URL = resources + "/images/image-2.jpg";
81             /* Using Size, you can set SizePolicyWidth and SizePolicyHeight separately, default by relative. */
82             imageVisualMap2.Size = new Vector2(400.0f, 0.3f);
83             /* Using RelativePosition, then PositionPolicyX and PositionPolicyY will be relative. */
84             imageVisualMap2.RelativePosition = new Vector2(0.1f, 0.1f);
85             imageVisualMap2.SizePolicyWidth = VisualTransformPolicyType.Absolute;
86             imageVisualMap2.Origin = Visual.AlignType.TopBegin;
87             imageVisualMap2.AnchorPoint = Visual.AlignType.TopBegin;
88             /* Ensure imageVisual show  */
89             imageVisualMap2.DepthIndex = 9;
90             _visualView.AddVisual("imageVisual2", imageVisualMap2);
91             /* If imageVisual2 added first, the it will be covered by imageVisual1.
92                so, we need to set their depth index to ensure they all can be showed.
93              */
94             _visualView.AddVisual("imageVisual1", imageVisualMap1);
95
96             _window = Window.Instance;
97             _window.FocusChanged += (sender, ee) =>
98             {
99                 cnt++;
100                 Tizen.Log.Debug("NUI", "[WindowFocusTest] WindowFocusChanged event comes! focus gained=" + ee.FocusGained);
101             };
102
103             Tizen.Log.Debug("NUI", "[WindowFocusTest] is focus acceptable=" + _window.IsFocusAcceptable());
104             _window.SetAcceptFocus(false);
105             Tizen.Log.Debug("NUI", "[WindowFocusTest] set focus acceptable=false!!!");
106             Tizen.Log.Debug("NUI", "[WindowFocusTest] is focus acceptable=" + _window.IsFocusAcceptable());
107             _window.SetAcceptFocus(true);
108             Tizen.Log.Debug("NUI", "[WindowFocusTest] set focus acceptable=true!!!");
109             Tizen.Log.Debug("NUI", "[WindowFocusTest] is focus acceptable=" + _window.IsFocusAcceptable());
110         }
111
112         [STAThread]
113         static void _Main(string[] args)
114         {
115             Example example = new Example();
116             example.Run(args);
117         }
118     }
119 }