首次提交:本地项目同步到Gitea
This commit is contained in:
37
LibShapes/Core/State/ChangeStrategy/IChangeStrategy.cs
Normal file
37
LibShapes/Core/State/ChangeStrategy/IChangeStrategy.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Io.Github.Kerwinxu.LibShapes.Core.Shape;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.State.ChangeStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// 更改策略
|
||||
/// </summary>
|
||||
interface IChangeStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否合适这个策略
|
||||
/// </summary>
|
||||
/// <param name="pointFs"></param>
|
||||
/// <param name="start_pointF"></param>
|
||||
/// <returns></returns>
|
||||
bool isRight(PointF [] pointFs, PointF start_pointF);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 这个策略的执行,
|
||||
/// </summary>
|
||||
/// <param name="shape"></param>
|
||||
void action(ShapeEle shape, PointF start_pointF, PointF end_pointF);
|
||||
|
||||
/// <summary>
|
||||
/// 更改成的鼠标样式
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Cursor changeCursor();
|
||||
}
|
||||
}
|
||||
39
LibShapes/Core/State/ChangeStrategy/MoveMode.cs
Normal file
39
LibShapes/Core/State/ChangeStrategy/MoveMode.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using Io.Github.Kerwinxu.LibShapes.Core.Shape;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.State.ChangeStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// 移动
|
||||
/// </summary>
|
||||
public class MoveMode : IChangeStrategy
|
||||
{
|
||||
public void action(ShapeEle shape, PointF start_pointF, PointF end_pointF)
|
||||
{
|
||||
// 这个是更改xy的
|
||||
RectangleF rect = new RectangleF() {
|
||||
X = end_pointF.X-start_pointF.X,
|
||||
Y = end_pointF.Y - start_pointF.Y
|
||||
};
|
||||
shape.Change(rect);
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Cursor changeCursor()
|
||||
{
|
||||
return Cursors.Hand;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool isRight(PointF[] pointFs, PointF start_pointF)
|
||||
{
|
||||
return true;// 一般是最后一项。
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
45
LibShapes/Core/State/ChangeStrategy/ResizeModeEast.cs
Normal file
45
LibShapes/Core/State/ChangeStrategy/ResizeModeEast.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Io.Github.Kerwinxu.LibShapes.Core.Shape;
|
||||
using Io.Github.Kerwinxu.LibShapes.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.State.ChangeStrategy
|
||||
{
|
||||
public class ResizeModeEast : IChangeStrategy
|
||||
{
|
||||
public void action(ShapeEle shape, PointF start_pointF, PointF end_pointF)
|
||||
{
|
||||
// 右边的话,是更改x,或者width,
|
||||
RectangleF rect = new RectangleF();
|
||||
var diff = end_pointF.X - start_pointF.X;
|
||||
if (shape.Width < 0)
|
||||
{
|
||||
rect.X = diff;
|
||||
}
|
||||
else
|
||||
{
|
||||
rect.Width = diff;
|
||||
}
|
||||
shape.Change(rect);
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Cursor changeCursor()
|
||||
{
|
||||
return Cursors.PanEast;
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool isRight(PointF[] pointFs, PointF start_pointF)
|
||||
{
|
||||
// 判断一句是跟右边的线足够的近。
|
||||
return DistanceCalculation.pointToLine(start_pointF, pointFs[1], pointFs[2]) <= DistanceCalculation.select_tolerance;
|
||||
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
54
LibShapes/Core/State/ChangeStrategy/ResizeModeNorth.cs
Normal file
54
LibShapes/Core/State/ChangeStrategy/ResizeModeNorth.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Io.Github.Kerwinxu.LibShapes.Core.Shape;
|
||||
using Io.Github.Kerwinxu.LibShapes.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.State.ChangeStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// 北方更改大小
|
||||
/// </summary>
|
||||
public class ResizeModeNorth : IChangeStrategy
|
||||
{
|
||||
public void action(ShapeEle shape, PointF start_pointF, PointF end_pointF)
|
||||
{
|
||||
// 右边的话,是更改x,或者width,
|
||||
RectangleF rect = new RectangleF();
|
||||
var diff = end_pointF.Y - start_pointF.Y;
|
||||
if (shape.Height < 0)
|
||||
{
|
||||
rect.Height = -diff;
|
||||
rect.Height = diff;
|
||||
Trace.WriteLine($"修改h:{rect}");
|
||||
}
|
||||
else
|
||||
{
|
||||
rect.Y = diff;
|
||||
rect.Height = -diff;
|
||||
Trace.WriteLine($"修改y:{rect}");
|
||||
}
|
||||
shape.Change(rect);
|
||||
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Cursor changeCursor()
|
||||
{
|
||||
return Cursors.PanNorth;
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool isRight(PointF[] pointFs, PointF start_pointF)
|
||||
{
|
||||
|
||||
return DistanceCalculation.pointToLine(start_pointF, pointFs[0], pointFs[1]) <= DistanceCalculation.select_tolerance;
|
||||
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
59
LibShapes/Core/State/ChangeStrategy/ResizeModeNorthEast.cs
Normal file
59
LibShapes/Core/State/ChangeStrategy/ResizeModeNorthEast.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using Io.Github.Kerwinxu.LibShapes.Core.Shape;
|
||||
using Io.Github.Kerwinxu.LibShapes.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.State.ChangeStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// 东北方向更改
|
||||
/// </summary>
|
||||
public class ResizeModeNorthEast : IChangeStrategy
|
||||
{
|
||||
public void action(ShapeEle shape, PointF start_pointF, PointF end_pointF)
|
||||
{
|
||||
RectangleF rect = new RectangleF();
|
||||
var diffx = end_pointF.X - start_pointF.X;
|
||||
var diffy = end_pointF.Y - start_pointF.Y;
|
||||
if (shape.Width < 0)
|
||||
{
|
||||
rect.X = diffx;
|
||||
rect.Width = -diffx;
|
||||
}
|
||||
else
|
||||
{
|
||||
rect.Width = diffx;
|
||||
}
|
||||
|
||||
if (shape.Height < 0)
|
||||
{
|
||||
rect.Y = -diffy;
|
||||
rect.Height = diffy;
|
||||
}
|
||||
else
|
||||
{
|
||||
rect.Y = diffy;
|
||||
rect.Height = -diffy;
|
||||
}
|
||||
Trace.WriteLine($"更改:{rect}");
|
||||
shape.Change(rect);
|
||||
}
|
||||
|
||||
public Cursor changeCursor()
|
||||
{
|
||||
return Cursors.PanNE;
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool isRight(PointF[] pointFs, PointF start_pointF)
|
||||
{
|
||||
return DistanceCalculation.distance(start_pointF, pointFs[1]) <= DistanceCalculation.select_tolerance * 2;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
54
LibShapes/Core/State/ChangeStrategy/ResizeModeNorthWest.cs
Normal file
54
LibShapes/Core/State/ChangeStrategy/ResizeModeNorthWest.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Io.Github.Kerwinxu.LibShapes.Core.Shape;
|
||||
using Io.Github.Kerwinxu.LibShapes.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.State.ChangeStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// 西北
|
||||
/// </summary>
|
||||
public class ResizeModeNorthWest : IChangeStrategy
|
||||
{
|
||||
public void action(ShapeEle shape, PointF start_pointF, PointF end_pointF)
|
||||
{
|
||||
RectangleF rect = new RectangleF();
|
||||
var diffx = end_pointF.X - start_pointF.X;
|
||||
var diffy = end_pointF.Y - start_pointF.Y;
|
||||
if (shape.Width < 0)
|
||||
{
|
||||
rect.Width = -diffx;
|
||||
}
|
||||
else
|
||||
{
|
||||
rect.X = diffx;
|
||||
rect.Width = -diffx;
|
||||
}
|
||||
if (shape.Height < 0)
|
||||
{
|
||||
rect.Height = -diffy;
|
||||
}
|
||||
else
|
||||
{
|
||||
rect.Y = diffy;
|
||||
rect.Height = -diffy;
|
||||
}
|
||||
shape.Change(rect);
|
||||
}
|
||||
|
||||
public Cursor changeCursor()
|
||||
{
|
||||
return Cursors.PanNW;
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool isRight(PointF[] pointFs, PointF start_pointF)
|
||||
{
|
||||
return DistanceCalculation.distance(start_pointF, pointFs[0]) <= DistanceCalculation.select_tolerance * 2 ;
|
||||
}
|
||||
}
|
||||
}
|
||||
53
LibShapes/Core/State/ChangeStrategy/ResizeModeSorthWest.cs
Normal file
53
LibShapes/Core/State/ChangeStrategy/ResizeModeSorthWest.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using Io.Github.Kerwinxu.LibShapes.Core.Shape;
|
||||
using Io.Github.Kerwinxu.LibShapes.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.State.ChangeStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// 西南
|
||||
/// </summary>
|
||||
public class ResizeModeSorthWest : IChangeStrategy
|
||||
{
|
||||
public void action(ShapeEle shape, PointF start_pointF, PointF end_pointF)
|
||||
{
|
||||
RectangleF rect = new RectangleF();
|
||||
var diffx = end_pointF.X - start_pointF.X;
|
||||
var diffy = end_pointF.Y - start_pointF.Y;
|
||||
if (shape.Width < 0)
|
||||
{
|
||||
rect.Width = -diffx;
|
||||
}
|
||||
else
|
||||
{
|
||||
rect.X = diffx;
|
||||
rect.Width = -diffx;
|
||||
}
|
||||
if (shape.Height < 0)
|
||||
{
|
||||
rect.Y = diffy;
|
||||
rect.Height = -diffy;
|
||||
}
|
||||
else
|
||||
{
|
||||
rect.Height = diffy;
|
||||
}
|
||||
shape.Change(rect);
|
||||
}
|
||||
|
||||
public Cursor changeCursor()
|
||||
{
|
||||
return Cursors.PanSW;
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
public bool isRight(PointF[] pointFs, PointF start_pointF)
|
||||
{
|
||||
return DistanceCalculation.distance(start_pointF, pointFs[3]) <= DistanceCalculation.select_tolerance * 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
44
LibShapes/Core/State/ChangeStrategy/ResizeModeSouth.cs
Normal file
44
LibShapes/Core/State/ChangeStrategy/ResizeModeSouth.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Io.Github.Kerwinxu.LibShapes.Core.Shape;
|
||||
using Io.Github.Kerwinxu.LibShapes.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.State.ChangeStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// 南方更改
|
||||
/// </summary>
|
||||
public class ResizeModeSouth : IChangeStrategy
|
||||
{
|
||||
public void action(ShapeEle shape, PointF start_pointF, PointF end_pointF)
|
||||
{
|
||||
// 右边的话,是更改x,或者width,
|
||||
RectangleF rect = new RectangleF();
|
||||
var diff = end_pointF.Y - start_pointF.Y;
|
||||
if (shape.Height < 0)
|
||||
{
|
||||
rect.Y = diff;
|
||||
}
|
||||
else
|
||||
{
|
||||
rect.Height = diff;
|
||||
}
|
||||
shape.Change(rect);
|
||||
}
|
||||
|
||||
public Cursor changeCursor()
|
||||
{
|
||||
return Cursors.PanSouth;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool isRight(PointF[] pointFs, PointF start_pointF)
|
||||
{
|
||||
return DistanceCalculation.pointToLine(start_pointF, pointFs[2], pointFs[3]) <= DistanceCalculation.select_tolerance;
|
||||
}
|
||||
}
|
||||
}
|
||||
52
LibShapes/Core/State/ChangeStrategy/ResizeModeSouthEast.cs
Normal file
52
LibShapes/Core/State/ChangeStrategy/ResizeModeSouthEast.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using Io.Github.Kerwinxu.LibShapes.Core.Shape;
|
||||
using Io.Github.Kerwinxu.LibShapes.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.State.ChangeStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// 东南方向更改
|
||||
/// </summary>
|
||||
public class ResizeModeSouthEast : IChangeStrategy
|
||||
{
|
||||
public void action(ShapeEle shape, PointF start_pointF, PointF end_pointF)
|
||||
{
|
||||
RectangleF rect = new RectangleF();
|
||||
var diffx = end_pointF.X - start_pointF.X;
|
||||
var diffy = end_pointF.Y - start_pointF.Y;
|
||||
if (shape.Width < 0)
|
||||
{
|
||||
rect.X = diffx;
|
||||
}
|
||||
else
|
||||
{
|
||||
rect.Width = diffx;
|
||||
}
|
||||
if (shape.Height < 0)
|
||||
{
|
||||
rect.Y = diffy;
|
||||
}
|
||||
else
|
||||
{
|
||||
rect.Height = diffy;
|
||||
}
|
||||
shape.Change(rect);
|
||||
}
|
||||
|
||||
public Cursor changeCursor()
|
||||
{
|
||||
return Cursors.PanSE;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool isRight(PointF[] pointFs, PointF start_pointF)
|
||||
{
|
||||
return DistanceCalculation.distance(start_pointF, pointFs[2]) <= DistanceCalculation.select_tolerance * 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
42
LibShapes/Core/State/ChangeStrategy/ResizeModeWest.cs
Normal file
42
LibShapes/Core/State/ChangeStrategy/ResizeModeWest.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Io.Github.Kerwinxu.LibShapes.Core.Shape;
|
||||
using Io.Github.Kerwinxu.LibShapes.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.State.ChangeStrategy
|
||||
{
|
||||
public class ResizeModeWest : IChangeStrategy
|
||||
{
|
||||
public void action(ShapeEle shape, PointF start_pointF, PointF end_pointF)
|
||||
{
|
||||
// 右边的话,是更改x,或者width,
|
||||
RectangleF rect = new RectangleF();
|
||||
var diff = end_pointF.X - start_pointF.X;
|
||||
if (shape.Width < 0)
|
||||
{
|
||||
rect.Width = -diff;
|
||||
}
|
||||
else
|
||||
{
|
||||
rect.X = diff;
|
||||
rect.Width = -diff;
|
||||
}
|
||||
shape.Change(rect);
|
||||
}
|
||||
|
||||
public Cursor changeCursor()
|
||||
{
|
||||
return Cursors.PanWest;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool isRight(PointF[] pointFs, PointF start_pointF)
|
||||
{
|
||||
return DistanceCalculation.pointToLine(start_pointF, pointFs[0], pointFs[3]) <= DistanceCalculation.select_tolerance;
|
||||
}
|
||||
}
|
||||
}
|
||||
91
LibShapes/Core/State/ShapeRectSelect.cs
Normal file
91
LibShapes/Core/State/ShapeRectSelect.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.State
|
||||
{
|
||||
public class ShapeRectSelect:State
|
||||
{
|
||||
|
||||
protected PointF endPoint;
|
||||
|
||||
private Pen penSelectShape = new Pen(Color.Black)
|
||||
{ // 选择框的画笔
|
||||
DashStyle = DashStyle.Dash,
|
||||
Width = 0.2f
|
||||
};
|
||||
|
||||
public ShapeRectSelect(UserControlCanvas canvas, PointF start_pointF) : base(canvas, start_pointF)
|
||||
{
|
||||
|
||||
}
|
||||
public ShapeRectSelect(UserControlCanvas canvas) : base(canvas)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Draw(Graphics g)
|
||||
{
|
||||
// 这个其实是绘制一个矩形。
|
||||
g.DrawRectangle(
|
||||
penSelectShape,
|
||||
startPoint.X,
|
||||
startPoint.Y,
|
||||
endPoint.X-startPoint.X,
|
||||
endPoint.Y - startPoint.Y);
|
||||
}
|
||||
|
||||
public override void LeftMouseDown(PointF pointF)
|
||||
{
|
||||
startPoint = pointF; // 只是保存开始地址
|
||||
base.LeftMouseDown(pointF);
|
||||
}
|
||||
|
||||
public override void LeftMouseMove(PointF pointF)
|
||||
{
|
||||
// 保存
|
||||
endPoint = pointF;
|
||||
this.canvas.Refresh(); // 刷新。
|
||||
|
||||
//base.LeftMouseMove(pointF);
|
||||
}
|
||||
|
||||
public override void LeftMouseUp(PointF pointF)
|
||||
{
|
||||
// 这里看一下是否有选择图形
|
||||
endPoint = pointF;
|
||||
var _rect = new RectangleF(startPoint.X, startPoint.Y, endPoint.X - startPoint.X, endPoint.Y - startPoint.Y);
|
||||
var _shapes = this.canvas.shapes.getSelectShapes(_rect);
|
||||
if (_shapes!=null && _shapes.Count > 0)
|
||||
{
|
||||
// 要更改成选择模式
|
||||
this.canvas.state = new StateSelected(this.canvas);
|
||||
// 如果只是选择了一个。
|
||||
if (_shapes.Count == 1)
|
||||
{
|
||||
this.canvas.changeSelect(_shapes[0]); //
|
||||
}
|
||||
else
|
||||
{
|
||||
var multi = new Shape.ShapeMultiSelect();
|
||||
multi.shapes.AddRange(_shapes);
|
||||
this.canvas.changeSelect(multi); // 这个只是通知,但起始这个做不了修改的。
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 说明没有选择图形
|
||||
this.canvas.changeSelect(null);
|
||||
this.canvas.state = new StateStandby(this.canvas);
|
||||
}
|
||||
|
||||
this.canvas.Refresh();
|
||||
|
||||
//base.LeftMouseUp(pointF);
|
||||
}
|
||||
}
|
||||
}
|
||||
48
LibShapes/Core/State/State.cs
Normal file
48
LibShapes/Core/State/State.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.State
|
||||
{
|
||||
public abstract class State
|
||||
{
|
||||
/// <summary>
|
||||
/// 画布
|
||||
/// </summary>
|
||||
public UserControlCanvas canvas { get; set; }
|
||||
|
||||
public PointF startPoint { get; set; }
|
||||
|
||||
|
||||
public State(UserControlCanvas canvas, PointF start_pointF)
|
||||
{
|
||||
this.canvas = canvas;
|
||||
this.startPoint = start_pointF;
|
||||
}
|
||||
|
||||
public State(UserControlCanvas canvas)
|
||||
{
|
||||
this.canvas = canvas;
|
||||
}
|
||||
|
||||
public virtual void LeftMouseDown(PointF pointF) { }
|
||||
public virtual void LeftMouseMove(PointF pointF) { }
|
||||
public virtual void LeftMouseUp(PointF pointF) {}
|
||||
|
||||
public virtual void RightMouseClick(PointF pointF) { }
|
||||
|
||||
/// <summary>
|
||||
/// 将画布的坐标转成虚拟的坐标
|
||||
/// </summary>
|
||||
/// <param name="pointF"></param>
|
||||
/// <returns></returns>
|
||||
protected PointF cantosPointToVirtualPoint(PointF pointF)
|
||||
{
|
||||
return this.canvas.shapes.pointTransform.CanvasToVirtualPoint(pointF);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
61
LibShapes/Core/State/StateCanvasMove.cs
Normal file
61
LibShapes/Core/State/StateCanvasMove.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.State
|
||||
{
|
||||
/// <summary>
|
||||
/// 画布整体的移动
|
||||
/// </summary>
|
||||
public class StateCanvasMove:State
|
||||
{
|
||||
public StateCanvasMove(UserControlCanvas canvas, PointF start_pointF) : base(canvas, start_pointF)
|
||||
{
|
||||
|
||||
}
|
||||
public StateCanvasMove(UserControlCanvas canvas) : base(canvas)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// 移动的话,我这个类会保存原先的偏移
|
||||
private float old_offsetX, old_offsetY;
|
||||
|
||||
private Shapes oldShapes;
|
||||
|
||||
public override void LeftMouseDown(PointF pointF)
|
||||
{
|
||||
this.oldShapes = this.canvas.shapes.DeepClone();
|
||||
// 保存偏移
|
||||
old_offsetX = this.canvas.shapes.pointTransform.OffsetX;
|
||||
old_offsetY = this.canvas.shapes.pointTransform.OffsetY;
|
||||
startPoint = pointF;
|
||||
|
||||
base.LeftMouseDown(pointF);
|
||||
}
|
||||
|
||||
public override void LeftMouseMove(PointF pointF)
|
||||
{
|
||||
float diffx = pointF.X - startPoint.X;
|
||||
float diffy = pointF.Y - startPoint.Y;
|
||||
// 然后修改偏移
|
||||
this.canvas.shapes.pointTransform.OffsetX = old_offsetX + diffx;
|
||||
this.canvas.shapes.pointTransform.OffsetY = old_offsetY + diffy;
|
||||
|
||||
//base.LeftMouseMove(pointF);
|
||||
}
|
||||
|
||||
public override void LeftMouseUp(PointF pointF)
|
||||
{
|
||||
// 保存命令,
|
||||
this.canvas.commandRecorder.addCommand(new Command.CommandShapesChanged() {
|
||||
canvas = this.canvas,
|
||||
OldShapes = this.oldShapes,
|
||||
NewShapes = this.canvas.shapes.DeepClone(),
|
||||
});
|
||||
//base.LeftMouseUp(pointF);
|
||||
}
|
||||
}
|
||||
}
|
||||
51
LibShapes/Core/State/StateCanvasZoom.cs
Normal file
51
LibShapes/Core/State/StateCanvasZoom.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.State
|
||||
{
|
||||
/// <summary>
|
||||
/// 画布的放大和缩小
|
||||
/// </summary>
|
||||
public class StateCanvasZoom:State
|
||||
{
|
||||
public StateCanvasZoom(UserControlCanvas canvas, PointF start_pointF) : base(canvas, start_pointF)
|
||||
{
|
||||
|
||||
}
|
||||
public StateCanvasZoom(UserControlCanvas canvas) : base(canvas)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void RightMouseClick(PointF pointF)
|
||||
{
|
||||
var oldShapes = this.canvas.shapes.DeepClone();
|
||||
this.canvas.reduce(pointF);
|
||||
// 保存命令,
|
||||
this.canvas.commandRecorder.addCommand(new Command.CommandShapesChanged()
|
||||
{
|
||||
canvas = this.canvas,
|
||||
OldShapes = oldShapes,
|
||||
NewShapes = this.canvas.shapes.DeepClone(),
|
||||
});
|
||||
//base.RightMouseClick(pointF);
|
||||
}
|
||||
|
||||
public override void LeftMouseUp(PointF pointF)
|
||||
{
|
||||
var oldShapes = this.canvas.shapes.DeepClone();
|
||||
this.canvas.zoom(pointF);
|
||||
// 保存命令,
|
||||
this.canvas.commandRecorder.addCommand(new Command.CommandShapesChanged()
|
||||
{
|
||||
canvas =this.canvas,
|
||||
OldShapes = oldShapes,
|
||||
NewShapes = this.canvas.shapes.DeepClone(),
|
||||
});
|
||||
//base.LeftMouseUp(pointF);
|
||||
}
|
||||
}
|
||||
}
|
||||
121
LibShapes/Core/State/StateChanging.cs
Normal file
121
LibShapes/Core/State/StateChanging.cs
Normal file
@@ -0,0 +1,121 @@
|
||||
using Io.Github.Kerwinxu.LibShapes.Core.State.ChangeStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.State
|
||||
{
|
||||
/// <summary>
|
||||
/// 更改状态,都是选择后才有的。
|
||||
/// </summary>
|
||||
public class StateChanging:State
|
||||
{
|
||||
public StateChanging(UserControlCanvas canvas, PointF start_pointF) : base(canvas, start_pointF)
|
||||
{
|
||||
|
||||
}
|
||||
public StateChanging(UserControlCanvas canvas) : base(canvas)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 原先的
|
||||
/// </summary>
|
||||
private Shapes oldShapes;
|
||||
|
||||
/// <summary>
|
||||
/// 当前选择的策略
|
||||
/// </summary>
|
||||
private IChangeStrategy changeStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// 所有的策略
|
||||
/// </summary>
|
||||
private IChangeStrategy[] changeStrategies = {
|
||||
// 先4个角点
|
||||
new ChangeStrategy.ResizeModeNorthEast(),
|
||||
new ChangeStrategy.ResizeModeNorthWest(),
|
||||
new ChangeStrategy.ResizeModeSorthWest(),
|
||||
new ChangeStrategy.ResizeModeSouthEast(),
|
||||
// 然后4个方向
|
||||
new ChangeStrategy.ResizeModeEast(),
|
||||
new ChangeStrategy.ResizeModeNorth(),
|
||||
new ChangeStrategy.ResizeModeSouth(),
|
||||
new ChangeStrategy.ResizeModeWest(),
|
||||
// 最后是移动
|
||||
new ChangeStrategy.MoveMode()
|
||||
};
|
||||
|
||||
public override void LeftMouseDown(PointF pointF)
|
||||
{
|
||||
oldShapes = this.canvas.shapes.DeepClone();
|
||||
|
||||
// 这个首先看一下是在四面还是八方上,运算是不同的。
|
||||
// 这里取得坐标
|
||||
var path = new GraphicsPath();
|
||||
path.AddRectangle(this.canvas.SelectShape.GetBounds(this.canvas.shapes.GetMatrix()));
|
||||
if (path.PointCount == 0) return;
|
||||
var points = path.PathPoints;
|
||||
foreach (var item in changeStrategies)
|
||||
{
|
||||
if (item.isRight(points, pointF))
|
||||
{
|
||||
changeStrategy = item;
|
||||
Cursor cursor = item.changeCursor();
|
||||
if (cursor != null) this.canvas.Cursor = cursor;// 更改鼠标样式。
|
||||
return;
|
||||
}
|
||||
}
|
||||
changeStrategy = null;
|
||||
//base.LeftMouseDown(pointF);
|
||||
}
|
||||
|
||||
public override void LeftMouseMove(PointF pointF)
|
||||
{
|
||||
if (changeStrategy != null && this.canvas.SelectShape != null)
|
||||
{
|
||||
// 这里要判断是否对齐网格
|
||||
changeStrategy.action(
|
||||
this.canvas.SelectShape,
|
||||
cantosPointToVirtualPoint(this.startPoint),
|
||||
cantosPointToVirtualPoint(this.canvas.gridAlign(pointF)));
|
||||
this.canvas.Refresh();
|
||||
}
|
||||
//base.LeftMouseMove(pointF);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override void LeftMouseUp(PointF pointF)
|
||||
{
|
||||
// 结束更改操作,然后转成选择模式
|
||||
if (changeStrategy != null && this.canvas.SelectShape != null)
|
||||
{
|
||||
changeStrategy.action(
|
||||
this.canvas.SelectShape,
|
||||
cantosPointToVirtualPoint(this.startPoint),
|
||||
cantosPointToVirtualPoint(this.canvas.gridAlign(pointF)));
|
||||
var old = this.canvas.SelectShape.DeepClone(); // 保存旧的
|
||||
this.canvas.SelectShape.ChangeComplated(); // 更改状态
|
||||
//
|
||||
this.canvas.commandRecorder.addCommand( // 发送命令
|
||||
new Command.CommandShapesChanged()
|
||||
{
|
||||
canvas = this.canvas,
|
||||
OldShapes = this.oldShapes,
|
||||
NewShapes = this.canvas.shapes.DeepClone()
|
||||
}) ;
|
||||
}
|
||||
// 转成
|
||||
this.canvas.state = new StateSelected(this.canvas);
|
||||
this.canvas.Cursor = Cursors.Default;// 换到原先的鼠标样式
|
||||
this.canvas.Refresh();
|
||||
//base.LeftMouseUp(pointF);
|
||||
}
|
||||
}
|
||||
}
|
||||
106
LibShapes/Core/State/StateCreate.cs
Normal file
106
LibShapes/Core/State/StateCreate.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
using Io.Github.Kerwinxu.LibShapes.Core.Shape;
|
||||
using Io.Github.Kerwinxu.LibShapes.Core.State.ChangeStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.State
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建状态。
|
||||
/// </summary>
|
||||
public class StateCreate:State
|
||||
{
|
||||
public StateCreate(UserControlCanvas canvas, PointF start_pointF) : base(canvas, start_pointF)
|
||||
{
|
||||
|
||||
}
|
||||
public StateCreate(UserControlCanvas canvas) : base(canvas)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private Shapes oldShapes;
|
||||
|
||||
public ShapeEle shape { get; set; }
|
||||
|
||||
public StateCreate(UserControlCanvas canvas, ShapeEle shape):base(canvas)
|
||||
{
|
||||
this.shape = shape; // 保存要创建的图形
|
||||
}
|
||||
|
||||
private IChangeStrategy strategy = new ResizeModeSouthEast(); // 更改的策略
|
||||
private ShapeEle newshape; // 建立的图形。
|
||||
|
||||
public override void LeftMouseDown(PointF pointF)
|
||||
{
|
||||
oldShapes = this.canvas.shapes.DeepClone();
|
||||
// 这里先创建一个拷贝
|
||||
newshape = shape.DeepClone();
|
||||
// 判断是否需要对齐
|
||||
startPoint = this.canvas.gridAlign(pointF);
|
||||
// 这里的坐标要转换成虚拟中的坐标
|
||||
var point3 = cantosPointToVirtualPoint(startPoint);
|
||||
// 这个x和y就有了
|
||||
newshape.X = point3.X;
|
||||
newshape.Y = point3.Y;
|
||||
// 然后计算id
|
||||
newshape.ID = this.canvas.shapes.getNextId();
|
||||
Trace.WriteLine($"增加了一个新的图形,id:{newshape.ID}");
|
||||
// 然后添加到图形中
|
||||
this.canvas.addShape(newshape);
|
||||
// 刷新
|
||||
this.canvas.Refresh();
|
||||
|
||||
//base.LeftMouseDown(pointF);
|
||||
}
|
||||
|
||||
public override void LeftMouseMove(PointF pointF)
|
||||
{
|
||||
// 判断是否需要对齐
|
||||
var point2 = cantosPointToVirtualPoint(this.canvas.gridAlign(pointF));
|
||||
strategy.action(newshape, cantosPointToVirtualPoint(startPoint), point2);
|
||||
// 刷新
|
||||
this.canvas.Refresh();
|
||||
base.LeftMouseMove(pointF);
|
||||
}
|
||||
|
||||
public override void LeftMouseUp(PointF pointF)
|
||||
{
|
||||
// 这里有一个特殊的情况,就是宽和高都是0的情况下,会死机
|
||||
|
||||
var point2 = cantosPointToVirtualPoint(this.canvas.gridAlign(pointF));
|
||||
strategy.action(newshape, cantosPointToVirtualPoint(startPoint), point2);
|
||||
newshape.ChangeComplated();
|
||||
|
||||
if (newshape.Width == 0 && newshape.Height == 0)
|
||||
{
|
||||
this.canvas.deleteShapes(newshape);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 更改成选择模式
|
||||
this.canvas.state = new StateSelected(this.canvas);
|
||||
// 需要发送命令
|
||||
this.canvas.commandRecorder.addCommand(
|
||||
new Command.CommandShapesChanged()
|
||||
{
|
||||
canvas=this.canvas,
|
||||
OldShapes = this.oldShapes,
|
||||
NewShapes = this.canvas.shapes.DeepClone()
|
||||
}
|
||||
) ;
|
||||
// 这里还是发出改变通知
|
||||
this.canvas.changeSelect(newshape);
|
||||
}
|
||||
|
||||
//base.LeftMouseUp(pointF);
|
||||
// 刷新
|
||||
this.canvas.Refresh();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
73
LibShapes/Core/State/StateSelected.cs
Normal file
73
LibShapes/Core/State/StateSelected.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using Io.Github.Kerwinxu.LibShapes.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.State
|
||||
{
|
||||
|
||||
|
||||
public class StateSelected:State
|
||||
{
|
||||
public StateSelected(UserControlCanvas canvas, PointF start_pointF) : base(canvas, start_pointF)
|
||||
{
|
||||
|
||||
}
|
||||
public StateSelected(UserControlCanvas canvas) : base(canvas)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void LeftMouseDown(PointF pointF)
|
||||
{
|
||||
// 首先判断一下是否在这个选择矩形的范围内
|
||||
// 在的话就是更改模式了,比如更改尺寸和移动。我这个在选择框上是更改尺寸,而在内部是移动
|
||||
// 如果不在,就转成待机模式
|
||||
// 1. 这里判断一下是否在矩形框的范围内
|
||||
GraphicsPath path = new GraphicsPath();
|
||||
// 这里要判断一下是否是ShapeMultiSelect
|
||||
if (this.canvas.SelectShape is Shape.ShapeMultiSelect)
|
||||
{
|
||||
// 那么最简单的方式是取消所有的选择,然后运行待机模式的选择
|
||||
this.canvas.changeSelect(null);
|
||||
this.canvas.state = new StateStandby(this.canvas);
|
||||
this.canvas.state.LeftMouseDown(pointF);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果选择的图形是其他类型
|
||||
// 看看是否被选择了吧。
|
||||
var rect = this.canvas.SelectShape.GetBounds(this.canvas.shapes.GetMatrix());
|
||||
// 放大范围,
|
||||
// 这里根据宽度和高度的情况酌情放大范围
|
||||
float select_tolerance = 1;
|
||||
if (rect.Width < 4 || rect.Height < 4) select_tolerance = Math.Min(rect.Height, rect.Width) / 4;
|
||||
|
||||
rect.X -= select_tolerance;
|
||||
rect.Y -= select_tolerance;
|
||||
rect.Width += select_tolerance * 2;
|
||||
rect.Height += select_tolerance * 2;
|
||||
path.AddRectangle(rect);
|
||||
// 判断是否
|
||||
if (path.IsVisible(pointF))
|
||||
{
|
||||
this.canvas.state = new StateChanging(this.canvas, pointF);
|
||||
this.canvas.state.LeftMouseDown(pointF);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 转成待机模式
|
||||
this.canvas.changeSelect(null);
|
||||
this.canvas.state = new StateStandby(this.canvas);
|
||||
this.canvas.state.LeftMouseDown(pointF);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//base.LeftMouseDown(pointF);
|
||||
}
|
||||
}
|
||||
}
|
||||
45
LibShapes/Core/State/StateStandby.cs
Normal file
45
LibShapes/Core/State/StateStandby.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Io.Github.Kerwinxu.LibShapes.Core.State
|
||||
{
|
||||
public class StateStandby : State
|
||||
{
|
||||
|
||||
public StateStandby(UserControlCanvas canvas, PointF start_pointF):base(canvas,start_pointF)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public StateStandby(UserControlCanvas canvas) : base(canvas)
|
||||
{
|
||||
this.canvas.changeSelect(null);// null表示没有选择,然后就是纸张。
|
||||
}
|
||||
|
||||
public override void LeftMouseDown(PointF pointF)
|
||||
{
|
||||
// 首先看看是否有选择的图形
|
||||
var shape = this.canvas.shapes.getSelectShape(pointF);
|
||||
if (shape != null)
|
||||
{
|
||||
this.canvas.changeSelect(shape); // 选择这个
|
||||
this.canvas.state = new StateSelected(this.canvas, pointF); // 改变状态
|
||||
this.canvas.state.LeftMouseDown(pointF); // 调用他的处理
|
||||
}
|
||||
else
|
||||
{
|
||||
this.canvas.changeSelect(null);
|
||||
this.canvas.state = new ShapeRectSelect(this.canvas, pointF);
|
||||
this.canvas.state.LeftMouseDown(pointF);
|
||||
}
|
||||
|
||||
this.canvas.Refresh();
|
||||
//base.LeftMouseDown(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user