3 using Tizen.NUI.UIComponents;
5 namespace VisualViewTest2
7 public class VisualSample : NUIApplication
14 ImageVisual imageMap2;
16 ImageVisual highlightImageMap;
17 ImageVisual dimImageMap;
24 readonly string resourcePath = "/home/owner/apps_rw/NUISamples.TizenTV/res/images/";
26 protected override void OnCreate()
30 view = new VisualView[2];
32 for (int i = 0; i < num; i++)
34 view[i] = new VisualView();
35 view[i].Size = new Size(600, 600, 0);
36 view[i].BackgroundColor = Color.Blue;
37 view[i].Position = new Position(400 + i * 800, 600, 0);
38 view[i].Focusable = true;
39 view[i].Name = "MyView" + i;
40 Stage.Instance.GetDefaultLayer().Add(view[i]);
41 view[i].FocusGained += VisualSample_FocusGained;
42 view[i].FocusLost += VisualSample_FocusLost;
43 view[i].KeyEvent += VisualSample_KeyEvent;
46 view[0].RightFocusableView = view[1];
47 view[1].LeftFocusableView = view[0];
49 imageMap = new ImageVisual();
50 imageMap.URL = resourcePath + "gallery-" + imgIndex++ + ".jpg";
51 imageMap.AnchorPoint = Visual.AlignType.TopBegin;
52 imageMap.Origin = Visual.AlignType.TopBegin;
53 imageMap.Position = new Vector2(0, 0);
54 imageMap.PositionPolicy = new Vector2(1, 1);
55 imageMap.Size = new Vector2(500, 500);
56 imageMap.SizePolicy = new Vector2(1, 1);
57 imageMap.DepthIndex = 0;
58 view[0].AddVisual("bgVisual", imageMap);
61 highlightImageMap = new ImageVisual();
62 highlightImageMap.URL = resourcePath + "star-highlight.png";
63 highlightImageMap.AnchorPoint = Visual.AlignType.TopBegin;
64 highlightImageMap.Origin = Visual.AlignType.TopBegin;
65 highlightImageMap.Size = new Vector2(40, 40);
66 highlightImageMap.SizePolicy = new Vector2(1, 1);
67 highlightImageMap.Position = new Vector2(10, 10);
68 highlightImageMap.PositionPolicy = new Vector2(1, 1);
69 highlightImageMap.DepthIndex = 1;
70 view[0].AddVisual("iconVisual", highlightImageMap);
73 textMap1 = new TextVisual();
74 textMap1.Text = "Hello";
75 textMap1.AnchorPoint = Visual.AlignType.TopBegin;
76 textMap1.Origin = Visual.AlignType.TopBegin;
77 textMap1.PointSize = 20;
78 textMap1.Position = new Vector2(60, 210);
79 textMap1.PositionPolicy = new Vector2(1, 1);
80 textMap1.Size = new Vector2(600, 200);
81 textMap1.SizePolicy = new Vector2(1, 1);
82 textMap1.TextColor = Color.Red;
83 textMap1.DepthIndex = 5;
84 view[0].AddVisual("textVisual", textMap1);
88 imageMap2 = new ImageVisual();
89 imageMap2.URL = resourcePath + "gallery-" + imgIndex + ".jpg";
90 imageMap2.AnchorPoint = Visual.AlignType.TopBegin;
91 imageMap2.Origin = Visual.AlignType.TopBegin;
92 imageMap2.Position = new Vector2(0, 0);
93 imageMap2.PositionPolicy = new Vector2(1, 1);
94 imageMap2.Size = new Vector2(500, 500);
95 imageMap2.SizePolicy = new Vector2(1, 1);
96 imageMap2.DepthIndex = 0;
97 view[1].AddVisual("bgVisual", imageMap2);
99 dimImageMap = new ImageVisual();
100 dimImageMap.URL = resourcePath + "star-dim.png";
101 dimImageMap.Size = new Vector2(40, 40);
102 dimImageMap.SizePolicy = new Vector2(1, 1);
103 dimImageMap.AnchorPoint = Visual.AlignType.TopBegin;
104 dimImageMap.Origin = Visual.AlignType.TopBegin;
105 dimImageMap.Position = new Vector2(10, 10);
106 dimImageMap.PositionPolicy = new Vector2(1, 1);
107 dimImageMap.DepthIndex = 1;
108 view[1].AddVisual("iconVisual", dimImageMap);
110 textMap2 = new TextVisual();
111 textMap2.Text = "I'm";
112 textMap2.PointSize = 20;
113 textMap2.AnchorPoint = Visual.AlignType.TopBegin;
114 textMap2.Origin = Visual.AlignType.TopBegin;
115 textMap2.Position = new Vector2(60, 210);
116 textMap2.PositionPolicy = new Vector2(1, 1);
117 textMap2.Size = new Vector2(600, 200);
118 textMap2.SizePolicy = new Vector2(1, 1);
119 textMap2.TextColor = Color.Black;
120 textMap2.DepthIndex = 5;
121 view[1].AddVisual("textVisual", textMap2);
124 guide = new TextLabel();
125 guide.AnchorPoint = AnchorPoint.TopLeft;
126 guide.Size2D = new Size2D(800, 200);
127 guide.Padding = new Vector4(50, 50, 50, 50);
128 guide.MultiLine = true;
129 guide.BackgroundColor = Color.Magenta;
130 guide.PointSize = 10;
131 guide.TextColor = Color.Black;
132 guide.Text = "Left/Right - Move focus\n" +
133 "Up/Down - Change Text\n" +
134 "Enter - Change BG image\n";
135 Stage.Instance.GetDefaultLayer().Add(guide);
137 Stage.Instance.Key += Instance_Key;
138 FocusManager.Instance.SetCurrentFocusView(view[0]);
139 Stage.Instance.Touch += Instance_Touch;
143 private void Instance_Touch(object sender, Stage.TouchEventArgs e)
145 FocusManager.Instance.SetCurrentFocusView(view[0]);
148 private bool VisualSample_KeyEvent(object source, View.KeyEventArgs e)
150 Tizen.Log.Debug("NUI", "View_KeyEvent" + e.Key.State.ToString() + ", Pressed-" + e.Key.KeyPressedName);
152 if (e.Key.State == Key.StateType.Down)
154 if (source.Equals(view[0]))
156 if (e.Key.KeyPressedName == "Up")
158 textMap1.PointSize = 14;
159 textMap1.TextColor = Color.Red;
160 textMap1.Text = "Hello NY!";
162 else if (e.Key.KeyPressedName == "Down")
164 textMap1.PointSize = 17;
165 textMap1.TextColor = Color.Blue;
166 textMap1.Text = "Goodbye NY.";
168 else if (e.Key.KeyPressedName == "Return")
170 imgIndex = (imgIndex + 1) % 6;
171 imageMap.URL = resourcePath + "gallery-" + imgIndex + ".jpg";
177 if (e.Key.KeyPressedName == "Up")
179 textMap2.PointSize = 14;
180 textMap2.TextColor = Color.Red;
181 textMap2.Text = "I'm happy!";
184 if (e.Key.KeyPressedName == "Down")
186 textMap2.PointSize = 17;
187 textMap2.TextColor = Color.Blue;
188 textMap2.Text = "I'm unhappy";
190 else if (e.Key.KeyPressedName == "Return")
192 imgIndex = (imgIndex + 1) % 6;
193 imageMap2.URL = resourcePath + "gallery-" + imgIndex + ".jpg";
200 private void Instance_Key(object sender, Stage.KeyEventArgs e)
202 View currentFocusView = FocusManager.Instance.GetCurrentFocusView();
204 Tizen.Log.Debug("NUI", "Stage_KeyEvent" + e.Key.State.ToString() + ", Pressed-" + e.Key.KeyPressedName);
205 //Tizen.Log.Debug("NUI", " CurrentFocusView : " + currentFocusView.HasBody() + currentFocusView?.Name);
208 private void VisualSample_FocusLost(object sender, EventArgs e)
210 VisualView view = sender as VisualView;
211 view.BackgroundColor = Color.Green;
212 view.Scale = new Vector3(1.0f, 1.0f, 1.0f);
214 view.AddVisual("iconVisual", dimImageMap);
216 if (view.Name == "MyView1")
218 imageMap2.MixColor = new Color(1, 0, 0, 0.5f);
219 imageMap2.Opacity = 0.5f;
221 else if (view.Name == "MyView0")
223 imageMap.MixColor = new Color(1, 0, 0, 0.5f);
224 imageMap.Opacity = 0.5f;
227 Tizen.Log.Debug("NUI", "FocusLost-" + view.Name);
230 private void VisualSample_FocusGained(object sender, EventArgs e)
232 VisualView view = sender as VisualView;
233 view.BackgroundColor = Color.Yellow;
234 view.Scale = new Vector3(1.2f, 1.2f, 1.0f);
236 view.AddVisual("iconVisual", highlightImageMap);
238 if (view.Name == "MyView1")
240 imageMap2.MixColor = new Color(1, 1, 1, 1);
241 imageMap2.Opacity = 1.0f;
243 else if (view.Name == "MyView0")
245 imageMap.MixColor = new Color(1, 1, 1, 1);
246 imageMap.Opacity = 1.0f;
249 Tizen.Log.Debug("NUI", "FocusGained-" + view.Name);
252 static void _Main(string[] args)
254 VisualSample sample = new VisualSample();