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