* Preparing for implementation of gradients.

* Make LottieGenCorpus more deterministic.
Previously the output depended on the width of the console, and sorting ignored case.

* Upgrading to SDK 18362 (May 2019) so that we can use RadialGradientBrush.
This commit is contained in:
Simeon 2019-08-29 10:03:44 -07:00 коммит произвёл GitHub
Родитель b63fe928b9
Коммит aeb87289e1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
34 изменённых файлов: 1089 добавлений и 541 удалений

Просмотреть файл

@ -20,7 +20,7 @@
<IsWpfProject Condition="'$(IsDesignProject)' != 'true'">$(MSBuildProjectName.Contains('Wpf'))</IsWpfProject>
<IsFormsProject Condition="'$(IsDesignProject)' != 'true'">$(MSBuildProjectName.Contains('Forms'))</IsFormsProject>
<IsSampleProject>$(MSBuildProjectName.Contains('Sample'))</IsSampleProject>
<DefaultTargetPlatformVersion>17763</DefaultTargetPlatformVersion>
<DefaultTargetPlatformVersion>18362</DefaultTargetPlatformVersion>
<DefaultTargetPlatformMinVersion>16299</DefaultTargetPlatformMinVersion>
<PackageOutputPath>$(MSBuildThisFileDirectory)bin\nupkg</PackageOutputPath>
<OutputPath>bin\$(Platform)\$(Configuration)</OutputPath>
@ -55,16 +55,16 @@
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<!-- Need RS5 or later.
<!-- Need 19H1 or later.
When changing this value, ensure the SDK is installed with the build process.
Need to check several files:
- /azure-pipelines.yml
This also needs to be installed on your local machine. Can do this with PowerShell:
./build/Install-WindowsSDKISO.ps1 17763
./build/Install-WindowsSDKISO.ps1 18362
-->
<TargetPlatformVersion>10.0.17763.0</TargetPlatformVersion>
<TargetPlatformVersion>10.0.18362.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.17134.0</TargetPlatformMinVersion>
<!-- Compiler -->

Просмотреть файл

@ -4,7 +4,7 @@ setlocal
dotnet tool uninstall -g LottieGen
:: Find nupkg and parse the name
@for /f "tokens=2,3,4,5,6 delims=." %%A in ('dir /b %~dp0\..\bin\nupkg\LottieGen.*.nupkg') do @set PackageVersion=%%A.%%B.%%C.%%D.%%E
for /f "tokens=2,3,4,5,6 delims=." %%A in ('dir /b %~dp0\..\bin\nupkg\LottieGen.*.nupkg') do @set PackageVersion=%%A.%%B.%%C.%%D.%%E
:: Install
+dotnet tool install LottieGen -g --version %PackageVersion% --add-source %~dp0\..\bin\nupkg
dotnet tool install LottieGen -g --version %PackageVersion% --add-source %~dp0\..\bin\nupkg

Просмотреть файл

@ -565,6 +565,7 @@ sealed class LottieFileProcessor
// improved things (where it did).
WriteStatsLine("CanvasGeometry", s => s.CanvasGeometryCount);
WriteStatsLine("ColorBrush", s => s.ColorBrushCount);
WriteStatsLine("ColorGradientStop", s => s.ColorGradientStopCount);
WriteStatsLine("ColorKeyFrameAnimation", s => s.ColorKeyFrameAnimationCount);
WriteStatsLine("CompositionPath", s => s.CompositionPathCount);
WriteStatsLine("ContainerShape", s => s.ContainerShapeCount);
@ -576,10 +577,12 @@ sealed class LottieFileProcessor
WriteStatsLine("GeometricClip", s => s.GeometricClipCount);
WriteStatsLine("InsetClip", s => s.InsetClipCount);
WriteStatsLine("LinearEasingFunction", s => s.LinearEasingFunctionCount);
WriteStatsLine("LinearGradientBrush", s => s.LinearGradientBrushCount);
WriteStatsLine("PathGeometry", s => s.PathGeometryCount);
WriteStatsLine("PathKeyFrameAnimation", s => s.PathKeyFrameAnimationCount);
WriteStatsLine("Property value", s => s.PropertySetPropertyCount);
WriteStatsLine("PropertySet", s => s.PropertySetCount);
WriteStatsLine("RadialGradientBrush", s => s.RadialGradientBrushCount);
WriteStatsLine("RectangleGeometry", s => s.RectangleGeometryCount);
WriteStatsLine("RoundedRectangleGeometry", s => s.RoundedRectangleGeometryCount);
WriteStatsLine("ScalarKeyFrameAnimation", s => s.ScalarKeyFrameAnimationCount);

Просмотреть файл

@ -11,7 +11,7 @@
<AssemblyName>LottieViewer</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.17763.0</TargetPlatformVersion>
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.18362.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>

Просмотреть файл

@ -12,7 +12,7 @@ Lottie-Windows consists of 3 related products:
* **[Lottie Viewer](/LottieViewer)** application for previewing JSON and also generating code
## <a name="supported"></a> Supported SDKs
* October 2018 Update (17763)
* May 2019 Update (18362)
## <a name="documentation"></a> Getting Started
* [Documentation and Tutorials](https://aka.ms/lottiedocs)

Просмотреть файл

@ -22,6 +22,10 @@
<Rule Id="CA1405" Action="Warning" />
<Rule Id="CA1410" Action="Warning" />
<Rule Id="CA1415" Action="Warning" />
<Rule Id="CA1800" Action="Warning" />
<Rule Id="CA1802" Action="Warning" />
<Rule Id="CA1804" Action="Warning" />
<Rule Id="CA1811" Action="Warning" />
<Rule Id="CA1821" Action="Warning" />
<Rule Id="CA1900" Action="Warning" />
<Rule Id="CA1901" Action="Warning" />

Просмотреть файл

@ -41,7 +41,7 @@ steps:
- script: nbgv cloud
displayName: Set Version
- powershell: .\build\Install-WindowsSdkISO.ps1 17763
- powershell: .\build\Install-WindowsSdkISO.ps1 18362
displayName: Insider SDK
- powershell: .\build.ps1 -target=Package

Просмотреть файл

@ -2,7 +2,7 @@
## Prerequisites
* [.NET Core 2.2 SDK](https://dotnet.microsoft.com/download/dotnet-core/2.2) or later
* Windows SDK October 2018 Update (17763) or later
* Windows SDK May 2019 Update (18362) or later
* Visual Studio 2017 or later
## As Azure DevOps does it

Просмотреть файл

@ -11,7 +11,7 @@
<AssemblyName>LottieSamples</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.17763.0</TargetPlatformVersion>
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.18362.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>

Просмотреть файл

@ -4,17 +4,6 @@
#define ReuseExpressionAnimation
// Define POST_RS5_SDK if using an SDK that is for a release
// after RS5. This is necessary because the build system does
// not easily support SDKs that are still prerelease.
// Once the release that has VisualSurface is out, this #if can
// be removed.
#if POST_RS5_SDK
// For allowing of Windows.UI.Composition.VisualSurface and the
// Lottie features that rely on it.
#define AllowVisualSurface
#endif
using System;
using System.Collections.Generic;
using System.IO;
@ -119,6 +108,65 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie
return target;
}
T CacheAndInitializeGradientBrush<T>(Wd.CompositionGradientBrush source, T target)
where T : Wc.CompositionGradientBrush
{
CacheAndInitializeCompositionObject(source, target);
if (source.AnchorPoint.HasValue)
{
target.AnchorPoint = source.AnchorPoint.Value;
}
if (source.CenterPoint.HasValue)
{
target.CenterPoint = source.CenterPoint.Value;
}
var stops = target.ColorStops;
foreach (var stop in source.ColorStops)
{
target.ColorStops.Add(GetCompositionColorGradientStop(stop));
}
if (source.ExtendMode.HasValue)
{
target.ExtendMode = ExtendMode(source.ExtendMode.Value);
}
if (source.InterpolationSpace.HasValue)
{
target.InterpolationSpace = ColorSpace(source.InterpolationSpace.Value);
}
if (source.MappingMode.HasValue)
{
target.MappingMode = MappingMode(source.MappingMode.Value);
}
if (source.Offset.HasValue)
{
target.Offset = source.Offset.Value;
}
if (source.RotationAngleInDegrees.HasValue)
{
target.RotationAngleInDegrees = source.RotationAngleInDegrees.Value;
}
if (source.Scale.HasValue)
{
target.Scale = source.Scale.Value;
}
if (source.TransformMatrix.HasValue)
{
target.TransformMatrix = source.TransformMatrix.Value;
}
return target;
}
T CacheAndInitializeVisual<T>(Wd.Visual source, T target)
where T : Wc.Visual
{
@ -350,6 +398,8 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie
return GetColorKeyFrameAnimation((Wd.ColorKeyFrameAnimation)obj);
case Wd.CompositionObjectType.CompositionColorBrush:
return GetCompositionColorBrush((Wd.CompositionColorBrush)obj);
case Wd.CompositionObjectType.CompositionColorGradientStop:
return GetCompositionColorGradientStop((Wd.CompositionColorGradientStop)obj);
case Wd.CompositionObjectType.CompositionContainerShape:
return GetCompositionContainerShape((Wd.CompositionContainerShape)obj);
case Wd.CompositionObjectType.CompositionEffectBrush:
@ -358,10 +408,14 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie
return GetCompositionEllipseGeometry((Wd.CompositionEllipseGeometry)obj);
case Wd.CompositionObjectType.CompositionGeometricClip:
return GetCompositionGeometricClip((Wd.CompositionGeometricClip)obj);
case Wd.CompositionObjectType.CompositionLinearGradientBrush:
return GetCompositionLinearGradientBrush((Wd.CompositionLinearGradientBrush)obj);
case Wd.CompositionObjectType.CompositionPathGeometry:
return GetCompositionPathGeometry((Wd.CompositionPathGeometry)obj);
case Wd.CompositionObjectType.CompositionPropertySet:
return GetCompositionPropertySet((Wd.CompositionPropertySet)obj);
/*case Wd.CompositionObjectType.CompositionRadialGradientBrush:
return GetCompositionRadialGradientBrush((Wd.CompositionRadialGradientBrush)obj);*/
case Wd.CompositionObjectType.CompositionRectangleGeometry:
return GetCompositionRectangleGeometry((Wd.CompositionRectangleGeometry)obj);
case Wd.CompositionObjectType.CompositionRoundedRectangleGeometry:
@ -804,7 +858,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie
return result;
}
#if AllowVisualSurface
Wc.CompositionVisualSurface GetCompositionVisualSurface(Wd.CompositionVisualSurface obj)
{
if (GetExisting(obj, out Wc.CompositionVisualSurface result))
@ -832,12 +885,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie
StartAnimations(obj, result);
return result;
}
#else
Wc.CompositionObject GetCompositionVisualSurface(Wd.CompositionVisualSurface obj)
{
throw new InvalidOperationException();
}
#endif
Wc.CompositionShape GetCompositionShape(Wd.CompositionShape obj)
{
@ -998,6 +1045,19 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie
return result;
}
Wc.CompositionColorGradientStop GetCompositionColorGradientStop(Wd.CompositionColorGradientStop obj)
{
if (GetExisting(obj, out Wc.CompositionColorGradientStop result))
{
return result;
}
result = CacheAndInitializeCompositionObject(obj, _c.CreateColorGradientStop(obj.Offset, Color(obj.Color)));
StartAnimations(obj, result);
return result;
}
Wc.CompositionSurfaceBrush GetCompositionSurfaceBrush(Wd.CompositionSurfaceBrush obj)
{
if (GetExisting(obj, out Wc.CompositionSurfaceBrush result))
@ -1211,6 +1271,9 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie
return GetCompositionEffectBrush((Wd.CompositionEffectBrush)obj);
case Wd.CompositionObjectType.CompositionSurfaceBrush:
return GetCompositionSurfaceBrush((Wd.CompositionSurfaceBrush)obj);
case Wd.CompositionObjectType.CompositionLinearGradientBrush:
case Wd.CompositionObjectType.CompositionRadialGradientBrush:
return GetCompositionGradientBrush((Wd.CompositionGradientBrush)obj);
default:
throw new InvalidOperationException();
}
@ -1228,6 +1291,71 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie
return result;
}
Wc.CompositionGradientBrush GetCompositionGradientBrush(Wd.CompositionGradientBrush obj)
{
switch (obj.Type)
{
case Wd.CompositionObjectType.CompositionLinearGradientBrush:
return GetCompositionLinearGradientBrush((Wd.CompositionLinearGradientBrush)obj);
case Wd.CompositionObjectType.CompositionRadialGradientBrush:
// TODO - handle versioning - RadialGradientBrush was not added until 1903
// return GetCompositionRadialGradientBrush((Wd.CompositionRadialGradientBrush)obj);
default:
throw new InvalidOperationException();
}
}
Wc.CompositionLinearGradientBrush GetCompositionLinearGradientBrush(Wd.CompositionLinearGradientBrush obj)
{
if (GetExisting(obj, out Wc.CompositionLinearGradientBrush result))
{
return result;
}
result = CacheAndInitializeGradientBrush(obj, _c.CreateLinearGradientBrush());
if (obj.StartPoint.HasValue)
{
result.StartPoint = obj.StartPoint.Value;
}
if (obj.EndPoint.HasValue)
{
result.EndPoint = obj.EndPoint.Value;
}
StartAnimations(obj, result);
return result;
}
Wc.CompositionRadialGradientBrush GetCompositionRadialGradientBrush(Wd.CompositionRadialGradientBrush obj)
{
if (GetExisting(obj, out Wc.CompositionRadialGradientBrush result))
{
return result;
}
result = CacheAndInitializeGradientBrush(obj, _c.CreateRadialGradientBrush());
if (obj.EllipseCenter.HasValue)
{
result.EllipseCenter = obj.EllipseCenter.Value;
}
if (obj.EllipseRadius.HasValue)
{
result.EllipseRadius = obj.EllipseRadius.Value;
}
if (obj.GradientOriginOffset.HasValue)
{
result.GradientOriginOffset = obj.GradientOriginOffset.Value;
}
StartAnimations(obj, result);
return result;
}
Wc.ICompositionSurface GetCompositionSurface(Wd.ICompositionSurface obj)
{
switch (obj)
@ -1382,6 +1510,53 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie
}
}
static Wc.CompositionGradientExtendMode ExtendMode(Wd.CompositionGradientExtendMode value)
{
switch (value)
{
case Wd.CompositionGradientExtendMode.Clamp:
return Wc.CompositionGradientExtendMode.Clamp;
case Wd.CompositionGradientExtendMode.Wrap:
return Wc.CompositionGradientExtendMode.Wrap;
case Wd.CompositionGradientExtendMode.Mirror:
return Wc.CompositionGradientExtendMode.Mirror;
default:
throw new InvalidOperationException();
}
}
static Wc.CompositionColorSpace ColorSpace(Wd.CompositionColorSpace value)
{
switch (value)
{
case Wd.CompositionColorSpace.Auto:
return Wc.CompositionColorSpace.Auto;
case Wd.CompositionColorSpace.Hsl:
return Wc.CompositionColorSpace.Hsl;
case Wd.CompositionColorSpace.Rgb:
return Wc.CompositionColorSpace.Rgb;
case Wd.CompositionColorSpace.HslLinear:
return Wc.CompositionColorSpace.HslLinear;
case Wd.CompositionColorSpace.RgbLinear:
return Wc.CompositionColorSpace.RgbLinear;
default:
throw new InvalidOperationException();
}
}
static Wc.CompositionMappingMode MappingMode(Wd.CompositionMappingMode value)
{
switch (value)
{
case Wd.CompositionMappingMode.Absolute:
return Wc.CompositionMappingMode.Absolute;
case Wd.CompositionMappingMode.Relative:
return Wc.CompositionMappingMode.Relative;
default:
throw new InvalidOperationException();
}
}
sealed class ReferenceEqualsComparer : IEqualityComparer<object>
{
bool IEqualityComparer<object>.Equals(object x, object y) => ReferenceEquals(x, y);

Просмотреть файл

@ -7,30 +7,30 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieData
#if PUBLIC_LottieData
public
#endif
sealed class LinearGradientFill : ShapeLayerContent
sealed class LinearGradientFill : ShapeFill
{
public LinearGradientFill(
in ShapeLayerContentArgs args,
Animatable<double> opacityPercent,
Animatable<Vector2> startPoint,
Animatable<Vector2> endPoint,
IAnimatableVector3 startPoint,
IAnimatableVector3 endPoint,
Animatable<Sequence<GradientStop>> gradientStops)
: base(in args)
: base(in args, opacityPercent)
{
OpacityPercent = opacityPercent;
StartPoint = startPoint;
EndPoint = endPoint;
GradientStops = gradientStops;
}
public Animatable<Vector2> StartPoint { get; }
public IAnimatableVector3 StartPoint { get; }
public Animatable<Vector2> EndPoint { get; }
public Animatable<double> OpacityPercent { get; }
public IAnimatableVector3 EndPoint { get; }
public Animatable<Sequence<GradientStop>> GradientStops { get; }
/// <inheritdoc/>
public override ShapeFillKind FillKind => ShapeFillKind.LinearGradient;
/// <inheritdoc/>
public override ShapeContentType ContentType => ShapeContentType.LinearGradientFill;

Просмотреть файл

@ -6,6 +6,7 @@
<SharedGUID>b3db16ee-a821-4474-a188-e64926529bbd</SharedGUID>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)ShapeFill.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\Animatable.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\ExtensionMethods.cs" />
<Compile Include="$(MSBuildThisFileDirectory)\AnimatableVector3.cs" />

Просмотреть файл

@ -7,7 +7,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieData
#if PUBLIC_LottieData
public
#endif
sealed class RadialGradientFill : ShapeLayerContent
sealed class RadialGradientFill : ShapeFill
{
public RadialGradientFill(
in ShapeLayerContentArgs args,
@ -17,9 +17,8 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieData
Animatable<Sequence<GradientStop>> gradientStops,
Animatable<double> highlightLength,
Animatable<double> highlightDegrees)
: base(in args)
: base(in args, opacityPercent)
{
OpacityPercent = opacityPercent;
StartPoint = startPoint;
EndPoint = endPoint;
GradientStops = gradientStops;
@ -37,7 +36,8 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieData
public Animatable<double> HighlightDegrees { get; }
public Animatable<double> OpacityPercent { get; }
/// <inheritdoc/>
public override ShapeFillKind FillKind => ShapeFillKind.RadialGradient;
/// <inheritdoc/>
public override ShapeContentType ContentType => ShapeContentType.RadialGradientFill;

Просмотреть файл

@ -0,0 +1,30 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieData
{
#if PUBLIC_LottieData
public
#endif
abstract class ShapeFill : ShapeLayerContent
{
public ShapeFill(
in ShapeLayerContentArgs args, Animatable<double> opacityPercent)
: base(in args)
{
OpacityPercent = opacityPercent;
}
public Animatable<double> OpacityPercent { get; }
public abstract ShapeFillKind FillKind { get; }
public enum ShapeFillKind
{
SolidColor,
LinearGradient,
RadialGradient,
}
}
}

Просмотреть файл

@ -7,26 +7,25 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieData
#if PUBLIC_LottieData
public
#endif
sealed class SolidColorFill : ShapeLayerContent
sealed class SolidColorFill : ShapeFill
{
public SolidColorFill(
in ShapeLayerContentArgs args,
PathFillType fillType,
Animatable<Color> color,
Animatable<double> opacityPercent)
: base(in args)
: base(in args, opacityPercent)
{
FillType = fillType;
Color = color;
OpacityPercent = opacityPercent;
}
public Animatable<Color> Color { get; }
public Animatable<double> OpacityPercent { get; }
public PathFillType FillType { get; }
public override ShapeFillKind FillKind => ShapeFillKind.SolidColor;
/// <inheritdoc/>
public override ShapeContentType ContentType => ShapeContentType.SolidColorFill;

Просмотреть файл

@ -1154,8 +1154,8 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieData.Serialization
IgnoreFieldThatIsNotYetSupported(obj, "hd");
var opacityPercent = ReadOpacityPercent(obj);
var startPoint = ReadAnimatableVector2(obj.GetNamedObject("s"));
var endPoint = ReadAnimatableVector2(obj.GetNamedObject("e"));
var startPoint = ReadAnimatableVector3(obj.GetNamedObject("s"));
var endPoint = ReadAnimatableVector3(obj.GetNamedObject("e"));
var gradientStops = ReadAnimatableGradientStops(obj.GetNamedObject("g"));
AssertAllFieldsRead(obj);
return new LinearGradientFill(

Просмотреть файл

@ -0,0 +1,198 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.Toolkit.Uwp.UI.Lottie.LottieData;
using Microsoft.Toolkit.Uwp.UI.Lottie.WinCompData;
using Microsoft.Toolkit.Uwp.UI.Lottie.WinCompData.Mgce;
using Expr = Microsoft.Toolkit.Uwp.UI.Lottie.WinCompData.Expressions.Expression;
using Sn = System.Numerics;
#if DEBUG
// For diagnosing issues, give nothing a clip.
//#define NoClipping
#endif
namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
{
sealed class CompositionObjectFactory
{
readonly Compositor _compositor;
// Holds CubicBezierEasingFunctions for reuse when they have the same parameters.
readonly Dictionary<CubicBezierEasing, CubicBezierEasingFunction> _cubicBezierEasingFunctions = new Dictionary<CubicBezierEasing, CubicBezierEasingFunction>();
// Holds ColorBrushes that are not animated and can therefore be reused.
readonly Dictionary<Color, CompositionColorBrush> _nonAnimatedColorBrushes = new Dictionary<Color, CompositionColorBrush>();
// Holds a LinearEasingFunction that can be reused in multiple animations.
readonly LinearEasingFunction _linearEasingFunction;
// Holds a StepEasingFunction that can be reused in multiple animations.
readonly StepEasingFunction _holdStepEasingFunction;
// Holds a StepEasingFunction that can be reused in multiple animations.
readonly StepEasingFunction _jumpStepEasingFunction;
internal CompositionObjectFactory(Compositor compositor)
{
_compositor = compositor;
// Initialize singletons.
_linearEasingFunction = _compositor.CreateLinearEasingFunction();
_holdStepEasingFunction = _compositor.CreateStepEasingFunction(1);
_holdStepEasingFunction.IsFinalStepSingleFrame = true;
_jumpStepEasingFunction = _compositor.CreateStepEasingFunction(1);
_jumpStepEasingFunction.IsInitialStepSingleFrame = true;
}
internal CompositionEllipseGeometry CreateEllipseGeometry() => _compositor.CreateEllipseGeometry();
internal CompositionPathGeometry CreatePathGeometry() => _compositor.CreatePathGeometry();
internal CompositionPathGeometry CreatePathGeometry(CompositionPath path) => _compositor.CreatePathGeometry(path);
internal CompositionRectangleGeometry CreateRectangleGeometry() => _compositor.CreateRectangleGeometry();
internal CompositionRoundedRectangleGeometry CreateRoundedRectangleGeometry() => _compositor.CreateRoundedRectangleGeometry();
internal CompositionColorBrush CreateColorBrush(Color color) => _compositor.CreateColorBrush(WuiColor(color));
internal CompositionColorBrush CreateNonAnimatedColorBrush(Color color)
{
if (color.A == 0)
{
// Transparent brushes that are never animated are all equivalent.
color = LottieData.Color.TransparentBlack;
}
if (!_nonAnimatedColorBrushes.TryGetValue(color, out var result))
{
result = CreateColorBrush(color);
_nonAnimatedColorBrushes.Add(color, result);
}
return result;
}
internal CompositionColorGradientStop CreateColorGradientStop(float offset, Color color) => _compositor.CreateColorGradientStop(offset, WuiColor(color));
internal CompositionLinearGradientBrush CreateLinearGradientBrush() => _compositor.CreateLinearGradientBrush();
internal CompositionRadialGradientBrush CreateRadialGradientBrush() => _compositor.CreateRadialGradientBrush();
internal CompositionEasingFunction CreateCompositionEasingFunction(Easing easingFunction)
{
if (easingFunction == null)
{
return null;
}
switch (easingFunction.Type)
{
case Easing.EasingType.Linear:
return CreateLinearEasingFunction();
case Easing.EasingType.CubicBezier:
return CreateCubicBezierEasingFunction((CubicBezierEasing)easingFunction);
case Easing.EasingType.Hold:
return CreateHoldThenStepEasingFunction();
default:
throw new InvalidOperationException();
}
}
internal LinearEasingFunction CreateLinearEasingFunction() => _linearEasingFunction;
internal CubicBezierEasingFunction CreateCubicBezierEasingFunction(CubicBezierEasing cubicBezierEasing)
{
if (!_cubicBezierEasingFunctions.TryGetValue(cubicBezierEasing, out var result))
{
// WinComp does not support control points with components > 1. Clamp the values to 1.
var controlPoint1 = ClampedVector2(cubicBezierEasing.ControlPoint1);
var controlPoint2 = ClampedVector2(cubicBezierEasing.ControlPoint2);
result = _compositor.CreateCubicBezierEasingFunction(controlPoint1, controlPoint2);
_cubicBezierEasingFunctions.Add(cubicBezierEasing, result);
}
return result;
}
// Returns an easing function that holds its initial value and steps to the final value at the end.
internal StepEasingFunction CreateHoldThenStepEasingFunction() => _holdStepEasingFunction;
// Returns an easing function that steps immediately to its final value.
internal StepEasingFunction CreateStepThenHoldEasingFunction() => _jumpStepEasingFunction;
internal ScalarKeyFrameAnimation CreateScalarKeyFrameAnimation() => _compositor.CreateScalarKeyFrameAnimation();
internal ColorKeyFrameAnimation CreateColorKeyFrameAnimation()
{
var result = _compositor.CreateColorKeyFrameAnimation();
// BodyMovin always uses RGB interpolation. Composition defaults to
// HSL. Override the default to be compatible with BodyMovin.
result.InterpolationColorSpace = CompositionColorSpace.Rgb;
return result;
}
internal PathKeyFrameAnimation CreatePathKeyFrameAnimation() => _compositor.CreatePathKeyFrameAnimation();
internal Vector2KeyFrameAnimation CreateVector2KeyFrameAnimation() => _compositor.CreateVector2KeyFrameAnimation();
internal Vector3KeyFrameAnimation CreateVector3KeyFrameAnimation() => _compositor.CreateVector3KeyFrameAnimation();
internal InsetClip CreateInsetClip() => _compositor.CreateInsetClip();
internal CompositionGeometricClip CreateGeometricClip() => _compositor.CreateGeometricClip();
internal CompositionContainerShape CreateContainerShape() => _compositor.CreateContainerShape();
internal ContainerVisual CreateContainerVisual() => _compositor.CreateContainerVisual();
internal SpriteVisual CreateSpriteVisual() => _compositor.CreateSpriteVisual();
internal ShapeVisual CreateShapeVisualWithChild(CompositionShape child, Sn.Vector2 size)
{
var result = _compositor.CreateShapeVisual();
result.Shapes.Add(child);
// ShapeVisual clips to its size
#if NoClipping
result.Size = Vector2(float.MaxValue);
#else
result.Size = size;
#endif
return result;
}
internal CompositionSpriteShape CreateSpriteShape() => _compositor.CreateSpriteShape();
internal ExpressionAnimation CreateExpressionAnimation(Expr expression) => _compositor.CreateExpressionAnimation(expression);
internal CompositionVisualSurface CreateVisualSurface() => _compositor.CreateVisualSurface();
internal CompositionSurfaceBrush CreateSurfaceBrush(ICompositionSurface surface) => _compositor.CreateSurfaceBrush(surface);
internal CompositionEffectFactory CreateEffectFactory(GraphicsEffectBase effect) => _compositor.CreateEffectFactory(effect);
static float Clamp(float value, float min, float max)
{
Debug.Assert(min <= max, "Precondition");
return Math.Min(Math.Max(min, value), max);
}
static Sn.Vector2 ClampedVector2(LottieData.Vector3 vector3) => ClampedVector2((float)vector3.X, (float)vector3.Y);
static Sn.Vector2 ClampedVector2(float x, float y) => Vector2(Clamp(x, 0, 1), Clamp(y, 0, 1));
static WinCompData.Wui.Color WuiColor(Color color) =>
WinCompData.Wui.Color.FromArgb((byte)(255 * color.A), (byte)(255 * color.R), (byte)(255 * color.G), (byte)(255 * color.B));
static Sn.Vector2 Vector2(float x, float y) => new Sn.Vector2(x, y);
}
}

Просмотреть файл

@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)CanvasGeometryCombiner.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CompositionObjectFactory.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ContainerShapeOrVisual.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ExpressionFactory.cs" />
<Compile Include="$(MSBuildThisFileDirectory)LottieToWinCompTranslator.cs" />

Просмотреть файл

@ -77,7 +77,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
readonly LottieComposition _lc;
readonly TranslationIssues _issues;
readonly bool _addDescriptions;
readonly Compositor _c;
readonly CompositionObjectFactory _c;
readonly ContainerVisual _rootVisual;
readonly Dictionary<ScaleAndOffset, ExpressionAnimation> _progressBindingAnimations = new Dictionary<ScaleAndOffset, ExpressionAnimation>();
readonly Optimizer _lottieDataOptimizer = new Optimizer();
@ -91,15 +91,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
// Paths are shareable.
readonly Dictionary<(Sequence<BezierSegment>, SolidColorFill.PathFillType, bool), CompositionPath> _compositionPaths = new Dictionary<(Sequence<BezierSegment>, SolidColorFill.PathFillType, bool), CompositionPath>();
// Holds a LinearEasingFunction that can be reused in multiple animations.
LinearEasingFunction _linearEasingFunction;
// Holds a StepEasingFunction that can be reused in multiple animations.
StepEasingFunction _holdStepEasingFunction;
// Holds a StepEasingFunction that can be reused in multiple animations.
StepEasingFunction _jumpStepEasingFunction;
/// <summary>
/// Gets the name of the property on the resulting <see cref="Visual"/> that controls the progress
/// of the animation. Setting this property (directly or with an animation)
@ -114,12 +105,12 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
bool addDescriptions)
{
_lc = lottieComposition;
_c = compositor;
_c = new CompositionObjectFactory(compositor);
_issues = new TranslationIssues(strictTranslation);
_addDescriptions = addDescriptions;
// Create the root.
_rootVisual = CreateContainerVisual();
_rootVisual = _c.CreateContainerVisual();
if (_addDescriptions)
{
Describe(_rootVisual, "The root of the composition.", string.Empty);
@ -247,7 +238,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
case CompositionObjectType.CompositionSpriteShape:
if (shapeVisual == null)
{
shapeVisual = CreateShapeVisualWithChild((CompositionShape)item, context.Size);
shapeVisual = _c.CreateShapeVisualWithChild((CompositionShape)item, context.Size);
}
else
{
@ -312,7 +303,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
if (layerIsMattedLayer ||
mattedVisual != null)
{
visual = CreateShapeVisualWithChild((CompositionShape)item.translatedLayer, context.Size);
visual = _c.CreateShapeVisualWithChild((CompositionShape)item.translatedLayer, context.Size);
}
break;
@ -362,7 +353,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
TranslationContext context,
CompositionContainerShape containerShapeToMask)
{
var contentShapeVisual = CreateShapeVisualWithChild(containerShapeToMask, context.Size);
var contentShapeVisual = _c.CreateShapeVisualWithChild(containerShapeToMask, context.Size);
return TranslateAndApplyMasks(context, context.Layer, contentShapeVisual);
}
@ -411,7 +402,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
var geometry = context.TrimAnimatable(_lottieDataOptimizer.GetOptimized(mask.Points));
var compositionPathGeometry = CreatePathGeometry();
var compositionPathGeometry = _c.CreatePathGeometry();
compositionPathGeometry.Path = CompositionPathFromPathGeometry(
geometry.InitialValue,
SolidColorFill.PathFillType.EvenOdd,
@ -432,12 +423,12 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
if (mask.Mode == currentMaskMode)
{
var maskSpriteShape = CreateSpriteShape();
var maskSpriteShape = _c.CreateSpriteShape();
maskSpriteShape.Geometry = compositionPathGeometry;
// The mask geometry needs to be colored with something so that it can be used
// as a mask.
maskSpriteShape.FillBrush = CreateColorBrush(LottieData.Color.Black);
maskSpriteShape.FillBrush = _c.CreateNonAnimatedColorBrush(LottieData.Color.Black);
maskContainerShape.Shapes.Add(maskSpriteShape);
}
@ -472,7 +463,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
return null;
}
var maskShapeVisual = CreateShapeVisualWithChild(containerShapeMaskRootNode, context.Size);
var maskShapeVisual = _c.CreateShapeVisualWithChild(containerShapeMaskRootNode, context.Size);
// Do not add the mask if we failed to translate and add it
if (TranslateAndAddMaskPaths(context, layer, containerShapeMaskContentNode, out var maskMode))
@ -484,7 +475,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
Sn.Vector2.Zero,
maskMode == Mask.MaskMode.Additive ? CanvasComposite.DestinationIn : CanvasComposite.DestinationOut);
var layerRootContainerVisual = CreateContainerVisual();
var layerRootContainerVisual = _c.CreateContainerVisual();
layerRootContainerVisual.Children.Add(compositedVisual);
return layerRootContainerVisual;
}
@ -512,15 +503,15 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
// for the matte content and the content to be matted.
var contextSize = context.Size;
var matteLayerVisualSurface = CreateVisualSurface();
var matteLayerVisualSurface = _c.CreateVisualSurface();
matteLayerVisualSurface.SourceVisual = matteLayer;
matteLayerVisualSurface.SourceSize = contextSize;
var matteSurfaceBrush = CreateSurfaceBrush(matteLayerVisualSurface);
var matteSurfaceBrush = _c.CreateSurfaceBrush(matteLayerVisualSurface);
var mattedLayerVisualSurface = CreateVisualSurface();
var mattedLayerVisualSurface = _c.CreateVisualSurface();
mattedLayerVisualSurface.SourceVisual = mattedLayer;
mattedLayerVisualSurface.SourceSize = contextSize;
var mattedSurfaceBrush = CreateSurfaceBrush(mattedLayerVisualSurface);
var mattedSurfaceBrush = _c.CreateSurfaceBrush(mattedLayerVisualSurface);
return CompositeVisuals(
matteLayer,
@ -591,23 +582,23 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
// To capture any offsets we add an intermediate parent container visual so that
// the visual we want captured by the visual surface has a parent to use as the
// origin of its offsets.
var sourceIntermediateParent = CreateContainerVisual();
var sourceIntermediateParent = _c.CreateContainerVisual();
sourceIntermediateParent.Children.Add(source);
var destinationIntermediateParent = CreateContainerVisual();
var destinationIntermediateParent = _c.CreateContainerVisual();
destinationIntermediateParent.Children.Add(destination);
var sourceVisualSurface = CreateVisualSurface();
var sourceVisualSurface = _c.CreateVisualSurface();
sourceVisualSurface.SourceVisual = sourceIntermediateParent;
sourceVisualSurface.SourceSize = size;
sourceVisualSurface.SourceOffset = offset;
var sourceVisualSurfaceBrush = CreateSurfaceBrush(sourceVisualSurface);
var sourceVisualSurfaceBrush = _c.CreateSurfaceBrush(sourceVisualSurface);
var destinationVisualSurface = CreateVisualSurface();
var destinationVisualSurface = _c.CreateVisualSurface();
destinationVisualSurface.SourceVisual = destinationIntermediateParent;
destinationVisualSurface.SourceSize = size;
destinationVisualSurface.SourceOffset = offset;
var destinationVisualSurfaceBrush = CreateSurfaceBrush(destinationVisualSurface);
var destinationVisualSurfaceBrush = _c.CreateSurfaceBrush(destinationVisualSurface);
var compositeEffect = new CompositeEffect();
compositeEffect.Mode = compositeMode;
@ -615,13 +606,13 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
compositeEffect.Sources.Add(new CompositionEffectSourceParameter("destination"));
compositeEffect.Sources.Add(new CompositionEffectSourceParameter("source"));
var compositionEffectFactory = CreateEffectFactory(compositeEffect);
var compositionEffectFactory = _c.CreateEffectFactory(compositeEffect);
var effectBrush = compositionEffectFactory.CreateBrush();
effectBrush.SetSourceParameter("destination", destinationVisualSurfaceBrush);
effectBrush.SetSourceParameter("source", sourceVisualSurfaceBrush);
var compositedVisual = CreateSpriteVisual();
var compositedVisual = _c.CreateSpriteVisual();
compositedVisual.Brush = effectBrush;
compositedVisual.Size = size;
compositedVisual.Offset = Vector3(offset.X, offset.Y, 0);
@ -733,24 +724,24 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
if (inProgress > 0 || outProgress < 1)
{
// Create a node to control visibility.
var visibilityNode = CreateContainerShape();
var visibilityNode = _c.CreateContainerShape();
visibilityNode.Shapes.Add(transformsRoot);
rootNode = visibilityNode;
#if !NoInvisibility
#if ControllersSynchronizationWorkaround
// Animate between Matrix3x2(0,0,0,0,0,0) and Matrix3x2(1,0,0,1,0,0) (i.e. between 0 and identity).
var visibilityAnimation = CreateScalarKeyFrameAnimation();
var visibilityAnimation = _c.CreateScalarKeyFrameAnimation();
if (inProgress > 0)
{
// Set initial value to be non-visible (default is visible).
visibilityNode.TransformMatrix = default(Sn.Matrix3x2);
visibilityAnimation.InsertKeyFrame(inProgress, 1, CreateHoldThenStepEasingFunction());
visibilityAnimation.InsertKeyFrame(inProgress, 1, _c.CreateHoldThenStepEasingFunction());
}
if (outProgress < 1)
{
visibilityAnimation.InsertKeyFrame(outProgress, 0, CreateHoldThenStepEasingFunction());
visibilityAnimation.InsertKeyFrame(outProgress, 0, _c.CreateHoldThenStepEasingFunction());
}
visibilityAnimation.Duration = _lc.Duration;
@ -758,7 +749,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
// M11 and M22 need to have the same value. Either tie them together with an expression, or
// use the same keyframe animation for both. Probably cheaper to use an expression.
var m11expression = CreateExpressionAnimation(ExpressionFactory.TransformMatrixM11Expression);
var m11expression = _c.CreateExpressionAnimation(ExpressionFactory.TransformMatrixM11Expression);
m11expression.SetReferenceParameter("my", visibilityNode);
StartExpressionAnimation(visibilityNode, "TransformMatrix._22", m11expression);
@ -773,7 +764,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
new ExpressionFactory.Segment(outProgress, double.MaxValue, Expr.Matrix3x2Zero)
);
var visibilityAnimation = CreateExpressionAnimation(visibilityExpression);
var visibilityAnimation = _c.CreateExpressionAnimation(visibilityExpression);
visibilityAnimation.SetReferenceParameter(RootName, _rootVisual);
StartExpressionAnimation(visibilityNode, "TransformMatrix", visibilityAnimation);
#endif // ControllersSynchronizationWorkaround
@ -851,7 +842,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
if (layerOpacityPercent.IsAnimated || layerOpacityPercent.InitialValue < 100)
{
// Insert a new node to control opacity at the top of the chain.
var opacityNode = CreateContainerVisual();
var opacityNode = _c.CreateContainerVisual();
if (_addDescriptions)
{
@ -876,7 +867,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
if (inProgress > 0 || outProgress < 1)
{
// Insert a new node to control visibility at the top of the chain.
var visibilityNode = CreateContainerVisual();
var visibilityNode = _c.CreateContainerVisual();
if (_addDescriptions)
{
@ -889,17 +880,17 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
#if !NoInvisibility
#if ControllersSynchronizationWorkaround
// Animate opacity between 0 and 1.
var visibilityAnimation = CreateScalarKeyFrameAnimation();
var visibilityAnimation = _c.CreateScalarKeyFrameAnimation();
if (inProgress > 0)
{
// Set initial value to be non-visible.
visibilityNode.Opacity = 0;
visibilityAnimation.InsertKeyFrame(inProgress, 1, CreateHoldThenStepEasingFunction());
visibilityAnimation.InsertKeyFrame(inProgress, 1, _c.CreateHoldThenStepEasingFunction());
}
if (outProgress < 1)
{
visibilityAnimation.InsertKeyFrame(outProgress, 0, CreateHoldThenStepEasingFunction());
visibilityAnimation.InsertKeyFrame(outProgress, 0, _c.CreateHoldThenStepEasingFunction());
}
visibilityAnimation.Duration = _lc.Duration;
@ -916,7 +907,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
new ExpressionFactory.Segment(outProgress, double.MaxValue, invisible)
);
var visibilityAnimation = CreateExpressionAnimation(visibilityExpression);
var visibilityAnimation = _c.CreateExpressionAnimation(visibilityExpression);
visibilityAnimation.SetReferenceParameter(RootName, _rootVisual);
StartExpressionAnimation(visibilityNode, "Opacity", visibilityAnimation);
#endif // ControllersSynchronizationWorkaround
@ -940,7 +931,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
return null;
}
var content = CreateSpriteVisual();
var content = _c.CreateSpriteVisual();
containerVisualContentNode.Children.Add(content);
content.Size = new Sn.Vector2((float)imageAsset.Width, (float)imageAsset.Height);
@ -963,7 +954,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
throw new InvalidOperationException();
}
var imageBrush = CreateSurfaceBrush(surface);
var imageBrush = _c.CreateSurfaceBrush(surface);
content.Brush = imageBrush;
if (_addDescriptions)
@ -983,15 +974,15 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
return null;
}
var result = CreateContainerVisual();
var result = _c.CreateContainerVisual();
#if !NoClipping
// PreComps must clip to their size.
// Create another ContainerVisual to apply clipping to.
var clippingNode = CreateContainerVisual();
var clippingNode = _c.CreateContainerVisual();
contentsNode.Children.Add(clippingNode);
contentsNode = clippingNode;
contentsNode.Clip = CreateInsetClip();
contentsNode.Clip = _c.CreateInsetClip();
contentsNode.Size = Vector2(context.Layer.Width, context.Layer.Height);
#endif
@ -1502,7 +1493,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
// Some ShapeLayerContent evaluate to geometries (e.g. any geometry, merge path)
// Create a container to hold the contents.
var container = CreateContainerShape();
var container = _c.CreateContainerShape();
// This is the object that will be returned. Containers may be added above this
// as necessary to hold transforms.
@ -1641,7 +1632,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
shapeContext.UpdateOpacityFromTransform(transform);
// Insert a new container at the top. The transform will be applied to it.
var newContainer = CreateContainerShape();
var newContainer = _c.CreateContainerShape();
newContainer.Shapes.Add(result);
result = newContainer;
@ -1677,8 +1668,8 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
var mergedGeometry = MergeShapeLayerContent(context, shapeContext, stack, mergeMode);
if (mergedGeometry != null)
{
var result = CreateSpriteShape();
result.Geometry = CreatePathGeometry(new CompositionPath(mergedGeometry));
var result = _c.CreateSpriteShape();
result.Geometry = _c.CreatePathGeometry(new CompositionPath(mergedGeometry));
TranslateAndApplyShapeContentContext(context, shapeContext, result);
return result;
}
@ -2036,9 +2027,9 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
CompositionShape TranslateEllipseContent(TranslationContext context, ShapeContentContext shapeContext, Ellipse shapeContent)
{
// An ellipse is represented as a SpriteShape with a CompositionEllipseGeometry.
var compositionSpriteShape = CreateSpriteShape();
var compositionSpriteShape = _c.CreateSpriteShape();
var compositionEllipseGeometry = CreateEllipseGeometry();
var compositionEllipseGeometry = _c.CreateEllipseGeometry();
compositionSpriteShape.Geometry = compositionEllipseGeometry;
if (_addDescriptions)
{
@ -2073,7 +2064,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
CompositionShape TranslateRectangleContent(TranslationContext context, ShapeContentContext shapeContext, Rectangle shapeContent)
{
var compositionRectangle = CreateSpriteShape();
var compositionRectangle = _c.CreateSpriteShape();
var position = context.TrimAnimatable(shapeContent.Position);
var size = context.TrimAnimatable(shapeContent.Size);
@ -2083,10 +2074,10 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
#if WorkAroundRectangleGeometryHalfDrawn
// Rounded rectangles do not have a problem, so create a rounded rectangle with a tiny corner
// radius to work around the bug.
var geometry = CreateRoundedRectangleGeometry();
var geometry = _c.CreateRoundedRectangleGeometry();
geometry.CornerRadius = new Sn.Vector2(0.000001F, 0.000001F);
#else
var geometry = CreateRectangleGeometry();
var geometry = _c.CreateRectangleGeometry();
#endif
compositionRectangle.Geometry = geometry;
@ -2125,7 +2116,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
ApplyVector2KeyFrameAnimation(context, size, geometry, nameof(Rectangle.Size));
}
var offsetExpressionAnimation = CreateExpressionAnimation(offsetExpression);
var offsetExpressionAnimation = _c.CreateExpressionAnimation(offsetExpression);
offsetExpressionAnimation.SetReferenceParameter("my", geometry);
StartExpressionAnimation(geometry, nameof(geometry.Offset), offsetExpressionAnimation);
}
@ -2133,7 +2124,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
else
{
// Use a rounded rectangle geometry.
var geometry = CreateRoundedRectangleGeometry();
var geometry = _c.CreateRoundedRectangleGeometry();
compositionRectangle.Geometry = geometry;
// If a RoundedRectangle is in the context, use it to override the corner radius.
@ -2184,7 +2175,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
ApplyVector2KeyFrameAnimation(context, size, geometry, nameof(Rectangle.Size));
}
var offsetExpressionAnimation = CreateExpressionAnimation(offsetExpression);
var offsetExpressionAnimation = _c.CreateExpressionAnimation(offsetExpression);
offsetExpressionAnimation.SetReferenceParameter("my", geometry);
StartExpressionAnimation(geometry, nameof(geometry.Offset), offsetExpressionAnimation);
}
@ -2242,7 +2233,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
var fillType = GetPathFillType(shapeContext.Fill);
// A path is represented as a SpriteShape with a CompositionPathGeometry.
var compositionPathGeometry = CreatePathGeometry();
var compositionPathGeometry = _c.CreatePathGeometry();
var compositionPath = new CompositionPath(
CanvasGeometry.CreateGroup(
@ -2252,7 +2243,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
compositionPathGeometry.Path = compositionPath;
var compositionSpriteShape = CreateSpriteShape();
var compositionSpriteShape = _c.CreateSpriteShape();
compositionSpriteShape.Geometry = compositionPathGeometry;
if (_addDescriptions)
@ -2275,9 +2266,9 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
var pathGeometry = context.TrimAnimatable(_lottieDataOptimizer.GetOptimized(path.Data));
// A path is represented as a SpriteShape with a CompositionPathGeometry.
var compositionPathGeometry = CreatePathGeometry();
var compositionPathGeometry = _c.CreatePathGeometry();
var compositionSpriteShape = CreateSpriteShape();
var compositionSpriteShape = _c.CreateSpriteShape();
compositionSpriteShape.Geometry = compositionPathGeometry;
if (pathGeometry.IsAnimated)
@ -2449,7 +2440,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
ApplyPercentKeyFrameAnimation(context, startPercent, geometry.Properties, "TStart", "TStart", null);
}
var trimStartExpression = CreateExpressionAnimation(ExpressionFactory.MinTStartTEnd);
var trimStartExpression = _c.CreateExpressionAnimation(ExpressionFactory.MinTStartTEnd);
trimStartExpression.SetReferenceParameter("my", geometry);
StartExpressionAnimation(geometry, nameof(geometry.TrimStart), trimStartExpression);
@ -2459,7 +2450,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
ApplyPercentKeyFrameAnimation(context, endPercent, geometry.Properties, "TEnd", "TEnd", null);
}
var trimEndExpression = CreateExpressionAnimation(ExpressionFactory.MaxTStartTEnd);
var trimEndExpression = _c.CreateExpressionAnimation(ExpressionFactory.MaxTStartTEnd);
trimEndExpression.SetReferenceParameter("my", geometry);
StartExpressionAnimation(geometry, nameof(geometry.TrimEnd), trimEndExpression);
}
@ -2598,10 +2589,10 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
return ShapeOrVisual.Null;
}
var rectangleGeometry = CreateRectangleGeometry();
var rectangleGeometry = _c.CreateRectangleGeometry();
rectangleGeometry.Size = Vector2(context.Layer.Width, context.Layer.Height);
var rectangle = CreateSpriteShape();
var rectangle = _c.CreateSpriteShape();
rectangle.Geometry = rectangleGeometry;
containerShapeContentNode.Shapes.Add(rectangle);
@ -2615,7 +2606,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
// for the layer from TryCreateContainerVisualTransformChain.
// If that layer has no masks, opacity is implemented via the alpha channel on the brush.
rectangle.FillBrush = layerHasMasks
? CreateColorBrush(context.Layer.Color)
? _c.CreateNonAnimatedColorBrush(context.Layer.Color)
: CreateAnimatedColorBrush(context, context.Layer.Color, context.TrimAnimatable(context.Layer.Transform.OpacityPercent));
if (_addDescriptions)
@ -2643,7 +2634,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
out ContainerVisual leafTransformNode)
{
// Create a ContainerVisual to apply the transform to.
leafTransformNode = CreateContainerVisual();
leafTransformNode = _c.CreateContainerVisual();
// Apply the transform.
TranslateAndApplyTransform(context, layer.Transform, leafTransformNode);
@ -2678,7 +2669,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
out CompositionContainerShape leafTransformNode)
{
// Create a ContainerVisual to apply the transform to.
leafTransformNode = CreateContainerShape();
leafTransformNode = _c.CreateContainerShape();
// Apply the transform from the layer.
TranslateAndApplyTransform(context, layer.Transform, leafTransformNode);
@ -2809,7 +2800,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
if (anchorIsAnimated)
{
container.Properties.InsertVector2("Anchor", initialAnchor);
var centerPointExpression = CreateExpressionAnimation(container.IsShape ? MyAnchor2 : MyAnchor3);
var centerPointExpression = _c.CreateExpressionAnimation(container.IsShape ? MyAnchor2 : MyAnchor3);
centerPointExpression.SetReferenceParameter("my", container);
StartExpressionAnimation(container, nameof(container.CenterPoint), centerPointExpression);
@ -2840,7 +2831,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
if (positionIsAnimated && anchorIsAnimated)
{
// Both position and anchor are animated.
offsetExpression = CreateExpressionAnimation(container.IsShape ? PositionMinusAnchor2 : PositionMinusAnchor3);
offsetExpression = _c.CreateExpressionAnimation(container.IsShape ? PositionMinusAnchor2 : PositionMinusAnchor3);
}
else if (positionIsAnimated)
{
@ -2873,7 +2864,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
// TODO - when we support spatial bezier CubicBezierFunction3, we can enable this. For now this
// may result in a CubicBezierFunction2 being applied to the Vector3 Offset property.
//ApplyVector3KeyFrameAnimation(context, (AnimatableVector3)position, container, "Offset");
offsetExpression = CreateExpressionAnimation(container.IsShape
offsetExpression = _c.CreateExpressionAnimation(container.IsShape
? (Expr)Expr.Vector2(
Expr.Subtract(Expr.Scalar("my.Position.X"), Expr.Scalar(initialAnchor.X)),
Expr.Subtract(Expr.Scalar("my.Position.Y"), Expr.Scalar(initialAnchor.Y)))
@ -2886,7 +2877,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
}
else
{
offsetExpression = CreateExpressionAnimation(container.IsShape
offsetExpression = _c.CreateExpressionAnimation(container.IsShape
? (Expr)Expr.Vector2(
Expr.Subtract(Expr.Scalar("my.Position.X"), Expr.Scalar(initialAnchor.X)),
Expr.Subtract(Expr.Scalar("my.Position.Y"), Expr.Scalar(initialAnchor.Y)))
@ -2898,7 +2889,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
else if (anchorIsAnimated)
{
// Only anchor is animated.
offsetExpression = CreateExpressionAnimation(container.IsShape
offsetExpression = _c.CreateExpressionAnimation(container.IsShape
? (Expr)Expr.Vector2(
Expr.Subtract(Expr.Scalar(initialPosition.X), Expr.Scalar("my.Anchor.X")),
Expr.Subtract(Expr.Scalar(initialPosition.Y), Expr.Scalar("my.Anchor.Y")))
@ -2967,7 +2958,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
var key = new ScaleAndOffset(scale, offset);
if (!_progressBindingAnimations.TryGetValue(key, out var bindingAnimation))
{
bindingAnimation = CreateExpressionAnimation(ScaledAndOffsetRootProgress(scale, offset));
bindingAnimation = _c.CreateExpressionAnimation(ScaledAndOffsetRootProgress(scale, offset));
bindingAnimation.SetReferenceParameter(RootName, _rootVisual);
_progressBindingAnimations.Add(key, bindingAnimation);
}
@ -3008,7 +2999,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
GenericCreateCompositionKeyFrameAnimation(
context,
value,
CreateScalarKeyFrameAnimation,
_c.CreateScalarKeyFrameAnimation,
(ca, progress, val, easing) => ca.InsertKeyFrame(progress, (float)(val * scale), easing),
null,
targetObject,
@ -3029,7 +3020,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
GenericCreateCompositionKeyFrameAnimation(
context,
value,
CreateColorKeyFrameAnimation,
_c.CreateColorKeyFrameAnimation,
(ca, progress, val, easing) => ca.InsertKeyFrame(progress, Color(val), easing),
null,
targetObject,
@ -3051,7 +3042,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
GenericCreateCompositionKeyFrameAnimation(
context,
value,
CreatePathKeyFrameAnimation,
_c.CreatePathKeyFrameAnimation,
(ca, progress, val, easing) => ca.InsertKeyFrame(
progress,
CompositionPathFromPathGeometry(
@ -3092,7 +3083,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
GenericCreateCompositionKeyFrameAnimation(
context,
value,
CreateVector2KeyFrameAnimation,
_c.CreateVector2KeyFrameAnimation,
(ca, progress, val, easing) => ca.InsertKeyFrame(progress, Vector2(val * scale), easing),
(ca, progress, expr, easing) => ca.InsertExpressionKeyFrame(progress, scale != 1 ? Scale(expr, scale) : expr.ToString(), easing),
targetObject,
@ -3114,7 +3105,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
GenericCreateCompositionKeyFrameAnimation(
context,
value,
CreateVector3KeyFrameAnimation,
_c.CreateVector3KeyFrameAnimation,
(ca, progress, val, easing) => ca.InsertKeyFrame(progress, Vector3(val) * (float)scale, easing),
(ca, progress, expr, easing) => ca.InsertExpressionKeyFrame(progress, scale != 1 ? Scale(expr, scale).ToString() : expr.ToString(), easing),
targetObject,
@ -3162,7 +3153,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
// Note that we could set an initial value for the property instead of using a key frame,
// but seeing as we're creating key frames anyway, it will be fewer operations to
// just use a first key frame and not set an initial value
insertKeyFrame(compositionAnimation, 0 /* progress */, firstKeyFrame.Value, CreateStepThenHoldEasingFunction() /*easing*/);
insertKeyFrame(compositionAnimation, 0 /* progress */, firstKeyFrame.Value, _c.CreateStepThenHoldEasingFunction() /*easing*/);
animationStartTime = context.StartTime;
}
@ -3213,7 +3204,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
if (progressMappingProperty == null)
{
progressMappingProperty = $"t{_tCounter++}";
progressMappingAnimation = CreateScalarKeyFrameAnimation();
progressMappingAnimation = _c.CreateScalarKeyFrameAnimation();
progressMappingAnimation.Duration = _lc.Duration;
}
#if LinearEasingOnSpatialBeziers
@ -3247,13 +3238,13 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
{
// Ensure the previous expression doesn't continue being evaluated during the current keyframe.
// This is necessary because the expression is only defined from the previous progress to the current progress.
insertKeyFrame(compositionAnimation, (float)previousProgress + KeyFrameProgressEpsilon, previousValue, CreateStepThenHoldEasingFunction());
insertKeyFrame(compositionAnimation, (float)previousProgress + KeyFrameProgressEpsilon, previousValue, _c.CreateStepThenHoldEasingFunction());
}
// The easing for a keyframe at 0 is unimportant, so always use Hold.
var easing = adjustedProgress == 0 ? HoldEasing.Instance : keyFrame.Easing;
insertKeyFrame(compositionAnimation, (float)adjustedProgress, keyFrame.Value, CreateCompositionEasingFunction(easing));
insertKeyFrame(compositionAnimation, (float)adjustedProgress, keyFrame.Value, _c.CreateCompositionEasingFunction(easing));
previousKeyFrameWasExpression = false;
}
else
@ -3273,16 +3264,16 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
// Add an animation to map from progress to t over the range of this key frame.
if (previousProgress > 0)
{
progressMappingAnimation.InsertKeyFrame((float)previousProgress + KeyFrameProgressEpsilon, 0, CreateStepThenHoldEasingFunction());
progressMappingAnimation.InsertKeyFrame((float)previousProgress + KeyFrameProgressEpsilon, 0, _c.CreateStepThenHoldEasingFunction());
}
progressMappingAnimation.InsertKeyFrame((float)adjustedProgress, 1, CreateCompositionEasingFunction(keyFrame.Easing));
progressMappingAnimation.InsertKeyFrame((float)adjustedProgress, 1, _c.CreateCompositionEasingFunction(keyFrame.Easing));
#endif
insertExpressionKeyFrame(
compositionAnimation,
(float)adjustedProgress,
cb, // Expression.
CreateStepThenHoldEasingFunction()); // Jump to the final value so the expression is evaluated all the way through.
_c.CreateStepThenHoldEasingFunction()); // Jump to the final value so the expression is evaluated all the way through.
// Note that a reference to the root Visual is required by the animation because it
// is used in the expression.
@ -3295,10 +3286,10 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
if (previousKeyFrameWasExpression)
{
// Ensure the previous expression doesn't continue being evaluated during the current keyframe.
insertKeyFrame(compositionAnimation, (float)previousProgress + KeyFrameProgressEpsilon, previousValue, CreateStepThenHoldEasingFunction());
insertKeyFrame(compositionAnimation, (float)previousProgress + KeyFrameProgressEpsilon, previousValue, _c.CreateStepThenHoldEasingFunction());
}
insertKeyFrame(compositionAnimation, (float)adjustedProgress, keyFrame.Value, CreateCompositionEasingFunction(keyFrame.Easing));
insertKeyFrame(compositionAnimation, (float)adjustedProgress, keyFrame.Value, _c.CreateCompositionEasingFunction(keyFrame.Easing));
previousKeyFrameWasExpression = false;
}
@ -3310,7 +3301,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
{
// Add a keyframe to hold the final value. Otherwise the expression on the last keyframe
// will get evaluated outside the bounds of its keyframe.
insertKeyFrame(compositionAnimation, (float)previousProgress + KeyFrameProgressEpsilon, (T)(object)previousValue, CreateStepThenHoldEasingFunction());
insertKeyFrame(compositionAnimation, (float)previousProgress + KeyFrameProgressEpsilon, (T)(object)previousValue, _c.CreateStepThenHoldEasingFunction());
}
// Add a reference to the root Visual if needed (i.e. if an expression keyframe was added).
@ -3417,7 +3408,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
var oneOne = Vector2(1);
var easing = CubicBezierFunction2.Create(Vector2(0), Vector2(controlPoint1), Vector2(controlPoint2), oneOne, remap);
var animation = CreateExpressionAnimation(Expr.Scalar($"({easing}).Y"));
var animation = _c.CreateExpressionAnimation(Expr.Scalar($"({easing}).Y"));
animation.SetReferenceParameter(RootName, _rootVisual);
StartExpressionAnimation(_rootVisual, propertyName, animation);
result = Expr.Scalar($"{RootName}.{propertyName}");
@ -3529,7 +3520,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
{
if (color.IsAnimated)
{
var result = CreateColorBrush(color.InitialValue);
var result = _c.CreateColorBrush(color.InitialValue);
ApplyColorKeyFrameAnimation(
context,
@ -3542,226 +3533,16 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.LottieToWinComp
}
else
{
return CreateNonAnimatedColorBrush(color.InitialValue);
return _c.CreateNonAnimatedColorBrush(color.InitialValue);
}
}
CompositionColorBrush CreateNonAnimatedColorBrush(Color color)
{
if (color.A == 0)
{
// Transparent brushes that are never animated are all equivalent.
color = LottieData.Color.TransparentBlack;
}
if (!_nonAnimatedColorBrushes.TryGetValue(color, out var result))
{
result = CreateColorBrush(color);
_nonAnimatedColorBrushes.Add(color, result);
}
return result;
}
// Implements IDisposable.Dispose(). Currently not needed but will be required
// if this class needs to hold onto any IDisposable objects.
void IDisposable.Dispose()
{
}
CompositionEllipseGeometry CreateEllipseGeometry()
{
return _c.CreateEllipseGeometry();
}
CompositionPathGeometry CreatePathGeometry()
{
return _c.CreatePathGeometry();
}
CompositionPathGeometry CreatePathGeometry(CompositionPath path)
{
return _c.CreatePathGeometry(path);
}
CompositionRectangleGeometry CreateRectangleGeometry()
{
return _c.CreateRectangleGeometry();
}
CompositionRoundedRectangleGeometry CreateRoundedRectangleGeometry()
{
return _c.CreateRoundedRectangleGeometry();
}
CompositionColorBrush CreateColorBrush(Color color)
{
return _c.CreateColorBrush(Color(color));
}
CompositionEasingFunction CreateCompositionEasingFunction(Easing easingFunction)
{
if (easingFunction == null)
{
return null;
}
switch (easingFunction.Type)
{
case Easing.EasingType.Linear:
return CreateLinearEasingFunction();
case Easing.EasingType.CubicBezier:
return CreateCubicBezierEasingFunction((CubicBezierEasing)easingFunction);
case Easing.EasingType.Hold:
return CreateHoldThenStepEasingFunction();
default:
throw new InvalidOperationException();
}
}
LinearEasingFunction CreateLinearEasingFunction()
{
if (_linearEasingFunction == null)
{
_linearEasingFunction = _c.CreateLinearEasingFunction();
}
return _linearEasingFunction;
}
CubicBezierEasingFunction CreateCubicBezierEasingFunction(CubicBezierEasing cubicBezierEasing)
{
if (!_cubicBezierEasingFunctions.TryGetValue(cubicBezierEasing, out var result))
{
// WinComp does not support control points with components > 1. Clamp the values to 1.
var controlPoint1 = ClampedVector2(cubicBezierEasing.ControlPoint1);
var controlPoint2 = ClampedVector2(cubicBezierEasing.ControlPoint2);
result = _c.CreateCubicBezierEasingFunction(controlPoint1, controlPoint2);
_cubicBezierEasingFunctions.Add(cubicBezierEasing, result);
}
return result;
}
// Returns an easing function that holds its initial value and steps to the final value at the end.
StepEasingFunction CreateHoldThenStepEasingFunction()
{
if (_holdStepEasingFunction == null)
{
_holdStepEasingFunction = _c.CreateStepEasingFunction(1);
_holdStepEasingFunction.IsFinalStepSingleFrame = true;
}
return _holdStepEasingFunction;
}
// Returns an easing function that steps immediately to its final value.
StepEasingFunction CreateStepThenHoldEasingFunction()
{
if (_jumpStepEasingFunction == null)
{
_jumpStepEasingFunction = _c.CreateStepEasingFunction(1);
_jumpStepEasingFunction.IsInitialStepSingleFrame = true;
}
return _jumpStepEasingFunction;
}
ScalarKeyFrameAnimation CreateScalarKeyFrameAnimation()
{
return _c.CreateScalarKeyFrameAnimation();
}
ColorKeyFrameAnimation CreateColorKeyFrameAnimation()
{
var result = _c.CreateColorKeyFrameAnimation();
// BodyMovin always uses RGB interpolation. Composition defaults to
// HSL. Override the default to be compatible with BodyMovin.
result.InterpolationColorSpace = CompositionColorSpace.Rgb;
return result;
}
PathKeyFrameAnimation CreatePathKeyFrameAnimation()
{
return _c.CreatePathKeyFrameAnimation();
}
Vector2KeyFrameAnimation CreateVector2KeyFrameAnimation()
{
return _c.CreateVector2KeyFrameAnimation();
}
Vector3KeyFrameAnimation CreateVector3KeyFrameAnimation()
{
return _c.CreateVector3KeyFrameAnimation();
}
InsetClip CreateInsetClip()
{
return _c.CreateInsetClip();
}
CompositionGeometricClip CreateCompositionGeometricClip()
{
return _c.CreateCompositionGeometricClip();
}
CompositionContainerShape CreateContainerShape()
{
return _c.CreateContainerShape();
}
ContainerVisual CreateContainerVisual()
{
return _c.CreateContainerVisual();
}
SpriteVisual CreateSpriteVisual()
{
return _c.CreateSpriteVisual();
}
ShapeVisual CreateShapeVisualWithChild(CompositionShape child, Sn.Vector2 size)
{
var result = _c.CreateShapeVisual();
result.Shapes.Add(child);
// ShapeVisual clips to its size
#if NoClipping
result.Size = Vector2(float.MaxValue);
#else
result.Size = size;
#endif
return result;
}
CompositionSpriteShape CreateSpriteShape()
{
return _c.CreateSpriteShape();
}
ExpressionAnimation CreateExpressionAnimation(Expr expression)
{
return _c.CreateExpressionAnimation(expression);
}
CompositionVisualSurface CreateVisualSurface()
{
return _c.CreateVisualSurface();
}
CompositionSurfaceBrush CreateSurfaceBrush(ICompositionSurface surface)
{
return _c.CreateSurfaceBrush(surface);
}
CompositionEffectFactory CreateEffectFactory(GraphicsEffectBase effect)
{
return _c.CreateEffectFactory(effect);
}
static CompositionStrokeCap StrokeCap(SolidColorStroke.LineCapType lineCapType)
{
switch (lineCapType)

Просмотреть файл

@ -629,13 +629,13 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.UIData.CodeGen
foreach (var node in _nodes.Where(n => n.UsesStream))
{
WriteBytesField(builder, node.LoadedImageSurfaceBytesFieldName);
builder.OpenScope();
var loadedImageSurface = (Wmd.LoadedImageSurfaceFromStream)node.Object;
builder.BytesToLiteral(loadedImageSurface.Bytes, maximumColumns: 100);
builder.UnIndent();
builder.WriteLine("};");
bytesWritten = true;
WriteBytesField(builder, node.LoadedImageSurfaceBytesFieldName);
builder.OpenScope();
var loadedImageSurface = (Wmd.LoadedImageSurfaceFromStream)node.Object;
builder.BytesToLiteral(loadedImageSurface.Bytes, maximumColumns: 100);
builder.UnIndent();
builder.WriteLine("};");
bytesWritten = true;
}
if (bytesWritten)
@ -717,6 +717,8 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.UIData.CodeGen
return GenerateColorKeyFrameAnimationFactory(builder, (ColorKeyFrameAnimation)obj, node);
case CompositionObjectType.CompositionColorBrush:
return GenerateCompositionColorBrushFactory(builder, (CompositionColorBrush)obj, node);
case CompositionObjectType.CompositionColorGradientStop:
return GenerateCompositionColorGradientStopFactory(builder, (CompositionColorGradientStop)obj, node);
case CompositionObjectType.CompositionContainerShape:
return GenerateContainerShapeFactory(builder, (CompositionContainerShape)obj, node);
case CompositionObjectType.CompositionEffectBrush:
@ -725,11 +727,15 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.UIData.CodeGen
return GenerateCompositionEllipseGeometryFactory(builder, (CompositionEllipseGeometry)obj, node);
case CompositionObjectType.CompositionGeometricClip:
return GenerateCompositionGeometricClipFactory(builder, (CompositionGeometricClip)obj, node);
case CompositionObjectType.CompositionLinearGradientBrush:
return GenerateCompositionLinearGradientBrushFactory(builder, (CompositionLinearGradientBrush)obj, node);
case CompositionObjectType.CompositionPathGeometry:
return GenerateCompositionPathGeometryFactory(builder, (CompositionPathGeometry)obj, node);
case CompositionObjectType.CompositionPropertySet:
// Do not generate code for property sets. It is done inline in the CompositionObject initialization.
return true;
case CompositionObjectType.CompositionRadialGradientBrush:
return GenerateCompositionRadialGradientBrushFactory(builder, (CompositionRadialGradientBrush)obj, node);
case CompositionObjectType.CompositionRectangleGeometry:
return GenerateCompositionRectangleGeometryFactory(builder, (CompositionRectangleGeometry)obj, node);
case CompositionObjectType.CompositionRoundedRectangleGeometry:
@ -818,6 +824,32 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.UIData.CodeGen
return true;
}
bool GenerateCompositionLinearGradientBrushFactory(CodeBuilder builder, CompositionLinearGradientBrush obj, ObjectData node)
{
WriteObjectFactoryStart(builder, node);
WriteCreateAssignment(builder, node, $"_c{Deref}CreateLinearGradientBrush()");
InitializeCompositionGradientBrush(builder, obj, node);
if (obj.StartPoint.HasValue)
{
builder.WriteLine($"result{Deref}StartPoint = {Vector2(obj.StartPoint.Value)};");
}
if (obj.EndPoint.HasValue)
{
builder.WriteLine($"result{Deref}EndPoint = {Vector2(obj.EndPoint.Value)};");
}
StartAnimations(builder, obj, node);
WriteObjectFactoryEnd(builder);
return true;
}
bool GenerateCompositionRadialGradientBrushFactory(CodeBuilder builder, CompositionRadialGradientBrush obj, ObjectData node)
{
throw new NotImplementedException();
}
bool GenerateLinearEasingFunctionFactory(CodeBuilder builder, LinearEasingFunction obj, ObjectData node)
{
WriteSimpleObjectFactory(builder, node, $"_c{Deref}CreateLinearEasingFunction()");
@ -1061,6 +1093,67 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.UIData.CodeGen
}
}
void InitializeCompositionGradientBrush(CodeBuilder builder, CompositionGradientBrush obj, ObjectData node)
{
InitializeCompositionObject(builder, obj, node);
if (obj.AnchorPoint.HasValue)
{
builder.WriteLine($"result{Deref}AnchorPoint = {Vector2(obj.AnchorPoint.Value)};");
}
if (obj.CenterPoint.HasValue)
{
builder.WriteLine($"result{Deref}CenterPoint = {Vector2(obj.CenterPoint.Value)};");
}
if (obj.ColorStops.Count > 0)
{
builder.WriteLine("colorStops = result.ColorStops;");
foreach (var colorStop in obj.ColorStops)
{
builder.WriteLine($"colorStops{Deref}{IListAdd}({CallFactoryFromFor(node, colorStop)});");
}
}
// TODO - extendmode
if (obj.ExtendMode.HasValue)
{
builder.WriteLine($"result{Deref}ExtendMode = TODO");
}
// TODO - interpolationspace
if (obj.InterpolationSpace.HasValue)
{
builder.WriteLine($"result{Deref}InterpolationSpace = TODO");
}
// TODO - mappingmode
if (obj.MappingMode.HasValue)
{
builder.WriteLine($"result{Deref}MapingMode = TODO");
}
if (obj.Offset.HasValue)
{
builder.WriteLine($"result{Deref}Offset = {Vector2(obj.Offset.Value)}");
}
if (obj.RotationAngleInDegrees.HasValue)
{
builder.WriteLine($"result{Deref}RotationAngleInDegrees = {Float(obj.RotationAngleInDegrees.Value)}");
}
if (obj.Scale.HasValue)
{
builder.WriteLine($"result{Deref}Scale = {Vector2(obj.Scale.Value)}");
}
if (obj.TransformMatrix.HasValue)
{
builder.WriteLine($"result{Deref}TransformMatrix = {Matrix3x2(obj.TransformMatrix.Value)}");
}
}
void InitializeCompositionShape(CodeBuilder builder, CompositionShape obj, ObjectData node)
{
InitializeCompositionObject(builder, obj, node);
@ -1380,6 +1473,29 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.UIData.CodeGen
return true;
}
bool GenerateCompositionColorGradientStopFactory(CodeBuilder builder, CompositionColorGradientStop obj, ObjectData node)
{
var createCallText = $"_c{Deref}CreateCompositionColorGradientStop({Float(obj.Offset)}, {Color(obj.Color)})";
// TODO - support animated gradient stops.
if (obj.Animators.Count > 0)
{
WriteObjectFactoryStart(builder, node);
WriteCreateAssignment(builder, node, createCallText);
//InitializeCompositionBrush(builder, obj, node);
StartAnimations(builder, obj, node);
WriteObjectFactoryEnd(builder);
throw new NotImplementedException();
}
else
{
WriteSimpleObjectFactory(builder, node, createCallText);
}
return true;
}
bool GenerateShapeVisualFactory(CodeBuilder builder, ShapeVisual obj, ObjectData node)
{
WriteObjectFactoryStart(builder, node);

Просмотреть файл

@ -134,31 +134,38 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.UIData.CodeGen
where T : CompositionShape
{
CacheAndInitializeCompositionObject(source, target);
if (source.CenterPoint.HasValue)
target.CenterPoint = source.CenterPoint;
target.Offset = source.Offset;
target.RotationAngleInDegrees = source.RotationAngleInDegrees;
target.Scale = source.Scale;
target.TransformMatrix = source.TransformMatrix;
return target;
}
T CacheAndInitializeGradientBrush<T>(CompositionGradientBrush source, T target)
where T : CompositionGradientBrush
{
CacheAndInitializeCompositionObject(source, target);
target.AnchorPoint = source.AnchorPoint;
target.CenterPoint = source.CenterPoint;
var stops = target.ColorStops;
foreach (var stop in source.ColorStops)
{
target.CenterPoint = source.CenterPoint;
target.ColorStops.Add(GetCompositionColorGradientStop(stop));
}
if (source.Offset.HasValue)
{
target.Offset = source.Offset;
}
if (source.RotationAngleInDegrees.HasValue)
{
target.RotationAngleInDegrees = source.RotationAngleInDegrees.Value;
}
if (source.Scale.HasValue)
{
target.Scale = source.Scale;
}
if (source.TransformMatrix.HasValue)
{
target.TransformMatrix = source.TransformMatrix.Value;
}
target.ExtendMode = source.ExtendMode;
target.InterpolationSpace = source.InterpolationSpace;
target.MappingMode = source.MappingMode;
target.Offset = source.Offset;
target.RotationAngleInDegrees = source.RotationAngleInDegrees;
target.Scale = source.Scale;
target.TransformMatrix = source.TransformMatrix;
return target;
}
@ -171,35 +178,12 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.UIData.CodeGen
target.Clip = GetCompositionClip(source.Clip);
}
if (source.CenterPoint.HasValue)
{
target.CenterPoint = source.CenterPoint;
}
if (source.Offset.HasValue)
{
target.Offset = source.Offset;
}
if (source.Opacity.HasValue)
{
target.Opacity = source.Opacity.Value;
}
if (source.RotationAngleInDegrees.HasValue)
{
target.RotationAngleInDegrees = source.RotationAngleInDegrees.Value;
}
if (source.Scale.HasValue)
{
target.Scale = source.Scale;
}
if (source.Size.HasValue)
{
target.Size = source.Size;
}
target.CenterPoint = source.CenterPoint;
target.Offset = source.Offset;
target.Opacity = source.Opacity;
target.RotationAngleInDegrees = source.RotationAngleInDegrees;
target.Scale = source.Scale;
target.Size = source.Size;
return target;
}
@ -427,6 +411,8 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.UIData.CodeGen
return GetColorKeyFrameAnimation((ColorKeyFrameAnimation)obj);
case CompositionObjectType.CompositionColorBrush:
return GetCompositionColorBrush((CompositionColorBrush)obj);
case CompositionObjectType.CompositionColorGradientStop:
return GetCompositionColorGradientStop((CompositionColorGradientStop)obj);
case CompositionObjectType.CompositionContainerShape:
return GetCompositionContainerShape((CompositionContainerShape)obj);
case CompositionObjectType.CompositionEffectBrush:
@ -435,10 +421,14 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.UIData.CodeGen
return GetCompositionEllipseGeometry((CompositionEllipseGeometry)obj);
case CompositionObjectType.CompositionGeometricClip:
return GetCompositionGeometricClip((CompositionGeometricClip)obj);
case CompositionObjectType.CompositionLinearGradientBrush:
return GetCompositionLinearGradientBrush((CompositionLinearGradientBrush)obj);
case CompositionObjectType.CompositionPathGeometry:
return GetCompositionPathGeometry((CompositionPathGeometry)obj);
case CompositionObjectType.CompositionPropertySet:
return GetCompositionPropertySet((CompositionPropertySet)obj);
case CompositionObjectType.CompositionRadialGradientBrush:
return GetCompositionRadialGradientBrush((CompositionRadialGradientBrush)obj);
case CompositionObjectType.CompositionRectangleGeometry:
return GetCompositionRectangleGeometry((CompositionRectangleGeometry)obj);
case CompositionObjectType.CompositionRoundedRectangleGeometry:
@ -777,7 +767,7 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.UIData.CodeGen
return result;
}
result = CacheAndInitializeCompositionObject(obj, _c.CreateCompositionGeometricClip());
result = CacheAndInitializeCompositionObject(obj, _c.CreateGeometricClip());
result.Geometry = GetCompositionGeometry(obj.Geometry);
return result;
@ -945,6 +935,37 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.UIData.CodeGen
return result;
}
CompositionLinearGradientBrush GetCompositionLinearGradientBrush(CompositionLinearGradientBrush obj)
{
if (GetExisting(obj, out CompositionLinearGradientBrush result))
{
return result;
}
result = CacheAndInitializeGradientBrush(obj, _c.CreateLinearGradientBrush());
result.StartPoint = obj.StartPoint;
result.EndPoint = obj.EndPoint;
StartAnimationsAndFreeze(obj, result);
return result;
}
CompositionRadialGradientBrush GetCompositionRadialGradientBrush(CompositionRadialGradientBrush obj)
{
if (GetExisting(obj, out CompositionRadialGradientBrush result))
{
return result;
}
result = CacheAndInitializeGradientBrush(obj, _c.CreateRadialGradientBrush());
result.EllipseCenter = obj.EllipseCenter;
result.EllipseRadius = obj.EllipseRadius;
result.GradientOriginOffset = obj.GradientOriginOffset;
StartAnimationsAndFreeze(obj, result);
return result;
}
CompositionShape GetCompositionShape(CompositionShape obj)
{
switch (obj.Type)
@ -1286,6 +1307,9 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.UIData.CodeGen
return GetCompositionColorBrush((CompositionColorBrush)obj);
case CompositionObjectType.CompositionEffectBrush:
return GetCompositionEffectBrush((CompositionEffectBrush)obj);
case CompositionObjectType.CompositionLinearGradientBrush:
case CompositionObjectType.CompositionRadialGradientBrush:
return GetCompositionGradientBrush((CompositionGradientBrush)obj);
case CompositionObjectType.CompositionSurfaceBrush:
return GetCompositionSurfaceBrush((CompositionSurfaceBrush)obj);
default:
@ -1293,6 +1317,19 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.UIData.CodeGen
}
}
CompositionGradientBrush GetCompositionGradientBrush(CompositionGradientBrush obj)
{
switch (obj.Type)
{
case CompositionObjectType.CompositionLinearGradientBrush:
return GetCompositionLinearGradientBrush((CompositionLinearGradientBrush)obj);
case CompositionObjectType.CompositionRadialGradientBrush:
return GetCompositionRadialGradientBrush((CompositionRadialGradientBrush)obj);
default:
throw new InvalidOperationException();
}
}
CompositionColorBrush GetCompositionColorBrush(CompositionColorBrush obj)
{
if (GetExisting(obj, out CompositionColorBrush result))
@ -1305,6 +1342,18 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.UIData.CodeGen
return result;
}
CompositionColorGradientStop GetCompositionColorGradientStop(CompositionColorGradientStop obj)
{
if (GetExisting(obj, out CompositionColorGradientStop result))
{
return result;
}
result = CacheAndInitializeCompositionObject(obj, _c.CreateColorGradientStop(obj.Offset, obj.Color));
StartAnimationsAndFreeze(obj, result);
return result;
}
ICompositionSurface GetCompositionSurface(ICompositionSurface obj)
{
switch (obj)

Просмотреть файл

@ -276,10 +276,13 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.UIData.Tools
case CompositionObjectType.AnimationController:
case CompositionObjectType.ColorKeyFrameAnimation:
case CompositionObjectType.CompositionColorBrush:
case CompositionObjectType.CompositionColorGradientStop:
case CompositionObjectType.CompositionEllipseGeometry:
case CompositionObjectType.CompositionLinearGradientBrush:
case CompositionObjectType.CompositionGeometricClip:
case CompositionObjectType.CompositionPathGeometry:
case CompositionObjectType.CompositionPropertySet:
case CompositionObjectType.CompositionRadialGradientBrush:
case CompositionObjectType.CompositionRectangleGeometry:
case CompositionObjectType.CompositionRoundedRectangleGeometry:
case CompositionObjectType.CompositionViewBox:

Просмотреть файл

@ -113,6 +113,9 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.UIData.Tools
case CompositionObjectType.CompositionColorBrush:
VisitCompositionColorBrush((CompositionColorBrush)obj, node);
break;
case CompositionObjectType.CompositionColorGradientStop:
VisitCompositionColorGradientStop((CompositionColorGradientStop)obj, node);
break;
case CompositionObjectType.CompositionContainerShape:
VisitCompositionContainerShape((CompositionContainerShape)obj, node);
break;
@ -125,12 +128,18 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.UIData.Tools
case CompositionObjectType.CompositionGeometricClip:
VisitCompositionGeometricClip((CompositionGeometricClip)obj, node);
break;
case CompositionObjectType.CompositionLinearGradientBrush:
VisitCompositionLinearGradientBrush((CompositionLinearGradientBrush)obj, node);
break;
case CompositionObjectType.CompositionPathGeometry:
VisitCompositionPathGeometry((CompositionPathGeometry)obj, node);
break;
case CompositionObjectType.CompositionPropertySet:
VisitCompositionPropertySet((CompositionPropertySet)obj, node);
break;
case CompositionObjectType.CompositionRadialGradientBrush:
VisitCompositionRadialGradientBrush((CompositionRadialGradientBrush)obj, node);
break;
case CompositionObjectType.CompositionRectangleGeometry:
VisitCompositionRectangleGeometry((CompositionRectangleGeometry)obj, node);
break;
@ -518,6 +527,22 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.UIData.Tools
return true;
}
bool VisitCompositionGradientBrush(CompositionGradientBrush obj, T node)
{
VisitCompositionBrush(obj, node);
foreach (var stop in obj.ColorStops)
{
Reference(node, stop);
}
return true;
}
bool VisitCompositionLinearGradientBrush(CompositionLinearGradientBrush obj, T node)
{
return VisitCompositionGradientBrush(obj, node);
}
bool VisitCompositionPathGeometry(CompositionPathGeometry obj, T node)
{
VisitCompositionGeometry(obj, node);
@ -529,6 +554,11 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.UIData.Tools
return true;
}
bool VisitCompositionRadialGradientBrush(CompositionRadialGradientBrush obj, T node)
{
return VisitCompositionGradientBrush(obj, node);
}
bool VisitCompositionBrush(CompositionBrush obj, T node)
{
return VisitCompositionObject(obj, node);
@ -544,6 +574,11 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.UIData.Tools
return VisitCompositionBrush(obj, node);
}
bool VisitCompositionColorGradientStop(CompositionColorGradientStop obj, T node)
{
return VisitCompositionObject(obj, node);
}
bool VisitCompositionContainerShape(CompositionContainerShape obj, T node)
{
VisitCompositionShape(obj, node);

Просмотреть файл

@ -17,138 +17,115 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.UIData.Tools
#endif
sealed class Stats
{
readonly int _compositionObjectCount;
readonly int _compositionPathCount;
readonly int _canvasGeometryCount;
readonly int _animationControllerCount;
readonly int _colorKeyFrameAnimationCount;
readonly int _colorBrushCount;
readonly int _containerShapeCount;
readonly int _effectBrushCount;
readonly int _ellipseGeometryCount;
readonly int _geometricClipCount;
readonly int _pathGeometryCount;
readonly int _propertySetCount;
readonly int _rectangleGeometryCount;
readonly int _roundedRectangleGeometryCount;
readonly int _spriteShapeCount;
readonly int _surfaceBrushCount;
readonly int _viewBoxCount;
readonly int _visualSurfaceCount;
readonly int _containerVisualCount;
readonly int _cubicBezierEasingFunctionCount;
readonly int _expressionAnimationCount;
readonly int _insetClipCount;
readonly int _linearEasingFunctionCount;
readonly int _pathKeyFrameAnimationCount;
readonly int _scalarKeyFrameAnimationCount;
readonly int _shapeVisualCount;
readonly int _spriteVisualCount;
readonly int _stepEasingFunctionCount;
readonly int _vector2KeyFrameAnimationCount;
readonly int _vector3KeyFrameAnimationCount;
readonly int _propertySetPropertyCount;
public Stats(CompositionObject root)
{
var objectGraph = Graph.FromCompositionObject(root, includeVertices: false);
_compositionPathCount = objectGraph.CompositionPathNodes.Count();
_canvasGeometryCount = objectGraph.CanvasGeometryNodes.Count();
CompositionPathCount = objectGraph.CompositionPathNodes.Count();
CanvasGeometryCount = objectGraph.CanvasGeometryNodes.Count();
foreach (var n in objectGraph.CompositionObjectNodes)
{
_compositionObjectCount++;
CompositionObjectCount++;
switch (n.Object.Type)
{
case CompositionObjectType.AnimationController:
_animationControllerCount++;
AnimationControllerCount++;
break;
case CompositionObjectType.ColorKeyFrameAnimation:
_colorKeyFrameAnimationCount++;
ColorKeyFrameAnimationCount++;
break;
case CompositionObjectType.CompositionColorBrush:
_colorBrushCount++;
ColorBrushCount++;
break;
case CompositionObjectType.CompositionColorGradientStop:
ColorGradientStopCount++;
break;
case CompositionObjectType.CompositionContainerShape:
_containerShapeCount++;
ContainerShapeCount++;
break;
case CompositionObjectType.CompositionEffectBrush:
_effectBrushCount++;
EffectBrushCount++;
break;
case CompositionObjectType.CompositionEllipseGeometry:
_ellipseGeometryCount++;
EllipseGeometryCount++;
break;
case CompositionObjectType.CompositionGeometricClip:
_geometricClipCount++;
GeometricClipCount++;
break;
case CompositionObjectType.CompositionLinearGradientBrush:
LinearGradientBrushCount++;
break;
case CompositionObjectType.CompositionPathGeometry:
_pathGeometryCount++;
PathGeometryCount++;
break;
case CompositionObjectType.CompositionPropertySet:
{
var propertyCount = ((CompositionPropertySet)n.Object).PropertyNames.Count();
if (propertyCount > 0)
{
_propertySetCount++;
_propertySetPropertyCount += propertyCount;
PropertySetCount++;
PropertySetPropertyCount += propertyCount;
}
}
break;
case CompositionObjectType.CompositionRadialGradientBrush:
RadialGradientBrushCount++;
break;
case CompositionObjectType.CompositionRectangleGeometry:
_rectangleGeometryCount++;
RectangleGeometryCount++;
break;
case CompositionObjectType.CompositionRoundedRectangleGeometry:
_roundedRectangleGeometryCount++;
RoundedRectangleGeometryCount++;
break;
case CompositionObjectType.CompositionSpriteShape:
_spriteShapeCount++;
SpriteShapeCount++;
break;
case CompositionObjectType.CompositionSurfaceBrush:
_surfaceBrushCount++;
SurfaceBrushCount++;
break;
case CompositionObjectType.CompositionViewBox:
_viewBoxCount++;
ViewBoxCount++;
break;
case CompositionObjectType.CompositionVisualSurface:
_visualSurfaceCount++;
VisualSurfaceCount++;
break;
case CompositionObjectType.ContainerVisual:
_containerVisualCount++;
ContainerVisualCount++;
break;
case CompositionObjectType.CubicBezierEasingFunction:
_cubicBezierEasingFunctionCount++;
CubicBezierEasingFunctionCount++;
break;
case CompositionObjectType.ExpressionAnimation:
_expressionAnimationCount++;
ExpressionAnimationCount++;
break;
case CompositionObjectType.InsetClip:
_insetClipCount++;
InsetClipCount++;
break;
case CompositionObjectType.LinearEasingFunction:
_linearEasingFunctionCount++;
LinearEasingFunctionCount++;
break;
case CompositionObjectType.PathKeyFrameAnimation:
_pathKeyFrameAnimationCount++;
PathKeyFrameAnimationCount++;
break;
case CompositionObjectType.ScalarKeyFrameAnimation:
_scalarKeyFrameAnimationCount++;
ScalarKeyFrameAnimationCount++;
break;
case CompositionObjectType.ShapeVisual:
_shapeVisualCount++;
ShapeVisualCount++;
break;
case CompositionObjectType.SpriteVisual:
_spriteVisualCount++;
SpriteVisualCount++;
break;
case CompositionObjectType.StepEasingFunction:
_stepEasingFunctionCount++;
StepEasingFunctionCount++;
break;
case CompositionObjectType.Vector2KeyFrameAnimation:
_vector2KeyFrameAnimationCount++;
Vector2KeyFrameAnimationCount++;
break;
case CompositionObjectType.Vector3KeyFrameAnimation:
_vector3KeyFrameAnimationCount++;
Vector3KeyFrameAnimationCount++;
break;
default:
throw new InvalidOperationException();
@ -156,66 +133,72 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.UIData.Tools
}
}
public int CompositionObjectCount => _compositionObjectCount;
public int CompositionObjectCount { get; }
public int CompositionPathCount => _compositionPathCount;
public int CompositionPathCount { get; }
public int CanvasGeometryCount => _canvasGeometryCount;
public int CanvasGeometryCount { get; }
public int AnimationControllerCount => _animationControllerCount;
public int AnimationControllerCount { get; }
public int ColorKeyFrameAnimationCount => _colorKeyFrameAnimationCount;
public int ColorKeyFrameAnimationCount { get; }
public int ColorBrushCount => _colorBrushCount;
public int ColorBrushCount { get; }
public int ContainerShapeCount => _containerShapeCount;
public int ColorGradientStopCount { get; }
public int EffectBrushCount => _effectBrushCount;
public int ContainerShapeCount { get; }
public int EllipseGeometryCount => _ellipseGeometryCount;
public int EffectBrushCount { get; }
public int GeometricClipCount => _geometricClipCount;
public int EllipseGeometryCount { get; }
public int PathGeometryCount => _pathGeometryCount;
public int GeometricClipCount { get; }
public int PropertySetPropertyCount => _propertySetPropertyCount;
public int LinearGradientBrushCount { get; }
public int PropertySetCount => _propertySetCount;
public int PathGeometryCount { get; }
public int RectangleGeometryCount => _rectangleGeometryCount;
public int PropertySetPropertyCount { get; }
public int RoundedRectangleGeometryCount => _roundedRectangleGeometryCount;
public int PropertySetCount { get; }
public int SpriteShapeCount => _spriteShapeCount;
public int RadialGradientBrushCount { get; }
public int SurfaceBrushCount => _surfaceBrushCount;
public int RectangleGeometryCount { get; }
public int ViewBoxCount => _viewBoxCount;
public int RoundedRectangleGeometryCount { get; }
public int VisualSurfaceCount => _visualSurfaceCount;
public int SpriteShapeCount { get; }
public int ContainerVisualCount => _containerVisualCount;
public int SurfaceBrushCount { get; }
public int CubicBezierEasingFunctionCount => _cubicBezierEasingFunctionCount;
public int ViewBoxCount { get; }
public int ExpressionAnimationCount => _expressionAnimationCount;
public int VisualSurfaceCount { get; }
public int InsetClipCount => _insetClipCount;
public int ContainerVisualCount { get; }
public int LinearEasingFunctionCount => _linearEasingFunctionCount;
public int CubicBezierEasingFunctionCount { get; }
public int PathKeyFrameAnimationCount => _pathKeyFrameAnimationCount;
public int ExpressionAnimationCount { get; }
public int ScalarKeyFrameAnimationCount => _scalarKeyFrameAnimationCount;
public int InsetClipCount { get; }
public int ShapeVisualCount => _shapeVisualCount;
public int LinearEasingFunctionCount { get; }
public int SpriteVisualCount => _spriteVisualCount;
public int PathKeyFrameAnimationCount { get; }
public int StepEasingFunctionCount => _stepEasingFunctionCount;
public int ScalarKeyFrameAnimationCount { get; }
public int Vector2KeyFrameAnimationCount => _vector2KeyFrameAnimationCount;
public int ShapeVisualCount { get; }
public int Vector3KeyFrameAnimationCount => _vector3KeyFrameAnimationCount;
public int SpriteVisualCount { get; }
public int StepEasingFunctionCount { get; }
public int Vector2KeyFrameAnimationCount { get; }
public int Vector3KeyFrameAnimationCount { get; }
}
}

Просмотреть файл

@ -0,0 +1,25 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace Microsoft.Toolkit.Uwp.UI.Lottie.WinCompData
{
#if PUBLIC_WinCompData
public
#endif
sealed class CompositionColorGradientStop : CompositionObject
{
internal CompositionColorGradientStop(float offset, Wui.Color color)
{
Color = color;
Offset = offset;
}
public Wui.Color Color { get; set; }
public float Offset { get; set; }
/// <inheritdoc/>
public override CompositionObjectType Type => CompositionObjectType.CompositionColorGradientStop;
}
}

Просмотреть файл

@ -0,0 +1,40 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Numerics;
using Microsoft.Toolkit.Uwp.UI.Lottie.WinCompData.Tools;
namespace Microsoft.Toolkit.Uwp.UI.Lottie.WinCompData
{
#if PUBLIC_WinCompData
public
#endif
abstract class CompositionGradientBrush : CompositionBrush
{
internal CompositionGradientBrush()
{
}
public Vector2? AnchorPoint { get; set; }
public Vector2? CenterPoint { get; set; }
public IList<CompositionColorGradientStop> ColorStops { get; } = new ListOfNeverNull<CompositionColorGradientStop>();
public CompositionGradientExtendMode? ExtendMode { get; set; }
public CompositionColorSpace? InterpolationSpace { get; set; }
public CompositionMappingMode? MappingMode { get; set; }
public Vector2? Offset { get; set; }
public float? RotationAngleInDegrees { get; set; }
public Vector2? Scale { get; set; }
public Matrix3x2? TransformMatrix { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,19 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Numerics;
namespace Microsoft.Toolkit.Uwp.UI.Lottie.WinCompData
{
#if PUBLIC_WinCompData
public
#endif
enum CompositionGradientExtendMode
{
Clamp = 0,
Wrap = 1,
Mirror = 2,
}
}

Просмотреть файл

@ -0,0 +1,25 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Numerics;
namespace Microsoft.Toolkit.Uwp.UI.Lottie.WinCompData
{
#if PUBLIC_WinCompData
public
#endif
sealed class CompositionLinearGradientBrush : CompositionGradientBrush
{
internal CompositionLinearGradientBrush()
{
}
public Vector2? EndPoint { get; set; }
public Vector2? StartPoint { get; set; }
/// <inheritdoc/>
public override CompositionObjectType Type => CompositionObjectType.CompositionLinearGradientBrush;
}
}

Просмотреть файл

@ -0,0 +1,18 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Numerics;
namespace Microsoft.Toolkit.Uwp.UI.Lottie.WinCompData
{
#if PUBLIC_WinCompData
public
#endif
enum CompositionMappingMode
{
Absolute = 0,
Relative = 1,
}
}

Просмотреть файл

@ -12,13 +12,16 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.WinCompData
AnimationController,
ColorKeyFrameAnimation,
CompositionColorBrush,
CompositionColorGradientStop,
CompositionContainerShape,
CompositionEffectBrush,
CompositionEffectFactory,
CompositionEllipseGeometry,
CompositionGeometricClip,
CompositionLinearGradientBrush,
CompositionPathGeometry,
CompositionPropertySet,
CompositionRadialGradientBrush,
CompositionRectangleGeometry,
CompositionRoundedRectangleGeometry,
CompositionSpriteShape,

Просмотреть файл

@ -0,0 +1,27 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Numerics;
namespace Microsoft.Toolkit.Uwp.UI.Lottie.WinCompData
{
#if PUBLIC_WinCompData
public
#endif
sealed class CompositionRadialGradientBrush : CompositionGradientBrush
{
internal CompositionRadialGradientBrush()
{
}
public Vector2? EllipseCenter { get; set; }
public Vector2? EllipseRadius { get; set; }
public Vector2? GradientOriginOffset { get; set; }
/// <inheritdoc/>
public override CompositionObjectType Type => CompositionObjectType.CompositionRadialGradientBrush;
}
}

Просмотреть файл

@ -2,7 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Numerics;
using Microsoft.Toolkit.Uwp.UI.Lottie.WinCompData.Expressions;
using Microsoft.Toolkit.Uwp.UI.Lottie.WinCompData.Mgce;
namespace Microsoft.Toolkit.Uwp.UI.Lottie.WinCompData
{
@ -11,60 +12,66 @@ namespace Microsoft.Toolkit.Uwp.UI.Lottie.WinCompData
#endif
sealed class Compositor
{
public CompositionGeometricClip CreateCompositionGeometricClip() => new CompositionGeometricClip();
public CompositionColorBrush CreateColorBrush(Wui.Color color) => new CompositionColorBrush(color);
public ContainerVisual CreateContainerVisual() => new ContainerVisual();
public CompositionColorGradientStop CreateColorGradientStop(float offset, Wui.Color color) => new CompositionColorGradientStop(offset, color);
public ShapeVisual CreateShapeVisual() => new ShapeVisual();
public CompositionViewBox CreateViewBox() => new CompositionViewBox();
public ExpressionAnimation CreateExpressionAnimation(WinCompData.Expressions.Expression expression) => new ExpressionAnimation(expression);
public InsetClip CreateInsetClip() => new InsetClip();
public CompositionSpriteShape CreateSpriteShape() => new CompositionSpriteShape();
public ColorKeyFrameAnimation CreateColorKeyFrameAnimation() => new ColorKeyFrameAnimation();
public CompositionContainerShape CreateContainerShape() => new CompositionContainerShape();
public CompositionColorBrush CreateColorBrush(Wui.Color color) => new CompositionColorBrush(color);
public ContainerVisual CreateContainerVisual() => new ContainerVisual();
public CubicBezierEasingFunction CreateCubicBezierEasingFunction(System.Numerics.Vector2 controlPoint1, System.Numerics.Vector2 controlPoint2) => new CubicBezierEasingFunction(controlPoint1, controlPoint2);
public CompositionEffectFactory CreateEffectFactory(GraphicsEffectBase graphicsEffect) => new CompositionEffectFactory(graphicsEffect);
public CompositionEllipseGeometry CreateEllipseGeometry() => new CompositionEllipseGeometry();
public ExpressionAnimation CreateExpressionAnimation(Expression expression) => new ExpressionAnimation(expression);
public CompositionGeometricClip CreateGeometricClip() => new CompositionGeometricClip();
public InsetClip CreateInsetClip() => new InsetClip();
public LinearEasingFunction CreateLinearEasingFunction() => new LinearEasingFunction();
public CompositionLinearGradientBrush CreateLinearGradientBrush() => new CompositionLinearGradientBrush();
public CompositionPathGeometry CreatePathGeometry() => new CompositionPathGeometry();
public CompositionPathGeometry CreatePathGeometry(CompositionPath path) => new CompositionPathGeometry(path);
public CompositionPropertySet CreatePropertySet() => new CompositionPropertySet(null);
public CompositionEllipseGeometry CreateEllipseGeometry() => new CompositionEllipseGeometry();
public CubicBezierEasingFunction CreateCubicBezierEasingFunction(Vector2 controlPoint1, Vector2 controlPoint2) => new CubicBezierEasingFunction(controlPoint1, controlPoint2);
public StepEasingFunction CreateStepEasingFunction(int steps) => new StepEasingFunction(steps);
public StepEasingFunction CreateStepEasingFunction() => new StepEasingFunction(1);
public ScalarKeyFrameAnimation CreateScalarKeyFrameAnimation() => new ScalarKeyFrameAnimation();
public ColorKeyFrameAnimation CreateColorKeyFrameAnimation() => new ColorKeyFrameAnimation();
public PathKeyFrameAnimation CreatePathKeyFrameAnimation() => new PathKeyFrameAnimation();
public Vector2KeyFrameAnimation CreateVector2KeyFrameAnimation() => new Vector2KeyFrameAnimation();
public CompositionPropertySet CreatePropertySet() => new CompositionPropertySet(null);
public Vector3KeyFrameAnimation CreateVector3KeyFrameAnimation() => new Vector3KeyFrameAnimation();
public LinearEasingFunction CreateLinearEasingFunction() => new LinearEasingFunction();
public CompositionRadialGradientBrush CreateRadialGradientBrush() => new CompositionRadialGradientBrush();
public CompositionRectangleGeometry CreateRectangleGeometry() => new CompositionRectangleGeometry();
public CompositionRoundedRectangleGeometry CreateRoundedRectangleGeometry() => new CompositionRoundedRectangleGeometry();
public ScalarKeyFrameAnimation CreateScalarKeyFrameAnimation() => new ScalarKeyFrameAnimation();
public ShapeVisual CreateShapeVisual() => new ShapeVisual();
public CompositionSpriteShape CreateSpriteShape() => new CompositionSpriteShape();
public SpriteVisual CreateSpriteVisual() => new SpriteVisual();
public CompositionVisualSurface CreateVisualSurface() => new CompositionVisualSurface();
public StepEasingFunction CreateStepEasingFunction() => new StepEasingFunction(1);
public StepEasingFunction CreateStepEasingFunction(int stepCount) => new StepEasingFunction(stepCount);
public CompositionSurfaceBrush CreateSurfaceBrush(ICompositionSurface surface) => new CompositionSurfaceBrush(surface);
public CompositionEffectFactory CreateEffectFactory(Mgce.GraphicsEffectBase effect) => new CompositionEffectFactory(effect);
public Vector2KeyFrameAnimation CreateVector2KeyFrameAnimation() => new Vector2KeyFrameAnimation();
public Vector3KeyFrameAnimation CreateVector3KeyFrameAnimation() => new Vector3KeyFrameAnimation();
public CompositionViewBox CreateViewBox() => new CompositionViewBox();
public CompositionVisualSurface CreateVisualSurface() => new CompositionVisualSurface();
}
}

Просмотреть файл

@ -12,6 +12,7 @@
<Compile Include="$(MSBuildThisFileDirectory)CompositionBrush.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CompositionClip.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CompositionColorBrush.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CompositionColorGradientStop.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CompositionColorSpace.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CompositionContainerShape.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CompositionEasingFunction.cs" />
@ -21,11 +22,16 @@
<Compile Include="$(MSBuildThisFileDirectory)CompositionEllipseGeometry.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CompositionGeometricClip.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CompositionGeometry.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CompositionGradientBrush.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CompositionGradientExtendMode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CompositionLinearGradientBrush.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CompositionMappingMode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CompositionObject.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CompositionObjectType.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CompositionPath.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CompositionPathGeometry.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CompositionPropertySet.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CompositionRadialGradientBrush.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CompositionRectangleGeometry.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CompositionRoundedRectangleGeometry.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CompositionShape.cs" />

Просмотреть файл

@ -81,7 +81,7 @@ $errorLog = "$outputPath\Errors_and_Warnings.log"
$lottieGenExitCode = 99
$lottieGenTime = Measure-Command {
&dotnet $lottieGenDll -i "$CorpusDirectory\**json" -o $outputPath -l cs -l cppcx -l lottiexml -l wincompxml -l dgml -l stats 2>&1 |
select-string '(\:( warning )|( error ) L)|(Error: )' | Sort-Object > $errorLog
select-string '(\:( warning )|( error ) L)|(Error: )' | Sort-Object -CaseSensitive | Out-File $errorLog -Width 240
$lottieGenExitCode = $LASTEXITCODE
}