Refactor
This commit is contained in:
Родитель
bbf94d4db8
Коммит
e57c943050
|
@ -1,11 +1,8 @@
|
|||
using System;
|
||||
using Avalonia;
|
||||
using Avalonia.Animation;
|
||||
using Avalonia.Animation.Animators;
|
||||
using Avalonia.Data;
|
||||
using Avalonia.Animation.Animators;
|
||||
using Avalonia.Media;
|
||||
using WPFAnimations;
|
||||
|
||||
namespace PolyLineAnimation
|
||||
namespace Avalonia
|
||||
{
|
||||
public class GeometryAnimator : Animator<Geometry>
|
||||
{
|
||||
|
@ -13,8 +10,7 @@ namespace PolyLineAnimation
|
|||
{
|
||||
var clone = (oldValue as PathGeometry).ClonePathGeometry();
|
||||
|
||||
//Morph.To(clone, newValue as PathGeometry, progress);
|
||||
WPFAnimations.Morph.To(clone, newValue as PathGeometry, progress);
|
||||
Morph.To(clone, newValue as PathGeometry, progress);
|
||||
|
||||
return clone;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
using System;
|
||||
using Avalonia;
|
||||
using Avalonia.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace Avalonia
|
||||
|
@ -204,6 +204,27 @@ namespace Avalonia
|
|||
return pathOut;
|
||||
}
|
||||
|
||||
public static PathGeometry ToFlattenedPathGeometry(this IList<Point> sourcePoints)
|
||||
{
|
||||
var source = new PathGeometry
|
||||
{
|
||||
FillRule = FillRule.EvenOdd
|
||||
};
|
||||
|
||||
var sourceFigure = new PathFigure()
|
||||
{
|
||||
IsClosed = false,
|
||||
IsFilled = false,
|
||||
StartPoint = sourcePoints.First()
|
||||
};
|
||||
source.Figures.Add(sourceFigure);
|
||||
|
||||
var polylineSegment = new PolyLineSegment(sourcePoints.Skip(1));
|
||||
sourceFigure.Segments?.Add(polylineSegment);
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
public static PathGeometry ClonePathGeometry(this PathGeometry pathIn)
|
||||
{
|
||||
var pathOut = new PathGeometry()
|
||||
|
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Avalonia;
|
||||
using Avalonia.Animation;
|
||||
using Avalonia.Animation.Easings;
|
||||
using Avalonia.Media;
|
||||
|
||||
|
@ -9,6 +10,11 @@ namespace WPFAnimations
|
|||
{
|
||||
public static class Morph
|
||||
{
|
||||
//static Morph()
|
||||
//{
|
||||
// Animation.RegisterAnimator<GeometryAnimator>(prop => typeof(Geometry).IsAssignableFrom(prop.PropertyType));
|
||||
//}
|
||||
|
||||
public static bool Collapse(PathGeometry sourceGeometry, double progress)
|
||||
{
|
||||
int count = sourceGeometry.Figures.Count;
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace PolyLineAnimation
|
|||
// CACHE
|
||||
|
||||
var easing = new ElasticEaseOut(); // ExponentialEaseOut, BounceEaseOut, ElasticEaseOut
|
||||
//var cache = Morph.ToCache(sourceFlattened, targetFlattened, 0.01, easing);
|
||||
//var cache = PolyLineMorph.ToCache(sourceFlattened, targetFlattened, 0.01, easing);
|
||||
var cache = WPFAnimations.Morph.ToCache(sourceFlattened, targetFlattened, 0.01, easing);
|
||||
|
||||
// UI
|
||||
|
@ -105,7 +105,7 @@ namespace PolyLineAnimation
|
|||
targetPoints.Add(point);
|
||||
}
|
||||
|
||||
var target = Morph.CreatePathGeometry(targetPoints);
|
||||
var target = targetPoints.ToFlattenedPathGeometry();
|
||||
var targetFlattened = target;
|
||||
//var targetFlattened = target.Flatten(FlattenOutput.PolyLines);
|
||||
|
||||
|
@ -121,7 +121,7 @@ namespace PolyLineAnimation
|
|||
sourcePoints.Add(point);
|
||||
}
|
||||
|
||||
var source = Morph.CreatePathGeometry(sourcePoints);
|
||||
var source = sourcePoints.ToFlattenedPathGeometry();
|
||||
var sourceFlattened = source;
|
||||
//var sourceFlattened = source.Flatten(FlattenOutput.PolyLines);
|
||||
|
||||
|
@ -142,7 +142,7 @@ namespace PolyLineAnimation
|
|||
var max = sourcePoints.Max(p => p.Y);
|
||||
sourcePoints = sourcePoints.Select(p => new Point(p.X, p.Y / max)).ToList();
|
||||
|
||||
var source = Morph.CreatePathGeometry(sourcePoints);
|
||||
var source = sourcePoints.ToFlattenedPathGeometry();
|
||||
var sourceFlattened = source;
|
||||
//var sourceFlattened = source.Flatten(FlattenOutput.PolyLines);
|
||||
|
||||
|
|
|
@ -10,6 +10,9 @@
|
|||
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.6" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\MorphingDemo\Avalonia\GeometryAnimator.cs">
|
||||
<Link>Avalonia\GeometryAnimator.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MorphingDemo\Avalonia\PathGeometryExtensions.cs">
|
||||
<Link>Avalonia\PathGeometryExtensions.cs</Link>
|
||||
</Compile>
|
||||
|
|
|
@ -1,20 +1,13 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Avalonia;
|
||||
using Avalonia.Animation;
|
||||
using Avalonia.Animation.Easings;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace PolyLineAnimation
|
||||
{
|
||||
public static class Morph
|
||||
public static class PolyLineMorph
|
||||
{
|
||||
static Morph()
|
||||
{
|
||||
Animation.RegisterAnimator<GeometryAnimator>(prop => typeof(Geometry).IsAssignableFrom(prop.PropertyType));
|
||||
}
|
||||
|
||||
public static List<PathGeometry> ToCache(PathGeometry source, PathGeometry target, double speed, IEasing easing)
|
||||
{
|
||||
int steps = (int) (1 / speed);
|
||||
|
@ -70,25 +63,5 @@ namespace PolyLineAnimation
|
|||
return new Point(x, y);
|
||||
}
|
||||
|
||||
public static PathGeometry CreatePathGeometry(IList<Point> sourcePoints)
|
||||
{
|
||||
var source = new PathGeometry
|
||||
{
|
||||
FillRule = FillRule.EvenOdd
|
||||
};
|
||||
|
||||
var sourceFigure = new PathFigure()
|
||||
{
|
||||
IsClosed = false,
|
||||
IsFilled = false,
|
||||
StartPoint = sourcePoints.First()
|
||||
};
|
||||
source.Figures.Add(sourceFigure);
|
||||
|
||||
var polylineSegment = new PolyLineSegment(sourcePoints.Skip(1));
|
||||
sourceFigure.Segments?.Add(polylineSegment);
|
||||
|
||||
return source;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,10 @@
|
|||
using System;
|
||||
using Avalonia;
|
||||
using Avalonia.Animation;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Media;
|
||||
using WPFAnimations;
|
||||
|
||||
namespace PolyLineAnimation
|
||||
{
|
||||
|
@ -15,8 +18,12 @@ namespace PolyLineAnimation
|
|||
|
||||
// Avalonia configuration, don't remove; also used by visual designer.
|
||||
public static AppBuilder BuildAvaloniaApp()
|
||||
=> AppBuilder.Configure<App>()
|
||||
{
|
||||
Animation.RegisterAnimator<GeometryAnimator>(prop => typeof(Geometry).IsAssignableFrom(prop.PropertyType));
|
||||
|
||||
return AppBuilder.Configure<App>()
|
||||
.UsePlatformDetect()
|
||||
.LogToTrace();
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче