Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PipelineBrush and effects refactoring #3298

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
afa5047
Merge pull request #10 from windows-toolkit/master
Sergio0694 Mar 15, 2020
e8cd4f7
Merge pull request #18 from windows-toolkit/master
Sergio0694 Mar 27, 2020
cbc80ef
Merge pull request #19 from windows-toolkit/master
Sergio0694 Apr 3, 2020
4079a75
Merge remote-tracking branch 'upstream/master' into master2
Sergio0694 Apr 9, 2020
f0b5bf0
Merge remote-tracking branch 'upstream/master' into master2
Sergio0694 Apr 23, 2020
6129c69
Merge remote-tracking branch 'upstream/master' into master2
Sergio0694 Apr 30, 2020
fdaa307
Merge remote-tracking branch 'upstream/master' into master2
Sergio0694 May 6, 2020
db41e0d
Merge remote-tracking branch 'upstream/master' into master2
Sergio0694 May 13, 2020
6bb8323
Merge remote-tracking branch 'upstream/master' into master2
Sergio0694 May 16, 2020
b5029a7
Merge remote-tracking branch 'upstream/master' into master2
Sergio0694 May 18, 2020
8de5d11
Merge remote-tracking branch 'upstream/master' into master2
Sergio0694 May 20, 2020
d18b5b2
Code refactoring
Sergio0694 May 23, 2020
7c36d47
Code refactoring to Win2D effect mappings
Sergio0694 May 23, 2020
aefd351
Minor refactoring
Sergio0694 May 23, 2020
dbcfe5d
Updated sample page XAML code
Sergio0694 May 23, 2020
856a0e7
More code refactoring
Sergio0694 May 23, 2020
ed33efb
Removed Abstract namespace, code refactoring
Sergio0694 May 23, 2020
bec2112
Removed unnecessary async state machine
Sergio0694 May 24, 2020
99508b6
Renamed IPipeline[Input|Node] interfaces
Sergio0694 May 24, 2020
091fcab
Renamed input effects to source effects
Sergio0694 May 24, 2020
8e40ae4
Refactored inputs to markup extensions
Sergio0694 May 25, 2020
c5ad88d
Renamed some APIs for consistency
Sergio0694 May 25, 2020
8184cc6
More renames
Sergio0694 May 25, 2020
ebeaf78
Simplified code, improved XML docs
Sergio0694 May 25, 2020
3d415ff
Fixed XML comment reference
Sergio0694 May 25, 2020
43989a1
Set default backdrop source to backdrop
Sergio0694 May 25, 2020
31644bf
Fixed incorrect property
Sergio0694 May 25, 2020
c9c08f4
Renamed some parameter for consistency
Sergio0694 May 25, 2020
638b648
Updated PipelineBrush sample code
Sergio0694 May 25, 2020
0db6b4c
Merge branch 'master' into refactoring/win2d-apis
Sergio0694 May 26, 2020
b2d193c
Merge branch 'master' into refactoring/win2d-apis
Sergio0694 May 26, 2020
cb5f9fc
Added default pipeline/blend sources
Sergio0694 May 26, 2020
8db80ea
Merge branch 'master' into refactoring/win2d-apis
Sergio0694 May 26, 2020
1becb7a
Removed .Base namespace
Sergio0694 May 26, 2020
6b1d27c
Merge branch 'master' into refactoring/win2d-apis
Sergio0694 May 26, 2020
c38640c
Updated AcrylicBrush sample page
Sergio0694 May 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
Grid.Column="2"
Height="400">
<Border.Background>
<brushes:PipelineBrush Source="{effects:BackdropSource BackgroundSource=Backdrop}">
<brushes:PipelineBrush Source="{effects:BackdropSource}">
michael-hawker marked this conversation as resolved.
Show resolved Hide resolved
michael-hawker marked this conversation as resolved.
Show resolved Hide resolved
<effects:LuminanceToAlphaEffect/>
<effects:OpacityEffect Value="0.4"/>
<effects:BlendEffect Mode="Multiply" Source="{effects:BackdropSource BackgroundSource=Backdrop}"/>
<effects:BlendEffect Mode="Multiply" Source="{effects:BackdropSource}"/>
<effects:BlurEffect Amount="16"/>
<effects:ShadeEffect Color="#FF222222" Intensity="0.2"/>
<effects:BlendEffect Mode="Overlay" Placement="Background" Source="{effects:TileSource Uri=ms-appx:///Assets/BrushAssets/NoiseTexture.png}"/>
Expand Down
70 changes: 37 additions & 33 deletions Microsoft.Toolkit.Uwp.UI.Media/Brushes/AcrylicBrush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public sealed class AcrylicBrush : XamlCompositionEffectBrushBase
/// <summary>
/// The <see cref="EffectSetter{T}"/> instance in use to set the tint color
/// </summary>
private EffectSetter<Color> tintSetter;
private EffectSetter<Color> tintColorSetter;

/// <summary>
/// The <see cref="EffectSetter{T}"/> instance in use to set the tint mix amount
/// </summary>
private EffectSetter<float> tintMixSetter;
private EffectSetter<float> tintOpacitySetter;

/// <summary>
/// Gets or sets the source mode for the effect
/// Gets or sets the background source mode for the effect (the default is <see cref="AcrylicBackgroundSource.Backdrop"/>).
/// </summary>
public AcrylicBackgroundSource BackgroundSource
michael-hawker marked this conversation as resolved.
Show resolved Hide resolved
{
Expand Down Expand Up @@ -103,60 +103,64 @@ private static void OnBlurAmountPropertyChanged(DependencyObject d, DependencyPr
/// <summary>
/// Gets or sets the tint for the effect
/// </summary>
public Color Tint
public Color TintColor
{
get => (Color)GetValue(TintProperty);
set => SetValue(TintProperty, value);
get => (Color)GetValue(TintColorProperty);
set => SetValue(TintColorProperty, value);
}

/// <summary>
/// Identifies the <see cref="Tint"/> dependency property.
/// Identifies the <see cref="TintColor"/> dependency property.
/// </summary>
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));

/// <summary>
/// Updates the UI when <see cref="Tint"/> changes
/// Updates the UI when <see cref="TintColor"/> changes
/// </summary>
/// <param name="d">The current <see cref="AcrylicBrush"/> instance</param>
/// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance for <see cref="TintProperty"/></param>
private static void OnTintPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
/// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance for <see cref="TintColorProperty"/></param>
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);
}
}

/// <summary>
/// Gets or sets the tint mix factor for the effect
/// Gets or sets the tint opacity factor for the effect
/// </summary>
public double TintMix { get; set; }
public double TintOpacity
{
get => (double)GetValue(TintOpacityProperty);
set => SetValue(TintOpacityProperty, value);
}

/// <summary>
/// Identifies the <see cref="TintMix"/> dependency property.
/// Identifies the <see cref="TintOpacity"/> dependency property.
/// </summary>
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));

/// <summary>
/// Updates the UI when <see cref="TintMix"/> changes
/// Updates the UI when <see cref="TintOpacity"/> changes
/// </summary>
/// <param name="d">The current <see cref="AcrylicBrush"/> instance</param>
/// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance for <see cref="TintMixProperty"/></param>
private static void OnTintMixPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
/// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance for <see cref="TintOpacityProperty"/></param>
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);
}
}

Expand Down Expand Up @@ -200,19 +204,19 @@ protected override PipelineBuilder OnBrushRequested()
{
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(BackgroundSource), $"Invalid acrylic source: {BackgroundSource}");
}
Expand Down
6 changes: 3 additions & 3 deletions Microsoft.Toolkit.Uwp.UI.Media/Brushes/BackdropBlurBrush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class BackdropBlurBrush : XamlCompositionEffectBrushBase
/// <summary>
/// The <see cref="EffectSetter{T}"/> instance currently in use
/// </summary>
private EffectSetter<float> setter;
private EffectSetter<float> amountSetter;

/// <summary>
/// Gets or sets the amount of gaussian blur to apply to the background.
Expand Down Expand Up @@ -50,14 +50,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);
}
}

/// <inheritdoc/>
protected override PipelineBuilder OnBrushRequested()
{
return PipelineBuilder.FromBackdrop().Blur((float)Amount, out setter);
return PipelineBuilder.FromBackdrop().Blur((float)Amount, out this.amountSetter);
}
}
}
2 changes: 1 addition & 1 deletion Microsoft.Toolkit.Uwp.UI.Media/Effects/BlendEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public sealed class BlendEffect : IPipelineEffect
public ImageBlendMode Mode { get; set; }

/// <summary>
/// Gets or sets the placement of the input builder with respect to the current one (the default is <see cref="Placement.Foreground"/>)
/// Gets or sets the placement of the input builder with respect to the current one (the default is <see cref="Media.Placement.Foreground"/>)
/// </summary>
public Placement Placement { get; set; } = Placement.Foreground;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
public sealed class AcrylicSourceExtension : MarkupExtension
{
/// <summary>
/// Gets or sets the background source mode for the effect
/// Gets or sets the background source mode for the effect (the default is <see cref="AcrylicBackgroundSource.Backdrop"/>).
/// </summary>
public AcrylicBackgroundSource BackgroundSource { get; set; }
public AcrylicBackgroundSource BackgroundSource { get; set; } = AcrylicBackgroundSource.Backdrop;

/// <summary>
/// Gets or sets the blur amount for the effect
Expand All @@ -31,12 +31,12 @@ public sealed class AcrylicSourceExtension : MarkupExtension
/// <summary>
/// Gets or sets the tint for the effect
/// </summary>
public Color Tint { get; set; }
public Color TintColor { get; set; }

/// <summary>
/// Gets or sets the color for the tint effect
/// </summary>
public double TintMix { get; set; }
public double TintOpacity { get; set; }

/// <summary>
/// Gets or sets the <see cref="Uri"/> to the texture to use
Expand All @@ -48,8 +48,8 @@ protected override object ProvideValue()
{
return BackgroundSource switch
{
AcrylicBackgroundSource.Backdrop => PipelineBuilder.FromBackdropAcrylic(Tint, (float)TintMix, (float)BlurAmount, TextureUri),
AcrylicBackgroundSource.HostBackdrop => PipelineBuilder.FromHostBackdropAcrylic(Tint, (float)TintMix, TextureUri),
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}")
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ namespace Microsoft.Toolkit.Uwp.UI.Media.Effects
public sealed class BackdropSourceExtension : MarkupExtension
{
/// <summary>
/// Gets or sets the backdrop source to use to render the effect
/// Gets or sets the background source mode for the effect (the default is <see cref="AcrylicBackgroundSource.Backdrop"/>).
/// </summary>
public AcrylicBackgroundSource BackgroundSource { get; set; }
public AcrylicBackgroundSource BackgroundSource { get; set; } = AcrylicBackgroundSource.Backdrop;

/// <inheritdoc/>
protected override object ProvideValue()
Expand Down
Loading