橡皮修改

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

@@ -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, List<Point> points, bool erasable) : base(root)
@@ -56,10 +56,10 @@ namespace AIStudio.Wpf.DiagramDesigner
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转成几何图像所以不能有填充色
}
}
return true;
}
@@ -76,18 +76,17 @@ namespace AIStudio.Wpf.DiagramDesigner
}
else
{
//var area = erase.GetArea();
//if (area > 10)
//{
if (this.GetBounds().IntersectsWith(erase.Bounds))//相交
{
return true;
//}
}
}
return false;
}
public bool Erasable
{
get;set;
get; set;
}
private Geometry _geometry;

View File

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