Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Feature] 新增多步撤回功能 (Project Name: TimeMachine) #62

Merged
merged 25 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5d4f0d4
[TimeMachine] 引入TimeMachine(多步撤回工具)
Raspberry-Monster Apr 15, 2023
28a957e
[feat] 新增橡皮和清屏的撤销
kengwang Apr 15, 2023
27b75ca
[fix] 修复 Redo 时的清屏无效
kengwang Apr 15, 2023
349eaf6
[fix] 修复了可能导致崩溃的问题
kengwang Apr 16, 2023
d4cb88a
[chore] 支持撤销删除选中墨迹
kengwang Apr 16, 2023
500fd28
[WIP] 添加对切换页面保存记录的支持
Raspberry-Monster Apr 16, 2023
a74ac6e
Merge branch 'feat/TimeMachine' of https://github.com/WXRIW/Ink-Canva…
Raspberry-Monster Apr 16, 2023
c0b3314
[Typo/TimeMachine] 修改部分变量命名,支持撤回擦除行为
Raspberry-Monster Apr 19, 2023
5ccf315
[Clean UP/TimeMachine][WIP] 支持撤回EraseByPoint(此版本切换页面无法保留记录)
Raspberry-Monster Apr 21, 2023
eda13ff
[BugFix] 修复切换页面时无法保存墨迹的Bug
Raspberry-Monster Apr 22, 2023
043423d
[PPT] 支持PPT页面撤销
Raspberry-Monster Apr 22, 2023
2baa23f
Merge branch 'master' of https://github.com/WXRIW/Ink-Canvas into fea…
Raspberry-Monster Apr 22, 2023
f2f106a
[Bug Fix] 尝试修复在使用墨迹识别/图形绘制时撤销不正确的bug
Raspberry-Monster Apr 23, 2023
c570534
Merge branch 'master' of https://github.com/WXRIW/Ink-Canvas into fea…
Raspberry-Monster Apr 23, 2023
6012448
[Typo] 修正合并冲突
Raspberry-Monster Apr 23, 2023
99fd549
Merge branch 'master' of https://github.com/WXRIW/Ink-Canvas into fea…
Raspberry-Monster Apr 25, 2023
4d55584
[Merge/Exception Handle] 添加UnhandledException处理,解决合并冲突
Raspberry-Monster Apr 25, 2023
04beedc
[LogHelper] Save Unhandled Exception Info To File
Raspberry-Monster Apr 25, 2023
6d0e379
Use snackbar instead of messagebox for unhandled exception
WXRIW Apr 25, 2023
7b4041a
[Bug Fix/TimeMachine] 修复在部分情况下无法保存笔画记录,支持撤销完整正方体
Raspberry-Monster Apr 26, 2023
080b849
[EraseByPoint] 修改添加和移除Stroke的顺序以保证在Stroke复杂时的撤销/重做行为正常
Raspberry-Monster Apr 27, 2023
6d054cf
[Rotate] 支持撤回旋转操作
Raspberry-Monster May 7, 2023
72bf678
[Undo/Redo] 在Undo/Redo时取消选择
Raspberry-Monster May 7, 2023
89d438f
Fix UI
WXRIW May 8, 2023
2f617e2
Code cleanup
WXRIW May 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Ink Canvas/CountdownTimerWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ private void BtnMinimal_OnMouseUp(object sender, MouseButtonEventArgs e)
Height = 700;
BigViewController.Visibility = Visibility.Visible;
TbCurrentTime.Visibility = Visibility.Collapsed;

// Set to center
double screenWidth = System.Windows.SystemParameters.PrimaryScreenWidth;
double screenHeight = System.Windows.SystemParameters.PrimaryScreenHeight;
Expand Down
131 changes: 131 additions & 0 deletions Ink Canvas/Helpers/TimeMachine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
using System.Collections.Generic;
using System.Windows.Ink;

namespace Ink_Canvas.Helpers
{
public class TimeMachine
{
private readonly List<TimeMachineHistory> _currentStrokeHistory = new List<TimeMachineHistory>();

private int _currentIndex = -1;

public delegate void OnUndoStateChange(bool status);

public event OnUndoStateChange OnUndoStateChanged;

public delegate void OnRedoStateChange(bool status);

public event OnRedoStateChange OnRedoStateChanged;

public void CommitStrokeUserInputHistory(StrokeCollection stroke)
{
if (_currentIndex + 1 < _currentStrokeHistory.Count)
{
_currentStrokeHistory.RemoveRange(_currentIndex + 1, (_currentStrokeHistory.Count - 1) - _currentIndex);
}
_currentStrokeHistory.Add(new TimeMachineHistory(stroke, TimeMachineHistoryType.UserInput, false));
_currentIndex = _currentStrokeHistory.Count - 1;
NotifyUndoRedoState();
}

public void CommitStrokeShapeHistory(StrokeCollection strokeToBeReplaced, StrokeCollection generatedStroke)
{
if (_currentIndex + 1 < _currentStrokeHistory.Count)
{
_currentStrokeHistory.RemoveRange(_currentIndex + 1, (_currentStrokeHistory.Count - 1) - _currentIndex);
}
_currentStrokeHistory.Add(new TimeMachineHistory(generatedStroke,
TimeMachineHistoryType.ShapeRecognition,
false,
strokeToBeReplaced));
_currentIndex = _currentStrokeHistory.Count - 1;
NotifyUndoRedoState();
}

public void CommitStrokeEraseHistory(StrokeCollection stroke, StrokeCollection sourceStroke = null)
{
if (_currentIndex + 1 < _currentStrokeHistory.Count)
{
_currentStrokeHistory.RemoveRange(_currentIndex + 1, (_currentStrokeHistory.Count - 1) - _currentIndex);
}
_currentStrokeHistory.Add(new TimeMachineHistory(stroke, TimeMachineHistoryType.Clear, true, sourceStroke));
_currentIndex = _currentStrokeHistory.Count - 1;
NotifyUndoRedoState();
}

public void ClearStrokeHistory()
{
_currentStrokeHistory.Clear();
_currentIndex = -1;
NotifyUndoRedoState();
}
public TimeMachineHistory Undo()
{
var item = _currentStrokeHistory[_currentIndex];
item.StrokeHasBeenCleared = !item.StrokeHasBeenCleared;
_currentIndex--;
OnUndoStateChanged?.Invoke(_currentIndex > -1);
OnRedoStateChanged?.Invoke(_currentStrokeHistory.Count - _currentIndex - 1 > 0);
return item;
}

public TimeMachineHistory Redo()
{
var item = _currentStrokeHistory[++_currentIndex];
item.StrokeHasBeenCleared = !item.StrokeHasBeenCleared;
NotifyUndoRedoState();
return item;
}
public TimeMachineHistory[] ExportTimeMachineHistory()
{
if (_currentIndex + 1 < _currentStrokeHistory.Count)
{
_currentStrokeHistory.RemoveRange(_currentIndex + 1, (_currentStrokeHistory.Count - 1) - _currentIndex);
}
return _currentStrokeHistory.ToArray();
}

public bool ImportTimeMachineHistory(TimeMachineHistory[] sourceHistory)
{
_currentStrokeHistory.Clear();
_currentStrokeHistory.AddRange(sourceHistory);
_currentIndex = _currentStrokeHistory.Count - 1;
NotifyUndoRedoState();
return true;
}
private void NotifyUndoRedoState()
{
OnUndoStateChanged?.Invoke(_currentIndex > -1);
OnRedoStateChanged?.Invoke(_currentStrokeHistory.Count - _currentIndex - 1 > 0);
}
}

public class TimeMachineHistory
{
public TimeMachineHistoryType CommitType;
public bool StrokeHasBeenCleared;
public StrokeCollection CurrentStroke;
public StrokeCollection ReplacedStroke;
public TimeMachineHistory(StrokeCollection currentStroke, TimeMachineHistoryType commitType, bool strokeHasBeenCleared)
{
CommitType = commitType;
CurrentStroke = currentStroke;
StrokeHasBeenCleared = strokeHasBeenCleared;
ReplacedStroke = null;
}
public TimeMachineHistory(StrokeCollection currentStroke, TimeMachineHistoryType commitType, bool strokeHasBeenCleared, StrokeCollection replacedStroke)
{
CommitType = commitType;
CurrentStroke = currentStroke;
StrokeHasBeenCleared = strokeHasBeenCleared;
ReplacedStroke = replacedStroke;
}
}

public enum TimeMachineHistoryType
{
UserInput,
ShapeRecognition,
Clear
}
}
1 change: 1 addition & 0 deletions Ink Canvas/Ink Canvas.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
<Compile Include="Helpers\InkRecognizeHelper.cs" />
<Compile Include="Helpers\LogHelper.cs" />
<Compile Include="Helpers\MultiTouchInput.cs" />
<Compile Include="Helpers\TimeMachine.cs" />
<Compile Include="Helpers\VisibilityConverter.cs" />
<Compile Include="NamesInputWindow.xaml.cs">
<DependentUpon>NamesInputWindow.xaml</DependentUpon>
Expand Down
18 changes: 11 additions & 7 deletions Ink Canvas/MainWindow.xaml
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不用修改,在 master 里我已经进行了相关优化,换行看起来有点突兀

Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,17 @@
ManipulationDelta="Main_Grid_ManipulationDelta"
ManipulationCompleted="Main_Grid_ManipulationCompleted"
ManipulationInertiaStarting="inkCanvas_ManipulationInertiaStarting"
IsManipulationEnabled="True" EditingModeChanged="inkCanvas_EditingModeChanged"
IsManipulationEnabled="True"
EditingModeChanged="inkCanvas_EditingModeChanged"
PreviewTouchDown="inkCanvas_PreviewTouchDown"
PreviewTouchUp="inkCanvas_PreviewTouchUp"
MouseDown="inkCanvas_MouseDown" MouseMove="inkCanvas_MouseMove" MouseUp="inkCanvas_MouseUp"
MouseDown="inkCanvas_MouseDown"
MouseMove="inkCanvas_MouseMove"
MouseUp="inkCanvas_MouseUp"
ManipulationStarting="inkCanvas_ManipulationStarting"
SelectionChanged="inkCanvas_SelectionChanged"
StrokeCollected="inkCanvas_StrokeCollected">
StrokeCollected="inkCanvas_StrokeCollected"
>
<!--<InkCanvas.DefaultDrawingAttributes>
<DrawingAttributes StylusTip="Ellipse" Height="8" Width="4" IgnorePressure="False" FitToCurve="True" >
<DrawingAttributes.StylusTipTransform>
Expand Down Expand Up @@ -563,7 +567,7 @@
<Bold>开发者:</Bold> XY Wang (WXRIW)
</TextBlock>
<TextBlock FontSize="14">
<Bold>贡献者:</Bold> Kengwang, jiajiaxd, CN-Ironegg, Raspberry Kan
<Bold>贡献者:</Bold> Kengwang, jiajiaxd, CN-Ironegg<LineBreak/>Raspberry Kan
</TextBlock>
<TextBlock FontSize="14">
<Bold>开源地址:</Bold>
Expand Down Expand Up @@ -848,7 +852,7 @@
Margin="0,10,0,0" Width="{Binding ElementName=StackPanelMain, Path=ActualWidth}"
Click="BtnUndo_Click" Foreground="{Binding ElementName=BtnExit, Path=Foreground}"
Background="{Binding ElementName=BtnExit, Path=Background}"
IsEnabled="False" IsEnabledChanged="Btn_IsEnabledChanged">
IsEnabled="False" Visibility="Collapsed" IsEnabledChanged="Btn_IsEnabledChanged">
<StackPanel Opacity="0.2">
<ui:SymbolIcon Symbol="Undo"/>
<TextBlock Text="撤销" Margin="0,4,0,0"/>
Expand Down Expand Up @@ -1129,7 +1133,7 @@
</Border>
</Grid>
<Viewbox Margin="0,2">
<Grid>
<StackPanel Orientation="Horizontal">
<ui:SymbolIcon Symbol="Undo" Foreground="#666666"
Visibility="{Binding ElementName=BtnUndo, Path=Visibility}"
IsEnabled="{Binding ElementName=BtnUndo, Path=IsEnabled}"
Expand All @@ -1138,7 +1142,7 @@
Visibility="{Binding ElementName=BtnRedo, Path=Visibility}"
IsEnabled="{Binding ElementName=BtnRedo, Path=IsEnabled}"
MouseUp="SymbolIconRedo_MouseUp" MouseDown="Border_MouseDown"/>
</Grid>
</StackPanel>
</Viewbox>
</ui:SimpleStackPanel>
<ui:SimpleStackPanel Orientation="{Binding ElementName=StackPanelFloatingBar, Path=Orientation}">
Expand Down
Loading