diff --git a/Ink Canvas/MainWindow.xaml.cs b/Ink Canvas/MainWindow.xaml.cs index 9fff4046..69e86e9f 100644 --- a/Ink Canvas/MainWindow.xaml.cs +++ b/Ink Canvas/MainWindow.xaml.cs @@ -2028,52 +2028,30 @@ namespace Ink_Canvas return; } + // 暂时隐藏设置面板 + BorderSettings.Visibility = Visibility.Hidden; + BorderSettingsMask.Visibility = Visibility.Hidden; + // 创建快捷键设置窗口 var hotkeySettingsWindow = new HotkeySettingsWindow(this, _globalHotkeyManager); - // 确保窗口在显示前获得正确的焦点和置顶状态 - hotkeySettingsWindow.Loaded += (s, e) => - { - try - { - // 确保窗口获得焦点 - hotkeySettingsWindow.Activate(); - hotkeySettingsWindow.Focus(); - - // 如果主窗口处于置顶状态,临时调整子窗口的置顶状态 - if (Settings.Advanced.IsAlwaysOnTop) - { - // 临时设置子窗口为置顶,确保它在主窗口之上 - hotkeySettingsWindow.Topmost = true; - } - } - catch (Exception ex) - { - LogHelper.WriteLogToFile($"设置快捷键设置窗口焦点时出错: {ex.Message}", LogHelper.LogType.Error); - } - }; - - // 窗口关闭时恢复置顶状态 + // 设置窗口关闭事件,用于在快捷键设置窗口关闭后恢复设置面板 hotkeySettingsWindow.Closed += (s, e) => { - try - { - // 恢复主窗口的置顶状态 - if (Settings.Advanced.IsAlwaysOnTop) - { - ApplyAlwaysOnTop(); - } - } - catch (Exception ex) - { - LogHelper.WriteLogToFile($"恢复主窗口置顶状态时出错: {ex.Message}", LogHelper.LogType.Error); - } + // 恢复设置面板显示 + BorderSettings.Visibility = Visibility.Visible; + BorderSettingsMask.Visibility = Visibility.Visible; }; + // 显示快捷键设置窗口 hotkeySettingsWindow.ShowDialog(); } catch (Exception ex) { + // 确保在发生错误时也恢复设置面板显示 + BorderSettings.Visibility = Visibility.Visible; + BorderSettingsMask.Visibility = Visibility.Visible; + LogHelper.WriteLogToFile($"打开快捷键设置窗口时出错: {ex.Message}", LogHelper.LogType.Error); MessageBox.Show($"打开快捷键设置窗口时出错: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error); } diff --git a/Ink Canvas/MainWindow_cs/MW_TouchEvents.cs b/Ink Canvas/MainWindow_cs/MW_TouchEvents.cs index bfba3b73..a5f6af9c 100644 --- a/Ink Canvas/MainWindow_cs/MW_TouchEvents.cs +++ b/Ink Canvas/MainWindow_cs/MW_TouchEvents.cs @@ -468,45 +468,55 @@ namespace Ink_Canvas BlackboardUIGridForInkReplay.IsHitTestVisible = false; dec.Add(e.TouchDevice.Id); - // Palm Eraser 逻辑 - 优化:改进手掌判定条件,提高精度 + // Palm Eraser 逻辑 - 优化:改进手掌判定条件,使用设备提供的触摸面积信息 if (Settings.Canvas.EnablePalmEraser && dec.Count >= 2 && !isPalmEraserActive && !palmEraserTouchDownHandled) { - var bounds = e.GetTouchPoint(inkCanvas).Bounds; + touchPoint = e.GetTouchPoint(inkCanvas); + var size = touchPoint.Size; // 使用设备提供的触摸面积信息 + var bounds = touchPoint.Bounds; // 保留bounds用于宽高比计算 // 根据敏感度设置调整判定参数 - double palmThreshold; + double palmAreaThreshold; // 改为面积阈值 double aspectRatioThreshold; int minTouchPoints; switch (Settings.Canvas.PalmEraserSensitivity) { case 0: // 低敏感度 - 更严格的判定 - palmThreshold = 80; + palmAreaThreshold = 6400; // 80*80的面积 aspectRatioThreshold = 0.4; minTouchPoints = 4; break; case 1: // 中敏感度 - 平衡的判定 - palmThreshold = 60; + palmAreaThreshold = 3600; // 60*60的面积 aspectRatioThreshold = 0.3; minTouchPoints = 3; break; case 2: // 高敏感度 - 较宽松的判定 default: - palmThreshold = 50; + palmAreaThreshold = 2500; // 50*50的面积 aspectRatioThreshold = 0.25; minTouchPoints = 2; break; } - // 计算宽高比 + // 计算触摸面积(使用设备提供的Size) + double touchArea = size.Width * size.Height; + + // 计算宽高比(使用Bounds确保准确性) double aspectRatio = Math.Min(bounds.Width, bounds.Height) / Math.Max(bounds.Width, bounds.Height); - // 更严格的手掌判定条件 - bool isLargeTouch = bounds.Width >= palmThreshold && bounds.Height >= palmThreshold; + // 改进的手掌判定条件:使用面积而不是单独的宽高 + bool isLargeTouch = touchArea >= palmAreaThreshold; bool isPalmLikeShape = aspectRatio >= aspectRatioThreshold; bool hasMultipleTouchPoints = dec.Count >= minTouchPoints; + + // 新增:额外的判定条件提高准确性 + bool isReasonableSize = size.Width >= 20 && size.Height >= 20 && size.Width <= 200 && size.Height <= 200; // 合理的触摸尺寸范围 + bool isNotTooElongated = aspectRatio >= 0.2; // 避免过于细长的触摸(可能是手指) + bool hasEnoughArea = touchArea >= 400; // 最小面积要求,避免小面积误判 - if (isLargeTouch && isPalmLikeShape && hasMultipleTouchPoints) + if (isLargeTouch && isPalmLikeShape && hasMultipleTouchPoints && isReasonableSize && isNotTooElongated && hasEnoughArea) { // 记录当前编辑模式和高光状态 palmEraserLastEditingMode = inkCanvas.EditingMode; @@ -529,7 +539,7 @@ namespace Ink_Canvas StartPalmEraserRecoveryTimer(); // 记录日志 - LogHelper.WriteLogToFile($"Palm eraser activated - Sensitivity: {Settings.Canvas.PalmEraserSensitivity}, Touch bounds: {bounds.Width}x{bounds.Height}, Aspect ratio: {aspectRatio:F2}, Touch points: {dec.Count}"); + LogHelper.WriteLogToFile($"Palm eraser activated - Sensitivity: {Settings.Canvas.PalmEraserSensitivity}, Touch area: {touchArea:F0}, Size: {size.Width}x{size.Height}, Bounds: {bounds.Width}x{bounds.Height}, Aspect ratio: {aspectRatio:F2}, Touch points: {dec.Count}, Reasonable size: {isReasonableSize}, Not elongated: {isNotTooElongated}, Enough area: {hasEnoughArea}"); } } @@ -602,6 +612,8 @@ namespace Ink_Canvas // 当所有手掌擦触摸点都抬起时,恢复原编辑模式 if (isPalmEraserActive && palmEraserTouchIds.Count == 0) { + LogHelper.WriteLogToFile($"Palm eraser recovery triggered - Touch points remaining: {palmEraserTouchIds.Count}, dec.Count: {dec.Count}"); + // 恢复高光状态 drawingAttributes.IsHighlighter = palmEraserLastIsHighlighter; @@ -764,6 +776,37 @@ namespace Ink_Canvas // 修复:确保手掌擦除后触摸事件能正常响应 if (isPalmEraserActive) { + LogHelper.WriteLogToFile("Palm eraser force recovery - all touch points cleared"); + + // 恢复高光状态 + drawingAttributes.IsHighlighter = palmEraserLastIsHighlighter; + + // 恢复编辑模式 + try + { + if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint) + { + switch (palmEraserLastEditingMode) + { + case InkCanvasEditingMode.Ink: + PenIcon_Click(null, null); + break; + case InkCanvasEditingMode.Select: + SymbolIconSelect_MouseUp(null, null); + break; + default: + inkCanvas.EditingMode = palmEraserLastEditingMode; + break; + } + LogHelper.WriteLogToFile($"Palm eraser force recovered to mode: {palmEraserLastEditingMode}"); + } + } + catch (Exception ex) + { + LogHelper.WriteLogToFile($"Palm eraser force recovery failed: {ex.Message}, forcing to Ink mode", LogHelper.LogType.Error); + inkCanvas.EditingMode = InkCanvasEditingMode.Ink; + } + // 如果手掌擦还在激活状态但触摸点已清空,强制重置状态 isPalmEraserActive = false; palmEraserTouchDownHandled = false; @@ -773,6 +816,11 @@ namespace Ink_Canvas ViewboxFloatingBar.IsHitTestVisible = true; BlackboardUIGridForInkReplay.IsHitTestVisible = true; + + // 停止恢复定时器 + StopPalmEraserRecoveryTimer(); + + LogHelper.WriteLogToFile("Palm eraser force recovery completed"); } } } diff --git a/Ink Canvas/Resources/Settings.cs b/Ink Canvas/Resources/Settings.cs index 0f757ef9..8b27b726 100644 --- a/Ink Canvas/Resources/Settings.cs +++ b/Ink Canvas/Resources/Settings.cs @@ -89,7 +89,7 @@ namespace Ink_Canvas [JsonProperty("enablePalmEraser")] public bool EnablePalmEraser { get; set; } = true; [JsonProperty("palmEraserSensitivity")] - public int PalmEraserSensitivity { get; set; } = 2; // 0-低敏感度, 1-中敏感度, 2-高敏感度 + public int PalmEraserSensitivity { get; set; } = 0; // 0-低敏感度, 1-中敏感度, 2-高敏感度 [JsonProperty("clearCanvasAlsoClearImages")] public bool ClearCanvasAlsoClearImages { get; set; } = true; [JsonProperty("showCircleCenter")] diff --git a/Ink Canvas/Windows/HotkeySettingsWindow.xaml b/Ink Canvas/Windows/HotkeySettingsWindow.xaml index e6f41019..a61d785c 100644 --- a/Ink Canvas/Windows/HotkeySettingsWindow.xaml +++ b/Ink Canvas/Windows/HotkeySettingsWindow.xaml @@ -6,185 +6,194 @@ xmlns:local="clr-namespace:Ink_Canvas.Windows" xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern" ui:ThemeManager.RequestedTheme="Light" - Background="Transparent" + Background="#F9F9F9" AllowsTransparency="True" mc:Ignorable="d" WindowStyle="None" WindowStartupLocation="CenterScreen" + ResizeMode="CanResize" Title="快捷键设置" Height="600" Width="800"> - - - - - + + + + + + + + + + + -