2024-05-01 18:23:32 +08:00
|
|
|
|
using Ink_Canvas.Helpers;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Ink;
|
|
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
|
|
|
|
|
namespace Ink_Canvas {
|
|
|
|
|
public partial class MainWindow : Window {
|
2024-06-05 20:25:26 +08:00
|
|
|
|
private StrokeCollection[] strokeCollections = new StrokeCollection[101];
|
|
|
|
|
private bool[] whiteboadLastModeIsRedo = new bool[101];
|
|
|
|
|
private StrokeCollection lastTouchDownStrokeCollection = new StrokeCollection();
|
2024-05-01 18:23:32 +08:00
|
|
|
|
|
2024-06-05 20:25:26 +08:00
|
|
|
|
private int CurrentWhiteboardIndex = 1;
|
|
|
|
|
private int WhiteboardTotalCount = 1;
|
|
|
|
|
private TimeMachineHistory[][] TimeMachineHistories = new TimeMachineHistory[101][]; //最多99页,0用来存储非白板时的墨迹以便还原
|
2024-05-01 18:23:32 +08:00
|
|
|
|
|
|
|
|
|
private void SaveStrokes(bool isBackupMain = false) {
|
|
|
|
|
if (isBackupMain) {
|
|
|
|
|
var timeMachineHistory = timeMachine.ExportTimeMachineHistory();
|
|
|
|
|
TimeMachineHistories[0] = timeMachineHistory;
|
|
|
|
|
timeMachine.ClearStrokeHistory();
|
2024-06-05 20:25:26 +08:00
|
|
|
|
}
|
|
|
|
|
else {
|
2024-05-01 18:23:32 +08:00
|
|
|
|
var timeMachineHistory = timeMachine.ExportTimeMachineHistory();
|
|
|
|
|
TimeMachineHistories[CurrentWhiteboardIndex] = timeMachineHistory;
|
|
|
|
|
timeMachine.ClearStrokeHistory();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ClearStrokes(bool isErasedByCode) {
|
|
|
|
|
_currentCommitType = CommitReason.ClearingCanvas;
|
|
|
|
|
if (isErasedByCode) _currentCommitType = CommitReason.CodeInput;
|
|
|
|
|
inkCanvas.Strokes.Clear();
|
|
|
|
|
_currentCommitType = CommitReason.UserInput;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RestoreStrokes(bool isBackupMain = false) {
|
|
|
|
|
try {
|
|
|
|
|
if (TimeMachineHistories[CurrentWhiteboardIndex] == null) return; //防止白板打开后不居中
|
|
|
|
|
if (isBackupMain) {
|
|
|
|
|
timeMachine.ImportTimeMachineHistory(TimeMachineHistories[0]);
|
2024-06-05 20:25:26 +08:00
|
|
|
|
foreach (var item in TimeMachineHistories[0]) ApplyHistoryToCanvas(item);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2024-05-01 18:23:32 +08:00
|
|
|
|
timeMachine.ImportTimeMachineHistory(TimeMachineHistories[CurrentWhiteboardIndex]);
|
2024-06-05 20:25:26 +08:00
|
|
|
|
foreach (var item in TimeMachineHistories[CurrentWhiteboardIndex]) ApplyHistoryToCanvas(item);
|
2024-05-01 18:23:32 +08:00
|
|
|
|
}
|
2024-06-05 20:25:26 +08:00
|
|
|
|
}
|
|
|
|
|
catch {
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
2024-05-01 18:23:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BtnWhiteBoardSwitchPrevious_Click(object sender, EventArgs e) {
|
|
|
|
|
if (CurrentWhiteboardIndex <= 1) return;
|
|
|
|
|
|
|
|
|
|
SaveStrokes();
|
|
|
|
|
|
|
|
|
|
ClearStrokes(true);
|
|
|
|
|
CurrentWhiteboardIndex--;
|
|
|
|
|
|
|
|
|
|
RestoreStrokes();
|
|
|
|
|
|
|
|
|
|
UpdateIndexInfoDisplay();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BtnWhiteBoardSwitchNext_Click(object sender, EventArgs e) {
|
2024-06-05 20:25:26 +08:00
|
|
|
|
if (Settings.Automation.IsAutoSaveStrokesAtClear &&
|
|
|
|
|
inkCanvas.Strokes.Count > Settings.Automation.MinimumAutomationStrokeNumber) SaveScreenShot(true);
|
2024-05-01 18:23:32 +08:00
|
|
|
|
if (CurrentWhiteboardIndex >= WhiteboardTotalCount) {
|
|
|
|
|
BtnWhiteBoardAdd_Click(sender, e);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-06-05 20:25:26 +08:00
|
|
|
|
|
2024-05-01 18:23:32 +08:00
|
|
|
|
SaveStrokes();
|
|
|
|
|
|
|
|
|
|
ClearStrokes(true);
|
|
|
|
|
CurrentWhiteboardIndex++;
|
|
|
|
|
|
|
|
|
|
RestoreStrokes();
|
|
|
|
|
|
|
|
|
|
UpdateIndexInfoDisplay();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BtnWhiteBoardAdd_Click(object sender, EventArgs e) {
|
|
|
|
|
if (WhiteboardTotalCount >= 99) return;
|
2024-06-05 20:25:26 +08:00
|
|
|
|
if (Settings.Automation.IsAutoSaveStrokesAtClear &&
|
|
|
|
|
inkCanvas.Strokes.Count > Settings.Automation.MinimumAutomationStrokeNumber) SaveScreenShot(true);
|
2024-05-01 18:23:32 +08:00
|
|
|
|
SaveStrokes();
|
|
|
|
|
ClearStrokes(true);
|
|
|
|
|
|
|
|
|
|
WhiteboardTotalCount++;
|
|
|
|
|
CurrentWhiteboardIndex++;
|
|
|
|
|
|
2024-06-05 20:25:26 +08:00
|
|
|
|
if (CurrentWhiteboardIndex != WhiteboardTotalCount)
|
|
|
|
|
for (var i = WhiteboardTotalCount; i > CurrentWhiteboardIndex; i--)
|
2024-05-01 18:23:32 +08:00
|
|
|
|
TimeMachineHistories[i] = TimeMachineHistories[i - 1];
|
|
|
|
|
|
|
|
|
|
UpdateIndexInfoDisplay();
|
|
|
|
|
|
|
|
|
|
if (WhiteboardTotalCount >= 99) BtnWhiteBoardAdd.IsEnabled = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BtnWhiteBoardDelete_Click(object sender, RoutedEventArgs e) {
|
|
|
|
|
ClearStrokes(true);
|
|
|
|
|
|
2024-06-05 20:25:26 +08:00
|
|
|
|
if (CurrentWhiteboardIndex != WhiteboardTotalCount)
|
|
|
|
|
for (var i = CurrentWhiteboardIndex; i <= WhiteboardTotalCount; i++)
|
2024-05-01 18:23:32 +08:00
|
|
|
|
TimeMachineHistories[i] = TimeMachineHistories[i + 1];
|
2024-06-05 20:25:26 +08:00
|
|
|
|
else
|
2024-05-01 18:23:32 +08:00
|
|
|
|
CurrentWhiteboardIndex--;
|
|
|
|
|
|
|
|
|
|
WhiteboardTotalCount--;
|
|
|
|
|
|
|
|
|
|
RestoreStrokes();
|
|
|
|
|
|
|
|
|
|
UpdateIndexInfoDisplay();
|
|
|
|
|
|
|
|
|
|
if (WhiteboardTotalCount < 99) BtnWhiteBoardAdd.IsEnabled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateIndexInfoDisplay() {
|
2024-06-05 20:25:26 +08:00
|
|
|
|
TextBlockWhiteBoardIndexInfo.Text =
|
2024-06-09 15:14:58 +08:00
|
|
|
|
$"{CurrentWhiteboardIndex}/{WhiteboardTotalCount}";
|
2024-05-01 18:23:32 +08:00
|
|
|
|
|
|
|
|
|
if (CurrentWhiteboardIndex == WhiteboardTotalCount) {
|
2024-06-05 20:25:26 +08:00
|
|
|
|
var newImageSource = new BitmapImage();
|
2024-05-01 18:23:32 +08:00
|
|
|
|
newImageSource.BeginInit();
|
2024-06-05 20:25:26 +08:00
|
|
|
|
newImageSource.UriSource = new Uri("/Resources/Icons-Fluent/ic_fluent_add_circle_24_regular.png",
|
|
|
|
|
UriKind.RelativeOrAbsolute);
|
2024-05-01 18:23:32 +08:00
|
|
|
|
newImageSource.EndInit();
|
2024-06-09 15:14:58 +08:00
|
|
|
|
//BoardLeftPannelNextPage.Source = newImageSource;
|
|
|
|
|
//BoardRightPannelNextPage.Source = newImageSource;
|
|
|
|
|
//BoardRightPannelNextPageTextBlock.Text = "加页";
|
|
|
|
|
//BoardLeftPannelNextPageTextBlock.Text = "加页";
|
2024-06-05 20:25:26 +08:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
var newImageSource = new BitmapImage();
|
2024-05-01 18:23:32 +08:00
|
|
|
|
newImageSource.BeginInit();
|
2024-06-05 20:25:26 +08:00
|
|
|
|
newImageSource.UriSource =
|
|
|
|
|
new Uri("/Resources/Icons-Fluent/ic_fluent_arrow_circle_right_24_regular.png",
|
|
|
|
|
UriKind.RelativeOrAbsolute);
|
2024-05-01 18:23:32 +08:00
|
|
|
|
newImageSource.EndInit();
|
2024-06-09 15:14:58 +08:00
|
|
|
|
//BoardLeftPannelNextPage.Source = newImageSource;
|
|
|
|
|
//BoardRightPannelNextPage.Source = newImageSource;
|
|
|
|
|
//BoardRightPannelNextPageTextBlock.Text = "下一页";
|
|
|
|
|
//BoardLeftPannelNextPageTextBlock.Text = "下一页";
|
2024-05-01 18:23:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-05 20:25:26 +08:00
|
|
|
|
BtnWhiteBoardSwitchPrevious.IsEnabled = CurrentWhiteboardIndex != 1;
|
2024-05-01 18:23:32 +08:00
|
|
|
|
|
2024-06-05 20:25:26 +08:00
|
|
|
|
BtnWhiteBoardSwitchNext.IsEnabled = CurrentWhiteboardIndex != WhiteboardTotalCount;
|
2024-05-01 18:23:32 +08:00
|
|
|
|
|
2024-06-05 20:25:26 +08:00
|
|
|
|
BtnWhiteBoardDelete.IsEnabled = WhiteboardTotalCount != 1;
|
2024-05-01 18:23:32 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|