diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs b/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs index 87d54db..69b7c70 100644 --- a/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs +++ b/Windows/CS/Framework4.0/Toprie/Toprie/Camera.cs @@ -3110,14 +3110,18 @@ namespace JoyD.Windows.CS.Toprie } } + // 将相对坐标转换为绝对坐标 + int absoluteX = _detectionZone.X + zone.X; + int absoluteY = _detectionZone.Y + zone.Y; + // 创建画刷,使用区域的颜色作为文字颜色 using (Brush brush = new SolidBrush(zone.Color)) { // 绘制温度文本,从区域左上角开始,向下排列 - float currentY = zone.Y + 20; // 从区域编号下方开始 + float currentY = absoluteY + 20; // 从区域编号下方开始,使用绝对坐标 foreach (string text in areaTemperatureTexts) { - PointF textPosition = new PointF(zone.X + 5, currentY); + PointF textPosition = new PointF(absoluteX + 5, currentY); g.DrawString(text, font, brush, textPosition); currentY += 20; // 每行间隔20像素 } diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs b/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs index 9b4d958..9f3b103 100644 --- a/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs +++ b/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs @@ -977,17 +977,55 @@ namespace JoyD.Windows.CS btnModifyDetectionZone.ToolTipText = "修改检测区(点击开启)"; // 保存修改后的检测区配置 - _detectionZone.X = _tempDetectionZone.X; - _detectionZone.Y = _tempDetectionZone.Y; - _detectionZone.Width = _tempDetectionZone.Width; - _detectionZone.Height = _tempDetectionZone.Height; + _detectionZone.X = _tempDetectionZone.X; + _detectionZone.Y = _tempDetectionZone.Y; + _detectionZone.Width = _tempDetectionZone.Width; + _detectionZone.Height = _tempDetectionZone.Height; + _detectionZone.Color = _tempDetectionZone.Color; // 保存颜色 // 恢复叠加层绘制,显示测温区和温差图 CreateRectangleOverlayImage(); - // 更新按钮可见性 - UpdateButtonsVisibility(0); - btnModifyDetectionZone.Visible = true; + // 在检测区修改模式下,只显示相关按钮 + // 隐藏所有与检测区无关的按钮 + btnDrawRegion.Visible = false; // 隐藏绘制区域按钮 + btnDrawTempDiff.Visible = false; // 隐藏温差图按钮 + btnDeleteRegion.Visible = false; // 隐藏删除区域按钮 + + // 隐藏配置相关按钮 + btnNewTempRegion.Visible = false; + btnLoadTempRegion.Visible = false; + btnSaveTempRegion.Visible = false; + btnNewTempDiff.Visible = false; + btnLoadTempDiff.Visible = false; + btnSaveTempDiff.Visible = false; + + // 隐藏温差图例相关按钮 + btnAddTempDiff.Visible = false; + btnDeleteTempDiff.Visible = false; + + // 隐藏擦除按钮 + btnEraseTempDiff.Visible = false; + + // 隐藏所有画笔大小按钮 + btnBrushSize1.Visible = false; + btnBrushSize3.Visible = false; + btnBrushSize5.Visible = false; + btnBrushSize10.Visible = false; + btnBrushSize15.Visible = false; + btnBrushSize25.Visible = false; + + // 隐藏区域编号设置控件 + txtRegionNumber.Visible = false; + txtRegionNumber.Text = ""; + + // 显示修改检测区按钮和颜色选择按钮 + btnModifyDetectionZone.Visible = true; + btnSelectColor.Visible = true; + + // 更新_selectedColor为检测区的颜色,并更新按钮图标 + _selectedColor = _tempDetectionZone.Color; + UpdateColorButtonIcon(); // 刷新绘制 picBoxTemp.Invalidate(); @@ -1087,7 +1125,7 @@ namespace JoyD.Windows.CS } } // 处理选中区域的调整大小或移动 - else if (e.Button == MouseButtons.Left && !_isDrawingMode && _selectedRegionIndex != -1) + else if (e.Button == MouseButtons.Left && !_isDrawingMode && !_isModifyingDetectionZone && _selectedRegionIndex != -1) { RegionInfo selectedRegion = _drawnRectangles.FirstOrDefault(r => r.Index == _selectedRegionIndex); if (selectedRegion != null) @@ -1213,6 +1251,7 @@ namespace JoyD.Windows.CS btnDrawTempDiff.Visible = true; // 显示温差图按钮 btnSelectColor.Visible = false; // 隐藏颜色选择按钮 btnDeleteRegion.Visible = false; // 隐藏删除区域按钮 + btnModifyDetectionZone.Visible = true; // 显示修改检测区按钮 // 根据自动配置状态显示/隐藏六个新按钮 bool showConfigButtons = !_autoConfig; btnNewTempRegion.Visible = showConfigButtons; @@ -1245,6 +1284,7 @@ namespace JoyD.Windows.CS btnDrawRegion.Visible = true; // 显示绘制区域按钮 btnDeleteRegion.Visible = false; // 隐藏删除区域按钮 btnDrawTempDiff.Visible = false; // 隐藏温差图按钮 + btnModifyDetectionZone.Visible = false; // 隐藏修改检测区按钮 dataGridViewTempDiff.Visible = false; // 隐藏温差图例表格 dataGridViewTempDiff.ReadOnly = true; // 绘制状态下设置为只读 btnAddTempDiff.Visible = false; // 隐藏添加温差图例按钮 @@ -1279,6 +1319,7 @@ namespace JoyD.Windows.CS btnDrawTempDiff.Visible = false; // 隐藏温差图按钮 btnSelectColor.Visible = true; // 显示颜色选择按钮 btnDeleteRegion.Visible = true; // 显示删除区域按钮 + btnModifyDetectionZone.Visible = false; // 隐藏修改检测区按钮 dataGridViewTempDiff.Visible = false; // 隐藏温差图例表格 btnAddTempDiff.Visible = false; // 隐藏添加温差图例按钮 btnDeleteTempDiff.Visible = false; // 隐藏删除温差图例按钮 @@ -1317,6 +1358,7 @@ namespace JoyD.Windows.CS btnDrawRegion.Visible = false; // 隐藏绘制区域按钮 btnSelectColor.Visible = false; // 隐藏颜色选择按钮 btnDeleteRegion.Visible = false; // 隐藏删除区域按钮 + btnModifyDetectionZone.Visible = false; // 隐藏修改检测区按钮 dataGridViewTempDiff.Visible = true; // 显示温差图例表格 dataGridViewTempDiff.ReadOnly = false; // 温差图绘制状态下可编辑 btnAddTempDiff.Visible = true; // 显示添加温差图例按钮 @@ -1365,6 +1407,24 @@ namespace JoyD.Windows.CS _isTempDiffDrawingMode = !_isTempDiffDrawingMode; btnDrawTempDiff.Checked = _isTempDiffDrawingMode; + // 确保模式互斥:进入温差图模式前退出检测区修改模式 + if (_isTempDiffDrawingMode && _isModifyingDetectionZone) + { + // 退出检测区修改模式 + _isModifyingDetectionZone = false; + btnModifyDetectionZone.Checked = false; + btnModifyDetectionZone.ToolTipText = "修改检测区(点击开启)"; + + // 恢复叠加层绘制,显示测温区和温差图 + CreateRectangleOverlayImage(); + + // 更新按钮可见性 + UpdateButtonsVisibility(0); + btnModifyDetectionZone.Visible = true; + // 隐藏颜色选择按钮 + btnSelectColor.Visible = false; + } + if (_isTempDiffDrawingMode) { // 进入温差图绘制状态 @@ -1668,12 +1728,39 @@ namespace JoyD.Windows.CS if (_isDrawingMode) { + // 确保模式互斥:进入测温区模式前退出其他模式 + + // 退出温差图模式 + if (_isTempDiffDrawingMode) + { + _isTempDiffDrawingMode = false; + btnDrawTempDiff.Checked = false; + ExitTempDiffDrawingMode(); + } + + // 退出检测区修改模式 + if (_isModifyingDetectionZone) + { + _isModifyingDetectionZone = false; + btnModifyDetectionZone.Checked = false; + btnModifyDetectionZone.ToolTipText = "修改检测区(点击开启)"; + + // 恢复叠加层绘制,显示测温区和温差图 + CreateRectangleOverlayImage(); + + // 更新按钮可见性 + UpdateButtonsVisibility(0); + btnModifyDetectionZone.Visible = true; + // 隐藏颜色选择按钮 + btnSelectColor.Visible = false; + } + // 启用绘制模式 picBoxTemp.Cursor = Cursors.Cross; btnDrawRegion.ToolTipText = "绘制模式已启用,点击图片区域绘制矩形框(点击关闭)"; // 调用按钮可见性更新方法设置为绘制状态 - UpdateButtonsVisibility(2); // 2表示绘制状态 + UpdateButtonsVisibility(2); // 2表示绘制状态 } else { @@ -1685,7 +1772,7 @@ namespace JoyD.Windows.CS picBoxTemp.Invalidate(); // 调用按钮可见性更新方法设置为就绪状态 - UpdateButtonsVisibility(0); // 0表示初始状态/就绪状态 + UpdateButtonsVisibility(0); // 0表示初始状态/就绪状态 } } @@ -2177,7 +2264,7 @@ namespace JoyD.Windows.CS } // 处理调整大小 - if (_isResizing && !_isDrawingMode && _selectedRegionIndex != -1) + if (_isResizing && !_isDrawingMode && !_isModifyingDetectionZone && _selectedRegionIndex != -1) { RegionInfo selectedRegion = _drawnRectangles.FirstOrDefault(r => r.Index == _selectedRegionIndex); if (selectedRegion != null) @@ -2208,7 +2295,7 @@ namespace JoyD.Windows.CS } } // 处理移动区域 - else if (_isMoving && !_isDrawingMode && _selectedRegionIndex != -1) + else if (_isMoving && !_isDrawingMode && !_isModifyingDetectionZone && _selectedRegionIndex != -1) { RegionInfo selectedRegion = _drawnRectangles.FirstOrDefault(r => r.Index == _selectedRegionIndex); if (selectedRegion != null) @@ -2266,8 +2353,43 @@ namespace JoyD.Windows.CS // 处理鼠标悬停(更新光标或检测悬停区域) else if (!_isDrawingMode && !_isDrawing && !_isResizing) // 就绪状态 { - // 如果有选中的区域,检查是否悬停在句柄上 - if (_selectedRegionIndex != -1) + // 检测区修改模式下的鼠标样式处理 + if (_isModifyingDetectionZone) + { + // 将检测区坐标转换为控件坐标 + Rectangle controlDetectionRect = ImageRectangleToControlRectangle(new Rectangle( + _tempDetectionZone.X, + _tempDetectionZone.Y, + _tempDetectionZone.Width, + _tempDetectionZone.Height)); + + // 检测鼠标是否在检测区的某个句柄上 + ResizeHandle hoveredHandle = GetHoveredHandle(controlDetectionRect, e.Location); + + if (hoveredHandle != ResizeHandle.None) + { + // 设置相应的光标 + SetCursorByHandle(hoveredHandle); + _currentDetectionZoneHandle = hoveredHandle; + return; + } + else if (controlDetectionRect.Contains(e.Location)) + { + // 如果鼠标在检测区内但不在句柄上,设置移动光标 + picBoxTemp.Cursor = Cursors.SizeAll; + _currentDetectionZoneHandle = ResizeHandle.None; + return; + } + else + { + // 重置光标 + picBoxTemp.Cursor = Cursors.Default; + _currentDetectionZoneHandle = ResizeHandle.None; + return; + } + } + // 如果有选中的区域,且不在检测区修改模式下,检查是否悬停在句柄上 + if (!_isModifyingDetectionZone && _selectedRegionIndex != -1) { RegionInfo selectedRegion = _drawnRectangles.FirstOrDefault(r => r.Index == _selectedRegionIndex); if (selectedRegion != null) @@ -2289,8 +2411,8 @@ namespace JoyD.Windows.CS } } - // 如果没有悬停在句柄上,检查是否悬停在区域上 - if (_currentHandle == ResizeHandle.None && !_isMoving) + // 如果没有悬停在句柄上,且不在检测区修改模式下,检查是否悬停在区域上 + if (!_isModifyingDetectionZone && _currentHandle == ResizeHandle.None && !_isMoving) { // 将鼠标坐标转换为图像坐标 Point imagePoint = ControlPointToImagePoint(e.Location); @@ -2531,7 +2653,7 @@ namespace JoyD.Windows.CS } // 结束调整大小 - if (_isResizing && e.Button == MouseButtons.Left) + if (_isResizing && !_isModifyingDetectionZone && e.Button == MouseButtons.Left) { _isResizing = false; _currentHandle = ResizeHandle.None; @@ -2548,7 +2670,7 @@ namespace JoyD.Windows.CS return; } // 结束移动区域 - if (_isMoving && e.Button == MouseButtons.Left) + if (_isMoving && !_isModifyingDetectionZone && e.Button == MouseButtons.Left) { _isMoving = false; picBoxTemp.Cursor = Cursors.Default; @@ -2652,7 +2774,7 @@ namespace JoyD.Windows.CS Rectangle controlDetectionRect = ImageRectangleToControlRectangle(detectionRect); // 高亮显示检测区 - using (Pen pen = new Pen(Color.Red, 3)) + using (Pen pen = new Pen(_tempDetectionZone.Color, 3)) { // 设置绘制质量为无抗锯齿,确保边界清晰 e.Graphics.SmoothingMode = SmoothingMode.None; @@ -3388,8 +3510,15 @@ namespace JoyD.Windows.CS // 绘制边框 g.DrawRectangle(new Pen(Color.Black, 1), 3, 3, 18, 18); - // 使用_selectedColor填充矩形 - using (SolidBrush brush = new SolidBrush(_selectedColor)) + // 根据当前模式选择颜色 + Color displayColor = _selectedColor; + if (_isModifyingDetectionZone) + { + displayColor = _tempDetectionZone.Color; + } + + // 使用选择的颜色填充矩形 + using (SolidBrush brush = new SolidBrush(displayColor)) { g.FillRectangle(brush, 4, 4, 16, 16); } @@ -3414,8 +3543,15 @@ namespace JoyD.Windows.CS { using (ColorDialog colorDialog = new ColorDialog()) { - // 设置初始颜色为当前选中的颜色 - colorDialog.Color = _selectedColor; + // 根据当前模式设置初始颜色 + if (_isModifyingDetectionZone) + { + colorDialog.Color = _tempDetectionZone.Color; + } + else + { + colorDialog.Color = _selectedColor; + } // 允许自定义颜色 colorDialog.AllowFullOpen = true; @@ -3430,8 +3566,13 @@ namespace JoyD.Windows.CS // 更新按钮图标,显示新选择的颜色 UpdateColorButtonIcon(); + // 检测区修改模式下,更新检测区的颜色 + if (_isModifyingDetectionZone) + { + _tempDetectionZone.Color = _selectedColor; + } // 如果有区域被选中,更新该区域的颜色 - if (_selectedRegionIndex != -1) + else if (_selectedRegionIndex != -1) { RegionInfo selectedRegion = _drawnRectangles.FirstOrDefault(r => r.Index == _selectedRegionIndex); if (selectedRegion != null) @@ -3442,7 +3583,7 @@ namespace JoyD.Windows.CS } } - // 重绘图片区域,显示新颜色的矩形 + // 重绘图片区域,显示新颜色的矩形或检测区 picBoxTemp.Invalidate(); } } @@ -4851,6 +4992,29 @@ namespace JoyD.Windows.CS _isModifyingDetectionZone = !_isModifyingDetectionZone; btnModifyDetectionZone.Checked = _isModifyingDetectionZone; + // 确保模式互斥:进入检测区修改模式前退出其他模式 + if (_isModifyingDetectionZone) + { + // 退出温差图模式 + if (_isTempDiffDrawingMode) + { + _isTempDiffDrawingMode = false; + btnDrawTempDiff.Checked = false; + ExitTempDiffDrawingMode(); + } + + // 退出测温区模式(绘制状态) + if (_isDrawingMode || _isDrawing) + { + _isDrawingMode = false; + _isDrawing = false; + btnDrawRegion.Checked = false; + btnDrawRegion.ToolTipText = "绘制区域(点击开启)"; + UpdateButtonsVisibility(0); + picBoxTemp.Invalidate(); + } + } + if (_isModifyingDetectionZone) { // 进入修改模式 @@ -4888,9 +5052,42 @@ namespace JoyD.Windows.CS // 隐藏温差图例表格 dataGridViewTempDiff.Visible = false; - // 更新按钮可见性 - UpdateButtonsVisibility(0); + // 在检测区修改模式下,只显示相关按钮 + // 隐藏所有与检测区无关的按钮 + btnDrawRegion.Visible = false; // 隐藏绘制区域按钮 + btnDrawTempDiff.Visible = false; // 隐藏温差图按钮 + btnDeleteRegion.Visible = false; // 隐藏删除区域按钮 + + // 隐藏配置相关按钮 + btnNewTempRegion.Visible = false; + btnLoadTempRegion.Visible = false; + btnSaveTempRegion.Visible = false; + btnNewTempDiff.Visible = false; + btnLoadTempDiff.Visible = false; + btnSaveTempDiff.Visible = false; + + // 隐藏温差图例相关按钮 + btnAddTempDiff.Visible = false; + btnDeleteTempDiff.Visible = false; + + // 隐藏擦除按钮 + btnEraseTempDiff.Visible = false; + + // 隐藏所有画笔大小按钮 + btnBrushSize1.Visible = false; + btnBrushSize3.Visible = false; + btnBrushSize5.Visible = false; + btnBrushSize10.Visible = false; + btnBrushSize15.Visible = false; + btnBrushSize25.Visible = false; + + // 隐藏区域编号设置控件 + txtRegionNumber.Visible = false; + txtRegionNumber.Text = ""; + + // 显示修改检测区按钮和颜色选择按钮 btnModifyDetectionZone.Visible = true; + btnSelectColor.Visible = true; } else { @@ -4909,6 +5106,8 @@ namespace JoyD.Windows.CS // 更新按钮可见性 UpdateButtonsVisibility(0); btnModifyDetectionZone.Visible = true; + // 隐藏颜色选择按钮 + btnSelectColor.Visible = false; } // 刷新绘制