[Typo/TimeMachine] 修改部分变量命名,支持撤回擦除行为

This commit is contained in:
Raspberry-Monster 2023-04-19 22:34:49 +08:00
parent a74ac6eb7a
commit c0b33140ab
No known key found for this signature in database
GPG Key ID: 9A0D725BB122D507
3 changed files with 69 additions and 56 deletions

View File

@ -51,13 +51,7 @@ namespace Ink_Canvas.Helpers
{ {
_currentStrokeHistory.RemoveRange(_currentIndex +1 , (_currentStrokeHistory.Count - 1) - _currentIndex); _currentStrokeHistory.RemoveRange(_currentIndex +1 , (_currentStrokeHistory.Count - 1) - _currentIndex);
} }
var col = new StrokeCollection(); _currentStrokeHistory.Add(new TimeMachineHistory(stroke, TimeMachineHistoryType.Clear, true));
foreach (var stroke1 in stroke)
{
col.Add(stroke1);
}
_currentStrokeHistory.Add(new TimeMachineHistory(col, TimeMachineHistoryType.Clear, true));
_currentIndex = _currentStrokeHistory.Count - 1; _currentIndex = _currentStrokeHistory.Count - 1;
OnUndoStateChanged?.Invoke(true); OnUndoStateChanged?.Invoke(true);
OnRedoStateChanged?.Invoke(false); OnRedoStateChanged?.Invoke(false);
@ -73,7 +67,7 @@ namespace Ink_Canvas.Helpers
public TimeMachineHistory Undo() public TimeMachineHistory Undo()
{ {
var item = _currentStrokeHistory[_currentIndex]; var item = _currentStrokeHistory[_currentIndex];
item.IsReversed = !item.IsReversed; item.StrokeHasBeenCleared = !item.StrokeHasBeenCleared;
_currentIndex--; _currentIndex--;
OnUndoStateChanged?.Invoke(_currentIndex > -1); OnUndoStateChanged?.Invoke(_currentIndex > -1);
OnRedoStateChanged?.Invoke(_currentStrokeHistory.Count - _currentIndex - 1 > 0); OnRedoStateChanged?.Invoke(_currentStrokeHistory.Count - _currentIndex - 1 > 0);
@ -83,7 +77,7 @@ namespace Ink_Canvas.Helpers
public TimeMachineHistory Redo() public TimeMachineHistory Redo()
{ {
var item = _currentStrokeHistory[++_currentIndex]; var item = _currentStrokeHistory[++_currentIndex];
item.IsReversed = !item.IsReversed; item.StrokeHasBeenCleared = !item.StrokeHasBeenCleared;
OnUndoStateChanged?.Invoke(_currentIndex > -1); OnUndoStateChanged?.Invoke(_currentIndex > -1);
if (_currentIndex != -1) OnRedoStateChanged?.Invoke(_currentStrokeHistory.Count - _currentIndex - 1 > 0); if (_currentIndex != -1) OnRedoStateChanged?.Invoke(_currentStrokeHistory.Count - _currentIndex - 1 > 0);
return item; return item;
@ -111,22 +105,22 @@ namespace Ink_Canvas.Helpers
public class TimeMachineHistory public class TimeMachineHistory
{ {
public TimeMachineHistoryType CommitType; public TimeMachineHistoryType CommitType;
public bool IsReversed; public bool StrokeHasBeenCleared;
public StrokeCollection CurrentStroke; public StrokeCollection CurrentStroke;
public StrokeCollection ShapeRecognitionReplacedStroke; public StrokeCollection ReplacedStroke;
public TimeMachineHistory(StrokeCollection currentStroke, TimeMachineHistoryType commitType, bool isReversed) public TimeMachineHistory(StrokeCollection currentStroke, TimeMachineHistoryType commitType, bool strokeHasBeenCleared)
{ {
CommitType = commitType; CommitType = commitType;
CurrentStroke = currentStroke; CurrentStroke = currentStroke;
IsReversed = isReversed; StrokeHasBeenCleared = strokeHasBeenCleared;
ShapeRecognitionReplacedStroke = null; ReplacedStroke = null;
} }
public TimeMachineHistory(StrokeCollection currentStroke, TimeMachineHistoryType commitType, bool isReversed , StrokeCollection shapeRecognitionReplacedStroke) public TimeMachineHistory(StrokeCollection currentStroke, TimeMachineHistoryType commitType, bool strokeHasBeenCleared , StrokeCollection replacedStroke)
{ {
CommitType = commitType; CommitType = commitType;
CurrentStroke = currentStroke; CurrentStroke = currentStroke;
IsReversed = isReversed; StrokeHasBeenCleared = strokeHasBeenCleared;
ShapeRecognitionReplacedStroke = shapeRecognitionReplacedStroke; ReplacedStroke = replacedStroke;
} }
} }

View File

@ -106,7 +106,8 @@
MouseUp="inkCanvas_MouseUp" MouseUp="inkCanvas_MouseUp"
ManipulationStarting="inkCanvas_ManipulationStarting" ManipulationStarting="inkCanvas_ManipulationStarting"
SelectionChanged="inkCanvas_SelectionChanged" SelectionChanged="inkCanvas_SelectionChanged"
StrokeCollected="inkCanvas_StrokeCollected"> StrokeCollected="inkCanvas_StrokeCollected"
StrokeErasing="InkCanvas_OnStrokeErasing">
<!--<InkCanvas.DefaultDrawingAttributes> <!--<InkCanvas.DefaultDrawingAttributes>
<DrawingAttributes StylusTip="Ellipse" Height="8" Width="4" IgnorePressure="False" FitToCurve="True" > <DrawingAttributes StylusTip="Ellipse" Height="8" Width="4" IgnorePressure="False" FitToCurve="True" >
<DrawingAttributes.StylusTipTransform> <DrawingAttributes.StylusTipTransform>

View File

@ -192,9 +192,6 @@ namespace Ink_Canvas
catch { } catch { }
} }
private bool isPreviousErasing = false;
private StrokeCollection previousStrokes = new StrokeCollection();
private void inkCanvas_EditingModeChanged(object sender, RoutedEventArgs e) private void inkCanvas_EditingModeChanged(object sender, RoutedEventArgs e)
{ {
var inkCanvas1 = sender as InkCanvas; var inkCanvas1 = sender as InkCanvas;
@ -214,22 +211,6 @@ namespace Ink_Canvas
{ {
inkCanvas1.ForceCursor = false; inkCanvas1.ForceCursor = false;
} }
if (inkCanvas1.EditingMode == InkCanvasEditingMode.EraseByPoint ||
inkCanvas1.EditingMode == InkCanvasEditingMode.EraseByStroke)
{
isPreviousErasing = true;
previousStrokes.Clear();
foreach (var inkCanvas1Stroke in inkCanvas1.Strokes)
{
previousStrokes.Add(inkCanvas1Stroke);
}
}
else if (isPreviousErasing)
{
timeMachine.CommitStrokeEraseHistory(previousStrokes);
isPreviousErasing = false;
}
if (inkCanvas1.EditingMode == InkCanvasEditingMode.Ink) forcePointEraser = !forcePointEraser; if (inkCanvas1.EditingMode == InkCanvasEditingMode.Ink) forcePointEraser = !forcePointEraser;
} }
@ -1821,7 +1802,11 @@ namespace Ink_Canvas
} }
} }
} }
private void InkCanvas_OnStrokeErasing(object sender, InkCanvasStrokeErasingEventArgs e)
{
_previousIsErasing = true;
_erasedStrokeCollection.Add(e.Stroke);
}
private void inkCanvas_ManipulationStarting(object sender, ManipulationStartingEventArgs e) private void inkCanvas_ManipulationStarting(object sender, ManipulationStartingEventArgs e)
{ {
e.Mode = ManipulationModes.All; e.Mode = ManipulationModes.All;
@ -3072,7 +3057,7 @@ namespace Ink_Canvas
var item = timeMachine.Undo(); var item = timeMachine.Undo();
if (item.CommitType == TimeMachineHistoryType.UserInput) if (item.CommitType == TimeMachineHistoryType.UserInput)
{ {
if (!item.IsReversed) if (!item.StrokeHasBeenCleared)
{ {
foreach (var strokes in item.CurrentStroke) foreach (var strokes in item.CurrentStroke)
{ {
@ -3091,7 +3076,7 @@ namespace Ink_Canvas
} }
else if (item.CommitType == TimeMachineHistoryType.ShapeRecognition) else if (item.CommitType == TimeMachineHistoryType.ShapeRecognition)
{ {
if (item.IsReversed) if (item.StrokeHasBeenCleared)
{ {
foreach (var strokes in item.CurrentStroke) foreach (var strokes in item.CurrentStroke)
@ -3099,7 +3084,7 @@ namespace Ink_Canvas
if (inkCanvas.Strokes.Contains(strokes)) if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes); inkCanvas.Strokes.Remove(strokes);
} }
foreach (var strokes in item.ShapeRecognitionReplacedStroke) foreach (var strokes in item.ReplacedStroke)
{ {
if (!inkCanvas.Strokes.Contains(strokes)) if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes); inkCanvas.Strokes.Add(strokes);
@ -3112,7 +3097,7 @@ namespace Ink_Canvas
if (!inkCanvas.Strokes.Contains(strokes)) if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes); inkCanvas.Strokes.Add(strokes);
} }
foreach (var strokes in item.ShapeRecognitionReplacedStroke) foreach (var strokes in item.ReplacedStroke)
{ {
if (inkCanvas.Strokes.Contains(strokes)) if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes); inkCanvas.Strokes.Remove(strokes);
@ -3121,10 +3106,21 @@ namespace Ink_Canvas
} }
else if(item.CommitType == TimeMachineHistoryType.Clear) else if(item.CommitType == TimeMachineHistoryType.Clear)
{ {
inkCanvas.Strokes.Clear(); if (!item.StrokeHasBeenCleared)
foreach (var stroke in item.CurrentStroke)
{ {
inkCanvas.Strokes.Add(stroke); 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);
}
} }
} }
} }
@ -3134,7 +3130,7 @@ namespace Ink_Canvas
var item = timeMachine.Redo(); var item = timeMachine.Redo();
if (item.CommitType == TimeMachineHistoryType.UserInput) if (item.CommitType == TimeMachineHistoryType.UserInput)
{ {
if (!item.IsReversed) if (!item.StrokeHasBeenCleared)
{ {
foreach (var strokes in item.CurrentStroke) foreach (var strokes in item.CurrentStroke)
{ {
@ -3153,7 +3149,7 @@ namespace Ink_Canvas
} }
else if (item.CommitType == TimeMachineHistoryType.ShapeRecognition) else if (item.CommitType == TimeMachineHistoryType.ShapeRecognition)
{ {
if (item.IsReversed) if (item.StrokeHasBeenCleared)
{ {
foreach (var strokes in item.CurrentStroke) foreach (var strokes in item.CurrentStroke)
@ -3161,7 +3157,7 @@ namespace Ink_Canvas
if (inkCanvas.Strokes.Contains(strokes)) if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes); inkCanvas.Strokes.Remove(strokes);
} }
foreach (var strokes in item.ShapeRecognitionReplacedStroke) foreach (var strokes in item.ReplacedStroke)
{ {
if (!inkCanvas.Strokes.Contains(strokes)) if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes); inkCanvas.Strokes.Add(strokes);
@ -3174,7 +3170,7 @@ namespace Ink_Canvas
if (!inkCanvas.Strokes.Contains(strokes)) if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes); inkCanvas.Strokes.Add(strokes);
} }
foreach (var strokes in item.ShapeRecognitionReplacedStroke) foreach (var strokes in item.ReplacedStroke)
{ {
if (inkCanvas.Strokes.Contains(strokes)) if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes); inkCanvas.Strokes.Remove(strokes);
@ -3183,7 +3179,22 @@ namespace Ink_Canvas
} }
else if(item.CommitType == TimeMachineHistoryType.Clear) else if(item.CommitType == TimeMachineHistoryType.Clear)
{ {
inkCanvas.Strokes.Clear(); 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);
}
}
} }
} }
@ -4898,6 +4909,8 @@ namespace Ink_Canvas
} }
} }
private bool _previousIsErasing = false;
private StrokeCollection _erasedStrokeCollection = new StrokeCollection();
private void inkCanvas_MouseUp(object sender, MouseButtonEventArgs e) private void inkCanvas_MouseUp(object sender, MouseButtonEventArgs e)
{ {
if (drawingShapeMode == 5) if (drawingShapeMode == 5)
@ -4954,6 +4967,12 @@ namespace Ink_Canvas
} }
} }
isMouseDown = false; isMouseDown = false;
if (_previousIsErasing)
{
timeMachine.CommitStrokeEraseHistory(_erasedStrokeCollection);
_previousIsErasing = false;
_erasedStrokeCollection = new StrokeCollection();
}
} }
private bool NeedUpdateIniP() private bool NeedUpdateIniP()
@ -5008,7 +5027,7 @@ namespace Ink_Canvas
{ {
foreach (var item in TimeMachineHistories[0]) foreach (var item in TimeMachineHistories[0])
{ {
if (!item.IsReversed) if (!item.StrokeHasBeenCleared)
{ {
switch (item.CommitType) switch (item.CommitType)
{ {
@ -5016,7 +5035,7 @@ namespace Ink_Canvas
inkCanvas.Strokes.Add(item.CurrentStroke); inkCanvas.Strokes.Add(item.CurrentStroke);
break; break;
case TimeMachineHistoryType.ShapeRecognition: case TimeMachineHistoryType.ShapeRecognition:
inkCanvas.Strokes.Remove(item.ShapeRecognitionReplacedStroke); inkCanvas.Strokes.Remove(item.ReplacedStroke);
inkCanvas.Strokes.Add(item.CurrentStroke); inkCanvas.Strokes.Add(item.CurrentStroke);
break; break;
case TimeMachineHistoryType.Clear: case TimeMachineHistoryType.Clear:
@ -5032,7 +5051,7 @@ namespace Ink_Canvas
{ {
foreach (var item in TimeMachineHistories[CurrentWhiteboardIndex]) foreach (var item in TimeMachineHistories[CurrentWhiteboardIndex])
{ {
if (!item.IsReversed) if (!item.StrokeHasBeenCleared)
{ {
switch (item.CommitType) switch (item.CommitType)
{ {
@ -5040,7 +5059,7 @@ namespace Ink_Canvas
inkCanvas.Strokes.Add(item.CurrentStroke); inkCanvas.Strokes.Add(item.CurrentStroke);
break; break;
case TimeMachineHistoryType.ShapeRecognition: case TimeMachineHistoryType.ShapeRecognition:
inkCanvas.Strokes.Remove(item.ShapeRecognitionReplacedStroke); inkCanvas.Strokes.Remove(item.ReplacedStroke);
inkCanvas.Strokes.Add(item.CurrentStroke); inkCanvas.Strokes.Add(item.CurrentStroke);
break; break;
case TimeMachineHistoryType.Clear: case TimeMachineHistoryType.Clear:
@ -6551,7 +6570,6 @@ namespace Ink_Canvas
#endregion #endregion
} }
#region Test for pen #region Test for pen