[NUI] Remove build warning messages in NUI Samples (#4932)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / RiveAnimationFollowTouch.cs
1 using Tizen.NUI.BaseComponents;
2 using Tizen.NUI.Extension;
3 using Tizen.NUI.Components;
4
5 namespace Tizen.NUI.Samples
6 {
7     public class RiveAnimationFollowTouch : IExample
8     {
9         private Window window;
10         private Layer defaultLayer;
11
12         Tizen.NUI.Extension.RiveAnimationView rav;
13         Button playButton;
14         public void Activate()
15         {
16             window = NUIApplication.GetDefaultWindow();
17             defaultLayer = window.GetDefaultLayer();
18             window.TouchEvent += OnRiveWindowTouchEvent;
19
20             // Load RiveAnimation File
21             rav = new Tizen.NUI.Extension.RiveAnimationView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "rive/flame-and-spark.riv")
22             {
23                 Size = new Size(720, 720),
24             };
25
26             // Enable RiveAnimation and Play
27             rav.EnableAnimation("idle", true);
28             rav.Play();
29
30             playButton = new Button()
31             {
32                 Size = new Size(200, 100),
33                 Position = new Position(0, 0),
34                 Text = "Play"
35             };
36             playButton.Clicked += (object source, ClickedEventArgs args) =>
37             {
38                 rav.Play();
39             };
40
41             defaultLayer.Add(rav);
42             defaultLayer.Add(playButton);
43         }
44
45         private void OnRiveWindowTouchEvent(object source, Window.TouchEventArgs e)
46         {
47             Vector2 lp = e.Touch.GetLocalPosition(0);
48             Vector2 sp = e.Touch.GetScreenPosition(0);
49             float scale = (1000.0f / 720.0f);
50
51             // Set root and spark node position
52             rav.SetNodePosition("root", new Position(lp.X * scale, lp.Y * scale));
53             rav.SetNodePosition("spark", new Position((lp.X - 288) * scale, lp.Y) * scale);
54         }
55         public void Deactivate()
56         {
57             window.TouchEvent -= OnRiveWindowTouchEvent;
58             if (rav) { defaultLayer.Remove(rav); }
59             if (playButton) { defaultLayer.Remove(playButton); }
60         }
61     }
62 }