diff --git a/Ink Canvas/MainWindow_cs/MW_ElementsControls.cs b/Ink Canvas/MainWindow_cs/MW_ElementsControls.cs index 0daf4189..dae0a343 100644 --- a/Ink Canvas/MainWindow_cs/MW_ElementsControls.cs +++ b/Ink Canvas/MainWindow_cs/MW_ElementsControls.cs @@ -1334,6 +1334,90 @@ namespace Ink_Canvas } } + /// + /// 克隆墨迹集合 + /// + /// 要克隆的墨迹集合 + /// 克隆后的墨迹集合 + private StrokeCollection CloneStrokes(StrokeCollection strokes) + { + if (strokes == null || strokes.Count == 0) return new StrokeCollection(); + + try + { + // 创建墨迹集合的副本 + var clonedStrokes = strokes.Clone(); + + // 为每个墨迹添加位置偏移以避免重叠 + foreach (var stroke in clonedStrokes) + { + var offsetPoints = new StylusPointCollection(); + foreach (var point in stroke.StylusPoints) + { + offsetPoints.Add(new StylusPoint(point.X + 20, point.Y + 20, point.PressureFactor)); + } + stroke.StylusPoints = offsetPoints; + } + + // 添加到画布 + inkCanvas.Strokes.Add(clonedStrokes); + + // 提交到时间机器以支持撤销 + timeMachine.CommitStrokeUserInputHistory(clonedStrokes); + + LogHelper.WriteLogToFile($"墨迹克隆完成: {clonedStrokes.Count} 个墨迹"); + return clonedStrokes; + } + catch (Exception ex) + { + // 记录错误但不中断程序 + LogHelper.WriteLogToFile($"克隆墨迹时发生错误: {ex.Message}", LogHelper.LogType.Error); + return new StrokeCollection(); + } + } + + /// + /// 克隆墨迹集合到新页面 + /// + /// 要克隆的墨迹集合 + private void CloneStrokesToNewBoard(StrokeCollection strokes) + { + if (strokes == null || strokes.Count == 0) return; + + try + { + // 创建墨迹集合的副本 + var clonedStrokes = strokes.Clone(); + + // 为每个墨迹添加位置偏移以避免重叠 + foreach (var stroke in clonedStrokes) + { + var offsetPoints = new StylusPointCollection(); + foreach (var point in stroke.StylusPoints) + { + offsetPoints.Add(new StylusPoint(point.X + 20, point.Y + 20, point.PressureFactor)); + } + stroke.StylusPoints = offsetPoints; + } + + // 创建新页面 + BtnWhiteBoardAdd_Click(null, null); + + // 添加到新页面的画布 + inkCanvas.Strokes.Add(clonedStrokes); + + // 提交到时间机器以支持撤销 + timeMachine.CommitStrokeUserInputHistory(clonedStrokes); + + LogHelper.WriteLogToFile($"墨迹克隆到新页面完成: {clonedStrokes.Count} 个墨迹"); + } + catch (Exception ex) + { + // 记录错误但不中断程序 + LogHelper.WriteLogToFile($"克隆墨迹到新页面时发生错误: {ex.Message}", LogHelper.LogType.Error); + } + } + #endregion } } diff --git a/Ink Canvas/MainWindow_cs/MW_SelectionGestures.cs b/Ink Canvas/MainWindow_cs/MW_SelectionGestures.cs index 71981cd6..892527ad 100644 --- a/Ink Canvas/MainWindow_cs/MW_SelectionGestures.cs +++ b/Ink Canvas/MainWindow_cs/MW_SelectionGestures.cs @@ -34,23 +34,24 @@ namespace Ink_Canvas lastBorderMouseDownObject = sender; } - private bool isStrokeSelectionCloneOn; private void BorderStrokeSelectionClone_MouseUp(object sender, MouseButtonEventArgs e) { if (lastBorderMouseDownObject != sender) return; - if (isStrokeSelectionCloneOn) + try { - BorderStrokeSelectionClone.Background = Brushes.Transparent; - - isStrokeSelectionCloneOn = false; + var strokes = inkCanvas.GetSelectedStrokes(); + if (strokes.Count > 0) + { + // 直接执行克隆操作,与图片克隆保持一致 + CloneStrokes(strokes); + LogHelper.WriteLogToFile($"墨迹克隆完成: {strokes.Count} 个墨迹"); + } } - else + catch (Exception ex) { - BorderStrokeSelectionClone.Background = new SolidColorBrush(StringToColor("#FF1ED760")); - - isStrokeSelectionCloneOn = true; + LogHelper.WriteLogToFile($"墨迹克隆失败: {ex.Message}", LogHelper.LogType.Error); } } @@ -60,9 +61,7 @@ namespace Ink_Canvas var strokes = inkCanvas.GetSelectedStrokes(); inkCanvas.Select(new StrokeCollection()); - strokes = strokes.Clone(); - BtnWhiteBoardAdd_Click(null, null); - inkCanvas.Strokes.Add(strokes); + CloneStrokesToNewBoard(strokes); } private void BorderStrokeSelectionDelete_MouseUp(object sender, MouseButtonEventArgs e) @@ -408,7 +407,6 @@ namespace Ink_Canvas // 显示墨迹选择栏和选择框 GridInkCanvasSelectionCover.Visibility = Visibility.Visible; BorderStrokeSelectionClone.Background = Brushes.Transparent; - isStrokeSelectionCloneOn = false; updateBorderStrokeSelectionControlLocation(); UpdateSelectionDisplay(); return; @@ -657,23 +655,9 @@ namespace Ink_Canvas } } - if (isStrokeSelectionCloneOn) - { - var strokes = inkCanvas.GetSelectedStrokes(); - isProgramChangeStrokeSelection = true; - inkCanvas.Select(new StrokeCollection()); - StrokesSelectionClone = strokes.Clone(); - inkCanvas.Select(strokes); - isProgramChangeStrokeSelection = false; - inkCanvas.Strokes.Add(StrokesSelectionClone); - } - else - { - // 新增:启动套索选择模式 - // 使用集中化的工具模式切换方法 - SetCurrentToolMode(InkCanvasEditingMode.Select); - inkCanvas.Select(new StrokeCollection()); - } + + SetCurrentToolMode(InkCanvasEditingMode.Select); + inkCanvas.Select(new StrokeCollection()); } }