From 2f8c368eef1ac77c14adf36af0e6d65a2a1086ae Mon Sep 17 00:00:00 2001
From: doudou0720 <98651603+doudou0720@users.noreply.github.com>
Date: Mon, 16 Feb 2026 17:15:33 +0800
Subject: [PATCH] =?UTF-8?q?fix(Touch):=E6=B7=BB=E5=8A=A0=E6=8E=A7=E5=88=B6?=
=?UTF-8?q?=E7=82=B9=E8=A7=A6=E6=8E=A7=E6=94=AF=E6=8C=81=E4=BB=A5=E5=8F=8A?=
=?UTF-8?q?=E7=A7=BB=E5=8A=A8=E5=A2=A8=E8=BF=B9=E9=97=AE=E9=A2=98=20(#374)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* feat(MW_SelectionGestures.cs): 为缩放选择框添加触摸事件
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
* refactor(MW_SelectionGestures.cs): 清理PreviewTouch
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
* fix(MW_SelectionGestures.cs): 单指触摸时阻止缩放处理以允许拖动操作
当检测到单指触摸且存在选中笔迹时,直接返回以允许TouchMove处理拖动操作,避免与缩放手势冲突
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
---------
Signed-off-by: doudou0720 <98651603+doudou0720@users.noreply.github.com>
---
Ink Canvas/MainWindow.xaml | 33 ++--
.../MainWindow_cs/MW_SelectionGestures.cs | 174 +++++++++---------
2 files changed, 108 insertions(+), 99 deletions(-)
diff --git a/Ink Canvas/MainWindow.xaml b/Ink Canvas/MainWindow.xaml
index fc5b7f3b..f3555254 100644
--- a/Ink Canvas/MainWindow.xaml
+++ b/Ink Canvas/MainWindow.xaml
@@ -4451,12 +4451,9 @@
ManipulationStarting="GridInkCanvasSelectionCover_ManipulationStarting"
ManipulationCompleted="GridInkCanvasSelectionCover_ManipulationCompleted"
ManipulationDelta="GridInkCanvasSelectionCover_ManipulationDelta"
- PreviewTouchDown="GridInkCanvasSelectionCover_PreviewTouchDown"
- PreviewTouchUp="GridInkCanvasSelectionCover_PreviewTouchUp"
- PreviewTouchMove="GridInkCanvasSelectionCover_PreviewTouchMove"
- TouchDown="GridInkCanvasSelectionCover_TouchDown"
- TouchUp="GridInkCanvasSelectionCover_TouchUp"
- TouchMove="GridInkCanvasSelectionCover_TouchMove"
+ TouchDown="GridInkCanvasSelectionCover_TouchDown"
+ TouchUp="GridInkCanvasSelectionCover_TouchUp"
+ TouchMove="GridInkCanvasSelectionCover_TouchMove"
Background="#01FFFFFF" Opacity="0.01" Visibility="Visible" Margin="1,0,-1,0">
@@ -4474,23 +4471,31 @@
= 1)
{
+ // 单指时,让TouchMove处理拖动
+ if (dec.Count == 1 && inkCanvas.GetSelectedStrokes().Count > 0)
+ {
+ return;
+ }
+
bool disableScale = dec.Count >= 3;
var md = e.DeltaManipulation;
var trans = md.Translation; // 获得位移矢量
@@ -539,10 +545,51 @@ namespace Ink_Canvas
private void GridInkCanvasSelectionCover_TouchDown(object sender, TouchEventArgs e)
{
+ dec.Add(e.TouchDevice.Id);
+ //设备1个的时候,记录中心点
+ if (dec.Count == 1)
+ {
+ var touchPoint = e.GetTouchPoint(null);
+ centerPoint = touchPoint.Position;
+ lastTouchPointOnGridInkCanvasCover = touchPoint.Position;
+ }
}
private void GridInkCanvasSelectionCover_TouchUp(object sender, TouchEventArgs e)
{
+ dec.Remove(e.TouchDevice.Id);
+ if (dec.Count >= 1) return;
+ isProgramChangeStrokeSelection = false;
+
+ var touchUpPoint = e.GetTouchPoint(null).Position;
+ if (lastTouchPointOnGridInkCanvasCover == touchUpPoint)
+ {
+ var touchPointInCanvas = e.GetTouchPoint(inkCanvas).Position;
+ var selectionBounds = inkCanvas.GetSelectionBounds();
+
+ if (!(touchPointInCanvas.X < selectionBounds.Left) &&
+ !(touchPointInCanvas.Y < selectionBounds.Top) &&
+ !(touchPointInCanvas.X > selectionBounds.Right) &&
+ !(touchPointInCanvas.Y > selectionBounds.Bottom))
+ {
+ return;
+ }
+ isProgramChangeStrokeSelection = true;
+ inkCanvas.Select(new StrokeCollection());
+ GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
+ isProgramChangeStrokeSelection = false;
+ StrokesSelectionClone = new StrokeCollection();
+ }
+ else if (inkCanvas.GetSelectedStrokes().Count == 0)
+ {
+ GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
+ StrokesSelectionClone = new StrokeCollection();
+ }
+ else
+ {
+ GridInkCanvasSelectionCover.Visibility = Visibility.Visible;
+ StrokesSelectionClone = new StrokeCollection();
+ }
}
private void GridInkCanvasSelectionCover_TouchMove(object sender, TouchEventArgs e)
@@ -581,93 +628,8 @@ namespace Ink_Canvas
}
}
- private void GridInkCanvasSelectionCover_PreviewTouchMove(object sender, TouchEventArgs e)
- {
- // 预览触摸移动事件 - 用于更精确的触摸处理
- if (inkCanvas.GetSelectedStrokes().Count > 0 && dec.Count == 1)
- {
- var currentTouchPoint = e.GetTouchPoint(inkCanvas).Position;
-
- // 检查是否有有效的起始触摸点
- if (lastTouchPointOnGridInkCanvasCover != new Point(0, 0))
- {
- var delta = currentTouchPoint - lastTouchPointOnGridInkCanvasCover;
-
- // 只有当移动距离足够大时才进行拖动(避免微小移动造成的抖动)
- if (Math.Abs(delta.X) > 1 || Math.Abs(delta.Y) > 1)
- {
- // 创建变换矩阵
- var matrix = new Matrix();
- matrix.Translate(delta.X, delta.Y);
-
- // 对选中的墨迹应用变换
- var selectedStrokes = inkCanvas.GetSelectedStrokes();
- foreach (var stroke in selectedStrokes)
- {
- stroke.Transform(matrix, false);
- }
-
- // 更新选中栏位置
- updateBorderStrokeSelectionControlLocation();
-
- // 更新最后触摸点
- lastTouchPointOnGridInkCanvasCover = currentTouchPoint;
- }
- }
- }
- }
-
private Point lastTouchPointOnGridInkCanvasCover = new Point(0, 0);
- private void GridInkCanvasSelectionCover_PreviewTouchDown(object sender, TouchEventArgs e)
- {
- dec.Add(e.TouchDevice.Id);
- //设备1个的时候,记录中心点
- if (dec.Count == 1)
- {
- var touchPoint = e.GetTouchPoint(null);
- centerPoint = touchPoint.Position;
- lastTouchPointOnGridInkCanvasCover = touchPoint.Position;
- }
- }
-
- private void GridInkCanvasSelectionCover_PreviewTouchUp(object sender, TouchEventArgs e)
- {
- dec.Remove(e.TouchDevice.Id);
- if (dec.Count >= 1) return;
- isProgramChangeStrokeSelection = false;
-
- var touchUpPoint = e.GetTouchPoint(null).Position;
- if (lastTouchPointOnGridInkCanvasCover == touchUpPoint)
- {
- var touchPointInCanvas = e.GetTouchPoint(inkCanvas).Position;
- var selectionBounds = inkCanvas.GetSelectionBounds();
-
- if (!(touchPointInCanvas.X < selectionBounds.Left) &&
- !(touchPointInCanvas.Y < selectionBounds.Top) &&
- !(touchPointInCanvas.X > selectionBounds.Right) &&
- !(touchPointInCanvas.Y > selectionBounds.Bottom))
- {
- return;
- }
- isProgramChangeStrokeSelection = true;
- inkCanvas.Select(new StrokeCollection());
- GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
- isProgramChangeStrokeSelection = false;
- StrokesSelectionClone = new StrokeCollection();
- }
- else if (inkCanvas.GetSelectedStrokes().Count == 0)
- {
- GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
- StrokesSelectionClone = new StrokeCollection();
- }
- else
- {
- GridInkCanvasSelectionCover.Visibility = Visibility.Visible;
- StrokesSelectionClone = new StrokeCollection();
- }
- }
-
private void LassoSelect_Click(object sender, RoutedEventArgs e)
{
forceEraser = false;
@@ -818,6 +780,48 @@ namespace Ink_Canvas
}
}
+ private void SelectionHandle_TouchDown(object sender, TouchEventArgs e)
+ {
+ if (sender is Rectangle handle)
+ {
+ isResizing = true;
+ currentResizeHandle = handle.Name;
+ var touchPoint = e.GetTouchPoint(inkCanvas);
+ resizeStartPoint = touchPoint.Position;
+ originalSelectionBounds = inkCanvas.GetSelectionBounds();
+ e.Handled = true;
+ }
+ }
+
+ private void SelectionHandle_TouchMove(object sender, TouchEventArgs e)
+ {
+ if (!isResizing || !(sender is Rectangle handle)) return;
+
+ var touchPoint = e.GetTouchPoint(inkCanvas);
+ var currentPoint = touchPoint.Position;
+ var delta = new Point(currentPoint.X - resizeStartPoint.X, currentPoint.Y - resizeStartPoint.Y);
+
+ var newBounds = CalculateNewBounds(originalSelectionBounds, delta, currentResizeHandle);
+
+ // 应用新的边界到选中的墨迹
+ ApplyBoundsToStrokes(newBounds);
+
+ // 更新选择框显示
+ UpdateSelectionDisplay();
+
+ e.Handled = true;
+ }
+
+ private void SelectionHandle_TouchUp(object sender, TouchEventArgs e)
+ {
+ if (sender is Rectangle handle)
+ {
+ isResizing = false;
+ currentResizeHandle = "";
+ e.Handled = true;
+ }
+ }
+
private Rect CalculateNewBounds(Rect originalBounds, Point delta, string handleName)
{
var newBounds = originalBounds;