using System; using OwlCore.Extensions; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; namespace StrixMusic.Controls { /// /// A control to display the Strix icon. /// public sealed partial class StrixIcon : UserControl { private bool _isAnimationEnding; /// /// The backing for the property. /// public static readonly DependencyProperty ShowTextProperty = DependencyProperty.Register(nameof(ShowText), typeof(bool), typeof(StrixIcon), new PropertyMetadata(false)); /// /// The backing for the property. /// public static readonly DependencyProperty IsAnimatedProperty = DependencyProperty.Register(nameof(IsAnimated), typeof(bool), typeof(StrixIcon), new PropertyMetadata(false, (d, e) => d.Cast().OnAnimatedChanged())); /// /// The backing for the property. /// public static readonly DependencyProperty PlayIntroProperty = DependencyProperty.Register(nameof(PlayIntroProperty), typeof(bool), typeof(StrixIcon), new PropertyMetadata(false)); /// /// Initializes a new instance of the class. /// public StrixIcon() { this.InitializeComponent(); } /// /// Fired when the ending animation completes. /// public event EventHandler? AnimationFinished; /// /// Gets or sets a value indicating whether or not the text should show by the icon. /// public bool ShowText { get { return (bool)GetValue(ShowTextProperty); } set { SetValue(ShowTextProperty, value); } } /// /// Gets or sets a value indicating whether or not the starting animation should play if animated. /// public bool PlayIntro { get { return (bool)GetValue(PlayIntroProperty); } set { SetValue(PlayIntroProperty, value); } } /// /// Gets or sets a value indicating whether or not the icon should show by animated. /// public bool IsAnimated { get { return (bool)GetValue(IsAnimatedProperty); } set { SetValue(IsAnimatedProperty, value); } } /// /// A function that tells the control to begin ending the animation. /// public void FinishAnimation() { _isAnimationEnding = true; RepeatedAnimation.Stop(); EndingAnimation.Begin(); } private void OnAnimatedChanged() { if (IsAnimated) { if (PlayIntro) { StartingAnimation.Begin(); } else { RepeatedAnimation.Begin(); } } else { RepeatedAnimation.Stop(); } } private void StartingAnimation_Completed(object sender, object e) { RepeatedAnimation.Begin(); } private void RepeatedAnimation_Completed(object sender, object e) { if (!_isAnimationEnding) RepeatedAnimation.Begin(); } private void EndingAnimation_Completed(object sender, object e) { AnimationFinished?.Invoke(this, EventArgs.Empty); } } }