From 49406d4f1d4d7bdd70aa0d549d2086fe05b4829d Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Tue, 7 Nov 2023 20:55:41 +0900 Subject: [PATCH] [NUI] Support to get Marker list information from lottie 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 --- .../BaseComponents/AnimatedVectorImageView.cs | 100 ++++++++++++++++++++- .../public/BaseComponents/LottieAnimationView.cs | 58 ++++++++++++ .../src/public/Visuals/VisualConstants.cs | 10 +++ 3 files changed, 164 insertions(+), 4 deletions(-) diff --git a/src/Tizen.NUI/src/public/BaseComponents/AnimatedVectorImageView.cs b/src/Tizen.NUI/src/public/BaseComponents/AnimatedVectorImageView.cs index 33b77b0..690eacb 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/AnimatedVectorImageView.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/AnimatedVectorImageView.cs @@ -328,6 +328,25 @@ namespace Tizen.NUI.BaseComponents } /// + /// 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. + /// + /// First marker + /// Second marker + [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]"); + } + + /// /// SetMinMaxFrame(int startFrame, int endFrame) /// /// @@ -355,9 +374,9 @@ namespace Tizen.NUI.BaseComponents } /// - /// 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. /// /// First marker /// Second marker @@ -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, } diff --git a/src/Tizen.NUI/src/public/BaseComponents/LottieAnimationView.cs b/src/Tizen.NUI/src/public/BaseComponents/LottieAnimationView.cs index f5e80e4..c50318d 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/LottieAnimationView.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/LottieAnimationView.cs @@ -150,6 +150,7 @@ namespace Tizen.NUI.BaseComponents { // Reset cached infomations. currentStates.contentInfo = null; + currentStates.markerInfo = null; currentStates.mark1 = null; currentStates.mark2 = null; currentStates.framePlayRangeMin = -1; @@ -620,6 +621,62 @@ namespace Tizen.NUI.BaseComponents } /// + /// Get the list of markers' information such as the start frame and the end frame in the Lottie file. + /// + /// List of Tuple (string of marker name, integer of start frame, integer of end frame) + // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) + [EditorBrowsable(EditorBrowsableState.Never)] + public List> 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>(); + 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 item = new Tuple(key, startFrame, endFrame); + + currentStates.markerInfo?.Add(item); + } + } + } + markerMap.Dispose(); + val?.Dispose(); + } + NUILog.Debug($">"); + + return currentStates.markerInfo; + } + + /// /// 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. * @@ -1144,6 +1201,7 @@ namespace Tizen.NUI.BaseComponents internal float scale; internal PlayStateType playState; internal List> contentInfo; + internal List> markerInfo; internal string mark1, mark2; internal bool redrawInScalingDown; internal int desiredWidth, desiredHeight; diff --git a/src/Tizen.NUI/src/public/Visuals/VisualConstants.cs b/src/Tizen.NUI/src/public/Visuals/VisualConstants.cs index 1d4efb8..a4100ae 100755 --- a/src/Tizen.NUI/src/public/Visuals/VisualConstants.cs +++ b/src/Tizen.NUI/src/public/Visuals/VisualConstants.cs @@ -977,6 +977,16 @@ namespace Tizen.NUI /// [EditorBrowsable(EditorBrowsableState.Never)] public static readonly int FastTrackUploading = NDalic.ImageVisualOrientationCorrection + 13; + + /// + /// @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. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public static readonly int MarkerInfo = NDalic.ImageVisualOrientationCorrection + 15; } /// -- 2.7.4