-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnimatedIcon.cs
128 lines (105 loc) · 4.43 KB
/
AnimatedIcon.cs
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
using System;
using System.Diagnostics;
using System.Globalization;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls;
using Windows.Foundation;
namespace ProgressUIPrototype
{
public class AnimatedIcon : Panel
{
public AnimatedIcon()
{
AnimatedVisualPlayerProposed player = new AnimatedVisualPlayerProposed();
Children.Add(player);
}
protected override Size MeasureOverride(Size availableSize)
{
var desiredSize = new Size();
FrameworkElement child = (FrameworkElement)Children[0];
child.Measure(availableSize);
desiredSize = child.DesiredSize;
return desiredSize;
}
protected override Size ArrangeOverride(Size finalSize)
{
FrameworkElement child = (FrameworkElement)Children[0];
child.Arrange(new Rect(0, 0, finalSize.Width, finalSize.Height));
return finalSize;
}
public bool IsAnimating
{
get { return (bool)GetValue(IsAnimatingProperty); }
set { SetValue(IsAnimatingProperty, value); }
}
public static readonly DependencyProperty IsAnimatingProperty =
DependencyProperty.Register("IsAnimating", typeof(bool), typeof(AnimatedIcon), new PropertyMetadata(true, new PropertyChangedCallback(OnIsAnimatingChanged)));
private static void OnIsAnimatingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var animatedIcon = d as AnimatedIcon;
animatedIcon.UpdateStates();
}
public bool IsLooping
{
get { return (bool)GetValue(IsLoopingProperty); }
set { SetValue(IsLoopingProperty, value); }
}
public static readonly DependencyProperty IsLoopingProperty =
DependencyProperty.Register("IsLooping", typeof(bool), typeof(AnimatedIcon), new PropertyMetadata(true, new PropertyChangedCallback(OnIsLoopingChanged)));
private static void OnIsLoopingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var animatedIcon = d as AnimatedIcon;
animatedIcon.UpdateStates();
}
public double ProgressPosition
{
get { return (double)GetValue(ProgressPositionProperty); }
set { SetValue(ProgressPositionProperty, value); }
}
public static readonly DependencyProperty ProgressPositionProperty =
DependencyProperty.Register("ProgressPosition", typeof(double), typeof(AnimatedIcon), new PropertyMetadata(0, new PropertyChangedCallback(OnProgressPositionChanged)));
private static void OnProgressPositionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var animatedIcon = d as AnimatedIcon;
animatedIcon.UpdateProgressPosition(animatedIcon.ProgressPosition);
}
public IAnimatedVisualSource Source
{
get { return (IAnimatedVisualSource)GetValue(SourceProperty); }
set { SetValue(SourceProperty, value); }
}
public static readonly DependencyProperty SourceProperty =
DependencyProperty.Register("Source", typeof(IAnimatedVisualSource), typeof(AnimatedIcon), new PropertyMetadata(null, new PropertyChangedCallback(OnSourceChanged)));
private static void OnSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var animatedIcon = d as AnimatedIcon;
animatedIcon.UpdateSource(e);
}
private void UpdateStates()
{
AnimatedVisualPlayer player = (AnimatedVisualPlayer)Children[0];
if (this.IsAnimating)
{
_ = player.PlayAsync(0, 1, IsLooping);
}
else
{
player.Stop();
}
}
private void UpdateSource(DependencyPropertyChangedEventArgs e)
{
AnimatedVisualPlayer player = (AnimatedVisualPlayer)Children[0];
player.Source = e.NewValue as IAnimatedVisualSource;
}
private void UpdateProgressPosition(double progressPosition)
{
AnimatedVisualPlayer player = (AnimatedVisualPlayer)Children[0];
player.SetProgress(progressPosition);
}
}
}