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

View File

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

View File

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