mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-05 16:56:34 +08:00
支持画笔及痕迹擦除,为白板做准备
This commit is contained in:
@@ -8,6 +8,7 @@ using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
@@ -126,7 +127,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
RaisePropertyChanged(nameof(LineWidth));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private LineDashStyle _lineDashStyle = LineDashStyle.None;
|
||||
[CanDo]
|
||||
@@ -221,8 +222,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
set
|
||||
{
|
||||
var xx = this.GetHashCode();
|
||||
var yy = Thread.CurrentThread.ManagedThreadId.ToString();
|
||||
SetProperty(ref _color, value);
|
||||
}
|
||||
}
|
||||
@@ -391,8 +390,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get
|
||||
{
|
||||
return new SimpleCommand(para =>
|
||||
{
|
||||
return new SimpleCommand(para => {
|
||||
var offset = GradientStop.Skip(GradientStop.Count - 2).Select(p => p.Offset).Average();
|
||||
GradientStop.Add(new GradientStop(Colors.Gray, offset));
|
||||
});
|
||||
@@ -402,8 +400,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get
|
||||
{
|
||||
return new SimpleCommand(para =>
|
||||
{
|
||||
return new SimpleCommand(para => {
|
||||
if (SelectedGradientStop != null && GradientStop != null && GradientStop.Count > 2)
|
||||
{
|
||||
GradientStop.Remove(SelectedGradientStop);
|
||||
@@ -411,21 +408,231 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static Brush ToBrush(IColorObject colorObject)
|
||||
{
|
||||
Brush brush = null;
|
||||
|
||||
if (colorObject.BrushType == BrushType.None)
|
||||
brush = new SolidColorBrush(Colors.Transparent);
|
||||
else if (colorObject.BrushType == BrushType.SolidColorBrush)
|
||||
brush = new SolidColorBrush(colorObject.Color);
|
||||
else if (colorObject.BrushType == BrushType.LinearGradientBrush)
|
||||
{
|
||||
Point startPoint;
|
||||
Point endPoint;
|
||||
if (colorObject.LinearOrientation == LinearOrientation.LeftToRight)
|
||||
{
|
||||
startPoint = new Point(0, 0.5);
|
||||
endPoint = new Point(1, 0.5);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.LeftTopToRightBottom)
|
||||
{
|
||||
startPoint = new Point(0, 0);
|
||||
endPoint = new Point(1, 1);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.TopToBottom)
|
||||
{
|
||||
startPoint = new Point(0.5, 0);
|
||||
endPoint = new Point(0.5, 1);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.RightTopToLeftBottom)
|
||||
{
|
||||
startPoint = new Point(1, 0);
|
||||
endPoint = new Point(0, 1);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.RightToLeft)
|
||||
{
|
||||
startPoint = new Point(1, 0.5);
|
||||
endPoint = new Point(0, 0.5);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.RightBottomToLeftTop)
|
||||
{
|
||||
startPoint = new Point(1, 1);
|
||||
endPoint = new Point(0, 0);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.BottomToTop)
|
||||
{
|
||||
startPoint = new Point(0.5, 1);
|
||||
endPoint = new Point(0.5, 0);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.LeftBottomToRightTop)
|
||||
{
|
||||
startPoint = new Point(0, 1);
|
||||
endPoint = new Point(1, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
startPoint = new Point(0, 0.5);
|
||||
endPoint = new Point(1, 0.5);
|
||||
}
|
||||
|
||||
LinearGradientBrush myBrush = new LinearGradientBrush();
|
||||
myBrush.StartPoint = startPoint;
|
||||
myBrush.EndPoint = endPoint;
|
||||
if (colorObject.GradientStop != null)
|
||||
{
|
||||
foreach (var stop in colorObject.GradientStop)
|
||||
{
|
||||
myBrush.GradientStops.Add(new System.Windows.Media.GradientStop(stop.Color, stop.Offset));
|
||||
}
|
||||
}
|
||||
brush = myBrush;
|
||||
|
||||
RotateTransform rotateTransform = new RotateTransform(colorObject.Angle, 0.5, 0.5);
|
||||
myBrush.RelativeTransform = rotateTransform;
|
||||
}
|
||||
else if (colorObject.BrushType == BrushType.RadialGradientBrush)
|
||||
{
|
||||
Point center;
|
||||
Point gradientOrigin;
|
||||
double radiusX;
|
||||
double radiusY;
|
||||
|
||||
if (colorObject.RadialOrientation == RadialOrientation.LeftTop)
|
||||
{
|
||||
center = new Point(0, 0);
|
||||
gradientOrigin = center;
|
||||
radiusX = 1;
|
||||
radiusY = 1;
|
||||
}
|
||||
else if (colorObject.RadialOrientation == RadialOrientation.RightTop)
|
||||
{
|
||||
center = new Point(1, 0);
|
||||
gradientOrigin = center;
|
||||
radiusX = 1;
|
||||
radiusY = 1;
|
||||
}
|
||||
else if (colorObject.RadialOrientation == RadialOrientation.RightBottom)
|
||||
{
|
||||
center = new Point(1, 1);
|
||||
gradientOrigin = center;
|
||||
radiusX = 1;
|
||||
radiusY = 1;
|
||||
}
|
||||
else if (colorObject.RadialOrientation == RadialOrientation.LeftBottom)
|
||||
{
|
||||
center = new Point(0, 1);
|
||||
gradientOrigin = center;
|
||||
radiusX = 1;
|
||||
radiusY = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
center = new Point(0.5, 0.5);
|
||||
gradientOrigin = center;
|
||||
radiusX = 0.5;
|
||||
radiusY = 0.5;
|
||||
}
|
||||
|
||||
RadialGradientBrush myBrush = new RadialGradientBrush();
|
||||
myBrush.Center = center;
|
||||
myBrush.GradientOrigin = gradientOrigin;
|
||||
myBrush.RadiusX = radiusX;
|
||||
myBrush.RadiusY = radiusY;
|
||||
if (colorObject.GradientStop != null)
|
||||
{
|
||||
foreach (var stop in colorObject.GradientStop)
|
||||
{
|
||||
myBrush.GradientStops.Add(new System.Windows.Media.GradientStop(stop.Color, stop.Offset));
|
||||
}
|
||||
}
|
||||
brush = myBrush;
|
||||
|
||||
RotateTransform rotateTransform = new RotateTransform(colorObject.Angle, 0.5, 0.5);
|
||||
myBrush.RelativeTransform = rotateTransform;
|
||||
}
|
||||
else if (colorObject.BrushType == BrushType.ImageBrush)
|
||||
{
|
||||
ImageBrush myBrush = new ImageBrush();
|
||||
myBrush.ImageSource = new BitmapImage(new Uri(colorObject.Image, UriKind.Absolute));
|
||||
brush = myBrush;
|
||||
}
|
||||
else if (colorObject.BrushType == BrushType.DrawingBrush)
|
||||
{
|
||||
DrawingBrush myBrush = new DrawingBrush();
|
||||
|
||||
GeometryDrawing backgroundSquare =
|
||||
new GeometryDrawing(
|
||||
Brushes.White,
|
||||
null,
|
||||
new RectangleGeometry(new Rect(0, 0, 100, 100)));
|
||||
|
||||
GeometryGroup aGeometryGroup = new GeometryGroup();
|
||||
aGeometryGroup.Children.Add(new RectangleGeometry(new Rect(0, 0, 50, 50)));
|
||||
aGeometryGroup.Children.Add(new RectangleGeometry(new Rect(50, 50, 50, 50)));
|
||||
|
||||
LinearGradientBrush checkerBrush = new LinearGradientBrush();
|
||||
checkerBrush.GradientStops.Add(new System.Windows.Media.GradientStop(Colors.Black, 0.0));
|
||||
checkerBrush.GradientStops.Add(new System.Windows.Media.GradientStop(Colors.Gray, 1.0));
|
||||
|
||||
GeometryDrawing checkers = new GeometryDrawing(checkerBrush, null, aGeometryGroup);
|
||||
|
||||
DrawingGroup checkersDrawingGroup = new DrawingGroup();
|
||||
checkersDrawingGroup.Children.Add(backgroundSquare);
|
||||
checkersDrawingGroup.Children.Add(checkers);
|
||||
|
||||
myBrush.Drawing = checkersDrawingGroup;
|
||||
myBrush.Viewport = new Rect(0, 0, 0.25, 0.25);
|
||||
myBrush.TileMode = TileMode.Tile;
|
||||
|
||||
brush = myBrush;
|
||||
}
|
||||
if (brush != null)
|
||||
{
|
||||
brush.Opacity = colorObject.Opacity;
|
||||
}
|
||||
|
||||
return brush;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IColorObject
|
||||
{
|
||||
BrushType BrushType { get; set; }
|
||||
Color Color { get; set; }
|
||||
ObservableCollection<GradientStop> GradientStop { get; set; }
|
||||
Point StartPoint { get; set; }
|
||||
Point EndPoint { get; set; }
|
||||
double Opacity { get; set; }
|
||||
LinearOrientation LinearOrientation { get; set; }
|
||||
RadialOrientation RadialOrientation { get; set; }
|
||||
int Angle { get; set; }
|
||||
string Image { get; set; }
|
||||
int SubType { get; set; }
|
||||
BrushType BrushType
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
Color Color
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
ObservableCollection<GradientStop> GradientStop
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
Point StartPoint
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
Point EndPoint
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
double Opacity
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
LinearOrientation LinearOrientation
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
RadialOrientation RadialOrientation
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
int Angle
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
string Image
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
int SubType
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
}
|
||||
|
||||
public class GradientStop : BindableBase
|
||||
|
||||
@@ -16,9 +16,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
return LineDrawMode;
|
||||
}
|
||||
else if (ShapeDrawModeSelected)
|
||||
else if (DrawingDrawModeSelected)
|
||||
{
|
||||
return ShapeDrawMode;
|
||||
return DrawingDrawMode;
|
||||
}
|
||||
else if (TextDrawModeSelected)
|
||||
{
|
||||
@@ -80,7 +80,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
|
||||
private bool _shapeDrawModeSelected;
|
||||
public bool ShapeDrawModeSelected
|
||||
public bool DrawingDrawModeSelected
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -147,7 +147,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
|
||||
private DrawMode _shapeDrawMode = DrawMode.Rectangle;
|
||||
public DrawMode ShapeDrawMode
|
||||
public DrawMode DrawingDrawMode
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -156,7 +156,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
set
|
||||
{
|
||||
SetProperty(ref _shapeDrawMode, value);
|
||||
ShapeDrawModeSelected = true;
|
||||
DrawingDrawModeSelected = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,33 +185,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
SetProperty(ref _cursorMode, value);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _enableSnapping;
|
||||
public bool EnableSnapping
|
||||
{
|
||||
get
|
||||
{
|
||||
return _enableSnapping;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _enableSnapping, value);
|
||||
}
|
||||
}
|
||||
|
||||
private double _snappingRadius = 50;
|
||||
public double SnappingRadius
|
||||
{
|
||||
get
|
||||
{
|
||||
return _snappingRadius;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _snappingRadius, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,19 +41,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
bool ShapeDrawModeSelected
|
||||
bool DrawingDrawModeSelected
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
DrawMode ShapeDrawMode
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
bool EnableSnapping
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
double SnappingRadius
|
||||
DrawMode DrawingDrawMode
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
@@ -148,22 +148,22 @@ namespace AIStudio.Wpf.DiagramDesigner.ViewModels.BaseViewModel
|
||||
get; set;
|
||||
}
|
||||
|
||||
private SelectableDesignerItemViewModelBase _selectedItem;
|
||||
private SelectableDesignerItemViewModelBase _selectedItemViewModel;
|
||||
public SelectableDesignerItemViewModelBase SelectedItemViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
return _selectedItem;
|
||||
return _selectedItemViewModel;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_selectedItem != null)
|
||||
if (_selectedItemViewModel != null)
|
||||
{
|
||||
_selectedItem.PropertyChanged -= ViewModel_PropertyChanged;
|
||||
_selectedItemViewModel.PropertyChanged -= ViewModel_PropertyChanged;
|
||||
}
|
||||
if (SetProperty(ref _selectedItem, value))
|
||||
if (SetProperty(ref _selectedItemViewModel, value))
|
||||
{
|
||||
if (_selectedItem == null)
|
||||
if (_selectedItemViewModel == null)
|
||||
{
|
||||
ColorViewModel = GetOldValue<ColorViewModel>(nameof(ColorViewModel));
|
||||
FontViewModel = GetOldValue<FontViewModel>(nameof(FontViewModel));
|
||||
@@ -173,16 +173,16 @@ namespace AIStudio.Wpf.DiagramDesigner.ViewModels.BaseViewModel
|
||||
}
|
||||
else
|
||||
{
|
||||
ColorViewModel = _selectedItem.ColorViewModel;
|
||||
FontViewModel = _selectedItem.FontViewModel;
|
||||
ShapeViewModel = _selectedItem.ShapeViewModel;
|
||||
AnimationViewModel = _selectedItem.AnimationViewModel;
|
||||
LockObjectViewModel = _selectedItem.LockObjectViewModel;
|
||||
ColorViewModel = _selectedItemViewModel.ColorViewModel;
|
||||
FontViewModel = _selectedItemViewModel.FontViewModel;
|
||||
ShapeViewModel = _selectedItemViewModel.ShapeViewModel;
|
||||
AnimationViewModel = _selectedItemViewModel.AnimationViewModel;
|
||||
LockObjectViewModel = _selectedItemViewModel.LockObjectViewModel;
|
||||
}
|
||||
}
|
||||
if (_selectedItem != null)
|
||||
if (_selectedItemViewModel != null)
|
||||
{
|
||||
_selectedItem.PropertyChanged += ViewModel_PropertyChanged;
|
||||
_selectedItemViewModel.PropertyChanged += ViewModel_PropertyChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._editCommand ?? (this._editCommand = new SimpleCommand(Command_Enable, ExecuteSelectItemCommand));
|
||||
return this._selectItemCommand ?? (this._selectItemCommand = new SimpleCommand(Command_Enable, ExecuteSelectItemCommand));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -192,6 +192,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsHitTestVisible == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return _isSelected;
|
||||
}
|
||||
set
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class ShapeDesignerItemViewModel : DesignerItemViewModelBase
|
||||
{
|
||||
public ShapeDesignerItemViewModel() : this(null)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ShapeDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public ShapeDesignerItemViewModel(DrawMode drawMode, List<Point> points) : this(null, drawMode, points)
|
||||
{
|
||||
}
|
||||
|
||||
public ShapeDesignerItemViewModel(IDiagramViewModel root, DrawMode drawMode, List<Point> points) : base(root)
|
||||
{
|
||||
DrawMode = drawMode;
|
||||
ConnectionPoints = points;
|
||||
|
||||
ItemWidth = ConnectionPoints.Max(p => p.X) - ConnectionPoints.Min(p => p.X);
|
||||
ItemHeight = ConnectionPoints.Max(p => p.Y) - ConnectionPoints.Min(p => p.Y);
|
||||
Left = ConnectionPoints.Min(p => p.X);
|
||||
Top = ConnectionPoints.Min(p => p.Y);
|
||||
}
|
||||
|
||||
private List<Point> _connectionPoints;
|
||||
public List<Point> ConnectionPoints
|
||||
{
|
||||
get
|
||||
{
|
||||
return _connectionPoints;
|
||||
}
|
||||
private set
|
||||
{
|
||||
SetProperty(ref _connectionPoints, value);
|
||||
}
|
||||
}
|
||||
public DrawMode DrawMode
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
private bool _showConnectors = false;
|
||||
public new bool ShowConnectors
|
||||
{
|
||||
get
|
||||
{
|
||||
return _showConnectors;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _showConnectors, value))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand MenuItemCommand
|
||||
{
|
||||
get; private set;
|
||||
}
|
||||
|
||||
private void UpdatePoints()
|
||||
{
|
||||
ItemWidth = ConnectionPoints.Max(p => p.X) - ConnectionPoints.Min(p => p.X);
|
||||
ItemHeight = ConnectionPoints.Max(p => p.Y) - ConnectionPoints.Min(p => p.Y);
|
||||
Left = ConnectionPoints.Min(p => p.X);
|
||||
Top = ConnectionPoints.Min(p => p.Y);
|
||||
}
|
||||
|
||||
protected override void Init(IDiagramViewModel root, bool initNew)
|
||||
{
|
||||
MenuItemCommand = new SimpleCommand(Command_Enable, ExecuteMenuItemCommand);
|
||||
base.Init(root, initNew);
|
||||
|
||||
BuildMenuOptions();
|
||||
}
|
||||
|
||||
protected override void InitNew()
|
||||
{
|
||||
this.ClearConnectors();
|
||||
}
|
||||
|
||||
private void ExecuteMenuItemCommand(object obj)
|
||||
{
|
||||
ShowConnectors = (obj as CinchMenuItem).IsChecked;
|
||||
}
|
||||
|
||||
private void BuildMenuOptions()
|
||||
{
|
||||
menuOptions = new ObservableCollection<CinchMenuItem>();
|
||||
CinchMenuItem menuItem = new CinchMenuItem();
|
||||
menuItem.Text = "显示点";
|
||||
menuItem.IsCheckable = true;
|
||||
menuItem.Command = MenuItemCommand;
|
||||
menuItem.CommandParameter = menuItem;
|
||||
menuOptions.Add(menuItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Media3D;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class DirectLineDrawingDesignerItemViewModel : DrawingDesignerItemViewModelBase
|
||||
{
|
||||
public DirectLineDrawingDesignerItemViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public DirectLineDrawingDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public DirectLineDrawingDesignerItemViewModel(IDiagramViewModel root, Point startPoint, bool erasable) : base(root, DrawMode.DirectLine, startPoint, erasable)
|
||||
{
|
||||
}
|
||||
|
||||
public DirectLineDrawingDesignerItemViewModel(IDiagramViewModel root, List<Point> points, bool erasable) : base(root, DrawMode.DirectLine, points, erasable)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
||||
{
|
||||
var point = e.GetPosition(sender);
|
||||
if (Points == null || Points.Count == 0)//没有起始点
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((Points.LastOrDefault() - point).Length < ColorViewModel.LineWidth)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//按着LeftShift自动封闭曲线
|
||||
if (Keyboard.IsKeyDown(Key.LeftShift) == true)
|
||||
{
|
||||
point = Points[0];
|
||||
}
|
||||
|
||||
if (Geometry is PathGeometry geometry)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
geometry = new PathGeometry();
|
||||
var figure = new PathFigure { StartPoint = Points[0] };
|
||||
geometry.Figures.Add(figure);
|
||||
}
|
||||
|
||||
LineSegment arc = new LineSegment(point, true);
|
||||
|
||||
var preLine = geometry.Figures[0].Segments.LastOrDefault();
|
||||
if (preLine != _lastLine)
|
||||
{
|
||||
geometry.Figures[0].Segments.Remove(preLine);
|
||||
}
|
||||
geometry.Figures[0].Segments.Add(arc);
|
||||
Geometry = geometry;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private LineSegment _lastLine;
|
||||
public override bool OnMouseDown(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
//左键添加点
|
||||
if (e.ChangedButton == MouseButton.Left)
|
||||
{
|
||||
var point = e.GetPosition(sender);
|
||||
if (Points == null || Points.Count == 0)//没有起始点
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((Points.LastOrDefault() - point).Length < ColorViewModel.LineWidth)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
//按着LeftShift自动封闭曲线
|
||||
if (Keyboard.IsKeyDown(Key.LeftShift) == true)
|
||||
{
|
||||
point = Points[0];
|
||||
}
|
||||
Points.Add(point);
|
||||
|
||||
if (Geometry is PathGeometry geometry)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
geometry = new PathGeometry();
|
||||
var figure = new PathFigure { StartPoint = Points[0] };
|
||||
geometry.Figures.Add(figure);
|
||||
}
|
||||
|
||||
var preLine = geometry.Figures[0].Segments.LastOrDefault();
|
||||
if (preLine != _lastLine)
|
||||
{
|
||||
geometry.Figures[0].Segments.Remove(preLine);
|
||||
}
|
||||
|
||||
_lastLine = new LineSegment(point, true);
|
||||
geometry.Figures[0].Segments.Add(_lastLine);
|
||||
Geometry = geometry;
|
||||
|
||||
IsFinish = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnMouseUp(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.ChangedButton == MouseButton.Left && Keyboard.IsKeyDown(Key.LeftShift) == false)//按着LeftShift自动封闭曲线
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Geometry is PathGeometry geometry)
|
||||
{
|
||||
var preLine = geometry.Figures[0].Segments.LastOrDefault();
|
||||
if (preLine != _lastLine)
|
||||
{
|
||||
geometry.Figures[0].Segments.Remove(preLine);
|
||||
}
|
||||
|
||||
_lastLine = null;
|
||||
Geometry = geometry;
|
||||
}
|
||||
return base.OnMouseUp(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Media3D;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class DrawingDesignerItemViewModelBase : DesignerItemViewModelBase
|
||||
{
|
||||
public DrawingDesignerItemViewModelBase() : this(null)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public DrawingDesignerItemViewModelBase(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public DrawingDesignerItemViewModelBase(IDiagramViewModel root, DrawMode drawMode, Point startPoint, bool erasable) : this(root, drawMode, new List<Point> { startPoint }, erasable)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public DrawingDesignerItemViewModelBase(IDiagramViewModel root, DrawMode drawMode, List<Point> points, bool erasable) : base(root)
|
||||
{
|
||||
DrawMode = drawMode;
|
||||
Points = points;
|
||||
Erasable = erasable;
|
||||
}
|
||||
|
||||
public virtual bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual bool OnMouseDown(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual bool OnMouseUp(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (IsFinish)
|
||||
{
|
||||
UpdateLocation();
|
||||
|
||||
Geometry.Transform = new TranslateTransform(0 - Left, 0 - Top);
|
||||
|
||||
if (Erasable)
|
||||
{
|
||||
var aPen = new Pen(ColorObject.ToBrush(ColorViewModel.LineColor), ColorViewModel.LineWidth);
|
||||
Geometry = Geometry.GetWidenedPathGeometry(aPen); //可擦除,需要把Geometry转成几何图像,所以不能有填充色
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual bool Erase(Geometry erase)
|
||||
{
|
||||
if (Erasable)
|
||||
{
|
||||
erase.Transform = new TranslateTransform(0 - Left, 0 - Top);
|
||||
Geometry = Geometry.Combine(Geometry, erase, GeometryCombineMode.Exclude, null);
|
||||
|
||||
if (Geometry.IsEmpty())
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//var area = erase.GetArea();
|
||||
//if (area > 10)
|
||||
//{
|
||||
return true;
|
||||
//}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Erasable
|
||||
{
|
||||
get;set;
|
||||
}
|
||||
|
||||
private Geometry _geometry;
|
||||
public Geometry Geometry
|
||||
{
|
||||
get
|
||||
{
|
||||
return _geometry;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _geometry, value);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsFinish
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
private List<Point> _points;
|
||||
public List<Point> Points
|
||||
{
|
||||
get
|
||||
{
|
||||
return _points;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _points, value);
|
||||
}
|
||||
}
|
||||
public DrawMode DrawMode
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public void UpdateLocation()
|
||||
{
|
||||
ItemWidth = Geometry.Bounds.Width + ColorViewModel.LineWidth;
|
||||
ItemHeight = Geometry.Bounds.Height + ColorViewModel.LineWidth;
|
||||
Left = Geometry.Bounds.Left;
|
||||
Top = Geometry.Bounds.Top;
|
||||
}
|
||||
|
||||
protected override void Init(IDiagramViewModel root, bool initNew)
|
||||
{
|
||||
base.Init(root, initNew);
|
||||
IsHitTestVisible = false;
|
||||
}
|
||||
|
||||
protected override void InitNew()
|
||||
{
|
||||
ClearConnectors();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class EllipseDrawingDesignerItemViewModel : DrawingDesignerItemViewModelBase
|
||||
{
|
||||
public EllipseDrawingDesignerItemViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public EllipseDrawingDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public EllipseDrawingDesignerItemViewModel(IDiagramViewModel root, Point startPoint, bool erasable) : base(root, DrawMode.Rectangle, startPoint, erasable)
|
||||
{
|
||||
}
|
||||
|
||||
public EllipseDrawingDesignerItemViewModel(IDiagramViewModel root, List<Point> points, bool erasable) : base(root, DrawMode.Rectangle, points, erasable)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
var point = e.GetPosition(sender);
|
||||
if (Points == null || Points.Count == 0)//没有起始点
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((Points[0] - point).Length < ColorViewModel.LineWidth)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Keyboard.IsKeyDown(Key.LeftShift))//圆形
|
||||
{
|
||||
var len =Math.Abs(point.X - Points[0].X);//按X轴放大
|
||||
point = new Point(Points[0].X + (point.X > Points[0].X ? len : -len), Points[0].Y + (point.Y > Points[0].Y ? len : -len));
|
||||
}
|
||||
|
||||
if (Points.Count == 2)
|
||||
{
|
||||
Points[1] = point;
|
||||
}
|
||||
else
|
||||
{
|
||||
Points.Add(point);
|
||||
}
|
||||
Geometry = new EllipseGeometry(new Rect(Points[0], Points[1]));
|
||||
IsFinish = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool OnMouseDown(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnMouseUp(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return base.OnMouseUp(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using SvgPathProperties;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class EraserDrawingDesignerItemViewModel : DrawingDesignerItemViewModelBase
|
||||
{
|
||||
public EraserDrawingDesignerItemViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public EraserDrawingDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public EraserDrawingDesignerItemViewModel(IDiagramViewModel root, Point startPoint) : base(root, DrawMode.Eraser, startPoint, true)
|
||||
{
|
||||
}
|
||||
|
||||
public EraserDrawingDesignerItemViewModel(IDiagramViewModel root, List<Point> points) : base(root, DrawMode.Eraser, points, true)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
var point = e.GetPosition(sender);
|
||||
if (Points == null || Points.Count == 0)//没有起始点
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if ((Points[0] - point).Length < ColorViewModel.LineWidth)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
PathGeometry geometry;
|
||||
PathFigure figure;
|
||||
if (Keyboard.IsKeyDown(Key.LeftShift) && Geometry != null)//预览模式,一并擦除
|
||||
{
|
||||
geometry = (PathGeometry)Geometry;
|
||||
figure = geometry.Figures[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
geometry = new PathGeometry();
|
||||
figure = new PathFigure { IsClosed = true, IsFilled = true };
|
||||
geometry.Figures.Add(figure);
|
||||
}
|
||||
|
||||
var radius = ColorViewModel.LineWidth / 2;
|
||||
var positiveX = radius * (point.X > Points[0].X ? 1 : -1);
|
||||
var positiveY = radius * (point.Y > Points[0].Y ? 1 : -1);
|
||||
|
||||
figure.StartPoint = new Point( Points[0].X - positiveX, Points[0].Y - positiveY);
|
||||
|
||||
var line = new LineSegment(new Point( Points[0].X + positiveX, Points[0].Y - positiveY), false);
|
||||
figure.Segments.Add(line);
|
||||
|
||||
line = new LineSegment(new Point(point.X + positiveX, point.Y - positiveY), false);
|
||||
figure.Segments.Add(line);
|
||||
|
||||
line = new LineSegment(new Point(point.X + positiveX, point.Y + positiveY), false);
|
||||
figure.Segments.Add(line);
|
||||
|
||||
line = new LineSegment(new Point(point.X - positiveX, point.Y + positiveY), false);
|
||||
figure.Segments.Add(line);
|
||||
|
||||
line = new LineSegment(new Point( Points[0].X - positiveX, Points[0].Y + positiveY), false);
|
||||
figure.Segments.Add(line);
|
||||
|
||||
Points[0] = point;
|
||||
Geometry = geometry;
|
||||
if (Keyboard.IsKeyDown(Key.LeftShift))//预览模式,一并擦除
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Erase(Geometry);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool OnMouseDown(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnMouseUp(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (Geometry != null)
|
||||
{
|
||||
Erase(Geometry);
|
||||
}
|
||||
return base.OnMouseUp(sender, e);
|
||||
}
|
||||
|
||||
private new bool Erase(Geometry geometry)
|
||||
{
|
||||
var empty = true;
|
||||
List<DrawingDesignerItemViewModelBase> deleteDrawGeometries = new List<DrawingDesignerItemViewModelBase>();
|
||||
foreach (var g in this.Root.Items.OfType<DrawingDesignerItemViewModelBase>())
|
||||
{
|
||||
if (g.Erase(geometry))
|
||||
deleteDrawGeometries.Add(g);
|
||||
else
|
||||
empty = false;
|
||||
}
|
||||
|
||||
foreach (var g in deleteDrawGeometries)
|
||||
{
|
||||
this.Root.Remove(g);
|
||||
}
|
||||
|
||||
return empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class LineDrawingDesignerItemViewModel : DrawingDesignerItemViewModelBase
|
||||
{
|
||||
public LineDrawingDesignerItemViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public LineDrawingDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public LineDrawingDesignerItemViewModel(IDiagramViewModel root, Point startPoint, bool erasable) : base(root, DrawMode.Line, startPoint, erasable)
|
||||
{
|
||||
}
|
||||
|
||||
public LineDrawingDesignerItemViewModel(IDiagramViewModel root, List<Point> points, bool erasable) : base(root, DrawMode.Line, points, erasable)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
var point = e.GetPosition(sender);
|
||||
if (Points == null || Points.Count == 0)//没有起始点
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((Points[0] - point).Length < ColorViewModel.LineWidth)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Points.Count == 2)
|
||||
{
|
||||
Points[1] = point;
|
||||
}
|
||||
else
|
||||
{
|
||||
Points.Add(point);
|
||||
}
|
||||
|
||||
Geometry = new LineGeometry(Points[0], Points[1]);
|
||||
IsFinish = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool OnMouseDown(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnMouseUp(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return base.OnMouseUp(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class PolygonDrawingDesignerItemViewModel : DrawingDesignerItemViewModelBase
|
||||
{
|
||||
public PolygonDrawingDesignerItemViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public PolygonDrawingDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public PolygonDrawingDesignerItemViewModel(IDiagramViewModel root, Point startPoint, bool erasable) : base(root, DrawMode.Line, startPoint, erasable)
|
||||
{
|
||||
}
|
||||
|
||||
public PolygonDrawingDesignerItemViewModel(IDiagramViewModel root, List<Point> points, bool erasable) : base(root, DrawMode.Line, points, erasable)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
var point = e.GetPosition(sender);
|
||||
if (Points == null || Points.Count == 0)//没有起始点
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((Points.LastOrDefault() - point).Length < ColorViewModel.LineWidth)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Points.Add(point);
|
||||
|
||||
if (Geometry is PathGeometry geometry)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
geometry = new PathGeometry();
|
||||
var figure = new PathFigure { StartPoint = Points[0] };
|
||||
figure.IsClosed = true;
|
||||
geometry.Figures.Add(figure);
|
||||
}
|
||||
|
||||
LineSegment arc = new LineSegment(point, true) { IsSmoothJoin = true };
|
||||
geometry.Figures[0].Segments.Add(arc);
|
||||
Geometry = geometry;
|
||||
|
||||
IsFinish = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool OnMouseDown(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnMouseUp(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return base.OnMouseUp(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class PolylineDrawingDesignerItemViewModel : DrawingDesignerItemViewModelBase
|
||||
{
|
||||
public PolylineDrawingDesignerItemViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public PolylineDrawingDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public PolylineDrawingDesignerItemViewModel(IDiagramViewModel root, Point startPoint, bool erasable) : base(root, DrawMode.Line, startPoint, erasable)
|
||||
{
|
||||
}
|
||||
|
||||
public PolylineDrawingDesignerItemViewModel(IDiagramViewModel root, List<Point> points, bool erasable) : base(root, DrawMode.Line, points, erasable)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
var point = e.GetPosition(sender);
|
||||
if (Points == null || Points.Count == 0)//没有起始点
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((Points.LastOrDefault() - point).Length < ColorViewModel.LineWidth)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Points.Add(point);
|
||||
|
||||
if (Geometry is PathGeometry geometry)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
geometry = new PathGeometry();
|
||||
var figure = new PathFigure { StartPoint = Points[0] };
|
||||
geometry.Figures.Add(figure);
|
||||
}
|
||||
|
||||
LineSegment arc = new LineSegment(point, true);// { IsSmoothJoin = true };
|
||||
geometry.Figures[0].Segments.Add(arc);
|
||||
Geometry = geometry;
|
||||
|
||||
IsFinish = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool OnMouseDown(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnMouseUp(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return base.OnMouseUp(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class RectangleDrawingDesignerItemViewModel : DrawingDesignerItemViewModelBase
|
||||
{
|
||||
public RectangleDrawingDesignerItemViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public RectangleDrawingDesignerItemViewModel(IDiagramViewModel root) : base(root)
|
||||
{
|
||||
}
|
||||
|
||||
public RectangleDrawingDesignerItemViewModel(IDiagramViewModel root, Point startPoint, bool erasable) : base(root, DrawMode.Rectangle, startPoint, erasable)
|
||||
{
|
||||
}
|
||||
|
||||
public RectangleDrawingDesignerItemViewModel(IDiagramViewModel root, List<Point> points, bool erasable) : base(root, DrawMode.Rectangle, points, erasable)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool OnMouseMove(IInputElement sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
var point = e.GetPosition(sender);
|
||||
if (Points == null || Points.Count == 0)//没有起始点
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((Points[0] - point).Length < ColorViewModel.LineWidth)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Keyboard.IsKeyDown(Key.LeftShift))//正方形
|
||||
{
|
||||
var len = Math.Abs(point.X - Points[0].X);//按X轴放大
|
||||
point = new Point(Points[0].X + (point.X > Points[0].X ? len : -len), Points[0].Y + (point.Y > Points[0].Y ? len : -len));
|
||||
}
|
||||
|
||||
if (Points.Count == 2)
|
||||
{
|
||||
Points[1] = point;
|
||||
}
|
||||
else
|
||||
{
|
||||
Points.Add(point);
|
||||
}
|
||||
Geometry = new RectangleGeometry(new Rect(Points[0], Points[1]));
|
||||
IsFinish = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool OnMouseDown(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool OnMouseUp(IInputElement sender, MouseButtonEventArgs e)
|
||||
{
|
||||
return base.OnMouseUp(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user