2 * Copyright(c) 2021 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 System.ComponentModel;
21 namespace Tizen.NUI.BaseComponents
24 /// AnimatedVectorImageView is a class for displaying a vector resource.
26 [EditorBrowsable(EditorBrowsableState.Never)]
27 public class AnimatedVectorImageView : LottieAnimationView
29 #region Constructor, Destructor, Dispose
31 /// Construct VectorAnimationView.
33 [EditorBrowsable(EditorBrowsableState.Never)]
34 public AnimatedVectorImageView() : base()
36 NUILog.Debug($"[AnimatedVectorImageView START[ constructor objId={GetId()} ] END]");
40 /// Construct VectorAnimationView.
42 /// <param name="scale">Set scaling factor for Vector Animation, while creating.</param>
43 [EditorBrowsable(EditorBrowsableState.Never)]
44 public AnimatedVectorImageView(float scale) : base(scale)
46 NUILog.Debug($"[AnimatedVectorImageView START[ constructor scale={scale}) objId={GetId()} ] END]");
50 /// You can override it to clean-up your own resources
52 /// <param name="type">DisposeTypes</param>
53 [EditorBrowsable(EditorBrowsableState.Never)]
54 protected override void Dispose(DisposeTypes type)
60 NUILog.Debug($"AnimatedVectorImageView START");
62 //Release your own unmanaged resources here.
63 //You should not access any managed member here except static instance.
64 //because the execution order of Finalizes is non-deterministic.
68 NUILog.Debug($"AnimatedVectorImageView END");
70 #endregion Constructor, Destructor, Dispose
77 // Suppress warning : This has been being used by users, so that the interface can not be changed.
78 [EditorBrowsable(EditorBrowsableState.Never)]
79 public string ResourceURL
83 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] ResourceURL SET");
85 if (value == resourceUrl)
87 NUILog.Debug($"set same URL! ");
90 resourceUrl = (value == null) ? "" : value;
92 isMinMaxFrameSet = minMaxSetTypes.NotSetByUser;
93 totalFrameNum = base.TotalFrame;
94 NUILog.Debug($" [{GetId()}] resourceUrl={resourceUrl}) ]AnimatedVectorImageView END]");
102 // Suppress warning : This has been being used by users, so that the interface can not be changed.
103 [EditorBrowsable(EditorBrowsableState.Never)]
104 public new string ResourceUrl
108 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] ResourceUrl SET");
109 this.ResourceURL = value;
110 NUILog.Debug($" [{GetId()}] value={value}) ]AnimatedVectorImageView END]");
114 NUILog.Debug($"[AnimatedVectorImageView [ [{GetId()}] ResourceUrl GET");
115 return this.ResourceURL;
121 /// RepeatCount of animation.
122 /// The repeat count is 0 by default.
123 /// If the RepeatCount is 0, the animation is never repeated.
124 /// If the RepeatCount is greater than 0, the repeat mode will be taken into account.
125 /// If RepeatCount is -1, animation is infinite loops.
127 [EditorBrowsable(EditorBrowsableState.Never)]
128 public int RepeatCount
132 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] RepeatCount SET");
134 repeatCnt = (value < -1) ? -1 : value;
135 LoopCount = (repeatCnt < 0) ? repeatCnt : repeatCnt + 1;
137 NUILog.Debug($"[{GetId()}] repeatCnt={repeatCnt} ]AnimatedVectorImageView END]");
143 /// TotalFrame of animation.
145 [EditorBrowsable(EditorBrowsableState.Never)]
146 public new int TotalFrame
148 get => totalFrameNum;
152 /// CurrentFrame of animation.
154 /// <returns> Returns user set value for the current frame. Cannot provide actual playing current frame. </returns>
155 [EditorBrowsable(EditorBrowsableState.Never)]
156 public new int CurrentFrame
160 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] CurrentFrame SET");
162 if (string.IsNullOrEmpty(resourceUrl))
164 throw new InvalidOperationException("Resource Url not yet Set");
171 else if (value >= totalFrameNum)
173 value = totalFrameNum - 1;
176 innerCurrentFrame = value;
177 AnimationState = AnimationStates.Paused;
179 base.SetMinMaxFrame(0, totalFrameNum - 1);
180 base.CurrentFrame = innerCurrentFrame;
182 NUILog.Debug($" [{GetId()}] innerCurrentFrame={innerCurrentFrame}) ]AnimatedVectorImageView END]");
184 get => innerCurrentFrame;
188 /// RepeatMode of animation.
190 [EditorBrowsable(EditorBrowsableState.Never)]
191 public RepeatModes RepeatMode
195 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] RepeatMode SET");
200 case RepeatModes.Restart:
201 LoopingMode = LoopingModeType.Restart;
203 case RepeatModes.Reverse:
204 LoopingMode = LoopingModeType.AutoReverse;
207 LoopingMode = LoopingModeType.Restart;
211 NUILog.Debug($" [{GetId()}] repeatMode={repeatMode}) ]AnimatedVectorImageView END]");
217 /// Get state of animation.
219 [EditorBrowsable(EditorBrowsableState.Never)]
220 public AnimationStates AnimationState
224 CurrentAnimationState = value;
228 if (CurrentAnimationState == AnimationStates.Playing)
230 if (PlayState == PlayStateType.Stopped)
232 CurrentAnimationState = AnimationStates.Stopped;
235 return CurrentAnimationState;
243 /// Set minimum frame and maximum frame
245 /// <param name="minFrame">minimum frame.</param>
246 /// <param name="maxFrame">maximum frame.</param>
247 [EditorBrowsable(EditorBrowsableState.Never)]
248 public void SetMinAndMaxFrame(int minFrame, int maxFrame)
250 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] SetMinAndMaxFrame({minFrame}, {maxFrame})");
252 minimumFrame = (minFrame) > 0 ? minFrame : 0;
253 maximumFrame = (maxFrame) > 0 ? maxFrame : 0;
254 isMinMaxFrameSet = minMaxSetTypes.SetByMinAndMaxFrameMethod;
256 if (minimumFrame >= totalFrameNum)
258 minimumFrame = totalFrameNum - 1;
261 if (maximumFrame >= totalFrameNum)
263 maximumFrame = totalFrameNum - 1;
266 if (minimumFrame > maximumFrame)
271 NUILog.Debug($" [{GetId()}] minimumFrame:{minimumFrame}, maximumFrame:{maximumFrame}) ]AnimatedVectorImageView END]");
275 /// SetMinMaxFrame(int startFrame, int endFrame)
277 /// <param name="minFrame"></param>
278 /// <param name="maxFrame"></param>
279 [EditorBrowsable(EditorBrowsableState.Never)]
280 public new void SetMinMaxFrame(int minFrame, int maxFrame)
282 NUILog.Debug($"SetMinMaxFrame({minFrame}, {maxFrame})!!!");
284 minimumFrame = (minFrame) > 0 ? minFrame : 0;
285 maximumFrame = (maxFrame) > 0 ? maxFrame : 0;
286 isMinMaxFrameSet = minMaxSetTypes.SetByBaseSetMinMaxFrameMethod;
288 if (minimumFrame >= totalFrameNum)
290 minimumFrame = totalFrameNum - 1;
293 if (maximumFrame >= totalFrameNum)
295 maximumFrame = totalFrameNum - 1;
298 base.SetMinMaxFrame(minimumFrame, maximumFrame);
302 /// A marker has its start frame and end frame.
303 /// Animation will play between the start frame and the end frame of the marker if one marker is specified.
304 /// 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. *
306 /// <param name="marker1">First marker</param>
307 /// <param name="marker2">Second marker</param>
308 [EditorBrowsable(EditorBrowsableState.Never)]
309 public new void SetMinMaxFrameByMarker(string marker1, string marker2 = null)
311 NUILog.Debug($"SetMinMaxFrameByMarker({marker1}, {marker2})");
312 isMinMaxFrameSet = minMaxSetTypes.SetByMarker;
313 base.SetMinMaxFrameByMarker(marker1, marker2);
319 [EditorBrowsable(EditorBrowsableState.Never)]
320 public new void Play()
322 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] AnimationState={AnimationState}, PlayState={PlayState}");
324 if (string.IsNullOrEmpty(resourceUrl))
326 throw new InvalidOperationException("Resource Url not yet Set");
329 switch (isMinMaxFrameSet)
331 case minMaxSetTypes.NotSetByUser:
332 base.SetMinMaxFrame(0, totalFrameNum - 1);
333 base.CurrentFrame = 0;
336 case minMaxSetTypes.SetByMinAndMaxFrameMethod:
337 base.SetMinMaxFrame(minimumFrame, maximumFrame);
338 base.CurrentFrame = minimumFrame;
341 case minMaxSetTypes.SetByMarker:
342 case minMaxSetTypes.SetByBaseSetMinMaxFrameMethod:
349 Extents tmp = base.Margin;
353 AnimationState = AnimationStates.Playing;
355 NUILog.Debug($" [{GetId()}] isMinMaxFrameSet={isMinMaxFrameSet}) ]AnimatedVectorImageView END]");
361 [EditorBrowsable(EditorBrowsableState.Never)]
362 public new void Pause()
364 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] AnimationState={AnimationState}, PlayState={PlayState}");
366 if (string.IsNullOrEmpty(resourceUrl))
368 throw new InvalidOperationException("Resource Url not yet Set");
372 AnimationState = AnimationStates.Paused;
374 NUILog.Debug($" [{GetId()}] ]AnimatedVectorImageView END]");
380 /// <param name="endAction">Defines, what should be behaviour after cancel operation
381 /// End action is Cancel, Animation Stops at the Current Frame.
382 /// End action is Discard, Animation Stops at the Min Frame
383 /// End action is StopFinal, Animation Stops at the Max Frame
385 [EditorBrowsable(EditorBrowsableState.Never)]
386 public void Stop(EndActions endAction = EndActions.Cancel)
388 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] endAction:({endAction}), PlayState={PlayState}");
390 if (string.IsNullOrEmpty(resourceUrl))
392 throw new InvalidOperationException("Resource Url not yet Set");
395 if (AnimationState == AnimationStates.Stopped)
400 if (innerEndAction != endAction)
402 innerEndAction = endAction;
405 case EndActions.Cancel:
406 StopBehavior = StopBehaviorType.CurrentFrame;
408 case EndActions.Discard:
409 StopBehavior = StopBehaviorType.MinimumFrame;
411 case EndActions.StopFinal:
412 StopBehavior = StopBehaviorType.MaximumFrame;
415 NUILog.Debug($" [{GetId()}] no endAction : default set");
419 AnimationState = AnimationStates.Stopped;
423 if (endAction == EndActions.StopFinal)
425 switch (isMinMaxFrameSet)
427 case minMaxSetTypes.NotSetByUser:
428 if (base.CurrentFrame != totalFrameNum - 1)
430 NUILog.Debug($"isMinMaxFrameSet:{isMinMaxFrameSet}, CurrentFrameNumber:{base.CurrentFrame}, totalFrameNum:{ totalFrameNum}");
431 base.CurrentFrame = totalFrameNum - 1;
432 NUILog.Debug($"set CurrentFrameNumber({base.CurrentFrame}) as totalFrameNum({maximumFrame}) - 1 !");
436 case minMaxSetTypes.SetByMinAndMaxFrameMethod:
437 if (base.CurrentFrame != maximumFrame)
439 NUILog.Debug($"isMinMaxFrameSet:{isMinMaxFrameSet}, CurrentFrameNumber:{base.CurrentFrame}, maximumFrame:{ maximumFrame}");
440 base.CurrentFrame = maximumFrame;
441 NUILog.Debug($"set CurrentFrameNumber({base.CurrentFrame}) as maximumFrame({maximumFrame})!!!");
444 case minMaxSetTypes.SetByBaseSetMinMaxFrameMethod:
445 case minMaxSetTypes.SetByMarker:
451 NUILog.Debug($" [{GetId()}] ]AnimatedVectorImageView END]");
456 #region Event, Enum, Struct, ETC
458 /// RepeatMode of animation.
460 // Suppress warning : This has been being used by users, so that the interface can not be changed.
461 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names", Justification = "<Pending>")]
462 [EditorBrowsable(EditorBrowsableState.Never)]
463 public enum RepeatModes
466 /// When the animation reaches the end and RepeatCount is nonZero, the animation restarts from the beginning.
468 [EditorBrowsable(EditorBrowsableState.Never)]
469 Restart = LoopingModeType.Restart,
471 /// When the animation reaches the end and RepeatCount nonZero, the animation reverses direction on every animation cycle.
473 [EditorBrowsable(EditorBrowsableState.Never)]
474 Reverse = LoopingModeType.AutoReverse
478 /// EndActions of animation.
480 // Suppress warning : This has been being used by users, so that the interface can not be changed.
481 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names", Justification = "<Pending>")]
482 [EditorBrowsable(EditorBrowsableState.Never)]
483 public enum EndActions
485 /// <summary> End action is Cancel, Animation Stops at the Current Frame.</summary>
486 [EditorBrowsable(EditorBrowsableState.Never)]
488 /// <summary> End action is Discard, Animation Stops at the Min Frame</summary>
489 [EditorBrowsable(EditorBrowsableState.Never)]
491 /// <summary> End action is StopFinal, Animation Stops at the Max Frame</summary>
492 [EditorBrowsable(EditorBrowsableState.Never)]
497 /// AnimationStates of animation.
499 // Suppress warning : This has been being used by users, so that the interface can not be changed.
500 [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names", Justification = "<Pending>")]
501 [EditorBrowsable(EditorBrowsableState.Never)]
502 public enum AnimationStates
504 /// <summary> The animation has stopped.</summary>
505 [EditorBrowsable(EditorBrowsableState.Never)]
506 Stopped = PlayStateType.Stopped,
507 /// <summary> The animation is playing.</summary>
508 [EditorBrowsable(EditorBrowsableState.Never)]
509 Playing = PlayStateType.Playing,
510 /// <summary> The animation is paused.</summary>
511 [EditorBrowsable(EditorBrowsableState.Never)]
512 Paused = PlayStateType.Paused
514 #endregion Event, Enum, Struct, ETC
522 private string resourceUrl = null;
523 private int repeatCnt = 0;
524 private int totalFrameNum = 0;
525 private RepeatModes repeatMode = RepeatModes.Restart;
526 private int minimumFrame = -1, maximumFrame = -1;
527 private minMaxSetTypes isMinMaxFrameSet = minMaxSetTypes.NotSetByUser;
528 private int innerCurrentFrame = -1;
529 private EndActions innerEndAction = EndActions.Cancel;
530 private enum minMaxSetTypes
533 SetByMinAndMaxFrameMethod,
535 SetByBaseSetMinMaxFrameMethod,
538 private AnimationStates CurrentAnimationState = AnimationStates.Stopped;