From fad2571edb61198ac51523350aa7480246bdfa62 Mon Sep 17 00:00:00 2001
From: CJKmkp <2564608840@qq.com>
Date: Sun, 31 Aug 2025 12:16:29 +0800
Subject: [PATCH] =?UTF-8?q?fix:=E5=90=88=E5=B9=B6=E5=86=B2=E7=AA=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Windows/ScreenshotSelectorWindow.xaml | 7 +-
.../Windows/ScreenshotSelectorWindow.xaml.cs | 93 +++++++++---------
...vasForClass.csproj.AssemblyReference.cache | Bin 35309 -> 35374 bytes
3 files changed, 51 insertions(+), 49 deletions(-)
diff --git a/Ink Canvas/Windows/ScreenshotSelectorWindow.xaml b/Ink Canvas/Windows/ScreenshotSelectorWindow.xaml
index c811439e..2d424b75 100644
--- a/Ink Canvas/Windows/ScreenshotSelectorWindow.xaml
+++ b/Ink Canvas/Windows/ScreenshotSelectorWindow.xaml
@@ -18,14 +18,12 @@
+ Opacity="0.3" />
@@ -45,9 +43,8 @@
(_freehandPoints);
-
+
// 简化路径处理,不强制闭合
// 如果路径没有闭合,自动添加起始点
if (pathPoints.Count > 0)
@@ -301,13 +301,13 @@ namespace Ink_Canvas
// 优化路径:移除重复点和过于接近的点,提高路径质量
var optimizedPath = OptimizePath(pathPoints);
-
+
// 保存选择的路径
SelectedPath = optimizedPath;
// 计算边界矩形用于截图
var bounds = CalculatePathBounds(optimizedPath);
-
+
// 确保边界矩形有效
if (bounds.Width >= 0 && bounds.Height >= 0)
{
@@ -325,7 +325,7 @@ namespace Ink_Canvas
return;
}
}
-
+
// 如果自由绘制失败,清除路径并继续
_freehandPoints.Clear();
_freehandPolyline.Points.Clear();
@@ -363,7 +363,7 @@ namespace Ink_Canvas
_isMoving = true;
_lastMousePosition = e.GetPosition(this);
-
+
// 确定当前控制点类型
var ellipse = sender as Ellipse;
if (ellipse == TopLeftControl) _activeControlPoint = ControlPointType.TopLeft;
@@ -471,6 +471,10 @@ namespace Ink_Canvas
{
// 确保选择矩形在调整模式下可见
SelectionRectangle.Visibility = Visibility.Visible;
+ // 设置选择矩形的Z-index,确保它能够接收鼠标事件
+ WpfCanvas.SetZIndex(SelectionRectangle, 1001);
+ // 确保选择矩形能够接收鼠标事件
+ SelectionRectangle.IsHitTestVisible = true;
ControlPointsCanvas.Visibility = Visibility.Visible;
UpdateControlPointsPosition();
}
@@ -482,26 +486,26 @@ namespace Ink_Canvas
// 更新角控制点位置
WpfCanvas.SetLeft(TopLeftControl, rect.Left - 4);
WpfCanvas.SetTop(TopLeftControl, rect.Top - 4);
-
+
WpfCanvas.SetLeft(TopRightControl, rect.Right - 4);
WpfCanvas.SetTop(TopRightControl, rect.Top - 4);
-
+
WpfCanvas.SetLeft(BottomLeftControl, rect.Left - 4);
WpfCanvas.SetTop(BottomLeftControl, rect.Bottom - 4);
-
+
WpfCanvas.SetLeft(BottomRightControl, rect.Right - 4);
WpfCanvas.SetTop(BottomRightControl, rect.Bottom - 4);
// 更新边控制点位置
WpfCanvas.SetLeft(TopControl, rect.Left + rect.Width / 2 - 4);
WpfCanvas.SetTop(TopControl, rect.Top - 4);
-
+
WpfCanvas.SetLeft(BottomControl, rect.Left + rect.Width / 2 - 4);
WpfCanvas.SetTop(BottomControl, rect.Bottom - 4);
-
+
WpfCanvas.SetLeft(LeftControl, rect.Left - 4);
WpfCanvas.SetTop(LeftControl, rect.Top + rect.Height / 2 - 4);
-
+
WpfCanvas.SetLeft(RightControl, rect.Right - 4);
WpfCanvas.SetTop(RightControl, rect.Top + rect.Height / 2 - 4);
}
@@ -515,6 +519,12 @@ namespace Ink_Canvas
WpfCanvas.SetTop(SelectionRectangle, rect.Y);
SelectionRectangle.Width = rect.Width;
SelectionRectangle.Height = rect.Height;
+
+ // 在选择过程中,禁用选择矩形的鼠标事件,避免干扰选择操作
+ if (_isSelecting)
+ {
+ SelectionRectangle.IsHitTestVisible = false;
+ }
// 更新透明选择区域遮罩
UpdateTransparentSelectionMask(rect);
@@ -537,12 +547,12 @@ namespace Ink_Canvas
{
// 更新选择区域的几何体
SelectionClipGeometry.Rect = selectionRect;
-
+
// 显示透明遮罩,隐藏原始遮罩
TransparentSelectionMask.Visibility = Visibility.Visible;
OverlayRectangle.Visibility = Visibility.Collapsed;
}
- catch (Exception ex)
+ catch (Exception)
{
// 如果几何体操作失败,回退到原始遮罩
TransparentSelectionMask.Visibility = Visibility.Collapsed;
@@ -559,6 +569,13 @@ namespace Ink_Canvas
WpfCanvas.SetTop(SelectionRectangle, rect.Y);
SelectionRectangle.Width = rect.Width;
SelectionRectangle.Height = rect.Height;
+
+ // 确保选择矩形在调整模式下能够接收鼠标事件
+ if (_isAdjusting)
+ {
+ SelectionRectangle.IsHitTestVisible = true;
+ WpfCanvas.SetZIndex(SelectionRectangle, 1001);
+ }
// 更新透明选择区域遮罩
UpdateTransparentSelectionMask(rect);
@@ -595,7 +612,7 @@ namespace Ink_Canvas
{
return;
}
-
+
if (_isAdjusting)
{
// 转换为屏幕坐标,考虑DPI缩放
@@ -711,9 +728,6 @@ namespace Ink_Canvas
private void SelectionRectangle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
- // 添加调试信息
- System.Diagnostics.Debug.WriteLine($"SelectionRectangle_MouseLeftButtonDown: _isAdjusting={_isAdjusting}");
-
if (!_isAdjusting) return;
_isMoving = true;
@@ -723,8 +737,6 @@ namespace Ink_Canvas
// 捕获鼠标到选择矩形
SelectionRectangle.CaptureMouse();
e.Handled = true;
-
- System.Diagnostics.Debug.WriteLine("SelectionRectangle mouse capture started");
}
private void SelectionRectangle_MouseMove(object sender, MouseEventArgs e)
@@ -753,14 +765,10 @@ namespace Ink_Canvas
_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)
+ catch (Exception)
{
// 如果出现异常,停止移动
- System.Diagnostics.Debug.WriteLine($"SelectionRectangle move error: {ex.Message}");
_isMoving = false;
_activeControlPoint = ControlPointType.None;
SelectionRectangle.ReleaseMouseCapture();
@@ -785,29 +793,29 @@ namespace Ink_Canvas
_isAdjusting = false;
_isMoving = false;
_activeControlPoint = ControlPointType.None;
-
+
// 清除自由绘制的内容
_freehandPoints.Clear();
_freehandPolyline.Points.Clear();
_freehandPolyline.Visibility = Visibility.Collapsed;
-
+
// 清除矩形选择的内容
SelectionRectangle.Visibility = Visibility.Collapsed;
+ SelectionRectangle.IsHitTestVisible = false;
ControlPointsCanvas.Visibility = Visibility.Collapsed;
SizeInfoBorder.Visibility = Visibility.Collapsed;
SelectionPath.Visibility = Visibility.Collapsed;
AdjustModeHint.Visibility = Visibility.Collapsed;
-
+
// 重置遮罩
TransparentSelectionMask.Visibility = Visibility.Collapsed;
OverlayRectangle.Visibility = Visibility.Visible;
-
+
// 释放鼠标捕获
if (IsMouseCaptured)
{
ReleaseMouseCapture();
}
-<<<<<<< HEAD
// 释放选择矩形的鼠标捕获
if (SelectionRectangle.IsMouseCaptured)
@@ -815,9 +823,6 @@ namespace Ink_Canvas
SelectionRectangle.ReleaseMouseCapture();
}
-=======
-
->>>>>>> ff086e497c2dc751d72f3a6d72ce5d883b297672
// 重置选择区域
_currentSelection = new Rect();
SelectedArea = null;
diff --git a/Ink Canvas/obj/Debug/net472/InkCanvasForClass.csproj.AssemblyReference.cache b/Ink Canvas/obj/Debug/net472/InkCanvasForClass.csproj.AssemblyReference.cache
index e30091c894a532a9d72b5db5c6031ca33407681b..4af914e22079d93b58f0e03491291464a0dba41e 100644
GIT binary patch
delta 1269
zcmaDmnQ7e=CJr`6Jq88_#>B}1lA#l03&l)btztZ#ofVv2p_D>yVrJfC19pkYyo|hT
zzak6wZ`n3kfzepbHZ3zJ)k?U${cum{9pFPuA
zJi*y2CbT%Us5r(kB{wrKv$&)vu_V7}vYqz~`3#tTXDfZM8hsQso4^ntV2X113dUYV}`*SmQ=~O21
zFq|exO}UT4W2jeiHvavxvnt%b~O)r?mLva`&+SWYTqyjw#wzUZ{ipSy5a<6^jWVSSPExjEH
pjFXQkhELAo7Ep4Amm~}i9B+JAxXJ-4+PKP0^bGWj4U7#f836XS#1jAj
delta 1280
zcmZ2Ch3V~NCJr`6T?PgQ#>B~j@}U!B3)S76tztrpQ;UjY0*X@85|dL?ob!v)V_fo+
zOLJ56N{VCLGfO;5lO{ezcQC714t5Q{0+!2_;C002
z1A!-*#gedVUl2M?E(@>r$){2+Hur`ZGK%HlGQwhVLY(O2_Yu64^&>*$$_N?fHaRbj
zee?SWC04Oid`70o