sync ElmSharp source code latest
[platform/core/csapi/tizenfx.git] / test / ElmSharp.Test / TC / EcoreTimelineAnimatorTest1.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using ElmSharp;
5
6 namespace ElmSharp.Test
7 {
8     class EcoreTimelineAnimatorTest1 : TestCaseBase
9
10     {
11         public override string TestName => "Timeline Animator Test1";
12
13         public override string TestDescription => "Ecore Timeline Animator Test1";
14
15         EcoreTimelineAnimator timelineAnimator;
16
17         int X1, Y1, X2, Y2;
18
19         Tuple<string, AnimatorMotionMapper>[] mappers =
20         {
21             new Tuple<string, AnimatorMotionMapper>("Linear", new LinearMotionMapper()),
22             new Tuple<string, AnimatorMotionMapper>("Accelerate", new AccelerateMotionMapper()),
23             new Tuple<string, AnimatorMotionMapper>("Decelerate", new DecelerateMotionMapper()),
24             new Tuple<string, AnimatorMotionMapper>("Sinusoida", new SinusoidalMotionMapper()),
25             new Tuple<string, AnimatorMotionMapper>("Bounce", new BounceMotionMapper{ Bounces = 3, DecayFactor = 1.8 }),
26             new Tuple<string, AnimatorMotionMapper>("Spring", new SpringMotionMapper{ Wobbles = 3, DecayFactor = 1.8 }),
27             new Tuple<string, AnimatorMotionMapper>("AccelerateFactor", new AccelerateFactorMotionMapper{ PowerFactor = 1.5 }),
28             new Tuple<string, AnimatorMotionMapper>("DecelerateFactor", new DecelerateFactorMotionMapper{ PowerFactor = 1.5 }),
29             new Tuple<string, AnimatorMotionMapper>("SinusoidaFactor", new SinusoidalFactorMotionMapper{ PowerFactor = 1.5 }),
30             new Tuple<string, AnimatorMotionMapper>("DivisorInterpolate", new DivisorInterpolatedMotionMapper{ Divisor = 1.0, Power = 2.0 }),
31             new Tuple<string, AnimatorMotionMapper>("CubicBezier", new CubicBezierMotionMapper{ X1 = 0, X2 = 1, Y1 = 0, Y2 = 1})
32         };
33
34         int map_index = 0;
35
36         Rectangle square;
37
38         public override void Run(Window window)
39         {
40             Rect rect = new Rect(0, 0, window.ScreenSize.Width, window.ScreenSize.Height);
41
42             X1 = rect.X;
43             Y1 = rect.Y;
44             X2 = rect.X + rect.Width - rect.Width / 10;
45             Y2 = rect.Y;
46
47             square = new Rectangle(window)
48             {
49                 Geometry = new Rect(X1, Y1, rect.Width / 10, rect.Height / 6),
50                 Color = Color.Red
51             };
52             square.Show();
53
54             Button btn = new Button(window)
55             {
56                 Geometry = new Rect(rect.X, rect.Y + rect.Height - rect.Height / 4, rect.Width, rect.Height / 4),
57                 Text = mappers[map_index].Item1
58             };
59             btn.Show();
60
61             timelineAnimator = new EcoreTimelineAnimator(1.0, OnTimeline);
62
63             btn.Clicked += Btn_Clicked;
64             timelineAnimator.Finished += (s, e) =>
65             {
66                 map_index = (map_index + 1) % mappers.Length;
67                 btn.IsEnabled = true;
68             };
69         }
70
71         private void Btn_Clicked(object sender, EventArgs e)
72         {
73             timelineAnimator.Start();
74             ((Button)sender).IsEnabled = false;
75             Log.Debug(mappers[map_index].Item1);
76         }
77
78         void OnTimeline()
79         {
80             double o = mappers[map_index].Item2.Caculate(timelineAnimator.Position);
81             int x = (int)((X2 * o) + (X1 * (1.0 - o)));
82             int y = (int)((Y2 * o) + (Y1 * (1.0 - o)));
83
84             square.Move(x, y);
85         }
86     }
87 }