diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/PipelineBrush/PipelineBrushPage.xaml b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/PipelineBrush/PipelineBrushPage.xaml
index b1f92c65a2c..7a934c95530 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/PipelineBrush/PipelineBrushPage.xaml
+++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/PipelineBrush/PipelineBrushPage.xaml
@@ -26,6 +26,7 @@
+
diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/PipelineBrush/PipelineBrushXaml.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/PipelineBrush/PipelineBrushXaml.bind
index 4c3d90bfdc4..65233b7e255 100644
--- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/PipelineBrush/PipelineBrushXaml.bind
+++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/PipelineBrush/PipelineBrushXaml.bind
@@ -26,8 +26,8 @@
-
-
+
+
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/AcrylicBrush.cs b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/AcrylicBrush.cs
index b0de6c15f72..30c67aa3a37 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/AcrylicBrush.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/AcrylicBrush.cs
@@ -66,13 +66,13 @@ private static void OnSourcePropertyChanged(DependencyObject d, DependencyProper
}
///
- /// Gets or sets the blur amount for the effect
+ /// Gets or sets the blur amount for the effect (must be a positive value)
///
/// This property is ignored when the active mode is
public double BlurAmount
{
get => (double)GetValue(BlurAmountProperty);
- set => SetValue(BlurAmountProperty, value);
+ set => SetValue(BlurAmountProperty, Math.Max(value, 0));
}
///
@@ -132,12 +132,12 @@ private static void OnTintColorPropertyChanged(DependencyObject d, DependencyPro
}
///
- /// Gets or sets the tint opacity factor for the effect
+ /// Gets or sets the tint opacity factor for the effect (default is 0.5, must be in the [0, 1] range)
///
public double TintOpacity
{
get => (double)GetValue(TintOpacityProperty);
- set => SetValue(TintOpacityProperty, value);
+ set => SetValue(TintOpacityProperty, Math.Clamp(value, 0, 1));
}
///
@@ -147,7 +147,7 @@ public double TintOpacity
nameof(TintOpacity),
typeof(double),
typeof(AcrylicBrush),
- new PropertyMetadata(0.0, OnTintOpacityPropertyChanged));
+ new PropertyMetadata(0.5, OnTintOpacityPropertyChanged));
///
/// Updates the UI when changes
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlendEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlendEffect.cs
index 2799770b5ee..ce282c29ced 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlendEffect.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlendEffect.cs
@@ -5,6 +5,7 @@
using System.Collections.Generic;
using Microsoft.Graphics.Canvas.Effects;
using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
+using Windows.UI.Xaml.Markup;
namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
{
@@ -12,6 +13,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
/// A blend effect that merges the current builder with an input one
///
/// This effect maps to the Win2D effect
+ [ContentProperty(Name = nameof(Effects))]
public sealed class BlendEffect : IPipelineEffect
{
///
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlurEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlurEffect.cs
index 2442d2915f9..b1e6c9437c2 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlurEffect.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/BlurEffect.cs
@@ -2,6 +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 System;
using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
@@ -12,10 +13,16 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
/// This effect maps to the Win2D effect
public sealed class BlurEffect : IPipelineEffect
{
+ private double amount;
+
///
- /// Gets or sets the amount of gaussian blur to apply to the background.
+ /// Gets or sets the blur amount for the effect (must be a positive value)
///
- public double Amount { get; set; }
+ public double Amount
+ {
+ get => this.amount;
+ set => this.amount = Math.Max(value, 0);
+ }
///
public PipelineBuilder AppendToPipeline(PipelineBuilder builder)
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/CrossFadeEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/CrossFadeEffect.cs
new file mode 100644
index 00000000000..8bd4d183f55
--- /dev/null
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/CrossFadeEffect.cs
@@ -0,0 +1,53 @@
+// 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 System.Collections.Generic;
+using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
+using Windows.UI.Xaml.Markup;
+
+namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
+{
+ ///
+ /// A blend effect that merges the current builder with an input one
+ ///
+ /// This effect maps to the Win2D effect
+ [ContentProperty(Name = nameof(Effects))]
+ public sealed class CrossFadeEffect : IPipelineEffect
+ {
+ ///
+ /// Gets or sets the input to merge with the current instance (defaults to a with source).
+ ///
+ 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();
+
+ private double factor = 0.5;
+
+ ///
+ /// Gets or sets the The cross fade factor to blend the input effects (default to 0.5, should be in the [0, 1] range)
+ ///
+ public double Factor
+ {
+ get => this.factor;
+ set => this.factor = Math.Clamp(value, 0, 1);
+ }
+
+ ///
+ public PipelineBuilder AppendToPipeline(PipelineBuilder builder)
+ {
+ PipelineBuilder inputBuilder = Source ?? PipelineBuilder.FromBackdrop();
+
+ foreach (IPipelineEffect effect in this.Effects)
+ {
+ inputBuilder = effect.AppendToPipeline(inputBuilder);
+ }
+
+ return builder.CrossFade(inputBuilder, (float)Factor);
+ }
+ }
+}
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/ExposureEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/ExposureEffect.cs
index 0fd847584e8..eeb6a708f8c 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/ExposureEffect.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/ExposureEffect.cs
@@ -2,6 +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 System;
using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
@@ -12,10 +13,16 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
/// This effect maps to the Win2D effect
public sealed class ExposureEffect : IPipelineEffect
{
+ private double amount;
+
///
/// 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 double Amount
+ {
+ get => this.amount;
+ set => this.amount = Math.Clamp(value, -2, 2);
+ }
///
public PipelineBuilder AppendToPipeline(PipelineBuilder builder)
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/Extensions/AcrylicSourceExtension.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/Extensions/AcrylicSourceExtension.cs
index 0cec9ce4017..ce9f0fd7f4f 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/Extensions/AcrylicSourceExtension.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/Extensions/AcrylicSourceExtension.cs
@@ -22,21 +22,33 @@ public sealed class AcrylicSourceExtension : MarkupExtension
///
public AcrylicBackgroundSource BackgroundSource { get; set; } = AcrylicBackgroundSource.Backdrop;
+ private double blurAmount;
+
///
- /// Gets or sets the blur amount for the effect
+ /// Gets or sets the blur amount for the effect (must be a positive value)
///
/// This property is ignored when the active mode is
- public double BlurAmount { get; set; }
+ public double BlurAmount
+ {
+ get => this.blurAmount;
+ set => this.blurAmount = Math.Max(value, 0);
+ }
///
/// Gets or sets the tint for the effect
///
public Color TintColor { get; set; }
+ private double tintOpacity = 0.5f;
+
///
- /// Gets or sets the color for the tint effect
+ /// Gets or sets the color for the tint effect (default is 0.5, must be in the [0, 1] range)
///
- public double TintOpacity { get; set; }
+ public double TintOpacity
+ {
+ get => this.tintOpacity;
+ set => this.tintOpacity = Math.Clamp(value, 0, 1);
+ }
///
/// Gets or sets the to the texture to use
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/OpacityEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/OpacityEffect.cs
index 1535e58d025..82b8ea33c56 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/OpacityEffect.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/OpacityEffect.cs
@@ -2,6 +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 System;
using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
@@ -12,10 +13,16 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
/// This effect maps to the Win2D effect
public sealed class OpacityEffect : IPipelineEffect
{
+ private double value = 1;
+
///
/// 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 double Value
+ {
+ get => this.value;
+ set => this.value = Math.Clamp(value, 0, 1);
+ }
///
public PipelineBuilder AppendToPipeline(PipelineBuilder builder)
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/SaturationEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/SaturationEffect.cs
index 1ed8f924079..cce6eee390f 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/SaturationEffect.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/SaturationEffect.cs
@@ -2,6 +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 System;
using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
@@ -12,10 +13,16 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
/// This effect maps to the Win2D effect
public sealed class SaturationEffect : IPipelineEffect
{
+ private double value = 1;
+
///
/// 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 double Value
+ {
+ get => this.value;
+ set => this.value = Math.Clamp(value, 0, 1);
+ }
///
public PipelineBuilder AppendToPipeline(PipelineBuilder builder)
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/SepiaEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/SepiaEffect.cs
index 3dea7a9e361..8e3039d0980 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/SepiaEffect.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/SepiaEffect.cs
@@ -2,6 +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 System;
using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
@@ -12,10 +13,16 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
/// This effect maps to the Win2D effect
public sealed class SepiaEffect : IPipelineEffect
{
+ private double intensity = 0.5;
+
///
/// 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 double Intensity
+ {
+ get => this.intensity;
+ set => this.intensity = Math.Clamp(value, 0, 1);
+ }
///
public PipelineBuilder AppendToPipeline(PipelineBuilder builder)
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/ShadeEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/ShadeEffect.cs
index d4575d226b8..4b6e0debe2d 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/ShadeEffect.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/ShadeEffect.cs
@@ -2,6 +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 System;
using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
using Windows.UI;
@@ -17,10 +18,16 @@ public sealed class ShadeEffect : IPipelineEffect
///
public Color Color { get; set; }
+ private double intensity = 0.5;
+
///
- /// Gets or sets the intensity of the color layer
+ /// Gets or sets the intensity of the color layer (default to 0.5, should be in the [0, 1] range)
///
- public double Intensity { get; set; }
+ public double Intensity
+ {
+ get => this.intensity;
+ set => this.intensity = Math.Clamp(value, 0, 1);
+ }
///
public PipelineBuilder AppendToPipeline(PipelineBuilder builder)
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/TemperatureAndTintEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/TemperatureAndTintEffect.cs
index 6fb4b42afc4..2c31cbe1c65 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/TemperatureAndTintEffect.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/TemperatureAndTintEffect.cs
@@ -2,6 +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 System;
using Microsoft.Toolkit.Uwp.UI.Media.Pipelines;
namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
@@ -12,15 +13,27 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
/// This effect maps to the Win2D effect
public sealed class TemperatureAndTintEffect : IPipelineEffect
{
+ private double temperature;
+
///
- /// Gets or sets the value of the temperature for the current effect
+ /// Gets or sets the value of the temperature for the current effect (defaults to 0, should be in the [-1, 1] range)
///
- public double Temperature { get; set; }
+ public double Temperature
+ {
+ get => this.temperature;
+ set => this.temperature = Math.Clamp(value, -1, 1);
+ }
+
+ private double tint;
///
- /// Gets or sets the value of the tint for the current effect
+ /// Gets or sets the value of the tint for the current effect (defaults to 0, should be in the [-1, 1] range)
///
- public double Tint { get; set; }
+ public double Tint
+ {
+ get => this.tint;
+ set => this.tint = Math.Clamp(value, -1, 1);
+ }
///
public PipelineBuilder AppendToPipeline(PipelineBuilder builder)
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Effects.cs b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Effects.cs
index 4011fb7d691..96529ce540b 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Effects.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Effects.cs
@@ -98,7 +98,7 @@ public PipelineBuilder Blur(float blur, out EffectAnimation animation, Ef
///
/// Adds a new to the current pipeline
///
- /// The saturation amount for the new effect
+ /// The saturation amount for the new effect (should be in the [0, 1] range)
/// A new instance to use to keep adding new effects
[Pure]
public PipelineBuilder Saturation(float saturation)
@@ -115,7 +115,7 @@ public PipelineBuilder Saturation(float saturation)
///
/// Adds a new to the current pipeline
///
- /// The initial saturation amount for the new effect
+ /// The initial saturation amount for the new effect (should be in the [0, 1] range)
/// The optional saturation setter for the effect
/// A new instance to use to keep adding new effects
[Pure]
@@ -138,7 +138,7 @@ public PipelineBuilder Saturation(float saturation, out EffectSetter sett
///
/// Adds a new to the current pipeline
///
- /// The initial saturation amount for the new effect
+ /// The initial saturation amount for the new effect (should be in the [0, 1] range)
/// The optional saturation animation for the effect
/// A new instance to use to keep adding new effects
[Pure]
@@ -287,7 +287,7 @@ public PipelineBuilder Opacity(float opacity, out EffectAnimation animati
///
/// Applies an exposure effect on the current pipeline
///
- /// The amount of exposure to apply over the current effect
+ /// The amount of exposure to apply over the current effect (should be in the [-2, 2] range)
/// A new instance to use to keep adding new effects
[Pure]
public PipelineBuilder Exposure(float amount)
@@ -304,7 +304,7 @@ public PipelineBuilder Exposure(float amount)
///
/// Applies an exposure effect on the current pipeline
///
- /// The initial exposure of tint to apply over the current effect
+ /// The initial exposure of tint to apply over the current effect (should be in the [-2, 2] range)
/// The optional amount setter for the effect
/// A new instance to use to keep adding new effects
[Pure]
@@ -327,7 +327,7 @@ public PipelineBuilder Exposure(float amount, out EffectSetter setter)
///
/// Applies an exposure effect on the current pipeline
///
- /// The initial exposure of tint to apply over the current effect
+ /// The initial exposure of tint to apply over the current effect (should be in the [-2, 2] range)
/// The optional amount animation for the effect
/// A new instance to use to keep adding new effects
[Pure]
@@ -476,8 +476,8 @@ public PipelineBuilder Tint(Color color, out EffectAnimation animation)
///
/// Applies a temperature and tint effect on the current pipeline
///
- /// The temperature value to use
- /// The tint value to use
+ /// The temperature value to use (should be in the [-1, 1] range)
+ /// The tint value to use (should be in the [-1, 1] range)
/// A new instance to use to keep adding new effects
[Pure]
public PipelineBuilder TemperatureAndTint(float temperature, float tint)
@@ -495,9 +495,9 @@ public PipelineBuilder TemperatureAndTint(float temperature, float tint)
///
/// Applies a temperature and tint effect on the current pipeline
///
- /// The temperature value to use
+ /// The temperature value to use (should be in the [-1, 1] range)
/// The optional temperature setter for the effect
- /// The tint value to use
+ /// The tint value to use (should be in the [-1, 1] range)
/// The optional tint setter for the effect
/// A new instance to use to keep adding new effects
[Pure]
@@ -527,9 +527,9 @@ public PipelineBuilder TemperatureAndTint(
///
/// Applies a temperature and tint effect on the current pipeline
///
- /// The temperature value to use
+ /// The temperature value to use (should be in the [-1, 1] range)
/// The optional temperature animation for the effect
- /// The tint value to use
+ /// The tint value to use (should be in the [-1, 1] range)
/// The optional tint animation for the effect
/// A new instance to use to keep adding new effects
[Pure]
@@ -560,7 +560,7 @@ public PipelineBuilder TemperatureAndTint(
/// Applies a shade effect on the current pipeline
///
/// The color to use
- /// The amount of mix to apply over the current effect
+ /// The amount of mix to apply over the current effect (must be in the [0, 1] range)
/// A new instance to use to keep adding new effects
[Pure]
public PipelineBuilder Shade(Color color, float mix)
@@ -573,7 +573,7 @@ public PipelineBuilder Shade(Color color, float mix)
///
/// The color to use
/// The optional color setter for the effect
- /// The initial amount of mix to apply over the current effect
+ /// The initial amount of mix to apply over the current effect (must be in the [0, 1] range)
/// The optional mix setter for the effect
/// A new instance to use to keep adding new effects
[Pure]
@@ -591,7 +591,7 @@ public PipelineBuilder Shade(
///
/// The color to use
/// The optional color animation for the effect
- /// The initial amount of mix to apply over the current effect
+ /// The initial amount of mix to apply over the current effect (must be in the [0, 1] range)
/// The optional mix animation for the effect
/// A new instance to use to keep adding new effects
[Pure]
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Merge.cs b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Merge.cs
index 56b8fcb1938..9caba936497 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Merge.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Merge.cs
@@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
-using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Threading.Tasks;
@@ -20,126 +19,100 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Pipelines
///
public sealed partial class PipelineBuilder
{
- ///
- /// Gets the aligned pipelines to merge for a given operation
- ///
- /// The left pipeline to merge
- /// The right pipeline to merge
- /// The placemeht to use with the two input pipelines
- /// A instance with the aligned pipelines
- [Pure]
- [SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1008", Justification = "ValueTuple return type")]
- private static (PipelineBuilder Foreground, PipelineBuilder Background) GetMergePipeline(
- PipelineBuilder left,
- PipelineBuilder right,
- Placement placement)
- {
- return placement switch
- {
- Placement.Foreground => (left, right),
- Placement.Background => (right, left),
- _ => throw new ArgumentException($"Invalid placement value: {placement}")
- };
- }
-
///
/// Blends two pipelines using a instance with the specified mode
///
/// The second instance to blend
/// The desired to use to blend the input pipelines
- /// The placemeht to use with the two input pipelines
+ /// The placemeht to use with the two input pipelines (the default is )
/// A new instance to use to keep adding new effects
[Pure]
public PipelineBuilder Blend(PipelineBuilder pipeline, BlendEffectMode mode, Placement placement = Placement.Foreground)
{
- var pipelines = GetMergePipeline(this, pipeline, placement);
+ var (foreground, background) = placement switch
+ {
+ Placement.Foreground => (pipeline, this),
+ Placement.Background => (this, pipeline),
+ _ => throw new ArgumentException($"Invalid placement value: {placement}")
+ };
async ValueTask Factory() => new BlendEffect
{
- Foreground = await pipelines.Foreground.sourceProducer(),
- Background = await pipelines.Background.sourceProducer(),
+ Foreground = await foreground.sourceProducer(),
+ Background = await background.sourceProducer(),
Mode = mode
};
- return new PipelineBuilder(Factory, pipelines.Foreground, pipelines.Background);
+ return new PipelineBuilder(Factory, foreground, background);
}
///
/// Cross fades two pipelines using an instance
///
/// The second instance to cross fade
- /// The cross fade factor to blend the input effects
- /// The placement to use with the two input pipelines
+ /// The cross fade factor to blend the input effects (default is 0.5, must be in the [0, 1] range)
/// A new instance to use to keep adding new effects
[Pure]
- public PipelineBuilder CrossFade(PipelineBuilder pipeline, float factor = 0.5f, Placement placement = Placement.Foreground)
+ public PipelineBuilder CrossFade(PipelineBuilder pipeline, float factor = 0.5f)
{
- var pipelines = GetMergePipeline(this, pipeline, placement);
-
async ValueTask Factory() => new CrossFadeEffect
{
CrossFade = factor,
- Source1 = await pipelines.Foreground.sourceProducer(),
- Source2 = await pipelines.Background.sourceProducer()
+ Source1 = await this.sourceProducer(),
+ Source2 = await pipeline.sourceProducer()
};
- return new PipelineBuilder(Factory, pipelines.Foreground, pipelines.Background);
+ return new PipelineBuilder(Factory, this, pipeline);
}
///
/// Cross fades two pipelines using an instance
///
/// The second instance to cross fade
- /// The cross fade factor to blend the input effects
+ /// The cross fade factor to blend the input effects (should be in the [0, 1] range)
/// The optional blur setter for the effect
- /// The placement to use with the two input pipelines
/// A new instance to use to keep adding new effects
[Pure]
- public PipelineBuilder CrossFade(PipelineBuilder pipeline, float factor, out EffectSetter setter, Placement placement = Placement.Foreground)
+ public PipelineBuilder CrossFade(PipelineBuilder pipeline, float factor, out EffectSetter setter)
{
- var pipelines = GetMergePipeline(this, pipeline, placement);
-
string id = Guid.NewGuid().ToUppercaseAsciiLetters();
async ValueTask Factory() => new CrossFadeEffect
{
CrossFade = factor,
- Source1 = await pipelines.Foreground.sourceProducer(),
- Source2 = await pipelines.Background.sourceProducer(),
+ Source1 = await this.sourceProducer(),
+ Source2 = await pipeline.sourceProducer(),
Name = id
};
setter = (brush, value) => brush.Properties.InsertScalar($"{id}.{nameof(CrossFadeEffect.CrossFade)}", value);
- return new PipelineBuilder(Factory, pipelines.Foreground, pipelines.Background, new[] { $"{id}.{nameof(CrossFadeEffect.CrossFade)}" });
+ return new PipelineBuilder(Factory, this, pipeline, new[] { $"{id}.{nameof(CrossFadeEffect.CrossFade)}" });
}
///
/// Cross fades two pipelines using an instance
///
/// The second instance to cross fade
- /// The cross fade factor to blend the input effects
+ /// The cross fade factor to blend the input effects (should be in the [0, 1] range)
/// The optional blur animation for the effect
- /// The placement to use with the two input pipelines
/// A new instance to use to keep adding new effects
[Pure]
- public PipelineBuilder CrossFade(PipelineBuilder pipeline, float factor, out EffectAnimation animation, Placement placement = Placement.Foreground)
+ public PipelineBuilder CrossFade(PipelineBuilder pipeline, float factor, out EffectAnimation animation)
{
- var pipelines = GetMergePipeline(this, pipeline, placement);
-
string id = Guid.NewGuid().ToUppercaseAsciiLetters();
async ValueTask Factory() => new CrossFadeEffect
{
CrossFade = factor,
- Source1 = await pipelines.Foreground.sourceProducer(),
- Source2 = await pipelines.Background.sourceProducer(),
+ Source1 = await this.sourceProducer(),
+ Source2 = await pipeline.sourceProducer(),
Name = id
};
animation = (brush, value, duration) => brush.StartAnimationAsync($"{id}.{nameof(CrossFadeEffect.CrossFade)}", value, duration);
- return new PipelineBuilder(Factory, pipelines.Foreground, pipelines.Background, new[] { $"{id}.{nameof(CrossFadeEffect.CrossFade)}" });
+ return new PipelineBuilder(Factory, this, pipeline, new[] { $"{id}.{nameof(CrossFadeEffect.CrossFade)}" });
}
///
diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Prebuilt.cs b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Prebuilt.cs
index 52ef3f2d1b1..f1ec4ccf407 100644
--- a/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Prebuilt.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Prebuilt.cs
@@ -116,7 +116,7 @@ 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 tint to apply over the current effect (must be in the [0, 1] range)
/// 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
@@ -129,10 +129,7 @@ public static PipelineBuilder FromBackdropAcrylic(
Uri noiseUri,
CacheMode cacheMode = CacheMode.Default)
{
- var pipeline =
- FromBackdrop()
- .Shade(tintColor, tintOpacity)
- .Blur(blurAmount);
+ var pipeline = FromBackdrop().Shade(tintColor, tintOpacity).Blur(blurAmount);
if (noiseUri != null)
{