mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 08:10:50 +08:00
线条动画支持大小切换
This commit is contained in:
@@ -6,17 +6,17 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
[Serializable]
|
||||
public class AnimationViewModel : BindableBase, IAnimationViewModel
|
||||
{
|
||||
private LineAnimation _lineAnimation = LineAnimation.None;
|
||||
private LineAnimation _animation = LineAnimation.None;
|
||||
[CanDo]
|
||||
public LineAnimation LineAnimation
|
||||
public LineAnimation Animation
|
||||
{
|
||||
get
|
||||
{
|
||||
return _lineAnimation;
|
||||
return _animation;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _lineAnimation, value);
|
||||
SetProperty(ref _animation, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
SetProperty(ref _duration, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Color _color = Colors.Red;
|
||||
[CanDo]
|
||||
@@ -51,45 +51,39 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
private ISharpPath _animationPath = SharpPath.Circle;
|
||||
public ISharpPath AnimationPath
|
||||
{
|
||||
get
|
||||
{
|
||||
return _path;
|
||||
return _animationPath;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _path, value);
|
||||
if (_animationPath != value)
|
||||
{
|
||||
if (_animationPath != null && _animationPath is SharpPath _sharpPath1)
|
||||
{
|
||||
_sharpPath1.PropertyChanged -= AnimationViewModel_PropertyChanged;
|
||||
}
|
||||
SetProperty(ref _animationPath, value);
|
||||
if (_animationPath != null && _animationPath is SharpPath _sharpPath2)
|
||||
{
|
||||
_sharpPath2.PropertyChanged += AnimationViewModel_PropertyChanged;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RaisePropertyChanged(nameof(AnimationPath));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private double _witdh;
|
||||
[CanDo]
|
||||
public double Width
|
||||
private void AnimationViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
get
|
||||
if (sender == AnimationPath)
|
||||
{
|
||||
return _witdh;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _witdh, value);
|
||||
}
|
||||
}
|
||||
|
||||
private double _height;
|
||||
[CanDo]
|
||||
public double Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return _height;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _height, value);
|
||||
RaisePropertyChanged(nameof(AnimationPath));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public interface IAnimationViewModel
|
||||
{
|
||||
LineAnimation LineAnimation
|
||||
LineAnimation Animation
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
@@ -22,15 +22,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
string Path
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
double Width
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
double Height
|
||||
ISharpPath AnimationPath
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public interface ISharpPath
|
||||
{
|
||||
string Path
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
double Width
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
double Height
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
PathStyle PathStyle
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
SizeStyle SizeStyle
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,152 +75,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public class SharpPath : BindableBase, ISharpPath
|
||||
{
|
||||
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>()
|
||||
{
|
||||
{ ArrowPathStyle.None, None.Path },
|
||||
{ ArrowPathStyle.Arrow, Arrow.Path },
|
||||
{ ArrowPathStyle.Circle, Circle.Path },
|
||||
{ ArrowPathStyle.Square, Square.Path },
|
||||
};
|
||||
|
||||
public SharpPath()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public SharpPath(string path, double width, double height, ArrowPathStyle arrowPathStyle, ArrowSizeStyle arrowSizeStyle)
|
||||
{
|
||||
Path = path;
|
||||
Width = width;
|
||||
Height = height;
|
||||
_pathStyle = arrowPathStyle;
|
||||
_sizeStyle = arrowSizeStyle;
|
||||
}
|
||||
|
||||
private string _path;
|
||||
[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);
|
||||
}
|
||||
}
|
||||
|
||||
private ArrowPathStyle _pathStyle = ArrowPathStyle.None;
|
||||
[CanDo]
|
||||
public ArrowPathStyle PathStyle
|
||||
{
|
||||
get
|
||||
{
|
||||
return _pathStyle;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _pathStyle, value))
|
||||
{
|
||||
if (ArrowDictionary.ContainsKey(_pathStyle))
|
||||
{
|
||||
Path = ArrowDictionary[_pathStyle];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ArrowSizeStyle _sizeStyle = ArrowSizeStyle.Middle;
|
||||
[CanDo]
|
||||
public ArrowSizeStyle SizeStyle
|
||||
{
|
||||
get
|
||||
{
|
||||
return _sizeStyle;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _sizeStyle, value))
|
||||
{
|
||||
Width = (double)_sizeStyle;
|
||||
Height = (double)_sizeStyle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 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 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 SharpPath NewSquare(double size) => NewRectangle(size, size);
|
||||
}
|
||||
|
||||
public interface ISharpPath
|
||||
{
|
||||
string Path
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
double Width
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
double Height
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
ArrowPathStyle PathStyle
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
ArrowSizeStyle SizeStyle
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class SharpPath : BindableBase, ISharpPath
|
||||
{
|
||||
public static SharpPath None { get; } = new SharpPath("", 10, 10, PathStyle.None, SizeStyle.Middle);
|
||||
public static SharpPath Arrow { get; } = new SharpPath("M 0 -5 10 0 0 5 z", 10, 10, PathStyle.Arrow, SizeStyle.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, PathStyle.Circle, SizeStyle.Middle);
|
||||
public static SharpPath Square { get; } = new SharpPath("M 0 -5 10 -5 10 5 0 5 z", 10, 10, PathStyle.Square, SizeStyle.Middle);
|
||||
|
||||
public static readonly Dictionary<PathStyle, string> ArrowDictionary = new Dictionary<PathStyle, string>()
|
||||
{
|
||||
{ PathStyle.None, None.Path },
|
||||
{ PathStyle.Arrow, Arrow.Path },
|
||||
{ PathStyle.Circle, Circle.Path },
|
||||
{ PathStyle.Square, Square.Path },
|
||||
};
|
||||
|
||||
public SharpPath()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public SharpPath(string path, double width, double height, PathStyle arrowPathStyle, SizeStyle arrowSizeStyle)
|
||||
{
|
||||
Path = path;
|
||||
Width = width;
|
||||
Height = height;
|
||||
_pathStyle = arrowPathStyle;
|
||||
_sizeStyle = arrowSizeStyle;
|
||||
}
|
||||
|
||||
private string _path;
|
||||
[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);
|
||||
}
|
||||
}
|
||||
|
||||
private PathStyle _pathStyle = PathStyle.None;
|
||||
[CanDo]
|
||||
public PathStyle PathStyle
|
||||
{
|
||||
get
|
||||
{
|
||||
return _pathStyle;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _pathStyle, value))
|
||||
{
|
||||
if (ArrowDictionary.ContainsKey(_pathStyle))
|
||||
{
|
||||
Path = ArrowDictionary[_pathStyle];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private SizeStyle _sizeStyle = SizeStyle.Middle;
|
||||
[CanDo]
|
||||
public SizeStyle SizeStyle
|
||||
{
|
||||
get
|
||||
{
|
||||
return _sizeStyle;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _sizeStyle, value))
|
||||
{
|
||||
Width = (double)_sizeStyle;
|
||||
Height = (double)_sizeStyle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static SharpPath NewArrow(double width, double height)
|
||||
=> new SharpPath(FormattableString.Invariant($"M 0 -{height / 2} {width} 0 0 {height / 2}"), width, height, PathStyle.Arrow, (SizeStyle)width);
|
||||
|
||||
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, PathStyle.Circle, (SizeStyle)(r * 2));
|
||||
|
||||
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, PathStyle.Square, (SizeStyle)width);
|
||||
|
||||
public static SharpPath NewSquare(double size) => NewRectangle(size, size);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user