[NUI] Support to get Marker list information from lottie
authorEunki, Hong <eunkiki.hong@samsung.com>
Tue, 7 Nov 2023 11:55:41 +0000 (20:55 +0900)
committerJaehyun Cho <jaehyun0cho@gmail.com>
Fri, 8 Mar 2024 00:50:30 +0000 (09:50 +0900)
Let we allow to get the list of markers what current lottie image has now.

And also, Implement min/max frame index by marker, which is legacy
feature of VD FLUX code.

Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
src/Tizen.NUI/src/public/BaseComponents/AnimatedVectorImageView.cs
src/Tizen.NUI/src/public/BaseComponents/LottieAnimationView.cs
src/Tizen.NUI/src/public/Visuals/VisualConstants.cs

index 33b77b0..690eacb 100755 (executable)
@@ -328,6 +328,25 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
+        /// Set minimum frame and maximum frame by marker.
+        /// Animation will play between the start frame and the end frame of the marker if one marker is specified.
+        /// Or animation will play between the start frame of the first marker and the end frame of the second marker if two markers are specified.
+        /// </summary>
+        /// <param name="marker1">First marker</param>
+        /// <param name="marker2">Second marker</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void SetMinAndMaxFrameByMarker(string marker1, string marker2 = null)
+        {
+            NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] SetMinAndMaxFrameByMarker({marker1}, {marker2})");
+
+            minimumFrameMarker = marker1;
+            maximumFrameMarker = marker2;
+            isMinMaxFrameSet = minMaxSetTypes.SetByMinAndMaxFrameByMarkerMethod;
+
+            NUILog.Debug($" [{GetId()}] minimumFrameMarker:{minimumFrameMarker}, maximumFrameMarker:{maximumFrameMarker}) ]AnimatedVectorImageView END]");
+        }
+
+        /// <summary>
         /// SetMinMaxFrame(int startFrame, int endFrame)
         /// </summary>
         /// <param name="minFrame"></param>
@@ -355,9 +374,9 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
-        /// A marker has its start frame and end frame. 
+        /// A marker has its start frame and end frame.
         /// Animation will play between the start frame and the end frame of the marker if one marker is specified.
-        /// Or animation will play between the start frame of the first marker and the end frame of the second marker if two markers are specified.   *
+        /// Or animation will play between the start frame of the first marker and the end frame of the second marker if two markers are specified.
         /// </summary>
         /// <param name="marker1">First marker</param>
         /// <param name="marker2">Second marker</param>
@@ -390,6 +409,10 @@ namespace Tizen.NUI.BaseComponents
                     innerCurrentFrame = 0;
                     break;
 
+                case minMaxSetTypes.SetByMinAndMaxFrameByMarkerMethod:
+                    GetFrameValueFromMarkerInfo();
+                    goto case minMaxSetTypes.SetByMinAndMaxFrameMethod;
+
                 case minMaxSetTypes.SetByMinAndMaxFrameMethod:
                     base.SetMinMaxFrame(minimumFrame, maximumFrame);
                     base.CurrentFrame = minimumFrame;
@@ -479,7 +502,7 @@ namespace Tizen.NUI.BaseComponents
             switch (isMinMaxFrameSet)
             {
                 case minMaxSetTypes.NotSetByUser:
-                    switch(endAction)
+                    switch (endAction)
                     {
                         case EndActions.Cancel:
                             innerCurrentFrame = base.CurrentFrame;
@@ -488,11 +511,15 @@ namespace Tizen.NUI.BaseComponents
                             base.CurrentFrame = innerCurrentFrame = 0;
                             break;
                         case EndActions.StopFinal:
-                            base.CurrentFrame = innerCurrentFrame= totalFrameNum - 1;
+                            base.CurrentFrame = innerCurrentFrame = totalFrameNum - 1;
                             break;
                     }
                     break;
 
+                case minMaxSetTypes.SetByMinAndMaxFrameByMarkerMethod:
+                    GetFrameValueFromMarkerInfo();
+                    goto case minMaxSetTypes.SetByMinAndMaxFrameMethod;
+
                 case minMaxSetTypes.SetByMinAndMaxFrameMethod:
                     switch (endAction)
                     {
@@ -507,6 +534,7 @@ namespace Tizen.NUI.BaseComponents
                             break;
                     }
                     break;
+
                 case minMaxSetTypes.SetByMarker:
                 case minMaxSetTypes.SetByBaseSetMinMaxFrameMethod:
                 default:
@@ -581,6 +609,67 @@ namespace Tizen.NUI.BaseComponents
 
 
         #region Internal
+        internal void GetFrameValueFromMarkerInfo()
+        {
+            bool minimumMarkerFoundSuccess = false;
+            bool maximumMarkerFoundSuccess = false;
+            int foundedMinimumFrame = 0;
+            int foundedMaximumFrame = 0;
+
+            NUILog.Debug($" [{GetId()}] GetFrameValueFromMarkerInfo : marker = (minimumFrameMarker:{minimumFrameMarker}, maximumFrameMarker:{maximumFrameMarker})");
+
+            // Note : let we insure to get marker frame value only one time per each frame marker setter
+            if (minimumFrameMarker == null)
+            {
+                return;
+            }
+
+            var markerInfoList = GetMarkerInfo();
+            if (markerInfoList != null)
+            {
+                foreach (var markerInfo in markerInfoList)
+                {
+                    if (markerInfo.Item1 == minimumFrameMarker)
+                    {
+                        if (maximumFrameMarker == null)
+                        {
+                            minimumMarkerFoundSuccess = true;
+                            maximumMarkerFoundSuccess = true;
+                            foundedMinimumFrame = markerInfo.Item2;
+                            foundedMaximumFrame = markerInfo.Item3;
+                        }
+                        else
+                        {
+                            minimumMarkerFoundSuccess = true;
+                            foundedMinimumFrame = markerInfo.Item2;
+                        }
+                    }
+                    else if (markerInfo.Item1 == maximumFrameMarker)
+                    {
+                        maximumMarkerFoundSuccess = true;
+                        foundedMaximumFrame = markerInfo.Item2;
+                    }
+                }
+            }
+
+            if (minimumMarkerFoundSuccess && maximumMarkerFoundSuccess)
+            {
+                minimumFrame = (foundedMinimumFrame) > 0 ? foundedMinimumFrame : 0;
+                maximumFrame = (foundedMaximumFrame) > 0 ? foundedMaximumFrame : 0;
+                NUILog.Debug($" [{GetId()}] GetFrameValueFromMarkerInfo Sucess! frame set as {minimumFrame} ~ {maximumFrame} : marker = (minimumFrameMarker:{minimumFrameMarker}, maximumFrameMarker:{maximumFrameMarker})");
+                if (minimumFrame > maximumFrame)
+                {
+                    NUILog.Debug($" [{GetId()}] minimumFrame:{minimumFrame} > maximumFrame:{maximumFrame})");
+                }
+                minimumFrameMarker = maximumFrameMarker = null;
+            }
+            else
+            {
+                minimumFrame = 0;
+                maximumFrame = totalFrameNum - 1;
+                NUILog.Debug($" [{GetId()}] GetFrameValueFromMarkerInfo Failed! frame set as {minimumFrame} ~ {maximumFrame} : marker = (minimumFrameMarker:{minimumFrameMarker}, maximumFrameMarker:{maximumFrameMarker})");
+            }
+        }
         #endregion Internal
 
 
@@ -589,6 +678,8 @@ namespace Tizen.NUI.BaseComponents
         private int repeatCnt = 0;
         private RepeatModes repeatMode = RepeatModes.Restart;
         private int minimumFrame = -1, maximumFrame = -1;
+        private string minimumFrameMarker = null;
+        private string maximumFrameMarker = null;
         private minMaxSetTypes isMinMaxFrameSet = minMaxSetTypes.NotSetByUser;
         private int innerCurrentFrame = -1;
         private EndActions innerEndAction = EndActions.Cancel;
@@ -596,6 +687,7 @@ namespace Tizen.NUI.BaseComponents
         {
             NotSetByUser,
             SetByMinAndMaxFrameMethod,
+            SetByMinAndMaxFrameByMarkerMethod,
             SetByMarker,
             SetByBaseSetMinMaxFrameMethod,
         }
index 65cb53b..54bc229 100755 (executable)
@@ -595,6 +595,62 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
+        /// Get the list of markers' information such as the start frame and the end frame in the Lottie file.
+        /// </summary>
+        /// <returns>List of Tuple (string of marker name, integer of start frame, integer of end frame)</returns>
+        // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public List<Tuple<string, int, int>> GetMarkerInfo()
+        {
+            if (currentStates.markerInfo != null)
+            {
+                return currentStates.markerInfo;
+            }
+
+            NUILog.Debug($"<");
+
+            PropertyMap imageMap = base.Image;
+            if (imageMap != null)
+            {
+                PropertyValue val = imageMap.Find(ImageVisualProperty.MarkerInfo);
+                PropertyMap markerMap = new PropertyMap();
+                if (val?.Get(ref markerMap) == true)
+                {
+                    currentStates.markerInfo = new List<Tuple<string, int, int>>();
+                    for (uint i = 0; i < markerMap.Count(); i++)
+                    {
+                        using PropertyKey propertyKey = markerMap.GetKeyAt(i);
+                        string key = propertyKey.StringKey;
+
+                        using PropertyValue arrVal = markerMap.GetValue(i);
+                        using PropertyArray arr = new PropertyArray();
+                        if (arrVal.Get(arr))
+                        {
+                            int startFrame = -1;
+                            using PropertyValue start = arr.GetElementAt(0);
+                            start?.Get(out startFrame);
+
+                            int endFrame = -1;
+                            using PropertyValue end = arr.GetElementAt(1);
+                            end?.Get(out endFrame);
+
+                            NUILog.Debug($"[{i}] marker name={key}, startFrame={startFrame}, endFrame={endFrame}");
+
+                            Tuple<string, int, int> item = new Tuple<string, int, int>(key, startFrame, endFrame);
+
+                            currentStates.markerInfo?.Add(item);
+                        }
+                    }
+                }
+                markerMap.Dispose();
+                val?.Dispose();
+            }
+            NUILog.Debug($">");
+
+            return currentStates.markerInfo;
+        }
+
+        /// <summary>
         /// A marker has its start frame and end frame.
         /// Animation will play between the start frame and the end frame of the marker if one marker is specified.
         /// Or animation will play between the start frame of the first marker and the end frame of the second marker if two markers are specified.   *
@@ -1043,6 +1099,7 @@ namespace Tizen.NUI.BaseComponents
             internal float scale;
             internal PlayStateType playState;
             internal List<Tuple<string, int, int>> contentInfo;
+            internal List<Tuple<string, int, int>> markerInfo;
             internal string mark1, mark2;
             internal bool redrawInScalingDown;
             internal bool enableFrameCache;
index c3afb75..368d2c7 100755 (executable)
@@ -971,6 +971,16 @@ namespace Tizen.NUI
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
         public static readonly int EnableFrameCache = NDalic.ImageVisualOrientationCorrection + 13;
+
+        /// <summary>
+        /// @brief The marker information the AnimatedVectorImageVisual will use.
+        /// @details Type Property::MAP.
+        /// The map contains the marker name as a key and Property::Array as a value.
+        /// And the array contains 2 integer values which are the frame numbers, the start frame number and the end frame number of the marker.
+        /// @note This property is read-only.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static readonly int MarkerInfo = NDalic.ImageVisualOrientationCorrection + 15;
     }
 
     /// <summary>