-
Notifications
You must be signed in to change notification settings - Fork 750
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18968 from ramezgerges/skia_coloranimations
fix(skia): support color animations
- Loading branch information
Showing
7 changed files
with
58 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/Uno.UI/UI/Xaml/Media/Animation/Animators/DispatcherColorAnimator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using Windows.UI; | ||
|
||
namespace Microsoft.UI.Xaml.Media.Animation | ||
{ | ||
internal sealed class DispatcherColorAnimator(ColorOffset from, ColorOffset to, int frameRate = DispatcherAnimator<ConsoleColor>.DefaultFrameRate) | ||
: DispatcherAnimator<ColorOffset>(from, to, frameRate) | ||
{ | ||
protected override ColorOffset GetUpdatedValue(long frame, ColorOffset from, ColorOffset to) => | ||
ColorOffset.FromArgb( | ||
(int)Math.Round(_easing.Ease(frame, from.A, to.A, Duration)), | ||
(int)Math.Round(_easing.Ease(frame, from.R, to.R, Duration)), | ||
(int)Math.Round(_easing.Ease(frame, from.G, to.G, Duration)), | ||
(int)Math.Round(_easing.Ease(frame, from.B, to.B, Duration))); | ||
} | ||
} |
27 changes: 3 additions & 24 deletions
27
src/Uno.UI/UI/Xaml/Media/Animation/Animators/DispatcherDoubleAnimator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,8 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace Microsoft.UI.Xaml.Media.Animation | ||
namespace Microsoft.UI.Xaml.Media.Animation | ||
{ | ||
internal sealed class DispatcherDoubleAnimator : CPUBoundAnimator<double> | ||
internal sealed class DispatcherDoubleAnimator(double from, double to, int frameRate = DispatcherAnimator<double>.DefaultFrameRate) | ||
: DispatcherAnimator<double>(from, to, frameRate) | ||
{ | ||
public const int DefaultFrameRate = 30; | ||
|
||
private readonly int _frameRate; | ||
private readonly DispatcherTimer _timer; | ||
|
||
public DispatcherDoubleAnimator(double from, double to, int frameRate = DefaultFrameRate) | ||
: base(from, to) | ||
{ | ||
_frameRate = frameRate; | ||
_timer = new DispatcherTimer(); | ||
_timer.Tick += OnFrame; | ||
} | ||
|
||
protected override void EnableFrameReporting() => _timer.Start(); | ||
protected override void DisableFrameReporting() => _timer.Stop(); | ||
|
||
protected override void SetStartFrameDelay(long delayMs) => _timer.Interval = TimeSpan.FromMilliseconds(delayMs); | ||
protected override void SetAnimationFramesInterval() => _timer.Interval = TimeSpan.FromSeconds(1d / _frameRate); | ||
|
||
protected override double GetUpdatedValue(long frame, double from, double to) => (float)_easing.Ease(frame, from, to, Duration); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters