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