From 3971b6801149f601eaebbfbd161aa7dc5e34b6a7 Mon Sep 17 00:00:00 2001 From: zqm Date: Wed, 25 Mar 2026 16:37:52 +0800 Subject: [PATCH] =?UTF-8?q?led=E5=8C=BA=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CS/Framework4.0/Camera/Camera/Setting.cs | 75 ++++++++++--------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/Windows/CS/Framework4.0/Camera/Camera/Setting.cs b/Windows/CS/Framework4.0/Camera/Camera/Setting.cs index 1855998..7aa05f2 100644 --- a/Windows/CS/Framework4.0/Camera/Camera/Setting.cs +++ b/Windows/CS/Framework4.0/Camera/Camera/Setting.cs @@ -23,6 +23,7 @@ namespace Camera private Rectangle _originalZone; private bool _isEditingDetectionZone = false; private bool _isEditingLedZone = false; + private bool _isDrawingLedMode = false; private int _ledZoneState = 0; private Color _detectionZoneColor = Color.Black; private ConcurrentDictionary _ledZoneColors = new ConcurrentDictionary(); @@ -240,8 +241,8 @@ namespace Camera if (_camera != null) { - var ledZones = _camera.GetLedZones(); - foreach (var kvp in ledZones) + var allLedZones = _camera.GetLedZones(); + foreach (var kvp in allLedZones) { int index = kvp.Key; Rectangle ledZone = kvp.Value; @@ -317,7 +318,7 @@ namespace Camera isEditing = true; editColor = _detectionZoneColor; } - else if (_isEditingLedZone && _currentLedIndex >= 0) + else if ((_isEditingLedZone || _isDrawingLedMode) && _currentLedIndex >= 0) { Rectangle ledZone = _camera.GetLedZone(_currentLedIndex); currentEditZone = new Rectangle( @@ -330,7 +331,7 @@ namespace Camera editColor = _camera.GetLedZoneColor(_currentLedIndex); } - if (_isDrawing && _isEditingLedZone && _startPoint != null && _currentMousePoint != null) + if (_isDrawing && (_isEditingLedZone || _isDrawingLedMode) && _startPoint != null && _currentMousePoint != null) { using (Pen pen = new Pen(_detectionZoneColor, 2)) { @@ -354,7 +355,7 @@ namespace Camera } } } - else if (_isEditingLedZone && _currentLedIndex >= 0) + else if ((_isEditingLedZone || _isDrawingLedMode) && _currentLedIndex >= 0) { using (Pen pen = new Pen(_detectionZoneColor, 2)) { @@ -362,8 +363,8 @@ namespace Camera g.DrawRectangle(pen, scaledDetectionZone); } - var ledZones = _camera.GetLedZones(); - foreach (var kvp in ledZones) + var allLedZones = _camera.GetLedZones(); + foreach (var kvp in allLedZones) { int index = kvp.Key; Rectangle ledZone = kvp.Value; @@ -416,8 +417,8 @@ namespace Camera if (_camera != null) { - var ledZones = _camera.GetLedZones(); - foreach (var kvp in ledZones) + var allLedZones = _camera.GetLedZones(); + foreach (var kvp in allLedZones) { int index = kvp.Key; Rectangle ledZone = kvp.Value; @@ -517,11 +518,11 @@ namespace Camera (int)(detectionZone.Height * scaleY) ); - var ledZones = _camera.GetLedZones(); + var allLedZones = _camera.GetLedZones(); bool clickedOnLedZone = false; int clickedLedIndex = -1; - foreach (var kvp in ledZones) + foreach (var kvp in allLedZones) { Rectangle led = kvp.Value; Rectangle scaledLed = new Rectangle( @@ -533,14 +534,14 @@ namespace Camera if (scaledLed.Width > 0 && scaledLed.Height > 0 && scaledLed.Contains(controlPoint)) { - if (!_isEditingDetectionZone && !_isEditingLedZone) + if (!_isEditingDetectionZone && !_isEditingLedZone && !_isDrawingLedMode) { clickedOnLedZone = true; clickedLedIndex = kvp.Key; ledZone = led; break; } - else if (_isEditingLedZone) + else if (_isEditingLedZone || _isDrawingLedMode) { clickedOnLedZone = true; clickedLedIndex = kvp.Key; @@ -553,10 +554,10 @@ namespace Camera if (clickedOnLedZone) { _isEditingLedZone = true; + _isDrawingLedMode = false; _currentLedIndex = clickedLedIndex; _selectedZoneIndex = clickedLedIndex; - _ledZoneState = 1; // 选中状态 - toolStripButton2.Checked = true; + toolStripButton2.Checked = false; toolStripButton2.Visible = false; toolStripButton1.Visible = false; UpdateLedZoneButtonsVisibility(1); @@ -565,12 +566,13 @@ namespace Camera _startPoint = imagePoint; _resizeStartPoint = controlPoint; _originalZone = ledZone; + _isDrawing = false; picBoxCamera.Invalidate(); return; } Rectangle scaledLedZone = new Rectangle(0, 0, 0, 0); - if (_isEditingLedZone && _currentLedIndex >= 0) + if ((_isEditingLedZone || _isDrawingLedMode) && _currentLedIndex >= 0) { Rectangle led = _camera.GetLedZone(_currentLedIndex); scaledLedZone = new Rectangle( @@ -581,7 +583,7 @@ namespace Camera ); } - if (_isEditingDetectionZone || _isEditingLedZone) + if (_isEditingDetectionZone || _isEditingLedZone || _isDrawingLedMode) { Rectangle editRect = _isEditingDetectionZone ? scaledDetectionZone : scaledLedZone; _hoveredHandle = GetHoveredHandle(editRect, controlPoint); @@ -599,13 +601,14 @@ namespace Camera _resizeStartPoint = controlPoint; _originalZone = _isEditingDetectionZone ? detectionZone : ledZone; } - else if (_isEditingLedZone) + else if (_isDrawingLedMode) { _currentLedIndex = -1; _selectedZoneIndex = -1; - _ledZoneState = 2; // 切换到绘制状态 + _isDrawing = true; + _startPoint = imagePoint; + _resizeStartPoint = controlPoint; UpdateLedZoneButtonsVisibility(2); - picBoxCamera.Invalidate(); } } else @@ -672,7 +675,7 @@ namespace Camera ); } - if (_isEditingDetectionZone || _isEditingLedZone) + if (_isEditingDetectionZone || _isEditingLedZone || _isDrawingLedMode) { Rectangle editRect = _isEditingDetectionZone ? scaledDetectionZone : scaledLedZone; int handle = GetHoveredHandle(editRect, e.Location); @@ -702,7 +705,7 @@ namespace Camera { _camera.SetDetectionZone(newZone); } - else + else if (_isEditingLedZone) { _camera.SetLedZone(_currentLedIndex, newZone); } @@ -731,7 +734,7 @@ namespace Camera { _camera.SetDetectionZone(newZone); } - else + else if (_isEditingLedZone) { _camera.SetLedZone(_currentLedIndex, newZone); } @@ -803,14 +806,15 @@ namespace Camera picBoxCamera.Invalidate(); return; } - if (_isEditingLedZone) + if (_isDrawingLedMode || _isEditingLedZone) { + _isDrawingLedMode = false; _isEditingLedZone = false; _isMoving = false; _isResizing = false; _currentLedIndex = -1; _selectedZoneIndex = -1; - _ledZoneState = 0; // 就绪状态 + _isDrawing = false; toolStripButton2.Checked = false; toolStripButton2.ToolTipText = "绘制Led区(点击开启)"; toolStripButton1.Visible = true; @@ -847,14 +851,14 @@ namespace Camera if (width > 10 && height > 10) { - if (toolStripButton2.Checked) + if (_isDrawingLedMode) { int newIndex = _camera.GetLedZoneCount() + 1; _camera.AddLedZone(newIndex, new Rectangle(x, y, width, height), Color.Lime); _selectedZoneIndex = newIndex; _currentLedIndex = newIndex; _isEditingLedZone = true; - _ledZoneState = 1; // 选中状态 + _isDrawingLedMode = true; UpdateLedZoneButtonsVisibility(1); UpdateColorButtonIcon(); } @@ -1007,11 +1011,10 @@ namespace Camera { if (toolStripButton2.Checked) { - _isEditingLedZone = true; + _isDrawingLedMode = true; _isEditingDetectionZone = false; _selectedZoneIndex = -1; _currentLedIndex = -1; - _ledZoneState = 2; // 绘制状态 toolStripButton2.ToolTipText = "绘制Led区(点击关闭)"; toolStripButton1.Checked = false; toolStripButton1.Visible = false; @@ -1021,13 +1024,14 @@ namespace Camera } else { + _isDrawingLedMode = false; _isEditingLedZone = false; _currentLedIndex = -1; _selectedZoneIndex = -1; - _ledZoneState = 0; // 就绪状态 toolStripButton2.ToolTipText = "绘制Led区(点击开启)"; toolStripButton1.Visible = true; UpdateLedZoneButtonsVisibility(0); + _isDrawing = false; } picBoxCamera.Invalidate(); UpdateDataGridView(); @@ -1042,7 +1046,7 @@ namespace Camera { colorDialog.Color = _detectionZoneColor; } - else if (_isEditingLedZone && _currentLedIndex >= 0) + else if ((_isEditingLedZone || _isDrawingLedMode) && _currentLedIndex >= 0) { colorDialog.Color = _camera.GetLedZoneColor(_currentLedIndex); } @@ -1053,7 +1057,7 @@ namespace Camera { _detectionZoneColor = colorDialog.Color; } - else if (_isEditingLedZone && _currentLedIndex >= 0) + else if ((_isEditingLedZone || _isDrawingLedMode) && _currentLedIndex >= 0) { _camera.SetLedZoneColor(_currentLedIndex, colorDialog.Color); } @@ -1065,13 +1069,13 @@ namespace Camera private void ToolStripButton4_Click(object sender, EventArgs e) { - if (_isEditingLedZone && _currentLedIndex >= 0) + if ((_isEditingLedZone || _isDrawingLedMode) && _currentLedIndex >= 0) { _camera.RemoveLedZone(_currentLedIndex); _currentLedIndex = -1; _selectedZoneIndex = -1; _isEditingLedZone = false; - _ledZoneState = 0; // 就绪状态 + _isDrawingLedMode = false; toolStripButton2.Checked = false; toolStripButton2.Visible = true; toolStripButton2.ToolTipText = "绘制Led区(点击开启)"; @@ -1089,7 +1093,7 @@ namespace Camera { currentColor = _detectionZoneColor; } - else if (_isEditingLedZone && _currentLedIndex >= 0) + else if ((_isEditingLedZone || _isDrawingLedMode) && _currentLedIndex >= 0) { currentColor = _camera.GetLedZoneColor(_currentLedIndex); } @@ -1111,6 +1115,7 @@ namespace Camera private void UpdateLedZoneButtonsVisibility(int state) { + _ledZoneState = state; switch (state) { case 0: // 就绪状态