Skip to content

Commit

Permalink
[BugFix] 修复无法正常截图的bug/修改TimeMachine行为
Browse files Browse the repository at this point in the history
  • Loading branch information
Raspberry-Monster committed Mar 3, 2024
1 parent 9a50c6f commit 13d5c59
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
6 changes: 3 additions & 3 deletions Ink Canvas/Helpers/TimeMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ public void CommitStrokeShapeHistory(StrokeCollection strokeToBeReplaced, Stroke
NotifyUndoRedoState();
}

public void CommitStrokeRotateHistory(StrokeCollection strokeToBeReplaced, StrokeCollection generatedStroke)
public void CommitStrokeManipulationHistory(StrokeCollection strokeToBeReplaced, StrokeCollection generatedStroke)
{
if (_currentIndex + 1 < _currentStrokeHistory.Count)
{
_currentStrokeHistory.RemoveRange(_currentIndex + 1, (_currentStrokeHistory.Count - 1) - _currentIndex);
}
_currentStrokeHistory.Add(new TimeMachineHistory(generatedStroke,
TimeMachineHistoryType.Rotate,
TimeMachineHistoryType.Manipulation,
false,
strokeToBeReplaced));
_currentIndex = _currentStrokeHistory.Count - 1;
Expand Down Expand Up @@ -143,6 +143,6 @@ public enum TimeMachineHistoryType
UserInput,
ShapeRecognition,
Clear,
Rotate
Manipulation
}
}
1 change: 1 addition & 0 deletions Ink Canvas/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
ManipulationDelta="Main_Grid_ManipulationDelta"
ManipulationCompleted="Main_Grid_ManipulationCompleted"
ManipulationInertiaStarting="inkCanvas_ManipulationInertiaStarting"
ManipulationStarted="inkCanvas_ManipulationStarted"
IsManipulationEnabled="True"
EditingModeChanged="inkCanvas_EditingModeChanged"
PreviewTouchDown="inkCanvas_PreviewTouchDown"
Expand Down
54 changes: 37 additions & 17 deletions Ink Canvas/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ private enum CommitReason
ShapeDrawing,
ShapeRecognition,
ClearingCanvas,
Rotate
Manipulation
}

private CommitReason _currentCommitType = CommitReason.UserInput;
Expand All @@ -370,9 +370,9 @@ private void TimeMachine_OnRedoStateChanged(bool status)
private void StrokesOnStrokesChanged(object sender, StrokeCollectionChangedEventArgs e)
{
if (_currentCommitType == CommitReason.CodeInput || _currentCommitType == CommitReason.ShapeDrawing) return;
if (_currentCommitType == CommitReason.Rotate)
if (_currentCommitType == CommitReason.Manipulation)
{
timeMachine.CommitStrokeRotateHistory(e.Removed, e.Added);
timeMachine.CommitStrokeManipulationHistory(e.Removed, e.Added);
return;
}
if ((e.Added.Count != 0 || e.Removed.Count != 0) && IsEraseByPoint)
Expand Down Expand Up @@ -1947,6 +1947,23 @@ private void inkCanvas_ManipulationInertiaStarting(object sender, ManipulationIn
{

}
private void inkCanvas_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
{
if (isInMultiTouchMode || !Settings.Gesture.IsEnableTwoFingerGesture || inkCanvas.Strokes.Count == 0 || e.Manipulators.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)
{
Expand Down Expand Up @@ -3366,7 +3383,7 @@ private void BtnUndo_Click(object sender, RoutedEventArgs e)
}
}
}
else if (item.CommitType == TimeMachineHistoryType.Rotate)
else if (item.CommitType == TimeMachineHistoryType.Manipulation)
{
if (item.StrokeHasBeenCleared)
{
Expand Down Expand Up @@ -3497,7 +3514,7 @@ private void BtnRedo_Click(object sender, RoutedEventArgs e)
}
}
}
else if (item.CommitType == TimeMachineHistoryType.Rotate)
else if (item.CommitType == TimeMachineHistoryType.Manipulation)
{
if (item.StrokeHasBeenCleared)
{
Expand Down Expand Up @@ -3704,7 +3721,7 @@ private void ImageFlipHorizontal_MouseUp(object sender, MouseButtonEventArgs e)
{
stroke.Transform(m, false);
}
_currentCommitType = CommitReason.Rotate;
_currentCommitType = CommitReason.Manipulation;
inkCanvas.Strokes.Replace(targetStrokes, resultStrokes);
_currentCommitType = CommitReason.UserInput;
isProgramChangeStrokeSelection = true;
Expand Down Expand Up @@ -3736,7 +3753,7 @@ private void ImageFlipVertical_MouseUp(object sender, MouseButtonEventArgs e)
{
stroke.Transform(m, false);
}
_currentCommitType = CommitReason.Rotate;
_currentCommitType = CommitReason.Manipulation;
inkCanvas.Strokes.Replace(targetStrokes, resultStrokes);
_currentCommitType = CommitReason.UserInput;
isProgramChangeStrokeSelection = true;
Expand Down Expand Up @@ -3766,7 +3783,7 @@ private void ImageRotate45_MouseUp(object sender, MouseButtonEventArgs e)
{
stroke.Transform(m, false);
}
_currentCommitType = CommitReason.Rotate;
_currentCommitType = CommitReason.Manipulation;
inkCanvas.Strokes.Replace(targetStrokes, resultStrokes);
_currentCommitType = CommitReason.UserInput;
isProgramChangeStrokeSelection = true;
Expand Down Expand Up @@ -3796,7 +3813,7 @@ private void ImageRotate90_MouseUp(object sender, MouseButtonEventArgs e)
{
stroke.Transform(m, false);
}
_currentCommitType = CommitReason.Rotate;
_currentCommitType = CommitReason.Manipulation;
inkCanvas.Strokes.Replace(targetStrokes, resultStrokes);
_currentCommitType = CommitReason.UserInput;
isProgramChangeStrokeSelection = true;
Expand Down Expand Up @@ -5474,16 +5491,19 @@ private void inkCanvas_MouseUp(object sender, MouseButtonEventArgs e)
if (_currentCommitType == CommitReason.ShapeDrawing && drawingShapeMode != 9)
{
_currentCommitType = CommitReason.UserInput;
StrokeCollection collection;
StrokeCollection collection = null;
if (lastTempStrokeCollection != null && lastTempStrokeCollection.Count > 0)
{
collection = lastTempStrokeCollection;
}
else
else if(lastTempStroke != null)
{
collection = new StrokeCollection() { lastTempStroke };
}
timeMachine.CommitStrokeUserInputHistory(collection);
if (collection != null)
{
timeMachine.CommitStrokeUserInputHistory(collection);
}
}
lastTempStroke = null;
lastTempStrokeCollection = null;
Expand Down Expand Up @@ -5596,7 +5616,7 @@ private void RestoreStrokes(bool isBackupMain = false)
}
}
}
else if (item.CommitType == TimeMachineHistoryType.Rotate)
else if (item.CommitType == TimeMachineHistoryType.Manipulation)
{
if (item.StrokeHasBeenCleared)
{
Expand Down Expand Up @@ -5723,7 +5743,7 @@ private void RestoreStrokes(bool isBackupMain = false)
}
}
}
else if (item.CommitType == TimeMachineHistoryType.Rotate)
else if (item.CommitType == TimeMachineHistoryType.Manipulation)
{
if (item.StrokeHasBeenCleared)
{
Expand Down Expand Up @@ -6556,7 +6576,7 @@ public static string GetWebClient(string url)
myrp = (HttpWebResponse)ex.Response;
}

if (myrp.StatusCode != HttpStatusCode.OK)
if (myrp?.StatusCode != HttpStatusCode.OK)
{
return "null";
}
Expand Down Expand Up @@ -6750,9 +6770,9 @@ private void BtnScreenshot_Click(object sender, RoutedEventArgs e)

private void SaveScreenShot(bool isHideNotification, string fileName = null)
{
System.Drawing.Rectangle rc = System.Windows.Forms.SystemInformation.VirtualScreen;
var size = System.Windows.Forms.SystemInformation.PrimaryMonitorSize;
var rc = new System.Drawing.Rectangle(new System.Drawing.Point(0, 0), new System.Drawing.Size(size.Width, size.Height));
var bitmap = new System.Drawing.Bitmap(rc.Width, rc.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

using (System.Drawing.Graphics memoryGrahics = System.Drawing.Graphics.FromImage(bitmap))
{
memoryGrahics.CopyFromScreen(rc.X, rc.Y, 0, 0, rc.Size, System.Drawing.CopyPixelOperation.SourceCopy);
Expand Down

0 comments on commit 13d5c59

Please sign in to comment.