From 25b52def92df5e5933f2f0db55d0aea220a19650 Mon Sep 17 00:00:00 2001 From: unknown <2564608840@qq.com> Date: Thu, 19 Jun 2025 14:30:24 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=E7=9B=B4=E7=BA=BF=E6=8B=89=E7=9B=B4?= =?UTF-8?q?=E5=8F=8A=E7=AB=AF=E7=82=B9=E5=90=B8=E9=99=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/MainWindow.xaml.cs | 2 + Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs | 5 +- .../MW_SimulatePressure&InkToShape.cs | 56 +++++++++++------- .../net472/InkCanvasForClass.g.resources | Bin 5180943 -> 5180943 bytes 4 files changed, 41 insertions(+), 22 deletions(-) diff --git a/Ink Canvas/MainWindow.xaml.cs b/Ink Canvas/MainWindow.xaml.cs index 15a5f238..c3fc55eb 100644 --- a/Ink Canvas/MainWindow.xaml.cs +++ b/Ink Canvas/MainWindow.xaml.cs @@ -646,7 +646,9 @@ namespace Ink_Canvas { { // 关闭设置面板 BorderSettings.Visibility = Visibility.Collapsed; + // 设置蒙版为不可点击,并清除背景 BorderSettingsMask.IsHitTestVisible = false; + BorderSettingsMask.Background = null; // 确保清除蒙层背景 } // 新增:折叠侧边栏 diff --git a/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs b/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs index 0f1f851e..9b94772d 100644 --- a/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs +++ b/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs @@ -519,6 +519,8 @@ namespace Ink_Canvas { // 初始化直线自动拉直相关设置 ToggleSwitchAutoStraightenLine.IsOn = Settings.Canvas.AutoStraightenLine; AutoStraightenLineThresholdSlider.Value = Settings.Canvas.AutoStraightenLineThreshold; + // 直线拉直灵敏度也在这里初始化,即使它存储在InkToShape中 + LineStraightenSensitivitySlider.Value = Settings.InkToShape.LineStraightenSensitivity; // 初始化直线端点吸附相关设置 ToggleSwitchLineEndpointSnapping.IsOn = Settings.Canvas.LineEndpointSnapping; @@ -588,8 +590,7 @@ namespace Ink_Canvas { ToggleCheckboxEnableInkToShapeRounded.IsChecked = Settings.InkToShape.IsInkToShapeRounded; - // 初始化直线拉直灵敏度 - LineStraightenSensitivitySlider.Value = Settings.InkToShape.LineStraightenSensitivity; + // 直线拉直灵敏度在Canvas部分已经初始化,这里不再重复 } else { Settings.InkToShape = new InkToShape(); } diff --git a/Ink Canvas/MainWindow_cs/MW_SimulatePressure&InkToShape.cs b/Ink Canvas/MainWindow_cs/MW_SimulatePressure&InkToShape.cs index 6593b927..5116a1d3 100644 --- a/Ink Canvas/MainWindow_cs/MW_SimulatePressure&InkToShape.cs +++ b/Ink Canvas/MainWindow_cs/MW_SimulatePressure&InkToShape.cs @@ -13,7 +13,6 @@ namespace Ink_Canvas { public partial class MainWindow : Window { private StrokeCollection newStrokes = new StrokeCollection(); private List circles = new List(); - private const double SNAP_THRESHOLD = 15.0; // Distance threshold for endpoint snapping private const double LINE_STRAIGHTEN_THRESHOLD = 0.10; // 降低阈值,让直线检测更严格 private void inkCanvas_StrokeCollected(object sender, InkCanvasStrokeCollectedEventArgs e) { @@ -120,25 +119,34 @@ namespace Ink_Canvas { // Apply line straightening and endpoint snapping if ink-to-shape is enabled if (Settings.InkToShape.IsInkToShapeEnabled) { - // Check if this stroke could be a straight line - if (IsPotentialStraightLine(e.Stroke)) { + // 检查是否启用了直线自动拉直功能 + if (Settings.Canvas.AutoStraightenLine && IsPotentialStraightLine(e.Stroke)) { // Get start and end points of the stroke Point startPoint = e.Stroke.StylusPoints[0].ToPoint(); Point endPoint = e.Stroke.StylusPoints[e.Stroke.StylusPoints.Count - 1].ToPoint(); - // Try to snap endpoints to existing strokes + // 端点吸附和直线拉直完全分离处理 bool snapped = false; - if (Settings.InkToShape.IsInkToShapeRectangle || Settings.InkToShape.IsInkToShapeTriangle) { - Point[] snappedPoints = GetSnappedEndpoints(startPoint, endPoint); - if (snappedPoints != null) { - startPoint = snappedPoints[0]; - endPoint = snappedPoints[1]; - snapped = true; + + // 只有在启用端点吸附时才尝试吸附 + if (Settings.Canvas.LineEndpointSnapping) { + // 只有在启用了形状识别(矩形或三角形)时才执行端点吸附 + if (Settings.InkToShape.IsInkToShapeRectangle || Settings.InkToShape.IsInkToShapeTriangle) { + Point[] snappedPoints = GetSnappedEndpoints(startPoint, endPoint); + if (snappedPoints != null) { + startPoint = snappedPoints[0]; + endPoint = snappedPoints[1]; + snapped = true; + } } } - // Create straight line stroke - if (snapped || ShouldStraightenLine(e.Stroke)) { + // 独立检查是否应该拉直线条,无论端点吸附是否启用或成功 + bool shouldStraighten = ShouldStraightenLine(e.Stroke); + + // 如果满足任一条件(吸附成功或应该拉直),则创建直线 + // 这里的条件是"或"关系,只要有一个条件满足就会创建直线 + if (snapped || shouldStraighten) { StylusPointCollection straightLinePoints = CreateStraightLine(startPoint, endPoint); Stroke straightStroke = new Stroke(straightLinePoints) { DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() @@ -574,8 +582,8 @@ namespace Ink_Canvas { Point end = stroke.StylusPoints.Last().ToPoint(); double lineLength = GetDistance(start, end); - // 线条必须足够长才考虑拉直,至少30像素 - if (lineLength < 30) + // 线条必须足够长才考虑拉直,使用设置中的阈值 + if (lineLength < Settings.Canvas.AutoStraightenLineThreshold) return false; // 获取用户设置的灵敏度值 @@ -620,8 +628,8 @@ namespace Ink_Canvas { double maxDeviation = 0; double lineLength = GetDistance(start, end); - // 如果线条太短,不进行拉直处理 - if (lineLength < 50) { + // 如果线条太短,不进行拉直处理,使用设置中的阈值 + if (lineLength < Settings.Canvas.AutoStraightenLineThreshold) { return false; } @@ -732,11 +740,19 @@ namespace Ink_Canvas { // New method: Attempts to snap endpoints to existing stroke endpoints private Point[] GetSnappedEndpoints(Point start, Point end) { + // 如果端点吸附功能关闭,直接返回null + // 这里不再返回原始点,因为调用此方法的地方会判断返回值是否为null + if (!Settings.Canvas.LineEndpointSnapping) + return null; + bool startSnapped = false; bool endSnapped = false; Point snappedStart = start; Point snappedEnd = end; + // 使用设置中的吸附距离阈值 + double snapThreshold = Settings.Canvas.LineEndpointSnappingThreshold; + // Check all strokes in canvas for potential snap points foreach (Stroke stroke in inkCanvas.Strokes) { if (stroke.StylusPoints.Count == 0) continue; @@ -747,10 +763,10 @@ namespace Ink_Canvas { // Check if start point should snap to an endpoint if (!startSnapped) { - if (GetDistance(start, strokeStart) < SNAP_THRESHOLD) { + if (GetDistance(start, strokeStart) < snapThreshold) { snappedStart = strokeStart; startSnapped = true; - } else if (GetDistance(start, strokeEnd) < SNAP_THRESHOLD) { + } else if (GetDistance(start, strokeEnd) < snapThreshold) { snappedStart = strokeEnd; startSnapped = true; } @@ -758,10 +774,10 @@ namespace Ink_Canvas { // Check if end point should snap to an endpoint if (!endSnapped) { - if (GetDistance(end, strokeStart) < SNAP_THRESHOLD) { + if (GetDistance(end, strokeStart) < snapThreshold) { snappedEnd = strokeStart; endSnapped = true; - } else if (GetDistance(end, strokeEnd) < SNAP_THRESHOLD) { + } else if (GetDistance(end, strokeEnd) < snapThreshold) { snappedEnd = strokeEnd; endSnapped = true; } diff --git a/Ink Canvas/obj/Debug/net472/InkCanvasForClass.g.resources b/Ink Canvas/obj/Debug/net472/InkCanvasForClass.g.resources index 3bfc4cc986985933c57f33680607a95a12e5fd0b..53276884e6d2d275b60306010ad90e05bd7c8d69 100644 GIT binary patch delta 465 zcmYk&xlRI67>3~-6hRps7jQ!n^|*n^FbeJ)gS#GUJCnHuP3$ZzOs0@xqLti(hQw)T zEW890TNAwnYu{uNo#H9Je`&tzVQ_K=2_q8JHhGiCn?%Eg6La!$-zvKSgHLUQB zbZ(_15JD505k?Clh@us3h(SX;I-sKyUFb#+;z*zuedxyk29d-NhLOSu(ip`U#vw6* zNlalHGsqx|S>!N>JPZ_IVjc@9qJ%{(VHqn}#TwSJflX{-8)aCiUN@GE?%siLRZs%-vO>RsI{JL2b;ntD$KPV)`*6Ak3+H+7c$d(C;7Pj#LS?7zfm GR{I6vdZRx8 delta 465 zcmYk&xlRI67>3~-6hRrs4ct&fJ#HW}jNra9xa+aDGnre^#LmLPWC|%JTFE_VNSubo z!b>o*HPKtJ_Dv?yDW2l{m*%TJHbPZA#Vk>DUn{b1SY|=!u6^+=^m^j*JMPb2!wTO> z=TGVYDEEC|c2m7&Np)M+Z95g>Lj9js$wqhkguT5J?PS7%7Y(jZutY91;_l z#1y76gAB5mMGkYw!$1Kh=21im3s}Swma&3WtYIA+*u)mLQHF&IcCd>*?Bf83IKr_f zos+u{zru%_DtVf%%I1Hi-qpRbBYu9VsrOXiG~ZA^(Lla_Q)kJ)*PNI6ROjiy{!5%@ FwO`ZJqbmRa From 0b72b1f1b3c97bdf47eeec60a9525751c2a70663 Mon Sep 17 00:00:00 2001 From: unknown <2564608840@qq.com> Date: Thu, 19 Jun 2025 14:32:16 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=E8=AE=BE=E7=BD=AE=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E5=AF=BC=E8=87=B4=E7=9A=84=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E7=82=B9=E5=87=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/MainWindow.xaml.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Ink Canvas/MainWindow.xaml.cs b/Ink Canvas/MainWindow.xaml.cs index c3fc55eb..e9e16b7a 100644 --- a/Ink Canvas/MainWindow.xaml.cs +++ b/Ink Canvas/MainWindow.xaml.cs @@ -681,7 +681,9 @@ namespace Ink_Canvas { { // 显示设置面板 BorderSettings.Visibility = Visibility.Visible; + // 设置蒙版为可点击,并添加半透明背景 BorderSettingsMask.IsHitTestVisible = true; + BorderSettingsMask.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(1, 0, 0, 0)); // 获取SettingsPanelScrollViewer中的所有GroupBox var stackPanel = SettingsPanelScrollViewer.Content as StackPanel; From 316d568cbc08bb52eda00d505199fa11b770e6fe Mon Sep 17 00:00:00 2001 From: unknown <2564608840@qq.com> Date: Thu, 19 Jun 2025 14:33:01 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AutomaticUpdateVersionControl.txt | 2 +- Ink Canvas/AssemblyInfo.cs | 4 ++-- Ink Canvas/Properties/AssemblyInfo.cs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/AutomaticUpdateVersionControl.txt b/AutomaticUpdateVersionControl.txt index 83d1a5eb..60fdb8d5 100644 --- a/AutomaticUpdateVersionControl.txt +++ b/AutomaticUpdateVersionControl.txt @@ -1 +1 @@ -1.6.6 \ No newline at end of file +1.6.7 \ No newline at end of file diff --git a/Ink Canvas/AssemblyInfo.cs b/Ink Canvas/AssemblyInfo.cs index 7955d3e7..0256f188 100644 --- a/Ink Canvas/AssemblyInfo.cs +++ b/Ink Canvas/AssemblyInfo.cs @@ -49,5 +49,5 @@ using System.Windows; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.6.6")] -[assembly: AssemblyFileVersion("1.6.6")] +[assembly: AssemblyVersion("1.6.7")] +[assembly: AssemblyFileVersion("1.6.7")] diff --git a/Ink Canvas/Properties/AssemblyInfo.cs b/Ink Canvas/Properties/AssemblyInfo.cs index 02d917e1..6404deac 100644 --- a/Ink Canvas/Properties/AssemblyInfo.cs +++ b/Ink Canvas/Properties/AssemblyInfo.cs @@ -49,5 +49,5 @@ using System.Windows; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.6.6")] -[assembly: AssemblyFileVersion("1.6.6")] \ No newline at end of file +[assembly: AssemblyVersion("1.6.7")] +[assembly: AssemblyFileVersion("1.6.7")] \ No newline at end of file