summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKangho Hur <kangho.hur@samsung.com>2017-08-21 01:12:59 +0000
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>2017-08-21 01:12:59 +0000
commit03c67b804006c7e0a6d09cf2f702e88846ad5f89 (patch)
tree639dd53956e4d3928f5f041b5fb6de656d576484
parentbf21450dcd55f8dcc363037b98976176d45c5dc1 (diff)
parent7e1157f8aad6e1220650e6fe25499fe3cda00f69 (diff)
downloadelm-sharp-03c67b804006c7e0a6d09cf2f702e88846ad5f89.tar.gz
elm-sharp-03c67b804006c7e0a6d09cf2f702e88846ad5f89.tar.bz2
elm-sharp-03c67b804006c7e0a6d09cf2f702e88846ad5f89.zip
Merge "Add Timeline Animator classes" into tizen
-rw-r--r--ElmSharp.Test/TC/EcoreTimelineAnimatorTest1.cs87
-rw-r--r--ElmSharp.Test/TC/Wearable/EcoreTimelineAnimatorTest1.cs87
-rw-r--r--ElmSharp/ElmSharp/AnimatorMotionMapper.cs119
-rw-r--r--ElmSharp/ElmSharp/EcoreTimelineAnimator.cs70
-rw-r--r--ElmSharp/Interop/Interop.Ecore.cs37
5 files changed, 400 insertions, 0 deletions
diff --git a/ElmSharp.Test/TC/EcoreTimelineAnimatorTest1.cs b/ElmSharp.Test/TC/EcoreTimelineAnimatorTest1.cs
new file mode 100644
index 0000000..e112cbb
--- /dev/null
+++ b/ElmSharp.Test/TC/EcoreTimelineAnimatorTest1.cs
@@ -0,0 +1,87 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using ElmSharp;
+
+namespace ElmSharp.Test
+{
+ class EcoreTimelineAnimatorTest1 : TestCaseBase
+
+ {
+ public override string TestName => "Timeline Animator Test1";
+
+ public override string TestDescription => "Ecore Timeline Animator Test1";
+
+ EcoreTimelineAnimator timelineAnimator;
+
+ int X1, Y1, X2, Y2;
+
+ Tuple<string, AnimatorMotionMapper>[] mappers =
+ {
+ new Tuple<string, AnimatorMotionMapper>("Linear", new LinearMotionMapper()),
+ new Tuple<string, AnimatorMotionMapper>("Accelerate", new AccelerateMotionMapper()),
+ new Tuple<string, AnimatorMotionMapper>("Decelerate", new DecelerateMotionMapper()),
+ new Tuple<string, AnimatorMotionMapper>("Sinusoida", new SinusoidalMotionMapper()),
+ new Tuple<string, AnimatorMotionMapper>("Bounce", new BounceMotionMapper{ Bounces = 3, DecayFactor = 1.8 }),
+ new Tuple<string, AnimatorMotionMapper>("Spring", new SpringMotionMapper{ Wobbles = 3, DecayFactor = 1.8 }),
+ new Tuple<string, AnimatorMotionMapper>("AccelerateFactor", new AccelerateFactorMotionMapper{ PowerFactor = 1.5 }),
+ new Tuple<string, AnimatorMotionMapper>("DecelerateFactor", new DecelerateFactorMotionMapper{ PowerFactor = 1.5 }),
+ new Tuple<string, AnimatorMotionMapper>("SinusoidaFactor", new SinusoidalFactorMotionMapper{ PowerFactor = 1.5 }),
+ new Tuple<string, AnimatorMotionMapper>("DivisorInterpolate", new DivisorInterpolatedMotionMapper{ Divisor = 1.0, Power = 2.0 }),
+ new Tuple<string, AnimatorMotionMapper>("CubicBezier", new CubicBezierMotionMapper{ X1 = 0, X2 = 1, Y1 = 0, Y2 = 1})
+ };
+
+ int map_index = 0;
+
+ Rectangle square;
+
+ public override void Run(Window window)
+ {
+ Rect rect = new Rect(0, 0, window.ScreenSize.Width, window.ScreenSize.Height);
+
+ X1 = rect.X;
+ Y1 = rect.Y;
+ X2 = rect.X + rect.Width - rect.Width / 10;
+ Y2 = rect.Y;
+
+ square = new Rectangle(window)
+ {
+ Geometry = new Rect(X1, Y1, rect.Width / 10, rect.Height / 6),
+ Color = Color.Red
+ };
+ square.Show();
+
+ Button btn = new Button(window)
+ {
+ Geometry = new Rect(rect.X, rect.Y + rect.Height - rect.Height / 4, rect.Width, rect.Height / 4),
+ Text = mappers[map_index].Item1
+ };
+ btn.Show();
+
+ timelineAnimator = new EcoreTimelineAnimator(1.0, OnTimeline);
+
+ btn.Clicked += Btn_Clicked;
+ timelineAnimator.Finished += (s, e) =>
+ {
+ map_index = (map_index + 1) % mappers.Length;
+ btn.IsEnabled = true;
+ };
+ }
+
+ private void Btn_Clicked(object sender, EventArgs e)
+ {
+ timelineAnimator.Start();
+ ((Button)sender).IsEnabled = false;
+ Log.Debug(mappers[map_index].Item1);
+ }
+
+ void OnTimeline()
+ {
+ double o = mappers[map_index].Item2.Caculate(timelineAnimator.Position);
+ int x = (int)((X2 * o) + (X1 * (1.0 - o)));
+ int y = (int)((Y2 * o) + (Y1 * (1.0 - o)));
+
+ square.Move(x, y);
+ }
+ }
+}
diff --git a/ElmSharp.Test/TC/Wearable/EcoreTimelineAnimatorTest1.cs b/ElmSharp.Test/TC/Wearable/EcoreTimelineAnimatorTest1.cs
new file mode 100644
index 0000000..16e023f
--- /dev/null
+++ b/ElmSharp.Test/TC/Wearable/EcoreTimelineAnimatorTest1.cs
@@ -0,0 +1,87 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using ElmSharp;
+
+namespace ElmSharp.Test.Wearable
+{
+ class EcoreTimelineAnimatorTest1 : WearableTestCase
+
+ {
+ public override string TestName => "Timeline Animator Test1";
+
+ public override string TestDescription => "Ecore Timeline Animator Test1";
+
+ EcoreTimelineAnimator timelineAnimator;
+
+ int X1, Y1, X2, Y2;
+
+ Tuple<string, AnimatorMotionMapper>[] mappers =
+ {
+ new Tuple<string, AnimatorMotionMapper>("Linear", new LinearMotionMapper()),
+ new Tuple<string, AnimatorMotionMapper>("Accelerate", new AccelerateMotionMapper()),
+ new Tuple<string, AnimatorMotionMapper>("Decelerate", new DecelerateMotionMapper()),
+ new Tuple<string, AnimatorMotionMapper>("Sinusoida", new SinusoidalMotionMapper()),
+ new Tuple<string, AnimatorMotionMapper>("Bounce", new BounceMotionMapper{ Bounces = 3, DecayFactor = 1.8 }),
+ new Tuple<string, AnimatorMotionMapper>("Spring", new SpringMotionMapper{ Wobbles = 3, DecayFactor = 1.8 }),
+ new Tuple<string, AnimatorMotionMapper>("AccelerateFactor", new AccelerateFactorMotionMapper{ PowerFactor = 1.5 }),
+ new Tuple<string, AnimatorMotionMapper>("DecelerateFactor", new DecelerateFactorMotionMapper{ PowerFactor = 1.5 }),
+ new Tuple<string, AnimatorMotionMapper>("SinusoidaFactor", new SinusoidalFactorMotionMapper{ PowerFactor = 1.5 }),
+ new Tuple<string, AnimatorMotionMapper>("DivisorInterpolate", new DivisorInterpolatedMotionMapper{ Divisor = 1.0, Power = 2.0 }),
+ new Tuple<string, AnimatorMotionMapper>("CubicBezier", new CubicBezierMotionMapper{ X1 = 0, X2 = 1, Y1 = 0, Y2 = 1})
+ };
+
+ int map_index = 0;
+
+ Rectangle square;
+
+ public override void Run(Window window)
+ {
+ Rect rect = window.GetInnerSquare();
+
+ X1 = rect.X;
+ Y1 = rect.Y;
+ X2 = rect.X + rect.Width - rect.Width / 10;
+ Y2 = rect.Y;
+
+ square = new Rectangle(window)
+ {
+ Geometry = new Rect(X1, Y1, rect.Width / 10, rect.Height / 6),
+ Color = Color.Red
+ };
+ square.Show();
+
+ Button btn = new Button(window)
+ {
+ Geometry = new Rect(rect.X, rect.Y + rect.Height - rect.Height / 4, rect.Width, rect.Height / 4),
+ Text = mappers[map_index].Item1
+ };
+ btn.Show();
+
+ timelineAnimator = new EcoreTimelineAnimator(1.0, OnTimeline);
+
+ btn.Clicked += Btn_Clicked;
+ timelineAnimator.Finished += (s, e) =>
+ {
+ map_index = (map_index + 1) % mappers.Length;
+ btn.IsEnabled = true;
+ };
+ }
+
+ private void Btn_Clicked(object sender, EventArgs e)
+ {
+ timelineAnimator.Start();
+ ((Button)sender).IsEnabled = false;
+ Log.Debug(mappers[map_index].Item1);
+ }
+
+ void OnTimeline()
+ {
+ double o = mappers[map_index].Item2.Caculate(timelineAnimator.Position);
+ int x = (int)((X2 * o) + (X1 * (1.0 - o)));
+ int y = (int)((Y2 * o) + (Y1 * (1.0 - o)));
+
+ square.Move(x, y);
+ }
+ }
+}
diff --git a/ElmSharp/ElmSharp/AnimatorMotionMapper.cs b/ElmSharp/ElmSharp/AnimatorMotionMapper.cs
new file mode 100644
index 0000000..defc7af
--- /dev/null
+++ b/ElmSharp/ElmSharp/AnimatorMotionMapper.cs
@@ -0,0 +1,119 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace ElmSharp
+{
+ public interface AnimatorMotionMapper
+ {
+ double Caculate(double position);
+ }
+
+ public class LinearMotionMapper : AnimatorMotionMapper
+ {
+ public double Caculate(double position)
+ {
+ return Interop.Ecore.ecore_animator_pos_map(position, Interop.Ecore.PositionMap.Linear, 0, 0);
+ }
+ }
+
+ public class AccelerateMotionMapper : AnimatorMotionMapper
+ {
+ public double Caculate(double position)
+ {
+ return Interop.Ecore.ecore_animator_pos_map(position, Interop.Ecore.PositionMap.Accelerate, 0, 0);
+ }
+ }
+
+ public class DecelerateMotionMapper : AnimatorMotionMapper
+ {
+ public double Caculate(double position)
+ {
+ return Interop.Ecore.ecore_animator_pos_map(position, Interop.Ecore.PositionMap.Decelerate, 0, 0);
+ }
+ }
+
+ public class SinusoidalMotionMapper : AnimatorMotionMapper
+ {
+ public double Caculate(double position)
+ {
+ return Interop.Ecore.ecore_animator_pos_map(position, Interop.Ecore.PositionMap.Sinusoidal, 0, 0);
+ }
+ }
+
+ public class AccelerateFactorMotionMapper : AnimatorMotionMapper
+ {
+ public double PowerFactor { get; set; } = 0;
+
+ public double Caculate(double position)
+ {
+ return Interop.Ecore.ecore_animator_pos_map(position, Interop.Ecore.PositionMap.AccelerateFactor, PowerFactor, 0);
+ }
+ }
+
+ public class DecelerateFactorMotionMapper : AnimatorMotionMapper
+ {
+ public double PowerFactor { get; set; } = 0;
+
+ public double Caculate(double position)
+ {
+ return Interop.Ecore.ecore_animator_pos_map(position, Interop.Ecore.PositionMap.DecelerateFactor, PowerFactor, 0);
+ }
+ }
+
+ public class SinusoidalFactorMotionMapper : AnimatorMotionMapper
+ {
+ public double PowerFactor { get; set; } = 0;
+
+ public double Caculate(double position)
+ {
+ return Interop.Ecore.ecore_animator_pos_map(position, Interop.Ecore.PositionMap.SinusoidalFactor, PowerFactor, 0);
+ }
+ }
+
+ public class DivisorInterpolatedMotionMapper : AnimatorMotionMapper
+ {
+ public double Divisor { get; set; } = 0;
+ public double Power { get; set; } = 0;
+
+ public double Caculate(double position)
+ {
+ return Interop.Ecore.ecore_animator_pos_map(position, Interop.Ecore.PositionMap.DivisorInterp, Divisor, Power);
+ }
+ }
+
+ public class BounceMotionMapper : AnimatorMotionMapper
+ {
+ public int Bounces { get; set; } = 0;
+ public double DecayFactor { get; set; } = 0;
+ public double Caculate(double position)
+ {
+ return Interop.Ecore.ecore_animator_pos_map(position, Interop.Ecore.PositionMap.Bounce, DecayFactor, Bounces);
+ }
+ }
+
+ public class SpringMotionMapper : AnimatorMotionMapper
+ {
+ public int Wobbles { get; set; } = 0;
+ public double DecayFactor { get; set; } = 0;
+
+ public double Caculate(double position)
+ {
+ return Interop.Ecore.ecore_animator_pos_map(position, Interop.Ecore.PositionMap.Bounce, DecayFactor, Wobbles);
+ }
+ }
+
+ public class CubicBezierMotionMapper : AnimatorMotionMapper
+ {
+ public double X1 { get; set; } = 0;
+ public double Y1 { get; set; } = 0;
+ public double X2 { get; set; } = 0;
+ public double Y2 { get; set; } = 0;
+
+ public double Caculate(double position)
+ {
+ double[] values = { X1, Y1, X2, Y2 };
+ return Interop.Ecore.ecore_animator_pos_map_n(position, Interop.Ecore.PositionMap.Bounce, values.Length, values);
+ }
+ }
+}
diff --git a/ElmSharp/ElmSharp/EcoreTimelineAnimator.cs b/ElmSharp/ElmSharp/EcoreTimelineAnimator.cs
new file mode 100644
index 0000000..8bc0a39
--- /dev/null
+++ b/ElmSharp/ElmSharp/EcoreTimelineAnimator.cs
@@ -0,0 +1,70 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace ElmSharp
+{
+ public class EcoreTimelineAnimator
+ {
+ double _runtime;
+ IntPtr _animator;
+ Action _timelineCallback;
+ Interop.Ecore.EcoreTimelineCallback _nativeCallback;
+ double _position;
+
+ public event EventHandler Finished;
+
+
+ public EcoreTimelineAnimator(double runtime, Action timelineCallback)
+ {
+ _runtime = runtime;
+ _nativeCallback = NativeCallback;
+ _timelineCallback = timelineCallback;
+ _position = 0;
+ }
+
+ public bool IsRunning { get; private set; }
+ public double Position => _position;
+
+ public void Start()
+ {
+ IsRunning = true;
+ _animator = Interop.Ecore.ecore_animator_timeline_add(_runtime, _nativeCallback, IntPtr.Zero);
+ }
+
+ public void Stop()
+ {
+ IsRunning = false;
+ _animator = IntPtr.Zero;
+ }
+
+ public void Freeze()
+ {
+ Interop.Ecore.ecore_animator_freeze(_animator);
+ }
+
+ public void Thaw()
+ {
+ Interop.Ecore.ecore_animator_thaw(_animator);
+ }
+
+ protected void OnTimeline()
+ {
+ _timelineCallback();
+ }
+
+ bool NativeCallback(IntPtr data, double pos)
+ {
+ _position = pos;
+ if (!IsRunning) return false;
+ OnTimeline();
+ if (pos == 1.0)
+ {
+ IsRunning = false;
+ _animator = IntPtr.Zero;
+ Finished?.Invoke(this, EventArgs.Empty);
+ }
+ return true;
+ }
+ }
+}
diff --git a/ElmSharp/Interop/Interop.Ecore.cs b/ElmSharp/Interop/Interop.Ecore.cs
index 99b9ee1..10e72d3 100644
--- a/ElmSharp/Interop/Interop.Ecore.cs
+++ b/ElmSharp/Interop/Interop.Ecore.cs
@@ -21,9 +21,25 @@ internal static partial class Interop
{
internal static partial class Ecore
{
+ internal enum PositionMap
+ {
+ Linear,
+ Accelerate,
+ Decelerate,
+ Sinusoidal,
+ AccelerateFactor,
+ DecelerateFactor,
+ SinusoidalFactor,
+ DivisorInterp,
+ Bounce,
+ Spring,
+ CubicBezier
+ }
+
internal delegate void EcoreCallback(IntPtr data);
internal delegate bool EcoreTaskCallback(IntPtr data);
internal delegate void EcoreEventCallback(IntPtr data, int type, IntPtr evt);
+ internal delegate bool EcoreTimelineCallback(IntPtr data, double pos);
[DllImport(Libraries.Ecore)]
internal static extern int ecore_init();
@@ -72,5 +88,26 @@ internal static partial class Interop
[DllImport(Libraries.Ecore)]
internal static extern IntPtr ecore_event_handler_del(IntPtr handler);
+
+ [DllImport(Libraries.Ecore)]
+ internal static extern IntPtr ecore_animator_timeline_add(double runtime, EcoreTimelineCallback func, IntPtr data);
+
+ [DllImport(Libraries.Ecore)]
+ internal static extern void ecore_animator_freeze(IntPtr animator);
+
+ [DllImport(Libraries.Ecore)]
+ internal static extern void ecore_animator_thaw(IntPtr animator);
+
+ [DllImport(Libraries.Ecore)]
+ internal static extern void ecore_animator_frametime_set(double frametime);
+
+ [DllImport(Libraries.Ecore)]
+ internal static extern void ecore_animator_frametime_get();
+
+ [DllImport(Libraries.Ecore)]
+ internal static extern double ecore_animator_pos_map(double pos, PositionMap map, double v1, double v2);
+
+ [DllImport(Libraries.Ecore)]
+ internal static extern double ecore_animator_pos_map_n(double pos, PositionMap map, int v_size, double[] v);
}
}