[NUI] Add SetUnderline, GetUnderline to Text Components
[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 #if (NUI_DEBUG_ON)
24     using tlog = Tizen.Log;
25 #endif
26
27     /// <summary>
28     /// AnimatedVectorImageView is a class for displaying a vector resource.
29     /// </summary>
30     [EditorBrowsable(EditorBrowsableState.Never)]
31     public class AnimatedVectorImageView : LottieAnimationView
32     {
33         #region Constructor, Destructor, Dispose
34         /// <summary>
35         /// Construct VectorAnimationView.
36         /// </summary>
37         [EditorBrowsable(EditorBrowsableState.Never)]
38         public AnimatedVectorImageView() : base()
39         {
40             tlog.Fatal(tag, $"[AnimatedVectorImageView START[ constructor objId={GetId()} ] END]");
41         }
42
43         /// <summary>
44         /// Construct VectorAnimationView.
45         /// </summary>
46         /// <param name="scale">Set scaling factor for Vector Animation, while creating.</param>
47         [EditorBrowsable(EditorBrowsableState.Never)]
48         public AnimatedVectorImageView(float scale) : base(scale)
49         {
50             tlog.Fatal(tag, $"[AnimatedVectorImageView START[ constructor scale={scale}) objId={GetId()} ] END]");
51         }
52
53         /// <summary>
54         /// You can override it to clean-up your own resources
55         /// </summary>
56         /// <param name="type">DisposeTypes</param>
57         [EditorBrowsable(EditorBrowsableState.Never)]
58         protected override void Dispose(DisposeTypes type)
59         {
60             if (disposed)
61             {
62                 return;
63             }
64             tlog.Fatal(tag, $"[AnimatedVectorImageView START[ [{GetId()}] type={type})");
65
66             //Release your own unmanaged resources here.
67             //You should not access any managed member here except static instance.
68             //because the execution order of Finalizes is non-deterministic.
69
70             base.Dispose(type);
71
72             tlog.Fatal(tag, $"]AnimatedVectorImageView END]");
73         }
74         #endregion Constructor, Destructor, Dispose
75
76
77         #region Property
78         /// <summary>
79         /// Set Resource URL
80         /// </summary>
81         // Suppress warning : This has been being used by users, so that the interface can not be changed.
82         [EditorBrowsable(EditorBrowsableState.Never)]
83         public string ResourceURL
84         {
85             set
86             {
87                 tlog.Fatal(tag, $"[AnimatedVectorImageView START[ [{GetId()}] ResourceURL SET");
88
89                 if (value == resourceUrl)
90                 {
91                     tlog.Fatal(tag, $"set same URL! ");
92                     return;
93                 }
94                 resourceUrl = (value == null) ? "" : value;
95                 URL = resourceUrl;
96                 isMinMaxFrameSet = minMaxSetTypes.NotSetByUser;
97                 totalFrameNum = base.TotalFrame;
98                 tlog.Fatal(tag, $" [{GetId()}] resourceUrl={resourceUrl}) ]AnimatedVectorImageView END]");
99             }
100             get => resourceUrl;
101         }
102
103         /// <summary>
104         /// Set Resource URL
105         /// </summary>
106         // Suppress warning : This has been being used by users, so that the interface can not be changed.
107         [EditorBrowsable(EditorBrowsableState.Never)]
108         public new string ResourceUrl
109         {
110             set
111             {
112                 tlog.Fatal(tag, $"[AnimatedVectorImageView START[ [{GetId()}] ResourceUrl SET");
113                 this.ResourceURL = value;
114                 tlog.Fatal(tag, $" [{GetId()}] value={value}) ]AnimatedVectorImageView END]");
115             }
116             get
117             {
118                 tlog.Fatal(tag, $"[AnimatedVectorImageView [ [{GetId()}] ResourceUrl GET");
119                 return this.ResourceURL;
120             }
121         }
122
123
124         /// <summary>
125         /// RepeatCount of animation.
126         /// The repeat count is 0 by default.
127         /// If the RepeatCount is 0, the animation is never repeated.
128         /// If the RepeatCount is greater than 0, the repeat mode will be taken into account.
129         /// If RepeatCount is -1, animation is infinite loops.
130         /// </summary>
131         [EditorBrowsable(EditorBrowsableState.Never)]
132         public int RepeatCount
133         {
134             set
135             {
136                 tlog.Fatal(tag, $"[AnimatedVectorImageView START[ [{GetId()}] RepeatCount SET");
137
138                 repeatCnt = (value < -1) ? -1 : value;
139                 LoopCount = (repeatCnt < 0) ? repeatCnt : repeatCnt + 1;
140
141                 tlog.Fatal(tag, $"[{GetId()}] repeatCnt={repeatCnt} ]AnimatedVectorImageView END]");
142             }
143             get => repeatCnt;
144         }
145
146         /// <summary>
147         /// TotalFrame of animation.
148         /// </summary>
149         [EditorBrowsable(EditorBrowsableState.Never)]
150         public new int TotalFrame
151         {
152             get => totalFrameNum;
153         }
154
155         /// <summary>
156         /// CurrentFrame of animation.
157         /// </summary>
158         /// <returns> Returns user set value for the current frame. Cannot provide actual playing current frame. </returns>
159         [EditorBrowsable(EditorBrowsableState.Never)]
160         public new int CurrentFrame
161         {
162             set
163             {
164                 tlog.Fatal(tag, $"[AnimatedVectorImageView START[ [{GetId()}] CurrentFrame SET");
165
166                 if (string.IsNullOrEmpty(resourceUrl))
167                 {
168                     throw new InvalidOperationException("Resource Url not yet Set");
169                 }
170
171                 if (value < 0)
172                 {
173                     value = 0;
174                 }
175                 else if (value >= totalFrameNum)
176                 {
177                     value = totalFrameNum - 1;
178                 }
179
180                 innerCurrentFrame = value;
181                 AnimationState = AnimationStates.Paused;
182
183                 base.SetMinMaxFrame(0, totalFrameNum - 1);
184                 base.CurrentFrame = innerCurrentFrame;
185
186                 tlog.Fatal(tag, $" [{GetId()}] innerCurrentFrame={innerCurrentFrame}) ]AnimatedVectorImageView END]");
187             }
188             get => innerCurrentFrame;
189         }
190
191         /// <summary>
192         /// RepeatMode of animation.
193         /// </summary>
194         [EditorBrowsable(EditorBrowsableState.Never)]
195         public RepeatModes RepeatMode
196         {
197             set
198             {
199                 tlog.Fatal(tag, $"[AnimatedVectorImageView START[ [{GetId()}] RepeatMode SET");
200                 repeatMode = value;
201
202                 switch (repeatMode)
203                 {
204                     case RepeatModes.Restart:
205                         LoopingMode = LoopingModeType.Restart;
206                         break;
207                     case RepeatModes.Reverse:
208                         LoopingMode = LoopingModeType.AutoReverse;
209                         break;
210                     default:
211                         LoopingMode = LoopingModeType.Restart;
212                         break;
213                 }
214
215                 tlog.Fatal(tag, $" [{GetId()}] repeatMode={repeatMode}) ]AnimatedVectorImageView END]");
216             }
217             get => repeatMode;
218         }
219
220         /// <summary>
221         /// Get state of animation.
222         /// </summary>
223         [EditorBrowsable(EditorBrowsableState.Never)]
224         public AnimationStates AnimationState
225         {
226             private set
227             {
228                 CurrentAnimationState = value;
229             }
230             get
231             {
232                 if (CurrentAnimationState == AnimationStates.Playing)
233                 {
234                     if (PlayState == PlayStateType.Stopped)
235                     {
236                         CurrentAnimationState = AnimationStates.Stopped;
237                     }
238                 }
239                 return CurrentAnimationState;
240             }
241         }
242         #endregion Property
243
244
245         #region Method
246         /// <summary>
247         /// Set minimum frame and maximum frame
248         /// </summary>
249         /// <param name="minFrame">minimum frame.</param>
250         /// <param name="maxFrame">maximum frame.</param>
251         [EditorBrowsable(EditorBrowsableState.Never)]
252         public void SetMinAndMaxFrame(int minFrame, int maxFrame)
253         {
254             tlog.Fatal(tag, $"[AnimatedVectorImageView START[ [{GetId()}] SetMinAndMaxFrame({minFrame}, {maxFrame})");
255
256             minimumFrame = (minFrame) > 0 ? minFrame : 0;
257             maximumFrame = (maxFrame) > 0 ? maxFrame : 0;
258             isMinMaxFrameSet = minMaxSetTypes.SetByMinAndMaxFrameMethod;
259
260             if (minimumFrame >= totalFrameNum)
261             {
262                 minimumFrame = totalFrameNum - 1;
263             }
264
265             if (maximumFrame >= totalFrameNum)
266             {
267                 maximumFrame = totalFrameNum - 1;
268             }
269
270             if (minimumFrame > maximumFrame)
271             {
272                 return;
273             }
274
275             tlog.Fatal(tag, $" [{GetId()}] minimumFrame:{minimumFrame}, maximumFrame:{maximumFrame}) ]AnimatedVectorImageView END]");
276         }
277
278         /// <summary>
279         /// SetMinMaxFrame(int startFrame, int endFrame)
280         /// </summary>
281         /// <param name="minFrame"></param>
282         /// <param name="maxFrame"></param>
283         [EditorBrowsable(EditorBrowsableState.Never)]
284         public new void SetMinMaxFrame(int minFrame, int maxFrame)
285         {
286             tlog.Fatal(tag, $"SetMinMaxFrame({minFrame}, {maxFrame})!!!");
287
288             minimumFrame = (minFrame) > 0 ? minFrame : 0;
289             maximumFrame = (maxFrame) > 0 ? maxFrame : 0;
290             isMinMaxFrameSet = minMaxSetTypes.SetByBaseSetMinMaxFrameMethod;
291
292             if (minimumFrame >= totalFrameNum)
293             {
294                 minimumFrame = totalFrameNum - 1;
295             }
296
297             if (maximumFrame >= totalFrameNum)
298             {
299                 maximumFrame = totalFrameNum - 1;
300             }
301
302             base.SetMinMaxFrame(minimumFrame, maximumFrame);
303         }
304
305         /// <summary>
306         /// A marker has its start frame and end frame. 
307         /// Animation will play between the start frame and the end frame of the marker if one marker is specified.
308         /// 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.   *
309         /// </summary>
310         /// <param name="marker1">First marker</param>
311         /// <param name="marker2">Second marker</param>
312         [EditorBrowsable(EditorBrowsableState.Never)]
313         public new void SetMinMaxFrameByMarker(string marker1, string marker2 = null)
314         {
315             tlog.Fatal(tag, $"SetMinMaxFrameByMarker({marker1}, {marker2})");
316             isMinMaxFrameSet = minMaxSetTypes.SetByMarker;
317             base.SetMinMaxFrameByMarker(marker1, marker2);
318         }
319
320         /// <summary>
321         /// Play Animation.
322         /// </summary>
323         [EditorBrowsable(EditorBrowsableState.Never)]
324         public new void Play()
325         {
326             tlog.Fatal(tag, $"[AnimatedVectorImageView START[ [{GetId()}] AnimationState={AnimationState}, PlayState={PlayState}");
327
328             if (string.IsNullOrEmpty(resourceUrl))
329             {
330                 throw new InvalidOperationException("Resource Url not yet Set");
331             }
332
333             switch (isMinMaxFrameSet)
334             {
335                 case minMaxSetTypes.NotSetByUser:
336                     base.SetMinMaxFrame(0, totalFrameNum - 1);
337                     base.CurrentFrame = 0;
338                     break;
339
340                 case minMaxSetTypes.SetByMinAndMaxFrameMethod:
341                     base.SetMinMaxFrame(minimumFrame, maximumFrame);
342                     base.CurrentFrame = minimumFrame;
343                     break;
344
345                 case minMaxSetTypes.SetByMarker:
346                 case minMaxSetTypes.SetByBaseSetMinMaxFrameMethod:
347                 default:
348                     //do nothing!
349                     break;
350             }
351
352             //temporal fix
353             Extents tmp = base.Margin;
354             base.Margin = tmp;
355
356             base.Play();
357             AnimationState = AnimationStates.Playing;
358
359             tlog.Fatal(tag, $" [{GetId()}] isMinMaxFrameSet={isMinMaxFrameSet}) ]AnimatedVectorImageView END]");
360         }
361
362         /// <summary>
363         /// Pause Animation.
364         /// </summary>
365         [EditorBrowsable(EditorBrowsableState.Never)]
366         public new void Pause()
367         {
368             tlog.Fatal(tag, $"[AnimatedVectorImageView START[ [{GetId()}] AnimationState={AnimationState}, PlayState={PlayState}");
369
370             if (string.IsNullOrEmpty(resourceUrl))
371             {
372                 throw new InvalidOperationException("Resource Url not yet Set");
373             }
374
375             base.Pause();
376             AnimationState = AnimationStates.Paused;
377
378             tlog.Fatal(tag, $" [{GetId()}] ]AnimatedVectorImageView END]");
379         }
380
381         /// <summary>
382         /// Stop Animation.
383         /// </summary>
384         /// <param name="endAction">Defines, what should be behaviour after cancel operation
385         /// End action is Cancel, Animation Stops at the Current Frame.
386         /// End action is Discard, Animation Stops at the Min Frame
387         /// End action is StopFinal, Animation Stops at the Max Frame
388         /// </param>
389         [EditorBrowsable(EditorBrowsableState.Never)]
390         public void Stop(EndActions endAction = EndActions.Cancel)
391         {
392             tlog.Fatal(tag, $"[AnimatedVectorImageView START[ [{GetId()}] endAction:({endAction}), PlayState={PlayState}");
393
394             if (string.IsNullOrEmpty(resourceUrl))
395             {
396                 throw new InvalidOperationException("Resource Url not yet Set");
397             }
398
399             if (AnimationState == AnimationStates.Stopped)
400             {
401                 return;
402             }
403
404             if (innerEndAction != endAction)
405             {
406                 innerEndAction = endAction;
407                 switch (endAction)
408                 {
409                     case EndActions.Cancel:
410                         StopBehavior = StopBehaviorType.CurrentFrame;
411                         break;
412                     case EndActions.Discard:
413                         StopBehavior = StopBehaviorType.MinimumFrame;
414                         break;
415                     case EndActions.StopFinal:
416                         StopBehavior = StopBehaviorType.MaximumFrame;
417                         break;
418                     default:
419                         tlog.Fatal(tag, $" [{GetId()}] no endAction : default set");
420                         break;
421                 }
422             }
423             AnimationState = AnimationStates.Stopped;
424
425             base.Stop();
426
427             if (endAction == EndActions.StopFinal)
428             {
429                 switch (isMinMaxFrameSet)
430                 {
431                     case minMaxSetTypes.NotSetByUser:
432                         if (base.CurrentFrame != totalFrameNum - 1)
433                         {
434                             tlog.Fatal(tag, $"isMinMaxFrameSet:{isMinMaxFrameSet}, CurrentFrameNumber:{base.CurrentFrame}, totalFrameNum:{ totalFrameNum}");
435                             base.CurrentFrame = totalFrameNum - 1;
436                             tlog.Fatal(tag, $"set CurrentFrameNumber({base.CurrentFrame}) as totalFrameNum({maximumFrame}) - 1 !");
437                         }
438                         break;
439
440                     case minMaxSetTypes.SetByMinAndMaxFrameMethod:
441                         if (base.CurrentFrame != maximumFrame)
442                         {
443                             tlog.Fatal(tag, $"isMinMaxFrameSet:{isMinMaxFrameSet}, CurrentFrameNumber:{base.CurrentFrame}, maximumFrame:{ maximumFrame}");
444                             base.CurrentFrame = maximumFrame;
445                             tlog.Fatal(tag, $"set CurrentFrameNumber({base.CurrentFrame}) as maximumFrame({maximumFrame})!!!");
446                         }
447                         break;
448                     case minMaxSetTypes.SetByBaseSetMinMaxFrameMethod:
449                     case minMaxSetTypes.SetByMarker:
450                     default:
451                         //do nothing!
452                         break;
453                 }
454             }
455             tlog.Fatal(tag, $" [{GetId()}] ]AnimatedVectorImageView END]");
456         }
457         #endregion Method
458
459
460         #region Event, Enum, Struct, ETC
461         /// <summary>
462         /// RepeatMode of animation.
463         /// </summary>
464         // Suppress warning : This has been being used by users, so that the interface can not be changed.
465         [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names", Justification = "<Pending>")]
466         [EditorBrowsable(EditorBrowsableState.Never)]
467         public enum RepeatModes
468         {
469             /// <summary>
470             /// When the animation reaches the end and RepeatCount is nonZero, the animation restarts from the beginning. 
471             /// </summary>
472             [EditorBrowsable(EditorBrowsableState.Never)]
473             Restart = LoopingModeType.Restart,
474             /// <summary>
475             /// When the animation reaches the end and RepeatCount nonZero, the animation reverses direction on every animation cycle. 
476             /// </summary>
477             [EditorBrowsable(EditorBrowsableState.Never)]
478             Reverse = LoopingModeType.AutoReverse
479         }
480
481         /// <summary>
482         /// EndActions of animation.
483         /// </summary>
484         // Suppress warning : This has been being used by users, so that the interface can not be changed.
485         [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names", Justification = "<Pending>")]
486         [EditorBrowsable(EditorBrowsableState.Never)]
487         public enum EndActions
488         {
489             /// <summary> End action is Cancel, Animation Stops at the Current Frame.</summary>
490             [EditorBrowsable(EditorBrowsableState.Never)]
491             Cancel = 0,
492             /// <summary>  End action is Discard, Animation Stops at the Min Frame</summary>
493             [EditorBrowsable(EditorBrowsableState.Never)]
494             Discard = 1,
495             /// <summary> End action is StopFinal, Animation Stops at the Max Frame</summary>
496             [EditorBrowsable(EditorBrowsableState.Never)]
497             StopFinal = 2
498         }
499
500         /// <summary>
501         /// AnimationStates of animation.
502         /// </summary>
503         // Suppress warning : This has been being used by users, so that the interface can not be changed.
504         [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1717:Only FlagsAttribute enums should have plural names", Justification = "<Pending>")]
505         [EditorBrowsable(EditorBrowsableState.Never)]
506         public enum AnimationStates
507         {
508             /// <summary> The animation has stopped.</summary>
509             [EditorBrowsable(EditorBrowsableState.Never)]
510             Stopped = PlayStateType.Stopped,
511             /// <summary> The animation is playing.</summary>
512             [EditorBrowsable(EditorBrowsableState.Never)]
513             Playing = PlayStateType.Playing,
514             /// <summary> The animation is paused.</summary>
515             [EditorBrowsable(EditorBrowsableState.Never)]
516             Paused = PlayStateType.Paused
517         }
518         #endregion Event, Enum, Struct, ETC
519
520
521         #region Internal
522         #endregion Internal
523
524
525         #region Private
526         private string resourceUrl = null;
527         private int repeatCnt = 0;
528         private int totalFrameNum = 0;
529         private RepeatModes repeatMode = RepeatModes.Restart;
530         private int minimumFrame = -1, maximumFrame = -1;
531         private minMaxSetTypes isMinMaxFrameSet = minMaxSetTypes.NotSetByUser;
532         private int innerCurrentFrame = -1;
533         private EndActions innerEndAction = EndActions.Cancel;
534         private enum minMaxSetTypes
535         {
536             NotSetByUser,
537             SetByMinAndMaxFrameMethod,
538             SetByMarker,
539             SetByBaseSetMinMaxFrameMethod,
540         }
541
542         private string tag = "NUITEST";
543         private AnimationStates CurrentAnimationState = AnimationStates.Stopped;
544         #endregion Private
545     }
546 }