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">
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+ FontSize="22"
+ FontWeight="SemiBold"
+ VerticalAlignment="Center"/>
+
+
+
+
-
-
-
-
-
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
-
-
-
+
+
+
\ No newline at end of file
diff --git a/Ink Canvas/Windows/HotkeySettingsWindow.xaml.cs b/Ink Canvas/Windows/HotkeySettingsWindow.xaml.cs
index bf24f0c0..bb7f41df 100644
--- a/Ink Canvas/Windows/HotkeySettingsWindow.xaml.cs
+++ b/Ink Canvas/Windows/HotkeySettingsWindow.xaml.cs
@@ -27,11 +27,8 @@ namespace Ink_Canvas.Windows
_hotkeyManager = hotkeyManager;
_hotkeyItems = new Dictionary();
- // 设置窗口属性以避免与主窗口置顶维护冲突
+ // 设置窗口属性
SetupWindowProperties();
-
- // 隐藏主窗口的设置页面
- HideMainWindowSettings();
InitializeHotkeyItems();
// 延迟加载快捷键,确保快捷键管理器已完全初始化
@@ -62,21 +59,17 @@ namespace Ink_Canvas.Windows
#region Private Methods
///
- /// 设置窗口属性以避免与主窗口置顶维护冲突
+ /// 设置窗口属性
///
private void SetupWindowProperties()
{
try
{
- // 设置为模态窗口,确保它始终在主窗口之上
- // 但不设置Topmost,避免与主窗口的置顶维护机制冲突
- this.Owner = _mainWindow;
-
// 设置窗口启动位置为屏幕中心
this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
// 确保窗口在显示时获得焦点
- this.ShowInTaskbar = false;
+ this.ShowInTaskbar = true;
LogHelper.WriteLogToFile("快捷键设置窗口属性已设置");
}
@@ -520,69 +513,6 @@ namespace Ink_Canvas.Windows
}
#endregion
- #region MainWindow Settings Management
- ///
- /// 隐藏主窗口的设置页面
- ///
- private void HideMainWindowSettings()
- {
- try
- {
- // 通过反射访问主窗口的设置面板
- var settingsBorder = _mainWindow.GetType().GetField("BorderSettings",
- BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(_mainWindow) as Border;
-
- if (settingsBorder != null)
- {
- settingsBorder.Visibility = Visibility.Collapsed;
- }
-
- // 隐藏设置蒙版
- var settingsMask = _mainWindow.GetType().GetField("BorderSettingsMask",
- BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(_mainWindow) as Border;
-
- if (settingsMask != null)
- {
- settingsMask.Visibility = Visibility.Collapsed;
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogToFile($"隐藏主窗口设置页面时出错: {ex.Message}", LogHelper.LogType.Error);
- }
- }
-
- ///
- /// 显示主窗口的设置页面
- ///
- private void ShowMainWindowSettings()
- {
- try
- {
- // 通过反射访问主窗口的设置面板
- var settingsBorder = _mainWindow.GetType().GetField("BorderSettings",
- BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(_mainWindow) as Border;
-
- if (settingsBorder != null)
- {
- settingsBorder.Visibility = Visibility.Visible;
- }
-
- // 显示设置蒙版
- var settingsMask = _mainWindow.GetType().GetField("BorderSettingsMask",
- BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(_mainWindow) as Border;
-
- if (settingsMask != null)
- {
- settingsMask.Visibility = Visibility.Visible;
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteLogToFile($"显示主窗口设置页面时出错: {ex.Message}", LogHelper.LogType.Error);
- }
- }
- #endregion
#region Window Event Handlers
///
@@ -592,13 +522,7 @@ namespace Ink_Canvas.Windows
{
try
{
- // 重置窗口置顶状态,避免影响主窗口
- this.Topmost = false;
-
- // 恢复主窗口设置页面的显示
- ShowMainWindowSettings();
-
- LogHelper.WriteLogToFile("快捷键设置窗口已关闭,置顶状态已重置");
+ LogHelper.WriteLogToFile("快捷键设置窗口已关闭");
}
catch (Exception ex)
{
@@ -613,6 +537,30 @@ namespace Ink_Canvas.Windows
Close();
}
+ ///
+ /// 标题栏拖拽事件
+ ///
+ private void TitleBar_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
+ {
+ if (e.ClickCount == 2)
+ {
+ // 双击标题栏切换最大化状态
+ if (WindowState == WindowState.Maximized)
+ {
+ WindowState = WindowState.Normal;
+ }
+ else
+ {
+ WindowState = WindowState.Maximized;
+ }
+ }
+ else
+ {
+ // 拖拽窗口
+ DragMove();
+ }
+ }
+
private void BtnResetToDefault_Click(object sender, RoutedEventArgs e)
{
try
diff --git a/Ink Canvas/Windows/PluginSettingsWindow.xaml b/Ink Canvas/Windows/PluginSettingsWindow.xaml
index cc3ef89b..776a2b1a 100644
--- a/Ink Canvas/Windows/PluginSettingsWindow.xaml
+++ b/Ink Canvas/Windows/PluginSettingsWindow.xaml
@@ -9,6 +9,8 @@
Title="插件管理" Height="550" Width="800"
WindowStartupLocation="CenterScreen"
ResizeMode="CanResize"
+ WindowStyle="None"
+ AllowsTransparency="True"
Background="#F9F9F9">
@@ -27,7 +29,8 @@
-
+
diff --git a/Ink Canvas/Windows/PluginSettingsWindow.xaml.cs b/Ink Canvas/Windows/PluginSettingsWindow.xaml.cs
index cdaecc4e..ef206124 100644
--- a/Ink Canvas/Windows/PluginSettingsWindow.xaml.cs
+++ b/Ink Canvas/Windows/PluginSettingsWindow.xaml.cs
@@ -624,6 +624,30 @@ namespace Ink_Canvas.Windows
// 直接关闭窗口,窗口关闭事件会处理配置保存
Close();
}
+
+ ///
+ /// 标题栏拖拽事件
+ ///
+ private void TitleBar_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
+ {
+ if (e.ClickCount == 2)
+ {
+ // 双击标题栏切换最大化状态
+ if (WindowState == WindowState.Maximized)
+ {
+ WindowState = WindowState.Normal;
+ }
+ else
+ {
+ WindowState = WindowState.Maximized;
+ }
+ }
+ else
+ {
+ // 拖拽窗口
+ DragMove();
+ }
+ }
}
///