From ec51c9ba039621a6f95a5ece1ee0b63c01dffb7f Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 29 Mar 2019 17:02:09 +0100 Subject: [PATCH 1/4] Minor refactoring, added new Uri extension --- .../Extensions/System/BaseExtensions.cs | 18 --------- .../Extensions/System/UriExtensions.cs | 40 +++++++++++++++++++ .../UICompositionAnimations.csproj | 1 + 3 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 UICompositionAnimations/Extensions/System/UriExtensions.cs diff --git a/UICompositionAnimations/Extensions/System/BaseExtensions.cs b/UICompositionAnimations/Extensions/System/BaseExtensions.cs index 15b822d..96179ca 100644 --- a/UICompositionAnimations/Extensions/System/BaseExtensions.cs +++ b/UICompositionAnimations/Extensions/System/BaseExtensions.cs @@ -30,23 +30,5 @@ public static class BaseExtensions [MethodImpl(MethodImplOptions.AggressiveInlining)] [Pure] public static float ToRadians(this float degrees) => (float)(Math.PI / 180 * degrees); - - /// - /// Returns an that starts with the ms-appx:// prefix - /// - /// The input to process - [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; - } } } diff --git a/UICompositionAnimations/Extensions/System/UriExtensions.cs b/UICompositionAnimations/Extensions/System/UriExtensions.cs new file mode 100644 index 0000000..425ce9b --- /dev/null +++ b/UICompositionAnimations/Extensions/System/UriExtensions.cs @@ -0,0 +1,40 @@ +using JetBrains.Annotations; + +namespace System +{ + /// + /// An extension for the type + /// + public static class UriExtensions + { + /// + /// Returns an that starts with the ms-appx:// prefix + /// + /// The input to process + /// This is needed because the XAML converter doesn't use the ms-appx:// prefix + [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; + } + + /// + /// Returns an that starts with the ms-appx:// prefix + /// + /// The input relative path to convert + [Pure, NotNull] + public static Uri ToAppxUri([NotNull] this string path) + { + string prefix = $"ms-appx://{(path.StartsWith('/') ? string.Empty : "/")}"; + return new Uri($"{prefix}{path}"); + } + } +} diff --git a/UICompositionAnimations/UICompositionAnimations.csproj b/UICompositionAnimations/UICompositionAnimations.csproj index e5d4ffd..8028b0e 100644 --- a/UICompositionAnimations/UICompositionAnimations.csproj +++ b/UICompositionAnimations/UICompositionAnimations.csproj @@ -143,6 +143,7 @@ + From 53cd6f57aec33baa10cb6bb3559f4af49859128e Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 29 Mar 2019 17:02:27 +0100 Subject: [PATCH 2/4] New PipelineBuilder APIs with a source path --- .../Behaviours/PipelineBuilder.cs | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/UICompositionAnimations/Behaviours/PipelineBuilder.cs b/UICompositionAnimations/Behaviours/PipelineBuilder.cs index 2aa121a..67c8997 100644 --- a/UICompositionAnimations/Behaviours/PipelineBuilder.cs +++ b/UICompositionAnimations/Behaviours/PipelineBuilder.cs @@ -174,6 +174,18 @@ private PipelineBuilder([NotNull] Func> factory, [Pure, NotNull] public static PipelineBuilder FromEffect(Func> factory) => new PipelineBuilder(factory); + /// + /// Starts a new pipeline from a Win2D image + /// + /// The relative path for the image to load (eg. "/Assets/image.png") + /// Indicates the desired DPI mode to use when loading the image + /// The cache mode to use to load the image + [Pure, NotNull] + public static PipelineBuilder FromImage([NotNull] string relativePath, DpiMode dpiMode = DpiMode.DisplayDpiWith96AsLowerBound, CacheMode cache = CacheMode.Default) + { + return FromImage(relativePath.ToAppxUri(), dpiMode, cache); + } + /// /// Starts a new pipeline from a Win2D image /// @@ -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)); } + /// + /// Starts a new pipeline from a Win2D image tiled to cover the available space + /// + /// The relative path for the image to load (eg. "/Assets/image.png") + /// Indicates the desired DPI mode to use when loading the image + /// The cache mode to use to load the image + [Pure, NotNull] + public static PipelineBuilder FromTiles([NotNull] string relativePath, DpiMode dpiMode = DpiMode.DisplayDpiWith96AsLowerBound, CacheMode cache = CacheMode.Default) + { + return FromTiles(relativePath.ToAppxUri(), dpiMode, cache); + } + /// /// Starts a new pipeline from a Win2D image tiled to cover the available space /// @@ -221,6 +245,19 @@ public static PipelineBuilder FromUIElement([NotNull] UIElement element) #region Prebuilt pipelines + /// + /// Returns a new instance that implements the host backdrop acrylic effect + /// + /// The tint color to use + /// The amount of tint to apply over the current effect + /// The relative path for the noise texture to load (eg. "/Assets/noise.png") + /// The cache mode to use to load the image + [Pure, NotNull] + public static PipelineBuilder FromHostBackdropAcrylic(Color tint, float mix, [NotNull] string noiseRelativePath, CacheMode cache = CacheMode.Default) + { + return FromHostBackdropAcrylic(tint, mix, noiseRelativePath.ToAppxUri(), cache); + } + /// /// Returns a new instance that implements the host backdrop acrylic effect /// @@ -239,6 +276,20 @@ public static PipelineBuilder FromHostBackdropAcrylic(Color tint, float mix, [No .Blend(FromTiles(noiseUri, cache: cache), BlendEffectMode.Overlay, Placement.Background); } + /// + /// Returns a new instance that implements the host backdrop acrylic effect + /// + /// The tint color to use + /// The animation to apply on the tint color of the effect + /// The amount of tint to apply over the current effect + /// The relative path for the noise texture to load (eg. "/Assets/noise.png") + /// The cache mode to use to load the image + [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); + } + /// /// Returns a new instance that implements the host backdrop acrylic effect /// @@ -258,6 +309,20 @@ public static PipelineBuilder FromHostBackdropAcrylic(Color tint, float mix, out .Blend(FromTiles(noiseUri, cache: cache), BlendEffectMode.Overlay, Placement.Background); } + /// + /// 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 blur to apply to the acrylic brush + /// The relative path for the noise texture to load (eg. "/Assets/noise.png") + /// The cache mode to use to load the image + [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); + } + /// /// Returns a new instance that implements the in-app backdrop acrylic effect /// @@ -275,6 +340,24 @@ public static PipelineBuilder FromBackdropAcrylic(Color tint, float mix, float b .Blend(FromTiles(noiseUri, cache: cache), BlendEffectMode.Overlay, Placement.Background); } + /// + /// 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 animation to apply on the tint color of the effect + /// The amount of blur to apply to the acrylic brush + /// The relative path for the noise texture to load (eg. "/Assets/noise.png") + /// The cache mode to use to load the image + [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); + } + /// /// Returns a new instance that implements the in-app backdrop acrylic effect /// @@ -296,6 +379,24 @@ public static PipelineBuilder FromBackdropAcrylic( .Blend(FromTiles(noiseUri, cache: cache), BlendEffectMode.Overlay, Placement.Background); } + /// + /// 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 blur to apply to the acrylic brush + /// The animation to apply on the blur effect in the pipeline + /// The relative path for the noise texture to load (eg. "/Assets/noise.png") + /// The cache mode to use to load the image + [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); + } + /// /// Returns a new instance that implements the in-app backdrop acrylic effect /// @@ -317,6 +418,25 @@ public static PipelineBuilder FromBackdropAcrylic( .Blend(FromTiles(noiseUri, cache: cache), BlendEffectMode.Overlay, Placement.Background); } + /// + /// 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 animation to apply on the tint color of the effect + /// The amount of blur to apply to the acrylic brush + /// The animation to apply on the blur effect in the pipeline + /// The relative path for the noise texture to load (eg. "/Assets/noise.png") + /// The cache mode to use to load the image + [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); + } + /// /// Returns a new instance that implements the in-app backdrop acrylic effect /// From ae2009372877e706fee338408e106a6726295142 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 29 Mar 2019 17:51:28 +0100 Subject: [PATCH 3/4] Fixed a bug in the offset animation --- .../Animations/CompositionAnimationBuilder.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/UICompositionAnimations/Animations/CompositionAnimationBuilder.cs b/UICompositionAnimations/Animations/CompositionAnimationBuilder.cs index 7abc3a1..375ab5c 100644 --- a/UICompositionAnimations/Animations/CompositionAnimationBuilder.cs +++ b/UICompositionAnimations/Animations/CompositionAnimationBuilder.cs @@ -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; From 6ab41ca372d0e9fc37990e5fcb842195463490cd Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 29 Mar 2019 17:57:17 +0100 Subject: [PATCH 4/4] NuGet info updated --- UICompositionAnimations/Properties/AssemblyInfo.cs | 6 +++--- UICompositionAnimations/UICompositionAnimations.nuspec | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/UICompositionAnimations/Properties/AssemblyInfo.cs b/UICompositionAnimations/Properties/AssemblyInfo.cs index dabc2f0..d9aa125 100644 --- a/UICompositionAnimations/Properties/AssemblyInfo.cs +++ b/UICompositionAnimations/Properties/AssemblyInfo.cs @@ -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)] diff --git a/UICompositionAnimations/UICompositionAnimations.nuspec b/UICompositionAnimations/UICompositionAnimations.nuspec index cda4dc0..a93e4c6 100644 --- a/UICompositionAnimations/UICompositionAnimations.nuspec +++ b/UICompositionAnimations/UICompositionAnimations.nuspec @@ -2,7 +2,7 @@ UICompositionAnimations - 4.0.0 + 4.0.1 UICompositionAnimations A wrapper UWP PCL to work with Windows.UI.Composition and XAML animations, and Win2D effects Sergio Pedri @@ -10,7 +10,7 @@ https://github.com/Sergio0694/UICompositionAnimations GPL-3.0-only false - Major refactoring, API changes + New overloads added, minor bug fixes Copyright © 2019 uwp composition animations xaml csharp windows winrt universal app ui win2d graphics