From df9c5090298ff4f01fb8b4b3119344d2ad622e58 Mon Sep 17 00:00:00 2001 From: Raspberry-Monster Date: Sun, 24 Mar 2024 15:15:23 +0800 Subject: [PATCH] =?UTF-8?q?[WIP]=20=E4=BF=AE=E6=94=B9=E6=92=A4=E5=9B=9E?= =?UTF-8?q?=E8=A1=8C=E4=B8=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/Helpers/TimeMachine.cs | 19 +- Ink Canvas/MainWindow.xaml | 1 - Ink Canvas/MainWindow.xaml.cs | 776 ++++++++---------------------- 3 files changed, 209 insertions(+), 587 deletions(-) diff --git a/Ink Canvas/Helpers/TimeMachine.cs b/Ink Canvas/Helpers/TimeMachine.cs index 4855ff13..cbc601f4 100644 --- a/Ink Canvas/Helpers/TimeMachine.cs +++ b/Ink Canvas/Helpers/TimeMachine.cs @@ -1,5 +1,7 @@ using System.Collections.Generic; +using System.Windows; using System.Windows.Ink; +using System.Windows.Media; namespace Ink_Canvas.Helpers { @@ -42,16 +44,16 @@ public void CommitStrokeShapeHistory(StrokeCollection strokeToBeReplaced, Stroke NotifyUndoRedoState(); } - public void CommitStrokeManipulationHistory(StrokeCollection strokeToBeReplaced, StrokeCollection generatedStroke) + public void CommitStrokeManipulationHistory(StrokeCollection manipulatedStrokes, Matrix matrix) { if (_currentIndex + 1 < _currentStrokeHistory.Count) { _currentStrokeHistory.RemoveRange(_currentIndex + 1, (_currentStrokeHistory.Count - 1) - _currentIndex); } - _currentStrokeHistory.Add(new TimeMachineHistory(generatedStroke, - TimeMachineHistoryType.Manipulation, - false, - strokeToBeReplaced)); + _currentStrokeHistory.Add( + new TimeMachineHistory(manipulatedStrokes, + TimeMachineHistoryType.Manipulation, + matrix)); _currentIndex = _currentStrokeHistory.Count - 1; NotifyUndoRedoState(); } @@ -122,6 +124,7 @@ public class TimeMachineHistory public bool StrokeHasBeenCleared; public StrokeCollection CurrentStroke; public StrokeCollection ReplacedStroke; + public Matrix ManipulationHistory; public TimeMachineHistory(StrokeCollection currentStroke, TimeMachineHistoryType commitType, bool strokeHasBeenCleared) { CommitType = commitType; @@ -136,6 +139,12 @@ public TimeMachineHistory(StrokeCollection currentStroke, TimeMachineHistoryType StrokeHasBeenCleared = strokeHasBeenCleared; ReplacedStroke = replacedStroke; } + public TimeMachineHistory(StrokeCollection currentStroke, TimeMachineHistoryType commitType, Matrix matrix) + { + CommitType=commitType; + CurrentStroke = currentStroke; + ManipulationHistory = matrix; + } } public enum TimeMachineHistoryType diff --git a/Ink Canvas/MainWindow.xaml b/Ink Canvas/MainWindow.xaml index 053bdeaf..ad39a338 100644 --- a/Ink Canvas/MainWindow.xaml +++ b/Ink Canvas/MainWindow.xaml @@ -98,7 +98,6 @@ ManipulationDelta="Main_Grid_ManipulationDelta" ManipulationCompleted="Main_Grid_ManipulationCompleted" ManipulationInertiaStarting="inkCanvas_ManipulationInertiaStarting" - ManipulationStarted="inkCanvas_ManipulationStarted" IsManipulationEnabled="True" EditingModeChanged="inkCanvas_EditingModeChanged" PreviewTouchDown="inkCanvas_PreviewTouchDown" diff --git a/Ink Canvas/MainWindow.xaml.cs b/Ink Canvas/MainWindow.xaml.cs index 666b996f..cd115667 100644 --- a/Ink Canvas/MainWindow.xaml.cs +++ b/Ink Canvas/MainWindow.xaml.cs @@ -351,6 +351,109 @@ private enum CommitReason private StrokeCollection CuboidStrokeCollection; private TimeMachine timeMachine = new TimeMachine(); + private void ApplyHistoryToCanvas(TimeMachineHistory item) + { + _currentCommitType = CommitReason.CodeInput; + if (item.CommitType == TimeMachineHistoryType.UserInput) + { + if (!item.StrokeHasBeenCleared) + { + foreach (var strokes in item.CurrentStroke) + { + if (!inkCanvas.Strokes.Contains(strokes)) + inkCanvas.Strokes.Add(strokes); + } + } + else + { + foreach (var strokes in item.CurrentStroke) + { + if (inkCanvas.Strokes.Contains(strokes)) + inkCanvas.Strokes.Remove(strokes); + } + } + } + else if (item.CommitType == TimeMachineHistoryType.ShapeRecognition) + { + if (item.StrokeHasBeenCleared) + { + + foreach (var strokes in item.CurrentStroke) + { + if (inkCanvas.Strokes.Contains(strokes)) + inkCanvas.Strokes.Remove(strokes); + } + foreach (var strokes in item.ReplacedStroke) + { + if (!inkCanvas.Strokes.Contains(strokes)) + inkCanvas.Strokes.Add(strokes); + } + } + else + { + foreach (var strokes in item.CurrentStroke) + { + if (!inkCanvas.Strokes.Contains(strokes)) + inkCanvas.Strokes.Add(strokes); + } + foreach (var strokes in item.ReplacedStroke) + { + if (inkCanvas.Strokes.Contains(strokes)) + inkCanvas.Strokes.Remove(strokes); + } + } + } + else if (item.CommitType == TimeMachineHistoryType.Manipulation) + { + item.ManipulationHistory.Invert(); + foreach (var strokes in item.CurrentStroke) + { + strokes.Transform(item.ManipulationHistory, false); + } + + } + else if (item.CommitType == TimeMachineHistoryType.Clear) + { + if (!item.StrokeHasBeenCleared) + { + if (item.CurrentStroke != null) + { + foreach (var currentStroke in item.CurrentStroke) + { + if (!inkCanvas.Strokes.Contains(currentStroke)) inkCanvas.Strokes.Add(currentStroke); + } + + } + if (item.ReplacedStroke != null) + { + foreach (var replacedStroke in item.ReplacedStroke) + { + if (inkCanvas.Strokes.Contains(replacedStroke)) inkCanvas.Strokes.Remove(replacedStroke); + } + } + + } + else + { + if (item.ReplacedStroke != null) + { + foreach (var replacedStroke in item.ReplacedStroke) + { + if (!inkCanvas.Strokes.Contains(replacedStroke)) inkCanvas.Strokes.Add(replacedStroke); + } + } + if (item.CurrentStroke != null) + { + foreach (var currentStroke in item.CurrentStroke) + { + if (inkCanvas.Strokes.Contains(currentStroke)) inkCanvas.Strokes.Remove(currentStroke); + } + } + } + } + _currentCommitType = CommitReason.UserInput; + } + private void TimeMachine_OnUndoStateChanged(bool status) { var result = status ? Visibility.Visible : Visibility.Collapsed; @@ -368,11 +471,6 @@ private void TimeMachine_OnRedoStateChanged(bool status) private void StrokesOnStrokesChanged(object sender, StrokeCollectionChangedEventArgs e) { if (_currentCommitType == CommitReason.CodeInput || _currentCommitType == CommitReason.ShapeDrawing) return; - if (_currentCommitType == CommitReason.Manipulation) - { - timeMachine.CommitStrokeManipulationHistory(e.Removed, e.Added); - return; - } if ((e.Added.Count != 0 || e.Removed.Count != 0) && IsEraseByPoint) { if (AddedStroke == null) AddedStroke = new StrokeCollection(); @@ -1995,23 +2093,6 @@ private void inkCanvas_ManipulationInertiaStarting(object sender, ManipulationIn { } - private void inkCanvas_ManipulationStarted(object sender, ManipulationStartedEventArgs e) - { - if (isInMultiTouchMode || !Settings.Gesture.IsEnableTwoFingerGesture || inkCanvas.Strokes.Count == 0 || dec.Count() < 2) return; - _currentCommitType = CommitReason.Manipulation; - StrokeCollection strokes = inkCanvas.GetSelectedStrokes(); - if (strokes.Count != 0) - { - inkCanvas.Strokes.Replace(strokes, strokes.Clone()); - } - else - { - var originalStrokes = inkCanvas.Strokes; - var targetStrokes = originalStrokes.Clone(); - originalStrokes.Replace(originalStrokes, targetStrokes); - } - _currentCommitType = CommitReason.UserInput; - } private void Main_Grid_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e) { @@ -2075,6 +2156,15 @@ private void Main_Grid_ManipulationDelta(object sender, ManipulationDeltaEventAr catch { } } } + if(lastTempManiputlaionMatrix == null) + { + lastTempManiputlaionMatrix = m; + lastTempStrokeCollection = strokes; + } + else + { + lastTempManiputlaionMatrix?.Append(m); + } } else { @@ -2098,6 +2188,15 @@ private void Main_Grid_ManipulationDelta(object sender, ManipulationDeltaEventAr circle.Centroid = new Point((circle.Stroke.StylusPoints[0].X + circle.Stroke.StylusPoints[circle.Stroke.StylusPoints.Count / 2].X) / 2, (circle.Stroke.StylusPoints[0].Y + circle.Stroke.StylusPoints[circle.Stroke.StylusPoints.Count / 2].Y) / 2); } + if (lastTempManiputlaionMatrix == null) + { + lastTempManiputlaionMatrix = m; + lastTempStrokeCollection = inkCanvas.Strokes; + } + else + { + lastTempManiputlaionMatrix?.Append(m); + } } } } @@ -3380,309 +3479,68 @@ private void BtnUndo_Click(object sender, RoutedEventArgs e) GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed; inkCanvas.Select(new StrokeCollection()); } - _currentCommitType = CommitReason.CodeInput; var item = timeMachine.Undo(); - if (item.CommitType == TimeMachineHistoryType.UserInput) + ApplyHistoryToCanvas(item); + } + private void BtnRedo_Click(object sender, RoutedEventArgs e) + { + if (inkCanvas.GetSelectedStrokes().Count != 0) { - if (!item.StrokeHasBeenCleared) - { - foreach (var strokes in item.CurrentStroke) - { - if (!inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Add(strokes); - } - } - else - { - foreach (var strokes in item.CurrentStroke) - { - if (inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Remove(strokes); - } - } + GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed; + inkCanvas.Select(new StrokeCollection()); } - else if (item.CommitType == TimeMachineHistoryType.ShapeRecognition) + var item = timeMachine.Redo(); + ApplyHistoryToCanvas(item); + } + private void Btn_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e) + { + if (!isLoaded) return; + try { - if (item.StrokeHasBeenCleared) + if (((Button)sender).IsEnabled) { - - foreach (var strokes in item.CurrentStroke) - { - if (inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Remove(strokes); - } - foreach (var strokes in item.ReplacedStroke) - { - if (!inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Add(strokes); - } + ((UIElement)((Button)sender).Content).Opacity = 1; } else { - foreach (var strokes in item.CurrentStroke) - { - if (!inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Add(strokes); - } - foreach (var strokes in item.ReplacedStroke) - { - if (inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Remove(strokes); - } + ((UIElement)((Button)sender).Content).Opacity = 0.25; } } - else if (item.CommitType == TimeMachineHistoryType.Manipulation) + catch { } + } + #endregion Other Controls + + #endregion Left Side Panel + + #region Selection Gestures + + #region Floating Control + + object lastBorderMouseDownObject; + + private void Border_MouseDown(object sender, MouseButtonEventArgs e) + { + lastBorderMouseDownObject = sender; + } + + bool isStrokeSelectionCloneOn = false; + private void BorderStrokeSelectionClone_MouseUp(object sender, MouseButtonEventArgs e) + { + if (lastBorderMouseDownObject != sender) return; + + if (isStrokeSelectionCloneOn) { - if (item.StrokeHasBeenCleared) - { + BorderStrokeSelectionClone.Background = Brushes.Transparent; - foreach (var strokes in item.CurrentStroke) - { - if (inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Remove(strokes); - } - foreach (var strokes in item.ReplacedStroke) - { - if (!inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Add(strokes); - } - } - else - { - foreach (var strokes in item.CurrentStroke) - { - if (!inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Add(strokes); - } - foreach (var strokes in item.ReplacedStroke) - { - if (inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Remove(strokes); - } - } + isStrokeSelectionCloneOn = false; } - else if (item.CommitType == TimeMachineHistoryType.Clear) + else { - if (!item.StrokeHasBeenCleared) - { - if (item.CurrentStroke != null) - { - foreach (var currentStroke in item.CurrentStroke) - { - if (!inkCanvas.Strokes.Contains(currentStroke)) inkCanvas.Strokes.Add(currentStroke); - } + BorderStrokeSelectionClone.Background = new SolidColorBrush(StringToColor("#FF1ED760")); - } - if (item.ReplacedStroke != null) - { - foreach (var replacedStroke in item.ReplacedStroke) - { - if (inkCanvas.Strokes.Contains(replacedStroke)) inkCanvas.Strokes.Remove(replacedStroke); - } - } - - } - else - { - if (item.ReplacedStroke != null) - { - foreach (var replacedStroke in item.ReplacedStroke) - { - if (!inkCanvas.Strokes.Contains(replacedStroke)) inkCanvas.Strokes.Add(replacedStroke); - } - } - if (item.CurrentStroke != null) - { - foreach (var currentStroke in item.CurrentStroke) - { - if (inkCanvas.Strokes.Contains(currentStroke)) inkCanvas.Strokes.Remove(currentStroke); - } - } - } - } - _currentCommitType = CommitReason.UserInput; - } - - private void BtnRedo_Click(object sender, RoutedEventArgs e) - { - if (inkCanvas.GetSelectedStrokes().Count != 0) - { - GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed; - inkCanvas.Select(new StrokeCollection()); - } - - _currentCommitType = CommitReason.CodeInput; - var item = timeMachine.Redo(); - if (item.CommitType == TimeMachineHistoryType.UserInput) - { - if (!item.StrokeHasBeenCleared) - { - foreach (var strokes in item.CurrentStroke) - { - if (!inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Add(strokes); - } - } - else - { - foreach (var strokes in item.CurrentStroke) - { - if (inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Remove(strokes); - } - } - } - else if (item.CommitType == TimeMachineHistoryType.ShapeRecognition) - { - if (item.StrokeHasBeenCleared) - { - - foreach (var strokes in item.CurrentStroke) - { - if (inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Remove(strokes); - } - foreach (var strokes in item.ReplacedStroke) - { - if (!inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Add(strokes); - } - } - else - { - foreach (var strokes in item.CurrentStroke) - { - if (!inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Add(strokes); - } - foreach (var strokes in item.ReplacedStroke) - { - if (inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Remove(strokes); - } - } - } - else if (item.CommitType == TimeMachineHistoryType.Manipulation) - { - if (item.StrokeHasBeenCleared) - { - - foreach (var strokes in item.CurrentStroke) - { - if (inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Remove(strokes); - } - foreach (var strokes in item.ReplacedStroke) - { - if (!inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Add(strokes); - } - } - else - { - foreach (var strokes in item.CurrentStroke) - { - if (!inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Add(strokes); - } - foreach (var strokes in item.ReplacedStroke) - { - if (inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Remove(strokes); - } - } - } - else if (item.CommitType == TimeMachineHistoryType.Clear) - { - if (!item.StrokeHasBeenCleared) - { - if (item.CurrentStroke != null) - { - foreach (var currentStroke in item.CurrentStroke) - { - if (!inkCanvas.Strokes.Contains(currentStroke)) inkCanvas.Strokes.Add(currentStroke); - } - - } - if (item.ReplacedStroke != null) - { - foreach (var replacedStroke in item.ReplacedStroke) - { - if (inkCanvas.Strokes.Contains(replacedStroke)) inkCanvas.Strokes.Remove(replacedStroke); - } - } - - } - else - { - if (item.ReplacedStroke != null) - { - foreach (var replacedStroke in item.ReplacedStroke) - { - if (!inkCanvas.Strokes.Contains(replacedStroke)) inkCanvas.Strokes.Add(replacedStroke); - } - } - if (item.CurrentStroke != null) - { - foreach (var currentStroke in item.CurrentStroke) - { - if (inkCanvas.Strokes.Contains(currentStroke)) inkCanvas.Strokes.Remove(currentStroke); - } - } - } - } - _currentCommitType = CommitReason.UserInput; - } - - private void Btn_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e) - { - if (!isLoaded) return; - try - { - if (((Button)sender).IsEnabled) - { - ((UIElement)((Button)sender).Content).Opacity = 1; - } - else - { - ((UIElement)((Button)sender).Content).Opacity = 0.25; - } - } - catch { } - } - #endregion Other Controls - - #endregion Left Side Panel - - #region Selection Gestures - - #region Floating Control - - object lastBorderMouseDownObject; - - private void Border_MouseDown(object sender, MouseButtonEventArgs e) - { - lastBorderMouseDownObject = sender; - } - - bool isStrokeSelectionCloneOn = false; - private void BorderStrokeSelectionClone_MouseUp(object sender, MouseButtonEventArgs e) - { - if (lastBorderMouseDownObject != sender) return; - - if (isStrokeSelectionCloneOn) - { - BorderStrokeSelectionClone.Background = Brushes.Transparent; - - isStrokeSelectionCloneOn = false; - } - else - { - BorderStrokeSelectionClone.Background = new SolidColorBrush(StringToColor("#FF1ED760")); - - isStrokeSelectionCloneOn = true; - } - } + isStrokeSelectionCloneOn = true; + } + } private void BorderStrokeSelectionCloneToNewBoard_MouseUp(object sender, MouseButtonEventArgs e) { @@ -3764,17 +3622,11 @@ private void ImageFlipHorizontal_MouseUp(object sender, MouseButtonEventArgs e) m.ScaleAt(-1, 1, center.X, center.Y); // 缩放 StrokeCollection targetStrokes = inkCanvas.GetSelectedStrokes(); - StrokeCollection resultStrokes = targetStrokes.Clone(); - foreach (Stroke stroke in resultStrokes) + foreach (Stroke stroke in targetStrokes) { stroke.Transform(m, false); } - _currentCommitType = CommitReason.Manipulation; - inkCanvas.Strokes.Replace(targetStrokes, resultStrokes); - _currentCommitType = CommitReason.UserInput; - isProgramChangeStrokeSelection = true; - inkCanvas.Select(resultStrokes); - isProgramChangeStrokeSelection = false; + timeMachine.CommitStrokeManipulationHistory(targetStrokes, m); //updateBorderStrokeSelectionControlLocation(); } @@ -3796,17 +3648,11 @@ private void ImageFlipVertical_MouseUp(object sender, MouseButtonEventArgs e) m.ScaleAt(1, -1, center.X, center.Y); // 缩放 StrokeCollection targetStrokes = inkCanvas.GetSelectedStrokes(); - StrokeCollection resultStrokes = targetStrokes.Clone(); - foreach (Stroke stroke in resultStrokes) + foreach (Stroke stroke in targetStrokes) { stroke.Transform(m, false); } - _currentCommitType = CommitReason.Manipulation; - inkCanvas.Strokes.Replace(targetStrokes, resultStrokes); - _currentCommitType = CommitReason.UserInput; - isProgramChangeStrokeSelection = true; - inkCanvas.Select(resultStrokes); - isProgramChangeStrokeSelection = false; + timeMachine.CommitStrokeManipulationHistory(targetStrokes, m); } private void ImageRotate45_MouseUp(object sender, MouseButtonEventArgs e) @@ -3826,17 +3672,11 @@ private void ImageRotate45_MouseUp(object sender, MouseButtonEventArgs e) m.RotateAt(45, center.X, center.Y); // 旋转 StrokeCollection targetStrokes = inkCanvas.GetSelectedStrokes(); - StrokeCollection resultStrokes = targetStrokes.Clone(); - foreach (Stroke stroke in resultStrokes) + foreach (Stroke stroke in targetStrokes) { stroke.Transform(m, false); } - _currentCommitType = CommitReason.Manipulation; - inkCanvas.Strokes.Replace(targetStrokes, resultStrokes); - _currentCommitType = CommitReason.UserInput; - isProgramChangeStrokeSelection = true; - inkCanvas.Select(resultStrokes); - isProgramChangeStrokeSelection = false; + timeMachine.CommitStrokeManipulationHistory(targetStrokes, m); } private void ImageRotate90_MouseUp(object sender, MouseButtonEventArgs e) @@ -3856,17 +3696,11 @@ private void ImageRotate90_MouseUp(object sender, MouseButtonEventArgs e) m.RotateAt(90, center.X, center.Y); // 旋转 StrokeCollection targetStrokes = inkCanvas.GetSelectedStrokes(); - StrokeCollection resultStrokes = targetStrokes.Clone(); - foreach (Stroke stroke in resultStrokes) + foreach (Stroke stroke in targetStrokes) { stroke.Transform(m, false); } - _currentCommitType = CommitReason.Manipulation; - inkCanvas.Strokes.Replace(targetStrokes, resultStrokes); - _currentCommitType = CommitReason.UserInput; - isProgramChangeStrokeSelection = true; - inkCanvas.Select(resultStrokes); - isProgramChangeStrokeSelection = false; + timeMachine.CommitStrokeManipulationHistory(targetStrokes, m); } #endregion @@ -4006,7 +3840,15 @@ private void GridInkCanvasSelectionCover_ManipulationDelta(object sender, Manipu } catch { } } - + if (lastTempManiputlaionMatrix == null) + { + lastTempManiputlaionMatrix = m; + lastTempStrokeCollection = strokes; + } + else + { + lastTempManiputlaionMatrix?.Append(m); + } updateBorderStrokeSelectionControlLocation(); } } @@ -5267,6 +5109,7 @@ private void Main_Grid_TouchUp(object sender, TouchEventArgs e) isWaitUntilNextTouchDown = false; } } + Matrix? lastTempManiputlaionMatrix = null; Stroke lastTempStroke = null; StrokeCollection lastTempStrokeCollection = new StrokeCollection(); bool isWaitUntilNextTouchDown = false; @@ -5561,8 +5404,15 @@ private void inkCanvas_MouseUp(object sender, MouseButtonEventArgs e) timeMachine.CommitStrokeUserInputHistory(collection); } } + if(lastTempManiputlaionMatrix != null) + { + timeMachine.CommitStrokeManipulationHistory(lastTempStrokeCollection, lastTempManiputlaionMatrix.Value); + lastTempStrokeCollection = null; + lastTempManiputlaionMatrix = null; + } lastTempStroke = null; lastTempStrokeCollection = null; + lastTempManiputlaionMatrix = null; } private bool NeedUpdateIniP() @@ -5623,125 +5473,7 @@ private void RestoreStrokes(bool isBackupMain = false) timeMachine.ImportTimeMachineHistory(TimeMachineHistories[0]); foreach (var item in TimeMachineHistories[0]) { - if (item.CommitType == TimeMachineHistoryType.UserInput) - { - if (!item.StrokeHasBeenCleared) - { - foreach (var strokes in item.CurrentStroke) - { - if (!inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Add(strokes); - } - } - else - { - foreach (var strokes in item.CurrentStroke) - { - if (inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Remove(strokes); - } - } - } - else if (item.CommitType == TimeMachineHistoryType.ShapeRecognition) - { - if (item.StrokeHasBeenCleared) - { - - foreach (var strokes in item.CurrentStroke) - { - if (inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Remove(strokes); - } - foreach (var strokes in item.ReplacedStroke) - { - if (!inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Add(strokes); - } - } - else - { - foreach (var strokes in item.CurrentStroke) - { - if (!inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Add(strokes); - } - foreach (var strokes in item.ReplacedStroke) - { - if (inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Remove(strokes); - } - } - } - else if (item.CommitType == TimeMachineHistoryType.Manipulation) - { - if (item.StrokeHasBeenCleared) - { - - foreach (var strokes in item.CurrentStroke) - { - if (inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Remove(strokes); - } - foreach (var strokes in item.ReplacedStroke) - { - if (!inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Add(strokes); - } - } - else - { - foreach (var strokes in item.CurrentStroke) - { - if (!inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Add(strokes); - } - foreach (var strokes in item.ReplacedStroke) - { - if (inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Remove(strokes); - } - } - } - else if (item.CommitType == TimeMachineHistoryType.Clear) - { - if (!item.StrokeHasBeenCleared) - { - if (item.CurrentStroke != null) - { - foreach (var currentStroke in item.CurrentStroke) - { - if (!inkCanvas.Strokes.Contains(currentStroke)) inkCanvas.Strokes.Add(currentStroke); - } - - } - if (item.ReplacedStroke != null) - { - foreach (var replacedStroke in item.ReplacedStroke) - { - if (inkCanvas.Strokes.Contains(replacedStroke)) inkCanvas.Strokes.Remove(replacedStroke); - } - } - - } - else - { - if (item.ReplacedStroke != null) - { - foreach (var replacedStroke in item.ReplacedStroke) - { - if (!inkCanvas.Strokes.Contains(replacedStroke)) inkCanvas.Strokes.Add(replacedStroke); - } - } - if (item.CurrentStroke != null) - { - foreach (var currentStroke in item.CurrentStroke) - { - if (inkCanvas.Strokes.Contains(currentStroke)) inkCanvas.Strokes.Remove(currentStroke); - } - } - } - } - _currentCommitType = CommitReason.UserInput; + ApplyHistoryToCanvas(item); } } else @@ -5750,126 +5482,8 @@ private void RestoreStrokes(bool isBackupMain = false) timeMachine.ImportTimeMachineHistory(TimeMachineHistories[CurrentWhiteboardIndex]); foreach (var item in TimeMachineHistories[CurrentWhiteboardIndex]) { - if (item.CommitType == TimeMachineHistoryType.UserInput) - { - if (!item.StrokeHasBeenCleared) - { - foreach (var strokes in item.CurrentStroke) - { - if (!inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Add(strokes); - } - } - else - { - foreach (var strokes in item.CurrentStroke) - { - if (inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Remove(strokes); - } - } - } - else if (item.CommitType == TimeMachineHistoryType.ShapeRecognition) - { - if (item.StrokeHasBeenCleared) - { - - foreach (var strokes in item.CurrentStroke) - { - if (inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Remove(strokes); - } - foreach (var strokes in item.ReplacedStroke) - { - if (!inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Add(strokes); - } - } - else - { - foreach (var strokes in item.CurrentStroke) - { - if (!inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Add(strokes); - } - foreach (var strokes in item.ReplacedStroke) - { - if (inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Remove(strokes); - } - } - } - else if (item.CommitType == TimeMachineHistoryType.Manipulation) - { - if (item.StrokeHasBeenCleared) - { - - foreach (var strokes in item.CurrentStroke) - { - if (inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Remove(strokes); - } - foreach (var strokes in item.ReplacedStroke) - { - if (!inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Add(strokes); - } - } - else - { - foreach (var strokes in item.CurrentStroke) - { - if (!inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Add(strokes); - } - foreach (var strokes in item.ReplacedStroke) - { - if (inkCanvas.Strokes.Contains(strokes)) - inkCanvas.Strokes.Remove(strokes); - } - } - } - else if (item.CommitType == TimeMachineHistoryType.Clear) - { - if (!item.StrokeHasBeenCleared) - { - if (item.CurrentStroke != null) - { - foreach (var currentStroke in item.CurrentStroke) - { - if (!inkCanvas.Strokes.Contains(currentStroke)) inkCanvas.Strokes.Add(currentStroke); - } - - } - if (item.ReplacedStroke != null) - { - foreach (var replacedStroke in item.ReplacedStroke) - { - if (inkCanvas.Strokes.Contains(replacedStroke)) inkCanvas.Strokes.Remove(replacedStroke); - } - } - - } - else - { - if (item.ReplacedStroke != null) - { - foreach (var replacedStroke in item.ReplacedStroke) - { - if (!inkCanvas.Strokes.Contains(replacedStroke)) inkCanvas.Strokes.Add(replacedStroke); - } - } - if (item.CurrentStroke != null) - { - foreach (var currentStroke in item.CurrentStroke) - { - if (inkCanvas.Strokes.Contains(currentStroke)) inkCanvas.Strokes.Remove(currentStroke); - } - } - } - } + ApplyHistoryToCanvas(item); } - _currentCommitType = CommitReason.UserInput; } } catch { }