improve:截图

This commit is contained in:
2025-08-31 10:47:33 +08:00
parent 80c1badba5
commit 40ecfbefa3
2 changed files with 102 additions and 4 deletions
@@ -191,7 +191,8 @@ namespace Ink_Canvas
hitElement is Separator ||
hitElement.Name == "SizeInfoBorder" ||
hitElement.Name == "HintText" ||
hitElement.Name == "AdjustModeHint"))
hitElement.Name == "AdjustModeHint" ||
hitElement.Name == "SelectionRectangle"))
{
return;
}
@@ -243,6 +244,12 @@ namespace Ink_Canvas
private void Window_MouseMove(object sender, MouseEventArgs e)
{
// 如果正在调整模式且正在移动,不处理窗口级别的鼠标移动
if (_isAdjusting && _isMoving)
{
return;
}
if (_isSelecting)
{
_currentPoint = e.GetPosition(this);
@@ -266,6 +273,12 @@ namespace Ink_Canvas
private void Window_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
// 如果正在调整模式且正在移动,不处理窗口级别的鼠标释放
if (_isAdjusting && _isMoving)
{
return;
}
if (_isSelecting)
{
_isSelecting = false;
@@ -456,6 +469,8 @@ namespace Ink_Canvas
private void ShowControlPoints()
{
// 确保选择矩形在调整模式下可见
SelectionRectangle.Visibility = Visibility.Visible;
ControlPointsCanvas.Visibility = Visibility.Visible;
UpdateControlPointsPosition();
}
@@ -694,6 +709,75 @@ namespace Ink_Canvas
return Math.Sqrt(dx * dx + dy * dy);
}
private void SelectionRectangle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
// 添加调试信息
System.Diagnostics.Debug.WriteLine($"SelectionRectangle_MouseLeftButtonDown: _isAdjusting={_isAdjusting}");
if (!_isAdjusting) return;
_isMoving = true;
_activeControlPoint = ControlPointType.Move;
_lastMousePosition = e.GetPosition(this);
// 捕获鼠标到选择矩形
SelectionRectangle.CaptureMouse();
e.Handled = true;
System.Diagnostics.Debug.WriteLine("SelectionRectangle mouse capture started");
}
private void SelectionRectangle_MouseMove(object sender, MouseEventArgs e)
{
if (!_isAdjusting || !_isMoving || _activeControlPoint != ControlPointType.Move) return;
try
{
var currentPosition = e.GetPosition(this);
var delta = currentPosition - _lastMousePosition;
// 移动整个选择区域
var newRect = _currentSelection;
newRect.X += delta.X;
newRect.Y += delta.Y;
// 确保选择区域不会移出屏幕边界
var screenBounds = new Rect(0, 0, ActualWidth, ActualHeight);
if (newRect.Left < 0) newRect.X = 0;
if (newRect.Top < 0) newRect.Y = 0;
if (newRect.Right > screenBounds.Right) newRect.X = screenBounds.Right - newRect.Width;
if (newRect.Bottom > screenBounds.Bottom) newRect.Y = screenBounds.Bottom - newRect.Height;
_currentSelection = newRect;
UpdateSelectionDisplay();
_lastMousePosition = currentPosition;
e.Handled = true;
// 添加调试信息
System.Diagnostics.Debug.WriteLine($"SelectionRectangle moving: delta=({delta.X}, {delta.Y}), newRect=({newRect.X}, {newRect.Y}, {newRect.Width}, {newRect.Height})");
}
catch (Exception ex)
{
// 如果出现异常,停止移动
System.Diagnostics.Debug.WriteLine($"SelectionRectangle move error: {ex.Message}");
_isMoving = false;
_activeControlPoint = ControlPointType.None;
SelectionRectangle.ReleaseMouseCapture();
}
}
private void SelectionRectangle_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (_isMoving && _activeControlPoint == ControlPointType.Move)
{
_isMoving = false;
_activeControlPoint = ControlPointType.None;
SelectionRectangle.ReleaseMouseCapture();
e.Handled = true;
}
}
private void ResetSelectionState()
{
// 重置所有选择相关的状态
@@ -724,6 +808,12 @@ namespace Ink_Canvas
ReleaseMouseCapture();
}
// 释放选择矩形的鼠标捕获
if (SelectionRectangle.IsMouseCaptured)
{
SelectionRectangle.ReleaseMouseCapture();
}
// 重置选择区域
_currentSelection = new Rect();
SelectedArea = null;