diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/AcrylicBrush/AcrylicBrushXaml.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/AcrylicBrush/AcrylicBrushXaml.bind index 40ffce65d83..c24d8070b27 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/AcrylicBrush/AcrylicBrushXaml.bind +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/AcrylicBrush/AcrylicBrushXaml.bind @@ -20,9 +20,9 @@ Grid.Column="2" Height="400"> - diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/PipelineBrush/PipelineBrushPage.xaml b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/PipelineBrush/PipelineBrushPage.xaml index 7584815b8cc..b1f92c65a2c 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/PipelineBrush/PipelineBrushPage.xaml +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/PipelineBrush/PipelineBrushPage.xaml @@ -20,62 +20,37 @@ VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="Red" Width="200" Height="200"/> - - - - - - - - - - - - - + + + + + + - - - - - - - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/PipelineBrush/PipelineBrushXaml.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/PipelineBrush/PipelineBrushXaml.bind index 6b3083b4698..4c3d90bfdc4 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/PipelineBrush/PipelineBrushXaml.bind +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/PipelineBrush/PipelineBrushXaml.bind @@ -20,29 +20,14 @@ Grid.Column="2" Height="400"> - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/AcrylicBrush.cs b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/AcrylicBrush.cs index 3ee477d605c..b0de6c15f72 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/AcrylicBrush.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/AcrylicBrush.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using Microsoft.Toolkit.Uwp.UI.Media.Base; using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; using Windows.UI; using Windows.UI.Composition; @@ -20,42 +19,42 @@ public sealed class AcrylicBrush : XamlCompositionEffectBrushBase /// /// The instance in use to set the blur amount /// - /// This is only set when is + /// This is only set when is private EffectSetter blurAmountSetter; /// /// The instance in use to set the tint color /// - private EffectSetter tintSetter; + private EffectSetter tintColorSetter; /// /// The instance in use to set the tint mix amount /// - private EffectSetter tintMixSetter; + private EffectSetter tintOpacitySetter; /// - /// Gets or sets the source mode for the effect + /// Gets or sets the background source mode for the effect (the default is ). /// - public AcrylicBackgroundSource Source + public AcrylicBackgroundSource BackgroundSource { - get => (AcrylicBackgroundSource)GetValue(SourceProperty); - set => SetValue(SourceProperty, value); + get => (AcrylicBackgroundSource)GetValue(BackgroundSourceProperty); + set => SetValue(BackgroundSourceProperty, value); } /// - /// Identifies the dependency property. + /// Identifies the dependency property. /// - public static readonly DependencyProperty SourceProperty = DependencyProperty.Register( - nameof(Source), + public static readonly DependencyProperty BackgroundSourceProperty = DependencyProperty.Register( + nameof(BackgroundSource), typeof(AcrylicBackgroundSource), typeof(AcrylicBrush), new PropertyMetadata(AcrylicBackgroundSource.Backdrop, OnSourcePropertyChanged)); /// - /// Updates the UI when changes + /// Updates the UI when changes /// /// The current instance - /// The instance for + /// The instance for private static void OnSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (d is AcrylicBrush brush && @@ -86,14 +85,14 @@ public double BlurAmount new PropertyMetadata(0.0, OnBlurAmountPropertyChanged)); /// - /// Updates the UI when changes + /// Updates the UI when changes /// /// The current instance - /// The instance for + /// The instance for private static void OnBlurAmountPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (d is AcrylicBrush brush && - brush.Source != AcrylicBackgroundSource.HostBackdrop && // Blur is fixed by OS when using HostBackdrop source. + brush.BackgroundSource != AcrylicBackgroundSource.HostBackdrop && // Blur is fixed by OS when using HostBackdrop source. brush.CompositionBrush is CompositionBrush target) { brush.blurAmountSetter?.Invoke(target, (float)(double)e.NewValue); @@ -103,60 +102,64 @@ private static void OnBlurAmountPropertyChanged(DependencyObject d, DependencyPr /// /// Gets or sets the tint for the effect /// - public Color Tint + public Color TintColor { - get => (Color)GetValue(TintProperty); - set => SetValue(TintProperty, value); + get => (Color)GetValue(TintColorProperty); + set => SetValue(TintColorProperty, value); } /// - /// Identifies the dependency property. + /// Identifies the dependency property. /// - public static readonly DependencyProperty TintProperty = DependencyProperty.Register( - nameof(Tint), + public static readonly DependencyProperty TintColorProperty = DependencyProperty.Register( + nameof(TintColor), typeof(Color), typeof(AcrylicBrush), - new PropertyMetadata(default(Color), OnTintPropertyChanged)); + new PropertyMetadata(default(Color), OnTintColorPropertyChanged)); /// - /// Updates the UI when changes + /// Updates the UI when changes /// /// The current instance - /// The instance for - private static void OnTintPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + /// The instance for + private static void OnTintColorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (d is AcrylicBrush brush && brush.CompositionBrush is CompositionBrush target) { - brush.tintSetter?.Invoke(target, (Color)e.NewValue); + brush.tintColorSetter?.Invoke(target, (Color)e.NewValue); } } /// - /// Gets or sets the tint mix factor for the effect + /// Gets or sets the tint opacity factor for the effect /// - public double TintMix { get; set; } + public double TintOpacity + { + get => (double)GetValue(TintOpacityProperty); + set => SetValue(TintOpacityProperty, value); + } /// - /// Identifies the dependency property. + /// Identifies the dependency property. /// - public static readonly DependencyProperty TintMixProperty = DependencyProperty.Register( - nameof(TintMix), + public static readonly DependencyProperty TintOpacityProperty = DependencyProperty.Register( + nameof(TintOpacity), typeof(double), typeof(AcrylicBrush), - new PropertyMetadata(0.0, OnTintMixPropertyChanged)); + new PropertyMetadata(0.0, OnTintOpacityPropertyChanged)); /// - /// Updates the UI when changes + /// Updates the UI when changes /// /// The current instance - /// The instance for - private static void OnTintMixPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + /// The instance for + private static void OnTintOpacityPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (d is AcrylicBrush brush && brush.CompositionBrush is CompositionBrush target) { - brush.tintMixSetter?.Invoke(target, (float)(double)e.NewValue); + brush.tintOpacitySetter?.Invoke(target, (float)(double)e.NewValue); } } @@ -196,25 +199,25 @@ private static void OnTextureUriPropertyChanged(DependencyObject d, DependencyPr /// protected override PipelineBuilder OnBrushRequested() { - switch (this.Source) + switch (BackgroundSource) { case AcrylicBackgroundSource.Backdrop: return PipelineBuilder.FromBackdropAcrylic( - Tint, - out tintSetter, - (float)TintMix, - out tintMixSetter, + TintColor, + out this.tintColorSetter, + (float)TintOpacity, + out this.tintOpacitySetter, (float)BlurAmount, - out this.blurAmountSetter, + out blurAmountSetter, TextureUri); case AcrylicBackgroundSource.HostBackdrop: return PipelineBuilder.FromHostBackdropAcrylic( - Tint, - out tintSetter, - (float)TintMix, - out tintMixSetter, + TintColor, + out this.tintColorSetter, + (float)TintOpacity, + out this.tintOpacitySetter, TextureUri); - default: throw new ArgumentOutOfRangeException(nameof(this.Source), $"Invalid acrylic source: {this.Source}"); + default: throw new ArgumentOutOfRangeException(nameof(BackgroundSource), $"Invalid acrylic source: {BackgroundSource}"); } } } diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropBlurBrush.cs b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropBlurBrush.cs index 69959a844c4..129fa289610 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropBlurBrush.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropBlurBrush.cs @@ -4,7 +4,6 @@ //// Example brush from https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.media.xamlcompositionbrushbase -using Microsoft.Toolkit.Uwp.UI.Media.Base; using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; using Windows.UI.Composition; using Windows.UI.Xaml; @@ -20,7 +19,7 @@ public class BackdropBlurBrush : XamlCompositionEffectBrushBase /// /// The instance currently in use /// - private EffectSetter setter; + private EffectSetter amountSetter; /// /// Gets or sets the amount of gaussian blur to apply to the background. @@ -50,14 +49,14 @@ private static void OnAmountChanged(DependencyObject d, DependencyPropertyChange if (d is BackdropBlurBrush brush && brush.CompositionBrush is CompositionBrush target) { - brush.setter?.Invoke(target, (float)brush.Amount); + brush.amountSetter?.Invoke(target, (float)brush.Amount); } } /// protected override PipelineBuilder OnBrushRequested() { - return PipelineBuilder.FromBackdrop().Blur((float)Amount, out setter); + return PipelineBuilder.FromBackdrop().Blur((float)Amount, out this.amountSetter); } } } diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropInvertBrush.cs b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropInvertBrush.cs index 156a27bd7a7..c225fa42fad 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropInvertBrush.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropInvertBrush.cs @@ -4,7 +4,6 @@ //// Example brush from https://blogs.windows.com/buildingapps/2017/07/18/working-brushes-content-xaml-visual-layer-interop-part-one/#z70vPv1QMAvZsceo.97 -using Microsoft.Toolkit.Uwp.UI.Media.Base; using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; using Windows.UI.Xaml.Media; diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropSaturationBrush.cs b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropSaturationBrush.cs index f358cfeab77..699ebe04849 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropSaturationBrush.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropSaturationBrush.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Toolkit.Uwp.UI.Media.Base; using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; using Windows.UI.Composition; using Windows.UI.Xaml; diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropSepiaBrush.cs b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropSepiaBrush.cs index 487e6897fa1..965d34de9ee 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropSepiaBrush.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropSepiaBrush.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Toolkit.Uwp.UI.Media.Base; using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; using Windows.UI.Composition; using Windows.UI.Xaml; diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/Base/XamlCompositionEffectBrushBase.cs b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/Base/XamlCompositionEffectBrushBase.cs index fe075953d9d..d9a4396e794 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/Base/XamlCompositionEffectBrushBase.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/Base/XamlCompositionEffectBrushBase.cs @@ -7,7 +7,7 @@ using Windows.UI.Composition; using Windows.UI.Xaml.Media; -namespace Microsoft.Toolkit.Uwp.UI.Media.Base +namespace Microsoft.Toolkit.Uwp.UI.Media { /// /// A custom that's ready to be used with a custom pipeline diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/PipelineBrush.cs b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/PipelineBrush.cs index d9a0b6d8846..4dfa2d41770 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/PipelineBrush.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/PipelineBrush.cs @@ -2,131 +2,41 @@ // 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; using System.Collections.Generic; -using System.Diagnostics.Contracts; -using System.Linq; -using Microsoft.Graphics.Canvas.Effects; -using Microsoft.Toolkit.Uwp.UI.Media.Base; using Microsoft.Toolkit.Uwp.UI.Media.Effects; -using Microsoft.Toolkit.Uwp.UI.Media.Effects.Interfaces; using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; +using Windows.UI.Xaml.Markup; using Windows.UI.Xaml.Media; -using BlendEffect = Microsoft.Toolkit.Uwp.UI.Media.Effects.BlendEffect; -using ExposureEffect = Microsoft.Toolkit.Uwp.UI.Media.Effects.ExposureEffect; -using GrayscaleEffect = Microsoft.Toolkit.Uwp.UI.Media.Effects.GrayscaleEffect; -using HueRotationEffect = Microsoft.Toolkit.Uwp.UI.Media.Effects.HueRotationEffect; -using InvertEffect = Microsoft.Toolkit.Uwp.UI.Media.Effects.InvertEffect; -using LuminanceToAlphaEffect = Microsoft.Toolkit.Uwp.UI.Media.Effects.LuminanceToAlphaEffect; -using OpacityEffect = Microsoft.Toolkit.Uwp.UI.Media.Effects.OpacityEffect; -using SaturationEffect = Microsoft.Toolkit.Uwp.UI.Media.Effects.SaturationEffect; -using SepiaEffect = Microsoft.Toolkit.Uwp.UI.Media.Effects.SepiaEffect; -using TemperatureAndTintEffect = Microsoft.Toolkit.Uwp.UI.Media.Effects.TemperatureAndTintEffect; -using TileEffect = Microsoft.Toolkit.Uwp.UI.Media.Effects.TileEffect; -using TintEffect = Microsoft.Toolkit.Uwp.UI.Media.Effects.TintEffect; namespace Microsoft.Toolkit.Uwp.UI.Media { /// /// A that renders a customizable Composition/Win2D effects pipeline /// + [ContentProperty(Name = nameof(Effects))] public sealed class PipelineBrush : XamlCompositionEffectBrushBase { /// - /// Builds a new effects pipeline from the input effects sequence + /// Gets or sets the input to merge with the current instance (defaults to a with source). /// - /// The input collection of instance - /// A new instance with the items in - [Pure] - private static PipelineBuilder Build(IList effects) - { - if (effects.Count == 0) - { - throw new ArgumentException("An effects pipeline can't be empty"); - } - - return effects.Skip(1).Aggregate(Start(effects[0]), (b, e) => Append(e, b)); - } + public PipelineBuilder Source { get; set; } /// - /// Starts a new composition pipeline from the given effect + /// Gets or sets the collection of effects to use in the current pipeline /// - /// The initial instance - /// A new instance starting from - [Pure] - private static PipelineBuilder Start(IPipelineEffect effect) - { - switch (effect) - { - case BackdropEffect backdrop when backdrop.Source == AcrylicBackgroundSource.Backdrop: - return PipelineBuilder.FromBackdrop(); - case BackdropEffect backdrop when backdrop.Source == AcrylicBackgroundSource.HostBackdrop: - return PipelineBuilder.FromHostBackdrop(); - 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 when acrylic.Source == AcrylicBackgroundSource.Backdrop: - return PipelineBuilder.FromBackdropAcrylic(acrylic.Tint, (float)acrylic.TintMix, (float)acrylic.BlurAmount, acrylic.TextureUri); - case AcrylicEffect acrylic when acrylic.Source == AcrylicBackgroundSource.HostBackdrop: - return PipelineBuilder.FromHostBackdropAcrylic(acrylic.Tint, (float)acrylic.TintMix, acrylic.TextureUri); - default: - throw new ArgumentException($"Invalid initial pipeline effect: {effect.GetType()}"); - } - } + public IList Effects { get; set; } = new List(); - /// - /// Appends an effect to an existing composition pipeline - /// - /// The instance to append to the current pipeline - /// The target instance to modify - /// The target instance in use - private static PipelineBuilder Append(IPipelineEffect effect, PipelineBuilder builder) + /// + protected override PipelineBuilder OnBrushRequested() { - switch (effect) + PipelineBuilder builder = Source ?? PipelineBuilder.FromBackdrop(); + + foreach (IPipelineEffect effect in Effects) { - case OpacityEffect opacity: - return builder.Opacity((float)opacity.Value); - case LuminanceToAlphaEffect _: - return builder.LuminanceToAlpha(); - case InvertEffect _: - return builder.Invert(); - case GrayscaleEffect _: - return builder.Grayscale(); - case ExposureEffect exposure: - return builder.Exposure((float)exposure.Value); - case SepiaEffect sepia: - return builder.Sepia((float)sepia.Value); - case ShadeEffect shade: - return builder.Shade(shade.Color, (float)shade.Intensity); - case HueRotationEffect hueRotation: - return builder.HueRotation((float)hueRotation.Angle); - case TintEffect tint: - return builder.Tint(tint.Color); - case TemperatureAndTintEffect temperatureAndTint: - return builder.TemperatureAndTint((float)temperatureAndTint.Temperature, (float)temperatureAndTint.Tint); - case BlurEffect blur: - return builder.Blur((float)blur.Value); - case SaturationEffect saturation: - return builder.Saturation((float)saturation.Value); - case BlendEffect blend: - return builder.Blend(Build(blend.Input), (BlendEffectMode)blend.Mode, blend.Placement); - default: - throw new ArgumentException($"Invalid pipeline effect: {effect.GetType()}"); + builder = effect.AppendToPipeline(builder); } - } - /// - protected override PipelineBuilder OnBrushRequested() - { - return Build(this.Effects); + return builder; } - - /// - /// Gets or sets the collection of effects to use in the current pipeline - /// - public IList Effects { get; set; } = new List(); } } diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/TilesBrush.cs b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/TilesBrush.cs index be1950c9bd3..3d75b4f3c53 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/TilesBrush.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/TilesBrush.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using Microsoft.Toolkit.Uwp.UI.Media.Base; using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; using Windows.UI.Xaml; diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/XamlCompositionBrush.cs b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/XamlCompositionBrush.cs index 7a2ccaa3e0a..44f1b527f23 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/XamlCompositionBrush.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/XamlCompositionBrush.cs @@ -5,7 +5,6 @@ using System; using System.Diagnostics.Contracts; using System.Threading.Tasks; -using Microsoft.Toolkit.Uwp.UI.Media.Base; using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; namespace Microsoft.Toolkit.Uwp.UI.Media diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/Abstract/ImageEffectBase.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/Abstract/ImageSourceBaseExtension.cs similarity index 79% rename from Microsoft.Toolkit.Uwp.UI.Media/Effects/Abstract/ImageEffectBase.cs rename to Microsoft.Toolkit.Uwp.UI.Media/Effects/Abstract/ImageSourceBaseExtension.cs index 2934d4e23a5..6117203665a 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/Abstract/ImageEffectBase.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/Abstract/ImageSourceBaseExtension.cs @@ -3,14 +3,16 @@ // See the LICENSE file in the project root for more information. using System; -using Microsoft.Toolkit.Uwp.UI.Media.Effects.Interfaces; +using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; +using Windows.UI.Xaml.Markup; -namespace Microsoft.Toolkit.Uwp.UI.Media.Effects.Abstract +namespace Microsoft.Toolkit.Uwp.UI.Media.Effects { /// /// An image based effect that loads an image at the specified location /// - public abstract class ImageEffectBase : IPipelineEffect + [MarkupExtensionReturnType(ReturnType = typeof(PipelineBuilder))] + public abstract class ImageSourceBaseExtension : MarkupExtension { /// /// Gets or sets the for the image to load diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/Abstract/ValueEffectBase.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/Abstract/ValueEffectBase.cs deleted file mode 100644 index 5e912a8c86b..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/Abstract/ValueEffectBase.cs +++ /dev/null @@ -1,19 +0,0 @@ -// 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 Microsoft.Toolkit.Uwp.UI.Media.Effects.Interfaces; - -namespace Microsoft.Toolkit.Uwp.UI.Media.Effects.Abstract -{ - /// - /// A base for an effect that exposes a single parameter - /// - public abstract class ValueEffectBase : IPipelineEffect - { - /// - /// Gets or sets the value of the parameter for the current effect - /// - public double Value { get; set; } - } -} diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/BackdropEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/BackdropEffect.cs deleted file mode 100644 index 5b20e450dcb..00000000000 --- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/BackdropEffect.cs +++ /dev/null @@ -1,20 +0,0 @@ -// 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 Microsoft.Toolkit.Uwp.UI.Media.Effects.Interfaces; -using Windows.UI.Xaml.Media; - -namespace Microsoft.Toolkit.Uwp.UI.Media.Effects -{ - /// - /// A backdrop effect that can sample from a specified source - /// - public sealed class BackdropEffect : IPipelineEffect - { - /// - /// Gets or sets the backdrop source to use to render the effect - /// - public AcrylicBackgroundSource Source { get; set; } - } -} diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlendEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlendEffect.cs index 611aae4a5e5..2799770b5ee 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlendEffect.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlendEffect.cs @@ -3,20 +3,26 @@ // See the LICENSE file in the project root for more information. using System.Collections.Generic; -using Microsoft.Toolkit.Uwp.UI.Media.Effects.Interfaces; +using Microsoft.Graphics.Canvas.Effects; +using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; namespace Microsoft.Toolkit.Uwp.UI.Media.Effects { /// - /// A blend effect that merges the current pipeline with an input one + /// A blend effect that merges the current builder with an input one /// /// This effect maps to the Win2D effect public sealed class BlendEffect : IPipelineEffect { /// - /// Gets or sets the input pipeline to merge with the current instance + /// Gets or sets the input to merge with the current instance (defaults to a with source). /// - public IList Input { get; set; } = new List(); + public PipelineBuilder Source { get; set; } + + /// + /// Gets or sets the effects to apply to the input to merge with the current instance + /// + public List Effects { get; set; } = new List(); /// /// Gets or sets the blending mode to use (the default mode is ) @@ -24,8 +30,21 @@ public sealed class BlendEffect : IPipelineEffect public ImageBlendMode Mode { get; set; } /// - /// Gets or sets the placement of the input pipeline with respect to the current one (the default is ) + /// Gets or sets the placement of the input builder with respect to the current one (the default is ) /// public Placement Placement { get; set; } = Placement.Foreground; + + /// + public PipelineBuilder AppendToPipeline(PipelineBuilder builder) + { + PipelineBuilder inputBuilder = Source ?? PipelineBuilder.FromBackdrop(); + + foreach (IPipelineEffect effect in this.Effects) + { + inputBuilder = effect.AppendToPipeline(inputBuilder); + } + + return builder.Blend(inputBuilder, (BlendEffectMode)Mode, Placement); + } } } diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlurEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlurEffect.cs index 3164f245e88..2442d2915f9 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlurEffect.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlurEffect.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Toolkit.Uwp.UI.Media.Effects.Abstract; +using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; namespace Microsoft.Toolkit.Uwp.UI.Media.Effects { @@ -10,7 +10,17 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Effects /// A gaussian blur effect /// /// This effect maps to the Win2D effect - public sealed class BlurEffect : ValueEffectBase + public sealed class BlurEffect : IPipelineEffect { + /// + /// Gets or sets the amount of gaussian blur to apply to the background. + /// + public double Amount { get; set; } + + /// + public PipelineBuilder AppendToPipeline(PipelineBuilder builder) + { + return builder.Blur((float)Amount); + } } } diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/ExposureEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/ExposureEffect.cs index e038c63cd4c..0fd847584e8 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/ExposureEffect.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/ExposureEffect.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Toolkit.Uwp.UI.Media.Effects.Abstract; +using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; namespace Microsoft.Toolkit.Uwp.UI.Media.Effects { @@ -10,7 +10,17 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Effects /// An exposure effect /// /// This effect maps to the Win2D effect - public sealed class ExposureEffect : ValueEffectBase + public sealed class ExposureEffect : IPipelineEffect { + /// + /// Gets or sets the amount of exposure to apply to the background (defaults to 0, should be in the [-2, 2] range). + /// + public double Amount { get; set; } + + /// + public PipelineBuilder AppendToPipeline(PipelineBuilder builder) + { + return builder.Exposure((float)Amount); + } } } diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/AcrylicEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/Extensions/AcrylicSourceExtension.cs similarity index 52% rename from Microsoft.Toolkit.Uwp.UI.Media/Effects/AcrylicEffect.cs rename to Microsoft.Toolkit.Uwp.UI.Media/Effects/Extensions/AcrylicSourceExtension.cs index 13c6208518d..0cec9ce4017 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/AcrylicEffect.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/Extensions/AcrylicSourceExtension.cs @@ -3,8 +3,9 @@ // See the LICENSE file in the project root for more information. using System; -using Microsoft.Toolkit.Uwp.UI.Media.Effects.Interfaces; +using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; using Windows.UI; +using Windows.UI.Xaml.Markup; using Windows.UI.Xaml.Media; namespace Microsoft.Toolkit.Uwp.UI.Media.Effects @@ -13,12 +14,13 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Effects /// A custom acrylic effect that can be inserted into a pipeline /// /// This effect mirrors the look of the default implementation - public sealed class AcrylicEffect : IPipelineEffect + [MarkupExtensionReturnType(ReturnType = typeof(PipelineBuilder))] + public sealed class AcrylicSourceExtension : MarkupExtension { /// - /// Gets or sets the source mode for the effect + /// Gets or sets the background source mode for the effect (the default is ). /// - public AcrylicBackgroundSource Source { get; set; } + public AcrylicBackgroundSource BackgroundSource { get; set; } = AcrylicBackgroundSource.Backdrop; /// /// Gets or sets the blur amount for the effect @@ -29,16 +31,27 @@ public sealed class AcrylicEffect : IPipelineEffect /// /// Gets or sets the tint for the effect /// - public Color Tint { get; set; } + public Color TintColor { get; set; } /// /// Gets or sets the color for the tint effect /// - public double TintMix { get; set; } + public double TintOpacity { get; set; } /// /// Gets or sets the to the texture to use /// public Uri TextureUri { get; set; } + + /// + protected override object ProvideValue() + { + return BackgroundSource switch + { + AcrylicBackgroundSource.Backdrop => PipelineBuilder.FromBackdropAcrylic(this.TintColor, (float)this.TintOpacity, (float)BlurAmount, TextureUri), + AcrylicBackgroundSource.HostBackdrop => PipelineBuilder.FromHostBackdropAcrylic(this.TintColor, (float)this.TintOpacity, TextureUri), + _ => throw new ArgumentException($"Invalid source mode for acrylic effect: {BackgroundSource}") + }; + } } } diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/Extensions/BackdropSourceExtension.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/Extensions/BackdropSourceExtension.cs new file mode 100644 index 00000000000..7ae6824c4aa --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/Extensions/BackdropSourceExtension.cs @@ -0,0 +1,34 @@ +// 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; +using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; +using Windows.UI.Xaml.Markup; +using Windows.UI.Xaml.Media; + +namespace Microsoft.Toolkit.Uwp.UI.Media.Effects +{ + /// + /// A backdrop effect that can sample from a specified source + /// + [MarkupExtensionReturnType(ReturnType = typeof(PipelineBuilder))] + public sealed class BackdropSourceExtension : MarkupExtension + { + /// + /// Gets or sets the background source mode for the effect (the default is ). + /// + public AcrylicBackgroundSource BackgroundSource { get; set; } = AcrylicBackgroundSource.Backdrop; + + /// + protected override object ProvideValue() + { + return BackgroundSource switch + { + AcrylicBackgroundSource.Backdrop => PipelineBuilder.FromBackdrop(), + AcrylicBackgroundSource.HostBackdrop => PipelineBuilder.FromHostBackdrop(), + _ => throw new ArgumentException($"Invalid source for backdrop effect: {BackgroundSource}") + }; + } + } +} diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/ImageEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/Extensions/ImageSourceExtension.cs similarity index 57% rename from Microsoft.Toolkit.Uwp.UI.Media/Effects/ImageEffect.cs rename to Microsoft.Toolkit.Uwp.UI.Media/Effects/Extensions/ImageSourceExtension.cs index d95dc44b93d..769aa67c88f 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/ImageEffect.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/Extensions/ImageSourceExtension.cs @@ -2,14 +2,19 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Toolkit.Uwp.UI.Media.Effects.Abstract; +using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; namespace Microsoft.Toolkit.Uwp.UI.Media.Effects { /// /// An image effect, which displays an image loaded as a Win2D surface /// - public sealed class ImageEffect : ImageEffectBase + public sealed class ImageSourceExtension : ImageSourceBaseExtension { + /// + protected override object ProvideValue() + { + return PipelineBuilder.FromImage(Uri, DpiMode, CacheMode); + } } } diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/SolidColorEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/Extensions/SolidColorSourceExtension.cs similarity index 59% rename from Microsoft.Toolkit.Uwp.UI.Media/Effects/SolidColorEffect.cs rename to Microsoft.Toolkit.Uwp.UI.Media/Effects/Extensions/SolidColorSourceExtension.cs index b0f90ae2989..598e976ddd6 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/SolidColorEffect.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/Extensions/SolidColorSourceExtension.cs @@ -2,19 +2,27 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Toolkit.Uwp.UI.Media.Effects.Interfaces; +using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; using Windows.UI; +using Windows.UI.Xaml.Markup; namespace Microsoft.Toolkit.Uwp.UI.Media.Effects { /// /// An effect that renders a standard 8bit SDR color on the available surface /// - public sealed class SolidColorEffect : IPipelineEffect + [MarkupExtensionReturnType(ReturnType = typeof(PipelineBuilder))] + public sealed class SolidColorSourceExtension : MarkupExtension { /// /// Gets or sets the color to display /// public Color Color { get; set; } + + /// + protected override object ProvideValue() + { + return PipelineBuilder.FromColor(Color); + } } } diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/TileEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/Extensions/TileSourceExtension.cs similarity index 64% rename from Microsoft.Toolkit.Uwp.UI.Media/Effects/TileEffect.cs rename to Microsoft.Toolkit.Uwp.UI.Media/Effects/Extensions/TileSourceExtension.cs index b2a340b5dc2..f45b7ba1b73 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/TileEffect.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/Extensions/TileSourceExtension.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Toolkit.Uwp.UI.Media.Effects.Abstract; +using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; namespace Microsoft.Toolkit.Uwp.UI.Media.Effects { @@ -10,7 +10,12 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Effects /// An effect that loads an image and replicates it to cover all the available surface area /// /// This effect maps to the Win2D effect - public sealed class TileEffect : ImageEffectBase + public sealed class TileSourceExtension : ImageSourceBaseExtension { + /// + protected override object ProvideValue() + { + return PipelineBuilder.FromTiles(Uri, DpiMode, CacheMode); + } } } diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/GrayscaleEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/GrayscaleEffect.cs index 2b1a246b6e5..5e2070d148b 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/GrayscaleEffect.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/GrayscaleEffect.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Toolkit.Uwp.UI.Media.Effects.Interfaces; +using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; namespace Microsoft.Toolkit.Uwp.UI.Media.Effects { @@ -12,5 +12,10 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Effects /// This effect maps to the Win2D effect public sealed class GrayscaleEffect : IPipelineEffect { + /// + public PipelineBuilder AppendToPipeline(PipelineBuilder builder) + { + return builder.Grayscale(); + } } } diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/HueRotationEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/HueRotationEffect.cs index ed90a0b87b8..bf76744f3b4 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/HueRotationEffect.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/HueRotationEffect.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Toolkit.Uwp.UI.Media.Effects.Interfaces; +using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; namespace Microsoft.Toolkit.Uwp.UI.Media.Effects { @@ -16,5 +16,11 @@ public sealed class HueRotationEffect : IPipelineEffect /// Gets or sets the angle to rotate the hue, in radians /// public double Angle { get; set; } + + /// + public PipelineBuilder AppendToPipeline(PipelineBuilder builder) + { + return builder.HueRotation((float)Angle); + } } } diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/Interfaces/IPipelineEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/Interfaces/IPipelineEffect.cs index 015355a22b8..24a867442c3 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/Interfaces/IPipelineEffect.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/Interfaces/IPipelineEffect.cs @@ -2,12 +2,20 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Microsoft.Toolkit.Uwp.UI.Media.Effects.Interfaces +using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; + +namespace Microsoft.Toolkit.Uwp.UI.Media.Effects { /// - /// The base for all the pipeline effects to be used in a + /// The base for all the builder effects to be used in a /// public interface IPipelineEffect { + /// + /// Appends the current effect to the input instance. + /// + /// The source instance to add the effect to. + /// A new with the new effects added to it. + PipelineBuilder AppendToPipeline(PipelineBuilder builder); } } diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/InvertEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/InvertEffect.cs index b5f5565c79f..04c0fcd9bb8 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/InvertEffect.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/InvertEffect.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Toolkit.Uwp.UI.Media.Effects.Interfaces; +using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; namespace Microsoft.Toolkit.Uwp.UI.Media.Effects { @@ -12,5 +12,10 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Effects /// This effect maps to the Win2D effect public sealed class InvertEffect : IPipelineEffect { + /// + public PipelineBuilder AppendToPipeline(PipelineBuilder builder) + { + return builder.Invert(); + } } } diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/LuminanceToAlphaEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/LuminanceToAlphaEffect.cs index 82f3547e816..527b55840e0 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/LuminanceToAlphaEffect.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/LuminanceToAlphaEffect.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Toolkit.Uwp.UI.Media.Effects.Interfaces; +using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; namespace Microsoft.Toolkit.Uwp.UI.Media.Effects { @@ -12,5 +12,10 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Effects /// This effect maps to the Win2D effect public sealed class LuminanceToAlphaEffect : IPipelineEffect { + /// + public PipelineBuilder AppendToPipeline(PipelineBuilder builder) + { + return builder.LuminanceToAlpha(); + } } } diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/OpacityEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/OpacityEffect.cs index 7b86916f90d..1535e58d025 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/OpacityEffect.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/OpacityEffect.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Toolkit.Uwp.UI.Media.Effects.Abstract; +using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; namespace Microsoft.Toolkit.Uwp.UI.Media.Effects { @@ -10,7 +10,17 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Effects /// An opacity effect /// /// This effect maps to the Win2D effect - public sealed class OpacityEffect : ValueEffectBase + public sealed class OpacityEffect : IPipelineEffect { + /// + /// Gets or sets the opacity value to apply to the background (defaults to 1, should be in the [0, 1] range). + /// + public double Value { get; set; } = 1; + + /// + public PipelineBuilder AppendToPipeline(PipelineBuilder builder) + { + return builder.Opacity((float)Value); + } } } diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/SaturationEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/SaturationEffect.cs index 9b30e0a4041..1ed8f924079 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/SaturationEffect.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/SaturationEffect.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Toolkit.Uwp.UI.Media.Effects.Abstract; +using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; namespace Microsoft.Toolkit.Uwp.UI.Media.Effects { @@ -10,7 +10,17 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Effects /// A saturation effect /// /// This effect maps to the Win2D effect - public sealed class SaturationEffect : ValueEffectBase + public sealed class SaturationEffect : IPipelineEffect { + /// + /// Gets or sets the saturation amount to apply to the background (defaults to 1, should be in the [0, 1] range). + /// + public double Value { get; set; } = 1; + + /// + public PipelineBuilder AppendToPipeline(PipelineBuilder builder) + { + return builder.Saturation((float)Value); + } } } diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/SepiaEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/SepiaEffect.cs index baf9e816d25..3dea7a9e361 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/SepiaEffect.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/SepiaEffect.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Toolkit.Uwp.UI.Media.Effects.Abstract; +using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; namespace Microsoft.Toolkit.Uwp.UI.Media.Effects { @@ -10,7 +10,17 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Effects /// A sepia effect /// /// This effect maps to the Win2D effect - public sealed class SepiaEffect : ValueEffectBase + public sealed class SepiaEffect : IPipelineEffect { + /// + /// Gets or sets the intensity of the effect (defaults to 0.5, should be in the [0, 1] range). + /// + public double Intensity { get; set; } = 0.5; + + /// + public PipelineBuilder AppendToPipeline(PipelineBuilder builder) + { + return builder.Sepia((float)Intensity); + } } } diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/ShadeEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/ShadeEffect.cs index b2659b27719..d4575d226b8 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/ShadeEffect.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/ShadeEffect.cs @@ -2,13 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Toolkit.Uwp.UI.Media.Effects.Interfaces; +using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; using Windows.UI; namespace Microsoft.Toolkit.Uwp.UI.Media.Effects { /// - /// An effect that overlays a color layer over the current pipeline, with a specified intensity + /// An effect that overlays a color layer over the current builder, with a specified intensity /// public sealed class ShadeEffect : IPipelineEffect { @@ -21,5 +21,11 @@ public sealed class ShadeEffect : IPipelineEffect /// Gets or sets the intensity of the color layer /// public double Intensity { get; set; } + + /// + public PipelineBuilder AppendToPipeline(PipelineBuilder builder) + { + return builder.Shade(Color, (float)Intensity); + } } } diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/TemperatureAndTintEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/TemperatureAndTintEffect.cs index 058e1019e70..6fb4b42afc4 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/TemperatureAndTintEffect.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/TemperatureAndTintEffect.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Toolkit.Uwp.UI.Media.Effects.Abstract; +using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; namespace Microsoft.Toolkit.Uwp.UI.Media.Effects { @@ -10,7 +10,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Effects /// A temperature and tint effect /// /// This effect maps to the Win2D effect - public sealed class TemperatureAndTintEffect : ValueEffectBase + public sealed class TemperatureAndTintEffect : IPipelineEffect { /// /// Gets or sets the value of the temperature for the current effect @@ -21,5 +21,11 @@ public sealed class TemperatureAndTintEffect : ValueEffectBase /// Gets or sets the value of the tint for the current effect /// public double Tint { get; set; } + + /// + public PipelineBuilder AppendToPipeline(PipelineBuilder builder) + { + return builder.TemperatureAndTint((float)Temperature, (float)Tint); + } } } diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/TintEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/TintEffect.cs index bc248f82890..11994b21182 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/TintEffect.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/TintEffect.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Toolkit.Uwp.UI.Media.Effects.Interfaces; +using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; using Windows.UI; namespace Microsoft.Toolkit.Uwp.UI.Media.Effects @@ -17,5 +17,11 @@ public sealed class TintEffect : IPipelineEffect /// Gets or sets the int color to use /// public Color Color { get; set; } + + /// + public PipelineBuilder AppendToPipeline(PipelineBuilder builder) + { + return builder.Tint(Color); + } } } diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Helpers/SurfaceLoader.cs b/Microsoft.Toolkit.Uwp.UI.Media/Helpers/SurfaceLoader.cs index ebcb7104243..84fae789318 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Helpers/SurfaceLoader.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Helpers/SurfaceLoader.cs @@ -32,16 +32,16 @@ public sealed partial class SurfaceLoader /// /// Gets the local cache mapping for previously loaded Win2D images /// - private static readonly CompositionObjectCache Cache = new CompositionObjectCache(); + private static readonly CompositionObjectCache Cache = new CompositionObjectCache(); /// - /// Loads a instance with the target image from the shared instance + /// Loads a instance with the target image from the shared instance /// /// The path to the image to load /// Indicates the desired DPI mode to use when loading the image /// Indicates the cache option to use to load the image - /// A that returns the loaded instance - public static async Task LoadImageAsync(Uri uri, DpiMode dpiMode, CacheMode cacheMode = CacheMode.Default) + /// A that returns the loaded instance + public static async Task LoadImageAsync(Uri uri, DpiMode dpiMode, CacheMode cacheMode = CacheMode.Default) { var compositor = Window.Current.Compositor; @@ -57,7 +57,7 @@ public static async Task LoadImageAsync(Uri uri, DpiMod } // Load the image - CompositionSurfaceBrush brush; + CompositionBrush brush; try { // This will throw and the canvas will re-initialize the Win2D device if needed @@ -82,14 +82,14 @@ public static async Task LoadImageAsync(Uri uri, DpiMod } /// - /// Loads a from the input , and prepares it to be used in a tile effect + /// Loads a from the input , and prepares it to be used in a tile effect /// /// The device to use to process the Win2D image /// The compositor instance to use to create the final brush /// The path to the image to load /// Indicates the desired DPI mode to use when loading the image - /// A that returns the loaded instance - private static async Task LoadSurfaceBrushAsync( + /// A that returns the loaded instance + private static async Task LoadSurfaceBrushAsync( CanvasDevice canvasDevice, Compositor compositor, Uri uri, diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Initialization.cs b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Initialization.cs index 02439a5f37a..8bd4f4f68f9 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Initialization.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Initialization.cs @@ -271,7 +271,7 @@ public static PipelineBuilder FromImage(string relativePath, DpiMode dpiMode = D [Pure] public static PipelineBuilder FromImage(Uri uri, DpiMode dpiMode = DpiMode.DisplayDpiWith96AsLowerBound, CacheMode cacheMode = CacheMode.Default) { - return new PipelineBuilder(async () => await SurfaceLoader.LoadImageAsync(uri, dpiMode, cacheMode)); + return new PipelineBuilder(() => new ValueTask(SurfaceLoader.LoadImageAsync(uri, dpiMode, cacheMode))); } /// diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Merge.cs b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Merge.cs index a9dcb621367..56b8fcb1938 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Merge.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Merge.cs @@ -34,15 +34,12 @@ private static (PipelineBuilder Foreground, PipelineBuilder Background) GetMerge PipelineBuilder right, Placement placement) { - switch (placement) + return placement switch { - case Placement.Foreground: - return (left, right); - case Placement.Background: - return (right, left); - default: - throw new ArgumentException($"Invalid placement value: {placement}"); - } + Placement.Foreground => (left, right), + Placement.Background => (right, left), + _ => throw new ArgumentException($"Invalid placement value: {placement}") + }; } /// diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Prebuilt.cs b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Prebuilt.cs index c5782b19ff5..52ef3f2d1b1 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Prebuilt.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Prebuilt.cs @@ -17,15 +17,15 @@ public sealed partial class PipelineBuilder /// /// Returns a new instance that implements the host backdrop acrylic effect /// - /// The tint color to use - /// The amount of tint to apply over the current effect + /// The tint color to use + /// The amount of tint to apply over the current effect /// The for the noise texture to load for the acrylic effect /// The cache mode to use to load the image /// A new instance to use to keep adding new effects [Pure] public static PipelineBuilder FromHostBackdropAcrylic( - Color tint, - float mix, + Color tintColor, + float tintOpacity, Uri noiseUri, CacheMode cacheMode = CacheMode.Default) { @@ -34,7 +34,7 @@ public static PipelineBuilder FromHostBackdropAcrylic( .LuminanceToAlpha() .Opacity(0.4f) .Blend(FromHostBackdrop(), BlendEffectMode.Multiply) - .Shade(tint, mix); + .Shade(tintColor, tintOpacity); if (noiseUri != null) { @@ -47,19 +47,19 @@ public static PipelineBuilder FromHostBackdropAcrylic( /// /// Returns a new instance that implements the host backdrop acrylic effect /// - /// The tint color to use - /// The optional tint color setter for the effect - /// The amount of tint to apply over the current effect - /// The optional tint mix setter for the effect + /// The tint color to use + /// The optional tint color setter for the effect + /// The amount of tint to apply over the current effect + /// The optional tint mix setter for the effect /// The for the noise texture to load for the acrylic effect /// The cache mode to use to load the image /// A new instance to use to keep adding new effects [Pure] public static PipelineBuilder FromHostBackdropAcrylic( - Color tint, - out EffectSetter tintSetter, - float mix, - out EffectSetter mixSetter, + Color tintColor, + out EffectSetter tintColorSetter, + float tintOpacity, + out EffectSetter tintOpacitySetter, Uri noiseUri, CacheMode cacheMode = CacheMode.Default) { @@ -68,7 +68,7 @@ public static PipelineBuilder FromHostBackdropAcrylic( .LuminanceToAlpha() .Opacity(0.4f) .Blend(FromHostBackdrop(), BlendEffectMode.Multiply) - .Shade(tint, out tintSetter, mix, out mixSetter); + .Shade(tintColor, out tintColorSetter, tintOpacity, out tintOpacitySetter); if (noiseUri != null) { @@ -81,19 +81,19 @@ public static PipelineBuilder FromHostBackdropAcrylic( /// /// Returns a new instance that implements the host backdrop acrylic effect /// - /// The tint color to use - /// The optional tint color animation for the effect - /// The amount of tint to apply over the current effect - /// The optional tint mix animation for the effect + /// The tint color to use + /// The optional tint color animation for the effect + /// The amount of tint to apply over the current effect + /// The optional tint mix animation for the effect /// The for the noise texture to load for the acrylic effect /// The cache mode to use to load the image /// A new instance to use to keep adding new effects [Pure] public static PipelineBuilder FromHostBackdropAcrylic( - Color tint, - out EffectAnimation tintAnimation, - float mix, - out EffectAnimation mixAnimation, + Color tintColor, + out EffectAnimation tintColorAnimation, + float tintOpacity, + out EffectAnimation tintOpacityAnimation, Uri noiseUri, CacheMode cacheMode = CacheMode.Default) { @@ -102,7 +102,7 @@ public static PipelineBuilder FromHostBackdropAcrylic( .LuminanceToAlpha() .Opacity(0.4f) .Blend(FromHostBackdrop(), BlendEffectMode.Multiply) - .Shade(tint, out tintAnimation, mix, out mixAnimation); + .Shade(tintColor, out tintColorAnimation, tintOpacity, out tintOpacityAnimation); if (noiseUri != null) { @@ -115,24 +115,24 @@ public static PipelineBuilder FromHostBackdropAcrylic( /// /// Returns a new instance that implements the in-app backdrop acrylic effect /// - /// The tint color to use - /// The amount of tint to apply over the current effect - /// The amount of blur to apply to the acrylic brush + /// The tint color to use + /// The amount of tint to apply over the current effect + /// The amount of blur to apply to the acrylic brush /// The for the noise texture to load for the acrylic effect /// The cache mode to use to load the image /// A new instance to use to keep adding new effects [Pure] public static PipelineBuilder FromBackdropAcrylic( - Color tint, - float mix, - float blur, + Color tintColor, + float tintOpacity, + float blurAmount, Uri noiseUri, CacheMode cacheMode = CacheMode.Default) { var pipeline = FromBackdrop() - .Shade(tint, mix) - .Blur(blur); + .Shade(tintColor, tintOpacity) + .Blur(blurAmount); if (noiseUri != null) { @@ -145,30 +145,30 @@ public static PipelineBuilder FromBackdropAcrylic( /// /// Returns a new instance that implements the in-app backdrop acrylic effect /// - /// The tint color to use - /// The optional tint color setter for the effect - /// The amount of tint to apply over the current effect - /// The optional tint mix setter for the effect - /// The amount of blur to apply to the acrylic brush - /// The optional blur setter for the effect + /// The tint color to use + /// The optional tint color setter for the effect + /// The amount of tint to apply over the current effect + /// The optional tint mix setter for the effect + /// The amount of blur to apply to the acrylic brush + /// The optional blur setter for the effect /// The for the noise texture to load for the acrylic effect /// The cache mode to use to load the image /// A new instance to use to keep adding new effects [Pure] public static PipelineBuilder FromBackdropAcrylic( - Color tint, - out EffectSetter tintSetter, - float mix, - out EffectSetter mixSetter, - float blur, - out EffectSetter blurSetter, + Color tintColor, + out EffectSetter tintColorSetter, + float tintOpacity, + out EffectSetter tintOpacitySetter, + float blurAmount, + out EffectSetter blurAmountSetter, Uri noiseUri, CacheMode cacheMode = CacheMode.Default) { var pipeline = FromBackdrop() - .Shade(tint, out tintSetter, mix, out mixSetter) - .Blur(blur, out blurSetter); + .Shade(tintColor, out tintColorSetter, tintOpacity, out tintOpacitySetter) + .Blur(blurAmount, out blurAmountSetter); if (noiseUri != null) { @@ -181,30 +181,30 @@ public static PipelineBuilder FromBackdropAcrylic( /// /// Returns a new instance that implements the in-app backdrop acrylic effect /// - /// The tint color to use + /// The tint color to use /// The optional tint color animation for the effect - /// The amount of tint to apply over the current effect - /// The optional tint mix animation for the effect - /// The amount of blur to apply to the acrylic brush - /// The optional blur animation for the effect + /// The amount of tint to apply over the current effect + /// The optional tint mix animation for the effect + /// The amount of blur to apply to the acrylic brush + /// The optional blur animation for the effect /// The for the noise texture to load for the acrylic effect /// The cache mode to use to load the image /// A new instance to use to keep adding new effects [Pure] public static PipelineBuilder FromBackdropAcrylic( - Color tint, + Color tintColor, out EffectAnimation tintAnimation, - float mix, - out EffectAnimation mixAnimation, - float blur, - out EffectAnimation blurAnimation, + float tintOpacity, + out EffectAnimation tintOpacityAnimation, + float blurAmount, + out EffectAnimation blurAmountAnimation, Uri noiseUri, CacheMode cacheMode = CacheMode.Default) { var pipeline = FromBackdrop() - .Shade(tint, out tintAnimation, mix, out mixAnimation) - .Blur(blur, out blurAnimation); + .Shade(tintColor, out tintAnimation, tintOpacity, out tintOpacityAnimation) + .Blur(blurAmount, out blurAmountAnimation); if (noiseUri != null) {