Manual merge for nui v0.2.35.
[platform/core/csapi/nui.git] / NUISamples / NUISamples / NUISamples.TizenTV / examples / visual-view-test2.cs
1 using System;
2 using Tizen.NUI;
3 using Tizen.NUI.UIComponents;
4
5 namespace VisualViewTest2
6 {
7     public class VisualSample : NUIApplication
8     {
9         const int num = 2;
10         VisualView[] view;
11
12         TextLabel guide;
13         ImageVisual imageMap;
14         ImageVisual imageMap2;
15
16         ImageVisual highlightImageMap;
17         ImageVisual dimImageMap;
18
19         TextVisual textMap1;
20         TextVisual textMap2;
21
22         int imgIndex;
23
24         readonly string resourcePath = "/home/owner/apps_rw/NUISamples.TizenTV/res/images/";
25
26         protected override void OnCreate()
27         {
28             base.OnCreate();
29
30             view = new VisualView[2];
31
32             for (int i = 0; i < num; i++)
33             {
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;
44             }
45
46             view[0].RightFocusableView = view[1];
47             view[1].LeftFocusableView = view[0];
48
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);
59
60
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);
71
72
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);
85
86
87
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);
98
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);
109
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);
122
123
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);
136
137             Stage.Instance.Key += Instance_Key;
138             FocusManager.Instance.SetCurrentFocusView(view[0]);
139             Stage.Instance.Touch += Instance_Touch;
140         }
141
142
143         private void Instance_Touch(object sender, Stage.TouchEventArgs e)
144         {
145             FocusManager.Instance.SetCurrentFocusView(view[0]);
146         }
147
148         private bool VisualSample_KeyEvent(object source, View.KeyEventArgs e)
149         {
150             Tizen.Log.Debug("NUI", "View_KeyEvent" + e.Key.State.ToString() + ", Pressed-" + e.Key.KeyPressedName);
151
152             if (e.Key.State == Key.StateType.Down)
153             {
154                 if (source.Equals(view[0]))
155                 {
156                     if (e.Key.KeyPressedName == "Up")
157                     {
158                         textMap1.PointSize = 14;
159                         textMap1.TextColor = Color.Red;
160                         textMap1.Text = "Hello NY!";
161                     }
162                     else if (e.Key.KeyPressedName == "Down")
163                     {
164                         textMap1.PointSize = 17;
165                         textMap1.TextColor = Color.Blue;
166                         textMap1.Text = "Goodbye NY.";
167                     }
168                     else if (e.Key.KeyPressedName == "Return")
169                     {
170                         imgIndex = (imgIndex + 1) % 6;
171                         imageMap.URL = resourcePath + "gallery-" + imgIndex + ".jpg";
172                     }
173
174                 }
175                 else
176                 {
177                     if (e.Key.KeyPressedName == "Up")
178                     {
179                         textMap2.PointSize = 14;
180                         textMap2.TextColor = Color.Red;
181                         textMap2.Text = "I'm happy!";
182                     }
183
184                     if (e.Key.KeyPressedName == "Down")
185                     {
186                         textMap2.PointSize = 17;
187                         textMap2.TextColor = Color.Blue;
188                         textMap2.Text = "I'm unhappy";
189                     }
190                     else if (e.Key.KeyPressedName == "Return")
191                     {
192                         imgIndex = (imgIndex + 1) % 6;
193                         imageMap2.URL = resourcePath + "gallery-" + imgIndex + ".jpg";
194                     }
195                 }
196             }
197             return false;
198         }
199
200         private void Instance_Key(object sender, Stage.KeyEventArgs e)
201         {
202             View currentFocusView = FocusManager.Instance.GetCurrentFocusView();
203
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);
206         }
207
208         private void VisualSample_FocusLost(object sender, EventArgs e)
209         {
210             VisualView view = sender as VisualView;
211             view.BackgroundColor = Color.Green;
212             view.Scale = new Vector3(1.0f, 1.0f, 1.0f);
213
214             view.AddVisual("iconVisual", dimImageMap);
215
216             if (view.Name == "MyView1")
217             {
218                 imageMap2.MixColor = new Color(1, 0, 0, 0.5f);
219                 imageMap2.Opacity = 0.5f;
220             }
221             else if (view.Name == "MyView0")
222             {
223                 imageMap.MixColor = new Color(1, 0, 0, 0.5f);
224                 imageMap.Opacity = 0.5f;
225             }
226
227             Tizen.Log.Debug("NUI", "FocusLost-" + view.Name);
228         }
229
230         private void VisualSample_FocusGained(object sender, EventArgs e)
231         {
232             VisualView view = sender as VisualView;
233             view.BackgroundColor = Color.Yellow;
234             view.Scale = new Vector3(1.2f, 1.2f, 1.0f);
235
236             view.AddVisual("iconVisual", highlightImageMap);
237
238             if (view.Name == "MyView1")
239             {
240                 imageMap2.MixColor = new Color(1, 1, 1, 1);
241                 imageMap2.Opacity = 1.0f;
242             }
243             else if (view.Name == "MyView0")
244             {
245                 imageMap.MixColor = new Color(1, 1, 1, 1);
246                 imageMap.Opacity = 1.0f;
247             }
248
249             Tizen.Log.Debug("NUI", "FocusGained-" + view.Name);
250         }
251
252         static void _Main(string[] args)
253         {
254             VisualSample sample = new VisualSample();
255             sample.Run(args);
256         }
257     }
258 }