From 6e17c3285352b2422729d0904e726358dadc2183 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 14 Jun 2019 16:49:08 +0200 Subject: [PATCH] Added acrylic pipeline effect --- .../Brushes/Effects/AcrylicEffect.cs | 39 +++++++++++++++++++ .../Brushes/PipelineBrush.cs | 7 ++++ .../UICompositionAnimations.csproj | 1 + 3 files changed, 47 insertions(+) create mode 100644 UICompositionAnimations/Brushes/Effects/AcrylicEffect.cs diff --git a/UICompositionAnimations/Brushes/Effects/AcrylicEffect.cs b/UICompositionAnimations/Brushes/Effects/AcrylicEffect.cs new file mode 100644 index 0000000..f78d554 --- /dev/null +++ b/UICompositionAnimations/Brushes/Effects/AcrylicEffect.cs @@ -0,0 +1,39 @@ +using System; +using Windows.UI; +using Windows.UI.Xaml.Media; +using UICompositionAnimations.Brushes.Effects.Interfaces; + +namespace UICompositionAnimations.Brushes.Effects +{ + /// + /// A custom acrylic effect that can be inserted into a pipeline + /// + public sealed class AcrylicEffect : IPipelineEffect + { + /// + /// Gets or sets the source mode for the effect + /// + public AcrylicBackgroundSource Source { get; set; } + + /// + /// Gets or sets the blur amount for the effect + /// + /// This property is ignored when the active mode is + public double BlurAmount { get; set; } + + /// + /// Gets or sets the tint for the effect + /// + public Color Tint { get; set; } + + /// + /// Gets or sets the color for the tint effect + /// + public double TintMix { get; set; } + + /// + /// Gets or sets the to the texture to use + /// + public Uri TextureUri { get; set; } + } +} diff --git a/UICompositionAnimations/Brushes/PipelineBrush.cs b/UICompositionAnimations/Brushes/PipelineBrush.cs index 0f33992..ea1f7c6 100644 --- a/UICompositionAnimations/Brushes/PipelineBrush.cs +++ b/UICompositionAnimations/Brushes/PipelineBrush.cs @@ -31,6 +31,13 @@ PipelineBuilder Start(IPipelineEffect effect) case SolidColorEffect color: return PipelineBuilder.FromColor(color.Color); case ImageEffect image: return PipelineBuilder.FromImage(image.Uri, image.DPIMode, image.CacheMode); case TileEffect tile: return PipelineBuilder.FromTiles(tile.Uri, tile.DPIMode, tile.CacheMode); + case AcrylicEffect acrylic: + switch (acrylic.Source) + { + case AcrylicBackgroundSource.Backdrop: return PipelineBuilder.FromBackdropAcrylic(acrylic.Tint, (float)acrylic.TintMix, (float)acrylic.BlurAmount, acrylic.TextureUri); + case AcrylicBackgroundSource.HostBackdrop: return PipelineBuilder.FromHostBackdropAcrylic(acrylic.Tint, (float)acrylic.TintMix, acrylic.TextureUri); + default: throw new ArgumentOutOfRangeException(nameof(acrylic.Source), $"Invalid acrylic source: {acrylic.Source}"); + } default: throw new ArgumentException($"Invalid initial pipeline effect: {effect.GetType()}"); } } diff --git a/UICompositionAnimations/UICompositionAnimations.csproj b/UICompositionAnimations/UICompositionAnimations.csproj index 8028b0e..f29595d 100644 --- a/UICompositionAnimations/UICompositionAnimations.csproj +++ b/UICompositionAnimations/UICompositionAnimations.csproj @@ -130,6 +130,7 @@ +