diff --git a/CHANGELOG.md b/CHANGELOG.md
index adac126..7269e32 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,10 @@
# 更新日志
+## 4.0.3
+
+- 优化 截图时的编辑体验
+- 修复 截图出错 [#6](/~https://github.com/hyjiacan/ColorWanted/issues/6)
+
## 4.0.2
- 优化 错误报告信息中添加异常类型
diff --git a/ColorWanted/Properties/AssemblyInfo.cs b/ColorWanted/Properties/AssemblyInfo.cs
index 223028d..f2e76d0 100644
--- a/ColorWanted/Properties/AssemblyInfo.cs
+++ b/ColorWanted/Properties/AssemblyInfo.cs
@@ -31,5 +31,5 @@
// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("4.0.2")]
-[assembly: AssemblyFileVersion("4.0.2")]
+[assembly: AssemblyVersion("4.0.3")]
+[assembly: AssemblyFileVersion("4.0.3")]
diff --git a/ColorWanted/bin/Release/ColorWanted.exe b/ColorWanted/bin/Release/ColorWanted.exe
index 8732a24..d8f7f4e 100644
Binary files a/ColorWanted/bin/Release/ColorWanted.exe and b/ColorWanted/bin/Release/ColorWanted.exe differ
diff --git a/ColorWanted/ext/GraphicsExtension.cs b/ColorWanted/ext/GraphicsExtension.cs
index 59acbc6..4103528 100644
--- a/ColorWanted/ext/GraphicsExtension.cs
+++ b/ColorWanted/ext/GraphicsExtension.cs
@@ -27,7 +27,7 @@ public static void Draw(this Graphics graphics, DrawRecord record)
{
case DrawShapes.Curve:
pen.EndCap = LineCap.Round;
- graphics.DrawCurve(pen, record.Points.Select(p=>new Point((int)p.X, (int)p.Y)).ToArray());
+ graphics.DrawCurve(pen, record.Points.Select(p => new Point((int)p.X, (int)p.Y)).ToArray());
break;
case DrawShapes.Ellipse:
graphics.DrawEllipse(pen, record.Rect.ToDrawingRectangle());
@@ -44,11 +44,27 @@ public static void Draw(this Graphics graphics, DrawRecord record)
{
return;
}
- graphics.DrawString(record.Text, record.TextFont,
+ graphics.DrawString(record.Text, record.TextFont,
new SolidBrush(record.Color.ToDrawingColor()), record.Start.ToDrawingPoint());
break;
case DrawShapes.Arrow:
- var cap = new AdjustableArrowCap(5, 5, false);
+ int arrowSize;
+ switch (record.Distance)
+ {
+ case 5:
+ case 4:
+ arrowSize = 2;
+ break;
+ case 3:
+ case 2:
+ case 1:
+ arrowSize = 1;
+ break;
+ default:
+ arrowSize = 5;
+ break;
+ }
+ var cap = new AdjustableArrowCap(arrowSize, arrowSize, false);
pen.CustomEndCap = cap;
graphics.DrawLine(pen, record.Start.ToDrawingPoint(), record.End.ToDrawingPoint());
break;
diff --git a/ColorWanted/screenshot/DrawRecord.cs b/ColorWanted/screenshot/DrawRecord.cs
index 8975b25..a50e183 100644
--- a/ColorWanted/screenshot/DrawRecord.cs
+++ b/ColorWanted/screenshot/DrawRecord.cs
@@ -161,7 +161,21 @@ public FrameworkElement GetElement()
StrokeLineJoin = PenLineJoin.Bevel
};
}
- ((Polygon)shape).Points = new PointCollection(MakePolygon(Start.X, Start.Y, End.X, End.Y));
+ double arrowSize;
+ var distance = Distance;
+ if (distance >= 60)
+ {
+ arrowSize = 20;
+ }
+ else if (distance >= 32)
+ {
+ arrowSize = distance / 4.0;
+ }
+ else
+ {
+ arrowSize = 8;
+ }
+ ((Polygon)shape).Points = new PointCollection(MakeArrow(Start.X, Start.Y, End.X, End.Y, arrowLength: arrowSize));
shape.Fill = new SolidColorBrush(Color);
break;
case DrawShapes.Text:
@@ -208,7 +222,7 @@ public FrameworkElement GetElement()
return shape;
}
- private Point[] MakePolygon(double x1, double y1, double x2, double y2, double arrowAngle = Math.PI / 12, double arrowLength = 20)
+ private Point[] MakeArrow(double x1, double y1, double x2, double y2, double arrowAngle = Math.PI / 12, double arrowLength = 20)
{
Point point1 = new Point(x1, y1); // 箭头起点
Point point2 = new Point(x2, y2); // 箭头终点
@@ -216,10 +230,10 @@ private Point[] MakePolygon(double x1, double y1, double x2, double y2, double a
double angleDown = angleOri - arrowAngle; // 箭头扩张角度
double angleUp = angleOri + arrowAngle; // 箭头扩张角度
int directionFlag = (x2 > x1) ? -1 : 1; // 方向标识
- double x3 = x2 + ((directionFlag * arrowLength) * Math.Cos(angleDown)); // 箭头第三个点的坐标
- double y3 = y2 + ((directionFlag * arrowLength) * Math.Sin(angleDown));
- double x4 = x2 + ((directionFlag * arrowLength) * Math.Cos(angleUp)); // 箭头第四个点的坐标
- double y4 = y2 + ((directionFlag * arrowLength) * Math.Sin(angleUp));
+ double x3 = x2 + (directionFlag * arrowLength * Math.Cos(angleDown)); // 箭头第三个点的坐标
+ double y3 = y2 + (directionFlag * arrowLength * Math.Sin(angleDown));
+ double x4 = x2 + (directionFlag * arrowLength * Math.Cos(angleUp)); // 箭头第四个点的坐标
+ double y4 = y2 + (directionFlag * arrowLength * Math.Sin(angleUp));
Point point3 = new Point(x3, y3); // 箭头第三个点
Point point4 = new Point(x4, y4); // 箭头第四个点
return new Point[] { point1, point2, point3, point4, point2 }; // 多边形,起点 --> 终点 --> 第三点 --> 第四点 --> 终点
@@ -299,7 +313,7 @@ public Rect ElementRect
///
/// 起点与终点的距离
///
- public int Distance => (int)Math.Sqrt(Math.Abs(Start.X - End.X) * Math.Abs(Start.X - End.X) + Math.Abs(Start.Y - End.Y) * Math.Abs(Start.Y - End.Y));
+ public int Distance => (int)Math.Sqrt((Math.Abs(Start.X - End.X) * Math.Abs(Start.X - End.X)) + Math.Abs(Start.Y - End.Y) * Math.Abs(Start.Y - End.Y));
public DrawRecord()
{
diff --git a/ColorWanted/screenshot/ExtendedCanvas.cs b/ColorWanted/screenshot/ExtendedCanvas.cs
index ed0b38a..e12ed5b 100644
--- a/ColorWanted/screenshot/ExtendedCanvas.cs
+++ b/ColorWanted/screenshot/ExtendedCanvas.cs
@@ -103,8 +103,8 @@ private void EmitDrawEvent(DrawState state, bool isEmpty = false)
private void BindEvent()
{
MouseLeftButtonDown += OnMouseLeftButtonDown;
- MouseLeftButtonUp += ExtendedCanvas_MouseLeaveOrUp;
- MouseLeave += ExtendedCanvas_MouseLeaveOrUp; ;
+ MouseLeftButtonUp += ExtendedCanvas_MouseUp;
+ MouseLeave += ExtendedCanvas_MouseLeave; ;
MouseMove += OnMouseMove;
MouseRightButtonDown += On_MouseRightButtonDown;
}
@@ -237,7 +237,7 @@ private void OnMouseLeftButtonDown(object sender, System.Windows.Input.MouseButt
if (e.ClickCount == 2)
{
// 双击图形,触发双击事件
- AreaDoubleClicked.Invoke(this, new AreaEventArgs(current.Rect));
+ AreaDoubleClicked.Invoke(this, new AreaEventArgs(current.ElementRect));
return;
}
MoveMode = true;
@@ -272,13 +272,18 @@ private void OnMouseLeftButtonDown(object sender, System.Windows.Input.MouseButt
EmitDrawEvent(DrawState.Start);
}
- private void ExtendedCanvas_MouseLeaveOrUp(object sender, System.Windows.Input.MouseEventArgs e)
+ public void ExtendedCanvas_MouseUp(object sender, System.Windows.Input.MouseEventArgs e)
+ {
+ ExtendedCanvas_MouseLeave(sender, e);
+ IsMouseDown = false;
+ }
+
+ private void ExtendedCanvas_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
if (!EditEnabled || !IsMouseDown)
{
return;
}
- IsMouseDown = false;
var point = e.GetPosition(this);
// 保证线不会画出界
@@ -318,7 +323,7 @@ private void ExtendedCanvas_MouseLeaveOrUp(object sender, System.Windows.Input.M
EmitDrawEvent(DrawState.End);
}
- private void OnMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
+ public void OnMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
if (!EditEnabled || !IsMouseDown)
{
@@ -326,6 +331,23 @@ private void OnMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
}
var point = e.GetPosition(this);
+ // 保证线不会画出界
+ if (point.X < 0)
+ {
+ point.X = 0;
+ }
+ else if (point.X > Width)
+ {
+ point.X = Width;
+ }
+ if (point.Y < 0)
+ {
+ point.Y = 0;
+ }
+ else if (point.Y > Height)
+ {
+ point.Y = Height;
+ }
if (MouseDownPoint == point)
{
return;
diff --git a/ColorWanted/screenshot/ImageEditor.xaml b/ColorWanted/screenshot/ImageEditor.xaml
index ffc8eb0..cce2c39 100644
--- a/ColorWanted/screenshot/ImageEditor.xaml
+++ b/ColorWanted/screenshot/ImageEditor.xaml
@@ -9,7 +9,8 @@