3 using Tizen.NUI.UIComponents;
5 namespace VisualViewTest2
7 public class VisualSample : NUIApplication
14 ImageVisual imageMap2;
16 ImageVisual highlightImageMap;
17 ImageVisual dimImageMap;
26 readonly string resourcePath = "/home/owner/apps_rw/NUISamples.TizenTV/res/images/";
28 protected override void OnCreate()
32 view = new VisualView[2];
34 for (int i = 0; i < num; i++)
36 view[i] = new VisualView();
37 view[i].Size = new Size(600, 600, 0);
38 view[i].BackgroundColor = Color.Blue;
39 view[i].Position = new Position(400 + i * 800, 600, 0);
40 view[i].Focusable = true;
41 view[i].Name = "MyView" + i;
42 Stage.Instance.GetDefaultLayer().Add(view[i]);
43 view[i].FocusGained += VisualSample_FocusGained;
44 view[i].FocusLost += VisualSample_FocusLost;
45 view[i].KeyEvent += VisualSample_KeyEvent;
48 view[0].RightFocusableView = view[1];
49 view[1].LeftFocusableView = view[0];
51 imageMap = new ImageVisual();
52 imageMap.URL = resourcePath + "gallery-" + imgIndex++ + ".jpg";
53 imageMap.AnchorPoint = Visual.AlignType.TopBegin;
54 imageMap.Origin = Visual.AlignType.TopBegin;
55 imageMap.Position = new Vector2(0, 0);
56 imageMap.PositionPolicy = new Vector2(1, 1);
57 imageMap.Size = new Vector2(500, 500);
58 imageMap.SizePolicy = new Vector2(1, 1);
59 imageMap.DepthIndex = 0;
60 view[0].AddVisual("bgVisual", imageMap);
63 highlightImageMap = new ImageVisual();
64 highlightImageMap.URL = resourcePath + "star-highlight.png";
65 highlightImageMap.AnchorPoint = Visual.AlignType.TopBegin;
66 highlightImageMap.Origin = Visual.AlignType.TopBegin;
67 highlightImageMap.Size = new Vector2(40, 40);
68 highlightImageMap.SizePolicy = new Vector2(1, 1);
69 highlightImageMap.Position = new Vector2(10, 10);
70 highlightImageMap.PositionPolicy = new Vector2(1, 1);
71 highlightImageMap.DepthIndex = 1;
72 view[0].AddVisual("iconVisual", highlightImageMap);
75 textMap1 = new TextVisual();
76 textMap1.Text = "Hello";
77 textMap1.AnchorPoint = Visual.AlignType.TopBegin;
78 textMap1.Origin = Visual.AlignType.TopBegin;
79 textMap1.PointSize = 20;
80 textMap1.Position = new Vector2(60, 210);
81 textMap1.PositionPolicy = new Vector2(1, 1);
82 textMap1.Size = new Vector2(600, 200);
83 textMap1.SizePolicy = new Vector2(1, 1);
84 textMap1.TextColor = Color.Red;
85 textMap1.DepthIndex = 5;
86 view[0].AddVisual("textVisual", textMap1);
90 imageMap2 = new ImageVisual();
91 imageMap2.URL = resourcePath + "gallery-" + imgIndex + ".jpg";
92 imageMap2.AnchorPoint = Visual.AlignType.TopBegin;
93 imageMap2.Origin = Visual.AlignType.TopBegin;
94 imageMap2.Position = new Vector2(0, 0);
95 imageMap2.PositionPolicy = new Vector2(1, 1);
96 imageMap2.Size = new Vector2(500, 500);
97 imageMap2.SizePolicy = new Vector2(1, 1);
98 imageMap2.DepthIndex = 0;
99 view[1].AddVisual("bgVisual", imageMap2);
101 dimImageMap = new ImageVisual();
102 dimImageMap.URL = resourcePath + "star-dim.png";
103 dimImageMap.Size = new Vector2(40, 40);
104 dimImageMap.SizePolicy = new Vector2(1, 1);
105 dimImageMap.AnchorPoint = Visual.AlignType.TopBegin;
106 dimImageMap.Origin = Visual.AlignType.TopBegin;
107 dimImageMap.Position = new Vector2(10, 10);
108 dimImageMap.PositionPolicy = new Vector2(1, 1);
109 dimImageMap.DepthIndex = 1;
110 view[1].AddVisual("iconVisual", dimImageMap);
112 textMap2 = new TextVisual();
113 textMap2.Text = "I'm";
114 textMap2.PointSize = 20;
115 textMap2.AnchorPoint = Visual.AlignType.TopBegin;
116 textMap2.Origin = Visual.AlignType.TopBegin;
117 textMap2.Position = new Vector2(60, 210);
118 textMap2.PositionPolicy = new Vector2(1, 1);
119 textMap2.Size = new Vector2(600, 200);
120 textMap2.SizePolicy = new Vector2(1, 1);
121 textMap2.TextColor = Color.Black;
122 textMap2.DepthIndex = 5;
123 view[1].AddVisual("textVisual", textMap2);
126 guide = new TextLabel();
127 guide.AnchorPoint = AnchorPoint.TopLeft;
128 guide.Size2D = new Size2D(800, 200);
129 guide.Padding = new Vector4(50, 50, 50, 50);
130 guide.MultiLine = true;
131 guide.BackgroundColor = Color.Magenta;
132 guide.PointSize = 10;
133 guide.TextColor = Color.Black;
134 guide.Text = "Left/Right - Move focus\n" +
135 "Up/Down - Change Text\n" +
136 "Enter - Change BG image\n";
137 Stage.Instance.GetDefaultLayer().Add(guide);
139 Stage.Instance.Key += Instance_Key;
140 FocusManager.Instance.SetCurrentFocusView(view[0]);
141 Stage.Instance.Touch += Instance_Touch;
142 _window = this.Window;
143 _window.WindowFocusChanged += _window_WindowFocusChanged;
147 private void _window_WindowFocusChanged(object sender, Window.WindowFocusChangedEventArgs e)
149 Tizen.Log.Fatal("NUI", "window focus changed!() focus gained=" + e.FocusGained);
152 private void Instance_Touch(object sender, Stage.TouchEventArgs e)
154 FocusManager.Instance.SetCurrentFocusView(view[0]);
157 private bool VisualSample_KeyEvent(object source, View.KeyEventArgs e)
159 Tizen.Log.Fatal("NUI", "View_KeyEvent" + e.Key.State.ToString() + ", Pressed-" + e.Key.KeyPressedName);
161 if (e.Key.State == Key.StateType.Down)
163 if (source.Equals(view[0]))
165 if (e.Key.KeyPressedName == "Up")
167 textMap1.PointSize = 14;
168 textMap1.TextColor = Color.Red;
169 textMap1.Text = "Hello NY!";
170 //this.VersionCheckTest();
172 DALI_KEY_VOLUME_UP = 200, ///< Volume up key @SINCE_1_0.0
173 DALI_KEY_VOLUME_DOWN = 201, ///< Volume down key @SINCE_1_0.0
177 Tizen.Log.Fatal("NUI", "GrabKeyTopmost (200==vol up) ret=" + _window.GrabKeyTopmost(200));
179 catch (Exception except)
181 Tizen.Log.Fatal("NUI", "Exception!!! GrabKeyTopmost (200==vol up) msg=" + except.Message);
185 else if (e.Key.KeyPressedName == "Down")
187 textMap1.PointSize = 17;
188 textMap1.TextColor = Color.Blue;
189 textMap1.Text = "Goodbye NY.";
191 Tizen.Log.Fatal("NUI", "UngrabKeyTopmost (200==vol up) ret=" + _window.UngrabKeyTopmost(200));
194 else if (e.Key.KeyPressedName == "Return")
196 imgIndex = (imgIndex + 1) % 6;
197 imageMap.URL = resourcePath + "gallery-" + imgIndex + ".jpg";
198 //Tizen.Log.Fatal("NUI", "get native ecore wayland hander=" + _window.GetNativeWindowHandler());
204 if (e.Key.KeyPressedName == "Up")
206 textMap2.PointSize = 14;
207 textMap2.TextColor = Color.Red;
208 textMap2.Text = "I'm happy!";
209 Tizen.Log.Fatal("NUI", "grab key (201==vol down) ret=" + _window.GrabKey(201, Window.KeyGrabMode.Topmost));
212 if (e.Key.KeyPressedName == "Down")
214 textMap2.PointSize = 17;
215 textMap2.TextColor = Color.Blue;
216 textMap2.Text = "I'm unhappy";
217 Tizen.Log.Fatal("NUI", "ungrab key (201==vol down) ret=" + _window.UngrabKey(201));
219 else if (e.Key.KeyPressedName == "Return")
221 imgIndex = (imgIndex + 1) % 6;
222 imageMap2.URL = resourcePath + "gallery-" + imgIndex + ".jpg";
223 //Tizen.Log.Fatal("NUI", "get native ecore wayland hander=" + _window.GetNativeWindowHandler());
230 private void Instance_Key(object sender, Stage.KeyEventArgs e)
232 View currentFocusView = FocusManager.Instance.GetCurrentFocusView();
234 Tizen.Log.Fatal("NUI", "Stage_KeyEvent" + e.Key.State.ToString() + ", Pressed-" + e.Key.KeyPressedName);
235 //Tizen.Log.Fatal("NUI", " CurrentFocusView : " + currentFocusView.HasBody() + currentFocusView?.Name);
238 private void VisualSample_FocusLost(object sender, EventArgs e)
240 VisualView view = sender as VisualView;
241 view.BackgroundColor = Color.Green;
242 view.Scale = new Vector3(1.0f, 1.0f, 1.0f);
244 view.AddVisual("iconVisual", dimImageMap);
246 if (view.Name == "MyView1")
248 imageMap2.MixColor = new Color(1, 0, 0, 0.5f);
249 imageMap2.Opacity = 0.5f;
251 else if (view.Name == "MyView0")
253 imageMap.MixColor = new Color(1, 0, 0, 0.5f);
254 imageMap.Opacity = 0.5f;
257 Tizen.Log.Fatal("NUI", "FocusLost-" + view.Name);
260 private void VisualSample_FocusGained(object sender, EventArgs e)
262 VisualView view = sender as VisualView;
263 view.BackgroundColor = Color.Yellow;
264 view.Scale = new Vector3(1.2f, 1.2f, 1.0f);
266 view.AddVisual("iconVisual", highlightImageMap);
268 if (view.Name == "MyView1")
270 imageMap2.MixColor = new Color(1, 1, 1, 1);
271 imageMap2.Opacity = 1.0f;
273 else if (view.Name == "MyView0")
275 imageMap.MixColor = new Color(1, 1, 1, 1);
276 imageMap.Opacity = 1.0f;
279 Tizen.Log.Fatal("NUI", "FocusGained-" + view.Name);
282 static void _Main(string[] args)
284 VisualSample sample = new VisualSample();