From 6bf4a7f6b97cb62e7553d97979fed754ca155269 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 27 May 2020 12:33:51 +0200 Subject: [PATCH 01/12] Added missing ContentProperty to BlendEffect --- Microsoft.Toolkit.Uwp.UI.Media/Effects/BlendEffect.cs | 2 ++ 1 file changed, 2 insertions(+) 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 { /// From c2e803fec8e963cd1e82f30811430aec6ffc9377 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 27 May 2020 12:55:25 +0200 Subject: [PATCH 02/12] Removed unnecessary placement parameter for cross fade --- .../Pipelines/PipelineBuilder.Merge.cs | 39 +++++++------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Merge.cs b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Merge.cs index 56b8fcb1938..fd74d032fb8 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Merge.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Merge.cs @@ -68,78 +68,69 @@ public PipelineBuilder Blend(PipelineBuilder pipeline, BlendEffectMode mode, Pla /// 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)}" }); } /// From b0a10e3a9c2eebb8f189eddd034afbbc1afa8bd5 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 27 May 2020 12:56:06 +0200 Subject: [PATCH 03/12] Added CrossFadeEffect type --- .../Effects/CrossFadeEffect.cs | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Microsoft.Toolkit.Uwp.UI.Media/Effects/CrossFadeEffect.cs 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..f4b91d9ab98 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/CrossFadeEffect.cs @@ -0,0 +1,46 @@ +// 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.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(); + + /// + /// 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; set; } = 0.5; + + /// + 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); + } + } +} From bfe9847d3af2545e0b6ad52decbc51cd02ac7edc Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 27 May 2020 12:56:22 +0200 Subject: [PATCH 04/12] Updated ShadeEffect default intensity value --- Microsoft.Toolkit.Uwp.UI.Media/Effects/ShadeEffect.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/ShadeEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/ShadeEffect.cs index d4575d226b8..8d9c784a71f 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/ShadeEffect.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/ShadeEffect.cs @@ -18,9 +18,9 @@ public sealed class ShadeEffect : IPipelineEffect public Color Color { get; set; } /// - /// 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; set; } = 0.5; /// public PipelineBuilder AppendToPipeline(PipelineBuilder builder) From 2c60f46b3006dc8a521e4a5018aca4de1e0cb866 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 27 May 2020 13:17:11 +0200 Subject: [PATCH 05/12] Inverted blend effect placement mode --- .../PipelineBrush/PipelineBrushXaml.bind | 4 +- .../Pipelines/PipelineBuilder.Merge.cs | 38 +++++-------------- 2 files changed, 12 insertions(+), 30 deletions(-) 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/Pipelines/PipelineBuilder.Merge.cs b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Merge.cs index fd74d032fb8..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,48 +19,31 @@ 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); } /// From 3fd58fb2231f7fe94f64afd37644581594beded4 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 27 May 2020 19:10:49 +0200 Subject: [PATCH 06/12] Added CrossFadeEffect to shallow copy page --- .../SamplePages/PipelineBrush/PipelineBrushPage.xaml | 1 + 1 file changed, 1 insertion(+) 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 @@ + From 387118eb7d0708ea9643191cdde7676231895ee4 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 27 May 2020 19:37:50 +0200 Subject: [PATCH 07/12] Improved XML docs --- .../Effects/TemperatureAndTintEffect.cs | 4 ++-- .../Pipelines/PipelineBuilder.Effects.cs | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/TemperatureAndTintEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/TemperatureAndTintEffect.cs index 6fb4b42afc4..f6936aa95bc 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/TemperatureAndTintEffect.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/TemperatureAndTintEffect.cs @@ -13,12 +13,12 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Effects public sealed class TemperatureAndTintEffect : IPipelineEffect { /// - /// 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; } /// - /// 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; } diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Effects.cs b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Effects.cs index 4011fb7d691..d271117cd1a 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Effects.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Effects.cs @@ -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] From cbbe4ed340329c52e16a987d4d4032a67434b3c3 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 28 May 2020 00:49:39 +0200 Subject: [PATCH 08/12] Added clamping for XAML effects for Win2D --- .../Effects/BlurEffect.cs | 11 ++++++++-- .../Effects/CrossFadeEffect.cs | 9 ++++++++- .../Effects/ExposureEffect.cs | 9 ++++++++- .../Extensions/AcrylicSourceExtension.cs | 20 +++++++++++++++---- .../Effects/OpacityEffect.cs | 9 ++++++++- .../Effects/SaturationEffect.cs | 9 ++++++++- .../Effects/SepiaEffect.cs | 9 ++++++++- .../Effects/ShadeEffect.cs | 9 ++++++++- .../Effects/TemperatureAndTintEffect.cs | 17 ++++++++++++++-- .../Pipelines/PipelineBuilder.Effects.cs | 12 +++++------ .../Pipelines/PipelineBuilder.Prebuilt.cs | 7 ++----- 11 files changed, 96 insertions(+), 25 deletions(-) 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 index f4b91d9ab98..8bd4d183f55 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/CrossFadeEffect.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/CrossFadeEffect.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 System.Collections.Generic; using Microsoft.Toolkit.Uwp.UI.Media.Pipelines; using Windows.UI.Xaml.Markup; @@ -25,10 +26,16 @@ public sealed class CrossFadeEffect : IPipelineEffect /// 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; set; } = 0.5; + public double Factor + { + get => this.factor; + set => this.factor = Math.Clamp(value, 0, 1); + } /// public PipelineBuilder AppendToPipeline(PipelineBuilder builder) 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..d36d944d6d0 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; + /// /// 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 8d9c784a71f..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 (default 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/TemperatureAndTintEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/TemperatureAndTintEffect.cs index f6936aa95bc..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 (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 (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 d271117cd1a..e012c5354d2 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] @@ -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.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) { From d7ce5150508a545245dece39fe2cd79a5ea97f92 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 28 May 2020 16:17:02 +0200 Subject: [PATCH 09/12] Added auto clamping for AcrylicBrush tint opacity --- Microsoft.Toolkit.Uwp.UI.Media/Brushes/AcrylicBrush.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/AcrylicBrush.cs b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/AcrylicBrush.cs index b0de6c15f72..4af10285189 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/AcrylicBrush.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/AcrylicBrush.cs @@ -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 From 762e51014ddd5ae792ac19b919286ddcc587d1c3 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 28 May 2020 16:19:27 +0200 Subject: [PATCH 10/12] Clamped AcrylicBrush blur property for negative value --- Microsoft.Toolkit.Uwp.UI.Media/Brushes/AcrylicBrush.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Brushes/AcrylicBrush.cs b/Microsoft.Toolkit.Uwp.UI.Media/Brushes/AcrylicBrush.cs index 4af10285189..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)); } /// From a376298c110413c2a4f67ef627370fca5437629b Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 29 May 2020 12:48:48 +0200 Subject: [PATCH 11/12] Fixed default value for OpacityEffect Co-authored-by: Alexandre Zollinger Chohfi --- Microsoft.Toolkit.Uwp.UI.Media/Effects/OpacityEffect.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Effects/OpacityEffect.cs b/Microsoft.Toolkit.Uwp.UI.Media/Effects/OpacityEffect.cs index d36d944d6d0..82b8ea33c56 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Effects/OpacityEffect.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Effects/OpacityEffect.cs @@ -13,7 +13,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Effects /// This effect maps to the Win2D effect public sealed class OpacityEffect : IPipelineEffect { - private double value; + 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). From 86b80d1697b43a5a51edb7e789215e1edfaeb053 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 29 May 2020 12:49:59 +0200 Subject: [PATCH 12/12] Added ranges in XML docs for exposure effect --- .../Pipelines/PipelineBuilder.Effects.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Effects.cs b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Effects.cs index e012c5354d2..96529ce540b 100644 --- a/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Effects.cs +++ b/Microsoft.Toolkit.Uwp.UI.Media/Pipelines/PipelineBuilder.Effects.cs @@ -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]