[NUI] Integreation from dalihub (#988)
[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             base.Play();
296             AnimationState = AnimationStates.Playing;
297
298             tlog.Fatal(tag, $" [{GetId()}] VectorAnimationView.Play(mIsMinMaxSet={mIsMinMaxSet}) >>>");
299         }
300
301         /// <summary>
302         /// Pause Animation.
303         /// </summary>
304         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
305         [EditorBrowsable(EditorBrowsableState.Never)]
306         public new void Pause()
307         {
308             tlog.Fatal(tag, $"<<< [{GetId()}] VectorAnimationView.Pause() AnimationState={AnimationState}");
309
310             if (mResourceURL == null || mResourceURL == String.Empty)
311             {
312                 throw new InvalidOperationException("Resource Url not yet Set");
313             }
314
315             base.Pause();
316             AnimationState = AnimationStates.Paused;
317
318             tlog.Fatal(tag, $" [{GetId()}] VectorAnimationView.Pause() >>>");
319         }
320
321         /// <summary>
322         /// Stop Animation.
323         /// </summary>
324         /// <param name="endAction">Defines, what should be behaviour after cancel operation
325         /// End action is Cancel, Animation Stops at the Current Frame.
326         /// End action is Discard, Animation Stops at the Min Frame
327         /// End action is StopFinal, Animation Stops at the Max Frame
328         /// </param>
329         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
330         [EditorBrowsable(EditorBrowsableState.Never)]
331         public void Stop(EndActions endAction = EndActions.Cancel)
332         {
333             tlog.Fatal(tag, $"<<< [{GetId()}] VectorAnimationView.Stop({endAction})");
334
335             if (mResourceURL == null || mResourceURL == String.Empty)
336             {
337                 throw new InvalidOperationException("Resource Url not yet Set");
338             }
339
340             if (AnimationState == AnimationStates.Stopped)
341             {
342                 return;
343             }
344
345             if (mEndAction != endAction)
346             {
347                 mEndAction = endAction;
348                 switch (endAction)
349             {
350                     case EndActions.Cancel:
351                         StopBehavior = StopBehaviorType.CurrentFrame;
352                         break;
353                     case EndActions.Discard:
354                         StopBehavior = StopBehaviorType.FirstFrame;
355                         break;
356                     case EndActions.StopFinal:
357                         StopBehavior = StopBehaviorType.LastFrame;
358                         break;
359                     default:
360                         tlog.Fatal(tag, $" [{GetId()}] no endAction : default set");
361                         break;
362             }
363             }
364             //if (endAction == EndActions.Discard)
365             //{
366             //    CurrentFrame = mMinFrame;
367             //}
368             //else if (endAction == EndActions.StopFinal)
369             //{
370             //    CurrentFrame = mMaxFrame;
371             //}
372             AnimationState = AnimationStates.Stopped;
373
374             base.Stop();
375
376             tlog.Fatal(tag, $" [{GetId()}] VectorAnimationView.Stop(endaction={endAction}) >>>");
377         }
378         #endregion Method
379
380
381         #region Event, Enum, Struct, ETC
382         /// <summary>
383         /// RepeatMode of animation.
384         /// </summary>
385         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
386         [EditorBrowsable(EditorBrowsableState.Never)]
387         public enum RepeatModes
388         {
389             /// <summary>
390             /// When the animation reaches the end and RepeatCount is nonZero, the animation restarts from the beginning. 
391             /// </summary>
392             // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
393             [EditorBrowsable(EditorBrowsableState.Never)]
394             Restart = LoopModes.Forward,
395             /// <summary>
396             /// When the animation reaches the end and RepeatCount nonZero, the animation reverses direction on every animation cycle. 
397             /// </summary>
398             // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
399             [EditorBrowsable(EditorBrowsableState.Never)]
400             Reverse = LoopModes.Backward
401         }
402
403         /// <summary>
404         /// EndActions of animation.
405         /// </summary>
406         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
407         [EditorBrowsable(EditorBrowsableState.Never)]
408         public enum EndActions
409         {
410             /// <summary> End action is Cancel, Animation Stops at the Current Frame.</summary>
411             // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
412             [EditorBrowsable(EditorBrowsableState.Never)]
413             Cancel = 0,
414             /// <summary>  End action is Discard, Animation Stops at the Min 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             Discard = 1,
418             /// <summary> End action is StopFinal, Animation Stops at the Max 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             StopFinal = 2
422         }
423
424         /// <summary>
425         /// AnimationStates of animation.
426         /// </summary>
427         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
428         [EditorBrowsable(EditorBrowsableState.Never)]
429         public enum AnimationStates
430         {
431             /// <summary> The animation has stopped.</summary>
432             // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
433             [EditorBrowsable(EditorBrowsableState.Never)]
434             Stopped = PlayStateType.Stopped,
435             /// <summary> The animation is playing.</summary>
436             // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
437             [EditorBrowsable(EditorBrowsableState.Never)]
438             Playing = PlayStateType.Playing,
439             /// <summary> The animation is paused.</summary>
440             // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
441             [EditorBrowsable(EditorBrowsableState.Never)]
442             Paused = PlayStateType.Paused
443         }
444         #endregion Event, Enum, Struct, ETC
445
446
447         #region Internal
448         #endregion Internal
449
450
451         #region Private
452         private string mResourceURL = null;
453         private int mRepeatCount = 0;
454         private int mFrameCount = 0;
455         private RepeatModes mRepeatMode = RepeatModes.Restart;
456         private int mMinFrame = -1, mMaxFrame = -1;
457         private bool mIsMinMaxSet = false;
458         private int mCurrentFrame = -1;
459         private EndActions mEndAction = EndActions.Cancel;
460
461         private string tag = "NUITEST";
462         #endregion Private
463     }
464 }