为线的动画做扩展准备

This commit is contained in:
艾竹
2023-04-29 15:29:22 +08:00
parent 7d8b19e4e0
commit f4268b9fc2
23 changed files with 397 additions and 120 deletions

View File

@@ -0,0 +1,96 @@
using System;
using System.Windows.Media;
namespace AIStudio.Wpf.DiagramDesigner
{
[Serializable]
public class AnimationViewModel : BindableBase, IAnimationViewModel
{
private LineAnimation _lineAnimation = LineAnimation.None;
[CanDo]
public LineAnimation LineAnimation
{
get
{
return _lineAnimation;
}
set
{
SetProperty(ref _lineAnimation, value);
}
}
private double _duration = 1;
[CanDo]
public double Duration
{
get
{
return _duration;
}
set
{
SetProperty(ref _duration, value);
}
}
private Color _color = Colors.Red;
[CanDo]
public Color Color
{
get
{
return _color;
}
set
{
if (!SetProperty(ref _color, value))
{
RaisePropertyChanged(nameof(Color));
}
}
}
private string _path = "M 10,20 A 20,20 0 1 1 50,20 A 20,20 0 1 1 10,20";
[CanDo]
public string Path
{
get
{
return _path;
}
set
{
SetProperty(ref _path, value);
}
}
private double _witdh;
[CanDo]
public double Width
{
get
{
return _witdh;
}
set
{
SetProperty(ref _witdh, value);
}
}
private double _height;
[CanDo]
public double Height
{
get
{
return _height;
}
set
{
SetProperty(ref _height, value);
}
}
}
}

View File

@@ -144,34 +144,6 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
}
private LineAnimation _lineAnimation = LineAnimation.None;
[CanDo]
public LineAnimation LineAnimation
{
get
{
return _lineAnimation;
}
set
{
SetProperty(ref _lineAnimation, value);
}
}
private double _lineAnimationDuration = 1;
[CanDo]
public double LineAnimationDuration
{
get
{
return _lineAnimationDuration;
}
set
{
SetProperty(ref _lineAnimationDuration, value);
}
}
}

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
namespace AIStudio.Wpf.DiagramDesigner
{
public interface IAnimationViewModel
{
LineAnimation LineAnimation
{
get; set;
}
double Duration
{
get; set;
}
Color Color
{
get; set;
}
string Path
{
get; set;
}
double Width
{
get; set;
}
double Height
{
get; set;
}
event PropertyChangedEventHandler PropertyChanged;
}
}

View File

@@ -28,15 +28,7 @@ namespace AIStudio.Wpf.DiagramDesigner
LineDashStyle LineDashStyle
{
get; set;
}
LineAnimation LineAnimation
{
get; set;
}
double LineAnimationDuration
{
get; set;
}
}
event PropertyChangedEventHandler PropertyChanged;
}
}

View File

@@ -7,12 +7,12 @@ namespace AIStudio.Wpf.DiagramDesigner
{
public interface IShapeViewModel
{
ILinkMarker SourceMarker
ISharpPath SourceMarker
{
get; set;
}
ILinkMarker SinkMarker
ISharpPath SinkMarker
{
get; set;
}

View File

@@ -6,8 +6,8 @@ namespace AIStudio.Wpf.DiagramDesigner
{
public class ShapeViewModel : BindableBase, IShapeViewModel
{
private ILinkMarker _sourceMarker = LinkMarker.None;
public ILinkMarker SourceMarker
private ISharpPath _sourceMarker = SharpPath.None;
public ISharpPath SourceMarker
{
get
{
@@ -17,12 +17,12 @@ namespace AIStudio.Wpf.DiagramDesigner
{
if (_sourceMarker != value)
{
if (_sourceMarker != null && _sourceMarker is LinkMarker _linkMarker1)
if (_sourceMarker != null && _sourceMarker is SharpPath _linkMarker1)
{
_linkMarker1.PropertyChanged -= ShapeViewModel_PropertyChanged;
}
SetProperty(ref _sourceMarker, value);
if (_sourceMarker != null && _sourceMarker is LinkMarker _linkMarker2)
if (_sourceMarker != null && _sourceMarker is SharpPath _linkMarker2)
{
_linkMarker2.PropertyChanged += ShapeViewModel_PropertyChanged;
}
@@ -34,8 +34,8 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
private ILinkMarker _sinkMarker = LinkMarker.Arrow;
public ILinkMarker SinkMarker
private ISharpPath _sinkMarker = SharpPath.Arrow;
public ISharpPath SinkMarker
{
get
{
@@ -45,12 +45,12 @@ namespace AIStudio.Wpf.DiagramDesigner
{
if (_sinkMarker != value)
{
if (_sinkMarker != null && _sinkMarker is LinkMarker _linkMarker1)
if (_sinkMarker != null && _sinkMarker is SharpPath _linkMarker1)
{
_linkMarker1.PropertyChanged -= ShapeViewModel_PropertyChanged;
}
SetProperty(ref _sinkMarker, value);
if (_sinkMarker != null && _sinkMarker is LinkMarker _linkMarker2)
if (_sinkMarker != null && _sinkMarker is SharpPath _linkMarker2)
{
_linkMarker2.PropertyChanged += ShapeViewModel_PropertyChanged;
}
@@ -75,12 +75,12 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
public class LinkMarker : BindableBase, ILinkMarker
public class SharpPath : BindableBase, ISharpPath
{
public static LinkMarker None { get; } = new LinkMarker("", 10, 10, ArrowPathStyle.None, ArrowSizeStyle.Middle);
public static LinkMarker Arrow { get; } = new LinkMarker("M 0 -5 10 0 0 5 z", 10, 10, ArrowPathStyle.Arrow, ArrowSizeStyle.Middle);
public static LinkMarker Circle { get; } = new LinkMarker("M 0, 0 a 5,5 0 1,0 10,0 a 5,5 0 1,0 -10,0", 10, 10, ArrowPathStyle.Circle, ArrowSizeStyle.Middle);
public static LinkMarker Square { get; } = new LinkMarker("M 0 -5 10 -5 10 5 0 5 z", 10, 10, ArrowPathStyle.Square, ArrowSizeStyle.Middle);
public static SharpPath None { get; } = new SharpPath("", 10, 10, ArrowPathStyle.None, ArrowSizeStyle.Middle);
public static SharpPath Arrow { get; } = new SharpPath("M 0 -5 10 0 0 5 z", 10, 10, ArrowPathStyle.Arrow, ArrowSizeStyle.Middle);
public static SharpPath Circle { get; } = new SharpPath("M 0, 0 a 5,5 0 1,0 10,0 a 5,5 0 1,0 -10,0", 10, 10, ArrowPathStyle.Circle, ArrowSizeStyle.Middle);
public static SharpPath Square { get; } = new SharpPath("M 0 -5 10 -5 10 5 0 5 z", 10, 10, ArrowPathStyle.Square, ArrowSizeStyle.Middle);
public static readonly Dictionary<ArrowPathStyle, string> ArrowDictionary = new Dictionary<ArrowPathStyle, string>()
{
@@ -90,12 +90,12 @@ namespace AIStudio.Wpf.DiagramDesigner
{ ArrowPathStyle.Square, Square.Path },
};
public LinkMarker()
public SharpPath()
{
}
public LinkMarker(string path, double width, double height, ArrowPathStyle arrowPathStyle, ArrowSizeStyle arrowSizeStyle)
public SharpPath(string path, double width, double height, ArrowPathStyle arrowPathStyle, ArrowSizeStyle arrowSizeStyle)
{
Path = path;
Width = width;
@@ -184,19 +184,19 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
public static LinkMarker NewArrow(double width, double height)
=> new LinkMarker(FormattableString.Invariant($"M 0 -{height / 2} {width} 0 0 {height / 2}"), width, height, ArrowPathStyle.Arrow, (ArrowSizeStyle)width);
public static SharpPath NewArrow(double width, double height)
=> new SharpPath(FormattableString.Invariant($"M 0 -{height / 2} {width} 0 0 {height / 2}"), width, height, ArrowPathStyle.Arrow, (ArrowSizeStyle)width);
public static LinkMarker NewCircle(double r)
=> new LinkMarker(FormattableString.Invariant($"M 0, 0 a {r},{r} 0 1,0 {r * 2},0 a {r},{r} 0 1,0 -{r * 2},0"), r * 2, r * 2, ArrowPathStyle.Circle, (ArrowSizeStyle)(r * 2));
public static SharpPath NewCircle(double r)
=> new SharpPath(FormattableString.Invariant($"M 0, 0 a {r},{r} 0 1,0 {r * 2},0 a {r},{r} 0 1,0 -{r * 2},0"), r * 2, r * 2, ArrowPathStyle.Circle, (ArrowSizeStyle)(r * 2));
public static LinkMarker NewRectangle(double width, double height)
=> new LinkMarker(FormattableString.Invariant($"M 0 -{height / 2} {width} -{height / 2} {width} {height / 2} 0 {height / 2} z"), width, height, ArrowPathStyle.Square, (ArrowSizeStyle)width);
public static SharpPath NewRectangle(double width, double height)
=> new SharpPath(FormattableString.Invariant($"M 0 -{height / 2} {width} -{height / 2} {width} {height / 2} 0 {height / 2} z"), width, height, ArrowPathStyle.Square, (ArrowSizeStyle)width);
public static LinkMarker NewSquare(double size) => NewRectangle(size, size);
public static SharpPath NewSquare(double size) => NewRectangle(size, size);
}
public interface ILinkMarker
public interface ISharpPath
{
string Path
{