[NUI] Remove build warning messages
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / AnimatedVectorImageView.cs
1 /*
2  * Copyright(c) 2021 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 using global::System;
19 using System.ComponentModel;
20
21 namespace Tizen.NUI.BaseComponents
22 {
23     /// <summary>
24     /// AnimatedVectorImageView is a class for displaying a vector resource.
25     /// </summary>
26     [EditorBrowsable(EditorBrowsableState.Never)]
27     public class AnimatedVectorImageView : LottieAnimationView
28     {
29         #region Constructor, Destructor, Dispose
30         /// <summary>
31         /// Construct VectorAnimationView.
32         /// </summary>
33         [EditorBrowsable(EditorBrowsableState.Never)]
34         public AnimatedVectorImageView() : base()
35         {
36             NUILog.Debug($"[AnimatedVectorImageView START[ constructor objId={GetId()} ] END]");
37         }
38
39         /// <summary>
40         /// Construct VectorAnimationView.
41         /// </summary>
42         /// <param name="scale">Set scaling factor for Vector Animation, while creating.</param>
43         [EditorBrowsable(EditorBrowsableState.Never)]
44         public AnimatedVectorImageView(float scale) : base(scale)
45         {
46             NUILog.Debug($"[AnimatedVectorImageView START[ constructor scale={scale}) objId={GetId()} ] END]");
47         }
48
49         /// <summary>
50         /// You can override it to clean-up your own resources
51         /// </summary>
52         /// <param name="type">DisposeTypes</param>
53         [EditorBrowsable(EditorBrowsableState.Never)]
54         protected override void Dispose(DisposeTypes type)
55         {
56             if (disposed)
57             {
58                 return;
59             }
60             NUILog.Debug($"AnimatedVectorImageView START");
61
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.
65
66             base.Dispose(type);
67
68             NUILog.Debug($"AnimatedVectorImageView END");
69         }
70         #endregion Constructor, Destructor, Dispose
71
72
73         #region Property
74         /// <summary>
75         /// Set Resource URL
76         /// </summary>
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
80         {
81             set
82             {
83                 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] ResourceURL SET");
84
85                 if (value == resourceUrl)
86                 {
87                     NUILog.Debug($"set same URL! ");
88                     return;
89                 }
90                 resourceUrl = (value == null) ? "" : value;
91                 URL = resourceUrl;
92                 isMinMaxFrameSet = minMaxSetTypes.NotSetByUser;
93                 totalFrameNum = base.TotalFrame;
94                 NUILog.Debug($" [{GetId()}] resourceUrl={resourceUrl}) ]AnimatedVectorImageView END]");
95             }
96             get => resourceUrl;
97         }
98
99         /// <summary>
100         /// Set Resource URL
101         /// </summary>
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
105         {
106             set
107             {
108                 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] ResourceUrl SET");
109                 this.ResourceURL = value;
110                 NUILog.Debug($" [{GetId()}] value={value}) ]AnimatedVectorImageView END]");
111             }
112             get
113             {
114                 NUILog.Debug($"[AnimatedVectorImageView [ [{GetId()}] ResourceUrl GET");
115                 return this.ResourceURL;
116             }
117         }
118
119
120         /// <summary>
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.
126         /// </summary>
127         [EditorBrowsable(EditorBrowsableState.Never)]
128         public int RepeatCount
129         {
130             set
131             {
132                 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] RepeatCount SET");
133
134                 repeatCnt = (value < -1) ? -1 : value;
135                 LoopCount = (repeatCnt < 0) ? repeatCnt : repeatCnt + 1;
136
137                 NUILog.Debug($"[{GetId()}] repeatCnt={repeatCnt} ]AnimatedVectorImageView END]");
138             }
139             get => repeatCnt;
140         }
141
142         /// <summary>
143         /// TotalFrame of animation.
144         /// </summary>
145         [EditorBrowsable(EditorBrowsableState.Never)]
146         public new int TotalFrame
147         {
148             get => totalFrameNum;
149         }
150
151         /// <summary>
152         /// CurrentFrame of animation.
153         /// </summary>
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
157         {
158             set
159             {
160                 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] CurrentFrame SET");
161
162                 if (string.IsNullOrEmpty(resourceUrl))
163                 {
164                     throw new InvalidOperationException("Resource Url not yet Set");
165                 }
166
167                 if (value < 0)
168                 {
169                     value = 0;
170                 }
171                 else if (value >= totalFrameNum)
172                 {
173                     value = totalFrameNum - 1;
174                 }
175
176                 innerCurrentFrame = value;
177                 AnimationState = AnimationStates.Paused;
178
179                 base.SetMinMaxFrame(0, totalFrameNum - 1);
180                 base.CurrentFrame = innerCurrentFrame;
181
182                 NUILog.Debug($" [{GetId()}] innerCurrentFrame={innerCurrentFrame}) ]AnimatedVectorImageView END]");
183             }
184             get => innerCurrentFrame;
185         }
186
187         /// <summary>
188         /// RepeatMode of animation.
189         /// </summary>
190         [EditorBrowsable(EditorBrowsableState.Never)]
191         public RepeatModes RepeatMode
192         {
193             set
194             {
195                 NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] RepeatMode SET");
196                 repeatMode = value;
197
198                 switch (repeatMode)
199                 {
200                     case RepeatModes.Restart:
201                         LoopingMode = LoopingModeType.Restart;
202                         break;
203                     case RepeatModes.Reverse:
204                         LoopingMode = LoopingModeType.AutoReverse;
205                         break;
206                     default:
207                         LoopingMode = LoopingModeType.Restart;
208                         break;
209                 }
210
211                 NUILog.Debug($" [{GetId()}] repeatMode={repeatMode}) ]AnimatedVectorImageView END]");
212             }
213             get => repeatMode;
214         }
215
216         /// <summary>
217         /// Get state of animation.
218         /// </summary>
219         [EditorBrowsable(EditorBrowsableState.Never)]
220         public AnimationStates AnimationState
221         {
222             private set
223             {
224                 CurrentAnimationState = value;
225             }
226             get
227             {
228                 if (CurrentAnimationState == AnimationStates.Playing)
229                 {
230                     if (PlayState == PlayStateType.Stopped)
231                     {
232                         CurrentAnimationState = AnimationStates.Stopped;
233                     }
234                 }
235                 return CurrentAnimationState;
236             }
237         }
238         #endregion Property
239
240
241         #region Method
242         /// <summary>
243         /// Set minimum frame and maximum frame
244         /// </summary>
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)
249         {
250             NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] SetMinAndMaxFrame({minFrame}, {maxFrame})");
251
252             minimumFrame = (minFrame) > 0 ? minFrame : 0;
253             maximumFrame = (maxFrame) > 0 ? maxFrame : 0;
254             isMinMaxFrameSet = minMaxSetTypes.SetByMinAndMaxFrameMethod;
255
256             if (minimumFrame >= totalFrameNum)
257             {
258                 minimumFrame = totalFrameNum - 1;
259             }
260
261             if (maximumFrame >= totalFrameNum)
262             {
263                 maximumFrame = totalFrameNum - 1;
264             }
265
266             if (minimumFrame > maximumFrame)
267             {
268                 return;
269             }
270
271             NUILog.Debug($" [{GetId()}] minimumFrame:{minimumFrame}, maximumFrame:{maximumFrame}) ]AnimatedVectorImageView END]");
272         }
273
274         /// <summary>
275         /// SetMinMaxFrame(int startFrame, int endFrame)
276         /// </summary>
277         /// <param name="minFrame"></param>
278         /// <param name="maxFrame"></param>
279         [EditorBrowsable(EditorBrowsableState.Never)]
280         public new void SetMinMaxFrame(int minFrame, int maxFrame)
281         {
282             NUILog.Debug($"SetMinMaxFrame({minFrame}, {maxFrame})!!!");
283
284             minimumFrame = (minFrame) > 0 ? minFrame : 0;
285             maximumFrame = (maxFrame) > 0 ? maxFrame : 0;
286             isMinMaxFrameSet = minMaxSetTypes.SetByBaseSetMinMaxFrameMethod;
287
288             if (minimumFrame >= totalFrameNum)
289             {
290                 minimumFrame = totalFrameNum - 1;
291             }
292
293             if (maximumFrame >= totalFrameNum)
294             {
295                 maximumFrame = totalFrameNum - 1;
296             }
297
298             base.SetMinMaxFrame(minimumFrame, maximumFrame);
299         }
300
301         /// <summary>
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.   *
305         /// </summary>
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)
310         {
311             NUILog.Debug($"SetMinMaxFrameByMarker({marker1}, {marker2})");
312             isMinMaxFrameSet = minMaxSetTypes.SetByMarker;
313             base.SetMinMaxFrameByMarker(marker1, marker2);
314         }
315
316         /// <summary>
317         /// Play Animation.
318         /// </summary>
319         [EditorBrowsable(EditorBrowsableState.Never)]
320         public new void Play()
321         {
322             NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] AnimationState={AnimationState}, PlayState={PlayState}");
323
324             if (string.IsNullOrEmpty(resourceUrl))
325             {
326                 throw new InvalidOperationException("Resource Url not yet Set");
327             }
328
329             switch (isMinMaxFrameSet)
330             {
331                 case minMaxSetTypes.NotSetByUser:
332                     base.SetMinMaxFrame(0, totalFrameNum - 1);
333                     base.CurrentFrame = 0;
334                     break;
335
336                 case minMaxSetTypes.SetByMinAndMaxFrameMethod:
337                     base.SetMinMaxFrame(minimumFrame, maximumFrame);
338                     base.CurrentFrame = minimumFrame;
339                     break;
340
341                 case minMaxSetTypes.SetByMarker:
342                 case minMaxSetTypes.SetByBaseSetMinMaxFrameMethod:
343                 default:
344                     //do nothing!
345                     break;
346             }
347
348             //temporal fix
349             Extents tmp = base.Margin;
350             base.Margin = tmp;
351
352             base.Play();
353             AnimationState = AnimationStates.Playing;
354
355             NUILog.Debug($" [{GetId()}] isMinMaxFrameSet={isMinMaxFrameSet}) ]AnimatedVectorImageView END]");
356         }
357
358         /// <summary>
359         /// Pause Animation.
360         /// </summary>
361         [EditorBrowsable(EditorBrowsableState.Never)]
362         public new void Pause()
363         {
364             NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] AnimationState={AnimationState}, PlayState={PlayState}");
365
366             if (string.IsNullOrEmpty(resourceUrl))
367             {
368                 throw new InvalidOperationException("Resource Url not yet Set");
369             }
370
371             base.Pause();
372             AnimationState = AnimationStates.Paused;
373
374             NUILog.Debug($" [{GetId()}] ]AnimatedVectorImageView END]");
375         }
376
377         /// <summary>
378         /// Stop Animation.
379         /// </summary>
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
384         /// </param>
385         [EditorBrowsable(EditorBrowsableState.Never)]
386         public void Stop(EndActions endAction = EndActions.Cancel)
387         {
388             NUILog.Debug($"[AnimatedVectorImageView START[ [{GetId()}] endAction:({endAction}), PlayState={PlayState}");
389
390             if (string.IsNullOrEmpty(resourceUrl))
391             {
392                 throw new InvalidOperationException("Resource Url not yet Set");
393             }
394
395             if (AnimationState == AnimationStates.Stopped)
396             {
397                 return;
398             }
399
400             if (innerEndAction != endAction)
401             {
402                 innerEndAction = endAction;
403                 switch (endAction)
404                 {
405                     case EndActions.Cancel:
406                         StopBehavior = StopBehaviorType.CurrentFrame;
407                         break;
408                     case EndActions.Discard:
409                         StopBehavior = StopBehaviorType.MinimumFrame;
410                         break;
411                     case EndActions.StopFinal:
412                         StopBehavior = StopBehaviorType.MaximumFrame;
413                         break;
414                     default:
415                         NUILog.Debug($" [{GetId()}] no endAction : default set");
416                         break;
417                 }
418             }
419             AnimationState = AnimationStates.Stopped;
420
421             base.Stop();
422
423             if (endAction == EndActions.StopFinal)
424             {
425                 switch (isMinMaxFrameSet)
426                 {
427                     case minMaxSetTypes.NotSetByUser:
428                         if (base.CurrentFrame != totalFrameNum - 1)
429                         {
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 !");
433                         }
434                         break;
435
436                     case minMaxSetTypes.SetByMinAndMaxFrameMethod:
437                         if (base.CurrentFrame != maximumFrame)
438                         {
439                             NUILog.Debug($"isMinMaxFrameSet:{isMinMaxFrameSet}, CurrentFrameNumber:{base.CurrentFrame}, maximumFrame:{ maximumFrame}");
440                             base.CurrentFrame = maximumFrame;
441                             NUILog.Debug($"set CurrentFrameNumber({base.CurrentFrame}) as maximumFrame({maximumFrame})!!!");
442                         }
443                         break;
444                     case minMaxSetTypes.SetByBaseSetMinMaxFrameMethod:
445                     case minMaxSetTypes.SetByMarker:
446                     default:
447                         //do nothing!
448                         break;
449                 }
450             }
451             NUILog.Debug($" [{GetId()}] ]AnimatedVectorImageView END]");
452         }
453         #endregion Method
454
455
456         #region Event, Enum, Struct, ETC
457         /// <summary>
458         /// RepeatMode of animation.
459         /// </summary>
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
464         {
465             /// <summary>
466             /// When the animation reaches the end and RepeatCount is nonZero, the animation restarts from the beginning. 
467             /// </summary>
468             [EditorBrowsable(EditorBrowsableState.Never)]
469             Restart = LoopingModeType.Restart,
470             /// <summary>
471             /// When the animation reaches the end and RepeatCount nonZero, the animation reverses direction on every animation cycle. 
472             /// </summary>
473             [EditorBrowsable(EditorBrowsableState.Never)]
474             Reverse = LoopingModeType.AutoReverse
475         }
476
477         /// <summary>
478         /// EndActions of animation.
479         /// </summary>
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
484         {
485             /// <summary> End action is Cancel, Animation Stops at the Current Frame.</summary>
486             [EditorBrowsable(EditorBrowsableState.Never)]
487             Cancel = 0,
488             /// <summary>  End action is Discard, Animation Stops at the Min Frame</summary>
489             [EditorBrowsable(EditorBrowsableState.Never)]
490             Discard = 1,
491             /// <summary> End action is StopFinal, Animation Stops at the Max Frame</summary>
492             [EditorBrowsable(EditorBrowsableState.Never)]
493             StopFinal = 2
494         }
495
496         /// <summary>
497         /// AnimationStates of animation.
498         /// </summary>
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
503         {
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
513         }
514         #endregion Event, Enum, Struct, ETC
515
516
517         #region Internal
518         #endregion Internal
519
520
521         #region Private
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
531         {
532             NotSetByUser,
533             SetByMinAndMaxFrameMethod,
534             SetByMarker,
535             SetByBaseSetMinMaxFrameMethod,
536         }
537
538         private AnimationStates CurrentAnimationState = AnimationStates.Stopped;
539         #endregion Private
540     }
541 }