-
-
Notifications
You must be signed in to change notification settings - Fork 679
Expand file tree
/
Copy pathCompositionVisualColorSource.cs
More file actions
92 lines (78 loc) · 2.58 KB
/
Copy pathCompositionVisualColorSource.cs
File metadata and controls
92 lines (78 loc) · 2.58 KB
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
//
// Copyright (c) Fela Ameghino 2015-2026
//
// 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.UI.Xaml.Controls;
using Telegram.Common;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
namespace Telegram.Composition
{
public partial class CompositionVisualColorSource
{
private readonly IAnimatedVisualSource2 _visual;
private readonly string _propertyName;
private SolidColorBrush _newValue;
private long _token;
public CompositionVisualColorSource(Brush value, IAnimatedVisualSource2 visual, string propertyName, bool connected)
{
_visual = visual;
_propertyName = propertyName;
if (value is SolidColorBrush newValue)
{
if (connected && _token == 0)
{
newValue.RegisterColorChangedCallback(OnColorChanged, ref _token);
}
_newValue = newValue;
_visual.SetColorProperty(_propertyName, newValue.Color);
}
else
{
_visual.SetColorProperty(_propertyName, Colors.Black);
}
}
public void PropertyChanged(SolidColorBrush newValue, bool connected)
{
if (_newValue != null && _token != 0)
{
_newValue.UnregisterPropertyChangedCallback(SolidColorBrush.ColorProperty, _token);
_token = 0;
}
if (newValue == null)
{
return;
}
_newValue = newValue;
_visual.SetColorProperty(_propertyName, newValue.Color);
if (connected)
{
_newValue.RegisterColorChangedCallback(OnColorChanged, ref _token);
}
}
private void OnColorChanged(DependencyObject sender, DependencyProperty dp)
{
var newValue = sender as SolidColorBrush;
if (newValue == null)
{
return;
}
_visual.SetColorProperty(_propertyName, newValue.Color);
}
public void Register()
{
if (_token == 0)
{
_newValue?.RegisterColorChangedCallback(OnColorChanged, ref _token);
OnColorChanged(_newValue, SolidColorBrush.ColorProperty);
}
}
public void Unregister()
{
_newValue?.UnregisterColorChangedCallback(ref _token);
}
}
}