improve:墨迹选择
This commit is contained in:
@@ -3418,10 +3418,12 @@
|
|||||||
ManipulationStarting="GridInkCanvasSelectionCover_ManipulationStarting"
|
ManipulationStarting="GridInkCanvasSelectionCover_ManipulationStarting"
|
||||||
ManipulationCompleted="GridInkCanvasSelectionCover_ManipulationCompleted"
|
ManipulationCompleted="GridInkCanvasSelectionCover_ManipulationCompleted"
|
||||||
ManipulationDelta="GridInkCanvasSelectionCover_ManipulationDelta"
|
ManipulationDelta="GridInkCanvasSelectionCover_ManipulationDelta"
|
||||||
PreviewTouchDown="GridInkCanvasSelectionCover_PreviewTouchDown"
|
PreviewTouchDown="GridInkCanvasSelectionCover_PreviewTouchDown"
|
||||||
PreviewTouchUp="GridInkCanvasSelectionCover_PreviewTouchUp"
|
PreviewTouchUp="GridInkCanvasSelectionCover_PreviewTouchUp"
|
||||||
TouchDown="GridInkCanvasSelectionCover_TouchDown"
|
PreviewTouchMove="GridInkCanvasSelectionCover_PreviewTouchMove"
|
||||||
TouchUp="GridInkCanvasSelectionCover_TouchUp"
|
TouchDown="GridInkCanvasSelectionCover_TouchDown"
|
||||||
|
TouchUp="GridInkCanvasSelectionCover_TouchUp"
|
||||||
|
TouchMove="GridInkCanvasSelectionCover_TouchMove"
|
||||||
Background="#01FFFFFF" Opacity="0.01" Visibility="Visible" Margin="1,0,-1,0" />
|
Background="#01FFFFFF" Opacity="0.01" Visibility="Visible" Margin="1,0,-1,0" />
|
||||||
<Border Name="BorderStrokeSelectionControl"
|
<Border Name="BorderStrokeSelectionControl"
|
||||||
HorizontalAlignment="Left" VerticalAlignment="Top" Margin="800,900,0,0"
|
HorizontalAlignment="Left" VerticalAlignment="Top" Margin="800,900,0,0"
|
||||||
|
|||||||
@@ -281,25 +281,19 @@ namespace Ink_Canvas
|
|||||||
BorderImageSelectionControl.Visibility = Visibility.Visible;
|
BorderImageSelectionControl.Visibility = Visibility.Visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 隐藏笔画选择工具栏
|
// 墨迹选择工具栏通过GridInkCanvasSelectionCover的可见性来控制
|
||||||
if (BorderStrokeSelectionControl != null)
|
// 不需要直接设置BorderStrokeSelectionControl.Visibility
|
||||||
{
|
|
||||||
BorderStrokeSelectionControl.Visibility = Visibility.Collapsed;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 显示笔画选择工具栏
|
|
||||||
if (BorderStrokeSelectionControl != null)
|
|
||||||
{
|
|
||||||
BorderStrokeSelectionControl.Visibility = Visibility.Visible;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 隐藏图片选择工具栏
|
// 隐藏图片选择工具栏
|
||||||
if (BorderImageSelectionControl != null)
|
if (BorderImageSelectionControl != null)
|
||||||
{
|
{
|
||||||
BorderImageSelectionControl.Visibility = Visibility.Collapsed;
|
BorderImageSelectionControl.Visibility = Visibility.Collapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 墨迹选择工具栏通过GridInkCanvasSelectionCover的可见性来控制
|
||||||
|
// 不需要直接设置BorderStrokeSelectionControl.Visibility
|
||||||
}
|
}
|
||||||
|
|
||||||
// 确保选择框不显示,避免蓝色边框
|
// 确保选择框不显示,避免蓝色边框
|
||||||
@@ -313,8 +307,8 @@ namespace Ink_Canvas
|
|||||||
{
|
{
|
||||||
// 清除当前选择
|
// 清除当前选择
|
||||||
inkCanvas.Select(new StrokeCollection());
|
inkCanvas.Select(new StrokeCollection());
|
||||||
// 设置编辑模式为非选择模式
|
// 保持选择模式,这样用户可以直接点击墨迹来选择
|
||||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
inkCanvas.EditingMode = InkCanvasEditingMode.Select;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,16 +317,14 @@ namespace Ink_Canvas
|
|||||||
{
|
{
|
||||||
// 去除选中效果
|
// 去除选中效果
|
||||||
|
|
||||||
// 隐藏所有选择工具栏
|
// 隐藏图片选择工具栏
|
||||||
if (BorderImageSelectionControl != null)
|
if (BorderImageSelectionControl != null)
|
||||||
{
|
{
|
||||||
BorderImageSelectionControl.Visibility = Visibility.Collapsed;
|
BorderImageSelectionControl.Visibility = Visibility.Collapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BorderStrokeSelectionControl != null)
|
// 墨迹选择工具栏通过GridInkCanvasSelectionCover的可见性来控制
|
||||||
{
|
// 不需要直接设置BorderStrokeSelectionControl.Visibility
|
||||||
BorderStrokeSelectionControl.Visibility = Visibility.Collapsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 确保选择框隐藏
|
// 确保选择框隐藏
|
||||||
if (GridInkCanvasSelectionCover != null)
|
if (GridInkCanvasSelectionCover != null)
|
||||||
@@ -340,7 +332,11 @@ namespace Ink_Canvas
|
|||||||
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
|
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 确保InkCanvas处于选择模式,这样用户可以直接点击墨迹来选择
|
||||||
|
if (inkCanvas != null)
|
||||||
|
{
|
||||||
|
inkCanvas.EditingMode = InkCanvasEditingMode.Select;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 应用矩阵变换到元素
|
// 应用矩阵变换到元素
|
||||||
|
|||||||
@@ -383,7 +383,29 @@ namespace Ink_Canvas
|
|||||||
{
|
{
|
||||||
if (isProgramChangeStrokeSelection) return;
|
if (isProgramChangeStrokeSelection) return;
|
||||||
|
|
||||||
// 检查是否有图片元素被选中
|
// 优先检查墨迹选择状态
|
||||||
|
if (inkCanvas.GetSelectedStrokes().Count > 0)
|
||||||
|
{
|
||||||
|
// 有墨迹被选中,清除图片选择状态
|
||||||
|
if (currentSelectedElement != null)
|
||||||
|
{
|
||||||
|
currentSelectedElement = null;
|
||||||
|
// 隐藏图片选择工具栏
|
||||||
|
if (BorderImageSelectionControl != null)
|
||||||
|
{
|
||||||
|
BorderImageSelectionControl.Visibility = Visibility.Collapsed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 显示墨迹选择栏
|
||||||
|
GridInkCanvasSelectionCover.Visibility = Visibility.Visible;
|
||||||
|
BorderStrokeSelectionClone.Background = Brushes.Transparent;
|
||||||
|
isStrokeSelectionCloneOn = false;
|
||||||
|
updateBorderStrokeSelectionControlLocation();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查是否有图片元素被选中(通过InkCanvas的选中元素)
|
||||||
var selectedElements = inkCanvas.GetSelectedElements();
|
var selectedElements = inkCanvas.GetSelectedElements();
|
||||||
bool hasImageElement = selectedElements.Any(element => element is Image);
|
bool hasImageElement = selectedElements.Any(element => element is Image);
|
||||||
|
|
||||||
@@ -394,17 +416,15 @@ namespace Ink_Canvas
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inkCanvas.GetSelectedStrokes().Count == 0)
|
// 检查是否有图片元素被选中(通过currentSelectedElement)
|
||||||
|
if (currentSelectedElement != null && currentSelectedElement is Image)
|
||||||
{
|
{
|
||||||
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
|
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
// 没有选中任何内容,隐藏选择框
|
||||||
GridInkCanvasSelectionCover.Visibility = Visibility.Visible;
|
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
|
||||||
BorderStrokeSelectionClone.Background = Brushes.Transparent;
|
|
||||||
isStrokeSelectionCloneOn = false;
|
|
||||||
updateBorderStrokeSelectionControlLocation();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -492,18 +512,11 @@ namespace Ink_Canvas
|
|||||||
strokes = StrokesSelectionClone;
|
strokes = StrokesSelectionClone;
|
||||||
else if (Settings.Gesture.IsEnableTwoFingerRotationOnSelection)
|
else if (Settings.Gesture.IsEnableTwoFingerRotationOnSelection)
|
||||||
m.RotateAt(rotate, center.X, center.Y); // 旋转
|
m.RotateAt(rotate, center.X, center.Y); // 旋转
|
||||||
|
|
||||||
|
// 应用变换到选中的墨迹
|
||||||
foreach (var stroke in strokes)
|
foreach (var stroke in strokes)
|
||||||
{
|
{
|
||||||
stroke.Transform(m, false);
|
stroke.Transform(m, false);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
stroke.DrawingAttributes.Width *= md.Scale.X;
|
|
||||||
stroke.DrawingAttributes.Height *= md.Scale.Y;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateBorderStrokeSelectionControlLocation();
|
updateBorderStrokeSelectionControlLocation();
|
||||||
@@ -522,6 +535,60 @@ namespace Ink_Canvas
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void GridInkCanvasSelectionCover_TouchMove(object sender, TouchEventArgs e)
|
||||||
|
{
|
||||||
|
// 处理触摸移动事件 - 用于拖动选中的墨迹
|
||||||
|
if (inkCanvas.GetSelectedStrokes().Count > 0 && dec.Count == 1)
|
||||||
|
{
|
||||||
|
var currentTouchPoint = e.GetTouchPoint(inkCanvas).Position;
|
||||||
|
var delta = currentTouchPoint - lastTouchPointOnGridInkCanvasCover;
|
||||||
|
|
||||||
|
// 创建变换矩阵
|
||||||
|
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 void GridInkCanvasSelectionCover_PreviewTouchMove(object sender, TouchEventArgs e)
|
||||||
|
{
|
||||||
|
// 预览触摸移动事件 - 用于更精确的触摸处理
|
||||||
|
if (inkCanvas.GetSelectedStrokes().Count > 0 && dec.Count == 1)
|
||||||
|
{
|
||||||
|
var currentTouchPoint = e.GetTouchPoint(inkCanvas).Position;
|
||||||
|
var delta = currentTouchPoint - lastTouchPointOnGridInkCanvasCover;
|
||||||
|
|
||||||
|
// 创建变换矩阵
|
||||||
|
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 Point lastTouchPointOnGridInkCanvasCover = new Point(0, 0);
|
||||||
|
|
||||||
private void GridInkCanvasSelectionCover_PreviewTouchDown(object sender, TouchEventArgs e)
|
private void GridInkCanvasSelectionCover_PreviewTouchDown(object sender, TouchEventArgs e)
|
||||||
@@ -532,7 +599,7 @@ namespace Ink_Canvas
|
|||||||
{
|
{
|
||||||
var touchPoint = e.GetTouchPoint(null);
|
var touchPoint = e.GetTouchPoint(null);
|
||||||
centerPoint = touchPoint.Position;
|
centerPoint = touchPoint.Position;
|
||||||
lastTouchPointOnGridInkCanvasCover = touchPoint.Position;
|
lastTouchPointOnGridInkCanvasCover = e.GetTouchPoint(inkCanvas).Position;
|
||||||
|
|
||||||
// 检查是否有选中的墨迹
|
// 检查是否有选中的墨迹
|
||||||
if (inkCanvas.GetSelectedStrokes().Count > 0)
|
if (inkCanvas.GetSelectedStrokes().Count > 0)
|
||||||
@@ -548,7 +615,7 @@ namespace Ink_Canvas
|
|||||||
touchPosition.Y <= selectionBounds.Bottom)
|
touchPosition.Y <= selectionBounds.Bottom)
|
||||||
{
|
{
|
||||||
// 只有在选择框边界内才允许拖动
|
// 只有在选择框边界内才允许拖动
|
||||||
// 这里可以添加触摸拖动的逻辑
|
// 触摸拖动状态已通过TouchMove事件处理
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user