[merge] 合并Raspberry-Monster的 “修改撤回行为”

--------

Co-authored-by: Raspberry-Monster <lele2194512339@outlook.com>
This commit is contained in:
Dubi906w 2024-06-05 19:57:15 +08:00
parent 3e0f8ab61d
commit 72f703ea0c
8 changed files with 174 additions and 467 deletions

View File

@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Windows.Ink;
using System.Windows.Media;
namespace Ink_Canvas.Helpers
{
@ -42,16 +43,16 @@ namespace Ink_Canvas.Helpers
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 +123,7 @@ namespace Ink_Canvas.Helpers
public bool StrokeHasBeenCleared;
public StrokeCollection CurrentStroke;
public StrokeCollection ReplacedStroke;
public Matrix ManipulationHistory;
public TimeMachineHistory(StrokeCollection currentStroke, TimeMachineHistoryType commitType, bool strokeHasBeenCleared)
{
CommitType = commitType;
@ -129,6 +131,12 @@ namespace Ink_Canvas.Helpers
StrokeHasBeenCleared = strokeHasBeenCleared;
ReplacedStroke = null;
}
public TimeMachineHistory(StrokeCollection currentStroke, TimeMachineHistoryType commitType, Matrix matrix)
{
CommitType = commitType;
CurrentStroke = currentStroke;
ManipulationHistory = matrix;
}
public TimeMachineHistory(StrokeCollection currentStroke, TimeMachineHistoryType commitType, bool strokeHasBeenCleared, StrokeCollection replacedStroke)
{
CommitType = commitType;

View File

@ -1241,7 +1241,6 @@
MouseMove="inkCanvas_MouseMove"
MouseUp="inkCanvas_MouseUp"
ManipulationStarting="inkCanvas_ManipulationStarting"
ManipulationStarted="inkCanvas_ManipulationStarted"
SelectionChanged="inkCanvas_SelectionChanged"
StrokeCollected="inkCanvas_StrokeCollected" ClipToBounds="False" Background="Transparent" />
<InkCanvas x:Name="FakeInkCanvas" Background="Transparent" IsHitTestVisible="False" Visibility="Hidden"

View File

@ -42,176 +42,14 @@ namespace Ink_Canvas {
_currentCommitType = CommitReason.CodeInput;
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 {
_currentCommitType = CommitReason.CodeInput;
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 { }
}

View File

@ -1152,127 +1152,8 @@ namespace Ink_Canvas
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
inkCanvas.Select(new StrokeCollection());
}
_currentCommitType = CommitReason.CodeInput;
var item = timeMachine.Undo();
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);
}
private void BtnRedo_Click(object sender, RoutedEventArgs e)
@ -1282,128 +1163,8 @@ namespace Ink_Canvas
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;
ApplyHistoryToCanvas(item);
}
private void Btn_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)

View File

@ -19,14 +19,18 @@ namespace Ink_Canvas {
}
bool isStrokeSelectionCloneOn = false;
private void BorderStrokeSelectionClone_MouseUp(object sender, MouseButtonEventArgs e) {
private void BorderStrokeSelectionClone_MouseUp(object sender, MouseButtonEventArgs e)
{
if (lastBorderMouseDownObject != sender) return;
if (isStrokeSelectionCloneOn) {
if (isStrokeSelectionCloneOn)
{
BorderStrokeSelectionClone.Background = Brushes.Transparent;
isStrokeSelectionCloneOn = false;
} else {
}
else
{
BorderStrokeSelectionClone.Background = new SolidColorBrush(StringToColor("#FF1ED760"));
isStrokeSelectionCloneOn = true;
@ -96,15 +100,10 @@ namespace Ink_Canvas {
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();
}
@ -126,15 +125,11 @@ namespace Ink_Canvas {
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) {
@ -154,15 +149,10 @@ namespace Ink_Canvas {
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) {
@ -182,15 +172,10 @@ namespace Ink_Canvas {
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
@ -302,6 +287,15 @@ namespace Ink_Canvas {
stroke.DrawingAttributes.Height *= md.Scale.Y;
} catch { }
}
if (lastTempManiputlaionMatrix == null)
{
lastTempManiputlaionMatrix = m;
lastTempStrokeCollection = strokes;
}
else
{
lastTempManiputlaionMatrix?.Append(m);
}
updateBorderStrokeSelectionControlLocation();
}

View File

@ -7,6 +7,7 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using MessageBox = System.Windows.MessageBox;
using Point = System.Windows.Point;
@ -1151,6 +1152,8 @@ namespace Ink_Canvas {
}
Stroke lastTempStroke = null;
StrokeCollection lastTempStrokeCollection = new StrokeCollection();
Matrix? lastTempManiputlaionMatrix = null;
bool isWaitUntilNextTouchDown = false;
private List<System.Windows.Point> GenerateEllipseGeometry(System.Windows.Point st, System.Windows.Point ed, bool isDrawTop = true, bool isDrawBottom = true) {
double a = 0.5 * (ed.X - st.X);
@ -1430,8 +1433,15 @@ namespace Ink_Canvas {
timeMachine.CommitStrokeUserInputHistory(collection);
}
}
if (lastTempManiputlaionMatrix != null)
{
timeMachine.CommitStrokeManipulationHistory(lastTempStrokeCollection, lastTempManiputlaionMatrix.Value);
lastTempStrokeCollection = null;
lastTempManiputlaionMatrix = null;
}
lastTempStroke = null;
lastTempStrokeCollection = null;
lastTempManiputlaionMatrix = null;
if (Settings.Canvas.FitToCurve == true)
{
drawingAttributes.FitToCurve = true;

View File

@ -21,6 +21,84 @@ namespace Ink_Canvas {
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;
BtnUndo.Visibility = result;
@ -40,11 +118,7 @@ namespace Ink_Canvas {
}
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();
if (ReplacedStroke == null) ReplacedStroke = new StrokeCollection();
@ -52,12 +126,14 @@ namespace Ink_Canvas {
ReplacedStroke.Add(e.Removed);
return;
}
if (e.Added.Count != 0) {
if (_currentCommitType == CommitReason.ShapeRecognition) {
timeMachine.CommitStrokeShapeHistory(ReplacedStroke, e.Added);
ReplacedStroke = null;
return;
} else {
}
else {
timeMachine.CommitStrokeUserInputHistory(e.Added);
return;
}
@ -67,11 +143,12 @@ namespace Ink_Canvas {
if (_currentCommitType == CommitReason.ShapeRecognition) {
ReplacedStroke = e.Removed;
return;
} else if (!IsEraseByPoint || _currentCommitType == CommitReason.ClearingCanvas) {
}
else if (!IsEraseByPoint || _currentCommitType == CommitReason.ClearingCanvas) {
timeMachine.CommitStrokeEraseHistory(e.Removed);
return;
}
}
}
}
}
}

View File

@ -358,23 +358,25 @@ namespace Ink_Canvas
}
}
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;
}
// -- removed --
//
//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_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
@ -433,6 +435,15 @@ namespace Ink_Canvas
catch { }
}
}
if (lastTempManiputlaionMatrix == null)
{
lastTempManiputlaionMatrix = m;
lastTempStrokeCollection = strokes;
}
else
{
lastTempManiputlaionMatrix?.Append(m);
}
}
else
{
@ -465,6 +476,15 @@ namespace Ink_Canvas
(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);
}
}
}
}