From 3589c9bdfd6558fef1e4aaeab6975c201b282786 Mon Sep 17 00:00:00 2001 From: arosis78 <35049857+arosis78@users.noreply.github.com> Date: Tue, 12 Mar 2019 13:46:37 +0900 Subject: [PATCH] [ElmSharp] Added some new APIs for AnimationView (#741) * [ElmSharp] Added some new APIs for AnimationView * [ElmSharp] modified from IsReversePlaying to IsReversedPlaying * Update AnimationView.cs --- src/ElmSharp/ElmSharp/AnimationView.cs | 196 ++++++++++++++++++++- src/ElmSharp/Interop/Interop.Eina.cs | 7 + .../Interop/Interop.Elementary.AnimationView.cs | 53 +++++- test/ElmSharp.Test/TC/AnimationViewTest1.cs | 173 ++++++++++-------- 4 files changed, 350 insertions(+), 79 deletions(-) diff --git a/src/ElmSharp/ElmSharp/AnimationView.cs b/src/ElmSharp/ElmSharp/AnimationView.cs index c34ebab..5e9e35e 100644 --- a/src/ElmSharp/ElmSharp/AnimationView.cs +++ b/src/ElmSharp/ElmSharp/AnimationView.cs @@ -19,6 +19,38 @@ using System; namespace ElmSharp { /// + /// Enumeration for the AnimationView state + /// + /// preview + public enum AnimationViewState + { + /// + /// Animation is not ready to play. + /// + NotReady, + + /// + /// Animation is on playing. + /// + Play, + + /// + /// Animation is on reverse playing. + /// + ReversedPlay, + + /// + /// Animation has been paused. + /// + Pause, + + /// + /// AnimationView successfully loaded a file then readied for playing. Otherwise after finished animation or stopped forcely by request. + /// + Stop + } + + /// /// The AnimationView is designed to show and play animation of vector graphics based content. /// Currently ElmSharp AnimationView is supporting only json format (known for Lottie file as well). /// @@ -207,23 +239,173 @@ namespace ElmSharp } /// - /// Sets or gets current keyframe position of animation view. + /// Sets or gets current progress position of animation view. + /// + /// When you required to jump on a certain progress instantly, + /// you can change current position by using this property + /// The range of progress is 0 ~ 1. + /// + /// + /// preview + public double Progress + { + get + { + return Interop.Elementary.elm_animation_view_progress_get(Handle); + } + set + { + Interop.Elementary.elm_animation_view_progress_set(Handle, value); + } + } + + /// + /// Sets or gets current frame position of animation view. + /// + /// The range of frame is from 0 to FrameCount - 1 + /// + /// + /// preview + public int Frame + { + get + { + return Interop.Elementary.elm_animation_view_frame_get(Handle); + } + set + { + Interop.Elementary.elm_animation_view_frame_set(Handle, value); + } + } + + /// + /// Get the default view size that specified from vector resource. + /// + /// preview + public Size DefaultSize + { + get + { + Interop.Elementary.elm_animation_view_default_size_get(Handle, out int w, out int h); + return new Size(w, h); + } + } + + /// + /// Get current animation view state. + /// + /// preview + public AnimationViewState State + { + get + { + return (AnimationViewState)Interop.Elementary.elm_animation_view_state_get(Handle); + } + } + + /// + /// Get the status whether current animation is on playing forward or backward. + /// /// - /// When you required to jump on a certain frame instantly, - /// you can change current keyframe by using this property - /// The range of keyframe is 0 ~ 1. + /// If AnimationView is not on playing, it will return False. /// + /// preview + public bool IsReversedPlaying + { + get + { + return Interop.Elementary.elm_animation_view_is_playing_back_get(Handle); + } + } + + /// + /// Get the index of end frame of the AnimationView, if it's animated. /// + /// + /// Frame number starts with 0. + /// + /// preview + public int FrameCount + { + get + { + return Interop.Elementary.elm_animation_view_frame_count_get(Handle); + } + } + + /// + /// Sets or Gets the start progress of the play + /// + /// + /// Default value is 0. + /// + /// preview + public double MinProgress + { + get + { + return Interop.Elementary.elm_animation_view_min_progress_get(Handle); + } + set + { + Interop.Elementary.elm_animation_view_min_progress_set(Handle, value); + } + } + + /// + /// Sets or Gets the last progress of the play + /// + /// + /// Default value is 1. + /// + /// preview + public double MaxProgress + { + get + { + return Interop.Elementary.elm_animation_view_max_progress_get(Handle); + } + set + { + Interop.Elementary.elm_animation_view_max_progress_set(Handle, value); + } + } + + /// + /// Sets or Gets the start frame of the play + /// + /// + /// Default value is 0. + /// + /// preview + public int MinFrame + { + get + { + return Interop.Elementary.elm_animation_view_min_frame_get(Handle); + } + set + { + Interop.Elementary.elm_animation_view_min_frame_set(Handle, value); + } + } + + /// + /// Sets or Gets the last frame of the play + /// + /// + /// Default value is FrameCount -1. + /// /// preview - public double KeyFrame + public int MaxFrame { get { - return Interop.Elementary.elm_animation_view_keyframe_get(Handle); + return Interop.Elementary.elm_animation_view_max_frame_get(Handle); } set { - Interop.Elementary.elm_animation_view_keyframe_set(Handle, value); + Interop.Elementary.elm_animation_view_max_frame_set(Handle, value); } } diff --git a/src/ElmSharp/Interop/Interop.Eina.cs b/src/ElmSharp/Interop/Interop.Eina.cs index 1051b52..ed28a67 100644 --- a/src/ElmSharp/Interop/Interop.Eina.cs +++ b/src/ElmSharp/Interop/Interop.Eina.cs @@ -21,6 +21,13 @@ internal static partial class Interop { internal static partial class Eina { + [StructLayout(LayoutKind.Sequential)] + internal struct Size2D + { + public int w; + public int h; + }; + [DllImport(Libraries.Eina)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool eina_main_loop_is(); diff --git a/src/ElmSharp/Interop/Interop.Elementary.AnimationView.cs b/src/ElmSharp/Interop/Interop.Elementary.AnimationView.cs index 5afcb64..16737e1 100644 --- a/src/ElmSharp/Interop/Interop.Elementary.AnimationView.cs +++ b/src/ElmSharp/Interop/Interop.Elementary.AnimationView.cs @@ -46,10 +46,16 @@ internal static partial class Interop internal static extern double elm_animation_view_duration_time_get(IntPtr obj); [DllImport(Libraries.Elementary)] - internal static extern double elm_animation_view_keyframe_get(IntPtr obj); + internal static extern double elm_animation_view_progress_get(IntPtr obj); [DllImport(Libraries.Elementary)] - internal static extern void elm_animation_view_keyframe_set(IntPtr obj, double keyframe); + internal static extern void elm_animation_view_progress_set(IntPtr obj, double progress); + + [DllImport(Libraries.Elementary)] + internal static extern int elm_animation_view_frame_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_animation_view_frame_set(IntPtr obj, int frame_num); [DllImport(Libraries.Elementary)] internal static extern bool elm_animation_view_play(IntPtr obj); @@ -66,6 +72,49 @@ internal static partial class Interop [DllImport(Libraries.Elementary)] internal static extern bool elm_animation_view_stop(IntPtr obj); + [DllImport(Libraries.Elementary, EntryPoint = "elm_animation_view_default_size_get")] + internal static extern Eina.Size2D _elm_animation_view_default_size_get(IntPtr obj); + + internal static void elm_animation_view_default_size_get(IntPtr obj, out int w, out int h) + { + var info = _elm_animation_view_default_size_get(obj); + w = info.w; + h = info.h; + } + + [DllImport(Libraries.Elementary)] + internal static extern int elm_animation_view_state_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern bool elm_animation_view_is_playing_back_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern int elm_animation_view_frame_count_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern double elm_animation_view_min_progress_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_animation_view_min_progress_set(IntPtr obj, double min_progress); + + [DllImport(Libraries.Elementary)] + internal static extern double elm_animation_view_max_progress_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_animation_view_max_progress_set(IntPtr obj, double max_progress); + + [DllImport(Libraries.Elementary)] + internal static extern int elm_animation_view_min_frame_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_animation_view_min_frame_set(IntPtr obj, int min_frame); + + [DllImport(Libraries.Elementary)] + internal static extern int elm_animation_view_max_frame_get(IntPtr obj); + + [DllImport(Libraries.Elementary)] + internal static extern void elm_animation_view_max_frame_set(IntPtr obj, double max_frame); + [DllImport(Libraries.Elementary)] internal static extern bool elm_animation_view_file_set(IntPtr obj, string file, string key); } diff --git a/test/ElmSharp.Test/TC/AnimationViewTest1.cs b/test/ElmSharp.Test/TC/AnimationViewTest1.cs index 4236847..c297bf4 100644 --- a/test/ElmSharp.Test/TC/AnimationViewTest1.cs +++ b/test/ElmSharp.Test/TC/AnimationViewTest1.cs @@ -25,37 +25,27 @@ namespace ElmSharp.Test public override string TestName => "AnimationViewTest1"; public override string TestDescription => "To test basic operation of AnimationView"; - private enum AnimationState + void UpdateAnimationViewStateLabel(AnimationView aniview, Label _stateLabel) { - NotReady, - Play, - ReversePlay, - Pause, - Stop, - } - - private AnimationState _state; - private bool _isPlayingReverse; + AnimationViewState _state = aniview.State; - void UpdateAnimationViewStateLabel(Label _stateLabel) - { - if (_state == AnimationState.NotReady) + if (_state == AnimationViewState.NotReady) { _stateLabel.Text = "State = Not Ready"; } - else if (_state == AnimationState.Play) + else if (_state == AnimationViewState.Play) { _stateLabel.Text = "State = Playing"; } - else if (_state == AnimationState.ReversePlay) + else if (_state == AnimationViewState.ReversePlay) { _stateLabel.Text = "State = Reverse Playing"; } - else if (_state == AnimationState.Pause) + else if (_state == AnimationViewState.Pause) { _stateLabel.Text = "State = Paused"; } - else if (_state == AnimationState.Stop) + else if (_state == AnimationViewState.Stop) { _stateLabel.Text = "State = Stopped"; } @@ -125,7 +115,28 @@ namespace ElmSharp.Test }; aniview.SetAnimation(Path.Combine(TestRunner.ResourceDir, "a_mountain.json")); aniview.Show(); - box.PackEnd(aniview); + + Box box1 = new Box(box) + { + WeightX = 1, + WeightY = 0, + AlignmentX = -1, + AlignmentY = 1, + IsHorizontal = true, + }; + box1.Show(); + box.PackEnd(box1); + + Label label1 = new Label(box) + { + WeightX = 1, + WeightY = 0, + AlignmentX = 0.0, + AlignmentY = 0.5, + Text = "Default Size = (" + aniview.DefaultSize.Width + "," + aniview.DefaultSize.Height + ")", + }; + label1.Show(); + box1.PackEnd(label1); Label label2 = new Label(box) { @@ -133,10 +144,23 @@ namespace ElmSharp.Test WeightY = 0, AlignmentX = 1.0, AlignmentY = 0.5, - Text = "Duration : " + (Math.Round(Convert.ToDouble(aniview.DurationTime), 2)).ToString(), + Text = "FrameCount : " + (aniview.FrameCount).ToString(), }; label2.Show(); - box.PackEnd(label2); + box1.PackEnd(label2); + + Label label3 = new Label(box) + { + WeightX = 1, + WeightY = 0, + AlignmentX = 1.0, + AlignmentY = 0.5, + Text = "Duration : " + (Math.Round(Convert.ToDouble(aniview.DurationTime), 2)).ToString(), + }; + label3.Show(); + box.PackEnd(label3); + + box.PackEnd(aniview); Box box2 = new Box(box) { @@ -204,7 +228,7 @@ namespace ElmSharp.Test slider.ValueChanged += (s, e) => { - aniview.KeyFrame = slider.Value; + aniview.Progress = slider.Value; }; Box box3 = new Box(box) @@ -218,7 +242,40 @@ namespace ElmSharp.Test box3.Show(); box.PackEnd(box3); - Button btn1 = new Button(box3) + Label label4 = new Label(box) + { + WeightX = 1, + WeightY = 0, + AlignmentX = 0.0, + AlignmentY = 0.5, + Text = (aniview.MinFrame).ToString() + " / " + (aniview.MaxFrame).ToString(), + }; + label4.Show(); + box3.PackEnd(label4); + + Label label5 = new Label(box) + { + WeightX = 1, + WeightY = 0, + AlignmentX = 1.0, + AlignmentY = 0.5, + Text = (aniview.MinProgress).ToString() + " / " + (aniview.MaxProgress).ToString(), + }; + label5.Show(); + box3.PackEnd(label5); + + Box box4 = new Box(box) + { + WeightX = 1, + WeightY = 0, + AlignmentX = -1, + AlignmentY = 1, + IsHorizontal = true, + }; + box4.Show(); + box.PackEnd(box4); + + Button btn1 = new Button(box4) { WeightX = 1, WeightY = 0, @@ -227,19 +284,15 @@ namespace ElmSharp.Test Text = "Play", }; btn1.Show(); - box3.PackEnd(btn1); + box4.PackEnd(btn1); btn1.Clicked += (s, e) => { - _isPlayingReverse = false; - if (_state == AnimationState.ReversePlay) - { - UpdateAnimationViewStateLabel(label); - } aniview.Play(); + UpdateAnimationViewStateLabel(aniview, label); }; - Button btn2 = new Button(box3) + Button btn2 = new Button(box4) { WeightX = 1, WeightY = 0, @@ -248,19 +301,15 @@ namespace ElmSharp.Test Text = "Reverse", }; btn2.Show(); - box3.PackEnd(btn2); + box4.PackEnd(btn2); btn2.Clicked += (s, e) => { - _isPlayingReverse = true; - if (_state == AnimationState.Play) - { - UpdateAnimationViewStateLabel(label); - } aniview.Play(true); + UpdateAnimationViewStateLabel(aniview, label); }; - Button btn3 = new Button(box3) + Button btn3 = new Button(box4) { WeightX = 1, WeightY = 0, @@ -269,14 +318,14 @@ namespace ElmSharp.Test Text = "Stop", }; btn3.Show(); - box3.PackEnd(btn3); + box4.PackEnd(btn3); btn3.Clicked += (s, e) => { aniview.Stop(); }; - Box box4 = new Box(box) + Box box5 = new Box(box) { WeightX = 1, WeightY = 0, @@ -284,10 +333,10 @@ namespace ElmSharp.Test AlignmentY = 1, IsHorizontal = true, }; - box4.Show(); - box.PackEnd(box4); + box5.Show(); + box.PackEnd(box5); - Button btn4 = new Button(box3) + Button btn4 = new Button(box5) { WeightX = 1, WeightY = 0, @@ -296,14 +345,14 @@ namespace ElmSharp.Test Text = "Pause", }; btn4.Show(); - box4.PackEnd(btn4); + box5.PackEnd(btn4); btn4.Clicked += (s, e) => { aniview.Pause(); }; - Button btn5 = new Button(box3) + Button btn5 = new Button(box5) { WeightX = 1, WeightY = 0, @@ -312,7 +361,7 @@ namespace ElmSharp.Test Text = "Resume", }; btn5.Show(); - box4.PackEnd(btn5); + box5.PackEnd(btn5); btn5.Clicked += (s, e) => { @@ -321,51 +370,35 @@ namespace ElmSharp.Test aniview.Started += (s, e) => { - if (!_isPlayingReverse) - { - _state = AnimationState.Play; - } - else - { - _state = AnimationState.ReversePlay; - } - UpdateAnimationViewStateLabel(label); + UpdateAnimationViewStateLabel(aniview, label); }; aniview.Stopped += (s, e) => { - _state = AnimationState.Stop; - UpdateAnimationViewStateLabel(label); - + UpdateAnimationViewStateLabel(aniview, label); + label4.Text = "0 / " + (aniview.MaxFrame).ToString(); + label5.Text = "0 / " + (aniview.MaxProgress).ToString(); slider.Value = 0; }; aniview.Paused += (s, e) => { - _state = AnimationState.Pause; - UpdateAnimationViewStateLabel(label); + UpdateAnimationViewStateLabel(aniview, label); }; aniview.Resumed += (s, e) => { - if (!_isPlayingReverse) - { - _state = AnimationState.Play; - } - else - { - _state = AnimationState.ReversePlay; - } - UpdateAnimationViewStateLabel(label); + UpdateAnimationViewStateLabel(aniview, label); }; aniview.Updated += (s, e) => { - slider.Value = aniview.KeyFrame; + slider.Value = aniview.Progress; + label4.Text = (aniview.Frame).ToString() + " / " + (aniview.MaxFrame).ToString(); + label5.Text = (Math.Round(Convert.ToDouble(aniview.Progress), 2)).ToString() + " / " + (aniview.MaxProgress).ToString(); }; - _state = AnimationState.NotReady; - UpdateAnimationViewStateLabel(label); + UpdateAnimationViewStateLabel(aniview, label); navi.Push(layout, "AnimationView Test"); } -- 2.7.4