Skip to content

Commit

Permalink
Merge pull request #18 from Sergio0694/dev
Browse files Browse the repository at this point in the history
New pipeline effects and brush properties
  • Loading branch information
Sergio0694 authored Jun 14, 2019
2 parents e8d5e13 + ae3fda9 commit e32a205
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,28 @@ public abstract class XamlCompositionEffectBrushBase : XamlCompositionBrushBase
[MustUseReturnValue, NotNull]
protected abstract PipelineBuilder OnBrushRequested();

private bool _IsEnabled = true;

/// <summary>
/// Gest or sets whether or not the current brush is using the provided pipeline, or the fallback color
/// </summary>
public bool IsEnabled
{
get => _IsEnabled;
set => OnEnabledToggled(value);
}

/// <inheritdoc/>
protected override async void OnConnected()
{
using (await ConnectedMutex.LockAsync())
{
if (CompositionBrush == null)
CompositionBrush = await OnBrushRequested().BuildAsync();
{
if (_IsEnabled) CompositionBrush = await OnBrushRequested().BuildAsync();
else CompositionBrush = await PipelineBuilder.FromColor(FallbackColor).BuildAsync();
}
}
base.OnConnected();
}

Expand All @@ -44,5 +60,24 @@ protected override async void OnDisconnected()
}
base.OnDisconnected();
}

/// <summary>
/// Updates the <see cref="XamlCompositionBrushBase.CompositionBrush"/> property depending on the input value
/// </summary>
/// <param name="value">The new value being set to the <see cref="IsEnabled"/> property</param>
protected async void OnEnabledToggled(bool value)
{
using (await ConnectedMutex.LockAsync())
{
if (_IsEnabled == value) return;
_IsEnabled = value;

if (CompositionBrush != null)
{
if (_IsEnabled) CompositionBrush = await OnBrushRequested().BuildAsync();
else CompositionBrush = await PipelineBuilder.FromColor(FallbackColor).BuildAsync();
}
}
}
}
}
39 changes: 39 additions & 0 deletions UICompositionAnimations/Brushes/Effects/AcrylicEffect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using Windows.UI;
using Windows.UI.Xaml.Media;
using UICompositionAnimations.Brushes.Effects.Interfaces;

namespace UICompositionAnimations.Brushes.Effects
{
/// <summary>
/// A custom acrylic effect that can be inserted into a pipeline
/// </summary>
public sealed class AcrylicEffect : IPipelineEffect
{
/// <summary>
/// Gets or sets the source mode for the effect
/// </summary>
public AcrylicBackgroundSource Source { get; set; }

/// <summary>
/// Gets or sets the blur amount for the effect
/// </summary>
/// <remarks>This property is ignored when the active mode is <see cref="AcrylicBackgroundSource.HostBackdrop"/></remarks>
public double BlurAmount { get; set; }

/// <summary>
/// Gets or sets the tint for the effect
/// </summary>
public Color Tint { get; set; }

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

/// <summary>
/// Gets or sets the <see cref="Uri"/> to the texture to use
/// </summary>
public Uri TextureUri { get; set; }
}
}
7 changes: 7 additions & 0 deletions UICompositionAnimations/Brushes/PipelineBrush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ PipelineBuilder Start(IPipelineEffect effect)
case SolidColorEffect color: return PipelineBuilder.FromColor(color.Color);
case ImageEffect image: return PipelineBuilder.FromImage(image.Uri, image.DPIMode, image.CacheMode);
case TileEffect tile: return PipelineBuilder.FromTiles(tile.Uri, tile.DPIMode, tile.CacheMode);
case AcrylicEffect acrylic:
switch (acrylic.Source)
{
case AcrylicBackgroundSource.Backdrop: return PipelineBuilder.FromBackdropAcrylic(acrylic.Tint, (float)acrylic.TintMix, (float)acrylic.BlurAmount, acrylic.TextureUri);
case AcrylicBackgroundSource.HostBackdrop: return PipelineBuilder.FromHostBackdropAcrylic(acrylic.Tint, (float)acrylic.TintMix, acrylic.TextureUri);
default: throw new ArgumentOutOfRangeException(nameof(acrylic.Source), $"Invalid acrylic source: {acrylic.Source}");
}
default: throw new ArgumentException($"Invalid initial pipeline effect: {effect.GetType()}");
}
}
Expand Down
6 changes: 3 additions & 3 deletions UICompositionAnimations/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("4.0.3.0")]
[assembly: AssemblyFileVersion("4.0.3.0")]
[assembly: AssemblyInformationalVersion("4.0.3")]
[assembly: AssemblyVersion("4.1.0.0")]
[assembly: AssemblyFileVersion("4.1.0.0")]
[assembly: AssemblyInformationalVersion("4.1.0")]
[assembly: ComVisible(false)]

1 change: 1 addition & 0 deletions UICompositionAnimations/UICompositionAnimations.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
<Compile Include="Brushes\AcrylicBrush.cs" />
<Compile Include="Brushes\Effects\Abstract\ImageEffectBase.cs" />
<Compile Include="Brushes\Effects\Abstract\ValueEffectBase.cs" />
<Compile Include="Brushes\Effects\AcrylicEffect.cs" />
<Compile Include="Brushes\Effects\BackdropEffect.cs" />
<Compile Include="Brushes\Effects\BlendEffect.cs" />
<Compile Include="Brushes\Effects\BlurEffect.cs" />
Expand Down
4 changes: 2 additions & 2 deletions UICompositionAnimations/UICompositionAnimations.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<package>
<metadata>
<id>UICompositionAnimations</id>
<version>4.0.3</version>
<version>4.1.0</version>
<title>UICompositionAnimations</title>
<description>A wrapper UWP PCL to work with Windows.UI.Composition and XAML animations, and Win2D effects</description>
<authors>Sergio Pedri</authors>
<owners>Sergio Pedri</owners>
<projectUrl>https://github.com/Sergio0694/UICompositionAnimations</projectUrl>
<license type="expression">GPL-3.0-only</license>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<releaseNotes>New extension APIs, more annotations</releaseNotes>
<releaseNotes>New composition brush APIs and pipeline effects</releaseNotes>
<copyright>Copyright © 2019</copyright>
<tags>uwp composition animations xaml csharp windows winrt universal app ui win2d graphics</tags>
<dependencies>
Expand Down

0 comments on commit e32a205

Please sign in to comment.