3 using Tizen.NUI.UIComponents;
4 using Tizen.NUI.BaseComponents;
6 namespace VisualViewTest2
8 public class VisualSample : NUIApplication
15 ImageVisual imageMap2;
17 ImageVisual highlightImageMap;
18 ImageVisual dimImageMap;
27 readonly string resourcePath = "/home/owner/apps_rw/NUISamples.TizenTV/res/images/";
29 protected override void OnCreate()
33 view = new VisualView[2];
35 for (int i = 0; i < num; i++)
37 view[i] = new VisualView();
38 view[i].Size2D = new Size2D(600, 600);
39 view[i].BackgroundColor = Color.Blue;
40 view[i].Position = new Position(400 + i * 800, 600, 0);
41 view[i].Focusable = true;
42 view[i].Name = "MyView" + i;
43 Window.Instance.Add(view[i]);
44 view[i].FocusGained += VisualSample_FocusGained;
45 view[i].FocusLost += VisualSample_FocusLost;
46 view[i].KeyEvent += VisualSample_KeyEvent;
49 view[0].RightFocusableView = view[1];
50 view[1].LeftFocusableView = view[0];
52 imageMap = new ImageVisual();
53 imageMap.URL = resourcePath + "gallery-" + imgIndex++ + ".jpg";
54 imageMap.AnchorPoint = Visual.AlignType.TopBegin;
55 imageMap.Origin = Visual.AlignType.TopBegin;
56 imageMap.Position = new Vector2(0, 0);
57 imageMap.PositionPolicy = VisualTransformPolicyType.Absolute;
58 imageMap.Size = new Size2D(500, 500);
59 imageMap.SizePolicy = VisualTransformPolicyType.Absolute;
60 imageMap.DepthIndex = 0;
61 view[0].AddVisual("bgVisual", imageMap);
64 highlightImageMap = new ImageVisual();
65 highlightImageMap.URL = resourcePath + "star-highlight.png";
66 highlightImageMap.AnchorPoint = Visual.AlignType.TopBegin;
67 highlightImageMap.Origin = Visual.AlignType.TopBegin;
68 highlightImageMap.Size = new Vector2(40, 40);
69 highlightImageMap.SizePolicy = VisualTransformPolicyType.Absolute;
70 highlightImageMap.Position = new Vector2(10, 10);
71 highlightImageMap.PositionPolicy = VisualTransformPolicyType.Absolute;
72 highlightImageMap.DepthIndex = 1;
73 view[0].AddVisual("iconVisual", highlightImageMap);
76 textMap1 = new TextVisual();
77 textMap1.Text = "Hello";
78 textMap1.AnchorPoint = Visual.AlignType.TopBegin;
79 textMap1.Origin = Visual.AlignType.TopBegin;
80 textMap1.PointSize = 20;
81 textMap1.Position = new Vector2(60, 210);
82 textMap1.PositionPolicy = VisualTransformPolicyType.Absolute;
83 textMap1.Size = new Vector2(600, 200);
84 textMap1.SizePolicy = VisualTransformPolicyType.Absolute;
85 textMap1.TextColor = Color.Red;
86 textMap1.DepthIndex = 5;
87 view[0].AddVisual("textVisual", textMap1);
91 imageMap2 = new ImageVisual();
92 imageMap2.URL = resourcePath + "gallery-" + imgIndex + ".jpg";
93 imageMap2.AnchorPoint = Visual.AlignType.TopBegin;
94 imageMap2.Origin = Visual.AlignType.TopBegin;
95 imageMap2.Position = new Vector2(0, 0);
96 imageMap2.PositionPolicy = VisualTransformPolicyType.Absolute;
97 imageMap2.Size = new Vector2(500, 500);
98 imageMap2.SizePolicy = VisualTransformPolicyType.Absolute;
99 imageMap2.DepthIndex = 0;
100 view[1].AddVisual("bgVisual", imageMap2);
102 dimImageMap = new ImageVisual();
103 dimImageMap.URL = resourcePath + "star-dim.png";
104 dimImageMap.Size = new Vector2(40, 40);
105 dimImageMap.SizePolicy = VisualTransformPolicyType.Absolute;
106 dimImageMap.AnchorPoint = Visual.AlignType.TopBegin;
107 dimImageMap.Origin = Visual.AlignType.TopBegin;
108 dimImageMap.Position = new Vector2(10, 10);
109 dimImageMap.PositionPolicy = VisualTransformPolicyType.Absolute;
110 dimImageMap.DepthIndex = 1;
111 view[1].AddVisual("iconVisual", dimImageMap);
113 textMap2 = new TextVisual();
114 textMap2.Text = "I'm";
115 textMap2.PointSize = 20;
116 textMap2.AnchorPoint = Visual.AlignType.TopBegin;
117 textMap2.Origin = Visual.AlignType.TopBegin;
118 textMap2.Position = new Vector2(60, 210);
119 textMap2.PositionPolicy = VisualTransformPolicyType.Absolute;
120 textMap2.Size = new Vector2(600, 200);
121 textMap2.SizePolicy = VisualTransformPolicyType.Absolute;
122 textMap2.TextColor = Color.Black;
123 textMap2.DepthIndex = 5;
124 view[1].AddVisual("textVisual", textMap2);
127 guide = new TextLabel();
128 guide.PivotPoint = PivotPoint.TopLeft;
129 guide.Size2D = new Size2D(800, 200);
130 guide.Padding = new Vector4(50, 50, 50, 50);
131 guide.MultiLine = true;
132 guide.BackgroundColor = Color.Magenta;
133 guide.PointSize = 10;
134 guide.TextColor = Color.Black;
135 guide.Text = "Left/Right - Move focus\n" +
136 "Up/Down - Change Text\n" +
137 "Enter - Change BG image\n";
138 Window.Instance.Add(guide);
140 Window.Instance.KeyEvent += Instance_Key;
141 FocusManager.Instance.SetCurrentFocusView(view[0]);
142 Window.Instance.TouchEvent += Instance_Touch;
143 _window = Window.Instance;
144 _window.FocusChanged += _window_WindowFocusChanged;
148 private void _window_WindowFocusChanged(object sender, Window.FocusChangedEventArgs e)
150 Tizen.Log.Fatal("NUI", "window focus changed!() focus gained=" + e.FocusGained);
153 private void Instance_Touch(object sender, Window.TouchEventArgs e)
155 FocusManager.Instance.SetCurrentFocusView(view[0]);
158 private bool VisualSample_KeyEvent(object source, View.KeyEventArgs e)
160 Tizen.Log.Fatal("NUI", "View_KeyEvent" + e.Key.State.ToString() + ", Pressed-" + e.Key.KeyPressedName);
162 if (e.Key.State == Key.StateType.Down)
164 if (source.Equals(view[0]))
166 if (e.Key.KeyPressedName == "Up")
168 textMap1.PointSize = 14;
169 textMap1.TextColor = Color.Red;
170 textMap1.Text = "Hello NY!";
171 //this.VersionCheckTest();
173 DALI_KEY_VOLUME_UP = 200, ///< Volume up key @SINCE_1_0.0
174 DALI_KEY_VOLUME_DOWN = 201, ///< Volume down key @SINCE_1_0.0
178 Tizen.Log.Fatal("NUI", "GrabKeyTopmost (200==vol up) ret=" + _window.GrabKeyTopmost(200));
180 catch (Exception except)
182 Tizen.Log.Fatal("NUI", "Exception!!! GrabKeyTopmost (200==vol up) msg=" + except.Message);
186 else if (e.Key.KeyPressedName == "Down")
188 textMap1.PointSize = 17;
189 textMap1.TextColor = Color.Blue;
190 textMap1.Text = "Goodbye NY.";
192 Tizen.Log.Fatal("NUI", "UngrabKeyTopmost (200==vol up) ret=" + _window.UngrabKeyTopmost(200));
195 else if (e.Key.KeyPressedName == "Return")
197 imgIndex = (imgIndex + 1) % 6;
198 imageMap.URL = resourcePath + "gallery-" + imgIndex + ".jpg";
199 //Tizen.Log.Fatal("NUI", "get native ecore wayland hander=" + _window.GetNativeWindowHandler());
205 if (e.Key.KeyPressedName == "Up")
207 textMap2.PointSize = 14;
208 textMap2.TextColor = Color.Red;
209 textMap2.Text = "I'm happy!";
210 Tizen.Log.Fatal("NUI", "grab key (201==vol down) ret=" + _window.GrabKey(201, Window.KeyGrabMode.Topmost));
213 if (e.Key.KeyPressedName == "Down")
215 textMap2.PointSize = 17;
216 textMap2.TextColor = Color.Blue;
217 textMap2.Text = "I'm unhappy";
218 Tizen.Log.Fatal("NUI", "ungrab key (201==vol down) ret=" + _window.UngrabKey(201));
220 else if (e.Key.KeyPressedName == "Return")
222 imgIndex = (imgIndex + 1) % 6;
223 imageMap2.URL = resourcePath + "gallery-" + imgIndex + ".jpg";
224 //Tizen.Log.Fatal("NUI", "get native ecore wayland hander=" + _window.GetNativeWindowHandler());
231 private void Instance_Key(object sender, Window.KeyEventArgs e)
233 View currentFocusView = FocusManager.Instance.GetCurrentFocusView();
235 Tizen.Log.Fatal("NUI", "Window_KeyEvent" + e.Key.State.ToString() + ", Pressed-" + e.Key.KeyPressedName);
236 //Tizen.Log.Fatal("NUI", " CurrentFocusView : " + currentFocusView.HasBody() + currentFocusView?.Name);
239 private void VisualSample_FocusLost(object sender, EventArgs e)
241 VisualView view = sender as VisualView;
242 view.BackgroundColor = Color.Green;
243 view.Scale = new Vector3(1.0f, 1.0f, 1.0f);
245 view.AddVisual("iconVisual", dimImageMap);
247 if (view.Name == "MyView1")
249 imageMap2.MixColor = new Color(1, 0, 0, 0.5f);
250 imageMap2.Opacity = 0.5f;
252 else if (view.Name == "MyView0")
254 imageMap.MixColor = new Color(1, 0, 0, 0.5f);
255 imageMap.Opacity = 0.5f;
258 Tizen.Log.Fatal("NUI", "FocusLost-" + view.Name);
261 private void VisualSample_FocusGained(object sender, EventArgs e)
263 VisualView view = sender as VisualView;
264 view.BackgroundColor = Color.Yellow;
265 view.Scale = new Vector3(1.2f, 1.2f, 1.0f);
267 view.AddVisual("iconVisual", highlightImageMap);
269 if (view.Name == "MyView1")
271 imageMap2.MixColor = new Color(1, 1, 1, 1);
272 imageMap2.Opacity = 1.0f;
274 else if (view.Name == "MyView0")
276 imageMap.MixColor = new Color(1, 1, 1, 1);
277 imageMap.Opacity = 1.0f;
280 Tizen.Log.Fatal("NUI", "FocusGained-" + view.Name);
283 static void _Main(string[] args)
285 VisualSample sample = new VisualSample();