4 namespace VisualViewTest2
6 public class VisualSample : NUIApplication
13 ImageVisual imageMap2;
15 ImageVisual highlightImageMap;
16 ImageVisual dimImageMap;
23 readonly string resourcePath = "/home/owner/apps_rw/NUISamples.TizenTV/res/images/";
25 protected override void OnCreate()
29 view = new VisualView[2];
31 for (int i = 0; i < num; i++)
33 view[i] = new VisualView();
34 view[i].Size = new Size(600, 600, 0);
35 view[i].BackgroundColor = Color.Blue;
36 view[i].Position = new Position(400 + i * 800, 600, 0);
37 view[i].Focusable = true;
38 view[i].Name = "MyView" + i;
39 Stage.Instance.GetDefaultLayer().Add(view[i]);
40 view[i].FocusGained += VisualSample_FocusGained;
41 view[i].FocusLost += VisualSample_FocusLost;
42 view[i].KeyEvent += VisualSample_KeyEvent;
45 view[0].RightFocusableView = view[1];
46 view[1].LeftFocusableView = view[0];
48 imageMap = new ImageVisual();
49 imageMap.URL = resourcePath + "gallery-" + imgIndex++ + ".jpg";
50 imageMap.AnchorPoint = Visual.AlignType.TopBegin;
51 imageMap.Origin = Visual.AlignType.TopBegin;
52 imageMap.Position = new Vector2(0, 0);
53 imageMap.PositionPolicy = new Vector2(1, 1);
54 imageMap.Size = new Vector2(500, 500);
55 imageMap.SizePolicy = new Vector2(1, 1);
56 imageMap.DepthIndex = 0;
57 view[0].AddVisual("bgVisual", imageMap);
60 highlightImageMap = new ImageVisual();
61 highlightImageMap.URL = resourcePath + "star-highlight.png";
62 highlightImageMap.AnchorPoint = Visual.AlignType.TopBegin;
63 highlightImageMap.Origin = Visual.AlignType.TopBegin;
64 highlightImageMap.Size = new Vector2(40, 40);
65 highlightImageMap.SizePolicy = new Vector2(1, 1);
66 highlightImageMap.Position = new Vector2(10, 10);
67 highlightImageMap.PositionPolicy = new Vector2(1, 1);
68 highlightImageMap.DepthIndex = 1;
69 view[0].AddVisual("iconVisual", highlightImageMap);
72 textMap1 = new TextVisual();
73 textMap1.Text = "Hello";
74 textMap1.AnchorPoint = Visual.AlignType.TopBegin;
75 textMap1.Origin = Visual.AlignType.TopBegin;
76 textMap1.PointSize = 20;
77 textMap1.Position = new Vector2(60, 210);
78 textMap1.PositionPolicy = new Vector2(1, 1);
79 textMap1.Size = new Vector2(600, 200);
80 textMap1.SizePolicy = new Vector2(1, 1);
81 textMap1.TextColor = Color.Red;
82 textMap1.DepthIndex = 5;
83 view[0].AddVisual("textVisual", textMap1);
87 imageMap2 = new ImageVisual();
88 imageMap2.URL = resourcePath + "gallery-" + imgIndex + ".jpg";
89 imageMap2.AnchorPoint = Visual.AlignType.TopBegin;
90 imageMap2.Origin = Visual.AlignType.TopBegin;
91 imageMap2.Position = new Vector2(0, 0);
92 imageMap2.PositionPolicy = new Vector2(1, 1);
93 imageMap2.Size = new Vector2(500, 500);
94 imageMap2.SizePolicy = new Vector2(1, 1);
95 imageMap2.DepthIndex = 0;
96 view[1].AddVisual("bgVisual", imageMap2);
98 dimImageMap = new ImageVisual();
99 dimImageMap.URL = resourcePath + "star-dim.png";
100 dimImageMap.Size = new Vector2(40, 40);
101 dimImageMap.SizePolicy = new Vector2(1, 1);
102 dimImageMap.AnchorPoint = Visual.AlignType.TopBegin;
103 dimImageMap.Origin = Visual.AlignType.TopBegin;
104 dimImageMap.Position = new Vector2(10, 10);
105 dimImageMap.PositionPolicy = new Vector2(1, 1);
106 dimImageMap.DepthIndex = 1;
107 view[1].AddVisual("iconVisual", dimImageMap);
109 textMap2 = new TextVisual();
110 textMap2.Text = "I'm";
111 textMap2.PointSize = 20;
112 textMap2.AnchorPoint = Visual.AlignType.TopBegin;
113 textMap2.Origin = Visual.AlignType.TopBegin;
114 textMap2.Position = new Vector2(60, 210);
115 textMap2.PositionPolicy = new Vector2(1, 1);
116 textMap2.Size = new Vector2(600, 200);
117 textMap2.SizePolicy = new Vector2(1, 1);
118 textMap2.TextColor = Color.Black;
119 textMap2.DepthIndex = 5;
120 view[1].AddVisual("textVisual", textMap2);
123 guide = new TextLabel();
124 guide.AnchorPoint = AnchorPoint.TopLeft;
125 guide.Size2D = new Size2D(800, 200);
126 guide.Padding = new Vector4(50, 50, 50, 50);
127 guide.MultiLine = true;
128 guide.BackgroundColor = Color.Magenta;
129 guide.PointSize = 10;
130 guide.TextColor = Color.Black;
131 guide.Text = "Left/Right - Move focus\n" +
132 "Up/Down - Change Text\n" +
133 "Enter - Change BG image\n";
134 Stage.Instance.GetDefaultLayer().Add(guide);
136 Stage.Instance.Key += Instance_Key;
137 FocusManager.Instance.SetCurrentFocusView(view[0]);
138 Stage.Instance.Touch += Instance_Touch;
142 private void Instance_Touch(object sender, Stage.TouchEventArgs e)
144 FocusManager.Instance.SetCurrentFocusView(view[0]);
147 private bool VisualSample_KeyEvent(object source, View.KeyEventArgs e)
149 Tizen.Log.Debug("NUI", "View_KeyEvent" + e.Key.State.ToString() + ", Pressed-" + e.Key.KeyPressedName);
151 if (e.Key.State == Key.StateType.Down)
153 if (source.Equals(view[0]))
155 if (e.Key.KeyPressedName == "Up")
157 textMap1.PointSize = 14;
158 textMap1.TextColor = Color.Red;
159 textMap1.Text = "Hello NY!";
161 else if (e.Key.KeyPressedName == "Down")
163 textMap1.PointSize = 17;
164 textMap1.TextColor = Color.Blue;
165 textMap1.Text = "Goodbye NY.";
167 else if (e.Key.KeyPressedName == "Return")
169 imgIndex = (imgIndex + 1) % 6;
170 imageMap.URL = resourcePath + "gallery-" + imgIndex + ".jpg";
176 if (e.Key.KeyPressedName == "Up")
178 textMap2.PointSize = 14;
179 textMap2.TextColor = Color.Red;
180 textMap2.Text = "I'm happy!";
183 if (e.Key.KeyPressedName == "Down")
185 textMap2.PointSize = 17;
186 textMap2.TextColor = Color.Blue;
187 textMap2.Text = "I'm unhappy";
189 else if (e.Key.KeyPressedName == "Return")
191 imgIndex = (imgIndex + 1) % 6;
192 imageMap2.URL = resourcePath + "gallery-" + imgIndex + ".jpg";
199 private void Instance_Key(object sender, Stage.KeyEventArgs e)
201 View currentFocusView = FocusManager.Instance.GetCurrentFocusView();
203 Tizen.Log.Debug("NUI", "Stage_KeyEvent" + e.Key.State.ToString() + ", Pressed-" + e.Key.KeyPressedName);
204 //Tizen.Log.Debug("NUI", " CurrentFocusView : " + currentFocusView.HasBody() + currentFocusView?.Name);
207 private void VisualSample_FocusLost(object sender, EventArgs e)
209 VisualView view = sender as VisualView;
210 view.BackgroundColor = Color.Green;
211 view.Scale = new Vector3(1.0f, 1.0f, 1.0f);
213 view.AddVisual("iconVisual", dimImageMap);
215 if (view.Name == "MyView1")
217 imageMap2.MixColor = new Color(1, 0, 0, 0.5f);
218 imageMap2.Opacity = 0.5f;
220 else if (view.Name == "MyView0")
222 imageMap.MixColor = new Color(1, 0, 0, 0.5f);
223 imageMap.Opacity = 0.5f;
226 Tizen.Log.Debug("NUI", "FocusLost-" + view.Name);
229 private void VisualSample_FocusGained(object sender, EventArgs e)
231 VisualView view = sender as VisualView;
232 view.BackgroundColor = Color.Yellow;
233 view.Scale = new Vector3(1.2f, 1.2f, 1.0f);
235 view.AddVisual("iconVisual", highlightImageMap);
237 if (view.Name == "MyView1")
239 imageMap2.MixColor = new Color(1, 1, 1, 1);
240 imageMap2.Opacity = 1.0f;
242 else if (view.Name == "MyView0")
244 imageMap.MixColor = new Color(1, 1, 1, 1);
245 imageMap.Opacity = 1.0f;
248 Tizen.Log.Debug("NUI", "FocusGained-" + view.Name);
251 static void _Main(string[] args)
253 VisualSample sample = new VisualSample();