diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs b/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs index eb0deb2..7c328ef 100644 --- a/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs +++ b/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs @@ -1375,6 +1375,49 @@ namespace JoyD.Windows.CS } } + /// + /// 在两点之间绘制方形路径,用于模拟方形画笔效果 + /// + private void DrawLineAsRectangles(Graphics g, Brush brush, Point startPoint, Point endPoint, int halfSize) + { + // 计算两点之间的距离和方向 + int dx = Math.Abs(endPoint.X - startPoint.X); + int dy = Math.Abs(endPoint.Y - startPoint.Y); + int sx = startPoint.X < endPoint.X ? 1 : -1; + int sy = startPoint.Y < endPoint.Y ? 1 : -1; + int err = dx - dy; + int e2; + + Point currentPoint = startPoint; + + // 使用Bresenham算法遍历直线上的每个点 + while (true) + { + // 在当前点绘制方形 + g.FillRectangle(brush, + currentPoint.X - halfSize, + currentPoint.Y - halfSize, + halfSize * 2, + halfSize * 2); + + // 检查是否到达终点 + if (currentPoint.X == endPoint.X && currentPoint.Y == endPoint.Y) + break; + + e2 = 2 * err; + if (e2 > -dy) + { + err -= dy; + currentPoint.X += sx; + } + if (e2 < dx) + { + err += dx; + currentPoint.Y += sy; + } + } + } + /// /// 将控件坐标转换为图像坐标 /// @@ -1660,23 +1703,22 @@ namespace JoyD.Windows.CS if (_lastDrawPoint == Point.Empty) { _lastDrawPoint = imagePoint; - // 绘制起始点的圆形(擦除区域) - int radius = adjustedBrushSize / 2; - g.FillEllipse(Brushes.Transparent, - imagePoint.X - radius, - imagePoint.Y - radius, + // 绘制起始点的方形(擦除区域) + int halfSize = adjustedBrushSize / 2; + g.FillRectangle(Brushes.Transparent, + imagePoint.X - halfSize, + imagePoint.Y - halfSize, adjustedBrushSize, adjustedBrushSize); } else { - // 使用透明色绘制粗线条进行擦除,使用调整后的画笔大小 - using (Pen pen = new Pen(Color.Transparent, adjustedBrushSize)) - { - pen.StartCap = LineCap.Round; - pen.EndCap = LineCap.Round; - pen.LineJoin = LineJoin.Round; - g.DrawLine(pen, _lastDrawPoint, imagePoint); + // 绘制方形路径进行擦除 + int halfSize = adjustedBrushSize / 2; + using (SolidBrush brush = new SolidBrush(Color.Transparent)) + { + // 计算两点之间的直线区域,并绘制方形 + DrawLineAsRectangles(g, brush, _lastDrawPoint, imagePoint, halfSize); } // 更新上一个点 _lastDrawPoint = imagePoint; @@ -1698,18 +1740,23 @@ namespace JoyD.Windows.CS if (_lastDrawPoint == Point.Empty) { _lastDrawPoint = imagePoint; - // 绘制起始点的圆形 - int radius = _currentBrushSize / 2; - g.FillEllipse(new SolidBrush(selectedColor), - imagePoint.X - radius, - imagePoint.Y - radius, + // 绘制起始点的方形 + int halfSize = _currentBrushSize / 2; + g.FillRectangle(new SolidBrush(selectedColor), + imagePoint.X - halfSize, + imagePoint.Y - halfSize, _currentBrushSize, _currentBrushSize); } else { - // 绘制连线 - g.DrawLine(pen, _lastDrawPoint, imagePoint); + // 绘制方形路径 + int halfSize = _currentBrushSize / 2; + using (SolidBrush brush = new SolidBrush(selectedColor)) + { + // 计算两点之间的直线区域,并绘制方形 + DrawLineAsRectangles(g, brush, _lastDrawPoint, imagePoint, halfSize); + } // 更新上一个点 _lastDrawPoint = imagePoint; } @@ -2882,9 +2929,9 @@ namespace JoyD.Windows.CS adjustedBrushSize = Math.Min(adjustedBrushSize, 50); // 最大50像素 } - // 绘制擦除区域(圆形) - int radius = adjustedBrushSize / 2; - g.FillEllipse(Brushes.Transparent, imagePoint.X - radius, imagePoint.Y - radius, adjustedBrushSize, adjustedBrushSize); + // 绘制擦除区域(方形) + int halfSize = adjustedBrushSize / 2; + g.FillRectangle(Brushes.Transparent, imagePoint.X - halfSize, imagePoint.Y - halfSize, adjustedBrushSize, adjustedBrushSize); // 恢复CompositingMode为默认值 g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; @@ -2927,11 +2974,11 @@ namespace JoyD.Windows.CS adjustedBrushSize = Math.Min(adjustedBrushSize, 50); // 最大50像素 } - // 绘制区域(圆形) - int radius = adjustedBrushSize / 2; + // 绘制区域(方形) + int halfSize = adjustedBrushSize / 2; using (SolidBrush brush = new SolidBrush(selectedColor)) { - g.FillEllipse(brush, imagePoint.X - radius, imagePoint.Y - radius, adjustedBrushSize, adjustedBrushSize); + g.FillRectangle(brush, imagePoint.X - halfSize, imagePoint.Y - halfSize, adjustedBrushSize, adjustedBrushSize); } } }