|
@@ -8,6 +8,8 @@ using System.Reactive.Linq;
|
|
|
using Avalonia.Collections;
|
|
using Avalonia.Collections;
|
|
|
using Avalonia.Animation.Transitions;
|
|
using Avalonia.Animation.Transitions;
|
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
|
|
+using System.Threading;
|
|
|
|
|
+using System.Collections.Concurrent;
|
|
|
|
|
|
|
|
namespace Avalonia.Animation
|
|
namespace Avalonia.Animation
|
|
|
{
|
|
{
|
|
@@ -22,29 +24,69 @@ namespace Avalonia.Animation
|
|
|
public Animatable()
|
|
public Animatable()
|
|
|
{
|
|
{
|
|
|
Transitions = new Transitions.Transitions();
|
|
Transitions = new Transitions.Transitions();
|
|
|
|
|
+ AnimatableTimer = Timing.AnimationStateTimer
|
|
|
|
|
+ .Select(p =>
|
|
|
|
|
+ {
|
|
|
|
|
+ if (p == PlayState.Run
|
|
|
|
|
+ && this._playState == PlayState.Run)
|
|
|
|
|
+ return _animationTime++;
|
|
|
|
|
+ else
|
|
|
|
|
+ return _animationTime;
|
|
|
|
|
+ })
|
|
|
|
|
+ .Publish()
|
|
|
|
|
+ .RefCount();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
- /// Defines the <see cref="AnimationPlayState"/> property.
|
|
|
|
|
|
|
+ /// The specific animations timer for this control.
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
- public static readonly DirectProperty<Animatable, PlayState> AnimationPlayStateProperty =
|
|
|
|
|
|
|
+ /// <returns></returns>
|
|
|
|
|
+ public IObservable<ulong> AnimatableTimer;
|
|
|
|
|
+
|
|
|
|
|
+ internal void PrepareAnimatableForAnimation()
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!_animationsInitialized)
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ _animationsInitialized = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ bool _animationsInitialized = false;
|
|
|
|
|
+
|
|
|
|
|
+ // internal ConcurrentDictionary<int, (int repeatCount, int direction)> _animationStates;
|
|
|
|
|
+
|
|
|
|
|
+ internal ulong _animationTime;
|
|
|
|
|
+
|
|
|
|
|
+ // internal int _iterationTokenCounter;
|
|
|
|
|
+
|
|
|
|
|
+ // internal uint GetIterationToken()
|
|
|
|
|
+ // {
|
|
|
|
|
+ // return (uint)Interlocked.Increment(ref _iterationTokenCounter);
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// Defines the <see cref="PlayState"/> property.
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ public static readonly DirectProperty<Animatable, PlayState> PlayStateProperty =
|
|
|
AvaloniaProperty.RegisterDirect<Animatable, PlayState>(
|
|
AvaloniaProperty.RegisterDirect<Animatable, PlayState>(
|
|
|
- nameof(AnimationPlayState),
|
|
|
|
|
- o => o.AnimationPlayState,
|
|
|
|
|
- (o, v) => o.AnimationPlayState = v);
|
|
|
|
|
|
|
+ nameof(PlayState),
|
|
|
|
|
+ o => o.PlayState,
|
|
|
|
|
+ (o, v) => o.PlayState = v);
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// Gets or sets the state of the animation for this
|
|
/// Gets or sets the state of the animation for this
|
|
|
/// control.
|
|
/// control.
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
- public PlayState AnimationPlayState
|
|
|
|
|
- {
|
|
|
|
|
- get { return _animationPlayState; }
|
|
|
|
|
- set { SetAndRaise(AnimationPlayStateProperty, ref _animationPlayState, value); }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ public PlayState PlayState
|
|
|
|
|
+ {
|
|
|
|
|
+ get { return _playState; }
|
|
|
|
|
+ set { SetAndRaise(PlayStateProperty, ref _playState, value); }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private PlayState _animationPlayState;
|
|
|
|
|
|
|
+ private PlayState _playState = PlayState.Run;
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// Defines the <see cref="Transitions"/> property.
|
|
/// Defines the <see cref="Transitions"/> property.
|