1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Loading.xaml.cs" company="HandBrake Project (http://handbrake.fr)">
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
// </copyright>
// <summary>
// Interaction logic for Loading.xaml
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.Controls
{
using System.Windows.Threading;
using System;
using System.Windows;
using System.Windows.Controls;
/// <summary>
/// Interaction logic for Loading.xaml
/// </summary>
public partial class Loading : UserControl
{
#region Fields
/// <summary>
/// Step
/// </summary>
private const double Step = Math.PI * 2 / 10.0;
/// <summary>
/// Timer for the spinning effect.
/// </summary>
private readonly DispatcherTimer timer;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="Loading"/> class.
/// </summary>
public Loading()
{
InitializeComponent();
IsVisibleChanged += OnVisibleChanged;
this.timer = new DispatcherTimer(DispatcherPriority.ContextIdle, Dispatcher)
{
Interval = new TimeSpan(0, 0, 0, 0, 75)
};
}
#endregion
/// <summary>
/// Sets the position.
/// </summary>
/// <param name="ellipse">The ellipse.</param>
/// <param name="offset">The offset.</param>
/// <param name="posOffSet">The pos off set.</param>
/// <param name="step">The step to change.</param>
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));
}
/// <summary>
/// Starts this instance.
/// </summary>
private void Start()
{
this.timer.Tick += this.OnTick;
this.timer.Start();
}
/// <summary>
/// Stops this instance.
/// </summary>
private void Stop()
{
this.timer.Stop();
this.timer.Tick -= this.OnTick;
}
/// <summary>
/// Run the Animation
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="e">
/// The e.
/// </param>
private void OnTick(object sender, EventArgs e)
{
this.rotate.Angle = (this.rotate.Angle + 36) % 360;
}
/// <summary>
/// Start and Stop the effect when the visibility changes
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="e">
/// The e.
/// </param>
private void OnVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if ((bool)e.NewValue)
{
Start();
}
else
{
Stop();
}
}
/// <summary>
/// Setup the Canvas
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="e">
/// The e.
/// </param>
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);
}
/// <summary>
/// Stop when we unload this canvas
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="e">
/// The e.
/// </param>
private void CanvasUnloaded(object sender, RoutedEventArgs e)
{
Stop();
}
}
}
|