[NUI][TSCACR-454] Add RiveAnimationView APIs
[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, stopButton;
14         Button bounceButton, brokeButton;
15         Button fillButton, strokeButton, opacityButton;
16         Button scaleButton, rotationButton, positionButton;
17         public void Activate()
18         {
19             window = NUIApplication.GetDefaultWindow();
20             defaultLayer = window.GetDefaultLayer();
21             window.TouchEvent += OnRiveWindowTouchEvent;
22
23             // Load RiveAnimation File
24             rav = new Tizen.NUI.Extension.RiveAnimationView(Tizen.Applications.Application.Current.DirectoryInfo.Resource + "rive/flame-and-spark.riv")
25             {
26                 Size = new Size(720, 720),
27             };
28
29             // Enable RiveAnimation and Play
30             rav.EnableAnimation("idle", true);
31             rav.Play();
32
33             playButton = new Button()
34             {
35                 Size = new Size(200, 100),
36                 Position = new Position(0, 0),
37                 Text = "Play"
38             };
39             playButton.Clicked += (object source, ClickedEventArgs args) =>
40             {
41                 rav.Play();
42             };
43
44             defaultLayer.Add(rav);
45             defaultLayer.Add(playButton);
46         }
47
48          private void OnRiveWindowTouchEvent(object source, Window.TouchEventArgs e)
49         {
50             Vector2 lp = e.Touch.GetLocalPosition(0);
51             Vector2 sp = e.Touch.GetScreenPosition(0);
52             float scale = (1000.0f /720.0f);
53
54             // Set root and spark node position
55             rav.SetNodePosition("root", new Position(lp.X * scale, lp.Y * scale));
56             rav.SetNodePosition("spark", new Position((lp.X - 288) * scale, lp.Y) * scale);
57         }
58         public void Deactivate()
59         {
60             defaultLayer.Remove(rav);
61             defaultLayer.Remove(playButton);
62         }
63     }
64 }