852f3575bcecf7ea3d2f44d8ca5698691e88ebd5
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / VectorAnimationView.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 #if (NUI_DEBUG_ON)
21 using tlog = Tizen.Log;
22 #endif
23
24 namespace Tizen.NUI.BaseComponents
25 {
26     /// <summary>
27     /// VectorAnimationView is a class for displaying a vector resource.
28     /// </summary>
29     // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
30     [EditorBrowsable(EditorBrowsableState.Never)]
31     public class VectorAnimationViewTBD : AnimatedVectorImageView
32     {
33         #region Constructor, Distructor, Dispose
34         /// <summary>
35         /// Construct VectorAnimationView.
36         /// </summary>
37         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
38         [EditorBrowsable(EditorBrowsableState.Never)]
39         public VectorAnimationViewTBD() : base()
40         {
41             tlog.Fatal(tag, $"<<< VectorAnimationView() constuctor objId={GetId()} >>>");
42         }
43
44         /// <summary>
45         /// Construct VectorAnimationView.
46         /// </summary>
47         /// <param name="scale">Set scaling factor for Vector Animation, while creating.</param>
48         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
49         [EditorBrowsable(EditorBrowsableState.Never)]
50         public VectorAnimationViewTBD(float scale) : base(scale)
51         {
52             tlog.Fatal(tag, $"<<< VectorAnimationView(scale={scale}) constuctor objId={GetId()}>>>");
53         }
54
55         /// <summary>
56         /// You can override it to clean-up your own resources
57         /// </summary>
58         /// <param name="type">DisposeTypes</param>
59         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
60         [EditorBrowsable(EditorBrowsableState.Never)]
61         protected override void Dispose(DisposeTypes type)
62         {
63             if (disposed)
64             {
65                 return;
66             }
67             tlog.Fatal(tag, $"<<< [{GetId()}] VectorAnimationView.Dispose(type={type})");
68
69             if (type == DisposeTypes.Explicit)
70             {
71                 //Called by User
72                 //Release your own managed resources here.
73                 //You should release all of your own disposable objects here.
74             }
75
76             //Release your own unmanaged resources here.
77             //You should not access any managed member here except static instance.
78             //because the execution order of Finalizes is non-deterministic.
79
80             base.Dispose(type);
81
82             tlog.Fatal(tag, $"[{GetId()}] VectorAnimationView.Dispose() >>>");
83         }
84         #endregion Constructor, Distructor, Dispose
85
86
87         #region Property
88         /// <summary>
89         /// Set Resource URL
90         /// </summary>
91         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
92         [EditorBrowsable(EditorBrowsableState.Never)]
93         public string ResourceURL
94         {
95             set
96             {
97                 tlog.Fatal(tag, $"<<< [{GetId()}] VectorAnimationView.ResourceURL SET");
98
99                 if (value == mResourceURL)
100                 {
101                     tlog.Fatal(tag, $"set same URL! ");
102                     return;
103                 }
104                 mResourceURL = (value == null) ? "" : value;
105                 URL = mResourceURL;
106                 mIsMinMaxSet = false;
107
108                 tlog.Fatal(tag, $" [{GetId()}] VectorAnimationView.ResourceURL SET mResourceURL={mResourceURL}) >>>");
109             }
110             get => mResourceURL;
111         }
112
113         /// <summary>
114         /// RepeatCount of animation.
115         /// The repeat count is 0 by default.
116         /// If the RepeatCount is 0, the animation is never repeated.
117         /// If the RepeatCount is greater than 0, the repeat mode will be taken into account.
118         /// If RepeatCount is -1, animation is infinite loops.
119         /// </summary>
120         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
121         [EditorBrowsable(EditorBrowsableState.Never)]
122         public int RepeatCount
123         {
124             set
125             {
126                 tlog.Fatal(tag, $"<<< [{GetId()}] VectorAnimationView.RepeatCount SET");
127
128                 mRepeatCount = (value < -1) ? -1 : value;
129                 //LoopCount = mRepeatCount;
130                 LoopCount = (mRepeatCount < 0) ? mRepeatCount : mRepeatCount + 1;
131
132                 tlog.Fatal(tag, $"[{GetId()}] VectorAnimationView.RepeatCount SET mRepeatCount={mRepeatCount} >>>");
133             }
134             get => mRepeatCount;
135         }
136
137         /// <summary>
138         /// TotalFrame of animation.
139         /// </summary>
140         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
141         [EditorBrowsable(EditorBrowsableState.Never)]
142         public int TotalFrame
143         {
144             get => TotalFrameNumber;
145         }
146
147         /// <summary>
148         /// CurrentFrame of animation.
149         /// </summary>
150         /// <returns> Returns user set value for the current frame. Cannot provide actual playing current frame. </returns>
151         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
152         [EditorBrowsable(EditorBrowsableState.Never)]
153         public int CurrentFrame
154         {
155             set
156             {
157                 tlog.Fatal(tag, $"<<< [{GetId()}] VectorAnimationView.CurrentFrame SET");
158
159                 if (mResourceURL == null || mResourceURL == String.Empty)
160                 {
161                     throw new InvalidOperationException("Resource Url not yet Set");
162                 }
163
164                 mFrameCount = TotalFrameNumber;
165
166                 if (value < 0)
167                 {
168                     value = 0;
169                 }
170                 else if (value >= mFrameCount)
171                 {
172                     value = mFrameCount - 1;
173                 }
174
175                 mCurrentFrame = value;
176                 AnimationState = AnimationStates.Paused;
177
178                 SetPlayRange(mCurrentFrame, mCurrentFrame);
179                 CurrentFrameNumber = mCurrentFrame;
180
181                 tlog.Fatal(tag, $" [{GetId()}] VectorAnimationView.CurrentFrame SET mCurrentFrame={mCurrentFrame}) >>>");
182             }
183             get => mCurrentFrame;
184         }
185
186         /// <summary>
187         /// RepeatMode of animation.
188         /// </summary>
189         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
190         [EditorBrowsable(EditorBrowsableState.Never)]
191         public RepeatModes RepeatMode
192         {
193             set
194             {
195                 tlog.Fatal(tag, $"<<< [{GetId()}] VectorAnimationView.RepeatMode SET");
196                 mRepeatMode = value;
197
198                 switch (mRepeatMode)
199                 {
200                     case RepeatModes.Restart:
201                         LoopMode = LoopingModeType.Restart;
202                         break;
203                     case RepeatModes.Reverse:
204                         LoopMode = LoopingModeType.AutoReverse;
205                         break;
206                     default:
207                         LoopMode = LoopingModeType.Restart;
208                         break;
209                 }
210
211                 tlog.Fatal(tag, $" [{GetId()}] VectorAnimationView.RepeatMode SET mRepeatMode={mRepeatMode}) >>>");
212             }
213             get => mRepeatMode;
214         }
215
216         /// <summary>
217         /// Get state of animation.
218         /// </summary>
219         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
220         [EditorBrowsable(EditorBrowsableState.Never)]
221         public AnimationStates AnimationState
222         {
223             private set;
224             get;
225         }
226         #endregion Property
227
228
229         #region Method
230         /// <summary>
231         /// Set minimum frame and maximum frame
232         /// </summary>
233         /// <param name="minFrame">minimum frame.</param>
234         /// <param name="maxFrame">maximum frame.</param>
235         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
236         [EditorBrowsable(EditorBrowsableState.Never)]
237         public void SetMinAndMaxFrame(int minFrame, int maxFrame)
238         {
239             tlog.Fatal(tag, $"<<< [{GetId()}] VectorAnimationView.SetMinAndMaxFrame({minFrame}, {maxFrame})");
240
241             mMinFrame = (minFrame) > 0 ? minFrame : 0;
242             mMaxFrame = (maxFrame) > 0 ? maxFrame : 0;
243             mIsMinMaxSet = true;
244             mFrameCount = TotalFrameNumber;
245
246             if (mMinFrame >= mFrameCount)
247             {
248                 mMinFrame = mFrameCount - 1;
249             }
250
251             if (mMaxFrame >= mFrameCount)
252             {
253                 mMaxFrame = mFrameCount - 1;
254             }
255
256             if (mMinFrame > mMaxFrame)
257             {
258                 return;
259             }
260
261             base.Stop();
262             SetPlayRange(mMinFrame, mMaxFrame);
263             CurrentFrameNumber = mMinFrame;
264
265             tlog.Fatal(tag, $" [{GetId()}] VectorAnimationView.SetMinAndMaxFrame(m: {mMinFrame}, {mMaxFrame}) >>>");
266         }
267
268         /// <summary>
269         /// Play Animation.
270         /// </summary>
271         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
272         [EditorBrowsable(EditorBrowsableState.Never)]
273         public new void Play()
274         {
275             tlog.Fatal(tag, $"<<< [{GetId()}] VectorAnimationView.Play()");
276
277             if (mResourceURL == null || mResourceURL == String.Empty)
278             {
279                 throw new InvalidOperationException("Resource Url not yet Set");
280             }
281
282             if (mIsMinMaxSet)
283             {
284                 //if(mRepeatCount > 0 )
285                 //{
286                 //    StopBehavior = StopBehaviorType.FirstFrame;
287                 //}
288                 SetPlayRange(mMinFrame, mMaxFrame);
289             }
290             else
291             {
292                 SetPlayRange(0, TotalFrameNumber - 1);
293             }
294
295             //temporal fix
296             Extents tmp = base.Margin;
297             base.Margin = tmp;
298
299             base.Play();
300             AnimationState = AnimationStates.Playing;
301
302             tlog.Fatal(tag, $" [{GetId()}] VectorAnimationView.Play(mIsMinMaxSet={mIsMinMaxSet}) >>>");
303         }
304
305         /// <summary>
306         /// Pause Animation.
307         /// </summary>
308         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
309         [EditorBrowsable(EditorBrowsableState.Never)]
310         public new void Pause()
311         {
312             tlog.Fatal(tag, $"<<< [{GetId()}] VectorAnimationView.Pause() AnimationState={AnimationState}");
313
314             if (mResourceURL == null || mResourceURL == String.Empty)
315             {
316                 throw new InvalidOperationException("Resource Url not yet Set");
317             }
318
319             base.Pause();
320             AnimationState = AnimationStates.Paused;
321
322             tlog.Fatal(tag, $" [{GetId()}] VectorAnimationView.Pause() >>>");
323         }
324
325         /// <summary>
326         /// Stop Animation.
327         /// </summary>
328         /// <param name="endAction">Defines, what should be behaviour after cancel operation
329         /// End action is Cancel, Animation Stops at the Current Frame.
330         /// End action is Discard, Animation Stops at the Min Frame
331         /// End action is StopFinal, Animation Stops at the Max Frame
332         /// </param>
333         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
334         [EditorBrowsable(EditorBrowsableState.Never)]
335         public void Stop(EndActions endAction = EndActions.Cancel)
336         {
337             tlog.Fatal(tag, $"<<< [{GetId()}] VectorAnimationView.Stop({endAction})");
338
339             if (mResourceURL == null || mResourceURL == String.Empty)
340             {
341                 throw new InvalidOperationException("Resource Url not yet Set");
342             }
343
344             if (AnimationState == AnimationStates.Stopped)
345             {
346                 return;
347             }
348
349             if (mEndAction != endAction)
350             {
351                 mEndAction = endAction;
352                 switch (endAction)
353             {
354                     case EndActions.Cancel:
355                         StopBehavior = StopBehaviorType.CurrentFrame;
356                         break;
357                     case EndActions.Discard:
358                         StopBehavior = StopBehaviorType.FirstFrame;
359                         break;
360                     case EndActions.StopFinal:
361                         StopBehavior = StopBehaviorType.LastFrame;
362                         break;
363                     default:
364                         tlog.Fatal(tag, $" [{GetId()}] no endAction : default set");
365                         break;
366             }
367             }
368             //if (endAction == EndActions.Discard)
369             //{
370             //    CurrentFrame = mMinFrame;
371             //}
372             //else if (endAction == EndActions.StopFinal)
373             //{
374             //    CurrentFrame = mMaxFrame;
375             //}
376             AnimationState = AnimationStates.Stopped;
377
378             base.Stop();
379
380             tlog.Fatal(tag, $" [{GetId()}] VectorAnimationView.Stop(endaction={endAction}) >>>");
381         }
382         #endregion Method
383
384
385         #region Event, Enum, Struct, ETC
386         /// <summary>
387         /// RepeatMode of animation.
388         /// </summary>
389         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
390         [EditorBrowsable(EditorBrowsableState.Never)]
391         public enum RepeatModes
392         {
393             /// <summary>
394             /// When the animation reaches the end and RepeatCount is nonZero, the animation restarts from the beginning. 
395             /// </summary>
396             // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
397             [EditorBrowsable(EditorBrowsableState.Never)]
398             Restart = LoopModes.Forward,
399             /// <summary>
400             /// When the animation reaches the end and RepeatCount nonZero, the animation reverses direction on every animation cycle. 
401             /// </summary>
402             // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
403             [EditorBrowsable(EditorBrowsableState.Never)]
404             Reverse = LoopModes.Backward
405         }
406
407         /// <summary>
408         /// EndActions of animation.
409         /// </summary>
410         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
411         [EditorBrowsable(EditorBrowsableState.Never)]
412         public enum EndActions
413         {
414             /// <summary> End action is Cancel, Animation Stops at the Current Frame.</summary>
415             // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
416             [EditorBrowsable(EditorBrowsableState.Never)]
417             Cancel = 0,
418             /// <summary>  End action is Discard, Animation Stops at the Min Frame</summary>
419             // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
420             [EditorBrowsable(EditorBrowsableState.Never)]
421             Discard = 1,
422             /// <summary> End action is StopFinal, Animation Stops at the Max Frame</summary>
423             // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
424             [EditorBrowsable(EditorBrowsableState.Never)]
425             StopFinal = 2
426         }
427
428         /// <summary>
429         /// AnimationStates of animation.
430         /// </summary>
431         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
432         [EditorBrowsable(EditorBrowsableState.Never)]
433         public enum AnimationStates
434         {
435             /// <summary> The animation has stopped.</summary>
436             // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
437             [EditorBrowsable(EditorBrowsableState.Never)]
438             Stopped = PlayStateType.Stopped,
439             /// <summary> The animation is playing.</summary>
440             // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
441             [EditorBrowsable(EditorBrowsableState.Never)]
442             Playing = PlayStateType.Playing,
443             /// <summary> The animation is paused.</summary>
444             // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
445             [EditorBrowsable(EditorBrowsableState.Never)]
446             Paused = PlayStateType.Paused
447         }
448         #endregion Event, Enum, Struct, ETC
449
450
451         #region Internal
452         #endregion Internal
453
454
455         #region Private
456         private string mResourceURL = null;
457         private int mRepeatCount = 0;
458         private int mFrameCount = 0;
459         private RepeatModes mRepeatMode = RepeatModes.Restart;
460         private int mMinFrame = -1, mMaxFrame = -1;
461         private bool mIsMinMaxSet = false;
462         private int mCurrentFrame = -1;
463         private EndActions mEndAction = EndActions.Cancel;
464
465         private string tag = "NUITEST";
466         #endregion Private
467     }
468 }