diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs b/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs index 4fff4f1..e8c4365 100644 --- a/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs +++ b/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs @@ -55,6 +55,8 @@ namespace JoyD.Windows.CS private int _currentBrushSize = 1; // 默认画笔大小为1像素 // 温差图绘制相关变量 private Point _lastDrawPoint = Point.Empty; // 上一个绘制点的位置 + private bool _isDrawingRectangle = false; // 是否正在绘制矩形 + private Point _rectangleStartPoint = Point.Empty; // 矩形起始点 public Setting() { @@ -599,6 +601,22 @@ namespace JoyD.Windows.CS // 退出温差图绘制状态,返回到就绪状态 ExitTempDiffDrawingMode(); } + // 温差图绘制模式下,按住Ctrl键并按下左键开始绘制矩形 + else if (_isTempDiffDrawingMode && e.Button == MouseButtons.Left && (ModifierKeys & Keys.Control) == Keys.Control) + { + // 初始化温差层图像(如果不存在或尺寸不匹配) + if (_tempDiffOverlayImage == null || + _tempDiffOverlayImage.Width != picBoxTemp.Image.Width || + _tempDiffOverlayImage.Height != picBoxTemp.Image.Height) + { + InitializeTempDiffOverlayImage(); + } + + // 获取相对于图像的坐标作为矩形起始点 + _rectangleStartPoint = ControlPointToImagePoint(e.Location); + _isDrawingRectangle = true; + return; + } // 检查是否处于绘制状态且右击鼠标 else if (_isDrawingMode && e.Button == MouseButtons.Right) { @@ -1189,8 +1207,52 @@ namespace JoyD.Windows.CS catch {} } - // 如果按下鼠标左键,执行绘制操作 - if (e.Button == MouseButtons.Left && picBoxTemp.Image != null) + // 处理矩形绘制(按住Ctrl键) + if (_isDrawingRectangle && e.Button == MouseButtons.Left && picBoxTemp.Image != null) + { + // 获取相对于图像的当前坐标 + Point currentImagePoint = ControlPointToImagePoint(e.Location); + + // 创建临时位图用于双重缓冲,避免闪烁 + using (Bitmap tempBitmap = new Bitmap(_tempDiffOverlayImage)) + { + using (Graphics g = Graphics.FromImage(tempBitmap)) + { + g.SmoothingMode = SmoothingMode.AntiAlias; + g.InterpolationMode = InterpolationMode.HighQualityBicubic; + + // 计算矩形参数 + int x = Math.Min(_rectangleStartPoint.X, currentImagePoint.X); + int y = Math.Min(_rectangleStartPoint.Y, currentImagePoint.Y); + int width = Math.Abs(currentImagePoint.X - _rectangleStartPoint.X); + int height = Math.Abs(currentImagePoint.Y - _rectangleStartPoint.Y); + Rectangle rect = new Rectangle(x, y, width, height); + + // 创建半透明的填充颜色 + Color fillColor = Color.FromArgb(128, selectedColor); + + // 绘制填充矩形 + g.FillRectangle(new SolidBrush(fillColor), rect); + + // 绘制矩形边框 + using (Pen pen = new Pen(selectedColor, _currentBrushSize)) + { + g.DrawRectangle(pen, rect); + } + } + + // 将临时位图复制回温差层图像 + using (Graphics g = Graphics.FromImage(_tempDiffOverlayImage)) + { + g.DrawImage(tempBitmap, 0, 0); + } + } + + // 触发重绘 + picBoxTemp.Invalidate(); + } + // 普通绘制操作(未按住Ctrl键) + else if (e.Button == MouseButtons.Left && !_isDrawingRectangle && picBoxTemp.Image != null) { // 初始化温差层图像(如果不存在或尺寸不匹配) if (_tempDiffOverlayImage == null || @@ -1519,10 +1581,16 @@ namespace JoyD.Windows.CS /// private void PicBoxTemp_MouseUp(object sender, MouseEventArgs e) { - // 在温差图绘制模式下,松开鼠标时重置上一个绘制点 + // 在温差图绘制模式下,松开鼠标时重置绘制状态 if (_isTempDiffDrawingMode) { _lastDrawPoint = Point.Empty; + // 结束矩形绘制 + if (_isDrawingRectangle) + { + _isDrawingRectangle = false; + _rectangleStartPoint = Point.Empty; + } } // 结束调整大小