2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 using System.ComponentModel;
21 using tlog = Tizen.Log;
24 namespace Tizen.NUI.BaseComponents
27 /// VectorAnimationView is a class for displaying a vector resource.
29 // InhouseAPI (HiddenAPI)
30 [EditorBrowsable(EditorBrowsableState.Never)]
31 public class VectorAnimationView : AnimatedVectorImageView
33 #region Constructor, Distructor, Dispose
35 /// Construct VectorAnimationView.
37 // InhouseAPI (HiddenAPI)
38 [EditorBrowsable(EditorBrowsableState.Never)]
39 public VectorAnimationView() : base()
41 tlog.Fatal(tag, $"VectorAnimationView() constuctor objId={GetId()} ");
45 /// Construct VectorAnimationView.
47 /// <param name="scale">Set scaling factor for Vector Animation, while creating.</param>
48 // InhouseAPI (HiddenAPI)
49 [EditorBrowsable(EditorBrowsableState.Never)]
50 public VectorAnimationView(float scale) : base(scale)
52 tlog.Fatal(tag, $"VectorAnimationView(scale={scale}) constuctor objId={GetId()}");
56 /// You can override it to clean-up your own resources
58 /// <param name="type">DisposeTypes</param>
59 // InhouseAPI (HiddenAPI)
60 [EditorBrowsable(EditorBrowsableState.Never)]
61 protected override void Dispose(DisposeTypes type)
67 tlog.Fatal(tag, $"[{GetId()}] VectorAnimationView.Dispose(type={type})");
69 if (type == DisposeTypes.Explicit)
72 //Release your own managed resources here.
73 //You should release all of your own disposable objects here.
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.
82 tlog.Fatal(tag, $"[{GetId()}] VectorAnimationView.Dispose() ");
84 #endregion Constructor, Distructor, Dispose
91 // InhouseAPI (HiddenAPI)
92 [EditorBrowsable(EditorBrowsableState.Never)]
93 public string ResourceURL
97 tlog.Fatal(tag, $"[{GetId()}] VectorAnimationView.ResourceURL SET");
99 if (value == mResourceURL)
101 tlog.Fatal(tag, $"set same URL! ");
104 mResourceURL = (value == null) ? "" : value;
106 mIsMinMaxSet = false;
108 tlog.Fatal(tag, $" [{GetId()}] VectorAnimationView.ResourceURL SET mResourceURL={mResourceURL}) ");
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.
120 // InhouseAPI (HiddenAPI)
121 [EditorBrowsable(EditorBrowsableState.Never)]
122 public int RepeatCount
126 tlog.Fatal(tag, $"[{GetId()}] VectorAnimationView.RepeatCount SET");
128 mRepeatCount = (value < -1) ? -1 : value;
129 //LoopCount = mRepeatCount;
130 LoopCount = (mRepeatCount < 0) ? mRepeatCount : mRepeatCount + 1;
132 tlog.Fatal(tag, $"[{GetId()}] VectorAnimationView.RepeatCount SET mRepeatCount={mRepeatCount} ");
138 /// TotalFrame of animation.
140 // InhouseAPI (HiddenAPI)
141 [EditorBrowsable(EditorBrowsableState.Never)]
142 public int TotalFrame
144 get => TotalFrameNumber;
148 /// CurrentFrame of animation.
150 /// <returns> Returns user set value for the current frame. Cannot provide actual playing current frame. </returns>
151 // InhouseAPI (HiddenAPI)
152 [EditorBrowsable(EditorBrowsableState.Never)]
153 public int CurrentFrame
157 tlog.Fatal(tag, $"[{GetId()}] VectorAnimationView.CurrentFrame SET");
159 if (mResourceURL == null || mResourceURL == String.Empty)
161 throw new InvalidOperationException("Resource Url not yet Set");
164 mFrameCount = TotalFrameNumber;
170 else if (value >= mFrameCount)
172 value = mFrameCount - 1;
175 mCurrentFrame = value;
176 AnimationState = AnimationStates.Paused;
178 SetPlayRange(mCurrentFrame, mCurrentFrame);
179 CurrentFrameNumber = mCurrentFrame;
181 tlog.Fatal(tag, $" [{GetId()}] VectorAnimationView.CurrentFrame SET mCurrentFrame={mCurrentFrame}) ");
183 get => mCurrentFrame;
187 /// RepeatMode of animation.
189 // InhouseAPI (HiddenAPI)
190 [EditorBrowsable(EditorBrowsableState.Never)]
191 public RepeatModes RepeatMode
195 tlog.Fatal(tag, $"[{GetId()}] VectorAnimationView.RepeatMode SET");
200 case RepeatModes.Restart:
201 LoopMode = LoopingModeType.Restart;
203 case RepeatModes.Reverse:
204 LoopMode = LoopingModeType.AutoReverse;
207 LoopMode = LoopingModeType.Restart;
211 tlog.Fatal(tag, $" [{GetId()}] VectorAnimationView.RepeatMode SET mRepeatMode={mRepeatMode}) ");
217 /// Get state of animation.
219 // InhouseAPI (HiddenAPI)
220 [EditorBrowsable(EditorBrowsableState.Never)]
221 public AnimationStates AnimationState
231 /// Set minimum frame and maximum frame
233 /// <param name="minFrame">minimum frame.</param>
234 /// <param name="maxFrame">maximum frame.</param>
235 // InhouseAPI (HiddenAPI)
236 [EditorBrowsable(EditorBrowsableState.Never)]
237 public void SetMinAndMaxFrame(int minFrame, int maxFrame)
239 tlog.Fatal(tag, $"[{GetId()}] VectorAnimationView.SetMinAndMaxFrame({minFrame}, {maxFrame})");
241 mMinFrame = (minFrame) > 0 ? minFrame : 0;
242 mMaxFrame = (maxFrame) > 0 ? maxFrame : 0;
244 mFrameCount = TotalFrameNumber;
246 if (mMinFrame >= mFrameCount)
248 mMinFrame = mFrameCount - 1;
251 if (mMaxFrame >= mFrameCount)
253 mMaxFrame = mFrameCount - 1;
256 if (mMinFrame > mMaxFrame)
262 SetPlayRange(mMinFrame, mMaxFrame);
263 CurrentFrameNumber = mMinFrame;
265 tlog.Fatal(tag, $" [{GetId()}] VectorAnimationView.SetMinAndMaxFrame(m: {mMinFrame}, {mMaxFrame}) ");
271 // InhouseAPI (HiddenAPI)
272 [EditorBrowsable(EditorBrowsableState.Never)]
273 public new void Play()
275 tlog.Fatal(tag, $"[{GetId()}] VectorAnimationView.Play()");
277 if (mResourceURL == null || mResourceURL == String.Empty)
279 throw new InvalidOperationException("Resource Url not yet Set");
284 //if(mRepeatCount > 0 )
286 // StopBehavior = StopBehaviorType.FirstFrame;
288 SetPlayRange(mMinFrame, mMaxFrame);
292 //SetPlayRange(0, TotalFrameNumber - 1);
296 AnimationState = AnimationStates.Playing;
298 tlog.Fatal(tag, $" [{GetId()}] VectorAnimationView.Play(mIsMinMaxSet={mIsMinMaxSet}) ");
304 // InhouseAPI (HiddenAPI)
305 [EditorBrowsable(EditorBrowsableState.Never)]
306 public new void Pause()
308 tlog.Fatal(tag, $"[{GetId()}] VectorAnimationView.Pause() AnimationState={AnimationState}");
310 if (mResourceURL == null || mResourceURL == String.Empty)
312 throw new InvalidOperationException("Resource Url not yet Set");
316 AnimationState = AnimationStates.Paused;
318 tlog.Fatal(tag, $" [{GetId()}] VectorAnimationView.Pause() ");
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
329 // InhouseAPI (HiddenAPI)
330 [EditorBrowsable(EditorBrowsableState.Never)]
331 public void Stop(EndActions endAction = EndActions.Cancel)
333 tlog.Fatal(tag, $"[{GetId()}] VectorAnimationView.Stop({endAction})");
335 if (mResourceURL == null || mResourceURL == String.Empty)
337 throw new InvalidOperationException("Resource Url not yet Set");
340 if (AnimationState == AnimationStates.Stopped)
345 if (mEndAction != endAction)
347 mEndAction = endAction;
350 case EndActions.Cancel:
351 StopBehavior = StopBehaviorType.CurrentFrame;
353 case EndActions.Discard:
354 StopBehavior = StopBehaviorType.FirstFrame;
356 case EndActions.StopFinal:
357 StopBehavior = StopBehaviorType.LastFrame;
360 tlog.Fatal(tag, $" [{GetId()}] no endAction : default set");
364 //if (endAction == EndActions.Discard)
366 // CurrentFrame = mMinFrame;
368 //else if (endAction == EndActions.StopFinal)
370 // CurrentFrame = mMaxFrame;
372 AnimationState = AnimationStates.Stopped;
376 tlog.Fatal(tag, $" [{GetId()}] VectorAnimationView.Stop(endaction={endAction}) ");
381 #region Event, Enum, Struct, ETC
383 /// RepeatMode of animation.
385 // InhouseAPI (HiddenAPI)
386 [EditorBrowsable(EditorBrowsableState.Never)]
387 public enum RepeatModes
390 /// When the animation reaches the end and RepeatCount is nonZero, the animation restarts from the beginning.
392 // InhouseAPI (HiddenAPI)
393 [EditorBrowsable(EditorBrowsableState.Never)]
394 Restart = LoopModes.Forward,
396 /// When the animation reaches the end and RepeatCount nonZero, the animation reverses direction on every animation cycle.
398 // InhouseAPI (HiddenAPI)
399 [EditorBrowsable(EditorBrowsableState.Never)]
400 Reverse = LoopModes.Backward
404 /// EndActions of animation.
406 // InhouseAPI (HiddenAPI)
407 [EditorBrowsable(EditorBrowsableState.Never)]
408 public enum EndActions
410 /// <summary> End action is Cancel, Animation Stops at the Current Frame.</summary>
411 // InhouseAPI (HiddenAPI)
412 [EditorBrowsable(EditorBrowsableState.Never)]
414 /// <summary> End action is Discard, Animation Stops at the Min Frame</summary>
415 // InhouseAPI (HiddenAPI)
416 [EditorBrowsable(EditorBrowsableState.Never)]
418 /// <summary> End action is StopFinal, Animation Stops at the Max Frame</summary>
419 // InhouseAPI (HiddenAPI)
420 [EditorBrowsable(EditorBrowsableState.Never)]
425 /// AnimationStates of animation.
427 // InhouseAPI (HiddenAPI)
428 [EditorBrowsable(EditorBrowsableState.Never)]
429 public enum AnimationStates
431 /// <summary> The animation has stopped.</summary>
432 // InhouseAPI (HiddenAPI)
433 [EditorBrowsable(EditorBrowsableState.Never)]
434 Stopped = PlayStateType.Stopped,
435 /// <summary> The animation is playing.</summary>
436 // InhouseAPI (HiddenAPI)
437 [EditorBrowsable(EditorBrowsableState.Never)]
438 Playing = PlayStateType.Playing,
439 /// <summary> The animation is paused.</summary>
440 // InhouseAPI (HiddenAPI)
441 [EditorBrowsable(EditorBrowsableState.Never)]
442 Paused = PlayStateType.Paused
444 #endregion Event, Enum, Struct, ETC
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;
461 private string tag = "NUITEST";