@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
if (isLargeTouch && isPalmLikeShape && hasMultipleTouchPoints)
|
||||
// 新增:额外的判定条件提高准确性
|
||||
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 && 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")]
|
||||
|
||||
@@ -6,41 +6,50 @@
|
||||
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">
|
||||
|
||||
<Border Background="#F0F3F9" CornerRadius="10" BorderThickness="1" BorderBrush="#0066BF" Margin="10">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 标题栏 -->
|
||||
<Border Height="50" Background="#0066BF" CornerRadius="10,10,0,0" VerticalAlignment="Top">
|
||||
<Border Grid.Row="0" Background="#3B82F6" Height="60"
|
||||
MouseLeftButtonDown="TitleBar_MouseLeftButtonDown">
|
||||
<Grid>
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="20,0,0,0">
|
||||
<TextBlock Text="快捷键设置"
|
||||
Foreground="White"
|
||||
FontSize="18"
|
||||
FontWeight="Bold"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Center"/>
|
||||
FontSize="22"
|
||||
FontWeight="SemiBold"
|
||||
VerticalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
<Button x:Name="BtnClose"
|
||||
Content="✕"
|
||||
Width="30"
|
||||
Height="30"
|
||||
Background="Transparent"
|
||||
Foreground="White"
|
||||
FontSize="14"
|
||||
Content=""
|
||||
FontFamily="Segoe MDL2 Assets"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="0,0,30,0"
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,0,20,0"
|
||||
Background="Transparent"
|
||||
BorderThickness="0"
|
||||
FontSize="16"
|
||||
Foreground="White"
|
||||
Click="BtnClose_Click"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- 内容区域 -->
|
||||
<ScrollViewer Margin="0,50,0,0" VerticalScrollBarVisibility="Auto">
|
||||
<!-- 主内容区 -->
|
||||
<ScrollViewer Grid.Row="1" Margin="20" VerticalScrollBarVisibility="Auto">
|
||||
<ui:SimpleStackPanel Margin="20">
|
||||
<!-- 说明文字 -->
|
||||
<TextBlock Text="在这里可以自定义全局快捷键设置。全局快捷键在任何情况下都能生效,即使应用程序不在焦点状态。"
|
||||
@@ -179,12 +188,12 @@
|
||||
DefaultModifiers="None"/>
|
||||
</ui:SimpleStackPanel>
|
||||
</GroupBox>
|
||||
</ui:SimpleStackPanel>
|
||||
</ui:SimpleStackPanel>
|
||||
</ui:SimpleStackPanel></ui:SimpleStackPanel>
|
||||
</ScrollViewer>
|
||||
|
||||
<!-- 底部按钮 -->
|
||||
<Border Height="60" Background="#F8F9FA" CornerRadius="0,0,10,10" VerticalAlignment="Bottom">
|
||||
<!-- 底部操作栏 -->
|
||||
<Border Grid.Row="2" Background="#F0F0F0" Height="60">
|
||||
<Grid>
|
||||
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,20,0">
|
||||
<Button x:Name="BtnResetToDefault"
|
||||
Content="重置为默认"
|
||||
@@ -196,11 +205,11 @@
|
||||
Content="保存设置"
|
||||
Width="100"
|
||||
Height="35"
|
||||
Background="#0066BF"
|
||||
Background="#3B82F6"
|
||||
Foreground="White"
|
||||
Click="BtnSave_Click"/>
|
||||
</ui:SimpleStackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -27,11 +27,8 @@ namespace Ink_Canvas.Windows
|
||||
_hotkeyManager = hotkeyManager;
|
||||
_hotkeyItems = new Dictionary<string, HotkeyItem>();
|
||||
|
||||
// 设置窗口属性以避免与主窗口置顶维护冲突
|
||||
// 设置窗口属性
|
||||
SetupWindowProperties();
|
||||
|
||||
// 隐藏主窗口的设置页面
|
||||
HideMainWindowSettings();
|
||||
InitializeHotkeyItems();
|
||||
|
||||
// 延迟加载快捷键,确保快捷键管理器已完全初始化
|
||||
@@ -62,21 +59,17 @@ namespace Ink_Canvas.Windows
|
||||
|
||||
#region Private Methods
|
||||
/// <summary>
|
||||
/// 设置窗口属性以避免与主窗口置顶维护冲突
|
||||
/// 设置窗口属性
|
||||
/// </summary>
|
||||
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
|
||||
/// <summary>
|
||||
/// 隐藏主窗口的设置页面
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 显示主窗口的设置页面
|
||||
/// </summary>
|
||||
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
|
||||
/// <summary>
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 标题栏拖拽事件
|
||||
/// </summary>
|
||||
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
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
Title="插件管理" Height="550" Width="800"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
ResizeMode="CanResize"
|
||||
WindowStyle="None"
|
||||
AllowsTransparency="True"
|
||||
Background="#F9F9F9">
|
||||
|
||||
<Window.Resources>
|
||||
@@ -27,7 +29,8 @@
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 标题栏 -->
|
||||
<Border Grid.Row="0" Background="{DynamicResource SystemAccentColorLight1}" Height="60">
|
||||
<Border Grid.Row="0" Background="{DynamicResource SystemAccentColorLight1}" Height="60"
|
||||
MouseLeftButtonDown="TitleBar_MouseLeftButtonDown">
|
||||
<Grid>
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="20,0,0,0">
|
||||
<TextBlock Text="插件管理" FontSize="22" FontWeight="SemiBold" Foreground="White" VerticalAlignment="Center"/>
|
||||
|
||||
@@ -624,6 +624,30 @@ namespace Ink_Canvas.Windows
|
||||
// 直接关闭窗口,窗口关闭事件会处理配置保存
|
||||
Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 标题栏拖拽事件
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user