// -------------------------------------------------------------------------------------------------------------------- // // This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. // // // Interaction logic for Loading.xaml // // -------------------------------------------------------------------------------------------------------------------- namespace HandBrakeWPF.Controls { using System; using System.Windows; using System.Windows.Controls; using System.Windows.Threading; /// /// Interaction logic for Loading.xaml /// public partial class Loading : UserControl { #region Fields /// /// Step /// private const double Step = Math.PI * 2 / 10.0; /// /// Timer for the spinning effect. /// private readonly DispatcherTimer timer; #endregion #region Constructors /// /// Initializes a new instance of the class. /// public Loading() { InitializeComponent(); IsVisibleChanged += OnVisibleChanged; this.timer = new DispatcherTimer(DispatcherPriority.ContextIdle, Dispatcher) { Interval = new TimeSpan(0, 0, 0, 0, 75) }; } #endregion /// /// Sets the position. /// /// The ellipse. /// The offset. /// The pos off set. /// The step to change. private static void SetPosition(DependencyObject ellipse, double offset, double posOffSet, double step) { ellipse.SetValue(Canvas.LeftProperty, 50 + (Math.Sin(offset + (posOffSet * step)) * 50)); ellipse.SetValue(Canvas.TopProperty, 50 + (Math.Cos(offset + (posOffSet * step)) * 50)); } /// /// Starts this instance. /// private void Start() { this.timer.Tick += this.OnTick; this.timer.Start(); } /// /// Stops this instance. /// private void Stop() { this.timer.Stop(); this.timer.Tick -= this.OnTick; } /// /// Run the Animation /// /// /// The sender. /// /// /// The e. /// private void OnTick(object sender, EventArgs e) { this.rotate.Angle = (this.rotate.Angle + 36) % 360; } /// /// Start and Stop the effect when the visibility changes /// /// /// The sender. /// /// /// The e. /// private void OnVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) { if ((bool)e.NewValue) { Start(); } else { Stop(); } } /// /// Setup the Canvas /// /// /// The sender. /// /// /// The e. /// private void CanvasLoaded(object sender, RoutedEventArgs e) { SetPosition(this.circle0, Math.PI, 0.0, Step); SetPosition(this.circle1, Math.PI, 1.0, Step); SetPosition(this.circle2, Math.PI, 2.0, Step); SetPosition(this.circle3, Math.PI, 3.0, Step); SetPosition(this.circle4, Math.PI, 4.0, Step); SetPosition(this.circle5, Math.PI, 5.0, Step); SetPosition(this.circle6, Math.PI, 6.0, Step); SetPosition(this.circle7, Math.PI, 7.0, Step); SetPosition(this.circle8, Math.PI, 8.0, Step); } /// /// Stop when we unload this canvas /// /// /// The sender. /// /// /// The e. /// private void CanvasUnloaded(object sender, RoutedEventArgs e) { Stop(); } } }