3 using Tizen.NUI.Components;
4 using Tizen.NUI.BaseComponents;
5 using Tizen.NUI.Extension;
9 class Program : NUIApplication
11 //Define RiveAnimation Variable as Member Variable
12 Tizen.NUI.Extension.RiveAnimationView rav;
14 //Control RiveAnimationState Buttons
15 Button inButton, outButton, thinkingButton, okButton, listenButton;
17 //Control Position Animation for RiveAnimationView
18 Animation moveAnimation;
19 AlphaFunction alphaFunction;
20 Button topButton, bottomButton, leftButton, centerButton, rightButton;
21 Button leftTopButton, rightTopButton, leftBottomButton, rightBottomButton;
23 //In and Out Animation Timer
24 Animation showAnimation;
25 Animation inAnimation;
26 Animation outAnimation;
27 Animation resetEyeAnimation;
28 Animation resetOkAnimation;
29 Animation resetThinkingAnimation;
30 Animation resetListenAnimation;
32 void resetEyeFinished(object sender, EventArgs e)
34 rav.SetAnimationElapsedTime("reset", -1.0f);
37 void resetOkFinished(object sender, EventArgs e)
39 rav.SetAnimationElapsedTime("thinking", -1.0f);
40 rav.SetAnimationElapsedTime("listen", -1.0f);
43 void resetThinkingFinished(object sender, EventArgs e)
45 rav.SetAnimationElapsedTime("ok", -1.0f);
46 rav.SetAnimationElapsedTime("listen", -1.0f);
49 void resetListenFinished(object sender, EventArgs e)
51 rav.SetAnimationElapsedTime("ok", -1.0f);
52 rav.SetAnimationElapsedTime("thinking", -1.0f);
55 void moveAnimationFinished(object sender, EventArgs e)
57 rav.SetAnimationElapsedTime("reset", 0.0f);
58 rav.SetAnimationElapsedTime("eye 360", -1.0f);
60 if (resetEyeAnimation)
62 resetEyeAnimation.Stop();
66 resetEyeAnimation = new Animation(100);
67 resetEyeAnimation.Finished += resetEyeFinished;
69 resetEyeAnimation.Play();
72 void showAnimationFinished(object sender, EventArgs e)
78 rav.SetAnimationElapsedTime("reset", -1.0f);
79 rav.SetAnimationElapsedTime("eye 360", -1.0f);
80 rav.SetAnimationElapsedTime("out", 0.0f);
82 rav.SetAnimationElapsedTime("thinking", 0.0f);
83 rav.SetAnimationElapsedTime("listen", 0.0f);
84 rav.SetAnimationElapsedTime("ok", 0.0f);
85 rav.EnableAnimation("thinking", false);
86 rav.EnableAnimation("listen", false);
87 rav.EnableAnimation("ok", false);
89 rav.EnableAnimation("out", false);
90 rav.EnableAnimation("in", true);
95 void inAnimationFinished(object sender, EventArgs e)
97 rav.SetAnimationElapsedTime("reset", -1.0f);
98 rav.SetAnimationElapsedTime("eye 360", -1.0f);
99 rav.SetAnimationElapsedTime("out", -1.0f);
100 rav.EnableAnimation("in", false);
101 rav.EnableAnimation("idle", true);
104 void outAnimationFinished(object sender, EventArgs e)
106 rav.SetAnimationElapsedTime("reset", 0.0f);
107 rav.SetAnimationElapsedTime("eye 360", -1.0f);
108 rav.SetAnimationElapsedTime("out", -1.0f);
109 rav.EnableAnimation("out", false);
110 rav.EnableAnimation("idle", false);
113 void InitializeTimer()
115 showAnimation = new Animation(100);
116 showAnimation.Finished += showAnimationFinished;
117 inAnimation = new Animation(1100);
118 inAnimation.Finished += inAnimationFinished;
119 outAnimation = new Animation(900);
120 outAnimation.Finished += outAnimationFinished;
123 protected override void OnCreate()
130 protected override void OnTerminate()
136 private double CalculateEyeAngle(Vector2 targetPos)
138 double ravCenterX = rav.PositionX + (rav.Size.Width / 2);
139 double ravCenterY = rav.PositionY + (rav.Size.Height / 2);
141 double angle = Math.Atan2(targetPos.Y - ravCenterY, targetPos.X - ravCenterX) * (180.0f / Math.PI);
145 angle = 360.0f + angle;
148 double angleToTime = angle / 180.0f;
152 private void OnTouchEvent(object source, Window.TouchEventArgs e)
154 if (e.Touch.GetState(0) == PointStateType.Motion)
156 //Calibrate Cursor Posiiton to Animation Time
157 Vector2 pos = e.Touch.GetScreenPosition(0);
158 double angleToTime = CalculateEyeAngle(pos);
160 //Control eye 360 animation using cursor position
161 rav.SetAnimationElapsedTime("reset", -1.0f);
162 rav.SetAnimationElapsedTime("eye 360", (float)angleToTime);
166 void ResetMoveAnimation()
168 //Reset previous moving animation
171 moveAnimation.Stop();
172 moveAnimation.Dispose();
175 moveAnimation = new Animation(800);
176 var c1 = new Vector2(0.5f, 0.0f);
177 var c2 = new Vector2(0.5f, 1.0f);
179 alphaFunction = new AlphaFunction(c1, c2);
180 moveAnimation.DefaultAlphaFunction = alphaFunction;
181 moveAnimation.Finished += moveAnimationFinished;
184 void ApplyMoveAnimation(int X, int Y)
186 ResetMoveAnimation();
187 Vector2 pos = new Vector2(X, Y);
188 double angleToTime = CalculateEyeAngle(pos);
189 rav.SetAnimationElapsedTime("reset", -1.0f);
190 rav.SetAnimationElapsedTime("eye 360", (float)angleToTime);
192 moveAnimation.AnimateTo(rav, "PositionX", pos.X);
193 moveAnimation.AnimateTo(rav, "PositionY", pos.Y);
194 moveAnimation.Play();
199 Window.Instance.WindowSize = new Size(1920, 1080);
201 //Make Window Transparency
202 Window.Instance.BackgroundColor = Color.Transparent;
203 Window.Instance.SetTransparency(true);
205 //Ignore Key Events for Receiving remote controller event
206 Window.Instance.SetAcceptFocus(false);
208 //Set Window Notification Type
209 Window.Instance.Type = WindowType.Notification;
211 //Make Window Notification Level Top
212 Window.Instance.SetNotificationLevel(NotificationLevel.Top);
214 Window.Instance.TouchEvent += OnTouchEvent;
216 //Create RiveAnimation
217 rav = new Tizen.NUI.Extension.RiveAnimationView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "mini_a.riv")
219 Size = new Size(250, 250),
220 Position = new Position( 750, 300)
223 //Enable In Animation
224 rav.EnableAnimation("in", true);
230 inButton = new Button()
232 Size = new Size(120, 100),
233 Position = new Position(10, 10),
236 inButton.Clicked += (object source, ClickedEventArgs args) =>
240 showAnimation.Stop();
243 showAnimation.Play();
246 outButton = new Button()
248 Size = new Size(120, 100),
249 Position = new Position(140, 10),
252 outButton.Clicked += (object source, ClickedEventArgs args) =>
258 rav.EnableAnimation("in", false);
259 rav.EnableAnimation("out", true);
263 okButton = new Button()
265 Size = new Size(120, 100),
266 Position = new Position(10, 120),
269 okButton.Clicked += (object source, ClickedEventArgs args) =>
271 rav.SetAnimationElapsedTime("reset", -1.0f);
272 rav.SetAnimationElapsedTime("eye 360", -1.0f);
273 //Enable ok animation only
274 rav.SetAnimationElapsedTime("thinking", 0.0f);
275 rav.SetAnimationElapsedTime("listen", 0.0f);
277 if (resetOkAnimation)
279 resetOkAnimation.Stop();
283 resetOkAnimation = new Animation(100);
284 resetOkAnimation.Finished += resetOkFinished;
286 resetOkAnimation.Play();
288 rav.EnableAnimation("thinking", false);
289 rav.EnableAnimation("listen", false);
290 rav.EnableAnimation("ok", true);
293 listenButton = new Button()
295 Size = new Size(120, 100),
296 Position = new Position(140, 120),
299 listenButton.Clicked += (object source, ClickedEventArgs args) =>
301 rav.SetAnimationElapsedTime("reset", -1.0f);
302 rav.SetAnimationElapsedTime("eye 360", -1.0f);
303 //Enable listen animation only
304 rav.SetAnimationElapsedTime("ok", 0.0f);
305 rav.SetAnimationElapsedTime("thinking", 0.0f);
307 if (resetListenAnimation)
309 resetListenAnimation.Stop();
313 resetListenAnimation = new Animation(100);
314 resetListenAnimation.Finished += resetListenFinished;
316 resetListenAnimation.Play();
318 rav.EnableAnimation("ok", false);
319 rav.EnableAnimation("thinking", false);
320 rav.EnableAnimation("listen", true);
323 thinkingButton = new Button()
325 Size = new Size(120, 100),
326 Position = new Position(270, 120),
329 thinkingButton.Clicked += (object source, ClickedEventArgs args) =>
331 rav.SetAnimationElapsedTime("reset", -1.0f);
332 rav.SetAnimationElapsedTime("eye 360", -1.0f);
333 //Enable ok animation only
334 rav.SetAnimationElapsedTime("ok", 0.0f);
335 rav.SetAnimationElapsedTime("listen", 0.0f);
337 if (resetThinkingAnimation)
339 resetThinkingAnimation.Stop();
343 resetThinkingAnimation = new Animation(100);
344 resetThinkingAnimation.Finished += resetThinkingFinished;
346 resetThinkingAnimation.Play();
348 rav.EnableAnimation("ok", false);
349 rav.EnableAnimation("listen", false);
350 rav.EnableAnimation("thinking", true);
353 topButton = new Button()
355 Size = new Size(160, 100),
356 Position = new Position(180, 250),
359 topButton.Clicked += (object source, ClickedEventArgs args) =>
361 ApplyMoveAnimation(750, 0);
364 bottomButton = new Button()
366 Size = new Size(160, 100),
367 Position = new Position(180, 470),
370 bottomButton.Clicked += (object source, ClickedEventArgs args) =>
372 ApplyMoveAnimation(750, 600);
375 leftButton = new Button()
377 Size = new Size(160, 100),
378 Position = new Position(10, 360),
381 leftButton.Clicked += (object source, ClickedEventArgs args) =>
383 ApplyMoveAnimation(300, 300);
386 centerButton = new Button()
388 Size = new Size(160, 100),
389 Position = new Position(180, 360),
392 centerButton.Clicked += (object source, ClickedEventArgs args) =>
394 ApplyMoveAnimation(750, 300);
397 rightButton = new Button()
399 Size = new Size(160, 100),
400 Position = new Position(350, 360),
403 rightButton.Clicked += (object source, ClickedEventArgs args) =>
405 ApplyMoveAnimation(1400, 300);
408 leftTopButton = new Button()
410 Size = new Size(160, 100),
411 Position = new Position(10, 250),
414 leftTopButton.Clicked += (object source, ClickedEventArgs args) =>
416 ApplyMoveAnimation(300, 0);
419 rightTopButton = new Button()
421 Size = new Size(160, 100),
422 Position = new Position(350, 250),
425 rightTopButton.Clicked += (object source, ClickedEventArgs args) =>
427 ApplyMoveAnimation(1400, 0);
430 leftBottomButton = new Button()
432 Size = new Size(160, 100),
433 Position = new Position(10, 470),
436 leftBottomButton.Clicked += (object source, ClickedEventArgs args) =>
438 ApplyMoveAnimation(300, 750);
441 rightBottomButton = new Button()
443 Size = new Size(160, 100),
444 Position = new Position(350, 470),
447 rightBottomButton.Clicked += (object source, ClickedEventArgs args) =>
449 ApplyMoveAnimation(1400, 750);
452 //Add RiveAnimationView and NUI Buttons to Main Window
453 Window.Instance.GetDefaultLayer().Add(rav);
454 Window.Instance.GetDefaultLayer().Add(inButton);
455 Window.Instance.GetDefaultLayer().Add(outButton);
456 Window.Instance.GetDefaultLayer().Add(thinkingButton);
457 Window.Instance.GetDefaultLayer().Add(listenButton);
458 Window.Instance.GetDefaultLayer().Add(okButton);
459 Window.Instance.GetDefaultLayer().Add(topButton);
460 Window.Instance.GetDefaultLayer().Add(bottomButton);
461 Window.Instance.GetDefaultLayer().Add(leftButton);
462 Window.Instance.GetDefaultLayer().Add(centerButton);
463 Window.Instance.GetDefaultLayer().Add(rightButton);
464 Window.Instance.GetDefaultLayer().Add(leftTopButton);
465 Window.Instance.GetDefaultLayer().Add(rightTopButton);
466 Window.Instance.GetDefaultLayer().Add(leftBottomButton);
467 Window.Instance.GetDefaultLayer().Add(rightBottomButton);
472 //Remove RiveAnimationView and NUI Buttons from Main Window
473 Window.Instance.GetDefaultLayer().Remove(rav);
474 Window.Instance.GetDefaultLayer().Remove(inButton);
475 Window.Instance.GetDefaultLayer().Remove(outButton);
476 Window.Instance.GetDefaultLayer().Remove(thinkingButton);
477 Window.Instance.GetDefaultLayer().Remove(listenButton);
478 Window.Instance.GetDefaultLayer().Remove(okButton);
479 Window.Instance.GetDefaultLayer().Remove(topButton);
480 Window.Instance.GetDefaultLayer().Remove(bottomButton);
481 Window.Instance.GetDefaultLayer().Remove(leftButton);
482 Window.Instance.GetDefaultLayer().Remove(centerButton);
483 Window.Instance.GetDefaultLayer().Remove(rightButton);
484 Window.Instance.GetDefaultLayer().Remove(leftTopButton);
485 Window.Instance.GetDefaultLayer().Remove(rightTopButton);
486 Window.Instance.GetDefaultLayer().Remove(leftBottomButton);
487 Window.Instance.GetDefaultLayer().Remove(rightBottomButton);
490 static void Main(string[] args)
492 var app = new Program();