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 // 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
33 #region Constructor, Distructor, Dispose
35 /// Construct VectorAnimationView.
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()
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 // 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)
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 // 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)
67 tlog.Fatal(tag, $"<<< [{GetId()}] VectorAnimationView.Dispose(type={type})");
69 //Release your own unmanaged resources here.
70 //You should not access any managed member here except static instance.
71 //because the execution order of Finalizes is non-deterministic.
75 tlog.Fatal(tag, $"[{GetId()}] VectorAnimationView.Dispose() >>>");
77 #endregion Constructor, Distructor, Dispose
84 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
85 [EditorBrowsable(EditorBrowsableState.Never)]
86 public string ResourceURL
90 tlog.Fatal(tag, $"<<< [{GetId()}] VectorAnimationView.ResourceURL SET");
92 if (value == mResourceURL)
94 tlog.Fatal(tag, $"set same URL! ");
97 mResourceURL = (value == null) ? "" : value;
101 tlog.Fatal(tag, $" [{GetId()}] VectorAnimationView.ResourceURL SET mResourceURL={mResourceURL}) >>>");
107 /// RepeatCount of animation.
108 /// The repeat count is 0 by default.
109 /// If the RepeatCount is 0, the animation is never repeated.
110 /// If the RepeatCount is greater than 0, the repeat mode will be taken into account.
111 /// If RepeatCount is -1, animation is infinite loops.
113 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
114 [EditorBrowsable(EditorBrowsableState.Never)]
115 public int RepeatCount
119 tlog.Fatal(tag, $"<<< [{GetId()}] VectorAnimationView.RepeatCount SET");
121 mRepeatCount = (value < -1) ? -1 : value;
122 //LoopCount = mRepeatCount;
123 LoopCount = (mRepeatCount < 0) ? mRepeatCount : mRepeatCount + 1;
125 tlog.Fatal(tag, $"[{GetId()}] VectorAnimationView.RepeatCount SET mRepeatCount={mRepeatCount} >>>");
131 /// TotalFrame of animation.
133 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
134 [EditorBrowsable(EditorBrowsableState.Never)]
135 public int TotalFrame
137 get => TotalFrameNumber;
141 /// CurrentFrame of animation.
143 /// <returns> Returns user set value for the current frame. Cannot provide actual playing current frame. </returns>
144 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
145 [EditorBrowsable(EditorBrowsableState.Never)]
146 public int CurrentFrame
150 tlog.Fatal(tag, $"<<< [{GetId()}] VectorAnimationView.CurrentFrame SET");
152 if (mResourceURL == null || mResourceURL == String.Empty)
154 throw new InvalidOperationException("Resource Url not yet Set");
157 mFrameCount = TotalFrameNumber;
163 else if (value >= mFrameCount)
165 value = mFrameCount - 1;
168 mCurrentFrame = value;
169 AnimationState = AnimationStates.Paused;
171 SetPlayRange(mCurrentFrame, mCurrentFrame);
172 CurrentFrameNumber = mCurrentFrame;
174 tlog.Fatal(tag, $" [{GetId()}] VectorAnimationView.CurrentFrame SET mCurrentFrame={mCurrentFrame}) >>>");
176 get => mCurrentFrame;
180 /// RepeatMode of animation.
182 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
183 [EditorBrowsable(EditorBrowsableState.Never)]
184 public RepeatModes RepeatMode
188 tlog.Fatal(tag, $"<<< [{GetId()}] VectorAnimationView.RepeatMode SET");
193 case RepeatModes.Restart:
194 LoopMode = LoopingModeType.Restart;
196 case RepeatModes.Reverse:
197 LoopMode = LoopingModeType.AutoReverse;
200 LoopMode = LoopingModeType.Restart;
204 tlog.Fatal(tag, $" [{GetId()}] VectorAnimationView.RepeatMode SET mRepeatMode={mRepeatMode}) >>>");
210 /// Get state of animation.
212 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
213 [EditorBrowsable(EditorBrowsableState.Never)]
214 public AnimationStates AnimationState
224 /// Set minimum frame and maximum frame
226 /// <param name="minFrame">minimum frame.</param>
227 /// <param name="maxFrame">maximum frame.</param>
228 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
229 [EditorBrowsable(EditorBrowsableState.Never)]
230 public void SetMinAndMaxFrame(int minFrame, int maxFrame)
232 tlog.Fatal(tag, $"<<< [{GetId()}] VectorAnimationView.SetMinAndMaxFrame({minFrame}, {maxFrame})");
234 mMinFrame = (minFrame) > 0 ? minFrame : 0;
235 mMaxFrame = (maxFrame) > 0 ? maxFrame : 0;
237 mFrameCount = TotalFrameNumber;
239 if (mMinFrame >= mFrameCount)
241 mMinFrame = mFrameCount - 1;
244 if (mMaxFrame >= mFrameCount)
246 mMaxFrame = mFrameCount - 1;
249 if (mMinFrame > mMaxFrame)
255 SetPlayRange(mMinFrame, mMaxFrame);
256 CurrentFrameNumber = mMinFrame;
258 tlog.Fatal(tag, $" [{GetId()}] VectorAnimationView.SetMinAndMaxFrame(m: {mMinFrame}, {mMaxFrame}) >>>");
264 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
265 [EditorBrowsable(EditorBrowsableState.Never)]
266 public new void Play()
268 tlog.Fatal(tag, $"<<< [{GetId()}] VectorAnimationView.Play()");
270 if (mResourceURL == null || mResourceURL == String.Empty)
272 throw new InvalidOperationException("Resource Url not yet Set");
277 //if(mRepeatCount > 0 )
279 // StopBehavior = StopBehaviorType.FirstFrame;
281 SetPlayRange(mMinFrame, mMaxFrame);
285 SetPlayRange(0, TotalFrameNumber - 1);
289 Extents tmp = base.Margin;
293 AnimationState = AnimationStates.Playing;
295 tlog.Fatal(tag, $" [{GetId()}] VectorAnimationView.Play(mIsMinMaxSet={mIsMinMaxSet}) >>>");
301 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
302 [EditorBrowsable(EditorBrowsableState.Never)]
303 public new void Pause()
305 tlog.Fatal(tag, $"<<< [{GetId()}] VectorAnimationView.Pause() AnimationState={AnimationState}");
307 if (mResourceURL == null || mResourceURL == String.Empty)
309 throw new InvalidOperationException("Resource Url not yet Set");
313 AnimationState = AnimationStates.Paused;
315 tlog.Fatal(tag, $" [{GetId()}] VectorAnimationView.Pause() >>>");
321 /// <param name="endAction">Defines, what should be behaviour after cancel operation
322 /// End action is Cancel, Animation Stops at the Current Frame.
323 /// End action is Discard, Animation Stops at the Min Frame
324 /// End action is StopFinal, Animation Stops at the Max Frame
326 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
327 [EditorBrowsable(EditorBrowsableState.Never)]
328 public void Stop(EndActions endAction = EndActions.Cancel)
330 tlog.Fatal(tag, $"<<< [{GetId()}] VectorAnimationView.Stop({endAction})");
332 if (mResourceURL == null || mResourceURL == String.Empty)
334 throw new InvalidOperationException("Resource Url not yet Set");
337 if (AnimationState == AnimationStates.Stopped)
342 if (mEndAction != endAction)
344 mEndAction = endAction;
347 case EndActions.Cancel:
348 StopBehavior = StopBehaviorType.CurrentFrame;
350 case EndActions.Discard:
351 StopBehavior = StopBehaviorType.FirstFrame;
353 case EndActions.StopFinal:
354 StopBehavior = StopBehaviorType.LastFrame;
357 tlog.Fatal(tag, $" [{GetId()}] no endAction : default set");
361 //if (endAction == EndActions.Discard)
363 // CurrentFrame = mMinFrame;
365 //else if (endAction == EndActions.StopFinal)
367 // CurrentFrame = mMaxFrame;
369 AnimationState = AnimationStates.Stopped;
373 tlog.Fatal(tag, $" [{GetId()}] VectorAnimationView.Stop(endaction={endAction}) >>>");
378 #region Event, Enum, Struct, ETC
380 /// RepeatMode of animation.
382 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
383 [EditorBrowsable(EditorBrowsableState.Never)]
384 public enum RepeatModes
387 /// When the animation reaches the end and RepeatCount is nonZero, the animation restarts from the beginning.
389 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
390 [EditorBrowsable(EditorBrowsableState.Never)]
391 Restart = LoopModes.Forward,
393 /// When the animation reaches the end and RepeatCount nonZero, the animation reverses direction on every animation cycle.
395 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
396 [EditorBrowsable(EditorBrowsableState.Never)]
397 Reverse = LoopModes.Backward
401 /// EndActions of animation.
403 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
404 [EditorBrowsable(EditorBrowsableState.Never)]
405 public enum EndActions
407 /// <summary> End action is Cancel, Animation Stops at the Current Frame.</summary>
408 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
409 [EditorBrowsable(EditorBrowsableState.Never)]
411 /// <summary> End action is Discard, Animation Stops at the Min Frame</summary>
412 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
413 [EditorBrowsable(EditorBrowsableState.Never)]
415 /// <summary> End action is StopFinal, Animation Stops at the Max Frame</summary>
416 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
417 [EditorBrowsable(EditorBrowsableState.Never)]
422 /// AnimationStates of animation.
424 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
425 [EditorBrowsable(EditorBrowsableState.Never)]
426 public enum AnimationStates
428 /// <summary> The animation has stopped.</summary>
429 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
430 [EditorBrowsable(EditorBrowsableState.Never)]
431 Stopped = PlayStateType.Stopped,
432 /// <summary> The animation is playing.</summary>
433 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
434 [EditorBrowsable(EditorBrowsableState.Never)]
435 Playing = PlayStateType.Playing,
436 /// <summary> The animation is paused.</summary>
437 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
438 [EditorBrowsable(EditorBrowsableState.Never)]
439 Paused = PlayStateType.Paused
441 #endregion Event, Enum, Struct, ETC
449 private string mResourceURL = null;
450 private int mRepeatCount = 0;
451 private int mFrameCount = 0;
452 private RepeatModes mRepeatMode = RepeatModes.Restart;
453 private int mMinFrame = -1, mMaxFrame = -1;
454 private bool mIsMinMaxSet = false;
455 private int mCurrentFrame = -1;
456 private EndActions mEndAction = EndActions.Cancel;
458 private string tag = "NUITEST";