[ElmSharp] Added some new APIs for AnimationView (#741)
authorarosis78 <35049857+arosis78@users.noreply.github.com>
Tue, 12 Mar 2019 04:46:37 +0000 (13:46 +0900)
committerGitHub <noreply@github.com>
Tue, 12 Mar 2019 04:46:37 +0000 (13:46 +0900)
* [ElmSharp] Added some new APIs for AnimationView

* [ElmSharp] modified from IsReversePlaying to IsReversedPlaying

* Update AnimationView.cs

src/ElmSharp/ElmSharp/AnimationView.cs
src/ElmSharp/Interop/Interop.Eina.cs
src/ElmSharp/Interop/Interop.Elementary.AnimationView.cs
test/ElmSharp.Test/TC/AnimationViewTest1.cs

index c34ebab..5e9e35e 100644 (file)
@@ -19,6 +19,38 @@ using System;
 namespace ElmSharp
 {
     /// <summary>
+    /// Enumeration for the AnimationView state
+    /// </summary>
+    /// <since_tizen> preview </since_tizen>
+    public enum AnimationViewState
+    {
+        /// <summary>
+        /// Animation is not ready to play.
+        /// </summary>
+        NotReady,
+
+        /// <summary>
+        /// Animation is on playing.
+        /// </summary>
+        Play,
+
+        /// <summary>
+        /// Animation is on reverse playing.
+        /// </summary>
+        ReversedPlay,
+
+        /// <summary>
+        /// Animation has been paused.
+        /// </summary>
+        Pause,
+
+        /// <summary>
+        /// AnimationView successfully loaded a file then readied for playing. Otherwise after finished animation or stopped forcely by request.
+        /// </summary>
+        Stop
+    }
+
+    /// <summary>
     /// 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).
     /// </summary>
@@ -207,23 +239,173 @@ namespace ElmSharp
         }
 
         /// <summary>
-        /// Sets or gets current keyframe position of animation view.
+        /// Sets or gets current progress position of animation view.
+        /// <remarks>
+        /// 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.
+        /// </remarks>
+        /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        public double Progress
+        {
+            get
+            {
+                return Interop.Elementary.elm_animation_view_progress_get(Handle);
+            }
+            set
+            {
+                Interop.Elementary.elm_animation_view_progress_set(Handle, value);
+            }
+        }
+
+        /// <summary>
+        /// Sets or gets current frame position of animation view.
+        /// <remarks>
+        /// The range of frame is from 0 to FrameCount - 1
+        /// </remarks>
+        /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        public int Frame
+        {
+            get
+            {
+                return Interop.Elementary.elm_animation_view_frame_get(Handle);
+            }
+            set
+            {
+                Interop.Elementary.elm_animation_view_frame_set(Handle, value);
+            }
+        }
+
+        /// <summary>
+        /// Get the default view size that specified from vector resource.
+        /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        public Size DefaultSize
+        {
+            get
+            {
+                Interop.Elementary.elm_animation_view_default_size_get(Handle, out int w, out int h);
+                return new Size(w, h);
+            }
+        }
+
+        /// <summary>
+        /// Get current animation view state.
+        /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        public AnimationViewState State
+        {
+            get
+            {
+                return (AnimationViewState)Interop.Elementary.elm_animation_view_state_get(Handle);
+            }
+        }
+
+        /// <summary>
+        /// Get the status whether current animation is on playing forward or backward.
+        /// </summary>
         /// <remarks>
-        /// 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.
         /// </remarks>
+        /// <since_tizen> preview </since_tizen>
+        public bool IsReversedPlaying
+        {
+            get
+            {
+                return Interop.Elementary.elm_animation_view_is_playing_back_get(Handle);
+            }
+        }
+
+        /// <summary>
+        /// Get the index of end frame of the AnimationView, if it's animated.
         /// </summary>
+        /// <remarks>
+        /// Frame number starts with 0.
+        /// </remarks>
+        /// <since_tizen> preview </since_tizen>
+        public int FrameCount
+        {
+            get
+            {
+                return Interop.Elementary.elm_animation_view_frame_count_get(Handle);
+            }
+        }
+
+        /// <summary>
+        /// Sets or Gets the start progress of the play
+        /// </summary>
+        /// <remarks>
+        /// Default value is 0.
+        /// </remarks>
+        /// <since_tizen> preview </since_tizen>
+        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);
+            }
+        }
+
+        /// <summary>
+        /// Sets or Gets the last progress of the play
+        /// </summary>
+        /// <remarks>
+        /// Default value is 1.
+        /// </remarks>
+        /// <since_tizen> preview </since_tizen>
+        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);
+            }
+        }
+
+        /// <summary>
+        /// Sets or Gets the start frame of the play
+        /// </summary>
+        /// <remarks>
+        /// Default value is 0.
+        /// </remarks>
+        /// <since_tizen> preview </since_tizen>
+        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);
+            }
+        }
+
+        /// <summary>
+        /// Sets or Gets the last frame of the play
+        /// </summary>
+        /// <remarks>
+        /// Default value is FrameCount -1.
+        /// </remarks>
         /// <since_tizen> preview </since_tizen>
-        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);
             }
         }
 
index 1051b52..ed28a67 100644 (file)
@@ -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();
index 5afcb64..16737e1 100644 (file)
@@ -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);
     }
index 4236847..c297bf4 100644 (file)
@@ -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 = "<font_size=32>State = Not Ready</font_size>";
             }
-            else if (_state == AnimationState.Play)
+            else if (_state == AnimationViewState.Play)
             {
                 _stateLabel.Text = "<font_size=32>State = Playing</font_size>";
             }
-            else if (_state == AnimationState.ReversePlay)
+            else if (_state == AnimationViewState.ReversePlay)
             {
                 _stateLabel.Text = "<font_size=32>State = Reverse Playing</font_size>";
             }
-            else if (_state == AnimationState.Pause)
+            else if (_state == AnimationViewState.Pause)
             {
                 _stateLabel.Text = "<font_size=32>State = Paused</font_size>";
             }
-            else if (_state == AnimationState.Stop)
+            else if (_state == AnimationViewState.Stop)
             {
                 _stateLabel.Text = "<font_size=32>State = Stopped</font_size>";
             }
@@ -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");
         }