橡皮修改

This commit is contained in:
kwai
2023-05-09 19:21:48 +08:00
parent c3342ced13
commit e61b505dd3
3 changed files with 45 additions and 49 deletions

View File

@@ -62,7 +62,7 @@ namespace AIStudio.Wpf.DiagramDesigner
{ {
_drawingDesignerItem = new EraserDrawingDesignerItemViewModel(_viewModel, dragStartPoint); _drawingDesignerItem = new EraserDrawingDesignerItemViewModel(_viewModel, dragStartPoint);
_rubberbandBrush = new SolidColorBrush(Colors.Red) { Opacity = 0.5 }; _rubberbandBrush = null;
_rubberbandPen = new Pen(new SolidColorBrush(Colors.Red) { Opacity = 0.5 }, _drawingDesignerItem.ColorViewModel.LineWidth); _rubberbandPen = new Pen(new SolidColorBrush(Colors.Red) { Opacity = 0.5 }, _drawingDesignerItem.ColorViewModel.LineWidth);
} }
else if (DrawMode >= DrawMode.Line && DrawMode <= DrawMode.DirectLine) else if (DrawMode >= DrawMode.Line && DrawMode <= DrawMode.DirectLine)

View File

@@ -26,7 +26,7 @@ namespace AIStudio.Wpf.DiagramDesigner
public DrawingDesignerItemViewModelBase(IDiagramViewModel root, DrawMode drawMode, Point startPoint, bool erasable) : this(root, drawMode, new List<Point> { startPoint }, erasable) 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) public DrawingDesignerItemViewModelBase(IDiagramViewModel root, DrawMode drawMode, List<Point> points, bool erasable) : base(root)
@@ -56,10 +56,10 @@ namespace AIStudio.Wpf.DiagramDesigner
if (Erasable) if (Erasable)
{ {
var aPen = new Pen(ColorObject.ToBrush(ColorViewModel.LineColor), ColorViewModel.LineWidth); var aPen = new Pen(ColorObject.ToBrush(ColorViewModel.LineColor), ColorViewModel.LineWidth);
Geometry = Geometry.GetWidenedPathGeometry(aPen); //可擦除需要把Geometry转成几何图像所以不能有填充色 Geometry = Geometry.GetWidenedPathGeometry(aPen); //可擦除需要把Geometry转成几何图像所以不能有填充色
} }
} }
return true; return true;
} }
@@ -76,18 +76,17 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
else else
{ {
//var area = erase.GetArea(); if (this.GetBounds().IntersectsWith(erase.Bounds))//相交
//if (area > 10) {
//{
return true; return true;
//} }
} }
return false; return false;
} }
public bool Erasable public bool Erasable
{ {
get;set; get; set;
} }
private Geometry _geometry; private Geometry _geometry;

View File

@@ -29,67 +29,64 @@ namespace AIStudio.Wpf.DiagramDesigner
} }
public override bool OnMouseMove(IInputElement sender, MouseEventArgs e) public override bool OnMouseMove(IInputElement sender, MouseEventArgs e)
{ {
if (e.LeftButton == MouseButtonState.Pressed) if (e.RightButton == MouseButtonState.Pressed)
{ {
var point = e.GetPosition(sender); var point = e.GetPosition(sender);
if (Points == null || Points.Count == 0)//没有起始点 if (Points == null || Points.Count == 0)//没有起始点
{ {
return true; return true;
} }
if ((Points[0] - point).Length < ColorViewModel.LineWidth)
if ((Points.LastOrDefault() - point).Length < ColorViewModel.LineWidth)
{ {
return true; return true;
} }
PathGeometry geometry; Points.Add(point);
PathFigure figure; if (Geometry is PathGeometry geometry)
if (Keyboard.IsKeyDown(Key.LeftShift) && Geometry != null)//预览模式,一并擦除
{ {
geometry = (PathGeometry)Geometry;
figure = geometry.Figures[0];
} }
else else
{ {
geometry = new PathGeometry(); geometry = new PathGeometry();
figure = new PathFigure { IsClosed = true, IsFilled = true }; var figure = new PathFigure { StartPoint = Points[0] };
geometry.Figures.Add(figure); 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); LineSegment arc = new LineSegment(point, true);// { IsSmoothJoin = true };
geometry.Figures[0].Segments.Add(arc);
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; Geometry = geometry;
if (Keyboard.IsKeyDown(Key.LeftShift))//预览模式,一并擦除
{
}
else
{
Erase(Geometry);
}
return true; return true;
} }
else 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;
}
var 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;
Points[0] = point;
Erase(Geometry);
return true;
}
else else
{ {
return false; return false;