代码清理
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using Ink_Canvas.Helpers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -8,7 +9,6 @@ using System.Windows.Ink;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
using Ink_Canvas.Helpers;
|
||||
using Point = System.Windows.Point;
|
||||
|
||||
namespace Ink_Canvas
|
||||
@@ -113,14 +113,14 @@ namespace Ink_Canvas
|
||||
var touchPoint = e.GetTouchPoint(this);
|
||||
var floatingBarBounds = ViewboxFloatingBar.TransformToAncestor(this).TransformBounds(
|
||||
new Rect(0, 0, ViewboxFloatingBar.ActualWidth, ViewboxFloatingBar.ActualHeight));
|
||||
|
||||
|
||||
// 如果触摸发生在浮动栏区域,不阻止事件传播,让浮动栏按钮能够接收触摸事件
|
||||
if (floatingBarBounds.Contains(touchPoint.Position))
|
||||
{
|
||||
// 不设置 ViewboxFloatingBar.IsHitTestVisible = false,让浮动栏按钮能够接收触摸事件
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint
|
||||
|| inkCanvas.EditingMode == InkCanvasEditingMode.EraseByStroke
|
||||
|| inkCanvas.EditingMode == InkCanvasEditingMode.Select) return;
|
||||
@@ -142,7 +142,7 @@ namespace Ink_Canvas
|
||||
// 只保留普通橡皮逻辑
|
||||
TouchDownPointsList[e.TouchDevice.Id] = InkCanvasEditingMode.None;
|
||||
inkCanvas.EraserShape = new EllipseStylusShape(50, 50);
|
||||
if (inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint
|
||||
if (inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint
|
||||
&& inkCanvas.EditingMode != InkCanvasEditingMode.EraseByStroke)
|
||||
{
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
@@ -155,16 +155,16 @@ namespace Ink_Canvas
|
||||
var stylusPoint = e.GetPosition(this);
|
||||
var floatingBarBounds = ViewboxFloatingBar.TransformToAncestor(this).TransformBounds(
|
||||
new Rect(0, 0, ViewboxFloatingBar.ActualWidth, ViewboxFloatingBar.ActualHeight));
|
||||
|
||||
|
||||
// 如果手写笔点击发生在浮动栏区域,不阻止事件传播,让浮动栏按钮能够接收手写笔事件
|
||||
if (floatingBarBounds.Contains(stylusPoint))
|
||||
{
|
||||
// 不设置 ViewboxFloatingBar.IsHitTestVisible = false,让浮动栏按钮能够接收手写笔事件
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
LogHelper.WriteLogToFile($"MainWindow_StylusDown 被调用,笔尾状态: {e.StylusDevice.Inverted}, 当前 drawingShapeMode: {drawingShapeMode}, 当前 EditingMode: {inkCanvas.EditingMode}");
|
||||
|
||||
|
||||
// 新增:根据是否为笔尾自动切换橡皮擦/画笔模式
|
||||
if (e.StylusDevice.Inverted)
|
||||
{
|
||||
@@ -232,14 +232,14 @@ namespace Ink_Canvas
|
||||
try
|
||||
{
|
||||
LogHelper.WriteLogToFile($"MainWindow_StylusUp 被调用,EditingMode: {inkCanvas.EditingMode}, EnableInkFade: {Settings.Canvas.EnableInkFade}");
|
||||
|
||||
|
||||
var stroke = GetStrokeVisual(e.StylusDevice.Id).Stroke;
|
||||
LogHelper.WriteLogToFile($"获取到墨迹,StylusPoints数量: {stroke.StylusPoints.Count}");
|
||||
|
||||
|
||||
// 正常模式:添加到画布并参与墨迹纠正
|
||||
// 墨迹渐隐功能现在在 StrokeCollected 事件中统一处理所有输入方式
|
||||
LogHelper.WriteLogToFile("StylusUp: 添加墨迹到画布");
|
||||
|
||||
|
||||
inkCanvas.Strokes.Add(stroke);
|
||||
await Task.Delay(5); // 避免渲染墨迹完成前预览墨迹被删除导致墨迹闪烁
|
||||
inkCanvas.Children.Remove(GetVisualCanvas(e.StylusDevice.Id));
|
||||
@@ -351,14 +351,14 @@ namespace Ink_Canvas
|
||||
var touchPoint = e.GetTouchPoint(this);
|
||||
var floatingBarBounds = ViewboxFloatingBar.TransformToAncestor(this).TransformBounds(
|
||||
new Rect(0, 0, ViewboxFloatingBar.ActualWidth, ViewboxFloatingBar.ActualHeight));
|
||||
|
||||
|
||||
// 如果触摸发生在浮动栏区域,不阻止事件传播,让浮动栏按钮能够接收触摸事件
|
||||
if (floatingBarBounds.Contains(touchPoint.Position))
|
||||
{
|
||||
// 不设置 ViewboxFloatingBar.IsHitTestVisible = false,让浮动栏按钮能够接收触摸事件
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
SetCursorBasedOnEditingMode(inkCanvas);
|
||||
inkCanvas.CaptureTouch(e.TouchDevice);
|
||||
|
||||
@@ -411,14 +411,14 @@ namespace Ink_Canvas
|
||||
var touchPoint = e.GetTouchPoint(this);
|
||||
var floatingBarBounds = ViewboxFloatingBar.TransformToAncestor(this).TransformBounds(
|
||||
new Rect(0, 0, ViewboxFloatingBar.ActualWidth, ViewboxFloatingBar.ActualHeight));
|
||||
|
||||
|
||||
// 如果触摸发生在浮动栏区域,不阻止事件传播,让浮动栏按钮能够接收触摸事件
|
||||
if (floatingBarBounds.Contains(touchPoint.Position))
|
||||
{
|
||||
// 不设置 ViewboxFloatingBar.IsHitTestVisible = false,让浮动栏按钮能够接收触摸事件
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 橡皮状态下不做任何切换,直接return,保证橡皮可持续
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint
|
||||
|| inkCanvas.EditingMode == InkCanvasEditingMode.EraseByStroke)
|
||||
@@ -435,7 +435,7 @@ namespace Ink_Canvas
|
||||
inkCanvas.CaptureTouch(e.TouchDevice);
|
||||
ViewboxFloatingBar.IsHitTestVisible = false;
|
||||
BlackboardUIGridForInkReplay.IsHitTestVisible = false;
|
||||
|
||||
|
||||
// 修复:几何绘制模式下,只记录几何绘制的起点,不记录触摸轨迹
|
||||
if (dec.Count == 0)
|
||||
{
|
||||
@@ -460,108 +460,108 @@ namespace Ink_Canvas
|
||||
dec.Add(e.TouchDevice.Id);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 非几何绘制模式下的正常触摸处理
|
||||
SetCursorBasedOnEditingMode(inkCanvas);
|
||||
inkCanvas.CaptureTouch(e.TouchDevice);
|
||||
ViewboxFloatingBar.IsHitTestVisible = false;
|
||||
BlackboardUIGridForInkReplay.IsHitTestVisible = false;
|
||||
dec.Add(e.TouchDevice.Id);
|
||||
|
||||
// Palm Eraser 逻辑 - 优化:改进手掌判定条件,提高精度
|
||||
if (Settings.Canvas.EnablePalmEraser && dec.Count >= 2 && !isPalmEraserActive && !palmEraserTouchDownHandled)
|
||||
{
|
||||
var bounds = e.GetTouchPoint(inkCanvas).Bounds;
|
||||
|
||||
// 根据敏感度设置调整判定参数
|
||||
double palmThreshold;
|
||||
double aspectRatioThreshold;
|
||||
int minTouchPoints;
|
||||
|
||||
switch (Settings.Canvas.PalmEraserSensitivity)
|
||||
{
|
||||
case 0: // 低敏感度 - 更严格的判定
|
||||
palmThreshold = 80;
|
||||
aspectRatioThreshold = 0.4;
|
||||
minTouchPoints = 4;
|
||||
break;
|
||||
case 1: // 中敏感度 - 平衡的判定
|
||||
palmThreshold = 60;
|
||||
aspectRatioThreshold = 0.3;
|
||||
minTouchPoints = 3;
|
||||
break;
|
||||
case 2: // 高敏感度 - 较宽松的判定
|
||||
default:
|
||||
palmThreshold = 50;
|
||||
aspectRatioThreshold = 0.25;
|
||||
minTouchPoints = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
// 计算宽高比
|
||||
double aspectRatio = Math.Min(bounds.Width, bounds.Height) / Math.Max(bounds.Width, bounds.Height);
|
||||
|
||||
// 更严格的手掌判定条件
|
||||
bool isLargeTouch = bounds.Width >= palmThreshold && bounds.Height >= palmThreshold;
|
||||
bool isPalmLikeShape = aspectRatio >= aspectRatioThreshold;
|
||||
bool hasMultipleTouchPoints = dec.Count >= minTouchPoints;
|
||||
|
||||
if (isLargeTouch && isPalmLikeShape && hasMultipleTouchPoints)
|
||||
{
|
||||
// 记录当前编辑模式和高光状态
|
||||
palmEraserLastEditingMode = inkCanvas.EditingMode;
|
||||
palmEraserLastIsHighlighter = drawingAttributes.IsHighlighter;
|
||||
|
||||
// 记录参与手掌擦的触摸点ID
|
||||
palmEraserTouchIds.Clear();
|
||||
foreach (int touchId in dec)
|
||||
{
|
||||
palmEraserTouchIds.Add(touchId);
|
||||
}
|
||||
|
||||
// 切换为橡皮擦
|
||||
EraserIcon_Click(null, null);
|
||||
isPalmEraserActive = true;
|
||||
palmEraserActivationTime = DateTime.Now; // 记录激活时间
|
||||
palmEraserTouchDownHandled = true; // 标记已处理
|
||||
|
||||
// 启动恢复定时器,防止卡死
|
||||
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}");
|
||||
}
|
||||
}
|
||||
|
||||
// 设备1个的时候,记录中心点
|
||||
if (dec.Count == 1)
|
||||
{
|
||||
touchPoint = e.GetTouchPoint(inkCanvas);
|
||||
centerPoint = touchPoint.Position;
|
||||
|
||||
// 修复:只允许在此处赋值iniP,防止TouchMove等其他地方覆盖,保证几何绘制起点一致
|
||||
if (drawingShapeMode != 0)
|
||||
// Palm Eraser 逻辑 - 优化:改进手掌判定条件,提高精度
|
||||
if (Settings.Canvas.EnablePalmEraser && dec.Count >= 2 && !isPalmEraserActive && !palmEraserTouchDownHandled)
|
||||
{
|
||||
// 对于双曲线绘制,第一笔时记录起点,第二笔时不更新起点
|
||||
if (drawingShapeMode == 24 || drawingShapeMode == 25)
|
||||
var bounds = e.GetTouchPoint(inkCanvas).Bounds;
|
||||
|
||||
// 根据敏感度设置调整判定参数
|
||||
double palmThreshold;
|
||||
double aspectRatioThreshold;
|
||||
int minTouchPoints;
|
||||
|
||||
switch (Settings.Canvas.PalmEraserSensitivity)
|
||||
{
|
||||
// 双曲线绘制:第一笔记录起点,第二笔保持第一笔的起点
|
||||
if (drawMultiStepShapeCurrentStep == 0)
|
||||
case 0: // 低敏感度 - 更严格的判定
|
||||
palmThreshold = 80;
|
||||
aspectRatioThreshold = 0.4;
|
||||
minTouchPoints = 4;
|
||||
break;
|
||||
case 1: // 中敏感度 - 平衡的判定
|
||||
palmThreshold = 60;
|
||||
aspectRatioThreshold = 0.3;
|
||||
minTouchPoints = 3;
|
||||
break;
|
||||
case 2: // 高敏感度 - 较宽松的判定
|
||||
default:
|
||||
palmThreshold = 50;
|
||||
aspectRatioThreshold = 0.25;
|
||||
minTouchPoints = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
// 计算宽高比
|
||||
double aspectRatio = Math.Min(bounds.Width, bounds.Height) / Math.Max(bounds.Width, bounds.Height);
|
||||
|
||||
// 更严格的手掌判定条件
|
||||
bool isLargeTouch = bounds.Width >= palmThreshold && bounds.Height >= palmThreshold;
|
||||
bool isPalmLikeShape = aspectRatio >= aspectRatioThreshold;
|
||||
bool hasMultipleTouchPoints = dec.Count >= minTouchPoints;
|
||||
|
||||
if (isLargeTouch && isPalmLikeShape && hasMultipleTouchPoints)
|
||||
{
|
||||
// 记录当前编辑模式和高光状态
|
||||
palmEraserLastEditingMode = inkCanvas.EditingMode;
|
||||
palmEraserLastIsHighlighter = drawingAttributes.IsHighlighter;
|
||||
|
||||
// 记录参与手掌擦的触摸点ID
|
||||
palmEraserTouchIds.Clear();
|
||||
foreach (int touchId in dec)
|
||||
{
|
||||
palmEraserTouchIds.Add(touchId);
|
||||
}
|
||||
|
||||
// 切换为橡皮擦
|
||||
EraserIcon_Click(null, null);
|
||||
isPalmEraserActive = true;
|
||||
palmEraserActivationTime = DateTime.Now; // 记录激活时间
|
||||
palmEraserTouchDownHandled = true; // 标记已处理
|
||||
|
||||
// 启动恢复定时器,防止卡死
|
||||
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}");
|
||||
}
|
||||
}
|
||||
|
||||
// 设备1个的时候,记录中心点
|
||||
if (dec.Count == 1)
|
||||
{
|
||||
touchPoint = e.GetTouchPoint(inkCanvas);
|
||||
centerPoint = touchPoint.Position;
|
||||
|
||||
// 修复:只允许在此处赋值iniP,防止TouchMove等其他地方覆盖,保证几何绘制起点一致
|
||||
if (drawingShapeMode != 0)
|
||||
{
|
||||
// 对于双曲线绘制,第一笔时记录起点,第二笔时不更新起点
|
||||
if (drawingShapeMode == 24 || drawingShapeMode == 25)
|
||||
{
|
||||
// 双曲线绘制:第一笔记录起点,第二笔保持第一笔的起点
|
||||
if (drawMultiStepShapeCurrentStep == 0)
|
||||
{
|
||||
iniP = touchPoint.Position;
|
||||
}
|
||||
// 第二笔时不更新iniP,保持第一笔的起点
|
||||
}
|
||||
else
|
||||
{
|
||||
// 其他图形正常记录起点
|
||||
iniP = touchPoint.Position;
|
||||
}
|
||||
// 第二笔时不更新iniP,保持第一笔的起点
|
||||
}
|
||||
else
|
||||
{
|
||||
// 其他图形正常记录起点
|
||||
iniP = touchPoint.Position;
|
||||
}
|
||||
}
|
||||
|
||||
// 记录第一根手指点击时的 StrokeCollection
|
||||
lastTouchDownStrokeCollection = inkCanvas.Strokes.Clone();
|
||||
}
|
||||
// 记录第一根手指点击时的 StrokeCollection
|
||||
lastTouchDownStrokeCollection = inkCanvas.Strokes.Clone();
|
||||
}
|
||||
//设备两个及两个以上,将画笔功能关闭
|
||||
if (dec.Count > 1 || isSingleFingerDragMode || !Settings.Gesture.IsEnableTwoFingerGesture)
|
||||
{
|
||||
@@ -571,7 +571,7 @@ namespace Ink_Canvas
|
||||
lastInkCanvasEditingMode = inkCanvas.EditingMode;
|
||||
// 修复:几何绘制模式下禁止切回Ink
|
||||
if (inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint
|
||||
&& inkCanvas.EditingMode != InkCanvasEditingMode.EraseByStroke
|
||||
&& inkCanvas.EditingMode != InkCanvasEditingMode.EraseByStroke
|
||||
&& drawingShapeMode == 0)
|
||||
{
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
@@ -592,19 +592,19 @@ namespace Ink_Canvas
|
||||
|
||||
// Palm Eraser 逻辑:优化状态恢复机制
|
||||
dec.Remove(e.TouchDevice.Id);
|
||||
|
||||
|
||||
// 如果是手掌擦的触摸点,从记录中移除
|
||||
if (palmEraserTouchIds.Contains(e.TouchDevice.Id))
|
||||
{
|
||||
palmEraserTouchIds.Remove(e.TouchDevice.Id);
|
||||
}
|
||||
|
||||
|
||||
// 当所有手掌擦触摸点都抬起时,恢复原编辑模式
|
||||
if (isPalmEraserActive && palmEraserTouchIds.Count == 0)
|
||||
{
|
||||
// 恢复高光状态
|
||||
drawingAttributes.IsHighlighter = palmEraserLastIsHighlighter;
|
||||
|
||||
|
||||
// 恢复编辑模式 - 优化:改进状态恢复逻辑
|
||||
try
|
||||
{
|
||||
@@ -623,7 +623,7 @@ namespace Ink_Canvas
|
||||
inkCanvas.EditingMode = palmEraserLastEditingMode;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
LogHelper.WriteLogToFile($"Palm eraser recovered to mode: {palmEraserLastEditingMode}");
|
||||
}
|
||||
}
|
||||
@@ -633,25 +633,25 @@ namespace Ink_Canvas
|
||||
LogHelper.WriteLogToFile($"Palm eraser recovery failed: {ex.Message}, forcing to Ink mode", LogHelper.LogType.Error);
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
|
||||
}
|
||||
|
||||
|
||||
// 重置手掌擦状态
|
||||
isPalmEraserActive = false;
|
||||
palmEraserTouchDownHandled = false;
|
||||
palmEraserTouchIds.Clear();
|
||||
|
||||
|
||||
// 停止恢复定时器
|
||||
StopPalmEraserRecoveryTimer();
|
||||
|
||||
|
||||
// 确保触摸事件能正常响应
|
||||
inkCanvas.IsHitTestVisible = true;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
|
||||
|
||||
ViewboxFloatingBar.IsHitTestVisible = true;
|
||||
BlackboardUIGridForInkReplay.IsHitTestVisible = true;
|
||||
|
||||
|
||||
LogHelper.WriteLogToFile("Palm eraser state reset completed");
|
||||
}
|
||||
|
||||
|
||||
// 新增:超时检测 - 如果手掌擦激活时间过长,强制重置状态
|
||||
if (isPalmEraserActive)
|
||||
{
|
||||
@@ -659,7 +659,7 @@ namespace Ink_Canvas
|
||||
if (timeSinceActivation.TotalMilliseconds > PALM_ERASER_TIMEOUT_MS)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"Palm eraser timeout detected ({timeSinceActivation.TotalMilliseconds}ms), forcing recovery", LogHelper.LogType.Warning);
|
||||
|
||||
|
||||
// 强制恢复状态
|
||||
try
|
||||
{
|
||||
@@ -684,20 +684,20 @@ namespace Ink_Canvas
|
||||
LogHelper.WriteLogToFile($"Palm eraser timeout recovery failed: {ex.Message}, forcing to Ink mode", LogHelper.LogType.Error);
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
|
||||
}
|
||||
|
||||
|
||||
// 重置所有手掌擦状态
|
||||
isPalmEraserActive = false;
|
||||
palmEraserTouchDownHandled = false;
|
||||
palmEraserTouchIds.Clear();
|
||||
inkCanvas.IsHitTestVisible = true;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
|
||||
|
||||
ViewboxFloatingBar.IsHitTestVisible = true;
|
||||
BlackboardUIGridForInkReplay.IsHitTestVisible = true;
|
||||
|
||||
|
||||
// 停止恢复定时器
|
||||
StopPalmEraserRecoveryTimer();
|
||||
|
||||
|
||||
LogHelper.WriteLogToFile("Palm eraser timeout recovery completed");
|
||||
}
|
||||
}
|
||||
@@ -760,7 +760,7 @@ namespace Ink_Canvas
|
||||
{
|
||||
inkCanvas.EditingMode = lastInkCanvasEditingMode;
|
||||
}
|
||||
|
||||
|
||||
// 修复:确保手掌擦除后触摸事件能正常响应
|
||||
if (isPalmEraserActive)
|
||||
{
|
||||
@@ -770,7 +770,7 @@ namespace Ink_Canvas
|
||||
palmEraserTouchIds.Clear(); // 确保清空触摸点ID
|
||||
inkCanvas.IsHitTestVisible = true;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
|
||||
|
||||
ViewboxFloatingBar.IsHitTestVisible = true;
|
||||
BlackboardUIGridForInkReplay.IsHitTestVisible = true;
|
||||
}
|
||||
@@ -799,7 +799,7 @@ namespace Ink_Canvas
|
||||
{
|
||||
if (e.Manipulators.Count() != 0) return;
|
||||
// 修复:几何绘制模式下不自动切换到Ink模式,避免触摸轨迹被收集
|
||||
if (drawingShapeMode == 0
|
||||
if (drawingShapeMode == 0
|
||||
&& inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint
|
||||
&& inkCanvas.EditingMode != InkCanvasEditingMode.EraseByStroke)
|
||||
{
|
||||
@@ -924,7 +924,7 @@ namespace Ink_Canvas
|
||||
inkCanvas.TouchDown -= MainWindow_TouchDown;
|
||||
inkCanvas.TouchDown += Main_Grid_TouchDown;
|
||||
// 修复:几何绘制模式下不自动切换到Ink模式,避免触摸轨迹被收集
|
||||
if (inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint
|
||||
if (inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint
|
||||
&& inkCanvas.EditingMode != InkCanvasEditingMode.EraseByStroke
|
||||
&& drawingShapeMode == 0)
|
||||
{
|
||||
@@ -958,7 +958,7 @@ namespace Ink_Canvas
|
||||
inkCanvas.TouchDown -= Main_Grid_TouchDown;
|
||||
// 修复:几何绘制模式下不自动切换到Ink模式,避免触摸轨迹被收集
|
||||
if (inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint
|
||||
&& inkCanvas.EditingMode != InkCanvasEditingMode.EraseByStroke
|
||||
&& inkCanvas.EditingMode != InkCanvasEditingMode.EraseByStroke
|
||||
&& drawingShapeMode == 0)
|
||||
{
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
@@ -976,7 +976,7 @@ namespace Ink_Canvas
|
||||
ToggleSwitchEnablePalmEraser.IsOn = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 启动手掌擦恢复定时器,防止卡死状态
|
||||
/// </summary>
|
||||
@@ -988,10 +988,10 @@ namespace Ink_Canvas
|
||||
palmEraserRecoveryTimer.Interval = TimeSpan.FromMilliseconds(1000); // 每秒检查一次
|
||||
palmEraserRecoveryTimer.Tick += PalmEraserRecoveryTimer_Tick;
|
||||
}
|
||||
|
||||
|
||||
palmEraserRecoveryTimer.Start();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 停止手掌擦恢复定时器
|
||||
/// </summary>
|
||||
@@ -1002,20 +1002,20 @@ namespace Ink_Canvas
|
||||
palmEraserRecoveryTimer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 手掌擦恢复定时器事件处理
|
||||
/// </summary>
|
||||
private void PalmEraserRecoveryTimer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
if (!isPalmEraserActive) return;
|
||||
|
||||
|
||||
// 检查是否超时
|
||||
var timeSinceActivation = DateTime.Now - palmEraserActivationTime;
|
||||
if (timeSinceActivation.TotalMilliseconds > PALM_ERASER_TIMEOUT_MS)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"Palm eraser recovery timer triggered, forcing recovery after {timeSinceActivation.TotalMilliseconds}ms", LogHelper.LogType.Warning);
|
||||
|
||||
|
||||
// 强制恢复状态
|
||||
try
|
||||
{
|
||||
@@ -1033,7 +1033,7 @@ namespace Ink_Canvas
|
||||
inkCanvas.EditingMode = palmEraserLastEditingMode;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
LogHelper.WriteLogToFile($"Palm eraser timer recovery to mode: {palmEraserLastEditingMode}");
|
||||
}
|
||||
}
|
||||
@@ -1042,20 +1042,20 @@ namespace Ink_Canvas
|
||||
LogHelper.WriteLogToFile($"Palm eraser recovery timer failed: {ex.Message}, forcing to Ink mode", LogHelper.LogType.Error);
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
|
||||
}
|
||||
|
||||
|
||||
// 重置所有手掌擦状态
|
||||
isPalmEraserActive = false;
|
||||
palmEraserTouchDownHandled = false;
|
||||
palmEraserTouchIds.Clear();
|
||||
inkCanvas.IsHitTestVisible = true;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
|
||||
|
||||
ViewboxFloatingBar.IsHitTestVisible = true;
|
||||
BlackboardUIGridForInkReplay.IsHitTestVisible = true;
|
||||
|
||||
|
||||
// 停止定时器
|
||||
StopPalmEraserRecoveryTimer();
|
||||
|
||||
|
||||
LogHelper.WriteLogToFile("Palm eraser timer recovery completed");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user