-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Sergio0694/feature_pipeline-brush
Added new PipelineBrush API
- Loading branch information
Showing
19 changed files
with
305 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
UICompositionAnimations/Behaviours/Xaml/Effects/Abstract/ImageEffectBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using UICompositionAnimations.Enums; | ||
|
||
namespace UICompositionAnimations.Behaviours.Xaml.Effects.Abstract | ||
{ | ||
/// <summary> | ||
/// An image based effect that loads an image at the specified location | ||
/// </summary> | ||
public abstract class ImageEffectBase : IPipelineEffect | ||
{ | ||
/// <summary> | ||
/// Gets or sets the <see cref="System.Uri"/> for the image to load | ||
/// </summary> | ||
public Uri Uri { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the DPI mode used to render the image (the default is <see cref="BitmapDPIMode.CopyDisplayDPISettingsWith96AsLowerBound"/>) | ||
/// </summary> | ||
public BitmapDPIMode DPIMode { get; set; } = BitmapDPIMode.CopyDisplayDPISettingsWith96AsLowerBound; | ||
|
||
/// <summary> | ||
/// Gets or sets the cache mode to use when loading the image (the default is <see cref="BitmapCacheMode.Default"/>) | ||
/// </summary> | ||
public BitmapCacheMode CacheMode { get; set; } = BitmapCacheMode.Default; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
UICompositionAnimations/Behaviours/Xaml/Effects/Abstract/ValueEffectBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace UICompositionAnimations.Behaviours.Xaml.Effects.Abstract | ||
{ | ||
/// <summary> | ||
/// A base <see langword="class"/> for an effect that exposes a single <see cref="float"/> parameter | ||
/// </summary> | ||
public abstract class ValueEffectBase : IPipelineEffect | ||
{ | ||
/// <summary> | ||
/// Gets or sets the value of the parameter for the current effect | ||
/// </summary> | ||
public double Value { get; set; } | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
UICompositionAnimations/Behaviours/Xaml/Effects/BackdropEffect.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Windows.UI.Xaml.Media; | ||
|
||
namespace UICompositionAnimations.Behaviours.Xaml.Effects | ||
{ | ||
/// <summary> | ||
/// A backdrop effect that can sample from a specified source | ||
/// </summary> | ||
public sealed class BackdropEffect : IPipelineEffect | ||
{ | ||
/// <summary> | ||
/// Gets or sets the backdrop source to use to render the effect | ||
/// </summary> | ||
public AcrylicBackgroundSource Source { get; set; } | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
UICompositionAnimations/Behaviours/Xaml/Effects/BlendEffect.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Collections.Generic; | ||
using JetBrains.Annotations; | ||
using Microsoft.Graphics.Canvas.Effects; | ||
using UICompositionAnimations.Enums; | ||
|
||
namespace UICompositionAnimations.Behaviours.Xaml.Effects | ||
{ | ||
/// <summary> | ||
/// A blend effect that merges the current pipeline with an input one | ||
/// </summary> | ||
public sealed class BlendEffect : IPipelineEffect | ||
{ | ||
/// <summary> | ||
/// Gets or sets the input pipeline to merge with the current instance | ||
/// </summary> | ||
[NotNull, ItemNotNull] | ||
public IList<IPipelineEffect> Input { get; set; } = new List<IPipelineEffect>(); | ||
|
||
/// <summary> | ||
/// Gets or sets the blending mode to use (the default mode is <see cref="BlendEffectMode.Multiply"/>) | ||
/// </summary> | ||
public BlendEffectMode Mode { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the placement of the input pipeline with respect to the current one (the default is <see cref="EffectPlacement.Foreground"/>) | ||
/// </summary> | ||
public EffectPlacement Placement { get; set; } = EffectPlacement.Foreground; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
UICompositionAnimations/Behaviours/Xaml/Effects/BlurEffect.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using UICompositionAnimations.Behaviours.Xaml.Effects.Abstract; | ||
|
||
namespace UICompositionAnimations.Behaviours.Xaml.Effects | ||
{ | ||
/// <summary> | ||
/// A gaussian blur effect | ||
/// </summary> | ||
public sealed class BlurEffect : ValueEffectBase { } | ||
} |
9 changes: 9 additions & 0 deletions
9
UICompositionAnimations/Behaviours/Xaml/Effects/ImageEffect.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using UICompositionAnimations.Behaviours.Xaml.Effects.Abstract; | ||
|
||
namespace UICompositionAnimations.Behaviours.Xaml.Effects | ||
{ | ||
/// <summary> | ||
/// An image effect, which displays an image loaded as a Win2D surface | ||
/// </summary> | ||
public sealed class ImageEffect : ImageEffectBase { } | ||
} |
7 changes: 7 additions & 0 deletions
7
UICompositionAnimations/Behaviours/Xaml/Effects/LuminanceEffect.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace UICompositionAnimations.Behaviours.Xaml.Effects | ||
{ | ||
/// <summary> | ||
/// A luminance effect which directly replicates <see cref="Microsoft.Graphics.Canvas.Effects.LuminanceToAlphaEffect"/> | ||
/// </summary> | ||
public sealed class LuminanceEffect : IPipelineEffect { } | ||
} |
9 changes: 9 additions & 0 deletions
9
UICompositionAnimations/Behaviours/Xaml/Effects/OpacityEffect.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using UICompositionAnimations.Behaviours.Xaml.Effects.Abstract; | ||
|
||
namespace UICompositionAnimations.Behaviours.Xaml.Effects | ||
{ | ||
/// <summary> | ||
/// A simple opacity effect | ||
/// </summary> | ||
public sealed class OpacityEffect : ValueEffectBase { } | ||
} |
9 changes: 9 additions & 0 deletions
9
UICompositionAnimations/Behaviours/Xaml/Effects/SaturationEffect.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using UICompositionAnimations.Behaviours.Xaml.Effects.Abstract; | ||
|
||
namespace UICompositionAnimations.Behaviours.Xaml.Effects | ||
{ | ||
/// <summary> | ||
/// A saturation effect | ||
/// </summary> | ||
public sealed class SaturationEffect : ValueEffectBase { } | ||
} |
15 changes: 15 additions & 0 deletions
15
UICompositionAnimations/Behaviours/Xaml/Effects/SolidColorEffect.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Windows.UI; | ||
|
||
namespace UICompositionAnimations.Behaviours.Xaml.Effects | ||
{ | ||
/// <summary> | ||
/// A simple effect that renders a solid color on the available surface | ||
/// </summary> | ||
public sealed class SolidColorEffect : IPipelineEffect | ||
{ | ||
/// <summary> | ||
/// Gets or sets the color to display | ||
/// </summary> | ||
public Color Color { get; set; } | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
UICompositionAnimations/Behaviours/Xaml/Effects/TileEffect.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using UICompositionAnimations.Behaviours.Xaml.Effects.Abstract; | ||
|
||
namespace UICompositionAnimations.Behaviours.Xaml.Effects | ||
{ | ||
/// <summary> | ||
/// An effect that loads an image and replicates it to cover all the available surface area | ||
/// </summary> | ||
public sealed class TileEffect : ImageEffectBase { } | ||
} |
20 changes: 20 additions & 0 deletions
20
UICompositionAnimations/Behaviours/Xaml/Effects/TintEffect.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Windows.UI; | ||
|
||
namespace UICompositionAnimations.Behaviours.Xaml.Effects | ||
{ | ||
/// <summary> | ||
/// A tint effect with a customizable opacity | ||
/// </summary> | ||
public sealed class TintEffect : IPipelineEffect | ||
{ | ||
/// <summary> | ||
/// Gets or sets the tint color to use | ||
/// </summary> | ||
public Color Color { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the opacity of the tint effect | ||
/// </summary> | ||
public double Opacity { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace UICompositionAnimations.Behaviours.Xaml | ||
{ | ||
/// <summary> | ||
/// The base <see langword="interface"/> for all the pipeline effects to be used in a <see cref="PipelineBrush"/> | ||
/// </summary> | ||
public interface IPipelineEffect { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Windows.UI.Xaml.Media; | ||
using JetBrains.Annotations; | ||
using UICompositionAnimations.Behaviours.Xaml.Effects; | ||
using UICompositionAnimations.Brushes.Base; | ||
using LuminanceToAlphaEffect = Microsoft.Graphics.Canvas.Effects.LuminanceToAlphaEffect; | ||
|
||
namespace UICompositionAnimations.Behaviours.Xaml | ||
{ | ||
/// <summary> | ||
/// A <see cref="Brush"/> that renders a customizable Composition/Win2D effects pipeline | ||
/// </summary> | ||
public sealed class PipelineBrush : XamlCompositionEffectBrushBase | ||
{ | ||
/// <inheritdoc/> | ||
protected override CompositionBrushBuilder OnBrushRequested() | ||
{ | ||
// Starts a new composition pipeline from the given effect | ||
CompositionBrushBuilder Start(IPipelineEffect effect) | ||
{ | ||
switch (effect) | ||
{ | ||
case BackdropEffect backdrop when backdrop.Source == AcrylicBackgroundSource.Backdrop: | ||
return CompositionBrushBuilder.FromBackdropBrush(); | ||
case BackdropEffect backdrop when backdrop.Source == AcrylicBackgroundSource.HostBackdrop: | ||
return CompositionBrushBuilder.FromHostBackdropBrush(); | ||
case SolidColorEffect color: return CompositionBrushBuilder.FromColor(color.Color); | ||
case ImageEffect image: return CompositionBrushBuilder.FromImage(image.Uri, image.DPIMode, image.CacheMode); | ||
case TileEffect tile: return CompositionBrushBuilder.FromTiles(tile.Uri, tile.DPIMode, tile.CacheMode); | ||
default: throw new ArgumentException($"Invalid initial pipeline effect: {effect.GetType()}"); | ||
} | ||
} | ||
|
||
// Appends an effect to an existing composition pipeline | ||
CompositionBrushBuilder Append(IPipelineEffect effect, CompositionBrushBuilder builder) | ||
{ | ||
switch (effect) | ||
{ | ||
case OpacityEffect opacity: return builder.Opacity((float)opacity.Value); | ||
case LuminanceEffect _: return builder.Effect(source => new LuminanceToAlphaEffect { Source = source }); | ||
case TintEffect tint: return builder.Tint(tint.Color, (float)tint.Opacity); | ||
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), blend.Mode, blend.Placement); | ||
default: throw new ArgumentException($"Invalid pipeline effect: {effect.GetType()}"); | ||
} | ||
} | ||
|
||
// Builds a new effects pipeline from the input effects sequence | ||
CompositionBrushBuilder Build(IList<IPipelineEffect> 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)); | ||
} | ||
|
||
return Build(Effects); | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the collection of effects to use in the current pipeline | ||
/// </summary> | ||
[NotNull, ItemNotNull] | ||
public IList<IPipelineEffect> Effects { get; set; } = new List<IPipelineEffect>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.