-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
PipelineBrush.cs
74 lines (64 loc) · 2.44 KB
/
PipelineBrush.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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Markup;
using Windows.UI.Xaml.Media;
namespace Microsoft.Toolkit.Uwp.UI.Media
{
/// <summary>
/// A <see cref="Brush"/> that renders a customizable Composition/Win2D effects pipeline
/// </summary>
[ContentProperty(Name = nameof(Effects))]
public sealed class PipelineBrush : XamlCompositionEffectBrushBase
{
/// <summary>
/// Gets or sets the source for the current pipeline (defaults to a <see cref="BackdropSourceExtension"/> with <see cref="AcrylicBackgroundSource.Backdrop"/> source).
/// </summary>
public PipelineBuilder Source { get; set; }
/// <summary>
/// Gets or sets the collection of effects to use in the current pipeline.
/// </summary>
public IList<PipelineEffect> Effects
{
get
{
if (GetValue(EffectsProperty) is not IList<PipelineEffect> effects)
{
effects = new List<PipelineEffect>();
SetValue(EffectsProperty, effects);
}
return effects;
}
set => SetValue(EffectsProperty, value);
}
/// <summary>
/// Identifies the <seealso cref="Effects"/> dependency property.
/// </summary>
public static readonly DependencyProperty EffectsProperty = DependencyProperty.Register(
nameof(Effects),
typeof(IList<PipelineEffect>),
typeof(PipelineBrush),
new PropertyMetadata(null));
/// <inheritdoc/>
protected override PipelineBuilder OnPipelineRequested()
{
PipelineBuilder builder = Source ?? PipelineBuilder.FromBackdrop();
foreach (IPipelineEffect effect in Effects)
{
builder = effect.AppendToBuilder(builder);
}
return builder;
}
/// <inheritdoc/>
protected override void OnCompositionBrushUpdated()
{
foreach (IPipelineEffect effect in Effects)
{
effect.NotifyCompositionBrushInUse(CompositionBrush);
}
}
}
}