From 72b6cbb65250ebbf4d9c373bd55de49e5cfcf591 Mon Sep 17 00:00:00 2001 From: ChangSakura Date: Thu, 8 Aug 2024 00:46:56 +0800 Subject: [PATCH] [add] BorderStrokeSelectionCloneToBoardOrNewPage_Click for elements --- Ink Canvas/Helpers/InkCanvasElementsHelper.cs | 31 ++++++++++++++++++- Ink Canvas/MainWindow_cs/MW_PPT.cs | 3 +- .../MainWindow_cs/MW_SelectionGestures.cs | 14 ++++----- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/Ink Canvas/Helpers/InkCanvasElementsHelper.cs b/Ink Canvas/Helpers/InkCanvasElementsHelper.cs index 03c66eb..236734f 100644 --- a/Ink Canvas/Helpers/InkCanvasElementsHelper.cs +++ b/Ink Canvas/Helpers/InkCanvasElementsHelper.cs @@ -69,12 +69,41 @@ public static List CloneSelectedElements(InkCanvas inkCanvas, ref Dic SetTopData = InkCanvas.GetTop(element), FrameworkElement = frameworkElement }; - LogHelper.WriteObjectLogToFile(frameworkElement); } } return clonedElements; } + public static List GetSelectedElementsCloned(InkCanvas inkCanvas) + { + List clonedElements = new List(); + int key = 0; + foreach (UIElement element in inkCanvas.GetSelectedElements()) + { + UIElement clonedElement = CloneUIElement(element); + if (clonedElement != null) + { + FrameworkElement frameworkElement = clonedElement as FrameworkElement; + string timestamp = "ele_" + DateTime.Now.ToString("ddHHmmssfff") + key.ToString(); + frameworkElement.Name = timestamp; + ++key; + InkCanvas.SetLeft(frameworkElement, InkCanvas.GetLeft(element)); + InkCanvas.SetTop(frameworkElement, InkCanvas.GetTop(element)); + clonedElements.Add(frameworkElement); + } + } + return clonedElements; + } + + public static void AddElements(InkCanvas inkCanvas, List elements, TimeMachine timeMachine) + { + foreach (UIElement element in elements) + { + inkCanvas.Children.Add(element); + timeMachine.CommitElementInsertHistory(element); + } + } + private static UIElement CloneUIElement(UIElement element) { if (element == null) return null; diff --git a/Ink Canvas/MainWindow_cs/MW_PPT.cs b/Ink Canvas/MainWindow_cs/MW_PPT.cs index b403bde..798ffdc 100644 --- a/Ink Canvas/MainWindow_cs/MW_PPT.cs +++ b/Ink Canvas/MainWindow_cs/MW_PPT.cs @@ -292,7 +292,7 @@ private void PptApplication_SlideShowBegin(SlideShowWindow Wn) { ImageBlackboard_Click(null, null); } - + /* //调整颜色 double screenRatio = SystemParameters.PrimaryScreenWidth / SystemParameters.PrimaryScreenHeight; if (Math.Abs(screenRatio - 16.0 / 9) <= -0.01) @@ -306,6 +306,7 @@ private void PptApplication_SlideShowBegin(SlideShowWindow Wn) { } + */ lastDesktopInkColor = 1; diff --git a/Ink Canvas/MainWindow_cs/MW_SelectionGestures.cs b/Ink Canvas/MainWindow_cs/MW_SelectionGestures.cs index c079b97..cee133e 100644 --- a/Ink Canvas/MainWindow_cs/MW_SelectionGestures.cs +++ b/Ink Canvas/MainWindow_cs/MW_SelectionGestures.cs @@ -44,19 +44,23 @@ private void BorderStrokeSelectionCloneToBoardOrNewPage_Click(object sender, Rou { if (currentMode == 0) { - var strokes = inkCanvas.GetSelectedStrokes(); + StrokeCollection strokes = inkCanvas.GetSelectedStrokes(); + List elements = InkCanvasElementsHelper.GetSelectedElementsCloned(inkCanvas); inkCanvas.Select(new StrokeCollection()); strokes = strokes.Clone(); ImageBlackboard_Click(null, null); inkCanvas.Strokes.Add(strokes); + InkCanvasElementsHelper.AddElements(inkCanvas, elements, timeMachine); } else { - var strokes = inkCanvas.GetSelectedStrokes(); + StrokeCollection strokes = inkCanvas.GetSelectedStrokes(); + List elements = InkCanvasElementsHelper.GetSelectedElementsCloned(inkCanvas); inkCanvas.Select(new StrokeCollection()); strokes = strokes.Clone(); BtnWhiteBoardAdd_Click(null, null); inkCanvas.Strokes.Add(strokes); + InkCanvasElementsHelper.AddElements(inkCanvas, elements, timeMachine); } } @@ -432,11 +436,7 @@ private void BtnSelect_Click(object sender, RoutedEventArgs e) selectedStrokes.Add(stroke); } } - List selectedElements = new List(); - foreach (UIElement element in inkCanvas.Children) - { - selectedElements.Add(element); - } + List selectedElements = InkCanvasElementsHelper.GetAllElements(inkCanvas); inkCanvas.Select(selectedStrokes, selectedElements); } }