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 /// A marker has its start frame and end frame.
599 /// Animation will play between the start frame and the end frame of the marker if one marker is specified.
600 /// 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. *
602 /// <param name="marker1">First marker</param>
603 /// <param name="marker2">Second marker</param>
604 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
605 [EditorBrowsable(EditorBrowsableState.Never)]
606 public void SetMinMaxFrameByMarker(string marker1, string marker2 = null)
608 if (currentStates.mark1 != marker1 || currentStates.mark2 != marker2)
610 NUILog.Debug($"< [{GetId()}] SetMinMaxFrameByMarker({marker1}, {marker2})");
612 currentStates.changed = true;
613 currentStates.mark1 = marker1;
614 currentStates.mark2 = marker2;
616 if (string.IsNullOrEmpty(currentStates.mark2))
618 Interop.View.InternalUpdateVisualPropertyString(this.SwigCPtr, ImageView.Property.IMAGE, ImageVisualProperty.PlayRange, currentStates.mark1);
622 Interop.View.InternalUpdateVisualPropertyStringPair(this.SwigCPtr, ImageView.Property.IMAGE, ImageVisualProperty.PlayRange, currentStates.mark1, currentStates.mark2);
625 NUILog.Debug($" [{GetId()}] currentStates.mark1:{currentStates.mark1}, mark2:{currentStates.mark2} >");
632 /// <returns>Tuple of Min and Max frames</returns>
633 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
634 [EditorBrowsable(EditorBrowsableState.Never)]
635 public Tuple<int, int> GetMinMaxFrame()
637 NUILog.Debug($"< [{GetId()}] GetMinMaxFrame()! total frame={currentStates.totalFrame}");
639 using PropertyMap map = Image;
642 using PropertyValue val = map.Find(ImageVisualProperty.PlayRange);
645 using PropertyArray array = new PropertyArray();
648 uint cnt = array.Count();
649 int item1 = -1, item2 = -1;
650 for (uint i = 0; i < cnt; i++)
652 using PropertyValue v = array.GetElementAt(i);
654 if (v.Get(out intRet))
656 NUILog.Debug($"Got play range of string [{i}]: {intRet}");
668 Tizen.Log.Error("NUI", $"[ERR] fail to get play range from dali! case#1");
671 NUILog.Debug($" [{GetId()}] GetMinMaxFrame(min:{item1}, max:{item2})! >");
672 return new Tuple<int, int>(item1, item2);
676 Tizen.Log.Error("NUI", $"[ERR] fail to get play range from dali! case#2");
677 return new Tuple<int, int>(-1, -1);
680 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
681 [EditorBrowsable(EditorBrowsableState.Never)]
682 public void DoActionExtension(LottieAnimationViewDynamicProperty info)
684 dynamicPropertyCallbackId++;
686 weakReferencesOfLottie?.Add(dynamicPropertyCallbackId, new WeakReference<LottieAnimationView>(this));
687 InternalSavedDynamicPropertyCallbacks?.Add(dynamicPropertyCallbackId, info.Callback);
689 Interop.View.DoActionExtension(SwigCPtr, ImageView.Property.IMAGE, SetDynamicProperty, dynamicPropertyCallbackId, info.KeyPath, (int)info.Property, Marshal.GetFunctionPointerForDelegate<System.Delegate>(rootCallback));
691 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
694 private void CleanCallbackDictionaries()
696 if (weakReferencesOfLottie?.Count > 0 && InternalSavedDynamicPropertyCallbacks != null)
698 foreach (var key in InternalSavedDynamicPropertyCallbacks?.Keys)
700 if (weakReferencesOfLottie.ContainsKey(key))
702 weakReferencesOfLottie.Remove(key);
706 InternalSavedDynamicPropertyCallbacks?.Clear();
707 InternalSavedDynamicPropertyCallbacks = null;
712 #region Event, Enum, Struct, ETC
714 /// Animation finished event.
716 /// <since_tizen> 7 </since_tizen>
717 public event EventHandler Finished
721 if (finishedEventHandler == null)
723 NUILog.Debug($"<[{GetId()}] Finished eventhandler added>");
724 visualEventSignalCallback = onVisualEventSignal;
725 using VisualEventSignal visualEvent = VisualEventSignal();
726 visualEvent.Connect(visualEventSignalCallback);
728 finishedEventHandler += value;
732 NUILog.Debug($"<[{GetId()}] Finished eventhandler removed>");
733 finishedEventHandler -= value;
734 if (finishedEventHandler == null && visualEventSignalCallback != null)
736 using VisualEventSignal visualEvent = VisualEventSignal();
737 visualEvent.Disconnect(visualEventSignalCallback);
738 if (visualEvent?.Empty() == true)
740 visualEventSignalCallback = null;
747 /// Enumeration for what state the vector animation is in
749 /// <since_tizen> 7 </since_tizen>
750 public enum PlayStateType
755 /// <since_tizen> 7 </since_tizen>
758 /// Vector Animation has stopped
760 /// <since_tizen> 7 </since_tizen>
763 /// The vector animation is playing
765 /// <since_tizen> 7 </since_tizen>
768 /// The vector animation is paused
770 /// <since_tizen> 7 </since_tizen>
775 /// Enumeration for what to do when the animation is stopped.
777 /// <since_tizen> 7 </since_tizen>
778 public enum StopBehaviorType
781 /// When the animation is stopped, the current frame is shown.
783 /// <since_tizen> 7 </since_tizen>
786 /// When the animation is stopped, the min frame (first frame) is shown.
788 /// <since_tizen> 7 </since_tizen>
791 /// When the animation is stopped, the max frame (last frame) is shown.
793 /// <since_tizen> 7 </since_tizen>
798 /// Enumeration for what looping mode is in.
800 /// <since_tizen> 7 </since_tizen>
801 public enum LoopingModeType
804 /// When the animation arrives at the end in looping mode, the animation restarts from the beginning.
806 /// <since_tizen> 7 </since_tizen>
809 /// When the animation arrives at the end in looping mode, the animation reverses direction and runs backwards again.
811 /// <since_tizen> 7 </since_tizen>
818 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
819 [EditorBrowsable(EditorBrowsableState.Never)]
820 public enum VectorProperty
823 /// Fill color of the object, Type of <see cref="Vector3"/>
825 [EditorBrowsable(EditorBrowsableState.Never)]
829 /// Fill opacity of the object, Type of float
831 [EditorBrowsable(EditorBrowsableState.Never)]
835 /// Stroke color of the object, Type of <see cref="Vector3"/>
837 [EditorBrowsable(EditorBrowsableState.Never)]
841 /// Stroke opacity of the object, Type of float
843 [EditorBrowsable(EditorBrowsableState.Never)]
847 /// Stroke width of the object, Type of float
849 [EditorBrowsable(EditorBrowsableState.Never)]
853 /// Transform anchor of the Layer and Group object, Type of <see cref="Vector2"/>
855 [EditorBrowsable(EditorBrowsableState.Never)]
859 /// Transform position of the Layer and Group object, Type of <see cref="Vector2"/>
861 [EditorBrowsable(EditorBrowsableState.Never)]
865 /// Transform scale of the Layer and Group object, Type of <see cref="Vector2"/>, Value range of [0..100]
867 [EditorBrowsable(EditorBrowsableState.Never)]
871 /// Transform rotation of the Layer and Group object, Type of float, Value range of [0..360] in degrees
873 [EditorBrowsable(EditorBrowsableState.Never)]
877 /// Transform opacity of the Layer and Group object, Type of float
879 [EditorBrowsable(EditorBrowsableState.Never)]
883 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
884 [EditorBrowsable(EditorBrowsableState.Never)]
885 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
886 public delegate PropertyValue DynamicPropertyCallbackType(int returnType, uint frameNumber);
887 #endregion Event, Enum, Struct, ETC
891 internal class VisualEventSignalArgs : EventArgs
893 public int VisualIndex
905 internal event EventHandler<VisualEventSignalArgs> VisualEvent
909 if (visualEventSignalHandler == null)
911 visualEventSignalCallback = onVisualEventSignal;
912 using VisualEventSignal visualEvent = VisualEventSignal();
913 visualEvent?.Connect(visualEventSignalCallback);
915 visualEventSignalHandler += value;
919 visualEventSignalHandler -= value;
920 if (visualEventSignalHandler == null && visualEventSignalCallback != null)
922 using VisualEventSignal visualEvent = VisualEventSignal();
923 visualEvent?.Disconnect(visualEventSignalCallback);
924 if (visualEvent?.Empty() == true)
926 visualEventSignalCallback = null;
932 internal void EmitVisualEventSignal(int visualIndex, int signalId)
934 using VisualEventSignal visualEvent = VisualEventSignal();
935 visualEvent?.Emit(this, visualIndex, signalId);
938 internal VisualEventSignal VisualEventSignal()
940 VisualEventSignal ret = new VisualEventSignal(Interop.VisualEventSignal.NewWithView(View.getCPtr(this)), false);
941 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
945 internal Dictionary<int, DynamicPropertyCallbackType> InternalSavedDynamicPropertyCallbacks = new Dictionary<int, DynamicPropertyCallbackType>();
947 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
948 internal delegate void RootCallbackType(int id, int returnType, uint frameNumber, ref float val1, ref float val2, ref float val3);
950 internal RootCallbackType rootCallback = RootCallback;
952 static internal void RootCallback(int id, int returnType, uint frameNumber, ref float val1, ref float val2, ref float val3)
954 WeakReference<LottieAnimationView> current = null;
955 LottieAnimationView currentView = null;
956 DynamicPropertyCallbackType currentCallback = null;
957 PropertyValue ret = null;
959 if (weakReferencesOfLottie.TryGetValue(id, out current))
961 if (current.TryGetTarget(out currentView))
963 if (currentView != null && currentView.InternalSavedDynamicPropertyCallbacks != null &&
964 currentView.InternalSavedDynamicPropertyCallbacks.TryGetValue(id, out currentCallback))
966 ret = currentCallback?.Invoke(returnType, frameNumber);
970 Tizen.Log.Error("NUI", "can't find the callback in LottieAnimationView, just return here!");
976 Tizen.Log.Error("NUI", "can't find the callback in LottieAnimationView, just return here!");
982 Tizen.Log.Error("NUI", "can't find LottieAnimationView by id, just return here!");
988 case (int)(VectorProperty.FillColor):
989 case (int)(VectorProperty.StrokeColor):
990 Vector3 tmpVector3 = new Vector3(-1, -1, -1);
991 if ((ret != null) && ret.Get(tmpVector3))
997 tmpVector3.Dispose();
1000 case (int)(VectorProperty.TransformAnchor):
1001 case (int)(VectorProperty.TransformPosition):
1002 case (int)(VectorProperty.TransformScale):
1003 Vector2 tmpVector2 = new Vector2(-1, -1);
1004 if ((ret != null) && ret.Get(tmpVector2))
1006 val1 = tmpVector2.X;
1007 val2 = tmpVector2.Y;
1009 tmpVector2.Dispose();
1012 case (int)(VectorProperty.FillOpacity):
1013 case (int)(VectorProperty.StrokeOpacity):
1014 case (int)(VectorProperty.StrokeWidth):
1015 case (int)(VectorProperty.TransformRotation):
1016 case (int)(VectorProperty.TransformOpacity):
1017 float tmpFloat = -1;
1018 if ((ret != null) && ret.Get(out tmpFloat))
1033 private struct states
1035 internal string url;
1036 internal int loopCount;
1037 internal LoopingModeType loopMode;
1038 internal StopBehaviorType stopEndAction;
1039 internal int framePlayRangeMin;
1040 internal int framePlayRangeMax;
1041 internal bool changed;
1042 internal int totalFrame;
1043 internal float scale;
1044 internal PlayStateType playState;
1045 internal List<Tuple<string, int, int>> contentInfo;
1046 internal string mark1, mark2;
1047 internal bool redrawInScalingDown;
1048 internal bool enableFrameCache;
1050 private states currentStates;
1052 private struct DevelVisual
1056 AnimatedGradient = Visual.Type.AnimatedImage + 1,
1057 AnimatedVectorImage = Visual.Type.AnimatedImage + 2,
1061 private const string tag = "NUITEST";
1062 private event EventHandler finishedEventHandler;
1064 private void OnFinished()
1066 NUILog.Debug($"<[{GetId()}] OnFinished()>");
1067 finishedEventHandler?.Invoke(this, null);
1070 private void onVisualEventSignal(IntPtr targetView, int visualIndex, int signalId)
1074 if (targetView != IntPtr.Zero)
1076 View v = Registry.GetManagedBaseHandleFromNativePtr(targetView) as View;
1079 NUILog.Debug($"targetView is not null! name={v.Name}");
1083 NUILog.Debug($"target is something created from dali");
1086 VisualEventSignalArgs e = new VisualEventSignalArgs();
1087 e.VisualIndex = visualIndex;
1088 e.SignalId = signalId;
1089 visualEventSignalHandler?.Invoke(this, e);
1091 NUILog.Debug($"<[{GetId()}] onVisualEventSignal()! visualIndex={visualIndex}, signalId={signalId}>");
1094 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
1095 private delegate void VisualEventSignalCallbackType(IntPtr targetView, int visualIndex, int signalId);
1097 private VisualEventSignalCallbackType visualEventSignalCallback;
1098 private EventHandler<VisualEventSignalArgs> visualEventSignalHandler;
1100 static private int dynamicPropertyCallbackId = 0;
1101 //static private Dictionary<int, DynamicPropertyCallbackType> dynamicPropertyCallbacks = new Dictionary<int, DynamicPropertyCallbackType>();
1102 static private Dictionary<int, WeakReference<LottieAnimationView>> weakReferencesOfLottie = new Dictionary<int, WeakReference<LottieAnimationView>>();
1104 private void debugPrint()
1106 NUILog.Debug($"===================================");
1107 NUILog.Debug($"<[{GetId()}] get currentStates : url={currentStates.url}, loopCount={currentStates.loopCount}, \nframePlayRangeMin/Max({currentStates.framePlayRangeMin},{currentStates.framePlayRangeMax}) ");
1108 NUILog.Debug($" get from Property : StopBehavior={StopBehavior}, LoopMode={LoopingMode}, LoopCount={LoopCount}, PlayState={PlayState}");
1109 NUILog.Debug($" RedrawInScalingDown={RedrawInScalingDown} >");
1110 NUILog.Debug($"===================================");
1117 /// A class containing frame informations for a LottieAnimationView.
1119 [EditorBrowsable(EditorBrowsableState.Never)]
1120 public class LottieFrameInfo : ICloneable
1123 /// Creates a new instance with a playing range.
1125 [EditorBrowsable(EditorBrowsableState.Never)]
1126 public LottieFrameInfo(int startFrame, int endFrame)
1128 StartFrame = startFrame;
1129 EndFrame = endFrame;
1133 /// Creates a new instance with a still image frame.
1135 [EditorBrowsable(EditorBrowsableState.Never)]
1136 public LottieFrameInfo(int stillImageFrame) : this(stillImageFrame, stillImageFrame)
1141 /// Create a new instance from a pair notation.
1143 [EditorBrowsable(EditorBrowsableState.Never)]
1144 public static implicit operator LottieFrameInfo((int, int) pair)
1146 return new LottieFrameInfo(pair.Item1, pair.Item2);
1150 /// Create a new instance from an int value.
1152 [EditorBrowsable(EditorBrowsableState.Never)]
1153 public static implicit operator LottieFrameInfo(int stillImageFrame)
1155 return new LottieFrameInfo(stillImageFrame);
1159 /// Create a new instance from string.
1160 /// Possible input : "0, 10", "10"
1162 [EditorBrowsable(EditorBrowsableState.Never)]
1163 public static implicit operator LottieFrameInfo(string pair)
1170 string[] parts = pair.Split(',');
1171 if (parts.Length == 1)
1173 return new LottieFrameInfo(Int32.Parse(parts[0].Trim(), CultureInfo.InvariantCulture));
1175 else if (parts.Length == 2)
1177 return new LottieFrameInfo(Int32.Parse(parts[0].Trim(), CultureInfo.InvariantCulture), Int32.Parse(parts[1].Trim(), CultureInfo.InvariantCulture));
1180 Tizen.Log.Error("NUI", $"Can not convert string {pair} to LottieFrameInfo");
1185 /// The start frame of the lottie animation.
1187 [EditorBrowsable(EditorBrowsableState.Never)]
1188 public int StartFrame { get; }
1191 /// The end frame of the lottie animation.
1193 [EditorBrowsable(EditorBrowsableState.Never)]
1194 public int EndFrame { get; }
1197 /// Create LottieFrameInfo struct with animation range information
1199 [EditorBrowsable(EditorBrowsableState.Never)]
1200 public static LottieFrameInfo CreateAnimationRange(int startFrame, int endFrame)
1202 return new LottieFrameInfo(startFrame, endFrame);
1206 /// Create LottieFrameInfo struct with still image information
1208 [EditorBrowsable(EditorBrowsableState.Never)]
1209 public static LottieFrameInfo CreateStillImage(int stillImageFrame)
1211 return new LottieFrameInfo(stillImageFrame, stillImageFrame);
1216 /// Whether this LottieFrameInfo represents one frame or more.
1218 [EditorBrowsable(EditorBrowsableState.Never)]
1219 public bool IsStillImage()
1221 return StartFrame == EndFrame;
1226 /// Play specified LottieAnimationView with this frame information.
1228 /// <param name="lottieView">The target LottieAnimationView to play.</param>
1229 /// <param name="noPlay">Whether go direct to the EndFrame. It is false by default.</param>
1230 [EditorBrowsable(EditorBrowsableState.Never)]
1231 [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062: Validate arguments of public methods", Justification = "The null checking is done by BeReadyToShow()")]
1232 public void Show(LottieAnimationView lottieView, bool noPlay = false)
1234 if (!BeReadyToShow(lottieView))
1239 lottieView.SetMinMaxFrame(StartFrame, Math.Min(EndFrame, lottieView.TotalFrame - 1));
1241 if (IsStillImage() || noPlay)
1243 lottieView.CurrentFrame = EndFrame;
1247 lottieView.CurrentFrame = StartFrame;
1253 [EditorBrowsable(EditorBrowsableState.Never)]
1254 public object Clone() => new LottieFrameInfo(StartFrame, EndFrame);
1256 private bool BeReadyToShow(LottieAnimationView lottieView)
1258 // Validate input lottieView
1259 if (null == lottieView || lottieView.PlayState == LottieAnimationView.PlayStateType.Invalid)
1264 // Stop if it was playing
1265 if (lottieView.PlayState == LottieAnimationView.PlayStateType.Playing)
1274 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
1275 [EditorBrowsable(EditorBrowsableState.Never)]
1276 public struct LottieAnimationViewDynamicProperty : IEquatable<LottieAnimationViewDynamicProperty>
1278 [EditorBrowsable(EditorBrowsableState.Never)]
1279 public string KeyPath { get; set; }
1281 [EditorBrowsable(EditorBrowsableState.Never)]
1282 public LottieAnimationView.VectorProperty Property { get; set; }
1284 [EditorBrowsable(EditorBrowsableState.Never)]
1285 public LottieAnimationView.DynamicPropertyCallbackType Callback { get; set; }
1287 public override bool Equals(object obj)
1289 if (obj is LottieAnimationViewDynamicProperty target)
1291 if (KeyPath == target.KeyPath && Property == target.Property && Callback == target.Callback)
1299 public override int GetHashCode()
1301 return base.GetHashCode();
1304 public static bool operator ==(LottieAnimationViewDynamicProperty left, LottieAnimationViewDynamicProperty right)
1306 return left.Equals(right);
1309 public static bool operator !=(LottieAnimationViewDynamicProperty left, LottieAnimationViewDynamicProperty right)
1311 return !(left == right);
1314 public bool Equals(LottieAnimationViewDynamicProperty other)
1318 if (KeyPath == other.KeyPath && Property == other.Property && Callback == other.Callback)