Skip to content

Commit

Permalink
Merge pull request #15 from Sergio0694/dev
Browse files Browse the repository at this point in the history
Minor fixes
  • Loading branch information
Sergio0694 authored Mar 29, 2019
2 parents 8e63427 + 6ab41ca commit 908e391
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@ protected override IAnimationBuilder OnOffset(Axis axis, double? from, double to
AnimationFactories.Add(duration =>
{
// Stop the animation and get the easing function
TargetVisual.StopAnimation(nameof(Visual.Offset));
string property = $"{nameof(Visual.Offset)}.{axis}";
TargetVisual.StopAnimation(property);
CompositionEasingFunction easingFunction = TargetVisual.GetEasingFunction(ease);

// Create and return the animation
ScalarKeyFrameAnimation animation = TargetVisual.Compositor.CreateScalarKeyFrameAnimation((float?)from, (float)to, duration, null, easingFunction);
TargetVisual.StartAnimation(nameof(Visual.Offset), animation);
TargetVisual.StartAnimation(property, animation);
});

return this;
Expand Down
120 changes: 120 additions & 0 deletions UICompositionAnimations/Behaviours/PipelineBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ private PipelineBuilder([NotNull] Func<Task<IGraphicsEffectSource>> factory,
[Pure, NotNull]
public static PipelineBuilder FromEffect(Func<Task<IGraphicsEffectSource>> factory) => new PipelineBuilder(factory);

/// <summary>
/// Starts a new <see cref="PipelineBuilder"/> pipeline from a Win2D image
/// </summary>
/// <param name="relativePath">The relative path for the image to load (eg. "/Assets/image.png")</param>
/// <param name="dpiMode">Indicates the desired DPI mode to use when loading the image</param>
/// <param name="cache">The cache mode to use to load the image</param>
[Pure, NotNull]
public static PipelineBuilder FromImage([NotNull] string relativePath, DpiMode dpiMode = DpiMode.DisplayDpiWith96AsLowerBound, CacheMode cache = CacheMode.Default)
{
return FromImage(relativePath.ToAppxUri(), dpiMode, cache);
}

/// <summary>
/// Starts a new <see cref="PipelineBuilder"/> pipeline from a Win2D image
/// </summary>
Expand All @@ -186,6 +198,18 @@ public static PipelineBuilder FromImage([NotNull] Uri uri, DpiMode dpiMode = Dpi
return new PipelineBuilder(() => Win2DImageHelper.LoadImageAsync(Window.Current.Compositor, uri, dpiMode, cache).ContinueWith(t => t.Result as CompositionBrush));
}

/// <summary>
/// Starts a new <see cref="PipelineBuilder"/> pipeline from a Win2D image tiled to cover the available space
/// </summary>
/// <param name="relativePath">The relative path for the image to load (eg. "/Assets/image.png")</param>
/// <param name="dpiMode">Indicates the desired DPI mode to use when loading the image</param>
/// <param name="cache">The cache mode to use to load the image</param>
[Pure, NotNull]
public static PipelineBuilder FromTiles([NotNull] string relativePath, DpiMode dpiMode = DpiMode.DisplayDpiWith96AsLowerBound, CacheMode cache = CacheMode.Default)
{
return FromTiles(relativePath.ToAppxUri(), dpiMode, cache);
}

/// <summary>
/// Starts a new <see cref="PipelineBuilder"/> pipeline from a Win2D image tiled to cover the available space
/// </summary>
Expand Down Expand Up @@ -221,6 +245,19 @@ public static PipelineBuilder FromUIElement([NotNull] UIElement element)

#region Prebuilt pipelines

/// <summary>
/// Returns a new <see cref="PipelineBuilder"/> instance that implements the host backdrop acrylic effect
/// </summary>
/// <param name="tint">The tint color to use</param>
/// <param name="mix">The amount of tint to apply over the current effect</param>
/// <param name="noiseRelativePath">The relative path for the noise texture to load (eg. "/Assets/noise.png")</param>
/// <param name="cache">The cache mode to use to load the image</param>
[Pure, NotNull]
public static PipelineBuilder FromHostBackdropAcrylic(Color tint, float mix, [NotNull] string noiseRelativePath, CacheMode cache = CacheMode.Default)
{
return FromHostBackdropAcrylic(tint, mix, noiseRelativePath.ToAppxUri(), cache);
}

/// <summary>
/// Returns a new <see cref="PipelineBuilder"/> instance that implements the host backdrop acrylic effect
/// </summary>
Expand All @@ -239,6 +276,20 @@ public static PipelineBuilder FromHostBackdropAcrylic(Color tint, float mix, [No
.Blend(FromTiles(noiseUri, cache: cache), BlendEffectMode.Overlay, Placement.Background);
}

/// <summary>
/// Returns a new <see cref="PipelineBuilder"/> instance that implements the host backdrop acrylic effect
/// </summary>
/// <param name="tint">The tint color to use</param>
/// <param name="tintAnimation">The animation to apply on the tint color of the effect</param>
/// <param name="mix">The amount of tint to apply over the current effect</param>
/// <param name="noiseRelativePath">The relative path for the noise texture to load (eg. "/Assets/noise.png")</param>
/// <param name="cache">The cache mode to use to load the image</param>
[Pure, NotNull]
public static PipelineBuilder FromHostBackdropAcrylic(Color tint, float mix, out EffectAnimation tintAnimation, [NotNull] string noiseRelativePath, CacheMode cache = CacheMode.Default)
{
return FromHostBackdropAcrylic(tint, mix, out tintAnimation, noiseRelativePath.ToAppxUri(), cache);
}

/// <summary>
/// Returns a new <see cref="PipelineBuilder"/> instance that implements the host backdrop acrylic effect
/// </summary>
Expand All @@ -258,6 +309,20 @@ public static PipelineBuilder FromHostBackdropAcrylic(Color tint, float mix, out
.Blend(FromTiles(noiseUri, cache: cache), BlendEffectMode.Overlay, Placement.Background);
}

/// <summary>
/// Returns a new <see cref="PipelineBuilder"/> instance that implements the in-app backdrop acrylic effect
/// </summary>
/// <param name="tint">The tint color to use</param>
/// <param name="mix">The amount of tint to apply over the current effect</param>
/// <param name="blur">The amount of blur to apply to the acrylic brush</param>
/// <param name="noiseRelativePath">The relative path for the noise texture to load (eg. "/Assets/noise.png")</param>
/// <param name="cache">The cache mode to use to load the image</param>
[Pure, NotNull]
public static PipelineBuilder FromBackdropAcrylic(Color tint, float mix, float blur, [NotNull] string noiseRelativePath, CacheMode cache = CacheMode.Default)
{
return FromBackdropAcrylic(tint, mix, blur, noiseRelativePath.ToAppxUri(), cache);
}

/// <summary>
/// Returns a new <see cref="PipelineBuilder"/> instance that implements the in-app backdrop acrylic effect
/// </summary>
Expand All @@ -275,6 +340,24 @@ public static PipelineBuilder FromBackdropAcrylic(Color tint, float mix, float b
.Blend(FromTiles(noiseUri, cache: cache), BlendEffectMode.Overlay, Placement.Background);
}

/// <summary>
/// Returns a new <see cref="PipelineBuilder"/> instance that implements the in-app backdrop acrylic effect
/// </summary>
/// <param name="tint">The tint color to use</param>
/// <param name="mix">The amount of tint to apply over the current effect</param>
/// <param name="tintAnimation">The animation to apply on the tint color of the effect</param>
/// <param name="blur">The amount of blur to apply to the acrylic brush</param>
/// <param name="noiseRelativePath">The relative path for the noise texture to load (eg. "/Assets/noise.png")</param>
/// <param name="cache">The cache mode to use to load the image</param>
[Pure, NotNull]
public static PipelineBuilder FromBackdropAcrylic(
Color tint, float mix, out EffectAnimation tintAnimation,
float blur,
[NotNull] string noiseRelativePath, CacheMode cache = CacheMode.Default)
{
return FromBackdropAcrylic(tint, mix, out tintAnimation, blur, noiseRelativePath.ToAppxUri(), cache);
}

/// <summary>
/// Returns a new <see cref="PipelineBuilder"/> instance that implements the in-app backdrop acrylic effect
/// </summary>
Expand All @@ -296,6 +379,24 @@ public static PipelineBuilder FromBackdropAcrylic(
.Blend(FromTiles(noiseUri, cache: cache), BlendEffectMode.Overlay, Placement.Background);
}

/// <summary>
/// Returns a new <see cref="PipelineBuilder"/> instance that implements the in-app backdrop acrylic effect
/// </summary>
/// <param name="tint">The tint color to use</param>
/// <param name="mix">The amount of tint to apply over the current effect</param>
/// <param name="blur">The amount of blur to apply to the acrylic brush</param>
/// <param name="blurAnimation">The animation to apply on the blur effect in the pipeline</param>
/// <param name="noiseRelativePath">The relative path for the noise texture to load (eg. "/Assets/noise.png")</param>
/// <param name="cache">The cache mode to use to load the image</param>
[Pure, NotNull]
public static PipelineBuilder FromBackdropAcrylic(
Color tint, float mix,
float blur, out EffectAnimation blurAnimation,
[NotNull] string noiseRelativePath, CacheMode cache = CacheMode.Default)
{
return FromBackdropAcrylic(tint, mix, blur, out blurAnimation, noiseRelativePath.ToAppxUri(), cache);
}

/// <summary>
/// Returns a new <see cref="PipelineBuilder"/> instance that implements the in-app backdrop acrylic effect
/// </summary>
Expand All @@ -317,6 +418,25 @@ public static PipelineBuilder FromBackdropAcrylic(
.Blend(FromTiles(noiseUri, cache: cache), BlendEffectMode.Overlay, Placement.Background);
}

/// <summary>
/// Returns a new <see cref="PipelineBuilder"/> instance that implements the in-app backdrop acrylic effect
/// </summary>
/// <param name="tint">The tint color to use</param>
/// <param name="mix">The amount of tint to apply over the current effect</param>
/// <param name="tintAnimation">The animation to apply on the tint color of the effect</param>
/// <param name="blur">The amount of blur to apply to the acrylic brush</param>
/// <param name="blurAnimation">The animation to apply on the blur effect in the pipeline</param>
/// <param name="noiseRelativePath">The relative path for the noise texture to load (eg. "/Assets/noise.png")</param>
/// <param name="cache">The cache mode to use to load the image</param>
[Pure, NotNull]
public static PipelineBuilder FromBackdropAcrylic(
Color tint, float mix, out EffectAnimation tintAnimation,
float blur, out EffectAnimation blurAnimation,
[NotNull] string noiseRelativePath, CacheMode cache = CacheMode.Default)
{
return FromBackdropAcrylic(tint, mix, out tintAnimation, blur, out blurAnimation, noiseRelativePath.ToAppxUri(), cache);
}

/// <summary>
/// Returns a new <see cref="PipelineBuilder"/> instance that implements the in-app backdrop acrylic effect
/// </summary>
Expand Down
18 changes: 0 additions & 18 deletions UICompositionAnimations/Extensions/System/BaseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,5 @@ public static class BaseExtensions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Pure]
public static float ToRadians(this float degrees) => (float)(Math.PI / 180 * degrees);

/// <summary>
/// Returns an <see cref="Uri"/> that starts with the ms-appx:// prefix
/// </summary>
/// <param name="uri">The input <see cref="Uri"/> to process</param>
[Pure, NotNull]
internal static Uri ToAppxUri([NotNull] this Uri uri)
{
if (uri.Scheme.Equals("ms-resource"))
{
string path = uri.AbsolutePath.StartsWith("/Files")
? uri.AbsolutePath.Replace("/Files", string.Empty)
: uri.AbsolutePath;
return new Uri($"ms-appx://{path}");
}

return uri;
}
}
}
40 changes: 40 additions & 0 deletions UICompositionAnimations/Extensions/System/UriExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using JetBrains.Annotations;

namespace System
{
/// <summary>
/// An extension <see langword="class"/> for the <see cref="Uri"/> type
/// </summary>
public static class UriExtensions
{
/// <summary>
/// Returns an <see cref="Uri"/> that starts with the ms-appx:// prefix
/// </summary>
/// <param name="uri">The input <see cref="Uri"/> to process</param>
/// <remarks>This is needed because the XAML converter doesn't use the ms-appx:// prefix</remarks>
[Pure, NotNull]
internal static Uri ToAppxUri([NotNull] this Uri uri)
{
if (uri.Scheme.Equals("ms-resource"))
{
string path = uri.AbsolutePath.StartsWith("/Files")
? uri.AbsolutePath.Replace("/Files", string.Empty)
: uri.AbsolutePath;
return new Uri($"ms-appx://{path}");
}

return uri;
}

/// <summary>
/// Returns an <see cref="Uri"/> that starts with the ms-appx:// prefix
/// </summary>
/// <param name="path">The input relative path to convert</param>
[Pure, NotNull]
public static Uri ToAppxUri([NotNull] this string path)
{
string prefix = $"ms-appx://{(path.StartsWith('/') ? string.Empty : "/")}";
return new Uri($"{prefix}{path}");
}
}
}
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.0.0")]
[assembly: AssemblyFileVersion("4.0.0.0")]
[assembly: AssemblyInformationalVersion("4.0.0")]
[assembly: AssemblyVersion("4.0.1.0")]
[assembly: AssemblyFileVersion("4.0.1.0")]
[assembly: AssemblyInformationalVersion("4.0.1")]
[assembly: ComVisible(false)]

1 change: 1 addition & 0 deletions UICompositionAnimations/UICompositionAnimations.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
<Compile Include="Brushes\Effects\Interfaces\IPipelineEffect.cs" />
<Compile Include="Brushes\PipelineBrush.cs" />
<Compile Include="Brushes\Base\XamlCompositionEffectBrushBase.cs" />
<Compile Include="Extensions\System\UriExtensions.cs" />
<Compile Include="Helpers\Cache\HostBackdropInstanceWrapper.cs" />
<Compile Include="Helpers\Cache\ThreadSafeCompositionCache.cs" />
<Compile Include="Helpers\Cache\ThreadSafeCompositionMapCache.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.0</version>
<version>4.0.1</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>Major refactoring, API changes</releaseNotes>
<releaseNotes>New overloads added, minor bug fixes</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 908e391

Please sign in to comment.