2 * Copyright(c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using global::System.Runtime.InteropServices;
20 using System.ComponentModel;
21 using System.Collections.Generic;
22 using System.Globalization;
24 namespace Tizen.NUI.BaseComponents
27 /// LottieAnimationView renders an animated vector image (Lottie file).
29 /// <since_tizen> 7 </since_tizen>
30 public partial class LottieAnimationView : ImageView
33 #region Constructor, Destructor, Dispose
35 /// LottieAnimationView constructor
37 /// <param name="scale">The factor of scaling image, default : 1.0f</param>
38 /// <param name="shown">false : not displayed (hidden), true : displayed (shown), default : true</param>
40 /// If the shown parameter is false, the animation is not visible even if the LottieAnimationView instance is created.
44 /// LottieAnimationView myLottie = new LottieAnimationView();
45 /// LottieAnimationView myLottie2 = new LottieAnimationView(2.0f);
46 /// LottieAnimationView myLottie3 = new LottieAnimationView(1.0f, false);
49 /// <since_tizen> 7 </since_tizen>
50 public LottieAnimationView(float scale = 1.0f, bool shown = true) : base()
52 ActionPlay = Interop.LottieAnimationView.AnimatedVectorImageVisualActionPlayGet();
53 ActionPause = Interop.LottieAnimationView.AnimatedVectorImageVisualActionPauseGet();
54 ActionStop = Interop.LottieAnimationView.AnimatedVectorImageVisualActionStopGet();
56 NUILog.Debug($"< constructor GetId={GetId()} >");
57 currentStates.url = "";
58 currentStates.loopCount = 1;
59 currentStates.loopMode = LoopingModeType.Restart;
60 currentStates.stopEndAction = StopBehaviorType.CurrentFrame;
61 currentStates.framePlayRangeMin = -1;
62 currentStates.framePlayRangeMax = -1;
63 currentStates.changed = false;
64 currentStates.totalFrame = -1;
65 currentStates.scale = scale;
66 currentStates.redrawInScalingDown = true;
71 /// Dispose(DisposeTypes type)
73 /// <param name="type"></param>
74 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
75 [EditorBrowsable(EditorBrowsableState.Never)]
76 protected override void Dispose(DisposeTypes type)
83 CleanCallbackDictionaries();
85 //Release your own unmanaged resources here.
86 //You should not access any managed member here except static instance.
87 //because the execution order of Finalizes is non-deterministic.
89 //disconnect event signal
90 if (finishedEventHandler != null && visualEventSignalCallback != null)
92 using VisualEventSignal visualEvent = VisualEventSignal();
93 visualEvent.Disconnect(visualEventSignalCallback);
94 finishedEventHandler = null;
95 NUILog.Debug($"disconnect event signal");
101 // This is used for internal purpose. hidden API.
102 [EditorBrowsable(EditorBrowsableState.Never)]
103 protected override void Dispose(bool disposing)
105 // Note : We can clean dictionaries even this API called from GC Thread.
106 CleanCallbackDictionaries();
107 base.Dispose(disposing);
109 #endregion Constructor, Destructor, Dispose
114 /// Set or Get resource URL of Lottie file.
116 /// <since_tizen> 7 </since_tizen>
121 return GetValue(URLProperty) as string;
125 SetValue(URLProperty, value);
126 NotifyPropertyChanged();
130 private string InternalURL
134 string ret = (value == null ? "" : value);
135 currentStates.url = ret;
136 currentStates.changed = true;
137 currentStates.totalFrame = -1; // Reset cached totalFrame value;
138 currentStates.enableFrameCache = false;
140 NUILog.Debug($"<[{GetId()}]SET url={currentStates.url}");
142 // TODO : Could create new Image without additional creation?
143 using PropertyMap map = new PropertyMap();
144 using PropertyValue type = new PropertyValue((int)DevelVisual.Type.AnimatedVectorImage);
145 using PropertyValue url = new PropertyValue(currentStates.url);
146 using PropertyValue loopCnt = new PropertyValue(currentStates.loopCount);
147 using PropertyValue stopAction = new PropertyValue((int)currentStates.stopEndAction);
148 using PropertyValue loopMode = new PropertyValue((int)currentStates.loopMode);
150 map.Add(Visual.Property.Type, type)
151 .Add(ImageVisualProperty.URL, url)
152 .Add(ImageVisualProperty.LoopCount, loopCnt)
153 .Add(ImageVisualProperty.StopBehavior, stopAction)
154 .Add(ImageVisualProperty.LoopingMode, loopMode);
157 currentStates.contentInfo = null;
159 if (currentStates.scale != 1.0f)
161 Scale = new Vector3(currentStates.scale, currentStates.scale, currentStates.scale);
163 NUILog.Debug($"<[{GetId()}]>");
167 string ret = currentStates.url;
168 NUILog.Debug($"<[{GetId()}] GET");
169 NUILog.Debug($"gotten url={ret} >");
175 /// Gets the playing state
177 /// <since_tizen> 7 </since_tizen>
178 public PlayStateType PlayState
182 NUILog.Debug($"< Get!");
185 Interop.View.InternalRetrievingVisualPropertyInt(this.SwigCPtr, ImageView.Property.IMAGE, ImageVisualProperty.PlayState, out ret);
187 currentStates.playState = (PlayStateType)ret;
188 NUILog.Debug($"gotten play state={currentStates.playState} >");
190 return currentStates.playState;
195 /// Get the number of total frames
197 /// <since_tizen> 7 </since_tizen>
198 public int TotalFrame
202 int ret = currentStates.totalFrame;
205 Interop.View.InternalRetrievingVisualPropertyInt(this.SwigCPtr, ImageView.Property.IMAGE, ImageVisualProperty.TotalFrameNumber, out ret);
207 currentStates.totalFrame = ret;
208 NUILog.Debug($"TotalFrameNumber get! ret={ret}");
215 /// Set or get the current frame. When setting a specific frame, it is displayed as a still image.
218 /// Gets the value set by a user. If the setting value is out-ranged, it is reset as a minimum frame or a maximum frame.
221 /// We assume that the animation in myLottie.json file has 100 frames originally. If so, its frame index will be 0 - 99.
223 /// LottieAnimationView myLottie = new LottieAnimationView();
224 /// myLottie.URL = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "myLottie.json"; //myLottie.json's total frame is 100 (frame: 0~99)
225 /// NUIApplication.GetDefaultWindow().GetDefaultLayer().Add(myLottie);
226 /// myLottie.CurrentFrame = 200; //display 99 frame
227 /// myLottie.SetMinMaxFrame(10, 20);
228 /// myLottie.CurrentFrame = 15; //display 15 frame
229 /// myLottie.CurrentFrame = 50; //display 20 frame, because the MinMax is set (10,20) above
232 /// <since_tizen> 7 </since_tizen>
233 public int CurrentFrame
237 return (int)GetValue(CurrentFrameProperty);
241 SetValue(CurrentFrameProperty, value);
242 NotifyPropertyChanged();
246 private int InternalCurrentFrame
250 NUILog.Debug($"<[{GetId()}]SET frame={value}>");
252 Interop.View.DoActionWithSingleIntAttributes(this.SwigCPtr, ImageView.Property.IMAGE, ActionJumpTo, value);
258 Interop.View.InternalRetrievingVisualPropertyInt(this.SwigCPtr, ImageView.Property.IMAGE, ImageVisualProperty.CurrentFrameNumber, out ret);
260 NUILog.Debug($"CurrentFrameNumber get! val={ret}");
266 /// Sets or gets the looping mode of Lottie animation.
268 /// <since_tizen> 7 </since_tizen>
269 public LoopingModeType LoopingMode
273 return (LoopingModeType)GetValue(LoopingModeProperty);
277 SetValue(LoopingModeProperty, value);
278 NotifyPropertyChanged();
282 private LoopingModeType InternalLoopingMode
286 if (currentStates.loopMode != (LoopingModeType)value)
288 currentStates.changed = true;
289 currentStates.loopMode = (LoopingModeType)value;
291 NUILog.Debug($"<[{GetId()}] SET loopMode={currentStates.loopMode}>");
293 Interop.View.InternalUpdateVisualPropertyInt(this.SwigCPtr, ImageView.Property.IMAGE, ImageVisualProperty.LoopingMode, (int)currentStates.loopMode);
298 NUILog.Debug($"LoopMode get! {currentStates.loopMode}");
299 return currentStates.loopMode;
304 /// Sets or gets the loop count.
307 /// The minus value means the infinite loop count.
311 /// LottieAnimationView myLottie = new LottieAnimationView();
312 /// myLottie.URL = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "myLottie.json"; //myLottie.json's total frame is 100 (frame: 0~99)
313 /// NUIApplication.GetDefaultWindow().GetDefaultLayer().Add(myLottie);
314 /// myLottie.LoopCount = -1; //infinite loop
316 /// myLottie.Stop(); //it plays continuously unless Stop() is called
317 /// myLottie.LoopCount = 2;
318 /// myLottie.Play(); //it plays only 2 times and stops automatically
321 /// <since_tizen> 7 </since_tizen>
326 return (int)GetValue(LoopCountProperty);
330 SetValue(LoopCountProperty, value);
331 NotifyPropertyChanged();
335 private int InternalLoopCount
339 if (currentStates.loopCount != value)
341 currentStates.changed = true;
342 currentStates.loopCount = value;
344 NUILog.Debug($"<[{GetId()}]SET currentStates.loopCount={currentStates.loopCount}>");
346 Interop.View.InternalUpdateVisualPropertyInt(this.SwigCPtr, ImageView.Property.IMAGE, ImageVisualProperty.LoopCount, currentStates.loopCount);
351 NUILog.Debug($"LoopCount get! {currentStates.loopCount}");
352 return currentStates.loopCount;
357 /// Sets or gets the stop behavior.
359 /// <since_tizen> 7 </since_tizen>
360 public StopBehaviorType StopBehavior
364 return (StopBehaviorType)GetValue(StopBehaviorProperty);
368 SetValue(StopBehaviorProperty, value);
369 NotifyPropertyChanged();
373 private StopBehaviorType InternalStopBehavior
377 if (currentStates.stopEndAction != (StopBehaviorType)value)
379 currentStates.changed = true;
380 currentStates.stopEndAction = (StopBehaviorType)value;
382 NUILog.Debug($"<[{GetId()}]SET val={currentStates.stopEndAction}>");
384 Interop.View.InternalUpdateVisualPropertyInt(this.SwigCPtr, ImageView.Property.IMAGE, ImageVisualProperty.StopBehavior, (int)currentStates.stopEndAction);
389 NUILog.Debug($"StopBehavior get! {currentStates.stopEndAction}");
390 return currentStates.stopEndAction;
395 /// Whether to redraw the image when the visual is scaled down.
399 /// It is used in the AnimatedVectorImageVisual.The default is true.
401 [EditorBrowsable(EditorBrowsableState.Never)]
402 public bool RedrawInScalingDown
406 return (bool)GetValue(RedrawInScalingDownProperty);
410 SetValue(RedrawInScalingDownProperty, value);
411 NotifyPropertyChanged();
415 private bool InternalRedrawInScalingDown
419 if (currentStates.redrawInScalingDown != value)
421 currentStates.changed = true;
422 currentStates.redrawInScalingDown = value;
424 NUILog.Debug($"<[{GetId()}]SET currentStates.redrawInScalingDown={currentStates.redrawInScalingDown}>");
426 Interop.View.InternalUpdateVisualPropertyBool(this.SwigCPtr, ImageView.Property.IMAGE, ImageVisualProperty.RedrawInScalingDown, currentStates.redrawInScalingDown);
431 NUILog.Debug($"RedrawInScalingDown get! {currentStates.redrawInScalingDown}");
432 return currentStates.redrawInScalingDown;
438 /// Actions property value to Jump to the specified frame.
439 /// This property can be redefined by child class if it use different value.
441 [EditorBrowsable(EditorBrowsableState.Never)]
442 protected int ActionJumpTo { get; set; } = Interop.LottieAnimationView.AnimatedVectorImageVisualActionJumpToGet();
444 // This is used for internal purpose. hidden API.
445 [EditorBrowsable(EditorBrowsableState.Never)]
446 protected int SetDynamicProperty => ActionJumpTo + 1;
447 [EditorBrowsable(EditorBrowsableState.Never)]
448 public bool EnableFrameCache
452 return (bool)GetValue(EnableFrameCacheProperty);
456 SetValue(EnableFrameCacheProperty, value);
457 NotifyPropertyChanged();
461 private bool InternalEnableFrameCache
465 if (currentStates.enableFrameCache != value)
467 currentStates.changed = true;
468 currentStates.enableFrameCache = value;
470 NUILog.Debug($"<[{GetId()}]SET currentStates.EnableFrameCache={currentStates.enableFrameCache}>");
472 Interop.View.InternalUpdateVisualPropertyBool(this.SwigCPtr, ImageView.Property.IMAGE, ImageVisualProperty.EnableFrameCache, currentStates.enableFrameCache);
477 NUILog.Debug($"EnableFrameCache get! {currentStates.enableFrameCache}");
478 return currentStates.enableFrameCache;
486 /// Set the minimum and the maximum frame.
488 /// <param name="minFrame">minimum frame</param>
489 /// <param name="maxFrame">maximum frame</param>
490 /// <since_tizen> 7 </since_tizen>
491 public void SetMinMaxFrame(int minFrame, int maxFrame)
493 if (currentStates.framePlayRangeMin != minFrame || currentStates.framePlayRangeMax != maxFrame)
495 NUILog.Debug($"< [{GetId()}] SetPlayRange({minFrame}, {maxFrame})");
496 currentStates.changed = true;
497 currentStates.framePlayRangeMin = minFrame;
498 currentStates.framePlayRangeMax = maxFrame;
500 Interop.View.InternalUpdateVisualPropertyIntPair(this.SwigCPtr, ImageView.Property.IMAGE, ImageVisualProperty.PlayRange, currentStates.framePlayRangeMin, currentStates.framePlayRangeMax);
502 NUILog.Debug($" [{GetId()}] currentStates.min:({currentStates.framePlayRangeMin}, max:{currentStates.framePlayRangeMax})>");
509 /// <since_tizen> 7 </since_tizen>
510 public new void Play()
512 NUILog.Debug($"<[{GetId()}] Play()");
515 NUILog.Debug($"[{GetId()}]>");
521 /// <since_tizen> 7 </since_tizen>
522 public new void Pause()
524 NUILog.Debug($"<[{GetId()}] Pause()>");
527 NUILog.Debug($"[{GetId()}]>");
533 /// <since_tizen> 7 </since_tizen>
534 public new void Stop()
536 NUILog.Debug($"<[{GetId()}] Stop()");
539 NUILog.Debug($"[{GetId()}]>");
543 /// Get the list of layers' information such as the start frame and the end frame in the Lottie file.
545 /// <returns>List of Tuple (string of layer name, integer of start frame, integer of end frame)</returns>
546 /// <since_tizen> 7 </since_tizen>
547 public List<Tuple<string, int, int>> GetContentInfo()
549 if (currentStates.contentInfo != null)
551 return currentStates.contentInfo;
556 PropertyMap imageMap = base.Image;
557 if (imageMap != null)
559 PropertyValue val = imageMap.Find(ImageVisualProperty.ContentInfo);
560 PropertyMap contentMap = new PropertyMap();
561 if (val?.Get(ref contentMap) == true)
563 currentStates.contentInfo = new List<Tuple<string, int, int>>();
564 for (uint i = 0; i < contentMap.Count(); i++)
566 using PropertyKey propertyKey = contentMap.GetKeyAt(i);
567 string key = propertyKey.StringKey;
569 using PropertyValue arrVal = contentMap.GetValue(i);
570 using PropertyArray arr = new PropertyArray();
574 using PropertyValue start = arr.GetElementAt(0);
575 start?.Get(out startFrame);
578 using PropertyValue end = arr.GetElementAt(1);
579 end?.Get(out endFrame);
581 NUILog.Debug($"[{i}] layer name={key}, startFrame={startFrame}, endFrame={endFrame}");
583 Tuple<string, int, int> item = new Tuple<string, int, int>(key, startFrame, endFrame);
585 currentStates.contentInfo?.Add(item);
589 contentMap.Dispose();
594 return currentStates.contentInfo;
598 /// Get the list of markers' information such as the start frame and the end frame in the Lottie file.
600 /// <returns>List of Tuple (string of marker name, integer of start frame, integer of end frame)</returns>
601 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
602 [EditorBrowsable(EditorBrowsableState.Never)]
603 public List<Tuple<string, int, int>> GetMarkerInfo()
605 if (currentStates.markerInfo != null)
607 return currentStates.markerInfo;
612 PropertyMap imageMap = base.Image;
613 if (imageMap != null)
615 PropertyValue val = imageMap.Find(ImageVisualProperty.MarkerInfo);
616 PropertyMap markerMap = new PropertyMap();
617 if (val?.Get(ref markerMap) == true)
619 currentStates.markerInfo = new List<Tuple<string, int, int>>();
620 for (uint i = 0; i < markerMap.Count(); i++)
622 using PropertyKey propertyKey = markerMap.GetKeyAt(i);
623 string key = propertyKey.StringKey;
625 using PropertyValue arrVal = markerMap.GetValue(i);
626 using PropertyArray arr = new PropertyArray();
630 using PropertyValue start = arr.GetElementAt(0);
631 start?.Get(out startFrame);
634 using PropertyValue end = arr.GetElementAt(1);
635 end?.Get(out endFrame);
637 NUILog.Debug($"[{i}] marker name={key}, startFrame={startFrame}, endFrame={endFrame}");
639 Tuple<string, int, int> item = new Tuple<string, int, int>(key, startFrame, endFrame);
641 currentStates.markerInfo?.Add(item);
650 return currentStates.markerInfo;
654 /// A marker has its start frame and end frame.
655 /// Animation will play between the start frame and the end frame of the marker if one marker is specified.
656 /// 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. *
658 /// <param name="marker1">First marker</param>
659 /// <param name="marker2">Second marker</param>
660 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
661 [EditorBrowsable(EditorBrowsableState.Never)]
662 public void SetMinMaxFrameByMarker(string marker1, string marker2 = null)
664 if (currentStates.mark1 != marker1 || currentStates.mark2 != marker2)
666 NUILog.Debug($"< [{GetId()}] SetMinMaxFrameByMarker({marker1}, {marker2})");
668 currentStates.changed = true;
669 currentStates.mark1 = marker1;
670 currentStates.mark2 = marker2;
672 if (string.IsNullOrEmpty(currentStates.mark2))
674 Interop.View.InternalUpdateVisualPropertyString(this.SwigCPtr, ImageView.Property.IMAGE, ImageVisualProperty.PlayRange, currentStates.mark1);
678 Interop.View.InternalUpdateVisualPropertyStringPair(this.SwigCPtr, ImageView.Property.IMAGE, ImageVisualProperty.PlayRange, currentStates.mark1, currentStates.mark2);
681 NUILog.Debug($" [{GetId()}] currentStates.mark1:{currentStates.mark1}, mark2:{currentStates.mark2} >");
688 /// <returns>Tuple of Min and Max frames</returns>
689 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
690 [EditorBrowsable(EditorBrowsableState.Never)]
691 public Tuple<int, int> GetMinMaxFrame()
693 NUILog.Debug($"< [{GetId()}] GetMinMaxFrame()! total frame={currentStates.totalFrame}");
695 using PropertyMap map = Image;
698 using PropertyValue val = map.Find(ImageVisualProperty.PlayRange);
701 using PropertyArray array = new PropertyArray();
704 uint cnt = array.Count();
705 int item1 = -1, item2 = -1;
706 for (uint i = 0; i < cnt; i++)
708 using PropertyValue v = array.GetElementAt(i);
710 if (v.Get(out intRet))
712 NUILog.Debug($"Got play range of string [{i}]: {intRet}");
724 Tizen.Log.Error("NUI", $"[ERR] fail to get play range from dali! case#1");
727 NUILog.Debug($" [{GetId()}] GetMinMaxFrame(min:{item1}, max:{item2})! >");
728 return new Tuple<int, int>(item1, item2);
732 Tizen.Log.Error("NUI", $"[ERR] fail to get play range from dali! case#2");
733 return new Tuple<int, int>(-1, -1);
736 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
737 [EditorBrowsable(EditorBrowsableState.Never)]
738 public void DoActionExtension(LottieAnimationViewDynamicProperty info)
740 dynamicPropertyCallbackId++;
742 weakReferencesOfLottie?.Add(dynamicPropertyCallbackId, new WeakReference<LottieAnimationView>(this));
743 InternalSavedDynamicPropertyCallbacks?.Add(dynamicPropertyCallbackId, info.Callback);
745 Interop.View.DoActionExtension(SwigCPtr, ImageView.Property.IMAGE, SetDynamicProperty, dynamicPropertyCallbackId, info.KeyPath, (int)info.Property, Marshal.GetFunctionPointerForDelegate<System.Delegate>(rootCallback));
747 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
750 private void CleanCallbackDictionaries()
752 if (weakReferencesOfLottie?.Count > 0 && InternalSavedDynamicPropertyCallbacks != null)
754 foreach (var key in InternalSavedDynamicPropertyCallbacks?.Keys)
756 if (weakReferencesOfLottie.ContainsKey(key))
758 weakReferencesOfLottie.Remove(key);
762 InternalSavedDynamicPropertyCallbacks?.Clear();
763 InternalSavedDynamicPropertyCallbacks = null;
768 #region Event, Enum, Struct, ETC
770 /// Animation finished event.
772 /// <since_tizen> 7 </since_tizen>
773 public event EventHandler Finished
777 if (finishedEventHandler == null)
779 NUILog.Debug($"<[{GetId()}] Finished eventhandler added>");
780 visualEventSignalCallback = onVisualEventSignal;
781 using VisualEventSignal visualEvent = VisualEventSignal();
782 visualEvent.Connect(visualEventSignalCallback);
784 finishedEventHandler += value;
788 NUILog.Debug($"<[{GetId()}] Finished eventhandler removed>");
789 finishedEventHandler -= value;
790 if (finishedEventHandler == null && visualEventSignalCallback != null)
792 using VisualEventSignal visualEvent = VisualEventSignal();
793 visualEvent.Disconnect(visualEventSignalCallback);
794 if (visualEvent?.Empty() == true)
796 visualEventSignalCallback = null;
803 /// Enumeration for what state the vector animation is in
805 /// <since_tizen> 7 </since_tizen>
806 public enum PlayStateType
811 /// <since_tizen> 7 </since_tizen>
814 /// Vector Animation has stopped
816 /// <since_tizen> 7 </since_tizen>
819 /// The vector animation is playing
821 /// <since_tizen> 7 </since_tizen>
824 /// The vector animation is paused
826 /// <since_tizen> 7 </since_tizen>
831 /// Enumeration for what to do when the animation is stopped.
833 /// <since_tizen> 7 </since_tizen>
834 public enum StopBehaviorType
837 /// When the animation is stopped, the current frame is shown.
839 /// <since_tizen> 7 </since_tizen>
842 /// When the animation is stopped, the min frame (first frame) is shown.
844 /// <since_tizen> 7 </since_tizen>
847 /// When the animation is stopped, the max frame (last frame) is shown.
849 /// <since_tizen> 7 </since_tizen>
854 /// Enumeration for what looping mode is in.
856 /// <since_tizen> 7 </since_tizen>
857 public enum LoopingModeType
860 /// When the animation arrives at the end in looping mode, the animation restarts from the beginning.
862 /// <since_tizen> 7 </since_tizen>
865 /// When the animation arrives at the end in looping mode, the animation reverses direction and runs backwards again.
867 /// <since_tizen> 7 </since_tizen>
874 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
875 [EditorBrowsable(EditorBrowsableState.Never)]
876 public enum VectorProperty
879 /// Fill color of the object, Type of <see cref="Vector3"/>
881 [EditorBrowsable(EditorBrowsableState.Never)]
885 /// Fill opacity of the object, Type of float
887 [EditorBrowsable(EditorBrowsableState.Never)]
891 /// Stroke color of the object, Type of <see cref="Vector3"/>
893 [EditorBrowsable(EditorBrowsableState.Never)]
897 /// Stroke opacity of the object, Type of float
899 [EditorBrowsable(EditorBrowsableState.Never)]
903 /// Stroke width of the object, Type of float
905 [EditorBrowsable(EditorBrowsableState.Never)]
909 /// Transform anchor of the Layer and Group object, Type of <see cref="Vector2"/>
911 [EditorBrowsable(EditorBrowsableState.Never)]
915 /// Transform position of the Layer and Group object, Type of <see cref="Vector2"/>
917 [EditorBrowsable(EditorBrowsableState.Never)]
921 /// Transform scale of the Layer and Group object, Type of <see cref="Vector2"/>, Value range of [0..100]
923 [EditorBrowsable(EditorBrowsableState.Never)]
927 /// Transform rotation of the Layer and Group object, Type of float, Value range of [0..360] in degrees
929 [EditorBrowsable(EditorBrowsableState.Never)]
933 /// Transform opacity of the Layer and Group object, Type of float
935 [EditorBrowsable(EditorBrowsableState.Never)]
939 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
940 [EditorBrowsable(EditorBrowsableState.Never)]
941 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
942 public delegate PropertyValue DynamicPropertyCallbackType(int returnType, uint frameNumber);
943 #endregion Event, Enum, Struct, ETC
947 internal class VisualEventSignalArgs : EventArgs
949 public int VisualIndex
961 internal event EventHandler<VisualEventSignalArgs> VisualEvent
965 if (visualEventSignalHandler == null)
967 visualEventSignalCallback = onVisualEventSignal;
968 using VisualEventSignal visualEvent = VisualEventSignal();
969 visualEvent?.Connect(visualEventSignalCallback);
971 visualEventSignalHandler += value;
975 visualEventSignalHandler -= value;
976 if (visualEventSignalHandler == null && visualEventSignalCallback != null)
978 using VisualEventSignal visualEvent = VisualEventSignal();
979 visualEvent?.Disconnect(visualEventSignalCallback);
980 if (visualEvent?.Empty() == true)
982 visualEventSignalCallback = null;
988 internal void EmitVisualEventSignal(int visualIndex, int signalId)
990 using VisualEventSignal visualEvent = VisualEventSignal();
991 visualEvent?.Emit(this, visualIndex, signalId);
994 internal VisualEventSignal VisualEventSignal()
996 VisualEventSignal ret = new VisualEventSignal(Interop.VisualEventSignal.NewWithView(View.getCPtr(this)), false);
997 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1001 internal Dictionary<int, DynamicPropertyCallbackType> InternalSavedDynamicPropertyCallbacks = new Dictionary<int, DynamicPropertyCallbackType>();
1003 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
1004 internal delegate void RootCallbackType(int id, int returnType, uint frameNumber, ref float val1, ref float val2, ref float val3);
1006 internal RootCallbackType rootCallback = RootCallback;
1008 static internal void RootCallback(int id, int returnType, uint frameNumber, ref float val1, ref float val2, ref float val3)
1010 WeakReference<LottieAnimationView> current = null;
1011 LottieAnimationView currentView = null;
1012 DynamicPropertyCallbackType currentCallback = null;
1013 PropertyValue ret = null;
1015 if (weakReferencesOfLottie.TryGetValue(id, out current))
1017 if (current.TryGetTarget(out currentView))
1019 if (currentView != null && currentView.InternalSavedDynamicPropertyCallbacks != null &&
1020 currentView.InternalSavedDynamicPropertyCallbacks.TryGetValue(id, out currentCallback))
1022 ret = currentCallback?.Invoke(returnType, frameNumber);
1026 Tizen.Log.Error("NUI", "can't find the callback in LottieAnimationView, just return here!");
1032 Tizen.Log.Error("NUI", "can't find the callback in LottieAnimationView, just return here!");
1038 Tizen.Log.Error("NUI", "can't find LottieAnimationView by id, just return here!");
1044 case (int)(VectorProperty.FillColor):
1045 case (int)(VectorProperty.StrokeColor):
1046 Vector3 tmpVector3 = new Vector3(-1, -1, -1);
1047 if ((ret != null) && ret.Get(tmpVector3))
1049 val1 = tmpVector3.X;
1050 val2 = tmpVector3.Y;
1051 val3 = tmpVector3.Z;
1053 tmpVector3.Dispose();
1056 case (int)(VectorProperty.TransformAnchor):
1057 case (int)(VectorProperty.TransformPosition):
1058 case (int)(VectorProperty.TransformScale):
1059 Vector2 tmpVector2 = new Vector2(-1, -1);
1060 if ((ret != null) && ret.Get(tmpVector2))
1062 val1 = tmpVector2.X;
1063 val2 = tmpVector2.Y;
1065 tmpVector2.Dispose();
1068 case (int)(VectorProperty.FillOpacity):
1069 case (int)(VectorProperty.StrokeOpacity):
1070 case (int)(VectorProperty.StrokeWidth):
1071 case (int)(VectorProperty.TransformRotation):
1072 case (int)(VectorProperty.TransformOpacity):
1073 float tmpFloat = -1;
1074 if ((ret != null) && ret.Get(out tmpFloat))
1089 private struct states
1091 internal string url;
1092 internal int loopCount;
1093 internal LoopingModeType loopMode;
1094 internal StopBehaviorType stopEndAction;
1095 internal int framePlayRangeMin;
1096 internal int framePlayRangeMax;
1097 internal bool changed;
1098 internal int totalFrame;
1099 internal float scale;
1100 internal PlayStateType playState;
1101 internal List<Tuple<string, int, int>> contentInfo;
1102 internal List<Tuple<string, int, int>> markerInfo;
1103 internal string mark1, mark2;
1104 internal bool redrawInScalingDown;
1105 internal bool enableFrameCache;
1107 private states currentStates;
1109 private struct DevelVisual
1113 AnimatedGradient = Visual.Type.AnimatedImage + 1,
1114 AnimatedVectorImage = Visual.Type.AnimatedImage + 2,
1118 private const string tag = "NUITEST";
1119 private event EventHandler finishedEventHandler;
1121 private void OnFinished()
1123 NUILog.Debug($"<[{GetId()}] OnFinished()>");
1124 finishedEventHandler?.Invoke(this, null);
1127 private void onVisualEventSignal(IntPtr targetView, int visualIndex, int signalId)
1131 if (targetView != IntPtr.Zero)
1133 View v = Registry.GetManagedBaseHandleFromNativePtr(targetView) as View;
1136 NUILog.Debug($"targetView is not null! name={v.Name}");
1140 NUILog.Debug($"target is something created from dali");
1143 VisualEventSignalArgs e = new VisualEventSignalArgs();
1144 e.VisualIndex = visualIndex;
1145 e.SignalId = signalId;
1146 visualEventSignalHandler?.Invoke(this, e);
1148 NUILog.Debug($"<[{GetId()}] onVisualEventSignal()! visualIndex={visualIndex}, signalId={signalId}>");
1151 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
1152 private delegate void VisualEventSignalCallbackType(IntPtr targetView, int visualIndex, int signalId);
1154 private VisualEventSignalCallbackType visualEventSignalCallback;
1155 private EventHandler<VisualEventSignalArgs> visualEventSignalHandler;
1157 static private int dynamicPropertyCallbackId = 0;
1158 //static private Dictionary<int, DynamicPropertyCallbackType> dynamicPropertyCallbacks = new Dictionary<int, DynamicPropertyCallbackType>();
1159 static private Dictionary<int, WeakReference<LottieAnimationView>> weakReferencesOfLottie = new Dictionary<int, WeakReference<LottieAnimationView>>();
1161 private void debugPrint()
1163 NUILog.Debug($"===================================");
1164 NUILog.Debug($"<[{GetId()}] get currentStates : url={currentStates.url}, loopCount={currentStates.loopCount}, \nframePlayRangeMin/Max({currentStates.framePlayRangeMin},{currentStates.framePlayRangeMax}) ");
1165 NUILog.Debug($" get from Property : StopBehavior={StopBehavior}, LoopMode={LoopingMode}, LoopCount={LoopCount}, PlayState={PlayState}");
1166 NUILog.Debug($" RedrawInScalingDown={RedrawInScalingDown} >");
1167 NUILog.Debug($"===================================");
1174 /// A class containing frame informations for a LottieAnimationView.
1176 [EditorBrowsable(EditorBrowsableState.Never)]
1177 public class LottieFrameInfo : ICloneable
1180 /// Creates a new instance with a playing range.
1182 [EditorBrowsable(EditorBrowsableState.Never)]
1183 public LottieFrameInfo(int startFrame, int endFrame)
1185 StartFrame = startFrame;
1186 EndFrame = endFrame;
1190 /// Creates a new instance with a still image frame.
1192 [EditorBrowsable(EditorBrowsableState.Never)]
1193 public LottieFrameInfo(int stillImageFrame) : this(stillImageFrame, stillImageFrame)
1198 /// Create a new instance from a pair notation.
1200 [EditorBrowsable(EditorBrowsableState.Never)]
1201 public static implicit operator LottieFrameInfo((int, int) pair)
1203 return new LottieFrameInfo(pair.Item1, pair.Item2);
1207 /// Create a new instance from an int value.
1209 [EditorBrowsable(EditorBrowsableState.Never)]
1210 public static implicit operator LottieFrameInfo(int stillImageFrame)
1212 return new LottieFrameInfo(stillImageFrame);
1216 /// Create a new instance from string.
1217 /// Possible input : "0, 10", "10"
1219 [EditorBrowsable(EditorBrowsableState.Never)]
1220 public static implicit operator LottieFrameInfo(string pair)
1227 string[] parts = pair.Split(',');
1228 if (parts.Length == 1)
1230 return new LottieFrameInfo(Int32.Parse(parts[0].Trim(), CultureInfo.InvariantCulture));
1232 else if (parts.Length == 2)
1234 return new LottieFrameInfo(Int32.Parse(parts[0].Trim(), CultureInfo.InvariantCulture), Int32.Parse(parts[1].Trim(), CultureInfo.InvariantCulture));
1237 Tizen.Log.Error("NUI", $"Can not convert string {pair} to LottieFrameInfo");
1242 /// The start frame of the lottie animation.
1244 [EditorBrowsable(EditorBrowsableState.Never)]
1245 public int StartFrame { get; }
1248 /// The end frame of the lottie animation.
1250 [EditorBrowsable(EditorBrowsableState.Never)]
1251 public int EndFrame { get; }
1254 /// Create LottieFrameInfo struct with animation range information
1256 [EditorBrowsable(EditorBrowsableState.Never)]
1257 public static LottieFrameInfo CreateAnimationRange(int startFrame, int endFrame)
1259 return new LottieFrameInfo(startFrame, endFrame);
1263 /// Create LottieFrameInfo struct with still image information
1265 [EditorBrowsable(EditorBrowsableState.Never)]
1266 public static LottieFrameInfo CreateStillImage(int stillImageFrame)
1268 return new LottieFrameInfo(stillImageFrame, stillImageFrame);
1273 /// Whether this LottieFrameInfo represents one frame or more.
1275 [EditorBrowsable(EditorBrowsableState.Never)]
1276 public bool IsStillImage()
1278 return StartFrame == EndFrame;
1283 /// Play specified LottieAnimationView with this frame information.
1285 /// <param name="lottieView">The target LottieAnimationView to play.</param>
1286 /// <param name="noPlay">Whether go direct to the EndFrame. It is false by default.</param>
1287 [EditorBrowsable(EditorBrowsableState.Never)]
1288 [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062: Validate arguments of public methods", Justification = "The null checking is done by BeReadyToShow()")]
1289 public void Show(LottieAnimationView lottieView, bool noPlay = false)
1291 if (!BeReadyToShow(lottieView))
1296 lottieView.SetMinMaxFrame(StartFrame, Math.Min(EndFrame, lottieView.TotalFrame - 1));
1298 if (IsStillImage() || noPlay)
1300 lottieView.CurrentFrame = EndFrame;
1304 lottieView.CurrentFrame = StartFrame;
1310 [EditorBrowsable(EditorBrowsableState.Never)]
1311 public object Clone() => new LottieFrameInfo(StartFrame, EndFrame);
1313 private bool BeReadyToShow(LottieAnimationView lottieView)
1315 // Validate input lottieView
1316 if (null == lottieView || lottieView.PlayState == LottieAnimationView.PlayStateType.Invalid)
1321 // Stop if it was playing
1322 if (lottieView.PlayState == LottieAnimationView.PlayStateType.Playing)
1331 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
1332 [EditorBrowsable(EditorBrowsableState.Never)]
1333 public struct LottieAnimationViewDynamicProperty : IEquatable<LottieAnimationViewDynamicProperty>
1335 [EditorBrowsable(EditorBrowsableState.Never)]
1336 public string KeyPath { get; set; }
1338 [EditorBrowsable(EditorBrowsableState.Never)]
1339 public LottieAnimationView.VectorProperty Property { get; set; }
1341 [EditorBrowsable(EditorBrowsableState.Never)]
1342 public LottieAnimationView.DynamicPropertyCallbackType Callback { get; set; }
1344 public override bool Equals(object obj)
1346 if (obj is LottieAnimationViewDynamicProperty target)
1348 if (KeyPath == target.KeyPath && Property == target.Property && Callback == target.Callback)
1356 public override int GetHashCode()
1358 return base.GetHashCode();
1361 public static bool operator ==(LottieAnimationViewDynamicProperty left, LottieAnimationViewDynamicProperty right)
1363 return left.Equals(right);
1366 public static bool operator !=(LottieAnimationViewDynamicProperty left, LottieAnimationViewDynamicProperty right)
1368 return !(left == right);
1371 public bool Equals(LottieAnimationViewDynamicProperty other)
1375 if (KeyPath == other.KeyPath && Property == other.Property && Callback == other.Callback)