-
-
Notifications
You must be signed in to change notification settings - Fork 492
/
Copy pathPlaybackNextButton.cs
152 lines (123 loc) · 5.4 KB
/
PlaybackNextButton.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//
// Copyright Fela Ameghino 2015-2025
//
// Distributed under the GNU General Public License v3.0. (See accompanying
// file LICENSE or copy at https://www.gnu.org/licenses/gpl-3.0.txt)
//
using Microsoft.Graphics.Canvas.Geometry;
using System.Numerics;
using Telegram.Navigation;
using Windows.UI;
using Windows.UI.Composition;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Hosting;
using Windows.UI.Xaml.Media;
namespace Telegram.Controls
{
public partial class PlaybackNextButton : GlyphButton
{
private CompositionSpriteShape _line;
private CompositionSpriteShape _triangle1;
private CompositionSpriteShape _triangle2;
public PlaybackNextButton()
{
DefaultStyleKey = typeof(PlaybackNextButton);
Click += OnClick;
}
private void OnClick(object sender, RoutedEventArgs e)
{
if (_triangle1 == null || _triangle2 == null)
{
return;
}
var easing = BootStrapper.Current.Compositor.CreateLinearEasingFunction();
var scale1 = BootStrapper.Current.Compositor.CreateVector2KeyFrameAnimation();
scale1.InsertKeyFrame(1, Vector2.One, easing);
scale1.InsertKeyFrame(0, Vector2.Zero, easing);
//scale1.Duration = TimeSpan.FromMilliseconds(500);
var scale2 = BootStrapper.Current.Compositor.CreateVector2KeyFrameAnimation();
scale2.InsertKeyFrame(1, Vector2.Zero, easing);
scale2.InsertKeyFrame(0, Vector2.One, easing);
//scale2.Duration = TimeSpan.FromMilliseconds(500);
_triangle1.StartAnimation("Scale", scale1);
_triangle2.StartAnimation("Scale", scale2);
}
protected override void OnApplyTemplate()
{
var w = 16;
var h = 16;
var back = IsPrevious;
var target = GetTemplateChild("Target") as UIElement;
var line = BootStrapper.Current.Compositor.CreateLineGeometry();
line.Start = new Vector2(back ? 2.5f : w - 2.5f, 2);
line.End = new Vector2(back ? 2.5f : w - 2.5f, 14);
var triangle = BootStrapper.Current.Compositor.CreatePathGeometry(GetPolygon(
new Vector2(back ? 13.5f : w - 13.5f, 3),
new Vector2(back ? 13.5f : w - 13.5f, 13),
new Vector2(back ? 6.5f : w - 6.5f, 8)));
var lineShape = BootStrapper.Current.Compositor.CreateSpriteShape(line);
lineShape.StrokeThickness = 1;
lineShape.StrokeBrush = BootStrapper.Current.Compositor.CreateColorBrush(Colors.Black);
var triangleShape1 = BootStrapper.Current.Compositor.CreateSpriteShape(triangle);
triangleShape1.StrokeThickness = 1;
triangleShape1.StrokeBrush = BootStrapper.Current.Compositor.CreateColorBrush(Colors.Black);
triangleShape1.CenterPoint = new Vector2(back ? 2.5f : w - 2.5f, 8);
triangleShape1.IsStrokeNonScaling = true;
var triangleShape2 = BootStrapper.Current.Compositor.CreateSpriteShape(triangle);
triangleShape2.StrokeThickness = 1;
triangleShape2.StrokeBrush = BootStrapper.Current.Compositor.CreateColorBrush(Colors.Black);
triangleShape2.CenterPoint = new Vector2(back ? 16 : w - 16, 8);
triangleShape2.Scale = Vector2.Zero;
triangleShape2.IsStrokeNonScaling = true;
var test = BootStrapper.Current.Compositor.CreateShapeVisual();
test.Size = new Vector2(w, h);
test.Shapes.Add(lineShape);
test.Shapes.Add(triangleShape1);
test.Shapes.Add(triangleShape2);
_line = lineShape;
_triangle1 = triangleShape1;
_triangle2 = triangleShape2;
ApplyForeground();
RegisterPropertyChangedCallback(ForegroundProperty, OnForegroundChanged);
ElementCompositionPreview.SetElementChildVisual(target, test);
}
private void OnForegroundChanged(DependencyObject sender, DependencyProperty dp)
{
ApplyForeground();
}
private void ApplyForeground()
{
if (Foreground is SolidColorBrush solid)
{
var brush = BootStrapper.Current.Compositor.CreateColorBrush(solid.Color);
_line.StrokeBrush = brush;
_triangle1.StrokeBrush = brush;
_triangle2.StrokeBrush = brush;
}
}
private CompositionPath GetPolygon(params Vector2[] pt)
{
CanvasGeometry result;
using (var builder = new CanvasPathBuilder(null))
{
builder.BeginFigure(pt[0]);
for (int i = 1; i < pt.Length; i++)
{
builder.AddLine(pt[i]);
}
builder.EndFigure(CanvasFigureLoop.Closed);
result = CanvasGeometry.CreatePath(builder);
}
return new CompositionPath(result);
}
#region IsPrevious
public bool IsPrevious
{
get => (bool)GetValue(IsPreviousProperty);
set => SetValue(IsPreviousProperty, value);
}
public static readonly DependencyProperty IsPreviousProperty =
DependencyProperty.Register("IsPrevious", typeof(bool), typeof(PlaybackNextButton), new PropertyMetadata(false));
#endregion
}
}