InkCanvasForClass/Ink Canvas/MainWindow.xaml.cs

7571 lines
362 KiB
C#
Raw Normal View History

2023-05-29 12:35:52 +08:00
using Ink_Canvas.Helpers;
2023-04-05 16:05:03 +08:00
using IWshRuntimeLibrary;
using Microsoft.Office.Interop.PowerPoint;
using Microsoft.Win32;
using ModernWpf;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
2023-12-22 00:14:15 +08:00
using System.Windows.Media.Imaging;
using System.Windows.Threading;
2023-04-05 16:05:03 +08:00
using Application = System.Windows.Application;
using File = System.IO.File;
using MessageBox = System.Windows.MessageBox;
using Path = System.IO.Path;
using Point = System.Windows.Point;
using Timer = System.Timers.Timer;
2023-12-22 00:14:15 +08:00
namespace Ink_Canvas {
public partial class MainWindow : Window {
2023-04-05 16:05:03 +08:00
#region Window Initialization
2023-12-22 00:14:15 +08:00
public MainWindow() {
/*
Topmost == false / currentMode != 0
PPT BtnPPTSlideShowEnd.Visibility
*/
2023-04-05 16:05:03 +08:00
InitializeComponent();
2023-12-22 00:14:15 +08:00
BlackboardLeftSide.Visibility = Visibility.Collapsed;
BlackboardCenterSide.Visibility = Visibility.Collapsed;
BlackboardRightSide.Visibility = Visibility.Collapsed;
BorderTools.Visibility = Visibility.Collapsed;
2023-04-05 16:05:03 +08:00
BorderSettings.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
LeftSidePanelForPPTNavigation.Visibility = Visibility.Collapsed;
RightSidePanelForPPTNavigation.Visibility = Visibility.Collapsed;
BorderSettings.Margin = new Thickness(0, 150, 0, 150);
TwoFingerGestureBorder.Visibility = Visibility.Collapsed;
BoardTwoFingerGestureBorder.Visibility = Visibility.Collapsed;
2023-04-05 16:05:03 +08:00
BorderDrawShape.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
BoardBorderDrawShape.Visibility = Visibility.Collapsed;
2023-04-05 16:05:03 +08:00
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
/*if (!App.StartArgs.Contains("-o")) //-old ui
2023-04-05 16:05:03 +08:00
{
2023-12-22 00:14:15 +08:00
GroupBoxAppearance.Visibility = Visibility.Collapsed;*/
ViewBoxStackPanelMain.Visibility = Visibility.Collapsed;
ViewBoxStackPanelShapes.Visibility = Visibility.Collapsed;
ViewboxFloatingBar.Margin = new Thickness((SystemParameters.WorkArea.Width - 284) / 2, SystemParameters.WorkArea.Height - 60, -2000, -200);
ViewboxFloatingBarMarginAnimation(100);
/*}
2023-04-05 16:05:03 +08:00
else
{
GroupBoxAppearanceNewUI.Visibility = Visibility.Collapsed;
ViewboxFloatingBar.Visibility = Visibility.Collapsed;
GridForRecoverOldUI.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
}*/
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
try {
if (File.Exists("debug.ini")) Label.Visibility = Visibility.Visible;
} catch (Exception ex) {
LogHelper.WriteLogToFile(ex.ToString(), LogHelper.LogType.Error);
}
2023-04-05 16:05:03 +08:00
InitTimers();
timeMachine.OnRedoStateChanged += TimeMachine_OnRedoStateChanged;
timeMachine.OnUndoStateChanged += TimeMachine_OnUndoStateChanged;
inkCanvas.Strokes.StrokesChanged += StrokesOnStrokesChanged;
Microsoft.Win32.SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged;
2023-12-22 00:14:15 +08:00
try {
if (File.Exists("SpecialVersion.ini")) SpecialVersionResetToSuggestion_Click();
} catch (Exception ex) {
LogHelper.WriteLogToFile(ex.ToString(), LogHelper.LogType.Error);
}
CheckColorTheme(true);
2023-04-05 16:05:03 +08:00
}
#endregion
#region Timer
Timer timerCheckPPT = new Timer();
Timer timerKillProcess = new Timer();
2023-12-22 00:14:15 +08:00
Timer timerCheckAutoFold = new Timer();
string AvailableLatestVersion = null;
Timer timerCheckAutoUpdateWithSilence = new Timer();
bool isHidingSubPanelsWhenInking = false; // 避免书写时触发二次关闭二级菜单导致动画不连续
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
private void InitTimers() {
2023-04-05 16:05:03 +08:00
timerCheckPPT.Elapsed += TimerCheckPPT_Elapsed;
timerCheckPPT.Interval = 1000;
timerKillProcess.Elapsed += TimerKillProcess_Elapsed;
timerKillProcess.Interval = 5000;
2023-12-22 00:14:15 +08:00
timerCheckAutoFold.Elapsed += timerCheckAutoFold_Elapsed;
timerCheckAutoFold.Interval = 1500;
timerCheckAutoUpdateWithSilence.Elapsed += timerCheckAutoUpdateWithSilence_Elapsed;
timerCheckAutoUpdateWithSilence.Interval = 1000 * 60 * 10;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void TimerKillProcess_Elapsed(object sender, ElapsedEventArgs e) {
try {
2023-09-24 23:15:30 +08:00
// 希沃相关: easinote swenserver RemoteProcess EasiNote.MediaHttpService smartnote.cloud EasiUpdate smartnote EasiUpdate3 EasiUpdate3Protect SeewoP2P CefSharp.BrowserSubprocess SeewoUploadService
2023-04-05 16:05:03 +08:00
string arg = "/F";
2023-12-22 00:14:15 +08:00
if (Settings.Automation.IsAutoKillPptService) {
2023-04-05 16:05:03 +08:00
Process[] processes = Process.GetProcessesByName("PPTService");
2023-12-22 00:14:15 +08:00
if (processes.Length > 0) {
2023-04-05 16:05:03 +08:00
arg += " /IM PPTService.exe";
}
2023-09-22 14:14:22 +08:00
processes = Process.GetProcessesByName("SeewoIwbAssistant");
2023-12-22 00:14:15 +08:00
if (processes.Length > 0) {
arg += " /IM SeewoIwbAssistant.exe" + " /IM Sia.Guard.exe";
2023-09-22 14:14:22 +08:00
}
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
if (Settings.Automation.IsAutoKillEasiNote) {
2023-04-05 16:05:03 +08:00
Process[] processes = Process.GetProcessesByName("EasiNote");
2023-12-22 00:14:15 +08:00
if (processes.Length > 0) {
2023-04-05 16:05:03 +08:00
arg += " /IM EasiNote.exe";
}
}
2023-12-22 00:14:15 +08:00
if (arg != "/F") {
2023-04-05 16:05:03 +08:00
Process p = new Process();
p.StartInfo = new ProcessStartInfo("taskkill", arg);
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.Start();
2023-12-22 00:14:15 +08:00
if (arg.Contains("EasiNote")) {
2023-04-05 16:05:03 +08:00
BtnSwitch_Click(BtnSwitch, null);
MessageBox.Show("“希沃白板 5”已自动关闭");
}
}
2023-12-22 00:14:15 +08:00
} catch { }
}
bool foldFloatingBarByUser = false, // 保持收纳操作不受自动收纳的控制
unfoldFloatingBarByUser = false; // 允许用户在希沃软件内进行展开操作
private void timerCheckAutoFold_Elapsed(object sender, ElapsedEventArgs e) {
if (isFloatingBarChangingHideMode) return;
try {
string windowProcessName = ForegroundWindowInfo.ProcessName();
//string windowTitle = ForegroundWindowInfo.WindowTitle();
//LogHelper.WriteLogToFile("windowTitle | " + windowTitle + " | windowProcessName | " + windowProcessName);
if (Settings.Automation.IsAutoFoldInEasiNote && windowProcessName == "EasiNote" // 希沃白板
|| Settings.Automation.IsAutoFoldInEasiCamera && windowProcessName == "EasiCamera" // 希沃视频展台
|| Settings.Automation.IsAutoFoldInEasiNote3C && windowProcessName == "EasiNote" // 希沃轻白板
|| Settings.Automation.IsAutoFoldInSeewoPincoTeacher && (windowProcessName == "BoardService" || windowProcessName == "seewoPincoTeacher") // 希沃品课
|| Settings.Automation.IsAutoFoldInHiteCamera && windowProcessName == "HiteCamera" // 鸿合视频展台
|| Settings.Automation.IsAutoFoldInHiteTouchPro && windowProcessName == "HiteTouchPro" // 鸿合白板
|| Settings.Automation.IsAutoFoldInWxBoardMain && windowProcessName == "WxBoardMain" // 文香白板
|| Settings.Automation.IsAutoFoldInMSWhiteboard && (windowProcessName == "MicrosoftWhiteboard" || windowProcessName == "msedgewebview2") // 微软白板
|| Settings.Automation.IsAutoFoldInOldZyBoard && // 中原旧白板
(WinTabWindowsChecker.IsWindowExisted("WhiteBoard - DrawingWindow")
|| WinTabWindowsChecker.IsWindowExisted("InstantAnnotationWindow"))) {
if (!unfoldFloatingBarByUser && !isFloatingBarFolded) {
FoldFloatingBar_MouseUp(null, null);
}
} else if (WinTabWindowsChecker.IsWindowExisted("幻灯片放映", false)) { // 处于幻灯片放映状态
if (!Settings.Automation.IsAutoFoldInPPTSlideShow && isFloatingBarFolded && !foldFloatingBarByUser) {
UnFoldFloatingBar_MouseUp(null, null);
}
} else {
if (isFloatingBarFolded && !foldFloatingBarByUser) {
UnFoldFloatingBar_MouseUp(null, null);
}
unfoldFloatingBarByUser = false;
}
} catch { }
}
private void timerCheckAutoUpdateWithSilence_Elapsed(object sender, ElapsedEventArgs e) {
Dispatcher.Invoke(() => {
try {
if ((!Topmost) || (inkCanvas.Strokes.Count > 0)) return;
} catch (Exception ex) {
LogHelper.WriteLogToFile(ex.ToString(), LogHelper.LogType.Error);
}
});
try {
if (AutoUpdateWithSilenceTimeComboBox.CheckIsInSilencePeriod(Settings.Startup.AutoUpdateWithSilenceStartTime, Settings.Startup.AutoUpdateWithSilenceEndTime)) {
AutoUpdateHelper.InstallNewVersionApp(AvailableLatestVersion, true);
timerCheckAutoUpdateWithSilence.Stop();
}
} catch (Exception ex) {
LogHelper.WriteLogToFile(ex.ToString(), LogHelper.LogType.Error);
2023-04-05 16:05:03 +08:00
}
}
#endregion Timer
#region Ink Canvas Functions
Color Ink_DefaultColor = Colors.Red;
DrawingAttributes drawingAttributes;
2023-12-22 00:14:15 +08:00
private void loadPenCanvas() {
try {
2023-04-05 16:05:03 +08:00
//drawingAttributes = new DrawingAttributes();
drawingAttributes = inkCanvas.DefaultDrawingAttributes;
drawingAttributes.Color = Ink_DefaultColor;
drawingAttributes.Height = 2.5;
drawingAttributes.Width = 2.5;
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
inkCanvas.Gesture += InkCanvas_Gesture;
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
}
//ApplicationGesture lastApplicationGesture = ApplicationGesture.AllGestures;
DateTime lastGestureTime = DateTime.Now;
2023-12-22 00:14:15 +08:00
private void InkCanvas_Gesture(object sender, InkCanvasGestureEventArgs e) {
2023-04-05 16:05:03 +08:00
ReadOnlyCollection<GestureRecognitionResult> gestures = e.GetGestureRecognitionResults();
2023-12-22 00:14:15 +08:00
try {
foreach (GestureRecognitionResult gest in gestures) {
2023-04-05 16:05:03 +08:00
//Trace.WriteLine(string.Format("Gesture: {0}, Confidence: {1}", gest.ApplicationGesture, gest.RecognitionConfidence));
2023-12-22 00:14:15 +08:00
if (StackPanelPPTControls.Visibility == Visibility.Visible) {
if (gest.ApplicationGesture == ApplicationGesture.Left) {
2023-04-05 16:05:03 +08:00
BtnPPTSlidesDown_Click(BtnPPTSlidesDown, null);
}
2023-12-22 00:14:15 +08:00
if (gest.ApplicationGesture == ApplicationGesture.Right) {
2023-04-05 16:05:03 +08:00
BtnPPTSlidesUp_Click(BtnPPTSlidesUp, null);
}
}
}
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void inkCanvas_EditingModeChanged(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
var inkCanvas1 = sender as InkCanvas;
if (inkCanvas1 == null) return;
2023-12-22 00:14:15 +08:00
if (Settings.Canvas.IsShowCursor) {
if (inkCanvas1.EditingMode == InkCanvasEditingMode.Ink || drawingShapeMode != 0) {
2023-04-05 16:05:03 +08:00
inkCanvas1.ForceCursor = true;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
inkCanvas1.ForceCursor = false;
}
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
inkCanvas1.ForceCursor = false;
}
if (inkCanvas1.EditingMode == InkCanvasEditingMode.Ink) forcePointEraser = !forcePointEraser;
2023-05-27 22:08:46 +08:00
2023-12-22 00:14:15 +08:00
if (inkCanvas.EditingMode == InkCanvasEditingMode.Select) {
//SymbolIconSelect.Foreground = new SolidColorBrush(Color.FromRgb(0, 136, 255));
} else {
//SymbolIconSelect.Foreground = new SolidColorBrush(toolBarForegroundColor);
2023-05-27 22:08:46 +08:00
}
2023-04-05 16:05:03 +08:00
}
#endregion Ink Canvas
#region Hotkeys
2023-12-22 00:14:15 +08:00
private void Window_MouseWheel(object sender, MouseWheelEventArgs e) {
2023-04-05 16:05:03 +08:00
if (StackPanelPPTControls.Visibility != Visibility.Visible || currentMode != 0) return;
2023-12-22 00:14:15 +08:00
if (e.Delta >= 120) {
2023-04-05 16:05:03 +08:00
BtnPPTSlidesUp_Click(BtnPPTSlidesUp, null);
2023-12-22 00:14:15 +08:00
} else if (e.Delta <= -120) {
2023-04-05 16:05:03 +08:00
BtnPPTSlidesDown_Click(BtnPPTSlidesDown, null);
}
}
2023-12-22 00:14:15 +08:00
private void Main_Grid_PreviewKeyDown(object sender, KeyEventArgs e) {
2023-04-05 16:05:03 +08:00
if (StackPanelPPTControls.Visibility != Visibility.Visible || currentMode != 0) return;
2023-12-22 00:14:15 +08:00
if (e.Key == Key.Down || e.Key == Key.PageDown || e.Key == Key.Right || e.Key == Key.N || e.Key == Key.Space) {
2023-04-05 16:05:03 +08:00
BtnPPTSlidesDown_Click(BtnPPTSlidesDown, null);
}
2023-12-22 00:14:15 +08:00
if (e.Key == Key.Up || e.Key == Key.PageUp || e.Key == Key.Left || e.Key == Key.P) {
2023-04-05 16:05:03 +08:00
BtnPPTSlidesUp_Click(BtnPPTSlidesUp, null);
}
}
2023-12-22 00:14:15 +08:00
private void Window_KeyDown(object sender, KeyEventArgs e) {
if (e.Key == Key.Escape) {
2023-04-05 16:05:03 +08:00
KeyExit(null, null);
}
}
2023-12-22 00:14:15 +08:00
private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
e.CanExecute = true;
}
2023-12-22 00:14:15 +08:00
private void HotKey_Undo(object sender, ExecutedRoutedEventArgs e) {
try {
SymbolIconUndo_MouseUp(lastBorderMouseDownObject, null);
} catch { }
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void HotKey_Redo(object sender, ExecutedRoutedEventArgs e) {
try {
SymbolIconRedo_MouseUp(lastBorderMouseDownObject, null);
} catch { }
}
private void HotKey_Clear(object sender, ExecutedRoutedEventArgs e) {
SymbolIconDelete_MouseUp(lastBorderMouseDownObject, null);
}
private void KeyExit(object sender, ExecutedRoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
BtnPPTSlideShowEnd_Click(BtnPPTSlideShowEnd, null);
}
2023-12-22 00:14:15 +08:00
private void KeyChangeToDrawTool(object sender, ExecutedRoutedEventArgs e) {
PenIcon_Click(lastBorderMouseDownObject, null);
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void KeyChangeToQuitDrawTool(object sender, ExecutedRoutedEventArgs e) {
if (currentMode != 0) {
ImageBlackboard_MouseUp(lastBorderMouseDownObject, null);
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
CursorIcon_Click(lastBorderMouseDownObject, null);
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void KeyChangeToSelect(object sender, ExecutedRoutedEventArgs e) {
if (StackPanelCanvasControls.Visibility == Visibility.Visible) {
SymbolIconSelect_MouseUp(lastBorderMouseDownObject, null);
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
}
private void KeyChangeToEraser(object sender, ExecutedRoutedEventArgs e) {
if (StackPanelCanvasControls.Visibility == Visibility.Visible) {
if (Eraser_Icon.Background != null) {
EraserIconByStrokes_Click(lastBorderMouseDownObject, null);
} else {
EraserIcon_Click(lastBorderMouseDownObject, null);
}
2023-04-05 16:05:03 +08:00
}
}
2023-12-22 00:14:15 +08:00
private void KeyChangeToBoard(object sender, ExecutedRoutedEventArgs e) {
ImageBlackboard_MouseUp(lastBorderMouseDownObject, null);
}
private void KeyCapture(object sender, ExecutedRoutedEventArgs e) {
BtnScreenshot_Click(sender, e);
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void KeyDrawLine(object sender, ExecutedRoutedEventArgs e) {
if (StackPanelCanvasControls.Visibility == Visibility.Visible) {
BtnDrawLine_Click(lastMouseDownSender, e);
}
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void KeyHide(object sender, ExecutedRoutedEventArgs e) {
SymbolIconEmoji_MouseUp(null, null);
2023-04-05 16:05:03 +08:00
}
2023-04-05 16:05:03 +08:00
#endregion Hotkeys
#region TimeMachine
2023-12-22 00:14:15 +08:00
private enum CommitReason {
2023-05-07 17:54:41 +08:00
UserInput,
CodeInput,
ShapeDrawing,
ShapeRecognition,
ClearingCanvas,
Rotate
}
2023-05-08 19:58:14 +08:00
2023-05-07 17:54:41 +08:00
private CommitReason _currentCommitType = CommitReason.UserInput;
private bool IsEraseByPoint => inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint;
private StrokeCollection ReplacedStroke;
private StrokeCollection AddedStroke;
private StrokeCollection CuboidStrokeCollection;
private TimeMachine timeMachine = new TimeMachine();
2023-05-08 19:58:14 +08:00
2023-12-22 00:14:15 +08:00
private void TimeMachine_OnUndoStateChanged(bool status) {
var result = status ? Visibility.Visible : Visibility.Collapsed;
BtnUndo.Visibility = result;
BtnUndo.IsEnabled = status;
}
2023-12-22 00:14:15 +08:00
private void TimeMachine_OnRedoStateChanged(bool status) {
var result = status ? Visibility.Visible : Visibility.Collapsed;
BtnRedo.Visibility = result;
BtnRedo.IsEnabled = status;
}
2023-05-08 19:58:14 +08:00
2023-12-22 00:14:15 +08:00
private void StrokesOnStrokesChanged(object sender, StrokeCollectionChangedEventArgs e) {
if (!isHidingSubPanelsWhenInking) {
isHidingSubPanelsWhenInking = true;
HideSubPanels(); // 书写时自动隐藏二级菜单
}
2023-05-07 17:54:41 +08:00
if (_currentCommitType == CommitReason.CodeInput || _currentCommitType == CommitReason.ShapeDrawing) return;
2023-12-22 00:14:15 +08:00
if (_currentCommitType == CommitReason.Rotate) {
2023-05-07 17:54:41 +08:00
timeMachine.CommitStrokeRotateHistory(e.Removed, e.Added);
return;
}
2023-12-22 00:14:15 +08:00
if ((e.Added.Count != 0 || e.Removed.Count != 0) && IsEraseByPoint) {
if (AddedStroke == null) AddedStroke = new StrokeCollection();
if (ReplacedStroke == null) ReplacedStroke = new StrokeCollection();
AddedStroke.Add(e.Added);
ReplacedStroke.Add(e.Removed);
return;
}
2023-12-22 00:14:15 +08:00
if (e.Added.Count != 0) {
if (_currentCommitType == CommitReason.ShapeRecognition) {
timeMachine.CommitStrokeShapeHistory(ReplacedStroke, e.Added);
ReplacedStroke = null;
return;
2023-12-22 00:14:15 +08:00
} else {
timeMachine.CommitStrokeUserInputHistory(e.Added);
return;
}
}
2023-12-22 00:14:15 +08:00
if (e.Removed.Count != 0) {
if (_currentCommitType == CommitReason.ShapeRecognition) {
ReplacedStroke = e.Removed;
return;
2023-12-22 00:14:15 +08:00
} else if (!IsEraseByPoint || _currentCommitType == CommitReason.ClearingCanvas) {
timeMachine.CommitStrokeEraseHistory(e.Removed);
return;
}
}
}
#endregion
2023-04-05 16:05:03 +08:00
#region Definations and Loading
public static Settings Settings = new Settings();
public static string settingsFileName = "Settings.json";
bool isLoaded = false;
2023-12-22 00:14:15 +08:00
private void Window_Loaded(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
loadPenCanvas();
//加载设置
LoadSettings();
2023-12-22 00:14:15 +08:00
if (Environment.Is64BitProcess) {
GroupBoxInkRecognition.Visibility = Visibility.Collapsed;
}
2023-04-05 16:05:03 +08:00
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Light;
2023-05-29 12:35:52 +08:00
SystemEvents_UserPreferenceChanged(null, null);
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
//TextBlockVersion.Text = Assembly.GetExecutingAssembly().GetName().Version.ToString();
2023-04-05 16:05:03 +08:00
LogHelper.WriteLogToFile("Ink Canvas Loaded", LogHelper.LogType.Event);
isLoaded = true;
}
2023-12-22 00:14:15 +08:00
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
2023-04-05 16:05:03 +08:00
LogHelper.WriteLogToFile("Ink Canvas closing", LogHelper.LogType.Event);
2023-12-22 00:14:15 +08:00
if (!CloseIsFromButton && Settings.Advanced.IsSecondConfimeWhenShutdownApp) {
2023-04-05 16:05:03 +08:00
e.Cancel = true;
2023-12-22 00:14:15 +08:00
if (MessageBox.Show("是否继续关闭 Ink Canvas 画板,这将丢失当前未保存的工作。", "Ink Canvas 画板", MessageBoxButton.OKCancel, MessageBoxImage.Warning) == MessageBoxResult.OK) {
if (MessageBox.Show("真的狠心关闭 Ink Canvas 画板吗?", "Ink Canvas 画板", MessageBoxButton.OKCancel, MessageBoxImage.Error) == MessageBoxResult.OK) {
if (MessageBox.Show("是否取消关闭 Ink Canvas 画板?", "Ink Canvas 画板", MessageBoxButton.OKCancel, MessageBoxImage.Error) != MessageBoxResult.OK) {
2023-04-05 16:05:03 +08:00
e.Cancel = false;
}
}
}
}
2023-12-22 00:14:15 +08:00
if (e.Cancel) {
2023-04-05 16:05:03 +08:00
LogHelper.WriteLogToFile("Ink Canvas closing cancelled", LogHelper.LogType.Event);
}
}
2023-12-22 00:14:15 +08:00
private void Window_Closed(object sender, EventArgs e) {
2023-04-05 16:05:03 +08:00
LogHelper.WriteLogToFile("Ink Canvas closed", LogHelper.LogType.Event);
}
2023-12-22 00:14:15 +08:00
private async void AutoUpdate() {
if (Settings.Startup.IsAutoUpdateWithProxy) AvailableLatestVersion = await AutoUpdateHelper.CheckForUpdates(Settings.Startup.AutoUpdateProxy);
else AvailableLatestVersion = await AutoUpdateHelper.CheckForUpdates();
if (AvailableLatestVersion != null) {
bool IsDownloadSuccessful = false;
if (Settings.Startup.IsAutoUpdateWithProxy) IsDownloadSuccessful = await AutoUpdateHelper.DownloadSetupFileAndSaveStatus(AvailableLatestVersion, Settings.Startup.AutoUpdateProxy);
else IsDownloadSuccessful = await AutoUpdateHelper.DownloadSetupFileAndSaveStatus(AvailableLatestVersion);
if (IsDownloadSuccessful) {
if (!Settings.Startup.IsAutoUpdateWithSilence) {
if (MessageBox.Show("ICA 新版本安装包已下载完成,是否立即更新?", "Ink Canvas Annotation New Version Available", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) {
AutoUpdateHelper.InstallNewVersionApp(AvailableLatestVersion, false);
}
} else {
timerCheckAutoUpdateWithSilence.Start();
}
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
} else {
AutoUpdateHelper.DeleteUpdatesFolder();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
}
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
private void LoadSettings(bool isStartup = true) {
AppVersionTextBlock.Text = Assembly.GetExecutingAssembly().GetName().Version.ToString();
try {
if (File.Exists(App.RootPath + settingsFileName)) {
try {
string text = File.ReadAllText(App.RootPath + settingsFileName);
Settings = JsonConvert.DeserializeObject<Settings>(text);
} catch { }
} else {
BtnResetToSuggestion_Click(null, null);
}
} catch (Exception ex) {
LogHelper.WriteLogToFile(ex.ToString(), LogHelper.LogType.Error);
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
if (isStartup) {
CursorIcon_Click(null, null);
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
/*
BtnHideInkCanvas_Click(BtnHideInkCanvas, null);/*
2023-04-05 16:05:03 +08:00
if (Settings.Startup.IsAutoHideCanvas)
{
if (isStartup)
{
BtnHideInkCanvas_Click(BtnHideInkCanvas, null);
}
ToggleSwitchAutoHideCanvas.IsOn = true;
}
else
{
if (isStartup)
{
BtnHideInkCanvas_Click(BtnHideInkCanvas, null);
BtnHideInkCanvas_Click(BtnHideInkCanvas, null);
}
ToggleSwitchAutoHideCanvas.IsOn = false;
}
if (Settings.Appearance.IsShowEraserButton)
{
BtnErase.Visibility = Visibility.Visible;
ToggleSwitchShowButtonEraser.IsOn = true;
}
else
{
BtnErase.Visibility = Visibility.Collapsed;
ToggleSwitchShowButtonEraser.IsOn = false;
}
if (Settings.Appearance.IsShowExitButton)
{
BtnExit.Visibility = Visibility.Visible;
ToggleSwitchShowButtonExit.IsOn = true;
}
else
{
BtnExit.Visibility = Visibility.Collapsed;
ToggleSwitchShowButtonExit.IsOn = false;
}
2023-12-22 00:14:15 +08:00
*/
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
if (Settings.Startup.IsEnableNibMode) {
ToggleSwitchEnableNibMode.IsOn = true;
ToggleSwitchBoardEnableNibMode.IsOn = true;
BoundsWidth = Settings.Advanced.NibModeBoundsWidth;
} else {
ToggleSwitchEnableNibMode.IsOn = false;
ToggleSwitchBoardEnableNibMode.IsOn = false;
BoundsWidth = Settings.Advanced.FingerModeBoundsWidth;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
if (!Settings.Appearance.IsEnableDisPlayNibModeToggler) {
NibModeSimpleStackPanel.Visibility = Visibility.Collapsed;
BoardNibModeSimpleStackPanel.Visibility = Visibility.Collapsed;
} else {
NibModeSimpleStackPanel.Visibility = Visibility.Visible;
BoardNibModeSimpleStackPanel.Visibility = Visibility.Visible;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
if (Settings.Appearance.IsColorfulViewboxFloatingBar) // 浮动工具栏背景色
2023-04-05 16:05:03 +08:00
{
2023-12-22 00:14:15 +08:00
LinearGradientBrush gradientBrush = new LinearGradientBrush();
gradientBrush.StartPoint = new Point(0, 0);
gradientBrush.EndPoint = new Point(1, 1);
GradientStop blueStop = new GradientStop(Color.FromArgb(0x95, 0x80, 0xB0, 0xFF), 0);
GradientStop greenStop = new GradientStop(Color.FromArgb(0x95, 0xC0, 0xFF, 0xC0), 1);
gradientBrush.GradientStops.Add(blueStop);
gradientBrush.GradientStops.Add(greenStop);
EnableTwoFingerGestureBorder.Background = gradientBrush;
BorderFloatingBarMainControls.Background = gradientBrush;
BorderFloatingBarMoveControls.Background = gradientBrush;
BorderFloatingBarExitPPTBtn.Background = gradientBrush;
ToggleSwitchColorfulViewboxFloatingBar.IsOn = true;
} else {
EnableTwoFingerGestureBorder.Background = (Brush)FindResource("ToolBarBackground");
BorderFloatingBarMainControls.Background = (Brush)FindResource("ToolBarBackground");
BorderFloatingBarMoveControls.Background = (Brush)FindResource("ToolBarBackground");
BorderFloatingBarExitPPTBtn.Background = (Brush)FindResource("ToolBarBackground");
ToggleSwitchColorfulViewboxFloatingBar.IsOn = false;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
if (Settings.Appearance.EnableViewboxFloatingBarScaleTransform) // 浮动工具栏 UI 缩放 85%
2023-04-05 16:05:03 +08:00
{
2023-12-22 00:14:15 +08:00
ViewboxFloatingBarScaleTransform.ScaleX = 0.85;
ViewboxFloatingBarScaleTransform.ScaleY = 0.85;
ToggleSwitchEnableViewboxFloatingBarScaleTransform.IsOn = true;
} else {
ViewboxFloatingBarScaleTransform.ScaleX = 1;
ViewboxFloatingBarScaleTransform.ScaleY = 1;
ToggleSwitchEnableViewboxFloatingBarScaleTransform.IsOn = false;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
if (Settings.Appearance.EnableViewboxBlackBoardScaleTransform) // 画板 UI 缩放 80%
2023-04-05 16:05:03 +08:00
{
2023-12-22 00:14:15 +08:00
ViewboxBlackboardLeftSideScaleTransform.ScaleX = 0.8;
ViewboxBlackboardLeftSideScaleTransform.ScaleY = 0.8;
ViewboxBlackboardCenterSideScaleTransform.ScaleX = 0.8;
ViewboxBlackboardCenterSideScaleTransform.ScaleY = 0.8;
ViewboxBlackboardRightSideScaleTransform.ScaleX = 0.8;
ViewboxBlackboardRightSideScaleTransform.ScaleY = 0.8;
ToggleSwitchEnableViewboxBlackBoardScaleTransform.IsOn = true;
} else {
ViewboxBlackboardLeftSideScaleTransform.ScaleX = 1;
ViewboxBlackboardLeftSideScaleTransform.ScaleY = 1;
ViewboxBlackboardCenterSideScaleTransform.ScaleX = 1;
ViewboxBlackboardCenterSideScaleTransform.ScaleY = 1;
ViewboxBlackboardRightSideScaleTransform.ScaleX = 1;
ViewboxBlackboardRightSideScaleTransform.ScaleY = 1;
ToggleSwitchEnableViewboxBlackBoardScaleTransform.IsOn = false;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
PptNavigationBtn.Visibility =
Settings.PowerPointSettings.IsShowPPTNavigation ? Visibility.Visible : Visibility.Collapsed;
ToggleSwitchShowButtonPPTNavigation.IsOn = Settings.PowerPointSettings.IsShowPPTNavigation;
ToggleSwitchShowBottomPPTNavigationPanel.IsOn = Settings.PowerPointSettings.IsShowBottomPPTNavigationPanel;
ToggleSwitchShowSidePPTNavigationPanel.IsOn = Settings.PowerPointSettings.IsShowSidePPTNavigationPanel;
if (Settings.Appearance.IsTransparentButtonBackground) {
2023-04-05 16:05:03 +08:00
BtnExit.Background = new SolidColorBrush(StringToColor("#7F909090"));
2023-12-22 00:14:15 +08:00
} else {
if (BtnSwitchTheme.Content.ToString() == "深色") {
2023-04-05 16:05:03 +08:00
//Light
BtnExit.Background = new SolidColorBrush(StringToColor("#FFCCCCCC"));
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
//Dark
BtnExit.Background = new SolidColorBrush(StringToColor("#FF555555"));
}
}
2023-12-22 00:14:15 +08:00
if (Settings.PowerPointSettings.PowerPointSupport) {
2023-04-05 16:05:03 +08:00
ToggleSwitchSupportPowerPoint.IsOn = true;
timerCheckPPT.Start();
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
ToggleSwitchSupportPowerPoint.IsOn = false;
timerCheckPPT.Stop();
}
2023-12-22 00:14:15 +08:00
if (Settings.PowerPointSettings.IsShowCanvasAtNewSlideShow) {
2023-04-05 16:05:03 +08:00
ToggleSwitchShowCanvasAtNewSlideShow.IsOn = true;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
ToggleSwitchShowCanvasAtNewSlideShow.IsOn = false;
}
2023-12-22 00:14:15 +08:00
if (Settings.Gesture == null) {
2023-04-05 16:05:03 +08:00
Settings.Gesture = new Gesture();
}
2023-12-22 00:14:15 +08:00
if (Settings.Gesture.IsEnableTwoFingerZoom) {
2023-04-05 16:05:03 +08:00
ToggleSwitchEnableTwoFingerZoom.IsOn = true;
2023-12-22 00:14:15 +08:00
BoardToggleSwitchEnableTwoFingerZoom.IsOn = true;
} else {
2023-04-05 16:05:03 +08:00
ToggleSwitchEnableTwoFingerZoom.IsOn = false;
2023-12-22 00:14:15 +08:00
BoardToggleSwitchEnableTwoFingerZoom.IsOn = false;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
if (Settings.Gesture.IsEnableTwoFingerTranslate) {
ToggleSwitchEnableTwoFingerTranslate.IsOn = true;
2023-12-22 00:14:15 +08:00
BoardToggleSwitchEnableTwoFingerTranslate.IsOn = true;
} else {
ToggleSwitchEnableTwoFingerTranslate.IsOn = false;
2023-12-22 00:14:15 +08:00
BoardToggleSwitchEnableTwoFingerTranslate.IsOn = false;
}
2023-12-22 00:14:15 +08:00
if (Settings.Gesture.IsEnableTwoFingerRotation) {
2023-04-05 16:05:03 +08:00
ToggleSwitchEnableTwoFingerRotation.IsOn = true;
2023-12-22 00:14:15 +08:00
BoardToggleSwitchEnableTwoFingerRotation.IsOn = true;
} else {
ToggleSwitchEnableTwoFingerRotation.IsOn = false;
BoardToggleSwitchEnableTwoFingerRotation.IsOn = false;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
if (Settings.Gesture.AutoSwitchTwoFingerGesture) {
ToggleSwitchAutoSwitchTwoFingerGesture.IsOn = true;
} else {
ToggleSwitchAutoSwitchTwoFingerGesture.IsOn = false;
}
if (Settings.Gesture.IsEnableTwoFingerRotation) {
ToggleSwitchEnableTwoFingerRotation.IsOn = true;
} else {
2023-04-05 16:05:03 +08:00
ToggleSwitchEnableTwoFingerRotation.IsOn = false;
}
2023-12-22 00:14:15 +08:00
if (Settings.Gesture.IsEnableTwoFingerRotationOnSelection) {
2023-04-05 16:05:03 +08:00
ToggleSwitchEnableTwoFingerRotationOnSelection.IsOn = true;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
ToggleSwitchEnableTwoFingerRotationOnSelection.IsOn = false;
}
2023-12-22 00:14:15 +08:00
if (Settings.Gesture.AutoSwitchTwoFingerGesture) {
if (Topmost) {
ToggleSwitchEnableTwoFingerTranslate.IsOn = false;
BoardToggleSwitchEnableTwoFingerTranslate.IsOn = false;
Settings.Gesture.IsEnableTwoFingerTranslate = false;
} else {
ToggleSwitchEnableTwoFingerTranslate.IsOn = true;
BoardToggleSwitchEnableTwoFingerTranslate.IsOn = true;
Settings.Gesture.IsEnableTwoFingerTranslate = true;
}
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
CheckEnableTwoFingerGestureBtnColorPrompt();
if (Settings.PowerPointSettings.IsEnableTwoFingerGestureInPresentationMode) {
ToggleSwitchEnableTwoFingerGestureInPresentationMode.IsOn = true;
} else {
2023-04-05 16:05:03 +08:00
ToggleSwitchEnableTwoFingerGestureInPresentationMode.IsOn = false;
}
2023-12-22 00:14:15 +08:00
if (Settings.PowerPointSettings.IsEnableFingerGestureSlideShowControl) {
2023-04-05 16:05:03 +08:00
ToggleSwitchEnableFingerGestureSlideShowControl.IsOn = true;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
ToggleSwitchEnableFingerGestureSlideShowControl.IsOn = false;
}
2023-12-22 00:14:15 +08:00
if (Settings.Startup.IsAutoUpdate) {
ToggleSwitchIsAutoUpdate.IsOn = true;
AutoUpdate();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
ToggleSwitchIsAutoUpdateWithProxy.IsOn = Settings.Startup.IsAutoUpdateWithProxy;
AutoUpdateWithProxy_Title.Visibility = Settings.Startup.IsAutoUpdateWithProxy ? Visibility.Visible : Visibility.Collapsed;
AutoUpdateProxyTextBox.Text = Settings.Startup.AutoUpdateProxy;
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
ToggleSwitchIsAutoUpdateWithSilence.Visibility = Settings.Startup.IsAutoUpdate ? Visibility.Visible : Visibility.Collapsed;
if (Settings.Startup.IsAutoUpdateWithSilence) {
ToggleSwitchIsAutoUpdateWithSilence.IsOn = true;
}
AutoUpdateTimePeriodBlock.Visibility = Settings.Startup.IsAutoUpdateWithSilence ? Visibility.Visible : Visibility.Collapsed;
AutoUpdateWithSilenceTimeComboBox.InitializeAutoUpdateWithSilenceTimeComboBoxOptions(AutoUpdateWithSilenceStartTimeComboBox, AutoUpdateWithSilenceEndTimeComboBox);
AutoUpdateWithSilenceStartTimeComboBox.SelectedItem = Settings.Startup.AutoUpdateWithSilenceStartTime;
AutoUpdateWithSilenceEndTimeComboBox.SelectedItem = Settings.Startup.AutoUpdateWithSilenceEndTime;
try {
if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\Ink Canvas Annotation.lnk")) {
ToggleSwitchRunAtStartup.IsOn = true;
}
} catch (Exception ex) {
LogHelper.WriteLogToFile(ex.ToString(), LogHelper.LogType.Error);
}
if (Settings.Canvas != null) {
2023-04-05 16:05:03 +08:00
drawingAttributes.Height = Settings.Canvas.InkWidth;
drawingAttributes.Width = Settings.Canvas.InkWidth;
InkWidthSlider.Value = Settings.Canvas.InkWidth * 2;
2023-12-22 00:14:15 +08:00
ComboBoxHyperbolaAsymptoteOption.SelectedIndex = (int)Settings.Canvas.HyperbolaAsymptoteOption;
if (Settings.Canvas.UsingWhiteboard) {
GridBackgroundCover.Background = new SolidColorBrush(StringToColor("#FFF2F2F2"));
} else {
GridBackgroundCover.Background = new SolidColorBrush(StringToColor("#FF1F1F1F"));
}
if (Settings.Canvas.IsShowCursor) {
2023-04-05 16:05:03 +08:00
ToggleSwitchShowCursor.IsOn = true;
inkCanvas.ForceCursor = true;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
ToggleSwitchShowCursor.IsOn = false;
inkCanvas.ForceCursor = false;
}
ComboBoxPenStyle.SelectedIndex = Settings.Canvas.InkStyle;
2023-12-22 00:14:15 +08:00
BoardComboBoxPenStyle.SelectedIndex = Settings.Canvas.InkStyle;
2023-04-05 16:05:03 +08:00
ComboBoxEraserSize.SelectedIndex = Settings.Canvas.EraserSize;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
Settings.Canvas = new Canvas();
}
2023-12-22 00:14:15 +08:00
if (Settings.Automation != null) {
StartOrStoptimerCheckAutoFold();
if (Settings.Automation.IsAutoFoldInEasiNote) {
ToggleSwitchAutoFoldInEasiNote.IsOn = true;
} else {
ToggleSwitchAutoFoldInEasiNote.IsOn = false;
}
if (Settings.Automation.IsAutoFoldInEasiCamera) {
ToggleSwitchAutoFoldInEasiCamera.IsOn = true;
} else {
ToggleSwitchAutoFoldInEasiCamera.IsOn = false;
}
if (Settings.Automation.IsAutoFoldInEasiNote3C) {
ToggleSwitchAutoFoldInEasiNote3C.IsOn = true;
} else {
ToggleSwitchAutoFoldInEasiNote3C.IsOn = false;
}
if (Settings.Automation.IsAutoFoldInSeewoPincoTeacher) {
ToggleSwitchAutoFoldInSeewoPincoTeacher.IsOn = true;
} else {
ToggleSwitchAutoFoldInSeewoPincoTeacher.IsOn = false;
}
if (Settings.Automation.IsAutoFoldInHiteTouchPro) {
ToggleSwitchAutoFoldInHiteTouchPro.IsOn = true;
} else {
ToggleSwitchAutoFoldInHiteTouchPro.IsOn = false;
}
if (Settings.Automation.IsAutoFoldInHiteCamera) {
ToggleSwitchAutoFoldInHiteCamera.IsOn = true;
} else {
ToggleSwitchAutoFoldInHiteCamera.IsOn = false;
}
if (Settings.Automation.IsAutoFoldInWxBoardMain) {
ToggleSwitchAutoFoldInWxBoardMain.IsOn = true;
} else {
ToggleSwitchAutoFoldInWxBoardMain.IsOn = false;
}
/*
if (Settings.Automation.IsAutoFoldInZySmartBoard) {
ToggleSwitchAutoFoldInZySmartBoard.IsOn = true;
} else {
ToggleSwitchAutoFoldInZySmartBoard.IsOn = false;
}
*/
if (Settings.Automation.IsAutoFoldInOldZyBoard) {
ToggleSwitchAutoFoldInOldZyBoard.IsOn = true;
} else {
ToggleSwitchAutoFoldInOldZyBoard.IsOn = false;
}
if (Settings.Automation.IsAutoFoldInMSWhiteboard) {
ToggleSwitchAutoFoldInMSWhiteboard.IsOn = true;
} else {
ToggleSwitchAutoFoldInMSWhiteboard.IsOn = false;
}
if (Settings.Automation.IsAutoFoldInPPTSlideShow) {
ToggleSwitchAutoFoldInPPTSlideShow.IsOn = true;
} else {
ToggleSwitchAutoFoldInPPTSlideShow.IsOn = false;
}
if (Settings.Automation.IsAutoKillEasiNote || Settings.Automation.IsAutoKillPptService) {
2023-04-05 16:05:03 +08:00
timerKillProcess.Start();
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
timerKillProcess.Stop();
}
2023-12-22 00:14:15 +08:00
if (Settings.Automation.IsAutoKillEasiNote) {
2023-04-05 16:05:03 +08:00
ToggleSwitchAutoKillEasiNote.IsOn = true;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
ToggleSwitchAutoKillEasiNote.IsOn = false;
}
2023-12-22 00:14:15 +08:00
if (Settings.Automation.IsAutoKillPptService) {
ToggleSwitchAutoKillPptService.IsOn = true;
} else {
ToggleSwitchAutoKillPptService.IsOn = false;
}
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
/*
2023-04-05 16:05:03 +08:00
if (Settings.Automation.IsAutoClearWhenExitingWritingMode)
{
ToggleSwitchClearExitingWritingMode.IsOn = true;
}
else
{
ToggleSwitchClearExitingWritingMode.IsOn = false;
}
2023-12-22 00:14:15 +08:00
*/
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
if (Settings.Automation.IsAutoSaveStrokesAtClear) {
2023-04-05 16:05:03 +08:00
ToggleSwitchAutoSaveStrokesAtClear.IsOn = true;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
ToggleSwitchAutoSaveStrokesAtClear.IsOn = false;
}
2023-12-22 00:14:15 +08:00
if (Settings.Automation.IsSaveScreenshotsInDateFolders) {
ToggleSwitchSaveScreenshotsInDateFolders.IsOn = true;
2023-12-22 00:14:15 +08:00
} else {
ToggleSwitchSaveScreenshotsInDateFolders.IsOn = false;
}
2023-12-22 00:14:15 +08:00
if (Settings.Automation.IsAutoSaveStrokesAtScreenshot) {
2023-04-05 16:05:03 +08:00
ToggleSwitchAutoSaveStrokesAtScreenshot.IsOn = true;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
ToggleSwitchAutoSaveStrokesAtScreenshot.IsOn = false;
}
2023-12-22 00:14:15 +08:00
if (Settings.PowerPointSettings.IsAutoSaveStrokesInPowerPoint) {
2023-04-05 16:05:03 +08:00
ToggleSwitchAutoSaveStrokesInPowerPoint.IsOn = true;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
ToggleSwitchAutoSaveStrokesInPowerPoint.IsOn = false;
}
2023-05-08 19:58:14 +08:00
2023-12-22 00:14:15 +08:00
if (Settings.PowerPointSettings.IsNotifyPreviousPage) {
ToggleSwitchNotifyPreviousPage.IsOn = true;
2023-12-22 00:14:15 +08:00
} else {
ToggleSwitchNotifyPreviousPage.IsOn = false;
}
2023-05-08 19:58:14 +08:00
2023-12-22 00:14:15 +08:00
if (Settings.PowerPointSettings.IsNotifyHiddenPage) {
ToggleSwitchNotifyHiddenPage.IsOn = true;
2023-12-22 00:14:15 +08:00
} else {
ToggleSwitchNotifyHiddenPage.IsOn = false;
}
2023-12-22 00:14:15 +08:00
/*
if (Settings.PowerPointSettings.IsNoClearStrokeOnSelectWhenInPowerPoint)
{
ToggleSwitchNoStrokeClearInPowerPoint.IsOn = true;
}
else
{
ToggleSwitchNoStrokeClearInPowerPoint.IsOn = false;
}
2023-05-08 19:58:14 +08:00
if (Settings.PowerPointSettings.IsShowStrokeOnSelectInPowerPoint)
{
ToggleSwitchShowStrokeOnSelectInPowerPoint.IsOn = true;
}
else
{
ToggleSwitchShowStrokeOnSelectInPowerPoint.IsOn = false;
}
2023-12-22 00:14:15 +08:00
*/
if (Settings.PowerPointSettings.IsSupportWPS) {
2023-06-05 19:42:23 +08:00
ToggleSwitchSupportWPS.IsOn = true;
2023-12-22 00:14:15 +08:00
} else {
2023-06-05 19:42:23 +08:00
ToggleSwitchSupportWPS.IsOn = false;
}
SideControlMinimumAutomationSlider.Value = Settings.Automation.MinimumAutomationStrokeNumber;
2023-12-22 00:14:15 +08:00
if (Settings.Canvas.HideStrokeWhenSelecting) {
2023-04-05 16:05:03 +08:00
ToggleSwitchHideStrokeWhenSelecting.IsOn = true;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
ToggleSwitchHideStrokeWhenSelecting.IsOn = false;
}
2023-12-22 00:14:15 +08:00
/*
2023-04-05 16:05:03 +08:00
if (Settings.Canvas.UsingWhiteboard)
{
ToggleSwitchUsingWhiteboard.IsOn = true;
}
else
{
ToggleSwitchUsingWhiteboard.IsOn = false;
}
2023-12-22 00:14:15 +08:00
*/
2023-07-15 15:28:10 +08:00
2023-12-22 00:14:15 +08:00
/*
2023-07-15 15:28:10 +08:00
switch (Settings.Canvas.EraserType)
{
case 1:
forcePointEraser = true;
break;
case 2:
forcePointEraser = false;
break;
}
ComboBoxEraserType.SelectedIndex = Settings.Canvas.EraserType;
2023-12-22 00:14:15 +08:00
*/
2023-07-15 15:28:10 +08:00
2023-12-22 00:14:15 +08:00
if (Settings.PowerPointSettings.IsAutoSaveScreenShotInPowerPoint) {
2023-04-05 16:05:03 +08:00
ToggleSwitchAutoSaveScreenShotInPowerPoint.IsOn = true;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
ToggleSwitchAutoSaveScreenShotInPowerPoint.IsOn = false;
}
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
Settings.Automation = new Automation();
}
2023-12-22 00:14:15 +08:00
if (Settings.Advanced != null) {
2023-05-08 19:58:14 +08:00
TouchMultiplierSlider.Value = Settings.Advanced.TouchMultiplier;
2023-12-22 00:14:15 +08:00
FingerModeBoundsWidthSlider.Value = Settings.Advanced.FingerModeBoundsWidth;
NibModeBoundsWidthSlider.Value = Settings.Advanced.NibModeBoundsWidth;
if (Settings.Advanced.IsLogEnabled) {
ToggleSwitchIsLogEnabled.IsOn = true;
2023-12-22 00:14:15 +08:00
} else {
ToggleSwitchIsLogEnabled.IsOn = false;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
if (Settings.Advanced.IsSecondConfimeWhenShutdownApp) {
ToggleSwitchIsSecondConfimeWhenShutdownApp.IsOn = true;
} else {
ToggleSwitchIsSecondConfimeWhenShutdownApp.IsOn = false;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
if (Settings.Advanced.EraserBindTouchMultiplier) {
ToggleSwitchEraserBindTouchMultiplier.IsOn = true;
} else {
ToggleSwitchEraserBindTouchMultiplier.IsOn = false;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
if (Settings.Advanced.IsSpecialScreen) {
ToggleSwitchIsSpecialScreen.IsOn = true;
2023-12-22 00:14:15 +08:00
} else {
ToggleSwitchIsSpecialScreen.IsOn = false;
2023-04-05 16:05:03 +08:00
}
TouchMultiplierSlider.Visibility = ToggleSwitchIsSpecialScreen.IsOn ? Visibility.Visible : Visibility.Collapsed;
2023-09-25 12:11:21 +08:00
ToggleSwitchIsQuadIR.IsOn = Settings.Advanced.IsQuadIR;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
Settings.Advanced = new Advanced();
}
2023-12-22 00:14:15 +08:00
if (Settings.InkToShape != null) {
if (Settings.InkToShape.IsInkToShapeEnabled) {
2023-04-05 16:05:03 +08:00
ToggleSwitchEnableInkToShape.IsOn = true;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
ToggleSwitchEnableInkToShape.IsOn = false;
}
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
Settings.InkToShape = new InkToShape();
}
2023-12-22 00:14:15 +08:00
if (Settings.RandSettings == null) Settings.RandSettings = new RandSettings();
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) {
ViewboxFloatingBarMarginAnimation(60);
} else {
ViewboxFloatingBarMarginAnimation(100);
}
2023-04-05 16:05:03 +08:00
}
#endregion Definations and Loading
#region Right Side Panel
public static bool CloseIsFromButton = false;
2023-12-22 00:14:15 +08:00
private void BtnExit_Click(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
CloseIsFromButton = true;
Close();
}
2023-12-22 00:14:15 +08:00
private void BtnRestart_Click(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
Process.Start(System.Windows.Forms.Application.ExecutablePath, "-m");
CloseIsFromButton = true;
Application.Current.Shutdown();
}
2023-12-22 00:14:15 +08:00
private void BtnSettings_Click(object sender, RoutedEventArgs e) {
if (BorderSettings.Visibility == Visibility.Visible) {
AnimationHelper.HideWithSlideAndFade(BorderSettings, 0.5);
} else {
AnimationHelper.ShowWithSlideFromBottomAndFade(BorderSettings, 0.5);
2023-04-05 16:05:03 +08:00
}
}
2023-12-22 00:14:15 +08:00
private void BtnThickness_Click(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
}
bool forceEraser = false;
2023-12-22 00:14:15 +08:00
private void BtnErase_Click(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
forcePointEraser = !forcePointEraser;
2023-12-22 00:14:15 +08:00
switch (Settings.Canvas.EraserType) {
2023-07-15 15:28:10 +08:00
case 1:
forcePointEraser = true;
break;
case 2:
forcePointEraser = false;
break;
}
inkCanvas.EraserShape = forcePointEraser ? new EllipseStylusShape(50, 50) : new EllipseStylusShape(5, 5);
2023-07-15 15:28:10 +08:00
inkCanvas.EditingMode =
forcePointEraser ? InkCanvasEditingMode.EraseByPoint : InkCanvasEditingMode.EraseByStroke;
2023-04-05 16:05:03 +08:00
drawingShapeMode = 0;
2023-12-22 00:14:15 +08:00
/*
2023-07-15 15:28:10 +08:00
GeometryDrawingEraser.Brush = forcePointEraser
? new SolidColorBrush(Color.FromRgb(0x23, 0xA9, 0xF2))
: new SolidColorBrush(Color.FromRgb(0x66, 0x66, 0x66));
2023-04-05 16:05:03 +08:00
ImageEraser.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
*/
2023-04-05 16:05:03 +08:00
inkCanvas_EditingModeChanged(inkCanvas, null);
CancelSingleFingerDragMode();
}
2023-12-22 00:14:15 +08:00
private void BtnClear_Click(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
forceEraser = false;
2023-12-22 00:14:15 +08:00
//BorderClearInDelete.Visibility = Visibility.Collapsed;
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
if (currentMode == 0) { // 先回到画笔再清屏,避免 TimeMachine 的相关 bug 影响
if (Pen_Icon.Background == null && StackPanelCanvasControls.Visibility == Visibility.Visible) {
PenIcon_Click(null, null);
}
} else {
if (Pen_Icon.Background == null) {
PenIcon_Click(null, null);
}
}
if (inkCanvas.Strokes.Count != 0) {
2023-04-05 16:05:03 +08:00
int whiteboardIndex = CurrentWhiteboardIndex;
2023-12-22 00:14:15 +08:00
if (currentMode == 0) {
2023-04-05 16:05:03 +08:00
whiteboardIndex = 0;
}
strokeCollections[whiteboardIndex] = inkCanvas.Strokes.Clone();
2023-04-05 16:05:03 +08:00
}
ClearStrokes(false);
2023-04-05 16:05:03 +08:00
inkCanvas.Children.Clear();
CancelSingleFingerDragMode();
}
2023-12-22 00:14:15 +08:00
private void CancelSingleFingerDragMode() {
if (ToggleSwitchDrawShapeBorderAutoHide.IsOn) {
CollapseBorderDrawShape();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
2023-04-05 16:05:03 +08:00
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
if (isSingleFingerDragMode) {
2023-04-05 16:05:03 +08:00
BtnFingerDragMode_Click(BtnFingerDragMode, null);
}
isLongPressSelected = false;
}
2023-12-22 00:14:15 +08:00
private void BtnHideControl_Click(object sender, RoutedEventArgs e) {
if (StackPanelControl.Visibility == Visibility.Visible) {
2023-04-05 16:05:03 +08:00
StackPanelControl.Visibility = Visibility.Hidden;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
StackPanelControl.Visibility = Visibility.Visible;
}
}
int currentMode = 0;
2023-12-22 00:14:15 +08:00
private void BtnSwitch_Click(object sender, RoutedEventArgs e) {
if (Main_Grid.Background == Brushes.Transparent) {
if (currentMode == 0) {
2023-04-05 16:05:03 +08:00
currentMode++;
GridBackgroundCover.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
AnimationHelper.HideWithSlideAndFade(BlackboardLeftSide);
AnimationHelper.HideWithSlideAndFade(BlackboardCenterSide);
AnimationHelper.HideWithSlideAndFade(BlackboardRightSide);
2023-04-05 16:05:03 +08:00
SaveStrokes(true);
ClearStrokes(true);
2023-04-05 16:05:03 +08:00
RestoreStrokes();
2023-12-22 00:14:15 +08:00
if (BtnSwitchTheme.Content.ToString() == "浅色") {
2023-04-05 16:05:03 +08:00
BtnSwitch.Content = "黑板";
BtnExit.Foreground = Brushes.White;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
BtnSwitch.Content = "白板";
2023-12-22 00:14:15 +08:00
if (isPresentationHaveBlackSpace) {
2023-04-05 16:05:03 +08:00
BtnExit.Foreground = Brushes.White;
2023-12-22 00:14:15 +08:00
//SymbolIconBtnColorBlackContent.Foreground = Brushes.White;
2023-04-05 16:05:03 +08:00
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Dark;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
BtnExit.Foreground = Brushes.Black;
2023-12-22 00:14:15 +08:00
//SymbolIconBtnColorBlackContent.Foreground = Brushes.White;
2023-04-05 16:05:03 +08:00
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Light;
}
}
StackPanelPPTButtons.Visibility = Visibility.Visible;
}
BtnHideInkCanvas_Click(BtnHideInkCanvas, e);
2023-12-22 00:14:15 +08:00
} else {
switch ((++currentMode) % 2) {
2023-04-05 16:05:03 +08:00
case 0: //屏幕模式
currentMode = 0;
GridBackgroundCover.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
AnimationHelper.HideWithSlideAndFade(BlackboardLeftSide);
AnimationHelper.HideWithSlideAndFade(BlackboardCenterSide);
AnimationHelper.HideWithSlideAndFade(BlackboardRightSide);
2023-04-05 16:05:03 +08:00
SaveStrokes();
ClearStrokes(true);
2023-04-05 16:05:03 +08:00
RestoreStrokes(true);
2023-12-22 00:14:15 +08:00
if (BtnSwitchTheme.Content.ToString() == "浅色") {
2023-04-05 16:05:03 +08:00
BtnSwitch.Content = "黑板";
BtnExit.Foreground = Brushes.White;
2023-12-22 00:14:15 +08:00
//SymbolIconBtnColorBlackContent.Foreground = Brushes.Black;
2023-04-05 16:05:03 +08:00
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Dark;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
BtnSwitch.Content = "白板";
2023-12-22 00:14:15 +08:00
if (isPresentationHaveBlackSpace) {
2023-04-05 16:05:03 +08:00
BtnExit.Foreground = Brushes.White;
2023-12-22 00:14:15 +08:00
//SymbolIconBtnColorBlackContent.Foreground = Brushes.White;
2023-04-05 16:05:03 +08:00
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Dark;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
BtnExit.Foreground = Brushes.Black;
2023-12-22 00:14:15 +08:00
//SymbolIconBtnColorBlackContent.Foreground = Brushes.White;
2023-04-05 16:05:03 +08:00
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Light;
}
}
2023-04-05 16:05:03 +08:00
StackPanelPPTButtons.Visibility = Visibility.Visible;
break;
case 1: //黑板或白板模式
currentMode = 1;
GridBackgroundCover.Visibility = Visibility.Visible;
2023-12-22 00:14:15 +08:00
AnimationHelper.ShowWithSlideFromBottomAndFade(BlackboardLeftSide);
AnimationHelper.ShowWithSlideFromBottomAndFade(BlackboardCenterSide);
AnimationHelper.ShowWithSlideFromBottomAndFade(BlackboardRightSide);
2023-04-05 16:05:03 +08:00
SaveStrokes(true);
ClearStrokes(true);
2023-04-05 16:05:03 +08:00
RestoreStrokes();
BtnSwitch.Content = "屏幕";
2023-12-22 00:14:15 +08:00
if (BtnSwitchTheme.Content.ToString() == "浅色") {
2023-04-05 16:05:03 +08:00
BtnExit.Foreground = Brushes.White;
2023-12-22 00:14:15 +08:00
//SymbolIconBtnColorBlackContent.Foreground = Brushes.Black;
2023-04-05 16:05:03 +08:00
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Dark;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
BtnExit.Foreground = Brushes.Black;
2023-12-22 00:14:15 +08:00
//SymbolIconBtnColorBlackContent.Foreground = Brushes.White;
2023-04-05 16:05:03 +08:00
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Light;
}
2023-04-05 16:05:03 +08:00
StackPanelPPTButtons.Visibility = Visibility.Collapsed;
break;
}
}
}
int BoundsWidth = 5;
2023-12-22 00:14:15 +08:00
private void BtnHideInkCanvas_Click(object sender, RoutedEventArgs e) {
if (Main_Grid.Background == Brushes.Transparent) {
2023-04-05 16:05:03 +08:00
Main_Grid.Background = new SolidColorBrush(StringToColor("#01FFFFFF"));
2023-12-22 00:14:15 +08:00
/*
2023-04-05 16:05:03 +08:00
if (Settings.Canvas.HideStrokeWhenSelecting)
{
inkCanvas.Visibility = Visibility.Visible;
inkCanvas.IsHitTestVisible = true;
}
else
{
inkCanvas.IsHitTestVisible = true;
inkCanvas.Visibility = Visibility.Visible;
}
2023-12-22 00:14:15 +08:00
*/
inkCanvas.IsHitTestVisible = true;
inkCanvas.Visibility = Visibility.Visible;
2023-04-05 16:05:03 +08:00
GridBackgroundCoverHolder.Visibility = Visibility.Visible;
2023-12-22 00:14:15 +08:00
2023-04-05 16:05:03 +08:00
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
//if (ImageEraserMask.Visibility == Visibility.Visible)
/*if (forceEraser && currentMode == 0)
BtnColorRed_Click(sender, null);*/
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
if (GridBackgroundCover.Visibility == Visibility.Collapsed) {
if (BtnSwitchTheme.Content.ToString() == "浅色") {
2023-04-05 16:05:03 +08:00
BtnSwitch.Content = "黑板";
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
BtnSwitch.Content = "白板";
}
StackPanelPPTButtons.Visibility = Visibility.Visible;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
BtnSwitch.Content = "屏幕";
StackPanelPPTButtons.Visibility = Visibility.Collapsed;
}
BtnHideInkCanvas.Content = "隐藏\n画板";
2023-12-22 00:14:15 +08:00
} else {
2023-05-08 19:58:14 +08:00
2023-04-05 16:05:03 +08:00
// Auto-clear Strokes
// 很烦, 要重新来, 要等待截图完成再清理笔记
2023-12-22 00:14:15 +08:00
if (BtnPPTSlideShowEnd.Visibility != Visibility.Visible) {
if (isLoaded && Settings.Automation.IsAutoClearWhenExitingWritingMode) {
if (inkCanvas.Strokes.Count > 0) {
if (Settings.Automation.IsAutoSaveStrokesAtClear && inkCanvas.Strokes.Count >
2023-12-22 00:14:15 +08:00
Settings.Automation.MinimumAutomationStrokeNumber) {
SaveScreenShot(true);
}
2023-12-22 00:14:15 +08:00
BtnClear_Click(null, null);
2023-04-05 16:05:03 +08:00
}
}
2023-12-22 00:14:15 +08:00
/*
if (Settings.Canvas.HideStrokeWhenSelecting)
inkCanvas.Visibility = Visibility.Collapsed;
else
{
inkCanvas.IsHitTestVisible = false;
inkCanvas.Visibility = Visibility.Visible;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
*/
inkCanvas.IsHitTestVisible = true;
inkCanvas.Visibility = Visibility.Visible;
} else {
if (isLoaded && Settings.Automation.IsAutoClearWhenExitingWritingMode && !Settings.PowerPointSettings.IsNoClearStrokeOnSelectWhenInPowerPoint) {
if (inkCanvas.Strokes.Count > 0) {
if (Settings.Automation.IsAutoSaveStrokesAtClear && inkCanvas.Strokes.Count >
2023-12-22 00:14:15 +08:00
Settings.Automation.MinimumAutomationStrokeNumber) {
SaveScreenShot(true);
}
2023-12-22 00:14:15 +08:00
BtnClear_Click(null, null);
}
}
2023-05-08 19:58:14 +08:00
2023-12-22 00:14:15 +08:00
if (Settings.PowerPointSettings.IsShowStrokeOnSelectInPowerPoint) {
inkCanvas.Visibility = Visibility.Visible;
inkCanvas.IsHitTestVisible = true;
2023-12-22 00:14:15 +08:00
} else {
/*
if (Settings.Canvas.HideStrokeWhenSelecting)
inkCanvas.Visibility = Visibility.Collapsed;
else
{
inkCanvas.IsHitTestVisible = false;
inkCanvas.Visibility = Visibility.Visible;
2023-12-22 00:14:15 +08:00
}*/
inkCanvas.IsHitTestVisible = true;
inkCanvas.Visibility = Visibility.Visible;
}
2023-04-05 16:05:03 +08:00
}
2023-05-08 19:58:14 +08:00
Main_Grid.Background = Brushes.Transparent;
2023-05-08 19:58:14 +08:00
2023-04-05 16:05:03 +08:00
GridBackgroundCoverHolder.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
if (currentMode != 0) {
2023-04-05 16:05:03 +08:00
SaveStrokes();
RestoreStrokes(true);
}
2023-12-22 00:14:15 +08:00
if (BtnSwitchTheme.Content.ToString() == "浅色") {
2023-04-05 16:05:03 +08:00
BtnSwitch.Content = "黑板";
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
BtnSwitch.Content = "白板";
}
StackPanelPPTButtons.Visibility = Visibility.Visible;
BtnHideInkCanvas.Content = "显示\n画板";
}
2023-12-22 00:14:15 +08:00
if (Main_Grid.Background == Brushes.Transparent) {
2023-04-05 16:05:03 +08:00
StackPanelCanvasControls.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
CheckEnableTwoFingerGestureBtnVisibility(false);
HideSubPanels("cursor");
} else {
AnimationHelper.ShowWithSlideFromLeftAndFade(StackPanelCanvasControls);
CheckEnableTwoFingerGestureBtnVisibility(true);
2023-04-05 16:05:03 +08:00
}
}
2023-12-22 00:14:15 +08:00
private void BtnSwitchSide_Click(object sender, RoutedEventArgs e) {
if (ViewBoxStackPanelMain.HorizontalAlignment == HorizontalAlignment.Right) {
2023-04-05 16:05:03 +08:00
ViewBoxStackPanelMain.HorizontalAlignment = HorizontalAlignment.Left;
ViewBoxStackPanelShapes.HorizontalAlignment = HorizontalAlignment.Right;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
ViewBoxStackPanelMain.HorizontalAlignment = HorizontalAlignment.Right;
ViewBoxStackPanelShapes.HorizontalAlignment = HorizontalAlignment.Left;
}
}
2023-12-22 00:14:15 +08:00
private void StackPanel_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) {
if (((StackPanel)sender).Visibility == Visibility.Visible) {
2023-04-05 16:05:03 +08:00
GridForLeftSideReservedSpace.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
GridForLeftSideReservedSpace.Visibility = Visibility.Visible;
}
}
#endregion
#region Right Side Panel (Buttons - Color)
int inkColor = 1;
2023-12-22 00:14:15 +08:00
private void ColorSwitchCheck() {
HideSubPanels("color");
if (Main_Grid.Background == Brushes.Transparent) {
if (currentMode == 1) {
2023-04-05 16:05:03 +08:00
currentMode = 0;
GridBackgroundCover.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
AnimationHelper.HideWithSlideAndFade(BlackboardLeftSide);
AnimationHelper.HideWithSlideAndFade(BlackboardCenterSide);
AnimationHelper.HideWithSlideAndFade(BlackboardRightSide);
2023-04-05 16:05:03 +08:00
}
BtnHideInkCanvas_Click(BtnHideInkCanvas, null);
}
StrokeCollection strokes = inkCanvas.GetSelectedStrokes();
2023-12-22 00:14:15 +08:00
if (strokes.Count != 0) {
foreach (Stroke stroke in strokes) {
try {
2023-04-05 16:05:03 +08:00
stroke.DrawingAttributes.Color = inkCanvas.DefaultDrawingAttributes.Color;
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
inkCanvas.IsManipulationEnabled = true;
drawingShapeMode = 0;
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
CancelSingleFingerDragMode();
forceEraser = false;
2023-12-22 00:14:15 +08:00
CheckColorTheme();
2023-04-05 16:05:03 +08:00
}
isLongPressSelected = false;
}
2023-12-22 00:14:15 +08:00
bool isUselightThemeColor = false, isDesktopUselightThemeColor = false;
int lastDesktopInkColor = 1, lastBoardInkColor = 5;
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
private void CheckColorTheme(bool changeColorTheme = false) {
if (changeColorTheme) {
if (currentMode != 0) {
if (Settings.Canvas.UsingWhiteboard) {
GridBackgroundCover.Background = new SolidColorBrush(StringToColor("#FFF2F2F2"));
isUselightThemeColor = false;
} else {
GridBackgroundCover.Background = new SolidColorBrush(StringToColor("#FF1F1F1F"));
isUselightThemeColor = true;
}
}
}
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
if (currentMode == 0) {
isUselightThemeColor = isDesktopUselightThemeColor;
inkColor = lastDesktopInkColor;
} else {
inkColor = lastBoardInkColor;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
if (inkColor == 0) { // Black
inkCanvas.DefaultDrawingAttributes.Color = Colors.Black;
} else if (inkColor == 5) { // White
inkCanvas.DefaultDrawingAttributes.Color = StringToColor("#FFFEFEFE");
} else if (isUselightThemeColor) {
if (inkColor == 1) { // Red
inkCanvas.DefaultDrawingAttributes.Color = StringToColor("#FFFF3333");
} else if (inkColor == 2) { // Green
inkCanvas.DefaultDrawingAttributes.Color = StringToColor("#FF1ED760");
} else if (inkColor == 3) { // Blue
inkCanvas.DefaultDrawingAttributes.Color = StringToColor("#FF23C0D6");
} else if (inkColor == 4) { // Yellow
inkCanvas.DefaultDrawingAttributes.Color = StringToColor("#FFFFC000");
} else if (inkColor == 6) { // Pink
inkCanvas.DefaultDrawingAttributes.Color = StringToColor("#FF#c72ec7");
}
} else {
if (inkColor == 1) { // Red
inkCanvas.DefaultDrawingAttributes.Color = Colors.Red;
} else if (inkColor == 2) { // Green
inkCanvas.DefaultDrawingAttributes.Color = StringToColor("#FF169141");
} else if (inkColor == 3) { // Blue
inkCanvas.DefaultDrawingAttributes.Color = StringToColor("#FF239AD6");
} else if (inkColor == 4) { // Yellow
inkCanvas.DefaultDrawingAttributes.Color = StringToColor("#FFF38B00");
} else if (inkColor == 6) { // Pink ( Purple )
inkCanvas.DefaultDrawingAttributes.Color = StringToColor("#FF331EB5");
}
}
if (isUselightThemeColor) { // 亮色系
BorderPenColorRed.Background = new SolidColorBrush(StringToColor("#FFFF3333"));
BorderPenColorGreen.Background = new SolidColorBrush(StringToColor("#FF1ED760"));
BorderPenColorBlue.Background = new SolidColorBrush(StringToColor("#FF23C0D6"));
BorderPenColorYellow.Background = new SolidColorBrush(StringToColor("#FFFFC000"));
BorderPenColorPink.Background = new SolidColorBrush(StringToColor("#FF#c72ec7"));
BoardBorderPenColorRed.Background = new SolidColorBrush(StringToColor("#FFFF3333"));
BoardBorderPenColorGreen.Background = new SolidColorBrush(StringToColor("#FF1ED760"));
BoardBorderPenColorBlue.Background = new SolidColorBrush(StringToColor("#FF23C0D6"));
BoardBorderPenColorYellow.Background = new SolidColorBrush(StringToColor("#FFFFC000"));
BoardBorderPenColorPink.Background = new SolidColorBrush(StringToColor("#FF#c72ec7"));
BitmapImage newImageSource = new BitmapImage();
newImageSource.BeginInit();
newImageSource.UriSource = new Uri("/Resources/Icons-Fluent/ic_fluent_weather_moon_24_regular.png", UriKind.RelativeOrAbsolute);
newImageSource.EndInit();
ColorThemeSwitchIcon.Source = newImageSource;
BoardColorThemeSwitchIcon.Source = newImageSource;
ColorThemeSwitchTextBlock.Text = "暗色系";
BoardColorThemeSwitchTextBlock.Text = "暗色系";
} else { // 暗色系
BorderPenColorRed.Background = new SolidColorBrush(Colors.Red);
BorderPenColorGreen.Background = new SolidColorBrush(StringToColor("#FF169141"));
BorderPenColorBlue.Background = new SolidColorBrush(StringToColor("#FF239AD6"));
BorderPenColorYellow.Background = new SolidColorBrush(StringToColor("#FFF38B00"));
BorderPenColorPink.Background = new SolidColorBrush(StringToColor("#FF331EB5"));
BoardBorderPenColorRed.Background = new SolidColorBrush(Colors.Red);
BoardBorderPenColorGreen.Background = new SolidColorBrush(StringToColor("#FF169141"));
BoardBorderPenColorBlue.Background = new SolidColorBrush(StringToColor("#FF239AD6"));
BoardBorderPenColorYellow.Background = new SolidColorBrush(StringToColor("#FFF38B00"));
BoardBorderPenColorPink.Background = new SolidColorBrush(StringToColor("#FF331EB5"));
BitmapImage newImageSource = new BitmapImage();
newImageSource.BeginInit();
newImageSource.UriSource = new Uri("/Resources/Icons-Fluent/ic_fluent_weather_sunny_24_regular.png", UriKind.RelativeOrAbsolute);
newImageSource.EndInit();
ColorThemeSwitchIcon.Source = newImageSource;
BoardColorThemeSwitchIcon.Source = newImageSource;
ColorThemeSwitchTextBlock.Text = "亮色系";
BoardColorThemeSwitchTextBlock.Text = "亮色系";
}
// 改变选中提示
ViewboxBtnColorBlackContent.Visibility = Visibility.Collapsed;
ViewboxBtnColorBlueContent.Visibility = Visibility.Collapsed;
ViewboxBtnColorGreenContent.Visibility = Visibility.Collapsed;
ViewboxBtnColorRedContent.Visibility = Visibility.Collapsed;
ViewboxBtnColorYellowContent.Visibility = Visibility.Collapsed;
ViewboxBtnColorWhiteContent.Visibility = Visibility.Collapsed;
ViewboxBtnColorPinkContent.Visibility = Visibility.Collapsed;
BoardViewboxBtnColorBlackContent.Visibility = Visibility.Collapsed;
BoardViewboxBtnColorBlueContent.Visibility = Visibility.Collapsed;
BoardViewboxBtnColorGreenContent.Visibility = Visibility.Collapsed;
BoardViewboxBtnColorRedContent.Visibility = Visibility.Collapsed;
BoardViewboxBtnColorYellowContent.Visibility = Visibility.Collapsed;
BoardViewboxBtnColorWhiteContent.Visibility = Visibility.Collapsed;
BoardViewboxBtnColorPinkContent.Visibility = Visibility.Collapsed;
switch (inkColor) {
case 0:
ViewboxBtnColorBlackContent.Visibility = Visibility.Visible;
BoardViewboxBtnColorBlackContent.Visibility = Visibility.Visible;
break;
case 1:
ViewboxBtnColorRedContent.Visibility = Visibility.Visible;
BoardViewboxBtnColorRedContent.Visibility = Visibility.Visible;
break;
case 2:
ViewboxBtnColorGreenContent.Visibility = Visibility.Visible;
BoardViewboxBtnColorGreenContent.Visibility = Visibility.Visible;
break;
case 3:
ViewboxBtnColorBlueContent.Visibility = Visibility.Visible;
BoardViewboxBtnColorBlueContent.Visibility = Visibility.Visible;
break;
case 4:
ViewboxBtnColorYellowContent.Visibility = Visibility.Visible;
BoardViewboxBtnColorYellowContent.Visibility = Visibility.Visible;
break;
case 5:
ViewboxBtnColorWhiteContent.Visibility = Visibility.Visible;
BoardViewboxBtnColorWhiteContent.Visibility = Visibility.Visible;
break;
case 6:
ViewboxBtnColorPinkContent.Visibility = Visibility.Visible;
BoardViewboxBtnColorPinkContent.Visibility = Visibility.Visible;
break;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
}
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
private void BtnColorBlack_Click(object sender, RoutedEventArgs e) {
if (currentMode == 0) {
lastDesktopInkColor = 0;
} else {
lastBoardInkColor = 0;
}
//inkColor = 0;
forceEraser = false;
2023-04-05 16:05:03 +08:00
ColorSwitchCheck();
}
2023-12-22 00:14:15 +08:00
private void BtnColorRed_Click(object sender, RoutedEventArgs e) {
if (currentMode == 0) {
lastDesktopInkColor = 1;
} else {
lastBoardInkColor = 1;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
//inkColor = 1;
forceEraser = false;
2023-04-05 16:05:03 +08:00
ColorSwitchCheck();
}
2023-12-22 00:14:15 +08:00
private void BtnColorGreen_Click(object sender, RoutedEventArgs e) {
if (currentMode == 0) {
lastDesktopInkColor = 2;
} else {
lastBoardInkColor = 2;
}
//inkColor = 2;
2023-04-05 16:05:03 +08:00
forceEraser = false;
ColorSwitchCheck();
}
2023-12-22 00:14:15 +08:00
private void BtnColorBlue_Click(object sender, RoutedEventArgs e) {
if (currentMode == 0) {
lastDesktopInkColor = 3;
} else {
lastBoardInkColor = 3;
}
//inkColor = 3;
2023-04-05 16:05:03 +08:00
forceEraser = false;
2023-12-22 00:14:15 +08:00
ColorSwitchCheck();
}
private void BtnColorYellow_Click(object sender, RoutedEventArgs e) {
if (currentMode == 0) {
lastDesktopInkColor = 4;
} else {
lastBoardInkColor = 4;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
//inkColor = 4;
forceEraser = false;
ColorSwitchCheck();
}
private void BtnColorWhite_Click(object sender, RoutedEventArgs e) {
if (currentMode == 0) {
lastDesktopInkColor = 5;
} else {
lastBoardInkColor = 5;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
//inkColor = 5;
forceEraser = false;
ColorSwitchCheck();
}
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
private void BtnColorPink_Click(object sender, RoutedEventArgs e) {
if (currentMode == 0) {
lastDesktopInkColor = 6;
} else {
lastBoardInkColor = 6;
}
//inkColor = 6;
forceEraser = false;
2023-04-05 16:05:03 +08:00
ColorSwitchCheck();
}
2023-12-22 00:14:15 +08:00
private Color StringToColor(string colorStr) {
2023-04-05 16:05:03 +08:00
Byte[] argb = new Byte[4];
2023-12-22 00:14:15 +08:00
for (int i = 0; i < 4; i++) {
2023-04-05 16:05:03 +08:00
char[] charArray = colorStr.Substring(i * 2 + 1, 2).ToCharArray();
//string str = "11";
Byte b1 = toByte(charArray[0]);
Byte b2 = toByte(charArray[1]);
argb[i] = (Byte)(b2 | (b1 << 4));
}
return Color.FromArgb(argb[0], argb[1], argb[2], argb[3]);//#FFFFFFFF
}
2023-12-22 00:14:15 +08:00
private static byte toByte(char c) {
2023-04-05 16:05:03 +08:00
byte b = (byte)"0123456789ABCDEF".IndexOf(c);
return b;
}
#endregion
#region Touch Events
#region Multi-Touch
bool isInMultiTouchMode = false;
2023-12-22 00:14:15 +08:00
private void BorderMultiTouchMode_MouseUp(object sender, MouseButtonEventArgs e) {
if (isInMultiTouchMode) {
2023-04-05 16:05:03 +08:00
inkCanvas.StylusDown -= MainWindow_StylusDown;
inkCanvas.StylusMove -= MainWindow_StylusMove;
inkCanvas.StylusUp -= MainWindow_StylusUp;
inkCanvas.TouchDown -= MainWindow_TouchDown;
inkCanvas.TouchDown += Main_Grid_TouchDown;
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
inkCanvas.Children.Clear();
isInMultiTouchMode = false;
2023-12-22 00:14:15 +08:00
//SymbolIconMultiTouchMode.Symbol = ModernWpf.Controls.Symbol.People;
} else {
2023-04-05 16:05:03 +08:00
inkCanvas.StylusDown += MainWindow_StylusDown;
inkCanvas.StylusMove += MainWindow_StylusMove;
inkCanvas.StylusUp += MainWindow_StylusUp;
inkCanvas.TouchDown -= Main_Grid_TouchDown;
inkCanvas.TouchDown += MainWindow_TouchDown;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.Children.Clear();
isInMultiTouchMode = true;
2023-12-22 00:14:15 +08:00
//SymbolIconMultiTouchMode.Symbol = ModernWpf.Controls.Symbol.Contact;
2023-04-05 16:05:03 +08:00
}
}
2023-12-22 00:14:15 +08:00
private void MainWindow_TouchDown(object sender, TouchEventArgs e) {
if (!isHidingSubPanelsWhenInking) {
isHidingSubPanelsWhenInking = true;
HideSubPanels(); // 书写时自动隐藏二级菜单
}
2023-04-05 16:05:03 +08:00
double boundWidth = e.GetTouchPoint(null).Bounds.Width;
2023-12-22 00:14:15 +08:00
if (boundWidth > 20) {
2023-04-05 16:05:03 +08:00
inkCanvas.EraserShape = new EllipseStylusShape(boundWidth, boundWidth);
TouchDownPointsList[e.TouchDevice.Id] = InkCanvasEditingMode.EraseByPoint;
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
TouchDownPointsList[e.TouchDevice.Id] = InkCanvasEditingMode.None;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
}
}
2023-12-22 00:14:15 +08:00
private void MainWindow_StylusDown(object sender, StylusDownEventArgs e) {
2023-04-05 16:05:03 +08:00
TouchDownPointsList[e.StylusDevice.Id] = InkCanvasEditingMode.None;
}
2023-12-22 00:14:15 +08:00
private void MainWindow_StylusUp(object sender, StylusEventArgs e) {
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Add(GetStrokeVisual(e.StylusDevice.Id).Stroke);
inkCanvas.Children.Remove(GetVisualCanvas(e.StylusDevice.Id));
inkCanvas_StrokeCollected(inkCanvas, new InkCanvasStrokeCollectedEventArgs(GetStrokeVisual(e.StylusDevice.Id).Stroke));
2023-12-22 00:14:15 +08:00
} catch (Exception ex) {
2023-04-05 16:05:03 +08:00
Label.Content = ex.ToString();
}
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
StrokeVisualList.Remove(e.StylusDevice.Id);
VisualCanvasList.Remove(e.StylusDevice.Id);
TouchDownPointsList.Remove(e.StylusDevice.Id);
2023-12-22 00:14:15 +08:00
if (StrokeVisualList.Count == 0 || VisualCanvasList.Count == 0 || TouchDownPointsList.Count == 0) {
2023-04-05 16:05:03 +08:00
inkCanvas.Children.Clear();
StrokeVisualList.Clear();
VisualCanvasList.Clear();
TouchDownPointsList.Clear();
}
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void MainWindow_StylusMove(object sender, StylusEventArgs e) {
try {
2023-04-05 16:05:03 +08:00
if (GetTouchDownPointsList(e.StylusDevice.Id) != InkCanvasEditingMode.None) return;
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
if (e.StylusDevice.StylusButtons[1].StylusButtonState == StylusButtonState.Down) return;
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
var strokeVisual = GetStrokeVisual(e.StylusDevice.Id);
var stylusPointCollection = e.GetStylusPoints(this);
2023-12-22 00:14:15 +08:00
foreach (var stylusPoint in stylusPointCollection) {
2023-04-05 16:05:03 +08:00
strokeVisual.Add(new StylusPoint(stylusPoint.X, stylusPoint.Y, stylusPoint.PressureFactor));
}
strokeVisual.Redraw();
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private StrokeVisual GetStrokeVisual(int id) {
if (StrokeVisualList.TryGetValue(id, out var visual)) {
2023-04-05 16:05:03 +08:00
return visual;
}
var strokeVisual = new StrokeVisual(inkCanvas.DefaultDrawingAttributes.Clone());
StrokeVisualList[id] = strokeVisual;
StrokeVisualList[id] = strokeVisual;
var visualCanvas = new VisualCanvas(strokeVisual);
VisualCanvasList[id] = visualCanvas;
inkCanvas.Children.Add(visualCanvas);
return strokeVisual;
}
2023-12-22 00:14:15 +08:00
private VisualCanvas GetVisualCanvas(int id) {
if (VisualCanvasList.TryGetValue(id, out var visualCanvas)) {
2023-04-05 16:05:03 +08:00
return visualCanvas;
}
return null;
}
2023-12-22 00:14:15 +08:00
private InkCanvasEditingMode GetTouchDownPointsList(int id) {
if (TouchDownPointsList.TryGetValue(id, out var inkCanvasEditingMode)) {
2023-04-05 16:05:03 +08:00
return inkCanvasEditingMode;
}
return inkCanvas.EditingMode;
}
private Dictionary<int, InkCanvasEditingMode> TouchDownPointsList { get; } = new Dictionary<int, InkCanvasEditingMode>();
private Dictionary<int, StrokeVisual> StrokeVisualList { get; } = new Dictionary<int, StrokeVisual>();
private Dictionary<int, VisualCanvas> VisualCanvasList { get; } = new Dictionary<int, VisualCanvas>();
#endregion
int lastTouchDownTime = 0, lastTouchUpTime = 0;
Point iniP = new Point(0, 0);
bool isLastTouchEraser = false;
private bool forcePointEraser = true;
2023-12-22 00:14:15 +08:00
private void Main_Grid_TouchDown(object sender, TouchEventArgs e) {
if (!isHidingSubPanelsWhenInking) {
isHidingSubPanelsWhenInking = true;
HideSubPanels(); // 书写时自动隐藏二级菜单
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
if (NeedUpdateIniP()) {
2023-04-05 16:05:03 +08:00
iniP = e.GetTouchPoint(inkCanvas).Position;
}
2023-12-22 00:14:15 +08:00
if (drawingShapeMode == 9 && isFirstTouchCuboid == false) {
2023-04-05 16:05:03 +08:00
MouseTouchMove(iniP);
}
inkCanvas.Opacity = 1;
double boundsWidth = GetTouchBoundWidth(e);
var eraserMultiplier = 1d;
if (!Settings.Advanced.EraserBindTouchMultiplier && Settings.Advanced.IsSpecialScreen) eraserMultiplier = 1 / Settings.Advanced.TouchMultiplier;
2023-12-22 00:14:15 +08:00
if (boundsWidth > BoundsWidth) {
2023-04-05 16:05:03 +08:00
isLastTouchEraser = true;
if (drawingShapeMode == 0 && forceEraser) return;
2023-12-22 00:14:15 +08:00
if (boundsWidth > BoundsWidth * 2.5) {
2023-04-05 16:05:03 +08:00
double k = 1;
2023-12-22 00:14:15 +08:00
switch (Settings.Canvas.EraserSize) {
2023-04-05 16:05:03 +08:00
case 0:
k = 0.5;
break;
case 1:
k = 0.8;
break;
case 3:
k = 1.25;
break;
case 4:
k = 1.8;
break;
}
inkCanvas.EraserShape = new EllipseStylusShape(boundsWidth * 1.5 * k * eraserMultiplier, boundsWidth * 1.5 * k * eraserMultiplier);
2023-04-05 16:05:03 +08:00
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
2023-12-22 00:14:15 +08:00
} else {
if (StackPanelPPTControls.Visibility == Visibility.Visible && inkCanvas.Strokes.Count == 0 && Settings.PowerPointSettings.IsEnableFingerGestureSlideShowControl) {
2023-04-05 16:05:03 +08:00
isLastTouchEraser = false;
inkCanvas.EditingMode = InkCanvasEditingMode.GestureOnly;
inkCanvas.Opacity = 0.1;
2023-12-22 00:14:15 +08:00
} else {
2023-09-25 12:11:21 +08:00
inkCanvas.EraserShape = new EllipseStylusShape(5, 5);
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByStroke;
2023-04-05 16:05:03 +08:00
}
}
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
isLastTouchEraser = false;
inkCanvas.EraserShape = forcePointEraser ? new EllipseStylusShape(50, 50) : new EllipseStylusShape(5, 5);
if (forceEraser) return;
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
}
}
2023-12-22 00:14:15 +08:00
public double GetTouchBoundWidth(TouchEventArgs e) {
var args = e.GetTouchPoint(null).Bounds;
2023-09-25 12:11:21 +08:00
double value;
if (!Settings.Advanced.IsQuadIR) value = args.Width;
else value = Math.Sqrt(args.Width * args.Height); //四边红外
if (Settings.Advanced.IsSpecialScreen) value *= Settings.Advanced.TouchMultiplier;
2023-04-05 16:05:03 +08:00
return value;
}
//记录触摸设备ID
private List<int> dec = new List<int>();
//中心点
System.Windows.Point centerPoint;
InkCanvasEditingMode lastInkCanvasEditingMode = InkCanvasEditingMode.Ink;
bool isSingleFingerDragMode = false;
//防止衣服误触造成的墨迹消失
2023-12-22 00:14:15 +08:00
private void inkCanvas_PreviewTouchDown(object sender, TouchEventArgs e) {
2023-04-05 16:05:03 +08:00
dec.Add(e.TouchDevice.Id);
//设备1个的时候记录中心点
2023-12-22 00:14:15 +08:00
if (dec.Count == 1) {
2023-04-05 16:05:03 +08:00
TouchPoint touchPoint = e.GetTouchPoint(inkCanvas);
centerPoint = touchPoint.Position;
//记录第一根手指点击时的 StrokeCollection
lastTouchDownStrokeCollection = inkCanvas.Strokes.Clone();
}
//设备两个及两个以上,将画笔功能关闭
2023-12-22 00:14:15 +08:00
if (dec.Count > 1 || isSingleFingerDragMode || !Settings.Gesture.IsEnableTwoFingerGesture) {
if (isInMultiTouchMode || !Settings.Gesture.IsEnableTwoFingerGesture) return;
2023-12-22 00:14:15 +08:00
if (inkCanvas.EditingMode != InkCanvasEditingMode.None && inkCanvas.EditingMode != InkCanvasEditingMode.Select) {
2023-04-05 16:05:03 +08:00
lastInkCanvasEditingMode = inkCanvas.EditingMode;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
}
}
}
2023-12-22 00:14:15 +08:00
private void inkCanvas_PreviewTouchUp(object sender, TouchEventArgs e) {
2023-04-05 16:05:03 +08:00
//手势完成后切回之前的状态
2023-12-22 00:14:15 +08:00
if (dec.Count > 1) {
if (inkCanvas.EditingMode == InkCanvasEditingMode.None) {
2023-04-05 16:05:03 +08:00
inkCanvas.EditingMode = lastInkCanvasEditingMode;
}
}
dec.Remove(e.TouchDevice.Id);
inkCanvas.Opacity = 1;
2023-12-22 00:14:15 +08:00
if (dec.Count == 0) {
2023-04-05 16:05:03 +08:00
if (lastTouchDownStrokeCollection.Count() != inkCanvas.Strokes.Count() &&
2023-12-22 00:14:15 +08:00
!(drawingShapeMode == 9 && !isFirstTouchCuboid)) {
2023-04-05 16:05:03 +08:00
int whiteboardIndex = CurrentWhiteboardIndex;
2023-12-22 00:14:15 +08:00
if (currentMode == 0) {
2023-04-05 16:05:03 +08:00
whiteboardIndex = 0;
}
strokeCollections[whiteboardIndex] = lastTouchDownStrokeCollection;
}
}
}
2023-12-22 00:14:15 +08:00
private void inkCanvas_ManipulationStarting(object sender, ManipulationStartingEventArgs e) {
2023-04-05 16:05:03 +08:00
e.Mode = ManipulationModes.All;
}
2023-12-22 00:14:15 +08:00
private void inkCanvas_ManipulationInertiaStarting(object sender, ManipulationInertiaStartingEventArgs e) {
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void Main_Grid_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e) {
if (e.Manipulators.Count() == 0) {
2023-04-05 16:05:03 +08:00
if (forceEraser) return;
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
}
}
2023-12-22 00:14:15 +08:00
private void Main_Grid_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) {
if (isInMultiTouchMode || !Settings.Gesture.IsEnableTwoFingerGesture) return;
2023-12-22 00:14:15 +08:00
if ((dec.Count >= 2 && (Settings.PowerPointSettings.IsEnableTwoFingerGestureInPresentationMode || StackPanelPPTControls.Visibility != Visibility.Visible || StackPanelPPTButtons.Visibility == Visibility.Collapsed)) || isSingleFingerDragMode) {
2023-04-05 16:05:03 +08:00
ManipulationDelta md = e.DeltaManipulation;
Vector trans = md.Translation; // 获得位移矢量
Matrix m = new Matrix();
if (Settings.Gesture.IsEnableTwoFingerTranslate)
m.Translate(trans.X, trans.Y); // 移动
2023-12-22 00:14:15 +08:00
if (Settings.Gesture.IsEnableTwoFingerGestureTranslateOrRotation) {
double rotate = md.Rotation; // 获得旋转角度
Vector scale = md.Scale; // 获得缩放倍数
// Find center of element and then transform to get current location of center
FrameworkElement fe = e.Source as FrameworkElement;
Point center = new Point(fe.ActualWidth / 2, fe.ActualHeight / 2);
center = m.Transform(center); // 转换为矩阵缩放和旋转的中心点
if (Settings.Gesture.IsEnableTwoFingerRotation)
m.RotateAt(rotate, center.X, center.Y); // 旋转
if (Settings.Gesture.IsEnableTwoFingerZoom)
m.ScaleAt(scale.X, scale.Y, center.X, center.Y); // 缩放
}
2023-04-05 16:05:03 +08:00
StrokeCollection strokes = inkCanvas.GetSelectedStrokes();
2023-12-22 00:14:15 +08:00
if (strokes.Count != 0) {
foreach (Stroke stroke in strokes) {
2023-04-05 16:05:03 +08:00
stroke.Transform(m, false);
2023-12-22 00:14:15 +08:00
foreach (Circle circle in circles) {
if (stroke == circle.Stroke) {
2023-04-05 16:05:03 +08:00
circle.R = GetDistance(circle.Stroke.StylusPoints[0].ToPoint(), circle.Stroke.StylusPoints[circle.Stroke.StylusPoints.Count / 2].ToPoint()) / 2;
circle.Centroid = new Point((circle.Stroke.StylusPoints[0].X + circle.Stroke.StylusPoints[circle.Stroke.StylusPoints.Count / 2].X) / 2,
(circle.Stroke.StylusPoints[0].Y + circle.Stroke.StylusPoints[circle.Stroke.StylusPoints.Count / 2].Y) / 2);
break;
}
}
2023-12-22 00:14:15 +08:00
if (Settings.Gesture.IsEnableTwoFingerZoom) {
try {
stroke.DrawingAttributes.Width *= md.Scale.X;
stroke.DrawingAttributes.Height *= md.Scale.Y;
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
}
}
2023-12-22 00:14:15 +08:00
} else {
if (Settings.Gesture.IsEnableTwoFingerZoom) {
foreach (Stroke stroke in inkCanvas.Strokes) {
stroke.Transform(m, false);
try {
stroke.DrawingAttributes.Width *= md.Scale.X;
stroke.DrawingAttributes.Height *= md.Scale.Y;
2023-12-22 00:14:15 +08:00
} catch { }
};
} else {
foreach (Stroke stroke in inkCanvas.Strokes) {
stroke.Transform(m, false);
};
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
foreach (Circle circle in circles) {
2023-04-05 16:05:03 +08:00
circle.R = GetDistance(circle.Stroke.StylusPoints[0].ToPoint(), circle.Stroke.StylusPoints[circle.Stroke.StylusPoints.Count / 2].ToPoint()) / 2;
2023-12-22 00:14:15 +08:00
circle.Centroid = new Point(
(circle.Stroke.StylusPoints[0].X + circle.Stroke.StylusPoints[circle.Stroke.StylusPoints.Count / 2].X) / 2,
(circle.Stroke.StylusPoints[0].Y + circle.Stroke.StylusPoints[circle.Stroke.StylusPoints.Count / 2].Y) / 2
);
};
2023-04-05 16:05:03 +08:00
}
}
}
#endregion Touch Events
#region PowerPoint
public static Microsoft.Office.Interop.PowerPoint.Application pptApplication = null;
public static Microsoft.Office.Interop.PowerPoint.Presentation presentation = null;
public static Microsoft.Office.Interop.PowerPoint.Slides slides = null;
public static Microsoft.Office.Interop.PowerPoint.Slide slide = null;
public static int slidescount = 0;
2023-12-22 00:14:15 +08:00
private void BtnCheckPPT_Click(object sender, RoutedEventArgs e) {
try {
2023-04-05 16:05:03 +08:00
pptApplication = (Microsoft.Office.Interop.PowerPoint.Application)Marshal.GetActiveObject("PowerPoint.Application");
//pptApplication.SlideShowWindows[1].View.Next();
2023-12-22 00:14:15 +08:00
if (pptApplication != null) {
2023-04-05 16:05:03 +08:00
//获得演示文稿对象
presentation = pptApplication.ActivePresentation;
pptApplication.SlideShowBegin += PptApplication_SlideShowBegin;
pptApplication.SlideShowNextSlide += PptApplication_SlideShowNextSlide;
pptApplication.SlideShowEnd += PptApplication_SlideShowEnd;
// 获得幻灯片对象集合
slides = presentation.Slides;
// 获得幻灯片的数量
slidescount = slides.Count;
memoryStreams = new MemoryStream[slidescount + 2];
// 获得当前选中的幻灯片
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
// 在普通视图下这种方式可以获得当前选中的幻灯片对象
// 然而在阅读模式下,这种方式会出现异常
slide = slides[pptApplication.ActiveWindow.Selection.SlideRange.SlideNumber];
2023-12-22 00:14:15 +08:00
} catch {
2023-04-05 16:05:03 +08:00
// 在阅读模式下出现异常时,通过下面的方式来获得当前选中的幻灯片对象
slide = pptApplication.SlideShowWindows[1].View.Slide;
}
}
if (pptApplication == null) throw new Exception();
//BtnCheckPPT.Visibility = Visibility.Collapsed;
StackPanelPPTControls.Visibility = Visibility.Visible;
2023-12-22 00:14:15 +08:00
} catch {
2023-04-05 16:05:03 +08:00
//BtnCheckPPT.Visibility = Visibility.Visible;
StackPanelPPTControls.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
BottomViewboxPPTSidesControl.Visibility = Visibility.Collapsed;
LeftSidePanelForPPTNavigation.Visibility = Visibility.Collapsed;
RightSidePanelForPPTNavigation.Visibility = Visibility.Collapsed;
2023-04-05 16:05:03 +08:00
MessageBox.Show("未找到幻灯片");
}
}
2023-12-22 00:14:15 +08:00
private void ToggleSwitchSupportWPS_Toggled(object sender, RoutedEventArgs e) {
2023-06-05 19:42:23 +08:00
if (!isLoaded) return;
Settings.PowerPointSettings.IsSupportWPS = ToggleSwitchSupportWPS.IsOn;
SaveSettingsToFile();
2023-04-05 16:05:03 +08:00
}
2023-06-05 19:42:23 +08:00
public static bool isWPSSupportOn => Settings.PowerPointSettings.IsSupportWPS;
2023-04-05 16:05:03 +08:00
public static bool IsShowingRestoreHiddenSlidesWindow = false;
2023-12-22 00:14:15 +08:00
private void TimerCheckPPT_Elapsed(object sender, ElapsedEventArgs e) {
2023-04-05 16:05:03 +08:00
if (IsShowingRestoreHiddenSlidesWindow) return;
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
Process[] processes = Process.GetProcessesByName("wpp");
2023-12-22 00:14:15 +08:00
if (processes.Length > 0 && !isWPSSupportOn) {
2023-04-05 16:05:03 +08:00
return;
}
//使用下方提前创建 PowerPoint 实例,将导致 PowerPoint 不再有启动界面
//pptApplication = (Microsoft.Office.Interop.PowerPoint.Application)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("91493441-5A91-11CF-8700-00AA0060263B")));
//new ComAwareEventInfo(typeof(EApplication_Event), "SlideShowBegin").AddEventHandler(pptApplication, new EApplication_SlideShowBeginEventHandler(this.PptApplication_SlideShowBegin));
//new ComAwareEventInfo(typeof(EApplication_Event), "SlideShowEnd").AddEventHandler(pptApplication, new EApplication_SlideShowEndEventHandler(this.PptApplication_SlideShowEnd));
//new ComAwareEventInfo(typeof(EApplication_Event), "SlideShowNextSlide").AddEventHandler(pptApplication, new EApplication_SlideShowNextSlideEventHandler(this.PptApplication_SlideShowNextSlide));
//ConfigHelper.Instance.IsInitApplicationSuccessful = true;
pptApplication = (Microsoft.Office.Interop.PowerPoint.Application)Marshal.GetActiveObject("PowerPoint.Application");
2023-12-22 00:14:15 +08:00
if (pptApplication != null) {
2023-04-05 16:05:03 +08:00
timerCheckPPT.Stop();
//获得演示文稿对象
presentation = pptApplication.ActivePresentation;
pptApplication.PresentationClose += PptApplication_PresentationClose;
pptApplication.SlideShowBegin += PptApplication_SlideShowBegin;
pptApplication.SlideShowNextSlide += PptApplication_SlideShowNextSlide;
pptApplication.SlideShowEnd += PptApplication_SlideShowEnd;
// 获得幻灯片对象集合
slides = presentation.Slides;
// 获得幻灯片的数量
slidescount = slides.Count;
memoryStreams = new MemoryStream[slidescount + 2];
// 获得当前选中的幻灯片
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
// 在普通视图下这种方式可以获得当前选中的幻灯片对象
// 然而在阅读模式下,这种方式会出现异常
slide = slides[pptApplication.ActiveWindow.Selection.SlideRange.SlideNumber];
2023-12-22 00:14:15 +08:00
} catch {
2023-04-05 16:05:03 +08:00
// 在阅读模式下出现异常时,通过下面的方式来获得当前选中的幻灯片对象
slide = pptApplication.SlideShowWindows[1].View.Slide;
}
}
if (pptApplication == null) return;
2023-04-05 16:05:03 +08:00
//BtnCheckPPT.Visibility = Visibility.Collapsed;
// 跳转到上次播放页
if (Settings.PowerPointSettings.IsNotifyPreviousPage)
2023-12-22 00:14:15 +08:00
Application.Current.Dispatcher.BeginInvoke(() => {
string defaultFolderPath;// = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Ink Canvas Strokes\Auto Saved\Presentations\";
try {
defaultFolderPath = $@"D:\Ink Canvas\Auto Saved - Presentations\";
} catch (IOException) {
defaultFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Ink Canvas Strokes\Auto Saved\Presentations\";
}
string folderPath = defaultFolderPath + presentation.Name + "_" + presentation.Slides.Count;
2023-12-22 00:14:15 +08:00
try {
if (File.Exists(folderPath + "/Position")) {
if (int.TryParse(File.ReadAllText(folderPath + "/Position"), out var page)) {
if (page <= 0) return;
new YesOrNoNotificationWindow($"上次播放到了第 {page} 页, 是否立即跳转", () => {
if (pptApplication.SlideShowWindows.Count >= 1) {
// 如果已经播放了的话, 跳转
presentation.SlideShowWindow.View.GotoSlide(page);
} else {
presentation.Windows[1].View.GotoSlide(page);
}
}).ShowDialog();
}
} else if (defaultFolderPath == $@"D:\Ink Canvas\Auto Saved - Presentations\") // 使用原版 InkCanvas 保存地点
{
defaultFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Ink Canvas Strokes\Auto Saved\Presentations\";
folderPath = defaultFolderPath + presentation.Name + "_" + presentation.Slides.Count;
try {
if (File.Exists(folderPath + "/Position")) {
if (int.TryParse(File.ReadAllText(folderPath + "/Position"), out var page)) {
if (page <= 0) return;
new YesOrNoNotificationWindow($"上次播放到了第 {page} 页, 是否立即跳转", () => {
if (pptApplication.SlideShowWindows.Count >= 1) {
// 如果已经播放了的话, 跳转
presentation.SlideShowWindow.View.GotoSlide(page);
} else {
presentation.Windows[1].View.GotoSlide(page);
}
}).ShowDialog();
}
}
2023-12-22 00:14:15 +08:00
} catch (Exception ex) {
LogHelper.WriteLogToFile(ex.ToString(), LogHelper.LogType.Error);
}
}
2023-12-22 00:14:15 +08:00
} catch (Exception ex) {
LogHelper.WriteLogToFile(ex.ToString(), LogHelper.LogType.Error);
2023-04-05 16:05:03 +08:00
}
}, DispatcherPriority.Normal);
2023-04-05 16:05:03 +08:00
//检查是否有隐藏幻灯片
2023-12-22 00:14:15 +08:00
if (Settings.PowerPointSettings.IsNotifyHiddenPage) {
bool isHaveHiddenSlide = false;
2023-12-22 00:14:15 +08:00
foreach (Slide slide in slides) {
if (slide.SlideShowTransition.Hidden == Microsoft.Office.Core.MsoTriState.msoTrue) {
isHaveHiddenSlide = true;
break;
}
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
Application.Current.Dispatcher.BeginInvoke(() => {
if (isHaveHiddenSlide && !IsShowingRestoreHiddenSlidesWindow) {
IsShowingRestoreHiddenSlidesWindow = true;
new YesOrNoNotificationWindow("检测到此演示文档中包含隐藏的幻灯片,是否取消隐藏?",
2023-12-22 00:14:15 +08:00
() => {
foreach (Slide slide in slides) {
if (slide.SlideShowTransition.Hidden ==
2023-12-22 00:14:15 +08:00
Microsoft.Office.Core.MsoTriState.msoTrue) {
slide.SlideShowTransition.Hidden =
Microsoft.Office.Core.MsoTriState.msoFalse;
}
}
}).ShowDialog();
}
2023-04-05 16:05:03 +08:00
BtnPPTSlideShow.Visibility = Visibility.Visible;
}, DispatcherPriority.Normal);
}
2023-04-05 16:05:03 +08:00
//如果检测到已经开始放映,则立即进入画板模式
2023-12-22 00:14:15 +08:00
if (pptApplication.SlideShowWindows.Count >= 1) {
2023-04-05 16:05:03 +08:00
PptApplication_SlideShowBegin(pptApplication.SlideShowWindows[1]);
}
2023-12-22 00:14:15 +08:00
} catch {
2023-04-05 16:05:03 +08:00
//StackPanelPPTControls.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
Application.Current.Dispatcher.Invoke(() => {
2023-04-05 16:05:03 +08:00
BtnPPTSlideShow.Visibility = Visibility.Collapsed;
});
timerCheckPPT.Start();
}
}
2023-12-22 00:14:15 +08:00
private void PptApplication_PresentationClose(Presentation Pres) {
2023-04-05 16:05:03 +08:00
pptApplication.PresentationClose -= PptApplication_PresentationClose;
pptApplication.SlideShowBegin -= PptApplication_SlideShowBegin;
pptApplication.SlideShowNextSlide -= PptApplication_SlideShowNextSlide;
pptApplication.SlideShowEnd -= PptApplication_SlideShowEnd;
pptApplication = null;
timerCheckPPT.Start();
2023-12-22 00:14:15 +08:00
Application.Current.Dispatcher.Invoke(() => {
2023-04-05 16:05:03 +08:00
BtnPPTSlideShow.Visibility = Visibility.Collapsed;
BtnPPTSlideShowEnd.Visibility = Visibility.Collapsed;
});
}
bool isPresentationHaveBlackSpace = false;
private string pptName = null;
//bool isButtonBackgroundTransparent = true; //此变量仅用于保存用于幻灯片放映时的优化
2023-12-22 00:14:15 +08:00
private void PptApplication_SlideShowBegin(SlideShowWindow Wn) {
if (Settings.Automation.IsAutoFoldInPPTSlideShow && !isFloatingBarFolded) {
FoldFloatingBar_MouseUp(null, null);
} else if (isFloatingBarFolded) {
UnFoldFloatingBar_MouseUp(null, null);
}
2023-04-05 16:05:03 +08:00
LogHelper.WriteLogToFile("PowerPoint Application Slide Show Begin", LogHelper.LogType.Event);
2023-12-22 00:14:15 +08:00
Application.Current.Dispatcher.Invoke(() => {
if (currentMode != 0) {
ImageBlackboard_MouseUp(null, null);
}
2023-04-05 16:05:03 +08:00
//调整颜色
double screenRatio = SystemParameters.PrimaryScreenWidth / SystemParameters.PrimaryScreenHeight;
2023-12-22 00:14:15 +08:00
if (Math.Abs(screenRatio - 16.0 / 9) <= -0.01) {
if (Wn.Presentation.PageSetup.SlideWidth / Wn.Presentation.PageSetup.SlideHeight < 1.65) {
2023-04-05 16:05:03 +08:00
isPresentationHaveBlackSpace = true;
//isButtonBackgroundTransparent = ToggleSwitchTransparentButtonBackground.IsOn;
2023-12-22 00:14:15 +08:00
if (BtnSwitchTheme.Content.ToString() == "深色") {
2023-04-05 16:05:03 +08:00
//Light
BtnExit.Foreground = Brushes.White;
2023-12-22 00:14:15 +08:00
//SymbolIconBtnColorBlackContent.Foreground = Brushes.White;
2023-04-05 16:05:03 +08:00
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Dark;
//BtnExit.Background = new SolidColorBrush(StringToColor("#AACCCCCC"));
2023-12-22 00:14:15 +08:00
} else {
//Dark
//BtnExit.Background = new SolidColorBrush(StringToColor("#AA555555"));
2023-04-05 16:05:03 +08:00
}
}
2023-12-22 00:14:15 +08:00
} else if (screenRatio == -256 / 135) {
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
lastDesktopInkColor = 1;
2023-04-05 16:05:03 +08:00
slidescount = Wn.Presentation.Slides.Count;
previousSlideID = 0;
memoryStreams = new MemoryStream[slidescount + 2];
pptName = Wn.Presentation.Name;
LogHelper.NewLog("Name: " + Wn.Presentation.Name);
LogHelper.NewLog("Slides Count: " + slidescount.ToString());
//检查是否有已有墨迹,并加载
2023-12-22 00:14:15 +08:00
if (Settings.PowerPointSettings.IsAutoSaveStrokesInPowerPoint) {
string defaultFolderPath;// = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Ink Canvas Strokes\Auto Saved\Presentations\";
try {
defaultFolderPath = $@"D:\Ink Canvas\Auto Saved - Presentations\";
} catch (IOException) {
defaultFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Ink Canvas Strokes\Auto Saved\Presentations\";
}
if (Directory.Exists(defaultFolderPath + Wn.Presentation.Name + "_" + Wn.Presentation.Slides.Count)) {
2023-04-05 16:05:03 +08:00
LogHelper.WriteLogToFile("Found saved strokes", LogHelper.LogType.Trace);
FileInfo[] files = new DirectoryInfo(defaultFolderPath + Wn.Presentation.Name + "_" + Wn.Presentation.Slides.Count).GetFiles();
int count = 0;
2023-12-22 00:14:15 +08:00
foreach (FileInfo file in files) {
if (file.Name != "Position") {
int i = -1;
try {
i = int.Parse(System.IO.Path.GetFileNameWithoutExtension(file.Name));
//var fs = new FileStream(file.FullName, FileMode.Open, FileAccess.Read);
//MemoryStream ms = new MemoryStream(File.ReadAllBytes(file.FullName));
//new StrokeCollection(fs).Save(ms);
//ms.Position = 0;
memoryStreams[i] = new MemoryStream(File.ReadAllBytes(file.FullName));
memoryStreams[i].Position = 0;
count++;
} catch (Exception ex) {
LogHelper.WriteLogToFile(string.Format("Failed to load strokes on Slide {0}\n{1}", i, ex.ToString()), LogHelper.LogType.Error);
}
2023-04-05 16:05:03 +08:00
}
}
LogHelper.WriteLogToFile(string.Format("Loaded {0} saved strokes", count.ToString()));
2023-12-22 00:14:15 +08:00
} else if (defaultFolderPath == $@"D:\Ink Canvas\Auto Saved - Presentations\") // 使用原版 InkCanvas 保存地点
{
defaultFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Ink Canvas Strokes\Auto Saved\Presentations\";
if (Directory.Exists(defaultFolderPath + Wn.Presentation.Name + "_" + Wn.Presentation.Slides.Count)) {
LogHelper.WriteLogToFile("Found saved strokes", LogHelper.LogType.Trace);
FileInfo[] files = new DirectoryInfo(defaultFolderPath + Wn.Presentation.Name + "_" + Wn.Presentation.Slides.Count).GetFiles();
int count = 0;
foreach (FileInfo file in files) {
if (file.Name != "Position") {
int i = -1;
try {
i = int.Parse(System.IO.Path.GetFileNameWithoutExtension(file.Name));
//var fs = new FileStream(file.FullName, FileMode.Open, FileAccess.Read);
//MemoryStream ms = new MemoryStream(File.ReadAllBytes(file.FullName));
//new StrokeCollection(fs).Save(ms);
//ms.Position = 0;
memoryStreams[i] = new MemoryStream(File.ReadAllBytes(file.FullName));
memoryStreams[i].Position = 0;
count++;
} catch (Exception ex) {
LogHelper.WriteLogToFile(string.Format("Failed to load strokes on Slide {0}\n{1}", i, ex.ToString()), LogHelper.LogType.Error);
}
}
}
LogHelper.WriteLogToFile(string.Format("Loaded {0} saved strokes", count.ToString()));
}
2023-04-05 16:05:03 +08:00
}
}
StackPanelPPTControls.Visibility = Visibility.Visible;
2023-12-22 00:14:15 +08:00
if (Settings.PowerPointSettings.IsShowBottomPPTNavigationPanel) {
AnimationHelper.ShowWithSlideFromBottomAndFade(BottomViewboxPPTSidesControl);
} else {
BottomViewboxPPTSidesControl.Visibility = Visibility.Collapsed;
}
if (Settings.PowerPointSettings.IsShowSidePPTNavigationPanel) {
AnimationHelper.ShowWithScaleFromLeft(LeftSidePanelForPPTNavigation);
AnimationHelper.ShowWithScaleFromRight(RightSidePanelForPPTNavigation);
} else {
LeftSidePanelForPPTNavigation.Visibility = Visibility.Collapsed;
RightSidePanelForPPTNavigation.Visibility = Visibility.Collapsed;
}
2023-04-05 16:05:03 +08:00
BtnPPTSlideShow.Visibility = Visibility.Collapsed;
BtnPPTSlideShowEnd.Visibility = Visibility.Visible;
ViewBoxStackPanelMain.Margin = new Thickness(10, 10, 10, 10);
2023-12-22 00:14:15 +08:00
if (Settings.Appearance.IsColorfulViewboxFloatingBar) {
ViewboxFloatingBar.Opacity = 0.8;
} else {
ViewboxFloatingBar.Opacity = 0.5;
}
if (Settings.PowerPointSettings.IsShowCanvasAtNewSlideShow && Main_Grid.Background == Brushes.Transparent) {
if (currentMode != 0) {
2023-04-05 16:05:03 +08:00
currentMode = 0;
GridBackgroundCover.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
AnimationHelper.HideWithSlideAndFade(BlackboardLeftSide);
AnimationHelper.HideWithSlideAndFade(BlackboardCenterSide);
AnimationHelper.HideWithSlideAndFade(BlackboardRightSide);
2023-04-05 16:05:03 +08:00
//SaveStrokes();
ClearStrokes(true);
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
if (BtnSwitchTheme.Content.ToString() == "浅色") {
2023-04-05 16:05:03 +08:00
BtnSwitch.Content = "黑板";
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
BtnSwitch.Content = "白板";
}
StackPanelPPTButtons.Visibility = Visibility.Visible;
}
BtnHideInkCanvas_Click(BtnHideInkCanvas, null);
}
//if (GridBackgroundCover.Visibility == Visibility.Visible)
//{
// SaveStrokes();
// currentMode = 0;
// GridBackgroundCover.Visibility = Visibility.Hidden;
//}
ClearStrokes(true);
2023-04-05 16:05:03 +08:00
BorderFloatingBarMainControls.Visibility = Visibility.Visible;
2023-12-22 00:14:15 +08:00
if (Settings.PowerPointSettings.IsShowCanvasAtNewSlideShow) {
BorderPenColorRed_MouseUp(BorderPenColorRed, null);
}
/*
2023-04-05 16:05:03 +08:00
BorderPenColorRed_MouseUp(BorderPenColorRed, null);
if (Settings.PowerPointSettings.IsShowCanvasAtNewSlideShow == false)
2023-04-05 16:05:03 +08:00
{
2023-12-22 00:14:15 +08:00
//BtnHideInkCanvas_Click(BtnHideInkCanvas, null);
CursorIcon_Click(null, null);
}*/
2023-04-05 16:05:03 +08:00
isEnteredSlideShowEndEvent = false;
PptNavigationTextBlock.Text = $"{Wn.View.CurrentShowPosition}/{Wn.Presentation.Slides.Count}";
LogHelper.NewLog("PowerPoint Slide Show Loading process complete");
2023-12-22 00:14:15 +08:00
new Thread(new ThreadStart(() => {
2023-04-05 16:05:03 +08:00
Thread.Sleep(100);
2023-12-22 00:14:15 +08:00
Application.Current.Dispatcher.Invoke(() => {
ViewboxFloatingBarMarginAnimation(60);
2023-04-05 16:05:03 +08:00
});
})).Start();
});
//previousSlideID = Wn.View.CurrentShowPosition;
////检查是否有已有墨迹,并加载当前页
//if (Settings.Automation.IsAutoSaveStrokesInPowerPoint)
//{
// try
// {
// if (memoryStreams[Wn.View.CurrentShowPosition].Length > 0)
// {
// Application.Current.Dispatcher.Invoke(() =>
// {
// inkCanvas.Strokes = new System.Windows.Ink.StrokeCollection(memoryStreams[Wn.View.CurrentShowPosition]);
// });
// }
// }
// catch (Exception ex)
// {
// LogHelper.WriteLogToFile(string.Format("Failed to load strokes for current slide (Slide {0})\n{1}", Wn.View.CurrentShowPosition, ex.ToString()), LogHelper.LogType.Error);
// }
//}
}
bool isEnteredSlideShowEndEvent = false; //防止重复调用本函数导致墨迹保存失效
2023-12-22 00:14:15 +08:00
private void PptApplication_SlideShowEnd(Presentation Pres) {
if (isFloatingBarFolded) UnFoldFloatingBar_MouseUp(null, null);
2023-04-05 16:05:03 +08:00
LogHelper.WriteLogToFile(string.Format("PowerPoint Slide Show End"), LogHelper.LogType.Event);
2023-12-22 00:14:15 +08:00
if (isEnteredSlideShowEndEvent) {
2023-04-05 16:05:03 +08:00
LogHelper.WriteLogToFile("Detected previous entrance, returning");
return;
}
isEnteredSlideShowEndEvent = true;
2023-12-22 00:14:15 +08:00
if (Settings.PowerPointSettings.IsAutoSaveStrokesInPowerPoint) {
string defaultFolderPath;// = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Ink Canvas Strokes\Auto Saved\Presentations\";
try {
defaultFolderPath = $@"D:\Ink Canvas\Auto Saved - Presentations\";
} catch (IOException) {
defaultFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Ink Canvas Strokes\Auto Saved\Presentations\";
}
2023-04-05 16:05:03 +08:00
string folderPath = defaultFolderPath + Pres.Name + "_" + Pres.Slides.Count;
2023-12-22 00:14:15 +08:00
if (!Directory.Exists(folderPath)) {
2023-04-05 16:05:03 +08:00
Directory.CreateDirectory(folderPath);
}
2023-12-22 00:14:15 +08:00
try {
File.WriteAllText(folderPath + "/Position", previousSlideID.ToString());
} catch { }
for (int i = 1; i <= Pres.Slides.Count; i++) {
if (memoryStreams[i] != null) {
try {
if (memoryStreams[i].Length > 8) {
2023-04-05 16:05:03 +08:00
byte[] srcBuf = new Byte[memoryStreams[i].Length];
//MessageBox.Show(memoryStreams[i].Length.ToString());
int byteLength = memoryStreams[i].Read(srcBuf, 0, srcBuf.Length);
File.WriteAllBytes(folderPath + @"\" + i.ToString("0000") + ".icstk", srcBuf);
LogHelper.WriteLogToFile(string.Format("Saved strokes for Slide {0}, size={1}, byteLength={2}", i.ToString(), memoryStreams[i].Length, byteLength));
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
File.Delete(folderPath + @"\" + i.ToString("0000") + ".icstk");
}
2023-12-22 00:14:15 +08:00
} catch (Exception ex) {
2023-04-05 16:05:03 +08:00
LogHelper.WriteLogToFile(string.Format("Failed to save strokes for Slide {0}\n{1}", i, ex.ToString()), LogHelper.LogType.Error);
File.Delete(folderPath + @"\" + i.ToString("0000") + ".icstk");
}
}
}
}
2023-12-22 00:14:15 +08:00
Application.Current.Dispatcher.Invoke(() => {
2023-04-05 16:05:03 +08:00
isPresentationHaveBlackSpace = false;
2023-12-22 00:14:15 +08:00
if (BtnSwitchTheme.Content.ToString() == "深色") {
2023-04-05 16:05:03 +08:00
//Light
BtnExit.Foreground = Brushes.Black;
2023-12-22 00:14:15 +08:00
//SymbolIconBtnColorBlackContent.Foreground = Brushes.White;
2023-04-05 16:05:03 +08:00
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Light;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
//Dark
}
BtnPPTSlideShow.Visibility = Visibility.Visible;
BtnPPTSlideShowEnd.Visibility = Visibility.Collapsed;
StackPanelPPTControls.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
BottomViewboxPPTSidesControl.Visibility = Visibility.Collapsed;
LeftSidePanelForPPTNavigation.Visibility = Visibility.Collapsed;
RightSidePanelForPPTNavigation.Visibility = Visibility.Collapsed;
2023-04-05 16:05:03 +08:00
ViewBoxStackPanelMain.Margin = new Thickness(10, 10, 10, 55);
2023-12-22 00:14:15 +08:00
if (currentMode != 0) {
2023-04-05 16:05:03 +08:00
currentMode = 0;
GridBackgroundCover.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
AnimationHelper.HideWithSlideAndFade(BlackboardLeftSide);
AnimationHelper.HideWithSlideAndFade(BlackboardCenterSide);
AnimationHelper.HideWithSlideAndFade(BlackboardRightSide);
2023-04-05 16:05:03 +08:00
//SaveStrokes();
ClearStrokes(true);
2023-04-05 16:05:03 +08:00
//RestoreStrokes(true);
2023-12-22 00:14:15 +08:00
if (BtnSwitchTheme.Content.ToString() == "浅色") {
2023-04-05 16:05:03 +08:00
BtnSwitch.Content = "黑板";
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
BtnSwitch.Content = "白板";
}
StackPanelPPTButtons.Visibility = Visibility.Visible;
}
//if (GridBackgroundCover.Visibility == Visibility.Visible)
//{
// SaveStrokes();
//}
2023-04-05 16:05:03 +08:00
ClearStrokes(true);
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
if (Main_Grid.Background != Brushes.Transparent) {
2023-04-05 16:05:03 +08:00
BtnHideInkCanvas_Click(BtnHideInkCanvas, null);
}
2023-12-22 00:14:15 +08:00
ViewboxFloatingBarMarginAnimation(100);
if (Settings.Appearance.IsColorfulViewboxFloatingBar) {
ViewboxFloatingBar.Opacity = 0.95;
} else {
ViewboxFloatingBar.Opacity = 1;
2023-04-05 16:05:03 +08:00
}
});
}
int previousSlideID = 0;
MemoryStream[] memoryStreams = new MemoryStream[50];
2023-12-22 00:14:15 +08:00
private void PptApplication_SlideShowNextSlide(SlideShowWindow Wn) {
2023-04-05 16:05:03 +08:00
LogHelper.WriteLogToFile(string.Format("PowerPoint Next Slide (Slide {0})", Wn.View.CurrentShowPosition), LogHelper.LogType.Event);
2023-12-22 00:14:15 +08:00
if (Wn.View.CurrentShowPosition != previousSlideID) {
Application.Current.Dispatcher.Invoke(() => {
2023-04-05 16:05:03 +08:00
MemoryStream ms = new MemoryStream();
inkCanvas.Strokes.Save(ms);
ms.Position = 0;
memoryStreams[previousSlideID] = ms;
if (inkCanvas.Strokes.Count > Settings.Automation.MinimumAutomationStrokeNumber && Settings.PowerPointSettings.IsAutoSaveScreenShotInPowerPoint && !_isPptClickingBtnTurned)
2023-04-05 16:05:03 +08:00
SaveScreenShot(true, Wn.Presentation.Name + "/" + Wn.View.CurrentShowPosition);
_isPptClickingBtnTurned = false;
ClearStrokes(true);
2023-04-22 11:06:42 +08:00
timeMachine.ClearStrokeHistory();
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
try {
if (memoryStreams[Wn.View.CurrentShowPosition] != null && memoryStreams[Wn.View.CurrentShowPosition].Length > 0) {
2023-04-22 11:06:42 +08:00
inkCanvas.Strokes.Add(new StrokeCollection(memoryStreams[Wn.View.CurrentShowPosition]));
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
PptNavigationTextBlock.Text = $"{Wn.View.CurrentShowPosition}/{Wn.Presentation.Slides.Count}";
});
previousSlideID = Wn.View.CurrentShowPosition;
}
}
private bool _isPptClickingBtnTurned = false;
2023-12-22 00:14:15 +08:00
private void BtnPPTSlidesUp_Click(object sender, RoutedEventArgs e) {
if (currentMode == 1) {
2023-04-05 16:05:03 +08:00
GridBackgroundCover.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
AnimationHelper.HideWithSlideAndFade(BlackboardLeftSide);
AnimationHelper.HideWithSlideAndFade(BlackboardCenterSide);
AnimationHelper.HideWithSlideAndFade(BlackboardRightSide);
2023-04-05 16:05:03 +08:00
currentMode = 0;
}
_isPptClickingBtnTurned = true;
2023-12-22 00:14:15 +08:00
if (inkCanvas.Strokes.Count > Settings.Automation.MinimumAutomationStrokeNumber &&
Settings.PowerPointSettings.IsAutoSaveScreenShotInPowerPoint)
2023-04-05 16:05:03 +08:00
SaveScreenShot(true, pptApplication.SlideShowWindows[1].Presentation.Name + "/" + pptApplication.SlideShowWindows[1].View.CurrentShowPosition);
2023-12-22 00:14:15 +08:00
try {
new Thread(new ThreadStart(() => {
try {
pptApplication.SlideShowWindows[1].Activate();
} catch { }
try {
pptApplication.SlideShowWindows[1].View.Previous();
} catch { } // Without this catch{}, app will crash when click the pre-page button in the fir page in some special env.
2023-04-05 16:05:03 +08:00
})).Start();
2023-12-22 00:14:15 +08:00
} catch {
2023-04-05 16:05:03 +08:00
StackPanelPPTControls.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
BottomViewboxPPTSidesControl.Visibility = Visibility.Collapsed;
LeftSidePanelForPPTNavigation.Visibility = Visibility.Collapsed;
RightSidePanelForPPTNavigation.Visibility = Visibility.Collapsed;
2023-04-05 16:05:03 +08:00
}
}
2023-12-22 00:14:15 +08:00
private void BtnPPTSlidesDown_Click(object sender, RoutedEventArgs e) {
if (currentMode == 1) {
2023-04-05 16:05:03 +08:00
GridBackgroundCover.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
AnimationHelper.HideWithSlideAndFade(BlackboardLeftSide);
AnimationHelper.HideWithSlideAndFade(BlackboardCenterSide);
AnimationHelper.HideWithSlideAndFade(BlackboardRightSide);
2023-04-05 16:05:03 +08:00
currentMode = 0;
}
_isPptClickingBtnTurned = true;
if (inkCanvas.Strokes.Count > Settings.Automation.MinimumAutomationStrokeNumber &&
Settings.PowerPointSettings.IsAutoSaveScreenShotInPowerPoint)
2023-04-05 16:05:03 +08:00
SaveScreenShot(true, pptApplication.SlideShowWindows[1].Presentation.Name + "/" + pptApplication.SlideShowWindows[1].View.CurrentShowPosition);
2023-12-22 00:14:15 +08:00
try {
new Thread(new ThreadStart(() => {
try {
pptApplication.SlideShowWindows[1].Activate();
} catch { }
try {
pptApplication.SlideShowWindows[1].View.Next();
} catch { }
2023-04-05 16:05:03 +08:00
})).Start();
2023-12-22 00:14:15 +08:00
} catch {
2023-04-05 16:05:03 +08:00
StackPanelPPTControls.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
BottomViewboxPPTSidesControl.Visibility = Visibility.Collapsed;
LeftSidePanelForPPTNavigation.Visibility = Visibility.Collapsed;
RightSidePanelForPPTNavigation.Visibility = Visibility.Collapsed;
2023-04-05 16:05:03 +08:00
}
}
2023-12-22 00:14:15 +08:00
private async void PPTNavigationBtn_Click(object sender, MouseButtonEventArgs e) {
if (lastBorderMouseDownObject != sender) return;
2023-04-05 16:05:03 +08:00
Main_Grid.Background = new SolidColorBrush(StringToColor("#01FFFFFF"));
2023-12-22 00:14:15 +08:00
CursorIcon_Click(null, null);
try {
pptApplication.SlideShowWindows[1].SlideNavigation.Visible = true;
} catch { }
2023-04-05 16:05:03 +08:00
// 控制居中
2023-12-22 00:14:15 +08:00
if (!isFloatingBarFolded) {
await Task.Delay(100);
ViewboxFloatingBarMarginAnimation(60);
2023-04-05 16:05:03 +08:00
}
}
2023-12-22 00:14:15 +08:00
private void BtnPPTSlideShow_Click(object sender, RoutedEventArgs e) {
new Thread(new ThreadStart(() => {
try {
2023-04-05 16:05:03 +08:00
presentation.SlideShowSettings.Run();
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
})).Start();
}
2023-12-22 00:14:15 +08:00
private void BtnPPTSlideShowEnd_Click(object sender, RoutedEventArgs e) {
Application.Current.Dispatcher.Invoke(() => {
try {
2023-04-05 16:05:03 +08:00
MemoryStream ms = new MemoryStream();
inkCanvas.Strokes.Save(ms);
ms.Position = 0;
memoryStreams[pptApplication.SlideShowWindows[1].View.CurrentShowPosition] = ms;
2023-04-22 11:06:42 +08:00
timeMachine.ClearStrokeHistory();
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
});
2023-12-22 00:14:15 +08:00
new Thread(new ThreadStart(() => {
try {
2023-04-05 16:05:03 +08:00
pptApplication.SlideShowWindows[1].View.Exit();
2023-12-22 00:14:15 +08:00
} catch { }
})).Start();
HideSubPanels("cursor");
new Thread(new ThreadStart(() => {
Thread.Sleep(50);
ViewboxFloatingBarMarginAnimation(100);
2023-04-05 16:05:03 +08:00
})).Start();
}
#endregion
#region Settings
#region Behavior
2023-12-22 00:14:15 +08:00
private void ToggleSwitchIsAutoUpdate_Toggled(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
if (!isLoaded) return;
2023-12-22 00:14:15 +08:00
Settings.Startup.IsAutoUpdate = ToggleSwitchIsAutoUpdate.IsOn;
ToggleSwitchIsAutoUpdateWithSilence.Visibility = ToggleSwitchIsAutoUpdate.IsOn ? Visibility.Visible : Visibility.Collapsed;
SaveSettingsToFile();
}
private void ToggleSwitchIsAutoUpdateWithSilence_Toggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
Settings.Startup.IsAutoUpdateWithSilence = ToggleSwitchIsAutoUpdateWithSilence.IsOn;
AutoUpdateTimePeriodBlock.Visibility = Settings.Startup.IsAutoUpdateWithSilence ? Visibility.Visible : Visibility.Collapsed;
SaveSettingsToFile();
}
private void ToggleSwitchIsAutoUpdateWithProxy_Toggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
Settings.Startup.IsAutoUpdateWithProxy = ToggleSwitchIsAutoUpdateWithProxy.IsOn;
AutoUpdateWithProxy_Title.Visibility = Settings.Startup.IsAutoUpdateWithProxy ? Visibility.Visible : Visibility.Collapsed;
SaveSettingsToFile();
}
private void AutoUpdateProxyTextBox_TextChanged(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
Settings.Startup.AutoUpdateProxy = AutoUpdateProxyTextBox.Text;
SaveSettingsToFile();
}
private void BtnResetAutoUpdateProxyToGHProxy_Click(object sender, RoutedEventArgs e) {
AutoUpdateProxyTextBox.Text = "https://mirror.ghproxy.com/";
}
private async void BtnCheckAutoUpdateProxyReturnedData_Click(object sender, RoutedEventArgs e) {
string ProxyReturnedData = await AutoUpdateHelper.GetRemoteVersion(Settings.Startup.AutoUpdateProxy + "https://raw.githubusercontent.com/ChangSakura/Ink-Canvas/main/AutomaticUpdateVersionControl.txt");
ShowNotification(ProxyReturnedData);
}
private void AutoUpdateWithSilenceStartTimeComboBox_SelectionChanged(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
Settings.Startup.AutoUpdateWithSilenceStartTime = (string)AutoUpdateWithSilenceStartTimeComboBox.SelectedItem;
SaveSettingsToFile();
}
private void AutoUpdateWithSilenceEndTimeComboBox_SelectionChanged(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
Settings.Startup.AutoUpdateWithSilenceEndTime = (string)AutoUpdateWithSilenceEndTimeComboBox.SelectedItem;
SaveSettingsToFile();
}
private void ToggleSwitchRunAtStartup_Toggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
if (ToggleSwitchRunAtStartup.IsOn) {
2023-04-05 16:05:03 +08:00
StartAutomaticallyDel("InkCanvas");
2023-12-22 00:14:15 +08:00
StartAutomaticallyCreate("Ink Canvas Annotation");
} else {
StartAutomaticallyDel("InkCanvas");
StartAutomaticallyDel("Ink Canvas Annotation");
2023-04-05 16:05:03 +08:00
}
}
2023-12-22 00:14:15 +08:00
private void ToggleSwitchSupportPowerPoint_Toggled(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
if (!isLoaded) return;
Settings.PowerPointSettings.PowerPointSupport = ToggleSwitchSupportPowerPoint.IsOn;
2023-04-05 16:05:03 +08:00
SaveSettingsToFile();
2023-12-22 00:14:15 +08:00
if (Settings.PowerPointSettings.PowerPointSupport) {
2023-04-05 16:05:03 +08:00
timerCheckPPT.Start();
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
timerCheckPPT.Stop();
}
}
2023-12-22 00:14:15 +08:00
private void ToggleSwitchShowCanvasAtNewSlideShow_Toggled(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
if (!isLoaded) return;
Settings.PowerPointSettings.IsShowCanvasAtNewSlideShow = ToggleSwitchShowCanvasAtNewSlideShow.IsOn;
2023-04-05 16:05:03 +08:00
SaveSettingsToFile();
}
#endregion
#region Startup
2023-12-22 00:14:15 +08:00
/*
2023-04-05 16:05:03 +08:00
private void ToggleSwitchAutoHideCanvas_Toggled(object sender, RoutedEventArgs e)
{
if (!isLoaded) return;
Settings.Startup.IsAutoHideCanvas = ToggleSwitchAutoHideCanvas.IsOn;
SaveSettingsToFile();
}
private void ToggleSwitchAutoEnterModeFinger_Toggled(object sender, RoutedEventArgs e)
{
if (!isLoaded) return;
Settings.Startup.IsAutoEnterModeFinger = ToggleSwitchAutoEnterModeFinger.IsOn;
SaveSettingsToFile();
}
2023-12-22 00:14:15 +08:00
*/
private void ToggleSwitchEnableNibMode_Toggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
if (sender == ToggleSwitchEnableNibMode) {
ToggleSwitchBoardEnableNibMode.IsOn = ToggleSwitchEnableNibMode.IsOn;
} else {
ToggleSwitchEnableNibMode.IsOn = ToggleSwitchBoardEnableNibMode.IsOn;
}
Settings.Startup.IsEnableNibMode = ToggleSwitchEnableNibMode.IsOn;
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
if (Settings.Startup.IsEnableNibMode) {
//ComboBoxEraserSize.SelectedIndex = 1;
BoundsWidth = Settings.Advanced.NibModeBoundsWidth;
} else {
//ComboBoxEraserSize.SelectedIndex = 3;
BoundsWidth = Settings.Advanced.FingerModeBoundsWidth;
}
SaveSettingsToFile();
}
2023-04-05 16:05:03 +08:00
#endregion
#region Appearance
2023-12-22 00:14:15 +08:00
private void ToggleSwitchEnableDisPlayNibModeToggle_Toggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
Settings.Appearance.IsEnableDisPlayNibModeToggler = ToggleSwitchEnableDisPlayNibModeToggle.IsOn;
SaveSettingsToFile();
LoadSettings(false);
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void ToggleSwitchIsColorfulViewboxFloatingBar_Toggled(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
if (!isLoaded) return;
2023-12-22 00:14:15 +08:00
Settings.Appearance.IsColorfulViewboxFloatingBar = ToggleSwitchColorfulViewboxFloatingBar.IsOn;
2023-04-05 16:05:03 +08:00
SaveSettingsToFile();
2023-12-22 00:14:15 +08:00
LoadSettings(false);
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void ToggleSwitchEnableViewboxFloatingBarScaleTransform_Toggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
Settings.Appearance.EnableViewboxFloatingBarScaleTransform = ToggleSwitchEnableViewboxFloatingBarScaleTransform.IsOn;
2023-04-05 16:05:03 +08:00
SaveSettingsToFile();
2023-12-22 00:14:15 +08:00
LoadSettings(false);
}
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
private void ToggleSwitchEnableViewboxBlackBoardScaleTransform_Toggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
Settings.Appearance.EnableViewboxBlackBoardScaleTransform = ToggleSwitchEnableViewboxBlackBoardScaleTransform.IsOn;
SaveSettingsToFile();
LoadSettings(false);
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void ToggleSwitchShowButtonPPTNavigation_OnToggled(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
if (!isLoaded) return;
Settings.PowerPointSettings.IsShowPPTNavigation = ToggleSwitchShowButtonPPTNavigation.IsOn;
2023-12-22 00:14:15 +08:00
PptNavigationBtn.Visibility = Settings.PowerPointSettings.IsShowPPTNavigation ? Visibility.Visible : Visibility.Collapsed;
2023-04-05 16:05:03 +08:00
SaveSettingsToFile();
2023-12-22 00:14:15 +08:00
}
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
private void ToggleSwitchShowBottomPPTNavigationPanel_OnToggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
Settings.PowerPointSettings.IsShowBottomPPTNavigationPanel = ToggleSwitchShowBottomPPTNavigationPanel.IsOn;
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) {
BottomViewboxPPTSidesControl.Visibility = Settings.PowerPointSettings.IsShowBottomPPTNavigationPanel ? Visibility.Visible : Visibility.Collapsed;
}
SaveSettingsToFile();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void ToggleSwitchShowSidePPTNavigationPanel_OnToggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
Settings.PowerPointSettings.IsShowSidePPTNavigationPanel = ToggleSwitchShowSidePPTNavigationPanel.IsOn;
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) {
LeftSidePanelForPPTNavigation.Visibility = Settings.PowerPointSettings.IsShowSidePPTNavigationPanel ? Visibility.Visible : Visibility.Collapsed;
RightSidePanelForPPTNavigation.Visibility = Settings.PowerPointSettings.IsShowSidePPTNavigationPanel ? Visibility.Visible : Visibility.Collapsed;
}
SaveSettingsToFile();
}
/*
private void ComboBoxTheme_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (!isLoaded) return;
Settings.Appearance.Theme = ComboBoxTheme.SelectedIndex;
SystemEvents_UserPreferenceChanged(null, null);
SaveSettingsToFile();
}
2023-04-05 16:05:03 +08:00
private void ToggleSwitchShowButtonHideControl_Toggled(object sender, RoutedEventArgs e)
{
if (!isLoaded) return;
Settings.Appearance.IsShowHideControlButton = ToggleSwitchShowButtonHideControl.IsOn;
SaveSettingsToFile();
if (ToggleSwitchShowButtonHideControl.IsOn)
{
BtnHideControl.Visibility = Visibility.Visible;
}
else
{
BtnHideControl.Visibility = Visibility.Collapsed;
}
}
private void ToggleSwitchShowButtonLRSwitch_Toggled(object sender, RoutedEventArgs e)
{
if (!isLoaded) return;
Settings.Appearance.IsShowLRSwitchButton = ToggleSwitchShowButtonLRSwitch.IsOn;
SaveSettingsToFile();
if (ToggleSwitchShowButtonLRSwitch.IsOn)
{
BtnSwitchSide.Visibility = Visibility.Visible;
}
else
{
BtnSwitchSide.Visibility = Visibility.Collapsed;
}
}
2023-12-22 00:14:15 +08:00
*/
/*
2023-04-05 16:05:03 +08:00
private void ToggleSwitchShowButtonModeFinger_Toggled(object sender, RoutedEventArgs e)
{
if (!isLoaded) return;
Settings.Appearance.IsShowModeFingerToggleSwitch = ToggleSwitchShowButtonModeFinger.IsOn;
SaveSettingsToFile();
if (ToggleSwitchShowButtonModeFinger.IsOn)
{
StackPanelModeFinger.Visibility = Visibility.Visible;
}
else
{
StackPanelModeFinger.Visibility = Visibility.Collapsed;
}
}
2023-12-22 00:14:15 +08:00
*/
/*
2023-04-05 16:05:03 +08:00
private void ToggleSwitchTransparentButtonBackground_Toggled(object sender, RoutedEventArgs e)
{
if (!isLoaded) return;
Settings.Appearance.IsTransparentButtonBackground = ToggleSwitchTransparentButtonBackground.IsOn;
if (Settings.Appearance.IsTransparentButtonBackground)
{
BtnExit.Background = new SolidColorBrush(StringToColor("#7F909090"));
}
else
{
if (BtnSwitchTheme.Content.ToString() == "深色")
{
//Light
BtnExit.Background = new SolidColorBrush(StringToColor("#FFCCCCCC"));
}
else
{
//Dark
BtnExit.Background = new SolidColorBrush(StringToColor("#FF555555"));
}
}
SaveSettingsToFile();
}
2023-12-22 00:14:15 +08:00
*/
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
private void ToggleSwitchShowCursor_Toggled(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
if (!isLoaded) return;
Settings.Canvas.IsShowCursor = ToggleSwitchShowCursor.IsOn;
inkCanvas_EditingModeChanged(inkCanvas, null);
SaveSettingsToFile();
}
#endregion
#region Canvas
2023-12-22 00:14:15 +08:00
private void ComboBoxPenStyle_SelectionChanged(object sender, SelectionChangedEventArgs e) {
2023-04-05 16:05:03 +08:00
if (!isLoaded) return;
2023-12-22 00:14:15 +08:00
if (sender == ComboBoxPenStyle) {
Settings.Canvas.InkStyle = ComboBoxPenStyle.SelectedIndex;
BoardComboBoxPenStyle.SelectedIndex = ComboBoxPenStyle.SelectedIndex;
} else {
Settings.Canvas.InkStyle = BoardComboBoxPenStyle.SelectedIndex;
ComboBoxPenStyle.SelectedIndex = BoardComboBoxPenStyle.SelectedIndex;
}
2023-04-05 16:05:03 +08:00
SaveSettingsToFile();
}
2023-12-22 00:14:15 +08:00
private void ComboBoxEraserSize_SelectionChanged(object sender, SelectionChangedEventArgs e) {
2023-04-05 16:05:03 +08:00
if (!isLoaded) return;
Settings.Canvas.EraserSize = ComboBoxEraserSize.SelectedIndex;
SaveSettingsToFile();
}
2023-12-22 00:14:15 +08:00
/*
2023-07-15 15:28:10 +08:00
private void ComboBoxEraserType_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (!isLoaded) return;
Settings.Canvas.EraserType = ComboBoxEraserType.SelectedIndex;
SaveSettingsToFile();
}
2023-12-22 00:14:15 +08:00
*/
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
private void InkWidthSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) {
2023-04-05 16:05:03 +08:00
if (!isLoaded) return;
2023-12-22 00:14:15 +08:00
if (sender == BoardInkWidthSlider) InkWidthSlider.Value = ((Slider)sender).Value;
if (sender == InkWidthSlider) BoardInkWidthSlider.Value = ((Slider)sender).Value;
2023-04-05 16:05:03 +08:00
drawingAttributes.Height = ((Slider)sender).Value / 2;
drawingAttributes.Width = ((Slider)sender).Value / 2;
Settings.Canvas.InkWidth = ((Slider)sender).Value / 2;
SaveSettingsToFile();
}
2023-12-22 00:14:15 +08:00
private void ComboBoxHyperbolaAsymptoteOption_SelectionChanged(object sender, SelectionChangedEventArgs e) {
2023-05-08 20:37:55 +08:00
if (!isLoaded) return;
Settings.Canvas.HyperbolaAsymptoteOption = (OptionalOperation)ComboBoxHyperbolaAsymptoteOption.SelectedIndex;
2023-05-08 20:37:55 +08:00
SaveSettingsToFile();
}
2023-04-05 16:05:03 +08:00
#endregion
#region Automation
2023-12-22 00:14:15 +08:00
private void StartOrStoptimerCheckAutoFold() {
if (Settings.Automation.IsEnableAutoFold) {
timerCheckAutoFold.Start();
} else {
timerCheckAutoFold.Stop();
2023-04-05 16:05:03 +08:00
}
}
2023-12-22 00:14:15 +08:00
private void ToggleSwitchAutoFoldInEasiNote_Toggled(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
if (!isLoaded) return;
2023-12-22 00:14:15 +08:00
Settings.Automation.IsAutoFoldInEasiNote = ToggleSwitchAutoFoldInEasiNote.IsOn;
2023-04-05 16:05:03 +08:00
SaveSettingsToFile();
2023-12-22 00:14:15 +08:00
StartOrStoptimerCheckAutoFold();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void ToggleSwitchAutoFoldInEasiCamera_Toggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
2023-12-22 00:14:15 +08:00
Settings.Automation.IsAutoFoldInEasiCamera = ToggleSwitchAutoFoldInEasiCamera.IsOn;
SaveSettingsToFile();
2023-12-22 00:14:15 +08:00
StartOrStoptimerCheckAutoFold();
}
2023-12-22 00:14:15 +08:00
private void ToggleSwitchAutoFoldInEasiNote3C_Toggled(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
if (!isLoaded) return;
2023-12-22 00:14:15 +08:00
Settings.Automation.IsAutoFoldInEasiNote3C = ToggleSwitchAutoFoldInEasiNote3C.IsOn;
2023-04-05 16:05:03 +08:00
SaveSettingsToFile();
2023-12-22 00:14:15 +08:00
StartOrStoptimerCheckAutoFold();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void ToggleSwitchAutoFoldInSeewoPincoTeacher_Toggled(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
if (!isLoaded) return;
2023-12-22 00:14:15 +08:00
Settings.Automation.IsAutoFoldInSeewoPincoTeacher = ToggleSwitchAutoFoldInSeewoPincoTeacher.IsOn;
2023-04-05 16:05:03 +08:00
SaveSettingsToFile();
2023-12-22 00:14:15 +08:00
StartOrStoptimerCheckAutoFold();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void ToggleSwitchAutoFoldInHiteTouchPro_Toggled(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
if (!isLoaded) return;
2023-12-22 00:14:15 +08:00
Settings.Automation.IsAutoFoldInHiteTouchPro = ToggleSwitchAutoFoldInHiteTouchPro.IsOn;
2023-04-05 16:05:03 +08:00
SaveSettingsToFile();
2023-12-22 00:14:15 +08:00
StartOrStoptimerCheckAutoFold();
}
2023-12-22 00:14:15 +08:00
private void ToggleSwitchAutoFoldInHiteCamera_Toggled(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
if (!isLoaded) return;
2023-12-22 00:14:15 +08:00
Settings.Automation.IsAutoFoldInHiteCamera = ToggleSwitchAutoFoldInHiteCamera.IsOn;
2023-04-05 16:05:03 +08:00
SaveSettingsToFile();
2023-12-22 00:14:15 +08:00
StartOrStoptimerCheckAutoFold();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void ToggleSwitchAutoFoldInWxBoardMain_Toggled(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
if (!isLoaded) return;
2023-12-22 00:14:15 +08:00
Settings.Automation.IsAutoFoldInWxBoardMain = ToggleSwitchAutoFoldInWxBoardMain.IsOn;
2023-04-05 16:05:03 +08:00
SaveSettingsToFile();
2023-12-22 00:14:15 +08:00
StartOrStoptimerCheckAutoFold();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
/*
private void ToggleSwitchAutoFoldInZySmartBoard_Toggled(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
if (!isLoaded) return;
2023-12-22 00:14:15 +08:00
Settings.Automation.IsAutoFoldInZySmartBoard = ToggleSwitchAutoFoldInZySmartBoard.IsOn;
SaveSettingsToFile();
2023-12-22 00:14:15 +08:00
StartOrStoptimerCheckAutoFold();
}
2023-12-22 00:14:15 +08:00
*/
private void ToggleSwitchAutoFoldInOldZyBoard_Toggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
2023-12-22 00:14:15 +08:00
Settings.Automation.IsAutoFoldInOldZyBoard = ToggleSwitchAutoFoldInOldZyBoard.IsOn;
SaveSettingsToFile();
2023-12-22 00:14:15 +08:00
StartOrStoptimerCheckAutoFold();
2023-05-08 19:58:14 +08:00
}
2023-12-22 00:14:15 +08:00
private void ToggleSwitchAutoFoldInMSWhiteboard_Toggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
2023-12-22 00:14:15 +08:00
Settings.Automation.IsAutoFoldInMSWhiteboard = ToggleSwitchAutoFoldInMSWhiteboard.IsOn;
SaveSettingsToFile();
2023-12-22 00:14:15 +08:00
StartOrStoptimerCheckAutoFold();
}
2023-05-08 19:58:14 +08:00
2023-12-22 00:14:15 +08:00
private void ToggleSwitchAutoFoldInPPTSlideShow_Toggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
Settings.Automation.IsAutoFoldInPPTSlideShow = ToggleSwitchAutoFoldInPPTSlideShow.IsOn;
SaveSettingsToFile();
StartOrStoptimerCheckAutoFold();
}
private void ToggleSwitchAutoKillPptService_Toggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
Settings.Automation.IsAutoKillPptService = ToggleSwitchAutoKillPptService.IsOn;
SaveSettingsToFile();
if (Settings.Automation.IsAutoKillEasiNote || Settings.Automation.IsAutoKillPptService) {
timerKillProcess.Start();
} else {
timerKillProcess.Stop();
}
}
private void ToggleSwitchAutoKillEasiNote_Toggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
Settings.Automation.IsAutoKillEasiNote = ToggleSwitchAutoKillEasiNote.IsOn;
SaveSettingsToFile();
if (Settings.Automation.IsAutoKillEasiNote || Settings.Automation.IsAutoKillPptService) {
timerKillProcess.Start();
} else {
timerKillProcess.Stop();
}
}
private void ToggleSwitchSaveScreenshotsInDateFolders_Toggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
Settings.Automation.IsSaveScreenshotsInDateFolders = ToggleSwitchSaveScreenshotsInDateFolders.IsOn;
SaveSettingsToFile();
}
private void ToggleSwitchAutoSaveStrokesAtScreenshot_Toggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
Settings.Automation.IsAutoSaveStrokesAtScreenshot = ToggleSwitchAutoSaveStrokesAtScreenshot.IsOn;
ToggleSwitchAutoSaveStrokesAtClear.Header =
ToggleSwitchAutoSaveStrokesAtScreenshot.IsOn ? "清屏时自动截图并保存墨迹" : "清屏时自动截图";
SaveSettingsToFile();
}
private void ToggleSwitchAutoSaveStrokesAtClear_Toggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
Settings.Automation.IsAutoSaveStrokesAtClear = ToggleSwitchAutoSaveStrokesAtClear.IsOn;
SaveSettingsToFile();
}
/*
private void ToggleSwitchExitingWritingMode_Toggled(object sender, RoutedEventArgs e)
{
if (!isLoaded) return;
Settings.Automation.IsAutoClearWhenExitingWritingMode = ToggleSwitchClearExitingWritingMode.IsOn;
SaveSettingsToFile();
}
*/
private void ToggleSwitchHideStrokeWhenSelecting_Toggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
Settings.Canvas.HideStrokeWhenSelecting = ToggleSwitchHideStrokeWhenSelecting.IsOn;
SaveSettingsToFile();
}
/*
private void ToggleSwitchUsingWhiteboard_Toggled(object sender, RoutedEventArgs e)
{
if (!isLoaded) return;
Settings.Canvas.UsingWhiteboard = ToggleSwitchUsingWhiteboard.IsOn;
if (!Settings.Canvas.UsingWhiteboard)
{
BtnSwitchTheme.Content = "浅色";
}
else
{
BtnSwitchTheme.Content = "深色";
}
BtnSwitchTheme_Click(sender, e);
SaveSettingsToFile();
}
*/
private void ToggleSwitchAutoSaveStrokesInPowerPoint_Toggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
Settings.PowerPointSettings.IsAutoSaveStrokesInPowerPoint = ToggleSwitchAutoSaveStrokesInPowerPoint.IsOn;
SaveSettingsToFile();
}
private void ToggleSwitchNotifyPreviousPage_Toggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
Settings.PowerPointSettings.IsNotifyPreviousPage = ToggleSwitchNotifyPreviousPage.IsOn;
SaveSettingsToFile();
}
private void ToggleSwitchNotifyHiddenPage_Toggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
Settings.PowerPointSettings.IsNotifyHiddenPage = ToggleSwitchNotifyHiddenPage.IsOn;
SaveSettingsToFile();
}
/*
private void ToggleSwitchNoStrokeClearInPowerPoint_Toggled(object sender, RoutedEventArgs e)
{
if (!isLoaded) return;
Settings.PowerPointSettings.IsNoClearStrokeOnSelectWhenInPowerPoint = ToggleSwitchNoStrokeClearInPowerPoint.IsOn;
SaveSettingsToFile();
}
2023-05-08 19:58:14 +08:00
private void ToggleSwitchShowStrokeOnSelectInPowerPoint_Toggled(object sender, RoutedEventArgs e)
{
if (!isLoaded) return;
Settings.PowerPointSettings.IsShowStrokeOnSelectInPowerPoint = ToggleSwitchShowStrokeOnSelectInPowerPoint.IsOn;
2023-04-05 16:05:03 +08:00
SaveSettingsToFile();
}
2023-12-22 00:14:15 +08:00
*/
private void SideControlMinimumAutomationSlider_ValueChanged(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
Settings.Automation.MinimumAutomationStrokeNumber = (int)SideControlMinimumAutomationSlider.Value;
SaveSettingsToFile();
}
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
private void ToggleSwitchAutoSaveScreenShotInPowerPoint_Toggled(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
if (!isLoaded) return;
Settings.PowerPointSettings.IsAutoSaveScreenShotInPowerPoint = ToggleSwitchAutoSaveScreenShotInPowerPoint.IsOn;
2023-04-05 16:05:03 +08:00
SaveSettingsToFile();
}
#endregion
#region Gesture
2023-12-22 00:14:15 +08:00
private void ToggleSwitchEnableFingerGestureSlideShowControl_Toggled(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
if (!isLoaded) return;
Settings.PowerPointSettings.IsEnableFingerGestureSlideShowControl = ToggleSwitchEnableFingerGestureSlideShowControl.IsOn;
2023-04-05 16:05:03 +08:00
SaveSettingsToFile();
}
2023-12-22 00:14:15 +08:00
private void ToggleSwitchAutoSwitchTwoFingerGesture_Toggled(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
if (!isLoaded) return;
2023-12-22 00:14:15 +08:00
Settings.Gesture.AutoSwitchTwoFingerGesture = ToggleSwitchAutoSwitchTwoFingerGesture.IsOn;
2023-04-05 16:05:03 +08:00
SaveSettingsToFile();
}
2023-12-22 00:14:15 +08:00
private void ToggleSwitchEnableTwoFingerZoom_Toggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
2023-12-22 00:14:15 +08:00
if (sender == ToggleSwitchEnableTwoFingerZoom) {
BoardToggleSwitchEnableTwoFingerZoom.IsOn = ToggleSwitchEnableTwoFingerZoom.IsOn;
} else {
ToggleSwitchEnableTwoFingerZoom.IsOn = BoardToggleSwitchEnableTwoFingerZoom.IsOn;
}
Settings.Gesture.IsEnableTwoFingerZoom = ToggleSwitchEnableTwoFingerZoom.IsOn;
CheckEnableTwoFingerGestureBtnColorPrompt();
SaveSettingsToFile();
}
2023-12-22 00:14:15 +08:00
private void ToggleSwitchEnableTwoFingerTranslate_Toggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
if (sender == ToggleSwitchEnableTwoFingerTranslate) {
BoardToggleSwitchEnableTwoFingerTranslate.IsOn = ToggleSwitchEnableTwoFingerTranslate.IsOn;
} else {
ToggleSwitchEnableTwoFingerTranslate.IsOn = BoardToggleSwitchEnableTwoFingerTranslate.IsOn;
}
Settings.Gesture.IsEnableTwoFingerTranslate = ToggleSwitchEnableTwoFingerTranslate.IsOn;
2023-12-22 00:14:15 +08:00
CheckEnableTwoFingerGestureBtnColorPrompt();
SaveSettingsToFile();
}
2023-12-22 00:14:15 +08:00
private void ToggleSwitchEnableTwoFingerRotation_Toggled(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
if (!isLoaded) return;
2023-12-22 00:14:15 +08:00
if (sender == ToggleSwitchEnableTwoFingerRotation) {
BoardToggleSwitchEnableTwoFingerRotation.IsOn = ToggleSwitchEnableTwoFingerRotation.IsOn;
} else {
ToggleSwitchEnableTwoFingerRotation.IsOn = BoardToggleSwitchEnableTwoFingerRotation.IsOn;
}
2023-04-05 16:05:03 +08:00
Settings.Gesture.IsEnableTwoFingerRotation = ToggleSwitchEnableTwoFingerRotation.IsOn;
Settings.Gesture.IsEnableTwoFingerRotationOnSelection = ToggleSwitchEnableTwoFingerRotationOnSelection.IsOn;
2023-12-22 00:14:15 +08:00
CheckEnableTwoFingerGestureBtnColorPrompt();
2023-04-05 16:05:03 +08:00
SaveSettingsToFile();
}
2023-12-22 00:14:15 +08:00
private void ToggleSwitchEnableTwoFingerGestureInPresentationMode_Toggled(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
if (!isLoaded) return;
Settings.PowerPointSettings.IsEnableTwoFingerGestureInPresentationMode = ToggleSwitchEnableTwoFingerGestureInPresentationMode.IsOn;
2023-04-05 16:05:03 +08:00
SaveSettingsToFile();
}
#endregion
#region Reset
2023-12-22 00:14:15 +08:00
public static void SetSettingsToRecommendation() {
//bool IsAutoKillPptService = Settings.Automation.IsAutoKillPptService;
//bool IsAutoKillEasiNote = Settings.Automation.IsAutoKillEasiNote;
2023-04-05 16:05:03 +08:00
Settings = new Settings();
2023-12-22 00:14:15 +08:00
Settings.Advanced.IsSpecialScreen = true;
Settings.Advanced.IsQuadIR = false;
Settings.Advanced.TouchMultiplier = 0.3;
Settings.Advanced.NibModeBoundsWidth = 5;
Settings.Advanced.FingerModeBoundsWidth = 20;
Settings.Advanced.EraserBindTouchMultiplier = true;
Settings.Advanced.IsLogEnabled = true;
Settings.Advanced.IsSecondConfimeWhenShutdownApp = false;
Settings.Appearance.IsEnableDisPlayNibModeToggler = false;
Settings.Appearance.IsColorfulViewboxFloatingBar = false;
Settings.Appearance.EnableViewboxFloatingBarScaleTransform = true;
Settings.Appearance.EnableViewboxBlackBoardScaleTransform = false;
Settings.Appearance.IsTransparentButtonBackground = true;
Settings.Appearance.IsShowExitButton = true;
Settings.Appearance.IsShowEraserButton = true;
Settings.Appearance.IsShowHideControlButton = false;
Settings.Appearance.IsShowLRSwitchButton = false;
Settings.Appearance.IsShowModeFingerToggleSwitch = true;
Settings.Appearance.Theme = 0;
Settings.Automation.IsAutoFoldInEasiNote = true;
Settings.Automation.IsAutoFoldInEasiCamera = true;
Settings.Automation.IsAutoFoldInEasiNote3C = false;
Settings.Automation.IsAutoFoldInSeewoPincoTeacher = false;
Settings.Automation.IsAutoFoldInHiteTouchPro = false;
Settings.Automation.IsAutoFoldInHiteCamera = false;
Settings.Automation.IsAutoFoldInWxBoardMain = false;
//Settings.Automation.IsAutoFoldInZySmartBoard = false;
Settings.Automation.IsAutoFoldInOldZyBoard = false;
Settings.Automation.IsAutoFoldInMSWhiteboard = false;
Settings.Automation.IsAutoFoldInPPTSlideShow = false;
Settings.Automation.IsAutoKillPptService = false;// IsAutoKillPptService;
Settings.Automation.IsAutoKillEasiNote = false;// IsAutoKillEasiNote;
Settings.Automation.IsSaveScreenshotsInDateFolders = false;
Settings.Automation.IsAutoSaveStrokesAtScreenshot = false;
Settings.Automation.IsAutoSaveStrokesAtClear = true;
Settings.Automation.IsAutoClearWhenExitingWritingMode = false;
Settings.Automation.MinimumAutomationStrokeNumber = 0;
Settings.PowerPointSettings.IsShowPPTNavigation = true;
Settings.PowerPointSettings.IsShowBottomPPTNavigationPanel = false;
Settings.PowerPointSettings.IsShowSidePPTNavigationPanel = true;
Settings.PowerPointSettings.PowerPointSupport = true;
Settings.PowerPointSettings.IsShowCanvasAtNewSlideShow = false;
Settings.PowerPointSettings.IsNoClearStrokeOnSelectWhenInPowerPoint = true;
Settings.PowerPointSettings.IsShowStrokeOnSelectInPowerPoint = false;
Settings.PowerPointSettings.IsAutoSaveStrokesInPowerPoint = true;
Settings.PowerPointSettings.IsAutoSaveScreenShotInPowerPoint = true;
Settings.PowerPointSettings.IsNotifyPreviousPage = false;
Settings.PowerPointSettings.IsNotifyHiddenPage = false;
Settings.PowerPointSettings.IsEnableTwoFingerGestureInPresentationMode = false;
Settings.PowerPointSettings.IsEnableFingerGestureSlideShowControl = false;
Settings.PowerPointSettings.IsSupportWPS = true;
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
Settings.Canvas.InkWidth = 2.5;
Settings.Canvas.IsShowCursor = false;
Settings.Canvas.InkStyle = 0;
Settings.Canvas.EraserSize = 1;
Settings.Canvas.EraserType = 0;
Settings.Canvas.HideStrokeWhenSelecting = false;
Settings.Canvas.UsingWhiteboard = false;
Settings.Canvas.HyperbolaAsymptoteOption = 0;
Settings.Gesture.AutoSwitchTwoFingerGesture = true;
Settings.Gesture.IsEnableTwoFingerTranslate = true;
Settings.Gesture.IsEnableTwoFingerZoom = false;
Settings.Gesture.IsEnableTwoFingerRotation = false;
Settings.Gesture.IsEnableTwoFingerRotationOnSelection = false;
Settings.InkToShape.IsInkToShapeEnabled = true;
Settings.Startup.IsEnableNibMode = false;
Settings.Startup.IsAutoUpdate = true;
Settings.Startup.IsAutoUpdateWithSilence = true;
Settings.Startup.IsAutoUpdateWithProxy = true;
Settings.Startup.AutoUpdateProxy = "https://mirror.ghproxy.com/";
Settings.Startup.AutoUpdateWithSilenceStartTime = "18:20";
Settings.Startup.AutoUpdateWithSilenceEndTime = "07:40";
}
private void BtnResetToSuggestion_Click(object sender, RoutedEventArgs e) {
try {
2023-04-05 16:05:03 +08:00
isLoaded = false;
SetSettingsToRecommendation();
SaveSettingsToFile();
LoadSettings(false);
isLoaded = true;
2023-12-22 00:14:15 +08:00
ToggleSwitchRunAtStartup.IsOn = true;
} catch { }
ShowNotification("设置已重置为默认推荐设置~");
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private async void SpecialVersionResetToSuggestion_Click() {
await Task.Delay(1000);
try {
2023-04-05 16:05:03 +08:00
isLoaded = false;
2023-12-22 00:14:15 +08:00
SetSettingsToRecommendation();
SaveSettingsToFile();
2023-04-05 16:05:03 +08:00
LoadSettings(false);
isLoaded = true;
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
}
#endregion
#region Ink To Shape
2023-12-22 00:14:15 +08:00
private void ToggleSwitchEnableInkToShape_Toggled(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
if (!isLoaded) return;
Settings.InkToShape.IsInkToShapeEnabled = ToggleSwitchEnableInkToShape.IsOn;
SaveSettingsToFile();
}
#endregion
#region Advanced
2023-05-08 19:58:14 +08:00
2023-12-22 00:14:15 +08:00
private void ToggleSwitchIsSpecialScreen_OnToggled(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
if (!isLoaded) return;
Settings.Advanced.IsSpecialScreen = ToggleSwitchIsSpecialScreen.IsOn;
TouchMultiplierSlider.Visibility = ToggleSwitchIsSpecialScreen.IsOn ? Visibility.Visible : Visibility.Collapsed;
SaveSettingsToFile();
}
2023-05-08 19:58:14 +08:00
2023-12-22 00:14:15 +08:00
private void TouchMultiplierSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) {
if (!isLoaded) return;
Settings.Advanced.TouchMultiplier = e.NewValue;
SaveSettingsToFile();
}
2023-12-22 00:14:15 +08:00
private void BorderCalculateMultiplier_TouchDown(object sender, TouchEventArgs e) {
2023-09-25 12:11:21 +08:00
var args = e.GetTouchPoint(null).Bounds;
double value;
if (!Settings.Advanced.IsQuadIR) value = args.Width;
else value = Math.Sqrt(args.Width * args.Height); //四边红外
TextBlockShowCalculatedMultiplier.Text = (5 / (value * 1.1)).ToString();
}
2023-12-22 00:14:15 +08:00
private void ToggleSwitchEraserBindTouchMultiplier_Toggled(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
if (!isLoaded) return;
2023-05-08 19:58:14 +08:00
Settings.Advanced.EraserBindTouchMultiplier = ToggleSwitchEraserBindTouchMultiplier.IsOn;
2023-04-05 16:05:03 +08:00
SaveSettingsToFile();
}
2023-12-22 00:14:15 +08:00
private void NibModeBoundsWidthSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) {
if (!isLoaded) return;
Settings.Advanced.NibModeBoundsWidth = (int)e.NewValue;
if (Settings.Startup.IsEnableNibMode) {
BoundsWidth = Settings.Advanced.NibModeBoundsWidth;
} else {
BoundsWidth = Settings.Advanced.FingerModeBoundsWidth;
}
SaveSettingsToFile();
}
private void FingerModeBoundsWidthSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) {
if (!isLoaded) return;
Settings.Advanced.FingerModeBoundsWidth = (int)e.NewValue;
if (Settings.Startup.IsEnableNibMode) {
BoundsWidth = Settings.Advanced.NibModeBoundsWidth;
} else {
BoundsWidth = Settings.Advanced.FingerModeBoundsWidth;
}
SaveSettingsToFile();
}
private void ToggleSwitchIsQuadIR_Toggled(object sender, RoutedEventArgs e) {
2023-09-25 12:11:21 +08:00
if (!isLoaded) return;
Settings.Advanced.IsQuadIR = ToggleSwitchIsQuadIR.IsOn;
SaveSettingsToFile();
}
2023-12-22 00:14:15 +08:00
private void ToggleSwitchIsLogEnabled_Toggled(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
if (!isLoaded) return;
Settings.Advanced.IsLogEnabled = ToggleSwitchIsLogEnabled.IsOn;
SaveSettingsToFile();
}
2023-12-22 00:14:15 +08:00
private void ToggleSwitchIsSecondConfimeWhenShutdownApp_Toggled(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
Settings.Advanced.IsSecondConfimeWhenShutdownApp = ToggleSwitchIsSecondConfimeWhenShutdownApp.IsOn;
SaveSettingsToFile();
}
2023-04-05 16:05:03 +08:00
#endregion
2023-12-22 00:14:15 +08:00
public static void SaveSettingsToFile() {
2023-04-05 16:05:03 +08:00
string text = JsonConvert.SerializeObject(Settings, Formatting.Indented);
2023-12-22 00:14:15 +08:00
try {
2023-05-17 22:26:09 +08:00
File.WriteAllText(App.RootPath + settingsFileName, text);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void SCManipulationBoundaryFeedback(object sender, ManipulationBoundaryFeedbackEventArgs e) {
2023-04-05 16:05:03 +08:00
e.Handled = true;
}
2023-12-22 00:14:15 +08:00
private void HyperlinkSourceToPresentRepository_Click(object sender, RoutedEventArgs e) {
Process.Start("https://github.com/ChangSakura/Ink-Canvas");
HideSubPanels();
}
private void HyperlinkSourceToOringinalRepository_Click(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
Process.Start("https://github.com/WXRIW/Ink-Canvas");
2023-12-22 00:14:15 +08:00
HideSubPanels();
2023-04-05 16:05:03 +08:00
}
#endregion
#region Left Side Panel
#region Other Controls
2023-12-22 00:14:15 +08:00
private void BtnFingerDragMode_Click(object sender, RoutedEventArgs e) {
if (isSingleFingerDragMode) {
2023-04-05 16:05:03 +08:00
isSingleFingerDragMode = false;
BtnFingerDragMode.Content = "单指\n拖动";
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
isSingleFingerDragMode = true;
BtnFingerDragMode.Content = "多指\n拖动";
}
}
2023-12-22 00:14:15 +08:00
private void BtnUndo_Click(object sender, RoutedEventArgs e) {
if (inkCanvas.GetSelectedStrokes().Count != 0) {
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
inkCanvas.Select(new StrokeCollection());
}
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.CodeInput;
var item = timeMachine.Undo();
2023-12-22 00:14:15 +08:00
if (item.CommitType == TimeMachineHistoryType.UserInput) {
if (!item.StrokeHasBeenCleared) {
foreach (var strokes in item.CurrentStroke) {
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
2023-12-22 00:14:15 +08:00
} else {
foreach (var strokes in item.CurrentStroke) {
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
}
2023-12-22 00:14:15 +08:00
} else if (item.CommitType == TimeMachineHistoryType.ShapeRecognition) {
if (item.StrokeHasBeenCleared) {
2023-12-22 00:14:15 +08:00
foreach (var strokes in item.CurrentStroke) {
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
2023-12-22 00:14:15 +08:00
foreach (var strokes in item.ReplacedStroke) {
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
2023-12-22 00:14:15 +08:00
} else {
foreach (var strokes in item.CurrentStroke) {
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
2023-12-22 00:14:15 +08:00
foreach (var strokes in item.ReplacedStroke) {
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
}
2023-12-22 00:14:15 +08:00
} else if (item.CommitType == TimeMachineHistoryType.Rotate) {
if (item.StrokeHasBeenCleared) {
2023-05-07 17:54:41 +08:00
2023-12-22 00:14:15 +08:00
foreach (var strokes in item.CurrentStroke) {
2023-05-07 17:54:41 +08:00
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
2023-12-22 00:14:15 +08:00
foreach (var strokes in item.ReplacedStroke) {
2023-05-07 17:54:41 +08:00
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
2023-12-22 00:14:15 +08:00
} else {
foreach (var strokes in item.CurrentStroke) {
2023-05-07 17:54:41 +08:00
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
2023-12-22 00:14:15 +08:00
foreach (var strokes in item.ReplacedStroke) {
2023-05-07 17:54:41 +08:00
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
}
2023-12-22 00:14:15 +08:00
} else if (item.CommitType == TimeMachineHistoryType.Clear) {
if (!item.StrokeHasBeenCleared) {
if (item.CurrentStroke != null) {
foreach (var currentStroke in item.CurrentStroke) {
if (!inkCanvas.Strokes.Contains(currentStroke)) inkCanvas.Strokes.Add(currentStroke);
}
}
2023-12-22 00:14:15 +08:00
if (item.ReplacedStroke != null) {
foreach (var replacedStroke in item.ReplacedStroke) {
if (inkCanvas.Strokes.Contains(replacedStroke)) inkCanvas.Strokes.Remove(replacedStroke);
}
}
2023-12-22 00:14:15 +08:00
} else {
if (item.ReplacedStroke != null) {
foreach (var replacedStroke in item.ReplacedStroke) {
if (!inkCanvas.Strokes.Contains(replacedStroke)) inkCanvas.Strokes.Add(replacedStroke);
}
}
2023-12-22 00:14:15 +08:00
if (item.CurrentStroke != null) {
foreach (var currentStroke in item.CurrentStroke) {
if (inkCanvas.Strokes.Contains(currentStroke)) inkCanvas.Strokes.Remove(currentStroke);
}
}
}
}
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.UserInput;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BtnRedo_Click(object sender, RoutedEventArgs e) {
if (inkCanvas.GetSelectedStrokes().Count != 0) {
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
inkCanvas.Select(new StrokeCollection());
}
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.CodeInput;
var item = timeMachine.Redo();
2023-12-22 00:14:15 +08:00
if (item.CommitType == TimeMachineHistoryType.UserInput) {
if (!item.StrokeHasBeenCleared) {
foreach (var strokes in item.CurrentStroke) {
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
2023-12-22 00:14:15 +08:00
} else {
foreach (var strokes in item.CurrentStroke) {
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
}
2023-12-22 00:14:15 +08:00
} else if (item.CommitType == TimeMachineHistoryType.ShapeRecognition) {
if (item.StrokeHasBeenCleared) {
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
foreach (var strokes in item.CurrentStroke) {
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
2023-12-22 00:14:15 +08:00
foreach (var strokes in item.ReplacedStroke) {
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
2023-12-22 00:14:15 +08:00
} else {
foreach (var strokes in item.CurrentStroke) {
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
2023-12-22 00:14:15 +08:00
foreach (var strokes in item.ReplacedStroke) {
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
}
2023-12-22 00:14:15 +08:00
} else if (item.CommitType == TimeMachineHistoryType.Rotate) {
if (item.StrokeHasBeenCleared) {
2023-05-07 17:54:41 +08:00
2023-12-22 00:14:15 +08:00
foreach (var strokes in item.CurrentStroke) {
2023-05-07 17:54:41 +08:00
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
2023-12-22 00:14:15 +08:00
foreach (var strokes in item.ReplacedStroke) {
2023-05-07 17:54:41 +08:00
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
2023-12-22 00:14:15 +08:00
} else {
foreach (var strokes in item.CurrentStroke) {
2023-05-07 17:54:41 +08:00
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
2023-12-22 00:14:15 +08:00
foreach (var strokes in item.ReplacedStroke) {
2023-05-07 17:54:41 +08:00
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
}
2023-12-22 00:14:15 +08:00
} else if (item.CommitType == TimeMachineHistoryType.Clear) {
if (!item.StrokeHasBeenCleared) {
if (item.CurrentStroke != null) {
foreach (var currentStroke in item.CurrentStroke) {
if (!inkCanvas.Strokes.Contains(currentStroke)) inkCanvas.Strokes.Add(currentStroke);
}
}
2023-12-22 00:14:15 +08:00
if (item.ReplacedStroke != null) {
foreach (var replacedStroke in item.ReplacedStroke) {
if (inkCanvas.Strokes.Contains(replacedStroke)) inkCanvas.Strokes.Remove(replacedStroke);
}
}
2023-12-22 00:14:15 +08:00
} else {
if (item.ReplacedStroke != null) {
foreach (var replacedStroke in item.ReplacedStroke) {
if (!inkCanvas.Strokes.Contains(replacedStroke)) inkCanvas.Strokes.Add(replacedStroke);
}
}
2023-12-22 00:14:15 +08:00
if (item.CurrentStroke != null) {
foreach (var currentStroke in item.CurrentStroke) {
if (inkCanvas.Strokes.Contains(currentStroke)) inkCanvas.Strokes.Remove(currentStroke);
}
}
}
}
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.UserInput;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void Btn_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e) {
2023-04-05 16:05:03 +08:00
if (!isLoaded) return;
2023-12-22 00:14:15 +08:00
try {
if (((Button)sender).IsEnabled) {
2023-04-05 16:05:03 +08:00
((UIElement)((Button)sender).Content).Opacity = 1;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
((UIElement)((Button)sender).Content).Opacity = 0.25;
}
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
}
#endregion Other Controls
#endregion Left Side Panel
#region Selection Gestures
#region Floating Control
object lastBorderMouseDownObject;
2023-12-22 00:14:15 +08:00
private void Border_MouseDown(object sender, MouseButtonEventArgs e) {
2023-04-05 16:05:03 +08:00
lastBorderMouseDownObject = sender;
}
bool isStrokeSelectionCloneOn = false;
2023-12-22 00:14:15 +08:00
private void BorderStrokeSelectionClone_MouseUp(object sender, MouseButtonEventArgs e) {
2023-04-05 16:05:03 +08:00
if (lastBorderMouseDownObject != sender) return;
2023-12-22 00:14:15 +08:00
if (isStrokeSelectionCloneOn) {
2023-04-05 16:05:03 +08:00
BorderStrokeSelectionClone.Background = Brushes.Transparent;
isStrokeSelectionCloneOn = false;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
BorderStrokeSelectionClone.Background = new SolidColorBrush(StringToColor("#FF1ED760"));
isStrokeSelectionCloneOn = true;
}
}
2023-12-22 00:14:15 +08:00
private void BorderStrokeSelectionCloneToNewBoard_MouseUp(object sender, MouseButtonEventArgs e) {
2023-04-05 16:05:03 +08:00
if (lastBorderMouseDownObject != sender) return;
var strokes = inkCanvas.GetSelectedStrokes();
inkCanvas.Select(new StrokeCollection());
strokes = strokes.Clone();
BtnWhiteBoardAdd_Click(null, null);
inkCanvas.Strokes.Add(strokes);
}
2023-12-22 00:14:15 +08:00
private void BorderStrokeSelectionDelete_MouseUp(object sender, MouseButtonEventArgs e) {
if (lastBorderMouseDownObject == sender) {
2023-04-05 16:05:03 +08:00
SymbolIconDelete_MouseUp(sender, e);
}
}
2023-12-22 00:14:15 +08:00
private void GridPenWidthDecrease_MouseUp(object sender, MouseButtonEventArgs e) {
2023-04-05 16:05:03 +08:00
if (lastBorderMouseDownObject != sender) return;
2023-12-22 00:14:15 +08:00
foreach (Stroke stroke in inkCanvas.GetSelectedStrokes()) {
2023-04-05 16:05:03 +08:00
stroke.DrawingAttributes.Width *= 0.8;
stroke.DrawingAttributes.Height *= 0.8;
}
}
2023-12-22 00:14:15 +08:00
private void GridPenWidthIncrease_MouseUp(object sender, MouseButtonEventArgs e) {
2023-04-05 16:05:03 +08:00
if (lastBorderMouseDownObject != sender) return;
2023-12-22 00:14:15 +08:00
foreach (Stroke stroke in inkCanvas.GetSelectedStrokes()) {
2023-04-05 16:05:03 +08:00
stroke.DrawingAttributes.Width *= 1.25;
stroke.DrawingAttributes.Height *= 1.25;
}
}
2023-12-22 00:14:15 +08:00
private void GridPenWidthRestore_MouseUp(object sender, MouseButtonEventArgs e) {
2023-04-05 16:05:03 +08:00
if (lastBorderMouseDownObject != sender) return;
2023-12-22 00:14:15 +08:00
foreach (Stroke stroke in inkCanvas.GetSelectedStrokes()) {
2023-04-05 16:05:03 +08:00
stroke.DrawingAttributes.Width = inkCanvas.DefaultDrawingAttributes.Width;
stroke.DrawingAttributes.Height = inkCanvas.DefaultDrawingAttributes.Height;
}
}
2023-12-22 00:14:15 +08:00
private void ImageFlipHorizontal_MouseUp(object sender, MouseButtonEventArgs e) {
2023-04-05 16:05:03 +08:00
if (lastBorderMouseDownObject != sender) return;
Matrix m = new Matrix();
// Find center of element and then transform to get current location of center
FrameworkElement fe = e.Source as FrameworkElement;
Point center = new Point(fe.ActualWidth / 2, fe.ActualHeight / 2);
center = new Point(inkCanvas.GetSelectionBounds().Left + inkCanvas.GetSelectionBounds().Width / 2,
inkCanvas.GetSelectionBounds().Top + inkCanvas.GetSelectionBounds().Height / 2);
center = m.Transform(center); // 转换为矩阵缩放和旋转的中心点
// Update matrix to reflect translation/rotation
m.ScaleAt(-1, 1, center.X, center.Y); // 缩放
2023-05-07 17:54:41 +08:00
StrokeCollection targetStrokes = inkCanvas.GetSelectedStrokes();
StrokeCollection resultStrokes = targetStrokes.Clone();
2023-12-22 00:14:15 +08:00
foreach (Stroke stroke in resultStrokes) {
2023-04-05 16:05:03 +08:00
stroke.Transform(m, false);
}
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.Rotate;
inkCanvas.Strokes.Replace(targetStrokes, resultStrokes);
_currentCommitType = CommitReason.UserInput;
isProgramChangeStrokeSelection = true;
inkCanvas.Select(resultStrokes);
isProgramChangeStrokeSelection = false;
2023-04-05 16:05:03 +08:00
//updateBorderStrokeSelectionControlLocation();
}
2023-12-22 00:14:15 +08:00
private void ImageFlipVertical_MouseUp(object sender, MouseButtonEventArgs e) {
2023-04-05 16:05:03 +08:00
if (lastBorderMouseDownObject != sender) return;
Matrix m = new Matrix();
// Find center of element and then transform to get current location of center
FrameworkElement fe = e.Source as FrameworkElement;
Point center = new Point(fe.ActualWidth / 2, fe.ActualHeight / 2);
center = new Point(inkCanvas.GetSelectionBounds().Left + inkCanvas.GetSelectionBounds().Width / 2,
inkCanvas.GetSelectionBounds().Top + inkCanvas.GetSelectionBounds().Height / 2);
center = m.Transform(center); // 转换为矩阵缩放和旋转的中心点
// Update matrix to reflect translation/rotation
m.ScaleAt(1, -1, center.X, center.Y); // 缩放
2023-05-07 17:54:41 +08:00
StrokeCollection targetStrokes = inkCanvas.GetSelectedStrokes();
StrokeCollection resultStrokes = targetStrokes.Clone();
2023-12-22 00:14:15 +08:00
foreach (Stroke stroke in resultStrokes) {
2023-04-05 16:05:03 +08:00
stroke.Transform(m, false);
}
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.Rotate;
inkCanvas.Strokes.Replace(targetStrokes, resultStrokes);
_currentCommitType = CommitReason.UserInput;
isProgramChangeStrokeSelection = true;
inkCanvas.Select(resultStrokes);
isProgramChangeStrokeSelection = false;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void ImageRotate45_MouseUp(object sender, MouseButtonEventArgs e) {
2023-04-05 16:05:03 +08:00
if (lastBorderMouseDownObject != sender) return;
Matrix m = new Matrix();
// Find center of element and then transform to get current location of center
FrameworkElement fe = e.Source as FrameworkElement;
Point center = new Point(fe.ActualWidth / 2, fe.ActualHeight / 2);
center = new Point(inkCanvas.GetSelectionBounds().Left + inkCanvas.GetSelectionBounds().Width / 2,
inkCanvas.GetSelectionBounds().Top + inkCanvas.GetSelectionBounds().Height / 2);
center = m.Transform(center); // 转换为矩阵缩放和旋转的中心点
// Update matrix to reflect translation/rotation
m.RotateAt(45, center.X, center.Y); // 旋转
2023-05-07 17:54:41 +08:00
StrokeCollection targetStrokes = inkCanvas.GetSelectedStrokes();
StrokeCollection resultStrokes = targetStrokes.Clone();
2023-12-22 00:14:15 +08:00
foreach (Stroke stroke in resultStrokes) {
2023-04-05 16:05:03 +08:00
stroke.Transform(m, false);
}
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.Rotate;
inkCanvas.Strokes.Replace(targetStrokes, resultStrokes);
_currentCommitType = CommitReason.UserInput;
isProgramChangeStrokeSelection = true;
inkCanvas.Select(resultStrokes);
isProgramChangeStrokeSelection = false;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void ImageRotate90_MouseUp(object sender, MouseButtonEventArgs e) {
2023-04-05 16:05:03 +08:00
if (lastBorderMouseDownObject != sender) return;
Matrix m = new Matrix();
// Find center of element and then transform to get current location of center
FrameworkElement fe = e.Source as FrameworkElement;
Point center = new Point(fe.ActualWidth / 2, fe.ActualHeight / 2);
center = new Point(inkCanvas.GetSelectionBounds().Left + inkCanvas.GetSelectionBounds().Width / 2,
inkCanvas.GetSelectionBounds().Top + inkCanvas.GetSelectionBounds().Height / 2);
center = m.Transform(center); // 转换为矩阵缩放和旋转的中心点
// Update matrix to reflect translation/rotation
m.RotateAt(90, center.X, center.Y); // 旋转
2023-05-07 17:54:41 +08:00
StrokeCollection targetStrokes = inkCanvas.GetSelectedStrokes();
StrokeCollection resultStrokes = targetStrokes.Clone();
2023-12-22 00:14:15 +08:00
foreach (Stroke stroke in resultStrokes) {
2023-04-05 16:05:03 +08:00
stroke.Transform(m, false);
}
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.Rotate;
inkCanvas.Strokes.Replace(targetStrokes, resultStrokes);
_currentCommitType = CommitReason.UserInput;
isProgramChangeStrokeSelection = true;
inkCanvas.Select(resultStrokes);
isProgramChangeStrokeSelection = false;
2023-04-05 16:05:03 +08:00
}
#endregion
bool isGridInkCanvasSelectionCoverMouseDown = false;
StrokeCollection StrokesSelectionClone = new StrokeCollection();
2023-12-22 00:14:15 +08:00
private void GridInkCanvasSelectionCover_MouseDown(object sender, MouseButtonEventArgs e) {
2023-04-05 16:05:03 +08:00
isGridInkCanvasSelectionCoverMouseDown = true;
}
2023-12-22 00:14:15 +08:00
private void GridInkCanvasSelectionCover_MouseUp(object sender, MouseButtonEventArgs e) {
if (isGridInkCanvasSelectionCoverMouseDown) {
2023-04-05 16:05:03 +08:00
isGridInkCanvasSelectionCoverMouseDown = false;
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
}
}
2023-12-22 00:14:15 +08:00
private void BtnSelect_Click(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
drawingShapeMode = 0;
inkCanvas.IsManipulationEnabled = false;
2023-12-22 00:14:15 +08:00
if (inkCanvas.EditingMode == InkCanvasEditingMode.Select) {
if (inkCanvas.GetSelectedStrokes().Count == inkCanvas.Strokes.Count) {
/*
//inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
2023-04-16 12:36:11 +08:00
inkCanvas.IsManipulationEnabled = true;
2023-12-22 00:14:15 +08:00
PenIcon_Click(null, null);
*/
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
inkCanvas.EditingMode = InkCanvasEditingMode.Select;
} else {
2023-04-16 12:36:11 +08:00
inkCanvas.Select(inkCanvas.Strokes);
}
2023-12-22 00:14:15 +08:00
} else {
2023-04-16 12:36:11 +08:00
inkCanvas.EditingMode = InkCanvasEditingMode.Select;
}
2023-04-05 16:05:03 +08:00
}
double BorderStrokeSelectionControlWidth = 490.0;
double BorderStrokeSelectionControlHeight = 80.0;
bool isProgramChangeStrokeSelection = false;
2023-12-22 00:14:15 +08:00
private void inkCanvas_SelectionChanged(object sender, EventArgs e) {
2023-04-05 16:05:03 +08:00
if (isProgramChangeStrokeSelection) return;
2023-12-22 00:14:15 +08:00
if (inkCanvas.GetSelectedStrokes().Count == 0) {
2023-04-05 16:05:03 +08:00
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
GridInkCanvasSelectionCover.Visibility = Visibility.Visible;
BorderStrokeSelectionClone.Background = Brushes.Transparent;
isStrokeSelectionCloneOn = false;
updateBorderStrokeSelectionControlLocation();
}
}
2023-12-22 00:14:15 +08:00
private void updateBorderStrokeSelectionControlLocation() {
2023-04-05 16:05:03 +08:00
double borderLeft = (inkCanvas.GetSelectionBounds().Left + inkCanvas.GetSelectionBounds().Right - BorderStrokeSelectionControlWidth) / 2;
double borderTop = inkCanvas.GetSelectionBounds().Bottom + 15;
if (borderLeft < 0) borderLeft = 0;
if (borderTop < 0) borderTop = 0;
if (Width - borderLeft < BorderStrokeSelectionControlWidth || double.IsNaN(borderLeft)) borderLeft = Width - BorderStrokeSelectionControlWidth;
if (Height - borderTop < BorderStrokeSelectionControlHeight || double.IsNaN(borderTop)) borderTop = Height - BorderStrokeSelectionControlHeight;
2023-12-22 00:14:15 +08:00
if (borderTop > 60) borderTop -= 60;
2023-04-05 16:05:03 +08:00
BorderStrokeSelectionControl.Margin = new Thickness(borderLeft, borderTop, 0, 0);
}
2023-12-22 00:14:15 +08:00
private void GridInkCanvasSelectionCover_ManipulationStarting(object sender, ManipulationStartingEventArgs e) {
2023-04-05 16:05:03 +08:00
e.Mode = ManipulationModes.All;
}
2023-12-22 00:14:15 +08:00
private void GridInkCanvasSelectionCover_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e) {
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void GridInkCanvasSelectionCover_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) {
try {
if (dec.Count >= 1) {
2023-04-05 16:05:03 +08:00
ManipulationDelta md = e.DeltaManipulation;
Vector trans = md.Translation; // 获得位移矢量
double rotate = md.Rotation; // 获得旋转角度
Vector scale = md.Scale; // 获得缩放倍数
Matrix m = new Matrix();
// Find center of element and then transform to get current location of center
FrameworkElement fe = e.Source as FrameworkElement;
Point center = new Point(fe.ActualWidth / 2, fe.ActualHeight / 2);
center = new Point(inkCanvas.GetSelectionBounds().Left + inkCanvas.GetSelectionBounds().Width / 2,
inkCanvas.GetSelectionBounds().Top + inkCanvas.GetSelectionBounds().Height / 2);
center = m.Transform(center); // 转换为矩阵缩放和旋转的中心点
// Update matrix to reflect translation/rotation
m.Translate(trans.X, trans.Y); // 移动
m.ScaleAt(scale.X, scale.Y, center.X, center.Y); // 缩放
StrokeCollection strokes = inkCanvas.GetSelectedStrokes();
2023-12-22 00:14:15 +08:00
if (StrokesSelectionClone.Count != 0) {
2023-04-05 16:05:03 +08:00
strokes = StrokesSelectionClone;
2023-12-22 00:14:15 +08:00
} else if (Settings.Gesture.IsEnableTwoFingerRotationOnSelection) {
2023-04-05 16:05:03 +08:00
m.RotateAt(rotate, center.X, center.Y); // 旋转
}
2023-12-22 00:14:15 +08:00
foreach (Stroke stroke in strokes) {
2023-04-05 16:05:03 +08:00
stroke.Transform(m, false);
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
stroke.DrawingAttributes.Width *= md.Scale.X;
stroke.DrawingAttributes.Height *= md.Scale.Y;
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
}
updateBorderStrokeSelectionControlLocation();
}
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void GridInkCanvasSelectionCover_TouchDown(object sender, TouchEventArgs e) {
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void GridInkCanvasSelectionCover_TouchUp(object sender, TouchEventArgs e) {
2023-04-05 16:05:03 +08:00
}
Point lastTouchPointOnGridInkCanvasCover = new Point(0, 0);
2023-12-22 00:14:15 +08:00
private void GridInkCanvasSelectionCover_PreviewTouchDown(object sender, TouchEventArgs e) {
2023-04-05 16:05:03 +08:00
dec.Add(e.TouchDevice.Id);
//设备1个的时候记录中心点
2023-12-22 00:14:15 +08:00
if (dec.Count == 1) {
2023-04-05 16:05:03 +08:00
TouchPoint touchPoint = e.GetTouchPoint(null);
centerPoint = touchPoint.Position;
lastTouchPointOnGridInkCanvasCover = touchPoint.Position;
2023-12-22 00:14:15 +08:00
if (isStrokeSelectionCloneOn) {
2023-04-05 16:05:03 +08:00
StrokeCollection strokes = inkCanvas.GetSelectedStrokes();
isProgramChangeStrokeSelection = true;
inkCanvas.Select(new StrokeCollection());
StrokesSelectionClone = strokes.Clone();
inkCanvas.Select(strokes);
isProgramChangeStrokeSelection = false;
inkCanvas.Strokes.Add(StrokesSelectionClone);
}
}
}
2023-12-22 00:14:15 +08:00
private void GridInkCanvasSelectionCover_PreviewTouchUp(object sender, TouchEventArgs e) {
2023-04-05 16:05:03 +08:00
dec.Remove(e.TouchDevice.Id);
if (dec.Count >= 1) return;
isProgramChangeStrokeSelection = false;
2023-12-22 00:14:15 +08:00
if (lastTouchPointOnGridInkCanvasCover == e.GetTouchPoint(null).Position) {
2023-04-05 16:05:03 +08:00
if (lastTouchPointOnGridInkCanvasCover.X < inkCanvas.GetSelectionBounds().Left ||
lastTouchPointOnGridInkCanvasCover.Y < inkCanvas.GetSelectionBounds().Top ||
lastTouchPointOnGridInkCanvasCover.X > inkCanvas.GetSelectionBounds().Right ||
2023-12-22 00:14:15 +08:00
lastTouchPointOnGridInkCanvasCover.Y > inkCanvas.GetSelectionBounds().Bottom) {
2023-04-05 16:05:03 +08:00
inkCanvas.Select(new StrokeCollection());
StrokesSelectionClone = new StrokeCollection();
}
2023-12-22 00:14:15 +08:00
} else if (inkCanvas.GetSelectedStrokes().Count == 0) {
2023-04-05 16:05:03 +08:00
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
StrokesSelectionClone = new StrokeCollection();
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
GridInkCanvasSelectionCover.Visibility = Visibility.Visible;
StrokesSelectionClone = new StrokeCollection();
}
}
#endregion Selection Gestures
#region Shape Drawing
#region Floating Bar Control
2023-12-22 00:14:15 +08:00
private void ImageDrawShape_MouseUp(object sender, MouseButtonEventArgs e) {
if (BorderDrawShape.Visibility == Visibility.Visible) {
AnimationHelper.HideWithSlideAndFade(BorderDrawShape);
AnimationHelper.HideWithSlideAndFade(BoardBorderDrawShape);
} else {
AnimationHelper.ShowWithSlideFromBottomAndFade(BorderDrawShape);
AnimationHelper.ShowWithSlideFromBottomAndFade(BoardBorderDrawShape);
2023-04-05 16:05:03 +08:00
}
}
#endregion Floating Bar Control
int drawingShapeMode = 0;
bool isLongPressSelected = false; // 用于存是否是“选中”状态,便于后期抬笔后不做切换到笔的处理
#region Buttons
2023-12-22 00:14:15 +08:00
private void SymbolIconPinBorderDrawShape_MouseUp(object sender, MouseButtonEventArgs e) {
2023-04-05 16:05:03 +08:00
if (lastBorderMouseDownObject != sender) return;
ToggleSwitchDrawShapeBorderAutoHide.IsOn = !ToggleSwitchDrawShapeBorderAutoHide.IsOn;
2023-12-22 00:14:15 +08:00
if (ToggleSwitchDrawShapeBorderAutoHide.IsOn) {
2023-04-05 16:05:03 +08:00
((ModernWpf.Controls.SymbolIcon)sender).Symbol = ModernWpf.Controls.Symbol.Pin;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
((ModernWpf.Controls.SymbolIcon)sender).Symbol = ModernWpf.Controls.Symbol.UnPin;
}
}
object lastMouseDownSender = null;
DateTime lastMouseDownTime = DateTime.MinValue;
2023-12-22 00:14:15 +08:00
private async void Image_MouseDown(object sender, MouseButtonEventArgs e) {
2023-04-05 16:05:03 +08:00
lastMouseDownSender = sender;
lastMouseDownTime = DateTime.Now;
await Task.Delay(500);
2023-12-22 00:14:15 +08:00
if (lastMouseDownSender == sender) {
2023-04-05 16:05:03 +08:00
lastMouseDownSender = null;
var dA = new DoubleAnimation(1, 0.3, new Duration(TimeSpan.FromMilliseconds(100)));
((UIElement)sender).BeginAnimation(OpacityProperty, dA);
forceEraser = true;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
2023-12-22 00:14:15 +08:00
if (sender == ImageDrawLine || sender == BoardImageDrawLine) {
2023-04-05 16:05:03 +08:00
drawingShapeMode = 1;
2023-12-22 00:14:15 +08:00
} else if (sender == ImageDrawDashedLine || sender == BoardImageDrawDashedLine) {
2023-04-05 16:05:03 +08:00
drawingShapeMode = 8;
2023-12-22 00:14:15 +08:00
} else if (sender == ImageDrawDotLine || sender == BoardImageDrawDotLine) {
2023-04-05 16:05:03 +08:00
drawingShapeMode = 18;
2023-12-22 00:14:15 +08:00
} else if (sender == ImageDrawArrow || sender == BoardImageDrawArrow) {
2023-04-05 16:05:03 +08:00
drawingShapeMode = 2;
2023-12-22 00:14:15 +08:00
} else if (sender == ImageDrawParallelLine || sender == BoardImageDrawParallelLine) {
2023-04-05 16:05:03 +08:00
drawingShapeMode = 15;
}
isLongPressSelected = true;
2023-12-22 00:14:15 +08:00
if (isSingleFingerDragMode) {
2023-04-05 16:05:03 +08:00
BtnFingerDragMode_Click(BtnFingerDragMode, null);
}
}
}
2023-12-22 00:14:15 +08:00
private void BtnPen_Click(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
forceEraser = false;
drawingShapeMode = 0;
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
isLongPressSelected = false;
}
2023-12-22 00:14:15 +08:00
private void BtnDrawLine_Click(object sender, EventArgs e) {
if (lastMouseDownSender == sender) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
drawingShapeMode = 1;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
}
lastMouseDownSender = null;
2023-12-22 00:14:15 +08:00
if (isLongPressSelected) {
CollapseBorderDrawShape(true);
2023-04-05 16:05:03 +08:00
var dA = new DoubleAnimation(1, 1, new Duration(TimeSpan.FromMilliseconds(0)));
ImageDrawLine.BeginAnimation(OpacityProperty, dA);
}
2023-12-22 00:14:15 +08:00
DrawShapePromptToPen();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BtnDrawDashedLine_Click(object sender, EventArgs e) {
if (lastMouseDownSender == sender) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
drawingShapeMode = 8;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
}
lastMouseDownSender = null;
2023-12-22 00:14:15 +08:00
if (isLongPressSelected) {
CollapseBorderDrawShape(true);
2023-04-05 16:05:03 +08:00
var dA = new DoubleAnimation(1, 1, new Duration(TimeSpan.FromMilliseconds(0)));
ImageDrawDashedLine.BeginAnimation(OpacityProperty, dA);
}
2023-12-22 00:14:15 +08:00
DrawShapePromptToPen();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BtnDrawDotLine_Click(object sender, EventArgs e) {
if (lastMouseDownSender == sender) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
drawingShapeMode = 18;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
}
lastMouseDownSender = null;
2023-12-22 00:14:15 +08:00
if (isLongPressSelected) {
CollapseBorderDrawShape(true);
2023-04-05 16:05:03 +08:00
var dA = new DoubleAnimation(1, 1, new Duration(TimeSpan.FromMilliseconds(0)));
ImageDrawDotLine.BeginAnimation(OpacityProperty, dA);
}
2023-12-22 00:14:15 +08:00
DrawShapePromptToPen();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BtnDrawArrow_Click(object sender, EventArgs e) {
if (lastMouseDownSender == sender) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
drawingShapeMode = 2;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
}
lastMouseDownSender = null;
2023-12-22 00:14:15 +08:00
if (isLongPressSelected) {
CollapseBorderDrawShape(true);
2023-04-05 16:05:03 +08:00
var dA = new DoubleAnimation(1, 1, new Duration(TimeSpan.FromMilliseconds(0)));
ImageDrawArrow.BeginAnimation(OpacityProperty, dA);
}
2023-12-22 00:14:15 +08:00
DrawShapePromptToPen();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BtnDrawParallelLine_Click(object sender, EventArgs e) {
if (lastMouseDownSender == sender) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
drawingShapeMode = 15;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
}
lastMouseDownSender = null;
2023-12-22 00:14:15 +08:00
if (isLongPressSelected) {
CollapseBorderDrawShape(true);
2023-04-05 16:05:03 +08:00
var dA = new DoubleAnimation(1, 1, new Duration(TimeSpan.FromMilliseconds(0)));
ImageDrawParallelLine.BeginAnimation(OpacityProperty, dA);
}
2023-12-22 00:14:15 +08:00
DrawShapePromptToPen();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BtnDrawCoordinate1_Click(object sender, EventArgs e) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
drawingShapeMode = 11;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
2023-12-22 00:14:15 +08:00
DrawShapePromptToPen();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BtnDrawCoordinate2_Click(object sender, EventArgs e) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
drawingShapeMode = 12;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
2023-12-22 00:14:15 +08:00
DrawShapePromptToPen();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BtnDrawCoordinate3_Click(object sender, EventArgs e) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
drawingShapeMode = 13;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
2023-12-22 00:14:15 +08:00
DrawShapePromptToPen();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BtnDrawCoordinate4_Click(object sender, EventArgs e) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
drawingShapeMode = 14;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
2023-12-22 00:14:15 +08:00
DrawShapePromptToPen();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BtnDrawCoordinate5_Click(object sender, EventArgs e) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
drawingShapeMode = 17;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
2023-12-22 00:14:15 +08:00
DrawShapePromptToPen();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BtnDrawRectangle_Click(object sender, EventArgs e) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
drawingShapeMode = 3;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
2023-12-22 00:14:15 +08:00
DrawShapePromptToPen();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BtnDrawRectangleCenter_Click(object sender, EventArgs e) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
drawingShapeMode = 19;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
2023-12-22 00:14:15 +08:00
DrawShapePromptToPen();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BtnDrawEllipse_Click(object sender, EventArgs e) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
drawingShapeMode = 4;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
2023-12-22 00:14:15 +08:00
DrawShapePromptToPen();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BtnDrawCircle_Click(object sender, EventArgs e) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
drawingShapeMode = 5;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
2023-12-22 00:14:15 +08:00
DrawShapePromptToPen();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BtnDrawCenterEllipse_Click(object sender, EventArgs e) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
drawingShapeMode = 16;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
2023-12-22 00:14:15 +08:00
DrawShapePromptToPen();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BtnDrawCenterEllipseWithFocalPoint_Click(object sender, EventArgs e) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
drawingShapeMode = 23;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
2023-12-22 00:14:15 +08:00
DrawShapePromptToPen();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BtnDrawDashedCircle_Click(object sender, EventArgs e) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
drawingShapeMode = 10;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
2023-12-22 00:14:15 +08:00
DrawShapePromptToPen();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BtnDrawHyperbola_Click(object sender, EventArgs e) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
drawingShapeMode = 24;
drawMultiStepShapeCurrentStep = 0;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
2023-12-22 00:14:15 +08:00
DrawShapePromptToPen();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BtnDrawHyperbolaWithFocalPoint_Click(object sender, EventArgs e) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
drawingShapeMode = 25;
drawMultiStepShapeCurrentStep = 0;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
2023-12-22 00:14:15 +08:00
DrawShapePromptToPen();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BtnDrawParabola1_Click(object sender, EventArgs e) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
drawingShapeMode = 20;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
2023-12-22 00:14:15 +08:00
DrawShapePromptToPen();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BtnDrawParabolaWithFocalPoint_Click(object sender, EventArgs e) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
drawingShapeMode = 22;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
2023-12-22 00:14:15 +08:00
DrawShapePromptToPen();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BtnDrawParabola2_Click(object sender, EventArgs e) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
drawingShapeMode = 21;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
2023-12-22 00:14:15 +08:00
DrawShapePromptToPen();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BtnDrawCylinder_Click(object sender, EventArgs e) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
drawingShapeMode = 6;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
2023-12-22 00:14:15 +08:00
DrawShapePromptToPen();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BtnDrawCone_Click(object sender, EventArgs e) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
drawingShapeMode = 7;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
2023-12-22 00:14:15 +08:00
DrawShapePromptToPen();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BtnDrawCuboid_Click(object sender, EventArgs e) {
2023-04-05 16:05:03 +08:00
forceEraser = true;
drawingShapeMode = 9;
isFirstTouchCuboid = true;
CuboidFrontRectIniP = new Point();
CuboidFrontRectEndP = new Point();
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
2023-12-22 00:14:15 +08:00
DrawShapePromptToPen();
2023-04-05 16:05:03 +08:00
}
#endregion
2023-12-22 00:14:15 +08:00
private void inkCanvas_TouchMove(object sender, TouchEventArgs e) {
2023-04-05 16:05:03 +08:00
if (isSingleFingerDragMode) return;
2023-12-22 00:14:15 +08:00
if (drawingShapeMode != 0) {
if (isLastTouchEraser) {
2023-04-05 16:05:03 +08:00
return;
}
//EraserContainer.Background = null;
2023-12-22 00:14:15 +08:00
//ImageEraser.Visibility = Visibility.Visible;
2023-04-05 16:05:03 +08:00
if (isWaitUntilNextTouchDown) return;
2023-12-22 00:14:15 +08:00
if (dec.Count > 1) {
2023-04-05 16:05:03 +08:00
isWaitUntilNextTouchDown = true;
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(lastTempStroke);
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
return;
}
2023-12-22 00:14:15 +08:00
if (inkCanvas.EditingMode != InkCanvasEditingMode.None) {
2023-04-05 16:05:03 +08:00
inkCanvas.EditingMode = InkCanvasEditingMode.None;
}
}
MouseTouchMove(e.GetTouchPoint(inkCanvas).Position);
}
int drawMultiStepShapeCurrentStep = 0; //多笔完成的图形 当前所处在的笔画
StrokeCollection drawMultiStepShapeSpecialStrokeCollection = new StrokeCollection(); //多笔完成的图形 当前所处在的笔画
2023-12-22 00:14:15 +08:00
//double drawMultiStepShapeSpecialParameter1 = 0.0; //多笔完成的图形 特殊参数 通常用于表示a
//double drawMultiStepShapeSpecialParameter2 = 0.0; //多笔完成的图形 特殊参数 通常用于表示b
2023-04-05 16:05:03 +08:00
double drawMultiStepShapeSpecialParameter3 = 0.0; //多笔完成的图形 特殊参数 通常用于表示k
2023-12-22 00:14:15 +08:00
private void MouseTouchMove(Point endP) {
2023-04-05 16:05:03 +08:00
List<System.Windows.Point> pointList;
StylusPointCollection point;
Stroke stroke;
StrokeCollection strokes = new StrokeCollection();
Point newIniP = iniP;
2023-12-22 00:14:15 +08:00
switch (drawingShapeMode) {
2023-04-05 16:05:03 +08:00
case 1:
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeDrawing;
2023-04-05 16:05:03 +08:00
pointList = new List<System.Windows.Point>{
new System.Windows.Point(iniP.X, iniP.Y),
new System.Windows.Point(endP.X, endP.Y)
};
point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(lastTempStroke);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
lastTempStroke = stroke;
inkCanvas.Strokes.Add(stroke);
break;
case 8:
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeDrawing;
2023-04-05 16:05:03 +08:00
strokes.Add(GenerateDashedLineStrokeCollection(iniP, endP));
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
lastTempStrokeCollection = strokes;
inkCanvas.Strokes.Add(strokes);
break;
case 18:
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeDrawing;
2023-04-05 16:05:03 +08:00
strokes.Add(GenerateDotLineStrokeCollection(iniP, endP));
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
lastTempStrokeCollection = strokes;
inkCanvas.Strokes.Add(strokes);
break;
case 2:
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeDrawing;
2023-04-05 16:05:03 +08:00
double w = 30, h = 10;
double theta = Math.Atan2(iniP.Y - endP.Y, iniP.X - endP.X);
double sint = Math.Sin(theta);
double cost = Math.Cos(theta);
pointList = new List<Point>
{
new Point(iniP.X, iniP.Y),
new Point(endP.X , endP.Y),
new Point(endP.X + (w * cost - h * sint), endP.Y + (w * sint + h * cost)),
new Point(endP.X,endP.Y),
new Point(endP.X + (w * cost + h * sint), endP.Y - (h * cost - w * sint))
};
point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(lastTempStroke);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
lastTempStroke = stroke;
inkCanvas.Strokes.Add(stroke);
break;
case 15:
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeDrawing;
2023-04-05 16:05:03 +08:00
double d = GetDistance(iniP, endP);
if (d == 0) return;
double sinTheta = (iniP.Y - endP.Y) / d;
double cosTheta = (endP.X - iniP.X) / d;
double tanTheta = Math.Abs(sinTheta / cosTheta);
double x = 25;
2023-12-22 00:14:15 +08:00
if (Math.Abs(tanTheta) < 1.0 / 12) {
2023-04-05 16:05:03 +08:00
sinTheta = 0;
cosTheta = 1;
endP.Y = iniP.Y;
}
if (tanTheta < 0.63 && tanTheta > 0.52) //30
{
sinTheta = sinTheta / Math.Abs(sinTheta) * 0.5;
cosTheta = cosTheta / Math.Abs(cosTheta) * 0.866;
endP.Y = iniP.Y - d * sinTheta;
endP.X = iniP.X + d * cosTheta;
}
if (tanTheta < 1.08 && tanTheta > 0.92) //45
{
sinTheta = sinTheta / Math.Abs(sinTheta) * 0.707;
cosTheta = cosTheta / Math.Abs(cosTheta) * 0.707;
endP.Y = iniP.Y - d * sinTheta;
endP.X = iniP.X + d * cosTheta;
}
if (tanTheta < 1.95 && tanTheta > 1.63) //60
{
sinTheta = sinTheta / Math.Abs(sinTheta) * 0.866;
cosTheta = cosTheta / Math.Abs(cosTheta) * 0.5;
endP.Y = iniP.Y - d * sinTheta;
endP.X = iniP.X + d * cosTheta;
}
2023-12-22 00:14:15 +08:00
if (Math.Abs(cosTheta / sinTheta) < 1.0 / 12) {
2023-04-05 16:05:03 +08:00
endP.X = iniP.X;
sinTheta = 1;
cosTheta = 0;
}
strokes.Add(GenerateLineStroke(new Point(iniP.X - 3 * x * sinTheta, iniP.Y - 3 * x * cosTheta), new Point(endP.X - 3 * x * sinTheta, endP.Y - 3 * x * cosTheta)));
strokes.Add(GenerateLineStroke(new Point(iniP.X - x * sinTheta, iniP.Y - x * cosTheta), new Point(endP.X - x * sinTheta, endP.Y - x * cosTheta)));
strokes.Add(GenerateLineStroke(new Point(iniP.X + x * sinTheta, iniP.Y + x * cosTheta), new Point(endP.X + x * sinTheta, endP.Y + x * cosTheta)));
strokes.Add(GenerateLineStroke(new Point(iniP.X + 3 * x * sinTheta, iniP.Y + 3 * x * cosTheta), new Point(endP.X + 3 * x * sinTheta, endP.Y + 3 * x * cosTheta)));
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
lastTempStrokeCollection = strokes;
inkCanvas.Strokes.Add(strokes);
break;
case 11:
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeDrawing;
2023-04-05 16:05:03 +08:00
strokes.Add(GenerateArrowLineStroke(new Point(2 * iniP.X - (endP.X - 20), iniP.Y), new Point(endP.X, iniP.Y)));
strokes.Add(GenerateArrowLineStroke(new Point(iniP.X, 2 * iniP.Y - (endP.Y + 20)), new Point(iniP.X, endP.Y)));
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
lastTempStrokeCollection = strokes;
inkCanvas.Strokes.Add(strokes);
break;
case 12:
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeDrawing;
2023-04-05 16:05:03 +08:00
if (Math.Abs(iniP.X - endP.X) < 0.01) return;
strokes.Add(GenerateArrowLineStroke(new Point(iniP.X + (iniP.X - endP.X) / Math.Abs(iniP.X - endP.X) * 25, iniP.Y), new Point(endP.X, iniP.Y)));
strokes.Add(GenerateArrowLineStroke(new Point(iniP.X, 2 * iniP.Y - (endP.Y + 20)), new Point(iniP.X, endP.Y)));
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
lastTempStrokeCollection = strokes;
inkCanvas.Strokes.Add(strokes);
break;
case 13:
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeDrawing;
2023-04-05 16:05:03 +08:00
if (Math.Abs(iniP.Y - endP.Y) < 0.01) return;
strokes.Add(GenerateArrowLineStroke(new Point(2 * iniP.X - (endP.X - 20), iniP.Y), new Point(endP.X, iniP.Y)));
strokes.Add(GenerateArrowLineStroke(new Point(iniP.X, iniP.Y + (iniP.Y - endP.Y) / Math.Abs(iniP.Y - endP.Y) * 25), new Point(iniP.X, endP.Y)));
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
lastTempStrokeCollection = strokes;
inkCanvas.Strokes.Add(strokes);
break;
case 14:
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeDrawing;
2023-04-05 16:05:03 +08:00
if (Math.Abs(iniP.X - endP.X) < 0.01 || Math.Abs(iniP.Y - endP.Y) < 0.01) return;
strokes.Add(GenerateArrowLineStroke(new Point(iniP.X + (iniP.X - endP.X) / Math.Abs(iniP.X - endP.X) * 25, iniP.Y), new Point(endP.X, iniP.Y)));
strokes.Add(GenerateArrowLineStroke(new Point(iniP.X, iniP.Y + (iniP.Y - endP.Y) / Math.Abs(iniP.Y - endP.Y) * 25), new Point(iniP.X, endP.Y)));
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
lastTempStrokeCollection = strokes;
inkCanvas.Strokes.Add(strokes);
break;
case 17:
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeDrawing;
2023-04-05 16:05:03 +08:00
strokes.Add(GenerateArrowLineStroke(new Point(iniP.X, iniP.Y), new Point(iniP.X + Math.Abs(endP.X - iniP.X), iniP.Y)));
strokes.Add(GenerateArrowLineStroke(new Point(iniP.X, iniP.Y), new Point(iniP.X, iniP.Y - Math.Abs(endP.Y - iniP.Y))));
d = (Math.Abs(iniP.X - endP.X) + Math.Abs(iniP.Y - endP.Y)) / 2;
strokes.Add(GenerateArrowLineStroke(new Point(iniP.X, iniP.Y), new Point(iniP.X - d / 1.76, iniP.Y + d / 1.76)));
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
lastTempStrokeCollection = strokes;
inkCanvas.Strokes.Add(strokes);
break;
case 3:
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeDrawing;
2023-04-05 16:05:03 +08:00
pointList = new List<System.Windows.Point>{
new System.Windows.Point(iniP.X, iniP.Y),
new System.Windows.Point(iniP.X, endP.Y),
new System.Windows.Point(endP.X, endP.Y),
new System.Windows.Point(endP.X, iniP.Y),
new System.Windows.Point(iniP.X, iniP.Y)
};
point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(lastTempStroke);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
lastTempStroke = stroke;
inkCanvas.Strokes.Add(stroke);
break;
case 19:
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeDrawing;
2023-04-05 16:05:03 +08:00
double a = iniP.X - endP.X;
double b = iniP.Y - endP.Y;
pointList = new List<System.Windows.Point>{
new System.Windows.Point(iniP.X - a, iniP.Y - b),
new System.Windows.Point(iniP.X - a, iniP.Y + b),
new System.Windows.Point(iniP.X + a, iniP.Y + b),
new System.Windows.Point(iniP.X + a, iniP.Y - b),
new System.Windows.Point(iniP.X - a, iniP.Y - b)
};
point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(lastTempStroke);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
lastTempStroke = stroke;
inkCanvas.Strokes.Add(stroke);
break;
case 4:
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeDrawing;
2023-04-05 16:05:03 +08:00
pointList = GenerateEllipseGeometry(iniP, endP);
point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(lastTempStroke);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
lastTempStroke = stroke;
inkCanvas.Strokes.Add(stroke);
break;
case 5:
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeDrawing;
2023-04-05 16:05:03 +08:00
double R = GetDistance(iniP, endP);
pointList = GenerateEllipseGeometry(new Point(iniP.X - R, iniP.Y - R), new Point(iniP.X + R, iniP.Y + R));
point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(lastTempStroke);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
lastTempStroke = stroke;
inkCanvas.Strokes.Add(stroke);
break;
case 16:
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeDrawing;
2023-04-05 16:05:03 +08:00
double halfA = endP.X - iniP.X;
double halfB = endP.Y - iniP.Y;
pointList = GenerateEllipseGeometry(new Point(iniP.X - halfA, iniP.Y - halfB), new Point(iniP.X + halfA, iniP.Y + halfB));
point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(lastTempStroke);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
lastTempStroke = stroke;
inkCanvas.Strokes.Add(stroke);
break;
case 23:
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeDrawing;
2023-04-05 16:05:03 +08:00
a = Math.Abs(endP.X - iniP.X);
b = Math.Abs(endP.Y - iniP.Y);
pointList = GenerateEllipseGeometry(new Point(iniP.X - a, iniP.Y - b), new Point(iniP.X + a, iniP.Y + b));
point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
strokes.Add(stroke);
double c = Math.Sqrt(Math.Abs(a * a - b * b));
StylusPoint stylusPoint;
2023-12-22 00:14:15 +08:00
if (a > b) {
2023-04-05 16:05:03 +08:00
stylusPoint = new StylusPoint(iniP.X + c, iniP.Y, (float)1.0);
point = new StylusPointCollection();
point.Add(stylusPoint);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
strokes.Add(stroke.Clone());
stylusPoint = new StylusPoint(iniP.X - c, iniP.Y, (float)1.0);
point = new StylusPointCollection();
point.Add(stylusPoint);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
strokes.Add(stroke.Clone());
2023-12-22 00:14:15 +08:00
} else if (a < b) {
2023-04-05 16:05:03 +08:00
stylusPoint = new StylusPoint(iniP.X, iniP.Y - c, (float)1.0);
point = new StylusPointCollection();
point.Add(stylusPoint);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
strokes.Add(stroke.Clone());
stylusPoint = new StylusPoint(iniP.X, iniP.Y + c, (float)1.0);
point = new StylusPointCollection();
point.Add(stylusPoint);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
strokes.Add(stroke.Clone());
}
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
lastTempStrokeCollection = strokes;
inkCanvas.Strokes.Add(strokes);
break;
case 10:
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeDrawing;
2023-04-05 16:05:03 +08:00
R = GetDistance(iniP, endP);
strokes = GenerateDashedLineEllipseStrokeCollection(new Point(iniP.X - R, iniP.Y - R), new Point(iniP.X + R, iniP.Y + R));
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
lastTempStrokeCollection = strokes;
inkCanvas.Strokes.Add(strokes);
break;
case 24:
case 25:
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeDrawing;
2023-04-05 16:05:03 +08:00
//双曲线 x^2/a^2 - y^2/b^2 = 1
if (Math.Abs(iniP.X - endP.X) < 0.01 || Math.Abs(iniP.Y - endP.Y) < 0.01) return;
var pointList2 = new List<Point>();
var pointList3 = new List<Point>();
var pointList4 = new List<Point>();
2023-12-22 00:14:15 +08:00
if (drawMultiStepShapeCurrentStep == 0) {
2023-04-05 16:05:03 +08:00
//第一笔:画渐近线
double k = Math.Abs((endP.Y - iniP.Y) / (endP.X - iniP.X));
strokes.Add(GenerateDashedLineStrokeCollection(new Point(2 * iniP.X - endP.X, 2 * iniP.Y - endP.Y), endP));
strokes.Add(GenerateDashedLineStrokeCollection(new Point(2 * iniP.X - endP.X, endP.Y), new Point(endP.X, 2 * iniP.Y - endP.Y)));
drawMultiStepShapeSpecialParameter3 = k;
drawMultiStepShapeSpecialStrokeCollection = strokes;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
//第二笔:画双曲线
double k = drawMultiStepShapeSpecialParameter3;
bool isHyperbolaFocalPointOnXAxis = Math.Abs((endP.Y - iniP.Y) / (endP.X - iniP.X)) < k;
if (isHyperbolaFocalPointOnXAxis) { // 焦点在 x 轴上
a = Math.Sqrt(Math.Abs((endP.X - iniP.X) * (endP.X - iniP.X) - (endP.Y - iniP.Y) * (endP.Y - iniP.Y) / (k * k)));
b = a * k;
pointList = new List<Point>();
2023-12-22 00:14:15 +08:00
for (double i = a; i <= Math.Abs(endP.X - iniP.X); i += 0.5) {
double rY = Math.Sqrt(Math.Abs(k * k * i * i - b * b));
pointList.Add(new Point(iniP.X + i, iniP.Y - rY));
pointList2.Add(new Point(iniP.X + i, iniP.Y + rY));
pointList3.Add(new Point(iniP.X - i, iniP.Y - rY));
pointList4.Add(new Point(iniP.X - i, iniP.Y + rY));
}
} else { // 焦点在 y 轴上
a = Math.Sqrt(Math.Abs((endP.Y - iniP.Y) * (endP.Y - iniP.Y) - (endP.X - iniP.X) * (endP.X - iniP.X) * (k * k)));
b = a / k;
pointList = new List<Point>();
2023-12-22 00:14:15 +08:00
for (double i = a; i <= Math.Abs(endP.Y - iniP.Y); i += 0.5) {
double rX = Math.Sqrt(Math.Abs(i * i / k / k - b * b));
pointList.Add(new Point(iniP.X - rX, iniP.Y + i));
pointList2.Add(new Point(iniP.X + rX, iniP.Y + i));
pointList3.Add(new Point(iniP.X - rX, iniP.Y - i));
pointList4.Add(new Point(iniP.X + rX, iniP.Y - i));
}
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
point = new StylusPointCollection(pointList);
stroke = new Stroke(point) { DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };
strokes.Add(stroke.Clone());
point = new StylusPointCollection(pointList2);
stroke = new Stroke(point) { DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };
strokes.Add(stroke.Clone());
point = new StylusPointCollection(pointList3);
stroke = new Stroke(point) { DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };
strokes.Add(stroke.Clone());
point = new StylusPointCollection(pointList4);
stroke = new Stroke(point) { DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };
strokes.Add(stroke.Clone());
2023-12-22 00:14:15 +08:00
if (drawingShapeMode == 25) {
2023-04-05 16:05:03 +08:00
//画焦点
c = Math.Sqrt(a * a + b * b);
stylusPoint = isHyperbolaFocalPointOnXAxis ? new StylusPoint(iniP.X + c, iniP.Y, (float)1.0) : new StylusPoint(iniP.X, iniP.Y + c, (float)1.0);
2023-04-05 16:05:03 +08:00
point = new StylusPointCollection();
point.Add(stylusPoint);
stroke = new Stroke(point) { DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };
strokes.Add(stroke.Clone());
stylusPoint = isHyperbolaFocalPointOnXAxis ? new StylusPoint(iniP.X - c, iniP.Y, (float)1.0) : new StylusPoint(iniP.X, iniP.Y - c, (float)1.0);
2023-04-05 16:05:03 +08:00
point = new StylusPointCollection();
point.Add(stylusPoint);
stroke = new Stroke(point) { DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };
strokes.Add(stroke.Clone());
}
2023-12-22 00:14:15 +08:00
} catch {
2023-04-05 16:05:03 +08:00
return;
}
}
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
lastTempStrokeCollection = strokes;
inkCanvas.Strokes.Add(strokes);
break;
case 20:
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeDrawing;
2023-04-05 16:05:03 +08:00
//抛物线 y=ax^2
if (Math.Abs(iniP.X - endP.X) < 0.01 || Math.Abs(iniP.Y - endP.Y) < 0.01) return;
a = (iniP.Y - endP.Y) / ((iniP.X - endP.X) * (iniP.X - endP.X));
pointList = new List<Point>();
pointList2 = new List<Point>();
2023-12-22 00:14:15 +08:00
for (double i = 0.0; i <= Math.Abs(endP.X - iniP.X); i += 0.5) {
2023-04-05 16:05:03 +08:00
pointList.Add(new Point(iniP.X + i, iniP.Y - a * i * i));
pointList2.Add(new Point(iniP.X - i, iniP.Y - a * i * i));
}
point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
strokes.Add(stroke.Clone());
point = new StylusPointCollection(pointList2);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
strokes.Add(stroke.Clone());
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
lastTempStrokeCollection = strokes;
inkCanvas.Strokes.Add(strokes);
break;
case 21:
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeDrawing;
2023-04-05 16:05:03 +08:00
//抛物线 y^2=ax
if (Math.Abs(iniP.X - endP.X) < 0.01 || Math.Abs(iniP.Y - endP.Y) < 0.01) return;
a = (iniP.X - endP.X) / ((iniP.Y - endP.Y) * (iniP.Y - endP.Y));
pointList = new List<Point>();
pointList2 = new List<Point>();
2023-12-22 00:14:15 +08:00
for (double i = 0.0; i <= Math.Abs(endP.Y - iniP.Y); i += 0.5) {
2023-04-05 16:05:03 +08:00
pointList.Add(new Point(iniP.X - a * i * i, iniP.Y + i));
pointList2.Add(new Point(iniP.X - a * i * i, iniP.Y - i));
}
point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
strokes.Add(stroke.Clone());
point = new StylusPointCollection(pointList2);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
strokes.Add(stroke.Clone());
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
lastTempStrokeCollection = strokes;
inkCanvas.Strokes.Add(strokes);
break;
case 22:
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeDrawing;
2023-04-05 16:05:03 +08:00
//抛物线 y^2=ax, 含焦点
if (Math.Abs(iniP.X - endP.X) < 0.01 || Math.Abs(iniP.Y - endP.Y) < 0.01) return;
double p = (iniP.Y - endP.Y) * (iniP.Y - endP.Y) / (2 * (iniP.X - endP.X));
a = 0.5 / p;
pointList = new List<Point>();
pointList2 = new List<Point>();
2023-12-22 00:14:15 +08:00
for (double i = 0.0; i <= Math.Abs(endP.Y - iniP.Y); i += 0.5) {
2023-04-05 16:05:03 +08:00
pointList.Add(new Point(iniP.X - a * i * i, iniP.Y + i));
pointList2.Add(new Point(iniP.X - a * i * i, iniP.Y - i));
}
point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
strokes.Add(stroke.Clone());
point = new StylusPointCollection(pointList2);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
strokes.Add(stroke.Clone());
stylusPoint = new StylusPoint(iniP.X - p / 2, iniP.Y, (float)1.0);
point = new StylusPointCollection();
point.Add(stylusPoint);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
strokes.Add(stroke.Clone());
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
lastTempStrokeCollection = strokes;
inkCanvas.Strokes.Add(strokes);
break;
case 6:
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeDrawing;
2023-04-05 16:05:03 +08:00
newIniP = iniP;
2023-12-22 00:14:15 +08:00
if (iniP.Y > endP.Y) {
2023-04-05 16:05:03 +08:00
newIniP = new Point(iniP.X, endP.Y);
endP = new Point(endP.X, iniP.Y);
}
double topA = Math.Abs(newIniP.X - endP.X);
double topB = topA / 2.646;
//顶部椭圆
pointList = GenerateEllipseGeometry(new Point(newIniP.X, newIniP.Y - topB / 2), new Point(endP.X, newIniP.Y + topB / 2));
point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
strokes.Add(stroke.Clone());
//底部椭圆
pointList = GenerateEllipseGeometry(new Point(newIniP.X, endP.Y - topB / 2), new Point(endP.X, endP.Y + topB / 2), false, true);
point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
strokes.Add(stroke.Clone());
strokes.Add(GenerateDashedLineEllipseStrokeCollection(new Point(newIniP.X, endP.Y - topB / 2), new Point(endP.X, endP.Y + topB / 2), true, false));
//左侧
pointList = new List<System.Windows.Point>{
new System.Windows.Point(newIniP.X, newIniP.Y),
new System.Windows.Point(newIniP.X, endP.Y)
};
point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
strokes.Add(stroke.Clone());
//右侧
pointList = new List<System.Windows.Point>{
new System.Windows.Point(endP.X, newIniP.Y),
new System.Windows.Point(endP.X, endP.Y)
};
point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
strokes.Add(stroke.Clone());
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
lastTempStrokeCollection = strokes;
inkCanvas.Strokes.Add(strokes);
break;
case 7:
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeDrawing;
2023-12-22 00:14:15 +08:00
if (iniP.Y > endP.Y) {
2023-04-05 16:05:03 +08:00
newIniP = new Point(iniP.X, endP.Y);
endP = new Point(endP.X, iniP.Y);
}
double bottomA = Math.Abs(newIniP.X - endP.X);
double bottomB = bottomA / 2.646;
//底部椭圆
pointList = GenerateEllipseGeometry(new Point(newIniP.X, endP.Y - bottomB / 2), new Point(endP.X, endP.Y + bottomB / 2), false, true);
point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
strokes.Add(stroke.Clone());
strokes.Add(GenerateDashedLineEllipseStrokeCollection(new Point(newIniP.X, endP.Y - bottomB / 2), new Point(endP.X, endP.Y + bottomB / 2), true, false));
//左侧
pointList = new List<System.Windows.Point>{
new System.Windows.Point((newIniP.X + endP.X) / 2, newIniP.Y),
new System.Windows.Point(newIniP.X, endP.Y)
};
point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
strokes.Add(stroke.Clone());
//右侧
pointList = new List<System.Windows.Point>{
new System.Windows.Point((newIniP.X + endP.X) / 2, newIniP.Y),
new System.Windows.Point(endP.X, endP.Y)
};
point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
strokes.Add(stroke.Clone());
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
lastTempStrokeCollection = strokes;
inkCanvas.Strokes.Add(strokes);
break;
case 9:
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeDrawing;
2023-12-22 00:14:15 +08:00
if (isFirstTouchCuboid) {
2023-04-05 16:05:03 +08:00
//分开画线条方便后期单独擦除某一条棱
strokes.Add(GenerateLineStroke(new Point(iniP.X, iniP.Y), new Point(iniP.X, endP.Y)));
strokes.Add(GenerateLineStroke(new Point(iniP.X, endP.Y), new Point(endP.X, endP.Y)));
strokes.Add(GenerateLineStroke(new Point(endP.X, endP.Y), new Point(endP.X, iniP.Y)));
strokes.Add(GenerateLineStroke(new Point(iniP.X, iniP.Y), new Point(endP.X, iniP.Y)));
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
lastTempStrokeCollection = strokes;
inkCanvas.Strokes.Add(strokes);
CuboidFrontRectIniP = iniP;
CuboidFrontRectEndP = endP;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
d = CuboidFrontRectIniP.Y - endP.Y;
if (d < 0) d = -d; //就是懒不想做反向的,不要让我去做,想做自己做好之后 Pull Request
a = CuboidFrontRectEndP.X - CuboidFrontRectIniP.X; //正面矩形长
b = CuboidFrontRectEndP.Y - CuboidFrontRectIniP.Y; //正面矩形宽
//横上
Point newLineIniP = new Point(CuboidFrontRectIniP.X + d, CuboidFrontRectIniP.Y - d);
Point newLineEndP = new Point(CuboidFrontRectEndP.X + d, CuboidFrontRectIniP.Y - d);
pointList = new List<System.Windows.Point> { newLineIniP, newLineEndP };
point = new StylusPointCollection(pointList);
stroke = new Stroke(point) { DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };
strokes.Add(stroke.Clone());
//横下 (虚线)
newLineIniP = new Point(CuboidFrontRectIniP.X + d, CuboidFrontRectEndP.Y - d);
newLineEndP = new Point(CuboidFrontRectEndP.X + d, CuboidFrontRectEndP.Y - d);
strokes.Add(GenerateDashedLineStrokeCollection(newLineIniP, newLineEndP));
//斜左上
newLineIniP = new Point(CuboidFrontRectIniP.X, CuboidFrontRectIniP.Y);
newLineEndP = new Point(CuboidFrontRectIniP.X + d, CuboidFrontRectIniP.Y - d);
pointList = new List<System.Windows.Point> { newLineIniP, newLineEndP };
point = new StylusPointCollection(pointList);
stroke = new Stroke(point) { DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };
strokes.Add(stroke.Clone());
//斜右上
newLineIniP = new Point(CuboidFrontRectEndP.X, CuboidFrontRectIniP.Y);
newLineEndP = new Point(CuboidFrontRectEndP.X + d, CuboidFrontRectIniP.Y - d);
pointList = new List<System.Windows.Point> { newLineIniP, newLineEndP };
point = new StylusPointCollection(pointList);
stroke = new Stroke(point) { DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };
strokes.Add(stroke.Clone());
//斜左下 (虚线)
newLineIniP = new Point(CuboidFrontRectIniP.X, CuboidFrontRectEndP.Y);
newLineEndP = new Point(CuboidFrontRectIniP.X + d, CuboidFrontRectEndP.Y - d);
strokes.Add(GenerateDashedLineStrokeCollection(newLineIniP, newLineEndP));
//斜右下
newLineIniP = new Point(CuboidFrontRectEndP.X, CuboidFrontRectEndP.Y);
newLineEndP = new Point(CuboidFrontRectEndP.X + d, CuboidFrontRectEndP.Y - d);
pointList = new List<System.Windows.Point> { newLineIniP, newLineEndP };
point = new StylusPointCollection(pointList);
stroke = new Stroke(point) { DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };
strokes.Add(stroke.Clone());
//竖左 (虚线)
newLineIniP = new Point(CuboidFrontRectIniP.X + d, CuboidFrontRectIniP.Y - d);
newLineEndP = new Point(CuboidFrontRectIniP.X + d, CuboidFrontRectEndP.Y - d);
strokes.Add(GenerateDashedLineStrokeCollection(newLineIniP, newLineEndP));
//竖右
newLineIniP = new Point(CuboidFrontRectEndP.X + d, CuboidFrontRectIniP.Y - d);
newLineEndP = new Point(CuboidFrontRectEndP.X + d, CuboidFrontRectEndP.Y - d);
pointList = new List<System.Windows.Point> { newLineIniP, newLineEndP };
point = new StylusPointCollection(pointList);
stroke = new Stroke(point) { DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };
strokes.Add(stroke.Clone());
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
lastTempStrokeCollection = strokes;
inkCanvas.Strokes.Add(strokes);
}
break;
}
}
bool isFirstTouchCuboid = true;
Point CuboidFrontRectIniP = new Point();
Point CuboidFrontRectEndP = new Point();
2023-12-22 00:14:15 +08:00
private void Main_Grid_TouchUp(object sender, TouchEventArgs e) {
2023-04-05 16:05:03 +08:00
inkCanvas_MouseUp(sender, null);
2023-12-22 00:14:15 +08:00
if (dec.Count == 0) {
2023-04-05 16:05:03 +08:00
isWaitUntilNextTouchDown = false;
}
}
Stroke lastTempStroke = null;
StrokeCollection lastTempStrokeCollection = new StrokeCollection();
bool isWaitUntilNextTouchDown = false;
2023-12-22 00:14:15 +08:00
private List<System.Windows.Point> GenerateEllipseGeometry(System.Windows.Point st, System.Windows.Point ed, bool isDrawTop = true, bool isDrawBottom = true) {
2023-04-05 16:05:03 +08:00
double a = 0.5 * (ed.X - st.X);
double b = 0.5 * (ed.Y - st.Y);
List<System.Windows.Point> pointList = new List<System.Windows.Point>();
2023-12-22 00:14:15 +08:00
if (isDrawTop && isDrawBottom) {
for (double r = 0; r <= 2 * Math.PI; r = r + 0.01) {
2023-04-05 16:05:03 +08:00
pointList.Add(new System.Windows.Point(0.5 * (st.X + ed.X) + a * Math.Cos(r), 0.5 * (st.Y + ed.Y) + b * Math.Sin(r)));
}
2023-12-22 00:14:15 +08:00
} else {
if (isDrawBottom) {
for (double r = 0; r <= Math.PI; r = r + 0.01) {
2023-04-05 16:05:03 +08:00
pointList.Add(new System.Windows.Point(0.5 * (st.X + ed.X) + a * Math.Cos(r), 0.5 * (st.Y + ed.Y) + b * Math.Sin(r)));
}
}
2023-12-22 00:14:15 +08:00
if (isDrawTop) {
for (double r = Math.PI; r <= 2 * Math.PI; r = r + 0.01) {
2023-04-05 16:05:03 +08:00
pointList.Add(new System.Windows.Point(0.5 * (st.X + ed.X) + a * Math.Cos(r), 0.5 * (st.Y + ed.Y) + b * Math.Sin(r)));
}
}
}
return pointList;
}
2023-12-22 00:14:15 +08:00
private StrokeCollection GenerateDashedLineEllipseStrokeCollection(System.Windows.Point st, System.Windows.Point ed, bool isDrawTop = true, bool isDrawBottom = true) {
2023-04-05 16:05:03 +08:00
double a = 0.5 * (ed.X - st.X);
double b = 0.5 * (ed.Y - st.Y);
double step = 0.05;
List<System.Windows.Point> pointList = new List<System.Windows.Point>();
StylusPointCollection point;
Stroke stroke;
StrokeCollection strokes = new StrokeCollection();
2023-12-22 00:14:15 +08:00
if (isDrawBottom) {
for (double i = 0.0; i < 1.0; i += step * 1.66) {
2023-04-05 16:05:03 +08:00
pointList = new List<Point>();
2023-12-22 00:14:15 +08:00
for (double r = Math.PI * i; r <= Math.PI * (i + step); r = r + 0.01) {
2023-04-05 16:05:03 +08:00
pointList.Add(new System.Windows.Point(0.5 * (st.X + ed.X) + a * Math.Cos(r), 0.5 * (st.Y + ed.Y) + b * Math.Sin(r)));
}
point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
strokes.Add(stroke.Clone());
}
}
2023-12-22 00:14:15 +08:00
if (isDrawTop) {
for (double i = 1.0; i < 2.0; i += step * 1.66) {
2023-04-05 16:05:03 +08:00
pointList = new List<Point>();
2023-12-22 00:14:15 +08:00
for (double r = Math.PI * i; r <= Math.PI * (i + step); r = r + 0.01) {
2023-04-05 16:05:03 +08:00
pointList.Add(new System.Windows.Point(0.5 * (st.X + ed.X) + a * Math.Cos(r), 0.5 * (st.Y + ed.Y) + b * Math.Sin(r)));
}
point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
strokes.Add(stroke.Clone());
}
}
return strokes;
}
2023-12-22 00:14:15 +08:00
private Stroke GenerateLineStroke(System.Windows.Point st, System.Windows.Point ed) {
2023-04-05 16:05:03 +08:00
List<System.Windows.Point> pointList = new List<System.Windows.Point>();
StylusPointCollection point;
Stroke stroke;
pointList = new List<System.Windows.Point>{
new System.Windows.Point(st.X, st.Y),
new System.Windows.Point(ed.X, ed.Y)
};
point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
return stroke;
}
2023-12-22 00:14:15 +08:00
private Stroke GenerateArrowLineStroke(System.Windows.Point st, System.Windows.Point ed) {
2023-04-05 16:05:03 +08:00
List<System.Windows.Point> pointList = new List<System.Windows.Point>();
StylusPointCollection point;
Stroke stroke;
double w = 20, h = 7;
double theta = Math.Atan2(st.Y - ed.Y, st.X - ed.X);
double sint = Math.Sin(theta);
double cost = Math.Cos(theta);
pointList = new List<Point>
{
new Point(st.X, st.Y),
new Point(ed.X , ed.Y),
new Point(ed.X + (w * cost - h * sint), ed.Y + (w * sint + h * cost)),
new Point(ed.X,ed.Y),
new Point(ed.X + (w * cost + h * sint), ed.Y - (h * cost - w * sint))
};
point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
return stroke;
}
2023-12-22 00:14:15 +08:00
private StrokeCollection GenerateDashedLineStrokeCollection(System.Windows.Point st, System.Windows.Point ed) {
2023-04-05 16:05:03 +08:00
double step = 5;
List<System.Windows.Point> pointList = new List<System.Windows.Point>();
StylusPointCollection point;
Stroke stroke;
StrokeCollection strokes = new StrokeCollection();
double d = GetDistance(st, ed);
double sinTheta = (ed.Y - st.Y) / d;
double cosTheta = (ed.X - st.X) / d;
2023-12-22 00:14:15 +08:00
for (double i = 0.0; i < d; i += step * 2.76) {
2023-04-05 16:05:03 +08:00
pointList = new List<System.Windows.Point>{
new System.Windows.Point(st.X + i * cosTheta, st.Y + i * sinTheta),
new System.Windows.Point(st.X + Math.Min(i + step, d) * cosTheta, st.Y + Math.Min(i + step, d) * sinTheta)
};
point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
strokes.Add(stroke.Clone());
}
return strokes;
}
2023-12-22 00:14:15 +08:00
private StrokeCollection GenerateDotLineStrokeCollection(System.Windows.Point st, System.Windows.Point ed) {
2023-04-05 16:05:03 +08:00
double step = 3;
List<System.Windows.Point> pointList = new List<System.Windows.Point>();
StylusPointCollection point;
Stroke stroke;
StrokeCollection strokes = new StrokeCollection();
double d = GetDistance(st, ed);
double sinTheta = (ed.Y - st.Y) / d;
double cosTheta = (ed.X - st.X) / d;
2023-12-22 00:14:15 +08:00
for (double i = 0.0; i < d; i += step * 2.76) {
2023-04-05 16:05:03 +08:00
var stylusPoint = new StylusPoint(st.X + i * cosTheta, st.Y + i * sinTheta, (float)0.8);
point = new StylusPointCollection();
point.Add(stylusPoint);
2023-12-22 00:14:15 +08:00
stroke = new Stroke(point) {
2023-04-05 16:05:03 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
strokes.Add(stroke.Clone());
}
return strokes;
}
bool isMouseDown = false;
2023-12-22 00:14:15 +08:00
private void inkCanvas_MouseDown(object sender, MouseButtonEventArgs e) {
isMouseDown = true;
2023-12-22 00:14:15 +08:00
if (NeedUpdateIniP()) {
2023-04-05 16:05:03 +08:00
iniP = e.GetPosition(inkCanvas);
}
}
2023-12-22 00:14:15 +08:00
private void inkCanvas_MouseMove(object sender, MouseEventArgs e) {
if (isMouseDown) {
2023-04-05 16:05:03 +08:00
MouseTouchMove(e.GetPosition(inkCanvas));
}
}
2023-05-08 19:58:14 +08:00
2023-12-22 00:14:15 +08:00
private void inkCanvas_MouseUp(object sender, MouseButtonEventArgs e) {
if (drawingShapeMode == 5) {
2023-04-05 16:05:03 +08:00
Circle circle = new Circle(new Point(), 0, lastTempStroke);
circle.R = GetDistance(circle.Stroke.StylusPoints[0].ToPoint(), circle.Stroke.StylusPoints[circle.Stroke.StylusPoints.Count / 2].ToPoint()) / 2;
circle.Centroid = new Point((circle.Stroke.StylusPoints[0].X + circle.Stroke.StylusPoints[circle.Stroke.StylusPoints.Count / 2].X) / 2,
(circle.Stroke.StylusPoints[0].Y + circle.Stroke.StylusPoints[circle.Stroke.StylusPoints.Count / 2].Y) / 2);
circles.Add(circle);
}
2023-12-22 00:14:15 +08:00
if (drawingShapeMode != 9 && drawingShapeMode != 0 && drawingShapeMode != 24 && drawingShapeMode != 25) {
if (isLongPressSelected) {
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
BtnPen_Click(null, null); //画完一次还原到笔模式
}
}
2023-12-22 00:14:15 +08:00
if (drawingShapeMode == 9) {
if (isFirstTouchCuboid) {
if (CuboidStrokeCollection == null) CuboidStrokeCollection = new StrokeCollection();
2023-04-05 16:05:03 +08:00
isFirstTouchCuboid = false;
Point newIniP = new Point(Math.Min(CuboidFrontRectIniP.X, CuboidFrontRectEndP.X), Math.Min(CuboidFrontRectIniP.Y, CuboidFrontRectEndP.Y));
Point newEndP = new Point(Math.Max(CuboidFrontRectIniP.X, CuboidFrontRectEndP.X), Math.Max(CuboidFrontRectIniP.Y, CuboidFrontRectEndP.Y));
CuboidFrontRectIniP = newIniP;
CuboidFrontRectEndP = newEndP;
CuboidStrokeCollection.Add(lastTempStrokeCollection);
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
BtnPen_Click(null, null); //画完还原到笔模式
2023-12-22 00:14:15 +08:00
if (_currentCommitType == CommitReason.ShapeDrawing) {
CuboidStrokeCollection.Add(lastTempStrokeCollection);
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.UserInput;
timeMachine.CommitStrokeUserInputHistory(CuboidStrokeCollection);
CuboidStrokeCollection = null;
}
2023-04-05 16:05:03 +08:00
}
}
2023-12-22 00:14:15 +08:00
if (drawingShapeMode == 24 || drawingShapeMode == 25) {
if (drawMultiStepShapeCurrentStep == 0) {
2023-04-05 16:05:03 +08:00
drawMultiStepShapeCurrentStep = 1;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
drawMultiStepShapeCurrentStep = 0;
2023-12-22 00:14:15 +08:00
if (drawMultiStepShapeSpecialStrokeCollection != null) {
2023-05-08 20:37:55 +08:00
bool opFlag = false;
2023-12-22 00:14:15 +08:00
switch (Settings.Canvas.HyperbolaAsymptoteOption) {
2023-05-08 20:37:55 +08:00
case OptionalOperation.Yes:
opFlag = true;
break;
case OptionalOperation.No:
opFlag = false;
break;
case OptionalOperation.Ask:
opFlag = MessageBox.Show("是否移除渐近线?", "Ink Canvas", MessageBoxButton.YesNo) != MessageBoxResult.Yes;
break;
};
2023-12-22 00:14:15 +08:00
if (!opFlag) {
2023-05-08 20:37:55 +08:00
inkCanvas.Strokes.Remove(drawMultiStepShapeSpecialStrokeCollection);
}
2023-04-05 16:05:03 +08:00
}
BtnPen_Click(null, null); //画完还原到笔模式
}
}
isMouseDown = false;
2023-12-22 00:14:15 +08:00
if (ReplacedStroke != null || AddedStroke != null) {
timeMachine.CommitStrokeEraseHistory(ReplacedStroke, AddedStroke);
AddedStroke = null;
ReplacedStroke = null;
}
2023-12-22 00:14:15 +08:00
if (_currentCommitType == CommitReason.ShapeDrawing && drawingShapeMode != 9) {
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.UserInput;
StrokeCollection collection;
2023-12-22 00:14:15 +08:00
if (lastTempStrokeCollection != null && lastTempStrokeCollection.Count > 0) {
collection = lastTempStrokeCollection;
2023-12-22 00:14:15 +08:00
} else {
collection = new StrokeCollection() { lastTempStroke };
}
timeMachine.CommitStrokeUserInputHistory(collection);
}
lastTempStroke = null;
lastTempStrokeCollection = null;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private bool NeedUpdateIniP() {
if (drawingShapeMode == 24 || drawingShapeMode == 25) {
2023-04-05 16:05:03 +08:00
if (drawMultiStepShapeCurrentStep == 1) return false;
}
return true;
}
#endregion Shape Drawing
#region Whiteboard Controls
StrokeCollection[] strokeCollections = new StrokeCollection[101];
bool[] whiteboadLastModeIsRedo = new bool[101];
StrokeCollection lastTouchDownStrokeCollection = new StrokeCollection();
int CurrentWhiteboardIndex = 1;
int WhiteboardTotalCount = 1;
TimeMachineHistory[][] TimeMachineHistories = new TimeMachineHistory[101][]; //最多99页0用来存储非白板时的墨迹以便还原
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
private void SaveStrokes(bool isBackupMain = false) {
if (isBackupMain) {
var timeMachineHistory = timeMachine.ExportTimeMachineHistory();
TimeMachineHistories[0] = timeMachineHistory;
timeMachine.ClearStrokeHistory();
2023-05-08 19:58:14 +08:00
2023-12-22 00:14:15 +08:00
} else {
var timeMachineHistory = timeMachine.ExportTimeMachineHistory();
TimeMachineHistories[CurrentWhiteboardIndex] = timeMachineHistory;
timeMachine.ClearStrokeHistory();
2023-04-05 16:05:03 +08:00
}
}
2023-12-22 00:14:15 +08:00
private void ClearStrokes(bool isErasedByCode) {
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ClearingCanvas;
if (isErasedByCode) _currentCommitType = CommitReason.CodeInput;
inkCanvas.Strokes.Clear();
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.UserInput;
}
2023-12-22 00:14:15 +08:00
private void RestoreStrokes(bool isBackupMain = false) {
try {
if (TimeMachineHistories[CurrentWhiteboardIndex] == null) return; //防止白板打开后不居中
2023-12-22 00:14:15 +08:00
if (isBackupMain) {
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.CodeInput;
timeMachine.ImportTimeMachineHistory(TimeMachineHistories[0]);
2023-12-22 00:14:15 +08:00
foreach (var item in TimeMachineHistories[0]) {
if (item.CommitType == TimeMachineHistoryType.UserInput) {
if (!item.StrokeHasBeenCleared) {
foreach (var strokes in item.CurrentStroke) {
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
2023-12-22 00:14:15 +08:00
} else {
foreach (var strokes in item.CurrentStroke) {
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
}
2023-12-22 00:14:15 +08:00
} else if (item.CommitType == TimeMachineHistoryType.ShapeRecognition) {
if (item.StrokeHasBeenCleared) {
2023-12-22 00:14:15 +08:00
foreach (var strokes in item.CurrentStroke) {
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
2023-12-22 00:14:15 +08:00
foreach (var strokes in item.ReplacedStroke) {
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
2023-12-22 00:14:15 +08:00
} else {
foreach (var strokes in item.CurrentStroke) {
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
2023-12-22 00:14:15 +08:00
foreach (var strokes in item.ReplacedStroke) {
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
}
2023-12-22 00:14:15 +08:00
} else if (item.CommitType == TimeMachineHistoryType.Rotate) {
if (item.StrokeHasBeenCleared) {
2023-12-22 00:14:15 +08:00
foreach (var strokes in item.CurrentStroke) {
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
2023-12-22 00:14:15 +08:00
foreach (var strokes in item.ReplacedStroke) {
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
2023-12-22 00:14:15 +08:00
} else {
foreach (var strokes in item.CurrentStroke) {
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
2023-12-22 00:14:15 +08:00
foreach (var strokes in item.ReplacedStroke) {
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
}
2023-12-22 00:14:15 +08:00
} else if (item.CommitType == TimeMachineHistoryType.Clear) {
if (!item.StrokeHasBeenCleared) {
if (item.CurrentStroke != null) {
foreach (var currentStroke in item.CurrentStroke) {
if (!inkCanvas.Strokes.Contains(currentStroke)) inkCanvas.Strokes.Add(currentStroke);
}
}
2023-12-22 00:14:15 +08:00
if (item.ReplacedStroke != null) {
foreach (var replacedStroke in item.ReplacedStroke) {
if (inkCanvas.Strokes.Contains(replacedStroke)) inkCanvas.Strokes.Remove(replacedStroke);
}
}
2023-12-22 00:14:15 +08:00
} else {
if (item.ReplacedStroke != null) {
foreach (var replacedStroke in item.ReplacedStroke) {
if (!inkCanvas.Strokes.Contains(replacedStroke)) inkCanvas.Strokes.Add(replacedStroke);
}
}
2023-12-22 00:14:15 +08:00
if (item.CurrentStroke != null) {
foreach (var currentStroke in item.CurrentStroke) {
if (inkCanvas.Strokes.Contains(currentStroke)) inkCanvas.Strokes.Remove(currentStroke);
}
}
}
2023-05-08 19:58:14 +08:00
}
_currentCommitType = CommitReason.UserInput;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
} else {
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.CodeInput;
timeMachine.ImportTimeMachineHistory(TimeMachineHistories[CurrentWhiteboardIndex]);
2023-12-22 00:14:15 +08:00
foreach (var item in TimeMachineHistories[CurrentWhiteboardIndex]) {
if (item.CommitType == TimeMachineHistoryType.UserInput) {
if (!item.StrokeHasBeenCleared) {
foreach (var strokes in item.CurrentStroke) {
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
2023-12-22 00:14:15 +08:00
} else {
foreach (var strokes in item.CurrentStroke) {
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
}
2023-12-22 00:14:15 +08:00
} else if (item.CommitType == TimeMachineHistoryType.ShapeRecognition) {
if (item.StrokeHasBeenCleared) {
2023-12-22 00:14:15 +08:00
foreach (var strokes in item.CurrentStroke) {
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
2023-12-22 00:14:15 +08:00
foreach (var strokes in item.ReplacedStroke) {
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
2023-12-22 00:14:15 +08:00
} else {
foreach (var strokes in item.CurrentStroke) {
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
2023-12-22 00:14:15 +08:00
foreach (var strokes in item.ReplacedStroke) {
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
}
2023-12-22 00:14:15 +08:00
} else if (item.CommitType == TimeMachineHistoryType.Rotate) {
if (item.StrokeHasBeenCleared) {
2023-12-22 00:14:15 +08:00
foreach (var strokes in item.CurrentStroke) {
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
2023-12-22 00:14:15 +08:00
foreach (var strokes in item.ReplacedStroke) {
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
2023-12-22 00:14:15 +08:00
} else {
foreach (var strokes in item.CurrentStroke) {
if (!inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Add(strokes);
}
2023-12-22 00:14:15 +08:00
foreach (var strokes in item.ReplacedStroke) {
if (inkCanvas.Strokes.Contains(strokes))
inkCanvas.Strokes.Remove(strokes);
}
}
2023-12-22 00:14:15 +08:00
} else if (item.CommitType == TimeMachineHistoryType.Clear) {
if (!item.StrokeHasBeenCleared) {
if (item.CurrentStroke != null) {
foreach (var currentStroke in item.CurrentStroke) {
if (!inkCanvas.Strokes.Contains(currentStroke)) inkCanvas.Strokes.Add(currentStroke);
}
}
2023-12-22 00:14:15 +08:00
if (item.ReplacedStroke != null) {
foreach (var replacedStroke in item.ReplacedStroke) {
if (inkCanvas.Strokes.Contains(replacedStroke)) inkCanvas.Strokes.Remove(replacedStroke);
}
}
2023-12-22 00:14:15 +08:00
} else {
if (item.ReplacedStroke != null) {
foreach (var replacedStroke in item.ReplacedStroke) {
if (!inkCanvas.Strokes.Contains(replacedStroke)) inkCanvas.Strokes.Add(replacedStroke);
}
}
2023-12-22 00:14:15 +08:00
if (item.CurrentStroke != null) {
foreach (var currentStroke in item.CurrentStroke) {
if (inkCanvas.Strokes.Contains(currentStroke)) inkCanvas.Strokes.Remove(currentStroke);
}
}
}
}
2023-04-05 16:05:03 +08:00
}
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.UserInput;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BtnWhiteBoardSwitchPrevious_Click(object sender, EventArgs e) {
2023-04-05 16:05:03 +08:00
if (CurrentWhiteboardIndex <= 1) return;
SaveStrokes();
ClearStrokes(true);
2023-04-05 16:05:03 +08:00
CurrentWhiteboardIndex--;
RestoreStrokes();
UpdateIndexInfoDisplay();
}
2023-12-22 00:14:15 +08:00
private void BtnWhiteBoardSwitchNext_Click(object sender, EventArgs e) {
if (/*Settings.Automation.IsAutoSaveStrokesAtClear && */inkCanvas.Strokes.Count > Settings.Automation.MinimumAutomationStrokeNumber) {
2023-04-05 16:05:03 +08:00
SaveScreenShot(true);
2023-12-22 00:14:15 +08:00
SaveInkCanvasStrokes(false, false);
//if (Settings.Automation.IsAutoSaveStrokesAtScreenshot) SaveInkCanvasStrokes(false, false);
2023-05-23 22:09:50 +08:00
}
2023-12-22 00:14:15 +08:00
if (CurrentWhiteboardIndex >= WhiteboardTotalCount) {
2023-04-05 16:05:03 +08:00
BtnWhiteBoardAdd_Click(sender, e);
return;
}
SaveStrokes();
2023-04-05 16:05:03 +08:00
ClearStrokes(true);
2023-04-05 16:05:03 +08:00
CurrentWhiteboardIndex++;
RestoreStrokes();
UpdateIndexInfoDisplay();
}
2023-12-22 00:14:15 +08:00
private void BtnWhiteBoardAdd_Click(object sender, EventArgs e) {
2023-04-05 16:05:03 +08:00
if (WhiteboardTotalCount >= 99) return;
2023-12-22 00:14:15 +08:00
if (Settings.Automation.IsAutoSaveStrokesAtClear && inkCanvas.Strokes.Count > Settings.Automation.MinimumAutomationStrokeNumber) {
2023-04-05 16:05:03 +08:00
SaveScreenShot(true);
2023-05-23 22:09:50 +08:00
if (Settings.Automation.IsAutoSaveStrokesAtScreenshot) SaveInkCanvasStrokes(false);
}
2023-04-05 16:05:03 +08:00
SaveStrokes();
ClearStrokes(true);
2023-04-05 16:05:03 +08:00
WhiteboardTotalCount++;
CurrentWhiteboardIndex++;
2023-12-22 00:14:15 +08:00
if (CurrentWhiteboardIndex != WhiteboardTotalCount) {
for (int i = WhiteboardTotalCount; i > CurrentWhiteboardIndex; i--) {
TimeMachineHistories[i] = TimeMachineHistories[i - 1];
2023-04-05 16:05:03 +08:00
}
}
UpdateIndexInfoDisplay();
if (WhiteboardTotalCount >= 99) BtnWhiteBoardAdd.IsEnabled = false;
}
2023-12-22 00:14:15 +08:00
private void BtnWhiteBoardDelete_Click(object sender, RoutedEventArgs e) {
ClearStrokes(true);
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
if (CurrentWhiteboardIndex != WhiteboardTotalCount) {
for (int i = CurrentWhiteboardIndex; i <= WhiteboardTotalCount; i++) {
TimeMachineHistories[i] = TimeMachineHistories[i + 1];
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
CurrentWhiteboardIndex--;
}
WhiteboardTotalCount--;
RestoreStrokes();
UpdateIndexInfoDisplay();
if (WhiteboardTotalCount < 99) BtnWhiteBoardAdd.IsEnabled = true;
}
2023-12-22 00:14:15 +08:00
private void UpdateIndexInfoDisplay() {
2023-04-05 16:05:03 +08:00
TextBlockWhiteBoardIndexInfo.Text = string.Format("{0} / {1}", CurrentWhiteboardIndex, WhiteboardTotalCount);
2023-12-22 00:14:15 +08:00
if (CurrentWhiteboardIndex == WhiteboardTotalCount) {
BitmapImage newImageSource = new BitmapImage();
newImageSource.BeginInit();
newImageSource.UriSource = new Uri("/Resources/Icons-Fluent/ic_fluent_add_circle_24_regular.png", UriKind.RelativeOrAbsolute);
newImageSource.EndInit();
BoardLeftPannelNextPage.Source = newImageSource;
BoardRightPannelNextPage.Source = newImageSource;
BoardRightPannelNextPageTextBlock.Text = "加页";
BoardLeftPannelNextPageTextBlock.Text = "加页";
} else {
BitmapImage newImageSource = new BitmapImage();
newImageSource.BeginInit();
newImageSource.UriSource = new Uri("/Resources/Icons-Fluent/ic_fluent_arrow_circle_right_24_regular.png", UriKind.RelativeOrAbsolute);
newImageSource.EndInit();
BoardLeftPannelNextPage.Source = newImageSource;
BoardRightPannelNextPage.Source = newImageSource;
BoardRightPannelNextPageTextBlock.Text = "下一页";
BoardLeftPannelNextPageTextBlock.Text = "下一页";
}
if (CurrentWhiteboardIndex == 1) {
2023-04-05 16:05:03 +08:00
BtnWhiteBoardSwitchPrevious.IsEnabled = false;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
BtnWhiteBoardSwitchPrevious.IsEnabled = true;
}
2023-12-22 00:14:15 +08:00
if (CurrentWhiteboardIndex == WhiteboardTotalCount) {
2023-04-05 16:05:03 +08:00
BtnWhiteBoardSwitchNext.IsEnabled = false;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
BtnWhiteBoardSwitchNext.IsEnabled = true;
}
2023-12-22 00:14:15 +08:00
if (WhiteboardTotalCount == 1) {
2023-04-05 16:05:03 +08:00
BtnWhiteBoardDelete.IsEnabled = false;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
BtnWhiteBoardDelete.IsEnabled = true;
}
}
#endregion Whiteboard Controls
#region Simulate Pen Pressure & Ink To Shape
StrokeCollection newStrokes = new StrokeCollection();
List<Circle> circles = new List<Circle>();
//此函数中的所有代码版权所有 WXRIW在其他项目中使用前必须提前联系wxriw@outlook.com谢谢
2023-12-22 00:14:15 +08:00
private void inkCanvas_StrokeCollected(object sender, InkCanvasStrokeCollectedEventArgs e) {
try {
2023-04-05 16:05:03 +08:00
inkCanvas.Opacity = 1;
2023-12-22 00:14:15 +08:00
if (Settings.InkToShape.IsInkToShapeEnabled && !Environment.Is64BitProcess) {
void InkToShapeProcess() {
try {
2023-04-25 11:58:41 +08:00
newStrokes.Add(e.Stroke);
if (newStrokes.Count > 4) newStrokes.RemoveAt(0);
2023-12-22 00:14:15 +08:00
for (int i = 0; i < newStrokes.Count; i++) {
2023-04-25 11:58:41 +08:00
if (!inkCanvas.Strokes.Contains(newStrokes[i])) newStrokes.RemoveAt(i--);
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
for (int i = 0; i < circles.Count; i++) {
2023-04-25 11:58:41 +08:00
if (!inkCanvas.Strokes.Contains(circles[i].Stroke)) circles.RemoveAt(i);
}
var strokeReco = new StrokeCollection();
var result = InkRecognizeHelper.RecognizeShape(newStrokes);
2023-12-22 00:14:15 +08:00
for (int i = newStrokes.Count - 1; i >= 0; i--) {
2023-04-25 11:58:41 +08:00
strokeReco.Add(newStrokes[i]);
var newResult = InkRecognizeHelper.RecognizeShape(strokeReco);
2023-12-22 00:14:15 +08:00
if (newResult.InkDrawingNode.GetShapeName() == "Circle" || newResult.InkDrawingNode.GetShapeName() == "Ellipse") {
2023-04-25 11:58:41 +08:00
result = newResult;
break;
2023-04-05 16:05:03 +08:00
}
2023-04-25 11:58:41 +08:00
//Label.Visibility = Visibility.Visible;
2023-12-22 00:14:15 +08:00
//Label.Content = circles.Count.ToString() + "\n" + newResult.InkDrawingNode.GetShapeName();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
if (result.InkDrawingNode.GetShapeName() == "Circle") {
2023-04-25 11:58:41 +08:00
var shape = result.InkDrawingNode.GetShape();
2023-12-22 00:14:15 +08:00
if (shape.Width > 75) {
foreach (Circle circle in circles) {
2023-04-25 11:58:41 +08:00
//判断是否画同心圆
if (Math.Abs(result.Centroid.X - circle.Centroid.X) / shape.Width < 0.12 &&
2023-12-22 00:14:15 +08:00
Math.Abs(result.Centroid.Y - circle.Centroid.Y) / shape.Width < 0.12) {
2023-04-25 11:58:41 +08:00
result.Centroid = circle.Centroid;
break;
2023-12-22 00:14:15 +08:00
} else {
2023-04-25 11:58:41 +08:00
double d = (result.Centroid.X - circle.Centroid.X) * (result.Centroid.X - circle.Centroid.X) +
(result.Centroid.Y - circle.Centroid.Y) * (result.Centroid.Y - circle.Centroid.Y);
d = Math.Sqrt(d);
//判断是否画外切圆
double x = shape.Width / 2.0 + circle.R - d;
2023-12-22 00:14:15 +08:00
if (Math.Abs(x) / shape.Width < 0.1) {
2023-04-25 11:58:41 +08:00
double sinTheta = (result.Centroid.Y - circle.Centroid.Y) / d;
double cosTheta = (result.Centroid.X - circle.Centroid.X) / d;
double newX = result.Centroid.X + x * cosTheta;
double newY = result.Centroid.Y + x * sinTheta;
result.Centroid = new Point(newX, newY);
2023-04-05 16:05:03 +08:00
}
2023-04-25 11:58:41 +08:00
//判断是否画外切圆
x = Math.Abs(circle.R - shape.Width / 2.0) - d;
2023-12-22 00:14:15 +08:00
if (Math.Abs(x) / shape.Width < 0.1) {
2023-04-25 11:58:41 +08:00
double sinTheta = (result.Centroid.Y - circle.Centroid.Y) / d;
double cosTheta = (result.Centroid.X - circle.Centroid.X) / d;
double newX = result.Centroid.X + x * cosTheta;
double newY = result.Centroid.Y + x * sinTheta;
result.Centroid = new Point(newX, newY);
2023-04-05 16:05:03 +08:00
}
}
}
2023-04-25 11:58:41 +08:00
Point iniP = new Point(result.Centroid.X - shape.Width / 2, result.Centroid.Y - shape.Height / 2);
Point endP = new Point(result.Centroid.X + shape.Width / 2, result.Centroid.Y + shape.Height / 2);
var pointList = GenerateEllipseGeometry(iniP, endP);
var point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
var stroke = new Stroke(point) {
2023-04-25 11:58:41 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
circles.Add(new Circle(result.Centroid, shape.Width / 2.0, stroke));
SetNewBackupOfStroke();
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeRecognition;
2023-04-25 11:58:41 +08:00
inkCanvas.Strokes.Remove(result.InkDrawingNode.Strokes);
inkCanvas.Strokes.Add(stroke);
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.UserInput;
2023-04-25 11:58:41 +08:00
newStrokes = new StrokeCollection();
}
2023-12-22 00:14:15 +08:00
} else if (result.InkDrawingNode.GetShapeName().Contains("Ellipse")) {
2023-04-25 11:58:41 +08:00
var shape = result.InkDrawingNode.GetShape();
//var shape1 = result.InkDrawingNode.GetShape();
//shape1.Fill = Brushes.Gray;
//Canvas.Children.Add(shape1);
var p = result.InkDrawingNode.HotPoints;
double a = GetDistance(p[0], p[2]) / 2; //长半轴
double b = GetDistance(p[1], p[3]) / 2; //短半轴
2023-12-22 00:14:15 +08:00
if (a < b) {
2023-04-25 11:58:41 +08:00
double t = a;
a = b;
b = t;
}
2023-04-05 16:05:03 +08:00
2023-04-25 11:58:41 +08:00
result.Centroid = new Point((p[0].X + p[2].X) / 2, (p[0].Y + p[2].Y) / 2);
bool needRotation = true;
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
if (shape.Width > 75 || shape.Height > 75 && p.Count == 4) {
2023-04-25 11:58:41 +08:00
Point iniP = new Point(result.Centroid.X - shape.Width / 2, result.Centroid.Y - shape.Height / 2);
Point endP = new Point(result.Centroid.X + shape.Width / 2, result.Centroid.Y + shape.Height / 2);
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
foreach (Circle circle in circles) {
2023-04-25 11:58:41 +08:00
//判断是否画同心椭圆
if (Math.Abs(result.Centroid.X - circle.Centroid.X) / a < 0.2 &&
2023-12-22 00:14:15 +08:00
Math.Abs(result.Centroid.Y - circle.Centroid.Y) / a < 0.2) {
2023-04-25 11:58:41 +08:00
result.Centroid = circle.Centroid;
iniP = new Point(result.Centroid.X - shape.Width / 2, result.Centroid.Y - shape.Height / 2);
endP = new Point(result.Centroid.X + shape.Width / 2, result.Centroid.Y + shape.Height / 2);
2023-04-05 16:05:03 +08:00
2023-04-25 11:58:41 +08:00
//再判断是否与圆相切
2023-12-22 00:14:15 +08:00
if (Math.Abs(a - circle.R) / a < 0.2) {
if (shape.Width >= shape.Height) {
2023-04-25 11:58:41 +08:00
iniP.X = result.Centroid.X - circle.R;
endP.X = result.Centroid.X + circle.R;
iniP.Y = result.Centroid.Y - b;
endP.Y = result.Centroid.Y + b;
2023-12-22 00:14:15 +08:00
} else {
2023-04-25 11:58:41 +08:00
iniP.Y = result.Centroid.Y - circle.R;
endP.Y = result.Centroid.Y + circle.R;
iniP.X = result.Centroid.X - a;
endP.X = result.Centroid.X + a;
}
2023-04-05 16:05:03 +08:00
}
2023-04-25 11:58:41 +08:00
break;
2023-12-22 00:14:15 +08:00
} else if (Math.Abs(result.Centroid.X - circle.Centroid.X) / a < 0.2) {
2023-04-25 11:58:41 +08:00
double sinTheta = Math.Abs(circle.Centroid.Y - result.Centroid.Y) / circle.R;
double cosTheta = Math.Sqrt(1 - sinTheta * sinTheta);
double newA = circle.R * cosTheta;
2023-12-22 00:14:15 +08:00
if (circle.R * sinTheta / circle.R < 0.9 && a / b > 2 && Math.Abs(newA - a) / newA < 0.3) {
2023-04-25 11:58:41 +08:00
iniP.X = circle.Centroid.X - newA;
endP.X = circle.Centroid.X + newA;
iniP.Y = result.Centroid.Y - newA / 5;
endP.Y = result.Centroid.Y + newA / 5;
2023-04-05 16:05:03 +08:00
2023-04-25 11:58:41 +08:00
double topB = endP.Y - iniP.Y;
2023-04-05 16:05:03 +08:00
2023-04-25 11:58:41 +08:00
SetNewBackupOfStroke();
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeRecognition;
2023-04-25 11:58:41 +08:00
inkCanvas.Strokes.Remove(result.InkDrawingNode.Strokes);
newStrokes = new StrokeCollection();
2023-04-05 16:05:03 +08:00
2023-04-25 11:58:41 +08:00
var _pointList = GenerateEllipseGeometry(iniP, endP, false, true);
var _point = new StylusPointCollection(_pointList);
2023-12-22 00:14:15 +08:00
var _stroke = new Stroke(_point) {
2023-04-25 11:58:41 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
var _dashedLineStroke = GenerateDashedLineEllipseStrokeCollection(iniP, endP, true, false);
StrokeCollection strokes = new StrokeCollection()
{
_stroke,
_dashedLineStroke
};
inkCanvas.Strokes.Add(strokes);
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.UserInput;
2023-04-25 11:58:41 +08:00
return;
}
2023-12-22 00:14:15 +08:00
} else if (Math.Abs(result.Centroid.Y - circle.Centroid.Y) / a < 0.2) {
2023-04-25 11:58:41 +08:00
double cosTheta = Math.Abs(circle.Centroid.X - result.Centroid.X) / circle.R;
double sinTheta = Math.Sqrt(1 - cosTheta * cosTheta);
double newA = circle.R * sinTheta;
2023-12-22 00:14:15 +08:00
if (circle.R * sinTheta / circle.R < 0.9 && a / b > 2 && Math.Abs(newA - a) / newA < 0.3) {
2023-04-25 11:58:41 +08:00
iniP.X = result.Centroid.X - newA / 5;
endP.X = result.Centroid.X + newA / 5;
iniP.Y = circle.Centroid.Y - newA;
endP.Y = circle.Centroid.Y + newA;
needRotation = false;
}
2023-04-05 16:05:03 +08:00
}
}
2023-04-25 11:58:41 +08:00
//纠正垂直与水平关系
var newPoints = FixPointsDirection(p[0], p[2]);
p[0] = newPoints[0];
p[2] = newPoints[1];
newPoints = FixPointsDirection(p[1], p[3]);
p[1] = newPoints[0];
p[3] = newPoints[1];
var pointList = GenerateEllipseGeometry(iniP, endP);
var point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
var stroke = new Stroke(point) {
2023-04-25 11:58:41 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
if (needRotation) {
2023-04-25 11:58:41 +08:00
Matrix m = new Matrix();
FrameworkElement fe = e.Source as FrameworkElement;
double tanTheta = (p[2].Y - p[0].Y) / (p[2].X - p[0].X);
double theta = Math.Atan(tanTheta);
m.RotateAt(theta * 180.0 / Math.PI, result.Centroid.X, result.Centroid.Y);
stroke.Transform(m, false);
}
2023-04-05 16:05:03 +08:00
2023-04-25 11:58:41 +08:00
SetNewBackupOfStroke();
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeRecognition;
2023-04-25 11:58:41 +08:00
inkCanvas.Strokes.Remove(result.InkDrawingNode.Strokes);
inkCanvas.Strokes.Add(stroke);
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.UserInput;
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
2023-04-25 11:58:41 +08:00
newStrokes = new StrokeCollection();
}
2023-12-22 00:14:15 +08:00
} else if (result.InkDrawingNode.GetShapeName().Contains("Triangle")) {
2023-04-25 11:58:41 +08:00
var shape = result.InkDrawingNode.GetShape();
var p = result.InkDrawingNode.HotPoints;
if ((Math.Max(Math.Max(p[0].X, p[1].X), p[2].X) - Math.Min(Math.Min(p[0].X, p[1].X), p[2].X) >= 100 ||
2023-12-22 00:14:15 +08:00
Math.Max(Math.Max(p[0].Y, p[1].Y), p[2].Y) - Math.Min(Math.Min(p[0].Y, p[1].Y), p[2].Y) >= 100) && result.InkDrawingNode.HotPoints.Count == 3) {
2023-04-25 11:58:41 +08:00
//纠正垂直与水平关系
var newPoints = FixPointsDirection(p[0], p[1]);
p[0] = newPoints[0];
p[1] = newPoints[1];
newPoints = FixPointsDirection(p[0], p[2]);
p[0] = newPoints[0];
p[2] = newPoints[1];
newPoints = FixPointsDirection(p[1], p[2]);
p[1] = newPoints[0];
p[2] = newPoints[1];
var pointList = p.ToList();
//pointList.Add(p[0]);
var point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
var stroke = new Stroke(GenerateFakePressureTriangle(point)) {
2023-04-25 11:58:41 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
SetNewBackupOfStroke();
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeRecognition;
2023-04-25 11:58:41 +08:00
inkCanvas.Strokes.Remove(result.InkDrawingNode.Strokes);
inkCanvas.Strokes.Add(stroke);
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.UserInput;
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
2023-04-25 11:58:41 +08:00
newStrokes = new StrokeCollection();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
} else if (result.InkDrawingNode.GetShapeName().Contains("Rectangle") ||
result.InkDrawingNode.GetShapeName().Contains("Diamond") ||
result.InkDrawingNode.GetShapeName().Contains("Parallelogram") ||
result.InkDrawingNode.GetShapeName().Contains("Square")) {
2023-04-25 11:58:41 +08:00
var shape = result.InkDrawingNode.GetShape();
var p = result.InkDrawingNode.HotPoints;
if ((Math.Max(Math.Max(Math.Max(p[0].X, p[1].X), p[2].X), p[3].X) - Math.Min(Math.Min(Math.Min(p[0].X, p[1].X), p[2].X), p[3].X) >= 100 ||
2023-12-22 00:14:15 +08:00
Math.Max(Math.Max(Math.Max(p[0].Y, p[1].Y), p[2].Y), p[3].Y) - Math.Min(Math.Min(Math.Min(p[0].Y, p[1].Y), p[2].Y), p[3].Y) >= 100) && result.InkDrawingNode.HotPoints.Count == 4) {
2023-04-25 11:58:41 +08:00
//纠正垂直与水平关系
var newPoints = FixPointsDirection(p[0], p[1]);
p[0] = newPoints[0];
p[1] = newPoints[1];
newPoints = FixPointsDirection(p[1], p[2]);
p[1] = newPoints[0];
p[2] = newPoints[1];
newPoints = FixPointsDirection(p[2], p[3]);
p[2] = newPoints[0];
p[3] = newPoints[1];
newPoints = FixPointsDirection(p[3], p[0]);
p[3] = newPoints[0];
p[0] = newPoints[1];
var pointList = p.ToList();
pointList.Add(p[0]);
var point = new StylusPointCollection(pointList);
2023-12-22 00:14:15 +08:00
var stroke = new Stroke(GenerateFakePressureRectangle(point)) {
2023-04-25 11:58:41 +08:00
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
SetNewBackupOfStroke();
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.ShapeRecognition;
2023-04-25 11:58:41 +08:00
inkCanvas.Strokes.Remove(result.InkDrawingNode.Strokes);
inkCanvas.Strokes.Add(stroke);
2023-05-07 17:54:41 +08:00
_currentCommitType = CommitReason.UserInput;
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
2023-04-25 11:58:41 +08:00
newStrokes = new StrokeCollection();
}
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
}
2023-04-25 11:58:41 +08:00
InkToShapeProcess();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
foreach (StylusPoint stylusPoint in e.Stroke.StylusPoints) {
// 检查是否是压感笔书写
//if (stylusPoint.PressureFactor != 0.5 && stylusPoint.PressureFactor != 0)
if ((stylusPoint.PressureFactor > 0.501 || stylusPoint.PressureFactor < 0.5) && stylusPoint.PressureFactor != 0) {
2023-04-05 16:05:03 +08:00
return;
}
}
2023-12-22 00:14:15 +08:00
try {
if (e.Stroke.StylusPoints.Count > 3) {
2023-04-05 16:05:03 +08:00
Random random = new Random();
double _speed = GetPointSpeed(e.Stroke.StylusPoints[random.Next(0, e.Stroke.StylusPoints.Count - 1)].ToPoint(), e.Stroke.StylusPoints[random.Next(0, e.Stroke.StylusPoints.Count - 1)].ToPoint(), e.Stroke.StylusPoints[random.Next(0, e.Stroke.StylusPoints.Count - 1)].ToPoint());
RandWindow.randSeed = (int)(_speed * 100000 * 1000);
}
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
switch (Settings.Canvas.InkStyle) {
2023-04-05 16:05:03 +08:00
case 1:
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
StylusPointCollection stylusPoints = new StylusPointCollection();
int n = e.Stroke.StylusPoints.Count - 1;
string s = "";
2023-12-22 00:14:15 +08:00
for (int i = 0; i <= n; i++) {
2023-04-05 16:05:03 +08:00
double speed = GetPointSpeed(e.Stroke.StylusPoints[Math.Max(i - 1, 0)].ToPoint(), e.Stroke.StylusPoints[i].ToPoint(), e.Stroke.StylusPoints[Math.Min(i + 1, n)].ToPoint());
s += speed.ToString() + "\t";
StylusPoint point = new StylusPoint();
2023-12-22 00:14:15 +08:00
if (speed >= 0.25) {
2023-04-05 16:05:03 +08:00
point.PressureFactor = (float)(0.5 - 0.3 * (Math.Min(speed, 1.5) - 0.3) / 1.2);
2023-12-22 00:14:15 +08:00
} else if (speed >= 0.05) {
2023-04-05 16:05:03 +08:00
point.PressureFactor = (float)0.5;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
point.PressureFactor = (float)(0.5 + 0.4 * (0.05 - speed) / 0.05);
}
point.X = e.Stroke.StylusPoints[i].X;
point.Y = e.Stroke.StylusPoints[i].Y;
stylusPoints.Add(point);
}
e.Stroke.StylusPoints = stylusPoints;
2023-12-22 00:14:15 +08:00
} catch {
2023-04-05 16:05:03 +08:00
}
break;
case 0:
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
StylusPointCollection stylusPoints = new StylusPointCollection();
int n = e.Stroke.StylusPoints.Count - 1;
double pressure = 0.1;
int x = 10;
if (n == 1) return;
2023-12-22 00:14:15 +08:00
if (n >= x) {
for (int i = 0; i < n - x; i++) {
2023-04-05 16:05:03 +08:00
StylusPoint point = new StylusPoint();
point.PressureFactor = (float)0.5;
point.X = e.Stroke.StylusPoints[i].X;
point.Y = e.Stroke.StylusPoints[i].Y;
stylusPoints.Add(point);
}
2023-12-22 00:14:15 +08:00
for (int i = n - x; i <= n; i++) {
2023-04-05 16:05:03 +08:00
StylusPoint point = new StylusPoint();
point.PressureFactor = (float)((0.5 - pressure) * (n - i) / x + pressure);
point.X = e.Stroke.StylusPoints[i].X;
point.Y = e.Stroke.StylusPoints[i].Y;
stylusPoints.Add(point);
}
2023-12-22 00:14:15 +08:00
} else {
for (int i = 0; i <= n; i++) {
2023-04-05 16:05:03 +08:00
StylusPoint point = new StylusPoint();
point.PressureFactor = (float)(0.4 * (n - i) / n + pressure);
point.X = e.Stroke.StylusPoints[i].X;
point.Y = e.Stroke.StylusPoints[i].Y;
stylusPoints.Add(point);
}
}
e.Stroke.StylusPoints = stylusPoints;
2023-12-22 00:14:15 +08:00
} catch {
2023-04-05 16:05:03 +08:00
}
break;
case 3: //根据 mode == 0 改写,目前暂未完成
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
StylusPointCollection stylusPoints = new StylusPointCollection();
int n = e.Stroke.StylusPoints.Count - 1;
double pressure = 0.1;
int x = 8;
2023-12-22 00:14:15 +08:00
if (lastTouchDownTime < lastTouchUpTime) {
2023-04-05 16:05:03 +08:00
double k = (lastTouchUpTime - lastTouchDownTime) / (n + 1); // 每个点之间间隔 k 毫秒
x = (int)(1000 / k); // 取 1000 ms 内的点
}
2023-12-22 00:14:15 +08:00
if (n >= x) {
for (int i = 0; i < n - x; i++) {
2023-04-05 16:05:03 +08:00
StylusPoint point = new StylusPoint();
point.PressureFactor = (float)0.5;
point.X = e.Stroke.StylusPoints[i].X;
point.Y = e.Stroke.StylusPoints[i].Y;
stylusPoints.Add(point);
}
2023-12-22 00:14:15 +08:00
for (int i = n - x; i <= n; i++) {
2023-04-05 16:05:03 +08:00
StylusPoint point = new StylusPoint();
point.PressureFactor = (float)((0.5 - pressure) * (n - i) / x + pressure);
point.X = e.Stroke.StylusPoints[i].X;
point.Y = e.Stroke.StylusPoints[i].Y;
stylusPoints.Add(point);
}
2023-12-22 00:14:15 +08:00
} else {
for (int i = 0; i <= n; i++) {
2023-04-05 16:05:03 +08:00
StylusPoint point = new StylusPoint();
point.PressureFactor = (float)(0.4 * (n - i) / n + pressure);
point.X = e.Stroke.StylusPoints[i].X;
point.Y = e.Stroke.StylusPoints[i].Y;
stylusPoints.Add(point);
}
}
e.Stroke.StylusPoints = stylusPoints;
2023-12-22 00:14:15 +08:00
} catch {
2023-04-05 16:05:03 +08:00
}
break;
}
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void SetNewBackupOfStroke() {
2023-04-05 16:05:03 +08:00
lastTouchDownStrokeCollection = inkCanvas.Strokes.Clone();
int whiteboardIndex = CurrentWhiteboardIndex;
2023-12-22 00:14:15 +08:00
if (currentMode == 0) {
2023-04-05 16:05:03 +08:00
whiteboardIndex = 0;
}
strokeCollections[whiteboardIndex] = lastTouchDownStrokeCollection;
}
2023-12-22 00:14:15 +08:00
public double GetDistance(Point point1, Point point2) {
2023-04-05 16:05:03 +08:00
return Math.Sqrt((point1.X - point2.X) * (point1.X - point2.X) + (point1.Y - point2.Y) * (point1.Y - point2.Y));
}
2023-12-22 00:14:15 +08:00
public double GetPointSpeed(Point point1, Point point2, Point point3) {
2023-04-05 16:05:03 +08:00
return (Math.Sqrt((point1.X - point2.X) * (point1.X - point2.X) + (point1.Y - point2.Y) * (point1.Y - point2.Y))
+ Math.Sqrt((point3.X - point2.X) * (point3.X - point2.X) + (point3.Y - point2.Y) * (point3.Y - point2.Y)))
/ 20;
}
2023-12-22 00:14:15 +08:00
public Point[] FixPointsDirection(Point p1, Point p2) {
if (Math.Abs(p1.X - p2.X) / Math.Abs(p1.Y - p2.Y) > 8) {
2023-04-05 16:05:03 +08:00
//水平
double x = Math.Abs(p1.Y - p2.Y) / 2;
2023-12-22 00:14:15 +08:00
if (p1.Y > p2.Y) {
2023-04-05 16:05:03 +08:00
p1.Y -= x;
p2.Y += x;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
p1.Y += x;
p2.Y -= x;
}
2023-12-22 00:14:15 +08:00
} else if (Math.Abs(p1.Y - p2.Y) / Math.Abs(p1.X - p2.X) > 8) {
2023-04-05 16:05:03 +08:00
//垂直
double x = Math.Abs(p1.X - p2.X) / 2;
2023-12-22 00:14:15 +08:00
if (p1.X > p2.X) {
2023-04-05 16:05:03 +08:00
p1.X -= x;
p2.X += x;
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
p1.X += x;
p2.X -= x;
}
}
return new Point[2] { p1, p2 };
}
2023-12-22 00:14:15 +08:00
public StylusPointCollection GenerateFakePressureTriangle(StylusPointCollection points) {
2023-04-05 16:05:03 +08:00
var newPoint = new StylusPointCollection();
newPoint.Add(new StylusPoint(points[0].X, points[0].Y, (float)0.4));
var cPoint = GetCenterPoint(points[0], points[1]);
newPoint.Add(new StylusPoint(cPoint.X, cPoint.Y, (float)0.8));
newPoint.Add(new StylusPoint(points[1].X, points[1].Y, (float)0.4));
newPoint.Add(new StylusPoint(points[1].X, points[1].Y, (float)0.4));
cPoint = GetCenterPoint(points[1], points[2]);
newPoint.Add(new StylusPoint(cPoint.X, cPoint.Y, (float)0.8));
newPoint.Add(new StylusPoint(points[2].X, points[2].Y, (float)0.4));
newPoint.Add(new StylusPoint(points[2].X, points[2].Y, (float)0.4));
cPoint = GetCenterPoint(points[2], points[0]);
newPoint.Add(new StylusPoint(cPoint.X, cPoint.Y, (float)0.8));
newPoint.Add(new StylusPoint(points[0].X, points[0].Y, (float)0.4));
return newPoint;
}
2023-12-22 00:14:15 +08:00
public StylusPointCollection GenerateFakePressureRectangle(StylusPointCollection points) {
2023-04-05 16:05:03 +08:00
var newPoint = new StylusPointCollection();
newPoint.Add(new StylusPoint(points[0].X, points[0].Y, (float)0.4));
var cPoint = GetCenterPoint(points[0], points[1]);
newPoint.Add(new StylusPoint(cPoint.X, cPoint.Y, (float)0.8));
newPoint.Add(new StylusPoint(points[1].X, points[1].Y, (float)0.4));
newPoint.Add(new StylusPoint(points[1].X, points[1].Y, (float)0.4));
cPoint = GetCenterPoint(points[1], points[2]);
newPoint.Add(new StylusPoint(cPoint.X, cPoint.Y, (float)0.8));
newPoint.Add(new StylusPoint(points[2].X, points[2].Y, (float)0.4));
newPoint.Add(new StylusPoint(points[2].X, points[2].Y, (float)0.4));
cPoint = GetCenterPoint(points[2], points[3]);
newPoint.Add(new StylusPoint(cPoint.X, cPoint.Y, (float)0.8));
newPoint.Add(new StylusPoint(points[3].X, points[3].Y, (float)0.4));
newPoint.Add(new StylusPoint(points[3].X, points[3].Y, (float)0.4));
cPoint = GetCenterPoint(points[3], points[0]);
newPoint.Add(new StylusPoint(cPoint.X, cPoint.Y, (float)0.8));
newPoint.Add(new StylusPoint(points[0].X, points[0].Y, (float)0.4));
return newPoint;
}
2023-12-22 00:14:15 +08:00
public Point GetCenterPoint(Point point1, Point point2) {
2023-04-05 16:05:03 +08:00
return new Point((point1.X + point2.X) / 2, (point1.Y + point2.Y) / 2);
}
2023-12-22 00:14:15 +08:00
public StylusPoint GetCenterPoint(StylusPoint point1, StylusPoint point2) {
2023-04-05 16:05:03 +08:00
return new StylusPoint((point1.X + point2.X) / 2, (point1.Y + point2.Y) / 2);
}
#endregion
#region Functions
/// <summary>
/// 传入域名返回对应的IP
/// </summary>
/// <param name="domainName">域名</param>
/// <returns></returns>
2023-12-22 00:14:15 +08:00
public static string GetIp(string domainName) {
2023-04-05 16:05:03 +08:00
domainName = domainName.Replace("http://", "").Replace("https://", "");
IPHostEntry hostEntry = Dns.GetHostEntry(domainName);
IPEndPoint ipEndPoint = new IPEndPoint(hostEntry.AddressList[0], 0);
return ipEndPoint.Address.ToString();
}
2023-12-22 00:14:15 +08:00
public static string GetWebClient(string url) {
2023-04-05 16:05:03 +08:00
HttpWebRequest myrq = (HttpWebRequest)WebRequest.Create(url);
myrq.Proxy = null;
myrq.KeepAlive = false;
myrq.Timeout = 30 * 1000;
myrq.Method = "Get";
myrq.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
myrq.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 UBrowser/6.2.4098.3 Safari/537.36";
HttpWebResponse myrp;
2023-12-22 00:14:15 +08:00
try {
2023-04-05 16:05:03 +08:00
myrp = (HttpWebResponse)myrq.GetResponse();
2023-12-22 00:14:15 +08:00
} catch (WebException ex) {
2023-04-05 16:05:03 +08:00
myrp = (HttpWebResponse)ex.Response;
}
2023-12-22 00:14:15 +08:00
if (myrp.StatusCode != HttpStatusCode.OK) {
2023-04-05 16:05:03 +08:00
return "null";
}
2023-12-22 00:14:15 +08:00
using (StreamReader sr = new StreamReader(myrp.GetResponseStream())) {
2023-04-05 16:05:03 +08:00
return sr.ReadToEnd();
}
}
#region
/// <summary>
/// 开机自启创建
/// </summary>
/// <param name="exeName">程序名称</param>
/// <returns></returns>
2023-12-22 00:14:15 +08:00
public static bool StartAutomaticallyCreate(string exeName) {
try {
2023-04-05 16:05:03 +08:00
WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\" + exeName + ".lnk");
//设置快捷方式的目标所在的位置(源程序完整路径)
shortcut.TargetPath = System.Windows.Forms.Application.ExecutablePath;
//应用程序的工作目录
//当用户没有指定一个具体的目录时,快捷方式的目标应用程序将使用该属性所指定的目录来装载或保存文件。
shortcut.WorkingDirectory = System.Environment.CurrentDirectory;
//目标应用程序窗口类型(1.Normal window普通窗口,3.Maximized最大化窗口,7.Minimized最小化)
shortcut.WindowStyle = 1;
//快捷方式的描述
shortcut.Description = exeName + "_Ink";
//设置快捷键(如果有必要的话.)
//shortcut.Hotkey = "CTRL+ALT+D";
shortcut.Save();
return true;
2023-12-22 00:14:15 +08:00
} catch (Exception) { }
2023-04-05 16:05:03 +08:00
return false;
}
/// <summary>
/// 开机自启删除
/// </summary>
/// <param name="exeName">程序名称</param>
/// <returns></returns>
2023-12-22 00:14:15 +08:00
public static bool StartAutomaticallyDel(string exeName) {
try {
2023-04-05 16:05:03 +08:00
System.IO.File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\" + exeName + ".lnk");
return true;
2023-12-22 00:14:15 +08:00
} catch (Exception) { }
2023-04-05 16:05:03 +08:00
return false;
}
#endregion
2023-05-29 12:35:52 +08:00
#region Auto Theme
Color toolBarForegroundColor = Color.FromRgb(102, 102, 102);
2023-12-22 00:14:15 +08:00
private void SetTheme(string theme) {
if (theme == "Light") {
ResourceDictionary rd1 = new ResourceDictionary() { Source = new Uri("Resources/Styles/Light.xaml", UriKind.Relative) };
Application.Current.Resources.MergedDictionaries.Add(rd1);
ResourceDictionary rd2 = new ResourceDictionary() { Source = new Uri("Resources/DrawShapeImageDictionary.xaml", UriKind.Relative) };
Application.Current.Resources.MergedDictionaries.Add(rd2);
ResourceDictionary rd3 = new ResourceDictionary() { Source = new Uri("Resources/SeewoImageDictionary.xaml", UriKind.Relative) };
Application.Current.Resources.MergedDictionaries.Add(rd3);
ResourceDictionary rd4 = new ResourceDictionary() { Source = new Uri("Resources/IconImageDictionary.xaml", UriKind.Relative) };
Application.Current.Resources.MergedDictionaries.Add(rd4);
ThemeManager.SetRequestedTheme(window, ElementTheme.Light);
2023-05-29 12:35:52 +08:00
toolBarForegroundColor = (Color)Application.Current.FindResource("ToolBarForegroundColor");
2023-12-22 00:14:15 +08:00
} else if (theme == "Dark") {
ResourceDictionary rd1 = new ResourceDictionary() { Source = new Uri("Resources/Styles/Dark.xaml", UriKind.Relative) };
Application.Current.Resources.MergedDictionaries.Add(rd1);
ResourceDictionary rd2 = new ResourceDictionary() { Source = new Uri("Resources/DrawShapeImageDictionary.xaml", UriKind.Relative) };
Application.Current.Resources.MergedDictionaries.Add(rd2);
ResourceDictionary rd3 = new ResourceDictionary() { Source = new Uri("Resources/SeewoImageDictionary.xaml", UriKind.Relative) };
Application.Current.Resources.MergedDictionaries.Add(rd3);
ResourceDictionary rd4 = new ResourceDictionary() { Source = new Uri("Resources/IconImageDictionary.xaml", UriKind.Relative) };
Application.Current.Resources.MergedDictionaries.Add(rd4);
ThemeManager.SetRequestedTheme(window, ElementTheme.Dark);
2023-05-29 12:35:52 +08:00
toolBarForegroundColor = (Color)Application.Current.FindResource("ToolBarForegroundColor");
}
2023-12-22 00:14:15 +08:00
//SymbolIconSelect.Foreground = new SolidColorBrush(toolBarForegroundColor);
//SymbolIconDelete.Foreground = new SolidColorBrush(toolBarForegroundColor);
}
2023-05-29 12:35:52 +08:00
2023-12-22 00:14:15 +08:00
private void SystemEvents_UserPreferenceChanged(object sender, Microsoft.Win32.UserPreferenceChangedEventArgs e) {
switch (Settings.Appearance.Theme) {
case 0:
SetTheme("Light");
break;
case 1:
SetTheme("Dark");
break;
case 2:
if (IsSystemThemeLight()) SetTheme("Light");
else SetTheme("Dark");
break;
}
}
2023-05-29 12:35:52 +08:00
2023-12-22 00:14:15 +08:00
private bool IsSystemThemeLight() {
bool light = false;
2023-12-22 00:14:15 +08:00
try {
RegistryKey registryKey = Registry.CurrentUser;
RegistryKey themeKey = registryKey.OpenSubKey("software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize");
int keyValue = 0;
2023-12-22 00:14:15 +08:00
if (themeKey != null) {
keyValue = (int)themeKey.GetValue("SystemUsesLightTheme");
}
if (keyValue == 1) light = true;
2023-12-22 00:14:15 +08:00
} catch { }
return light;
}
#endregion
2023-04-05 16:05:03 +08:00
#endregion Functions
#region Screenshot
2023-12-22 00:14:15 +08:00
private void BtnScreenshot_Click(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
bool isHideNotification = false;
if (sender is bool) isHideNotification = (bool)sender;
GridNotifications.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
new Thread(new ThreadStart(() => {
2023-04-05 16:05:03 +08:00
Thread.Sleep(20);
2023-12-22 00:14:15 +08:00
try {
Application.Current.Dispatcher.Invoke(() => {
2023-04-05 16:05:03 +08:00
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible)
SaveScreenShot(isHideNotification, $"{pptName}/{previousSlideID}_{DateTime.Now:HH-mm-ss}");
else
SaveScreenShot(isHideNotification);
});
2023-12-22 00:14:15 +08:00
} catch {
if (!isHideNotification) {
2023-04-05 16:05:03 +08:00
ShowNotification("截图保存失败");
}
}
2023-12-22 00:14:15 +08:00
try {
Application.Current.Dispatcher.Invoke(() => {
2023-04-05 16:05:03 +08:00
if (inkCanvas.Visibility != Visibility.Visible || inkCanvas.Strokes.Count == 0) return;
SaveInkCanvasStrokes(false);
});
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
if (isHideNotification) {
Application.Current.Dispatcher.Invoke(() => {
BtnClear_Click(null, null);
2023-04-05 16:05:03 +08:00
});
}
})).Start();
}
2023-12-22 00:14:15 +08:00
private void SaveScreenShot(bool isHideNotification, string fileName = null) {
2023-04-05 16:05:03 +08:00
System.Drawing.Rectangle rc = System.Windows.Forms.SystemInformation.VirtualScreen;
var bitmap = new System.Drawing.Bitmap(rc.Width, rc.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
2023-12-22 00:14:15 +08:00
using (System.Drawing.Graphics memoryGrahics = System.Drawing.Graphics.FromImage(bitmap)) {
2023-04-05 16:05:03 +08:00
memoryGrahics.CopyFromScreen(rc.X, rc.Y, 0, 0, rc.Size, System.Drawing.CopyPixelOperation.SourceCopy);
}
2023-12-22 00:14:15 +08:00
if (Settings.Automation.IsSaveScreenshotsInDateFolders) {
if (string.IsNullOrWhiteSpace(fileName)) fileName = DateTime.Now.ToString("HH-mm-ss");
string savePath;
//var savePath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)}\Ink Canvas Screenshots\{DateTime.Now.Date:yyyyMMdd}\{fileName}.png";
try {
savePath = $@"D:\Ink Canvas\Auto Saved - Screenshots\{DateTime.Now.Date:yyyyMMdd}\{fileName}.png";
} catch (IOException) {
savePath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)}\Ink Canvas Screenshots\{DateTime.Now.Date:yyyyMMdd}\{fileName}.png";
}
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
if (!Directory.Exists(Path.GetDirectoryName(savePath))) {
Directory.CreateDirectory(Path.GetDirectoryName(savePath));
}
2023-04-05 16:05:03 +08:00
bitmap.Save(savePath, ImageFormat.Png);
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
if (!isHideNotification) {
ShowNotification("截图成功保存至 " + savePath);
}
2023-12-22 00:14:15 +08:00
} else {
string savePath;
try {
savePath = @"D:\Ink Canvas\Auto Saved - Screenshots";
} catch (IOException) {
savePath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + @"\Ink Canvas\Auto Saved - Screenshots";
}
if (!Directory.Exists(savePath)) {
Directory.CreateDirectory(savePath);
}
2023-12-22 00:14:15 +08:00
bitmap.Save(savePath + @"\" + DateTime.Now.ToString("u").Replace(':', '-') + ".png", ImageFormat.Png);
2023-12-22 00:14:15 +08:00
if (!isHideNotification) {
ShowNotification("截图成功保存至 " + savePath + @"\" + DateTime.Now.ToString("u").Replace(':', '-') + ".png");
}
2023-04-05 16:05:03 +08:00
}
}
2023-12-22 00:14:15 +08:00
private void SaveScreenShotToDesktop() {
System.Drawing.Rectangle rc = System.Windows.Forms.SystemInformation.VirtualScreen;
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);
}
string savePath;
try {
savePath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
} catch (IOException) {
savePath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + @"\Ink Canvas\Auto Saved - Screenshots";
}
bitmap.Save(savePath + @"\" + DateTime.Now.ToString("u").Replace(':', '-') + ".png", ImageFormat.Png);
ShowNotification("截图成功保存至【桌面" + @"\" + DateTime.Now.ToString("u").Replace(':', '-') + ".png】");
}
2023-04-05 16:05:03 +08:00
#endregion
#region Notification
int lastNotificationShowTime = 0;
int notificationShowTime = 2500;
2023-12-22 00:14:15 +08:00
public static void ShowNewMessage(string notice, bool isShowImmediately = true) {
2023-09-24 23:15:30 +08:00
(Application.Current?.Windows.Cast<Window>().FirstOrDefault(window => window is MainWindow) as MainWindow)?.ShowNotification(notice, isShowImmediately);
}
2023-12-22 00:14:15 +08:00
public void ShowNotification(string notice, bool isShowImmediately = true) {
2023-04-05 16:05:03 +08:00
lastNotificationShowTime = Environment.TickCount;
TextBlockNotice.Text = notice;
2023-12-22 00:14:15 +08:00
AnimationHelper.ShowWithSlideFromBottomAndFade(GridNotifications);
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
new Thread(new ThreadStart(() => {
Thread.Sleep(notificationShowTime + 300);
if (Environment.TickCount - lastNotificationShowTime >= notificationShowTime) {
Application.Current.Dispatcher.Invoke(() => {
AnimationHelper.HideWithSlideAndFade(GridNotifications);
2023-04-05 16:05:03 +08:00
});
}
})).Start();
}
2023-12-22 00:14:15 +08:00
private void AppendNotification(string notice) {
2023-04-05 16:05:03 +08:00
TextBlockNotice.Text = TextBlockNotice.Text + Environment.NewLine + notice;
}
#endregion
2023-12-22 00:14:15 +08:00
#region Float Bar
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
private void HideSubPanelsImmediately() {
BorderTools.Visibility = Visibility.Collapsed;
BorderTools.Visibility = Visibility.Collapsed;
BoardBorderTools.Visibility = Visibility.Collapsed;
PenPalette.Visibility = Visibility.Collapsed;
BoardPenPalette.Visibility = Visibility.Collapsed;
BoardDeleteIcon.Visibility = Visibility.Collapsed;
BorderSettings.Visibility = Visibility.Collapsed;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private async void HideSubPanels(String mode = null, bool autoAlignCenter = false) {
AnimationHelper.HideWithSlideAndFade(BorderTools);
AnimationHelper.HideWithSlideAndFade(BoardBorderTools);
AnimationHelper.HideWithSlideAndFade(PenPalette);
AnimationHelper.HideWithSlideAndFade(BoardPenPalette);
AnimationHelper.HideWithSlideAndFade(BoardDeleteIcon);
AnimationHelper.HideWithSlideAndFade(BorderSettings, 0.5);
AnimationHelper.HideWithSlideAndFade(TwoFingerGestureBorder);
AnimationHelper.HideWithSlideAndFade(BoardTwoFingerGestureBorder);
if (ToggleSwitchDrawShapeBorderAutoHide.IsOn) {
AnimationHelper.HideWithSlideAndFade(BorderDrawShape);
AnimationHelper.HideWithSlideAndFade(BoardBorderDrawShape);
}
if (mode != null) {
if (mode != "clear") {
Pen_Icon.Background = null;
BoardPen.Background = new SolidColorBrush(Colors.LightGray);
Eraser_Icon.Background = null;
BoardEraser.Background = new SolidColorBrush(Colors.LightGray);
SymbolIconSelect.Background = null;
BoardSelect.Background = new SolidColorBrush(Colors.LightGray);
EraserByStrokes_Icon.Background = null;
BoardEraserByStrokes.Background = new SolidColorBrush(Colors.LightGray);
}
if (mode == "pen" || mode == "color") {
BoardPen.Background = new SolidColorBrush(Color.FromRgb(103, 156, 244));
Pen_Icon.Background = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/check-box-background.png"))) { Opacity = 0.75 };
/*
BitmapImage newImageSource = new BitmapImage();
newImageSource.BeginInit();
newImageSource.UriSource = new Uri("/Resources/Icons-Fluent/ic_fluent_color_24_regular.png", UriKind.RelativeOrAbsolute);
newImageSource.EndInit();
PenIcon.Source = newImageSource;
BoardPenIcon.Source = newImageSource;
*/
} else {
/*
BitmapImage newImageSource = new BitmapImage();
newImageSource.BeginInit();
newImageSource.UriSource = new Uri("/Resources/Icons-Fluent/ic_fluent_signature_24_regular.png", UriKind.RelativeOrAbsolute);
newImageSource.EndInit();
PenIcon.Source = newImageSource;
BoardPenIcon.Source = newImageSource;
*/
if (mode == "eraser") {
Eraser_Icon.Background = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/check-box-background.png"))) { Opacity = 0.75 };
BoardEraser.Background = new SolidColorBrush(Color.FromRgb(103, 156, 244));
//ChangeColorCheckPrompt(-1);
} else if (mode == "eraserByStrokes") {
EraserByStrokes_Icon.Background = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/check-box-background.png"))) { Opacity = 0.75 };
BoardEraserByStrokes.Background = new SolidColorBrush(Color.FromRgb(103, 156, 244));
//ChangeColorCheckPrompt(-1);
} else if (mode == "select") {
BoardSelect.Background = new SolidColorBrush(Color.FromRgb(103, 156, 244));
SymbolIconSelect.Background = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Resources/Icons-png/check-box-background.png"))) { Opacity = 0.75 };
//ChangeColorCheckPrompt(-1);
}
}
if (autoAlignCenter) // 控制居中
{
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) {
await Task.Delay(50);
ViewboxFloatingBarMarginAnimation(60);
} else if (Topmost == true) //非黑板
{
await Task.Delay(50);
ViewboxFloatingBarMarginAnimation(100);
} else //黑板
{
await Task.Delay(50);
ViewboxFloatingBarMarginAnimation(60);
}
}
}
await Task.Delay(150);
isHidingSubPanelsWhenInking = false;
}
private void BorderPenColorBlack_MouseUp(object sender, MouseButtonEventArgs e) {
BtnColorBlack_Click(null, null);
HideSubPanels();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BorderPenColorRed_MouseUp(object sender, MouseButtonEventArgs e) {
BtnColorRed_Click(null, null);
HideSubPanels();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void BorderPenColorGreen_MouseUp(object sender, MouseButtonEventArgs e) {
BtnColorGreen_Click(null, null);
2023-04-05 16:05:03 +08:00
HideSubPanels();
}
2023-12-22 00:14:15 +08:00
private void BorderPenColorBlue_MouseUp(object sender, MouseButtonEventArgs e) {
BtnColorBlue_Click(null, null);
2023-04-05 16:05:03 +08:00
HideSubPanels();
}
2023-12-22 00:14:15 +08:00
private void BorderPenColorYellow_MouseUp(object sender, MouseButtonEventArgs e) {
BtnColorYellow_Click(null, null);
2023-04-05 16:05:03 +08:00
HideSubPanels();
}
2023-12-22 00:14:15 +08:00
private void BorderPenColorWhite_MouseUp(object sender, MouseButtonEventArgs e) {
2023-04-05 16:05:03 +08:00
inkCanvas.DefaultDrawingAttributes.Color = StringToColor("#FFFEFEFE");
inkColor = 5;
ColorSwitchCheck();
HideSubPanels();
}
2023-12-22 00:14:15 +08:00
private void SymbolIconUndo_MouseUp(object sender, MouseButtonEventArgs e) {
if (lastBorderMouseDownObject != sender) return;
if (!BtnUndo.IsEnabled) return;
2023-04-05 16:05:03 +08:00
BtnUndo_Click(BtnUndo, null);
HideSubPanels();
}
2023-12-22 00:14:15 +08:00
private void SymbolIconRedo_MouseUp(object sender, MouseButtonEventArgs e) {
if (lastBorderMouseDownObject != sender) return;
if (!BtnRedo.IsEnabled) return;
2023-04-05 16:05:03 +08:00
BtnRedo_Click(BtnRedo, null);
HideSubPanels();
}
2023-12-22 00:14:15 +08:00
private async void SymbolIconCursor_Click(object sender, RoutedEventArgs e) {
if (currentMode != 0) {
2023-04-05 16:05:03 +08:00
ImageBlackboard_MouseUp(null, null);
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
BtnHideInkCanvas_Click(BtnHideInkCanvas, null);
2023-12-22 00:14:15 +08:00
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) {
/*
2023-04-05 16:05:03 +08:00
if (ViewboxFloatingBar.Margin == new Thickness((SystemParameters.PrimaryScreenWidth - ViewboxFloatingBar.ActualWidth) / 2, SystemParameters.PrimaryScreenHeight - 60, -2000, -200))
{
await Task.Delay(100);
ViewboxFloatingBar.Margin = new Thickness((SystemParameters.PrimaryScreenWidth - ViewboxFloatingBar.ActualWidth) / 2, SystemParameters.PrimaryScreenHeight - 60, -2000, -200);
2023-12-22 00:14:15 +08:00
}*/
await Task.Delay(100);
ViewboxFloatingBarMarginAnimation(60);
2023-04-05 16:05:03 +08:00
}
}
}
2023-12-22 00:14:15 +08:00
private void SymbolIconDelete_MouseUp(object sender, MouseButtonEventArgs e) {
2023-04-05 16:05:03 +08:00
if (sender != lastBorderMouseDownObject) return;
2023-12-22 00:14:15 +08:00
if (inkCanvas.GetSelectedStrokes().Count > 0) {
2023-04-05 16:05:03 +08:00
inkCanvas.Strokes.Remove(inkCanvas.GetSelectedStrokes());
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
} else if (inkCanvas.Strokes.Count > 0) {
if (Settings.Automation.IsAutoSaveStrokesAtClear && inkCanvas.Strokes.Count > Settings.Automation.MinimumAutomationStrokeNumber) {
2023-04-16 00:17:59 +08:00
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible)
SaveScreenShot(true, $"{pptName}/{previousSlideID}_{DateTime.Now:HH-mm-ss}");
else
SaveScreenShot(true);
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
BtnClear_Click(null, null);
}/*
2023-04-05 16:05:03 +08:00
else
{
if (currentMode == 0 && BtnPPTSlideShowEnd.Visibility != Visibility.Visible)
{
BtnHideInkCanvas_Click(BtnHideInkCanvas, null);
}
2023-12-22 00:14:15 +08:00
}*/
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void SymbolIconSettings_Click(object sender, RoutedEventArgs e) {
2023-04-05 16:05:03 +08:00
HideSubPanels();
2023-12-22 00:14:15 +08:00
BtnSettings_Click(null, null);
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void SymbolIconSelect_MouseUp(object sender, MouseButtonEventArgs e) {
BtnSelect_Click(null, null);
HideSubPanels("select");
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private async void SymbolIconScreenshot_MouseUp(object sender, MouseButtonEventArgs e) {
HideSubPanelsImmediately();
await Task.Delay(50);
SaveScreenShotToDesktop();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
bool Not_Enter_Blackboard_fir_Mouse_Click = true;
bool isDisplayingOrHidingBlackboard = false;
private void ImageBlackboard_MouseUp(object sender, MouseButtonEventArgs e) {
if (isDisplayingOrHidingBlackboard) return;
isDisplayingOrHidingBlackboard = true;
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
if (inkCanvas.EditingMode == InkCanvasEditingMode.Select) PenIcon_Click(null, null);
2023-09-25 12:11:21 +08:00
2023-12-22 00:14:15 +08:00
if (currentMode == 0) {
BottomViewboxPPTSidesControl.Visibility = Visibility.Collapsed;
LeftSidePanelForPPTNavigation.Visibility = Visibility.Collapsed;
RightSidePanelForPPTNavigation.Visibility = Visibility.Collapsed;
//进入黑板
if (Settings.Gesture.AutoSwitchTwoFingerGesture) // 自动开启双指移动
2023-04-05 16:05:03 +08:00
{
2023-12-22 00:14:15 +08:00
ToggleSwitchEnableTwoFingerTranslate.IsOn = true;
//ToggleSwitchEnableTwoFingerZoom.IsOn = false;
//ToggleSwitchEnableTwoFingerRotation.IsOn = false;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
/*
if (Not_Enter_Blackboard_fir_Mouse_Click) {// BUG-Fixed_tmp程序启动后直接进入白板会导致后续撤销功能、退出白板无法恢复墨迹
BtnColorRed_Click(BorderPenColorRed, null);
await Task.Delay(200);
SimulateMouseClick.SimulateMouseClickAtTopLeft();
await Task.Delay(10);
Not_Enter_Blackboard_fir_Mouse_Click = false;
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
*/
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
Topmost = false;
new Thread(new ThreadStart(() => {
2023-04-05 16:05:03 +08:00
Thread.Sleep(100);
2023-12-22 00:14:15 +08:00
Application.Current.Dispatcher.Invoke(() => {
ViewboxFloatingBarMarginAnimation(60);
2023-04-05 16:05:03 +08:00
});
})).Start();
2023-12-22 00:14:15 +08:00
if (Settings.Canvas.UsingWhiteboard) {
BorderPenColorBlack_MouseUp(BorderPenColorBlack, null);
2023-12-22 00:14:15 +08:00
} else {
BorderPenColorWhite_MouseUp(BorderPenColorWhite, null);
}
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
//关闭黑板
2023-12-22 00:14:15 +08:00
HideSubPanelsImmediately();
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
if (StackPanelPPTControls.Visibility == Visibility.Visible) {
if (Settings.PowerPointSettings.IsShowBottomPPTNavigationPanel) {
AnimationHelper.ShowWithSlideFromBottomAndFade(BottomViewboxPPTSidesControl);
}
if (Settings.PowerPointSettings.IsShowSidePPTNavigationPanel) {
AnimationHelper.ShowWithScaleFromLeft(LeftSidePanelForPPTNavigation);
AnimationHelper.ShowWithScaleFromRight(RightSidePanelForPPTNavigation);
2023-04-05 16:05:03 +08:00
}
}
2023-12-22 00:14:15 +08:00
if (Settings.Gesture.AutoSwitchTwoFingerGesture) // 自动关闭双指移动
2023-04-05 16:05:03 +08:00
{
2023-12-22 00:14:15 +08:00
ToggleSwitchEnableTwoFingerTranslate.IsOn = false;
//ToggleSwitchEnableTwoFingerZoom.IsOn = false;
//ToggleSwitchEnableTwoFingerRotation.IsOn = false;
}
if (Settings.Automation.IsAutoSaveStrokesAtClear && inkCanvas.Strokes.Count > Settings.Automation.MinimumAutomationStrokeNumber) {
SaveScreenShot(true);
SaveInkCanvasStrokes(false, false); // 自动保存当前页墨迹
}
Topmost = true;
if (isInMultiTouchMode) BorderMultiTouchMode_MouseUp(null, null);
if (BtnPPTSlideShowEnd.Visibility == Visibility.Collapsed) {
new Thread(new ThreadStart(() => {
2023-04-05 16:05:03 +08:00
Thread.Sleep(100);
2023-12-22 00:14:15 +08:00
Application.Current.Dispatcher.Invoke(() => {
ViewboxFloatingBarMarginAnimation(100);
});
})).Start();
} else {
new Thread(new ThreadStart(() => {
Thread.Sleep(100);
Application.Current.Dispatcher.Invoke(() => {
ViewboxFloatingBarMarginAnimation(60);
2023-04-05 16:05:03 +08:00
});
})).Start();
}
2023-12-22 00:14:15 +08:00
if (Pen_Icon.Background == null) {
PenIcon_Click(null, null);
}
//BorderPenColorRed_MouseUp(BorderPenColorRed, null);
2023-04-05 16:05:03 +08:00
}
BtnSwitch_Click(BtnSwitch, null);
2023-12-22 00:14:15 +08:00
if (currentMode == 0 && inkCanvas.Strokes.Count == 0 && BtnPPTSlideShowEnd.Visibility != Visibility.Visible) {
//BtnHideInkCanvas_Click(BtnHideInkCanvas, null);
CursorIcon_Click(null, null);
2023-04-05 16:05:03 +08:00
}
BtnExit.Foreground = Brushes.White;
ThemeManager.Current.ApplicationTheme = ApplicationTheme.Dark;
2023-12-22 00:14:15 +08:00
new Thread(new ThreadStart(() => {
Thread.Sleep(200);
Application.Current.Dispatcher.Invoke(() => {
isDisplayingOrHidingBlackboard = false;
});
})).Start();
CheckColorTheme(true);
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void ImageCountdownTimer_MouseUp(object sender, MouseButtonEventArgs e) {
if (lastBorderMouseDownObject != sender) return;
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
AnimationHelper.HideWithSlideAndFade(BorderTools);
AnimationHelper.HideWithSlideAndFade(BoardBorderTools);
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
new CountdownTimerWindow().Show();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void OperatingGuideWindowIcon_MouseUp(object sender, MouseButtonEventArgs e) {
//if (lastBorderMouseDownObject != sender) return;
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
AnimationHelper.HideWithSlideAndFade(BorderTools);
AnimationHelper.HideWithSlideAndFade(BoardBorderTools);
new OperatingGuideWindow().Show();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void SymbolIconRand_MouseUp(object sender, MouseButtonEventArgs e) {
2023-04-05 16:05:03 +08:00
if (lastBorderMouseDownObject != sender) return;
2023-12-22 00:14:15 +08:00
AnimationHelper.HideWithSlideAndFade(BorderTools);
AnimationHelper.HideWithSlideAndFade(BoardBorderTools);
new RandWindow().Show();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void SymbolIconRandOne_MouseUp(object sender, MouseButtonEventArgs e) {
2023-04-05 16:05:03 +08:00
if (lastBorderMouseDownObject != sender) return;
2023-12-22 00:14:15 +08:00
AnimationHelper.HideWithSlideAndFade(BorderTools);
AnimationHelper.HideWithSlideAndFade(BoardBorderTools);
2023-04-05 16:05:03 +08:00
new RandWindow(true).ShowDialog();
}
2023-12-22 00:14:15 +08:00
private void GridInkReplayButton_MouseUp(object sender, MouseButtonEventArgs e) {
2023-04-05 16:05:03 +08:00
if (lastBorderMouseDownObject != sender) return;
2023-12-22 00:14:15 +08:00
AnimationHelper.HideWithSlideAndFade(BorderTools);
AnimationHelper.HideWithSlideAndFade(BoardBorderTools);
CollapseBorderDrawShape();
2023-04-05 16:05:03 +08:00
InkCanvasForInkReplay.Visibility = Visibility.Visible;
inkCanvas.Visibility = Visibility.Collapsed;
isStopInkReplay = false;
InkCanvasForInkReplay.Strokes.Clear();
StrokeCollection strokes = inkCanvas.Strokes.Clone();
2023-12-22 00:14:15 +08:00
if (inkCanvas.GetSelectedStrokes().Count != 0) {
2023-04-05 16:05:03 +08:00
strokes = inkCanvas.GetSelectedStrokes().Clone();
}
int k = 1, i = 0;
2023-12-22 00:14:15 +08:00
new Thread(new ThreadStart(() => {
foreach (Stroke stroke in strokes) {
2023-04-05 16:05:03 +08:00
StylusPointCollection stylusPoints = new StylusPointCollection();
if (stroke.StylusPoints.Count == 629) //圆或椭圆
{
Stroke s = null;
2023-12-22 00:14:15 +08:00
foreach (StylusPoint stylusPoint in stroke.StylusPoints) {
if (i++ >= 50) {
2023-04-05 16:05:03 +08:00
i = 0;
Thread.Sleep(10);
if (isStopInkReplay) return;
}
2023-12-22 00:14:15 +08:00
Application.Current.Dispatcher.Invoke(() => {
try {
2023-04-05 16:05:03 +08:00
InkCanvasForInkReplay.Strokes.Remove(s);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
stylusPoints.Add(stylusPoint);
s = new Stroke(stylusPoints.Clone());
s.DrawingAttributes = stroke.DrawingAttributes;
InkCanvasForInkReplay.Strokes.Add(s);
});
}
2023-12-22 00:14:15 +08:00
} else {
2023-04-05 16:05:03 +08:00
Stroke s = null;
2023-12-22 00:14:15 +08:00
foreach (StylusPoint stylusPoint in stroke.StylusPoints) {
if (i++ >= k) {
2023-04-05 16:05:03 +08:00
i = 0;
Thread.Sleep(10);
if (isStopInkReplay) return;
}
2023-12-22 00:14:15 +08:00
Application.Current.Dispatcher.Invoke(() => {
try {
2023-04-05 16:05:03 +08:00
InkCanvasForInkReplay.Strokes.Remove(s);
2023-12-22 00:14:15 +08:00
} catch { }
2023-04-05 16:05:03 +08:00
stylusPoints.Add(stylusPoint);
s = new Stroke(stylusPoints.Clone());
s.DrawingAttributes = stroke.DrawingAttributes;
InkCanvasForInkReplay.Strokes.Add(s);
});
}
}
}
Thread.Sleep(100);
2023-12-22 00:14:15 +08:00
Application.Current.Dispatcher.Invoke(() => {
2023-04-05 16:05:03 +08:00
InkCanvasForInkReplay.Visibility = Visibility.Collapsed;
inkCanvas.Visibility = Visibility.Visible;
});
})).Start();
}
bool isStopInkReplay = false;
2023-12-22 00:14:15 +08:00
private void InkCanvasForInkReplay_MouseDown(object sender, MouseButtonEventArgs e) {
if (e.ClickCount == 2) {
2023-04-05 16:05:03 +08:00
InkCanvasForInkReplay.Visibility = Visibility.Collapsed;
inkCanvas.Visibility = Visibility.Visible;
isStopInkReplay = true;
}
}
2023-12-22 00:14:15 +08:00
private void SymbolIconTools_MouseUp(object sender, MouseButtonEventArgs e) {
if (BorderTools.Visibility == Visibility.Visible) {
AnimationHelper.HideWithSlideAndFade(BorderTools);
AnimationHelper.HideWithSlideAndFade(BoardBorderTools);
} else {
AnimationHelper.ShowWithSlideFromBottomAndFade(BorderTools);
AnimationHelper.ShowWithSlideFromBottomAndFade(BoardBorderTools);
2023-04-05 16:05:03 +08:00
}
}
#region Drag
bool isDragDropInEffect = false;
Point pos = new Point();
Point downPos = new Point();
2023-12-22 00:14:15 +08:00
Point pointDesktop = new Point(-1, -1); //用于记录上次在桌面时的坐标
Point pointPPT = new Point(-1, -1); //用于记录上次在PPT中的坐标
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
void SymbolIconEmoji_MouseMove(object sender, MouseEventArgs e) {
if (isDragDropInEffect) {
2023-04-05 16:05:03 +08:00
double xPos = e.GetPosition(null).X - pos.X + ViewboxFloatingBar.Margin.Left;
double yPos = e.GetPosition(null).Y - pos.Y + ViewboxFloatingBar.Margin.Top;
ViewboxFloatingBar.Margin = new Thickness(xPos, yPos, -2000, -200);
2023-12-22 00:14:15 +08:00
2023-04-05 16:05:03 +08:00
pos = e.GetPosition(null);
2023-12-22 00:14:15 +08:00
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) {
pointPPT = new Point(xPos, yPos);
} else {
pointDesktop = new Point(xPos, yPos);
}
2023-04-05 16:05:03 +08:00
}
}
2023-12-22 00:14:15 +08:00
void SymbolIconEmoji_MouseDown(object sender, MouseButtonEventArgs e) {
if (isViewboxFloatingBarMarginAnimationRunning) {
ViewboxFloatingBar.BeginAnimation(FrameworkElement.MarginProperty, null);
isViewboxFloatingBarMarginAnimationRunning = false;
}
2023-04-05 16:05:03 +08:00
isDragDropInEffect = true;
pos = e.GetPosition(null);
downPos = e.GetPosition(null);
GridForFloatingBarDraging.Visibility = Visibility.Visible;
SymbolIconEmoji.Symbol = ModernWpf.Controls.Symbol.Emoji;
}
2023-12-22 00:14:15 +08:00
void SymbolIconEmoji_MouseUp(object sender, MouseButtonEventArgs e) {
2023-04-05 16:05:03 +08:00
isDragDropInEffect = false;
2023-12-22 00:14:15 +08:00
if (e is null || (downPos.X == e.GetPosition(null).X && downPos.Y == e.GetPosition(null).Y)) {
if (BorderFloatingBarMainControls.Visibility == Visibility.Visible) {
2023-04-05 16:05:03 +08:00
BorderFloatingBarMainControls.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
CheckEnableTwoFingerGestureBtnVisibility(false);
} else {
2023-04-05 16:05:03 +08:00
BorderFloatingBarMainControls.Visibility = Visibility.Visible;
2023-12-22 00:14:15 +08:00
CheckEnableTwoFingerGestureBtnVisibility(true);
2023-04-05 16:05:03 +08:00
}
}
GridForFloatingBarDraging.Visibility = Visibility.Collapsed;
SymbolIconEmoji.Symbol = ModernWpf.Controls.Symbol.Emoji2;
}
#endregion
2023-12-22 00:14:15 +08:00
private void GridPPTControlPrevious_MouseUp(object sender, MouseButtonEventArgs e) {
if (lastBorderMouseDownObject != sender) return;
2023-04-05 16:05:03 +08:00
BtnPPTSlidesUp_Click(BtnPPTSlidesUp, null);
}
2023-12-22 00:14:15 +08:00
private void GridPPTControlNext_MouseUp(object sender, MouseButtonEventArgs e) {
if (lastBorderMouseDownObject != sender) return;
2023-04-05 16:05:03 +08:00
BtnPPTSlidesDown_Click(BtnPPTSlidesDown, null);
}
2023-12-22 00:14:15 +08:00
private void ImagePPTControlEnd_MouseUp(object sender, MouseButtonEventArgs e) {
2023-04-05 16:05:03 +08:00
BtnPPTSlideShowEnd_Click(BtnPPTSlideShowEnd, null);
}
2023-04-05 16:05:03 +08:00
#endregion
#region Save & Open
2023-12-22 00:14:15 +08:00
private void SymbolIconSaveStrokes_MouseUp(object sender, MouseButtonEventArgs e) {
2023-04-05 16:05:03 +08:00
if (lastBorderMouseDownObject != sender || inkCanvas.Visibility != Visibility.Visible) return;
2023-12-22 00:14:15 +08:00
AnimationHelper.HideWithSlideAndFade(BorderTools);
AnimationHelper.HideWithSlideAndFade(BoardBorderTools);
2023-04-05 16:05:03 +08:00
GridNotifications.Visibility = Visibility.Collapsed;
2023-12-22 00:14:15 +08:00
SaveInkCanvasStrokes(true, true);
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void SaveInkCanvasStrokes(bool newNotice = true, bool saveByUser = false) {
try {
string savePath;
if (saveByUser) // 用户手动保存
2023-04-05 16:05:03 +08:00
{
2023-12-22 00:14:15 +08:00
if (currentMode == 0) // 非黑板模式下
{
try {
savePath = @"D:\Ink Canvas\User Saved - Desktop Annotation Strokes";
} catch (IOException) // 用户电脑无 D 盘等情况
{
savePath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + @"\Ink Canvas\User Saved - Desktop Annotation Strokes";
}
} else // 黑板模式下
{
try {
savePath = @"D:\Ink Canvas\User Saved - BlackBoard Strokes";
} catch (IOException) {
savePath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + @"\Ink Canvas\User Saved - BlackBoard Strokes";
}
}
} else // 程序自动保存
{
if (currentMode == 0) // 非黑板模式下
{
try {
savePath = @"D:\Ink Canvas\Auto Saved - Desktop Annotation Strokes";
} catch (IOException) {
savePath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + @"\Ink Canvas\Auto Saved - Desktop Annotation Strokes";
}
} else {
try {
savePath = @"D:\Ink Canvas\Auto Saved - BlackBoard Strokes";
} catch (IOException) {
savePath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + @"\Ink Canvas\Auto Saved - BlackBoard Strokes";
}
}
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
if (!Directory.Exists(savePath)) {
Directory.CreateDirectory(savePath);
}
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
string savePathWithName;
if (currentMode != 0) // 黑板模式下
2023-04-05 16:05:03 +08:00
{
2023-12-22 00:14:15 +08:00
savePathWithName = savePath + @"\" + DateTime.Now.ToString("u").Replace(':', '-') + " Page-" + CurrentWhiteboardIndex + " StrokesCount-" + inkCanvas.Strokes.Count + ".icstk";
} else {
savePathWithName = savePath + @"\" + DateTime.Now.ToString("u").Replace(':', '-') + ".icstk";
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
FileStream fs = new FileStream(savePathWithName, FileMode.Create);
inkCanvas.Strokes.Save(fs);
if (newNotice) {
ShowNotification("墨迹成功保存至 " + savePathWithName);
} else {
//AppendNotification("墨迹成功保存至 " + savePathWithName);
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
} catch {
2023-04-05 16:05:03 +08:00
ShowNotification("墨迹保存失败");
}
}
2023-12-22 00:14:15 +08:00
private void SymbolIconOpenStrokes_MouseUp(object sender, MouseButtonEventArgs e) {
2023-04-05 16:05:03 +08:00
if (lastBorderMouseDownObject != sender) return;
2023-12-22 00:14:15 +08:00
AnimationHelper.HideWithSlideAndFade(BorderTools);
AnimationHelper.HideWithSlideAndFade(BoardBorderTools);
2023-04-05 16:05:03 +08:00
OpenFileDialog openFileDialog = new OpenFileDialog();
2023-12-22 00:14:15 +08:00
2023-04-05 16:05:03 +08:00
string defaultFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Ink Canvas Strokes\User Saved";
2023-12-22 00:14:15 +08:00
if (Directory.Exists(@"D:\Ink Canvas")) {
openFileDialog.InitialDirectory = @"D:\Ink Canvas";
} else if (Directory.Exists(defaultFolderPath)) {
2023-04-05 16:05:03 +08:00
openFileDialog.InitialDirectory = defaultFolderPath;
}
openFileDialog.Title = "打开墨迹文件";
openFileDialog.Filter = "Ink Canvas Strokes File (*.icstk)|*.icstk";
2023-12-22 00:14:15 +08:00
if (openFileDialog.ShowDialog() == true) {
2023-04-05 16:05:03 +08:00
LogHelper.WriteLogToFile(string.Format("Strokes Insert: Name: {0}", openFileDialog.FileName), LogHelper.LogType.Event);
2023-12-22 00:14:15 +08:00
try {
var fileStreamHasNoStroke = false;
2023-12-22 00:14:15 +08:00
using (var fs = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read)) {
var strokes = new StrokeCollection(fs);
fileStreamHasNoStroke = strokes.Count == 0;
2023-12-22 00:14:15 +08:00
if (!fileStreamHasNoStroke) {
ClearStrokes(true);
timeMachine.ClearStrokeHistory();
inkCanvas.Strokes.Add(strokes);
LogHelper.NewLog(string.Format("Strokes Insert: Strokes Count: {0}", inkCanvas.Strokes.Count.ToString()));
}
}
2023-12-22 00:14:15 +08:00
if (fileStreamHasNoStroke) {
using (var ms = new MemoryStream(File.ReadAllBytes(openFileDialog.FileName))) {
ms.Seek(0, SeekOrigin.Begin);
var strokes = new StrokeCollection(ms);
ClearStrokes(true);
timeMachine.ClearStrokeHistory();
inkCanvas.Strokes.Add(strokes);
LogHelper.NewLog(string.Format("Strokes Insert (2): Strokes Count: {0}", strokes.Count.ToString()));
}
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
if (inkCanvas.Visibility != Visibility.Visible) {
2023-04-05 16:05:03 +08:00
SymbolIconCursor_Click(sender, null);
}
2023-12-22 00:14:15 +08:00
} catch {
2023-04-05 16:05:03 +08:00
ShowNotification("墨迹打开失败");
}
}
}
#endregion
#region Multi-finger Inking
#endregion
2023-07-15 15:28:10 +08:00
2023-12-22 00:14:15 +08:00
#region ViewboxFloatingBar
#region Auto Fold
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
bool isFloatingBarFolded = false, isFloatingBarChangingHideMode = false;
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
private async void FoldFloatingBar_MouseUp(object sender, MouseButtonEventArgs e) {
if (sender == null) {
foldFloatingBarByUser = false;
} else {
foldFloatingBarByUser = true;
}
unfoldFloatingBarByUser = false;
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
if (isFloatingBarChangingHideMode) return;
/*if (sender == hiddenButtonInBorderTools) {
AnimationHelper.HideWithSlideAndFade(BorderTools);
AnimationHelper.HideWithSlideAndFade(BoardBorderTools);
}*/
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
await Dispatcher.InvokeAsync(() => {
isFloatingBarChangingHideMode = true;
isFloatingBarFolded = true;
if (currentMode != 0) ImageBlackboard_MouseUp(null, null);
if (StackPanelCanvasControls.Visibility == Visibility.Visible) {
if (foldFloatingBarByUser && inkCanvas.Strokes.Count > 2) {
ShowNotification("正在清空墨迹并收纳至侧边栏,可进入批注模式后通过【撤销】功能来恢复原先墨迹。");
}
}
lastBorderMouseDownObject = sender;
CursorWithDelIcon_Click(sender, null);
SidePannelMarginAnimation(-200);
});
await Task.Delay(500);
await Dispatcher.InvokeAsync(() => {
BottomViewboxPPTSidesControl.Visibility = Visibility.Collapsed;
LeftSidePanelForPPTNavigation.Visibility = Visibility.Collapsed;
RightSidePanelForPPTNavigation.Visibility = Visibility.Collapsed;
ViewboxFloatingBarMarginAnimation(-60);
HideSubPanels("cursor");
SidePannelMarginAnimation(-200);
});
isFloatingBarChangingHideMode = false;
}
private async void UnFoldFloatingBar_MouseUp(object sender, MouseButtonEventArgs e) {
if (sender == null || StackPanelPPTControls.Visibility == Visibility.Visible) {
unfoldFloatingBarByUser = false;
} else {
unfoldFloatingBarByUser = true;
}
foldFloatingBarByUser = false;
if (isFloatingBarChangingHideMode) return;
await Dispatcher.InvokeAsync(() => {
isFloatingBarChangingHideMode = true;
isFloatingBarFolded = false;
});
await Task.Delay(500);
await Dispatcher.InvokeAsync(() => {
if (StackPanelPPTControls.Visibility == Visibility.Visible) {
if (Settings.PowerPointSettings.IsShowBottomPPTNavigationPanel) {
AnimationHelper.ShowWithSlideFromBottomAndFade(BottomViewboxPPTSidesControl);
}
if (Settings.PowerPointSettings.IsShowSidePPTNavigationPanel) {
AnimationHelper.ShowWithScaleFromLeft(LeftSidePanelForPPTNavigation);
AnimationHelper.ShowWithScaleFromRight(RightSidePanelForPPTNavigation);
}
}
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) {
ViewboxFloatingBarMarginAnimation(60);
} else {
ViewboxFloatingBarMarginAnimation(100);
}
SidePannelMarginAnimation(-1500);
});
isFloatingBarChangingHideMode = false;
}
private async void SidePannelMarginAnimation(int heightFromBottom) // Possible value: -1500, -200
2023-04-05 16:05:03 +08:00
{
2023-12-22 00:14:15 +08:00
await Dispatcher.InvokeAsync(() => {
if (heightFromBottom == -200) LeftSidePanel.Visibility = Visibility.Visible;
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
ThicknessAnimation LeftSidePanelmarginAnimation = new ThicknessAnimation {
Duration = TimeSpan.FromSeconds(0.3),
From = LeftSidePanel.Margin,
To = new Thickness(-17, 0, 0, heightFromBottom)
};
ThicknessAnimation RightSidePanelmarginAnimation = new ThicknessAnimation {
Duration = TimeSpan.FromSeconds(0.3),
From = RightSidePanel.Margin,
To = new Thickness(0, 0, -17, heightFromBottom)
};
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
LeftSidePanel.BeginAnimation(FrameworkElement.MarginProperty, LeftSidePanelmarginAnimation);
RightSidePanel.BeginAnimation(FrameworkElement.MarginProperty, RightSidePanelmarginAnimation);
});
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
await Task.Delay(600);
await Dispatcher.InvokeAsync(() => {
LeftSidePanel.Margin = new Thickness(-17, 0, 0, heightFromBottom);
RightSidePanel.Margin = new Thickness(0, 0, -17, heightFromBottom);
if (heightFromBottom == -1500) LeftSidePanel.Visibility = Visibility.Collapsed;
});
isFloatingBarChangingHideMode = false;
}
#endregion Auto Fold
bool isViewboxFloatingBarMarginAnimationRunning = false;
private async void ViewboxFloatingBarMarginAnimation(int heightFromBottom) {
if (heightFromBottom == 60) {
heightFromBottom = 55;
}
await Dispatcher.InvokeAsync(() => {
if (Topmost == false) {
heightFromBottom = -60;
} else {
ViewboxFloatingBar.Visibility = Visibility.Visible;
}
isViewboxFloatingBarMarginAnimationRunning = true;
pos.X = (SystemParameters.PrimaryScreenWidth - ViewboxFloatingBar.ActualWidth * ViewboxFloatingBarScaleTransform.ScaleX) / 2;
pos.Y = SystemParameters.PrimaryScreenHeight - heightFromBottom * ((ViewboxFloatingBarScaleTransform.ScaleY == 1) ? 1 : 0.9);
if (heightFromBottom != -60) {
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) {
if (pointPPT.X != -1 || pointPPT.Y != -1) {
if (Math.Abs(pointPPT.Y - pos.Y) > 50) {
pos = pointPPT;
} else {
pointPPT = pos;
}
}
} else {
if (pointDesktop.X != -1 || pointDesktop.Y != -1) {
if (Math.Abs(pointDesktop.Y - pos.Y) > 50) {
pos = pointDesktop;
} else {
pointDesktop = pos;
}
}
}
}
ThicknessAnimation marginAnimation = new ThicknessAnimation {
Duration = TimeSpan.FromSeconds(0.5),
From = ViewboxFloatingBar.Margin,
To = new Thickness(pos.X, pos.Y, -2000, -200)
};
ViewboxFloatingBar.BeginAnimation(FrameworkElement.MarginProperty, marginAnimation);
});
await Task.Delay(200);
await Dispatcher.InvokeAsync(() => {
ViewboxFloatingBar.Margin = new Thickness(pos.X, pos.Y, -2000, -200);
if (Topmost == false) ViewboxFloatingBar.Visibility = Visibility.Hidden;
});
}
private async void CursorIcon_Click(object sender, RoutedEventArgs e) {
// 切换前自动截图保存墨迹
if (inkCanvas.Strokes.Count > 0 && inkCanvas.Strokes.Count > Settings.Automation.MinimumAutomationStrokeNumber) {
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) SaveScreenShot(true, $"{pptName}/{previousSlideID}_{DateTime.Now:HH-mm-ss}");
else SaveScreenShot(true);
}
if (BtnPPTSlideShowEnd.Visibility != Visibility.Visible) {
if (Settings.Canvas.HideStrokeWhenSelecting)
inkCanvas.Visibility = Visibility.Collapsed;
else {
inkCanvas.IsHitTestVisible = false;
inkCanvas.Visibility = Visibility.Visible;
}
} else {
if (Settings.PowerPointSettings.IsShowStrokeOnSelectInPowerPoint) {
inkCanvas.Visibility = Visibility.Visible;
inkCanvas.IsHitTestVisible = true;
} else {
if (Settings.Canvas.HideStrokeWhenSelecting)
inkCanvas.Visibility = Visibility.Collapsed;
else {
inkCanvas.IsHitTestVisible = false;
inkCanvas.Visibility = Visibility.Visible;
}
}
}
Main_Grid.Background = Brushes.Transparent;
GridBackgroundCoverHolder.Visibility = Visibility.Collapsed;
inkCanvas.Select(new StrokeCollection());
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
if (currentMode != 0) {
SaveStrokes();
RestoreStrokes(true);
}
if (BtnSwitchTheme.Content.ToString() == "浅色") {
BtnSwitch.Content = "黑板";
} else {
BtnSwitch.Content = "白板";
}
StackPanelPPTButtons.Visibility = Visibility.Visible;
BtnHideInkCanvas.Content = "显示\n画板";
CheckEnableTwoFingerGestureBtnVisibility(false);
StackPanelCanvasControls.Visibility = Visibility.Collapsed;
if (!isFloatingBarFolded) {
HideSubPanels("cursor", true);
await Task.Delay(50);
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) {
ViewboxFloatingBarMarginAnimation(60);
} else {
ViewboxFloatingBarMarginAnimation(100);
2023-04-05 16:05:03 +08:00
}
}
}
2023-12-22 00:14:15 +08:00
private void PenIcon_Click(object sender, RoutedEventArgs e) {
if (Pen_Icon.Background == null || StackPanelCanvasControls.Visibility == Visibility.Collapsed) {
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
Main_Grid.Background = new SolidColorBrush(StringToColor("#01FFFFFF"));
inkCanvas.IsHitTestVisible = true;
inkCanvas.Visibility = Visibility.Visible;
GridBackgroundCoverHolder.Visibility = Visibility.Visible;
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
/*if (forceEraser && currentMode == 0)
BtnColorRed_Click(sender, null);*/
if (GridBackgroundCover.Visibility == Visibility.Collapsed) {
if (BtnSwitchTheme.Content.ToString() == "浅色") {
BtnSwitch.Content = "黑板";
} else {
BtnSwitch.Content = "白板";
}
StackPanelPPTButtons.Visibility = Visibility.Visible;
} else {
BtnSwitch.Content = "屏幕";
StackPanelPPTButtons.Visibility = Visibility.Collapsed;
}
BtnHideInkCanvas.Content = "隐藏\n画板";
StackPanelCanvasControls.Visibility = Visibility.Visible;
//AnimationHelper.ShowWithSlideFromLeftAndFade(StackPanelCanvasControls);
CheckEnableTwoFingerGestureBtnVisibility(true);
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
ColorSwitchCheck();
HideSubPanels("pen", true);
} else {
if (PenPalette.Visibility == Visibility.Visible) {
AnimationHelper.HideWithSlideAndFade(PenPalette);
AnimationHelper.HideWithSlideAndFade(BoardPenPalette);
} else {
AnimationHelper.ShowWithSlideFromBottomAndFade(PenPalette);
AnimationHelper.ShowWithSlideFromBottomAndFade(BoardPenPalette);
}
}
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void ColorThemeSwitch_MouseUp(object sender, RoutedEventArgs e) {
isUselightThemeColor = !isUselightThemeColor;
if (currentMode == 0) {
isDesktopUselightThemeColor = isUselightThemeColor;
}
CheckColorTheme();
2023-04-05 16:05:03 +08:00
}
2023-12-22 00:14:15 +08:00
private void EraserIcon_Click(object sender, RoutedEventArgs e) {
forceEraser = true;
forcePointEraser = true;
double k = 1;
switch (Settings.Canvas.EraserSize) {
case 0:
k = 0.5;
break;
case 1:
k = 0.8;
break;
case 3:
k = 1.25;
break;
case 4:
k = 1.8;
break;
}
inkCanvas.EraserShape = new EllipseStylusShape(k * 80, k * 80);
//inkCanvas.EraserShape = new EllipseStylusShape(70, 70);
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
drawingShapeMode = 0;
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
inkCanvas_EditingModeChanged(inkCanvas, null);
CancelSingleFingerDragMode();
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
HideSubPanels("eraser");
}
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
private void EraserIconByStrokes_Click(object sender, RoutedEventArgs e) {
forceEraser = true;
forcePointEraser = false;
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
inkCanvas.EraserShape = new EllipseStylusShape(5, 5);
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByStroke;
drawingShapeMode = 0;
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
inkCanvas_EditingModeChanged(inkCanvas, null);
CancelSingleFingerDragMode();
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
HideSubPanels("eraserByStrokes");
}
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
private void CursorWithDelIcon_Click(object sender, RoutedEventArgs e) {
SymbolIconDelete_MouseUp(sender, null);
CursorIcon_Click(null, null);
}
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
private void SelectIcon_MouseUp(object sender, RoutedEvent e) {
forceEraser = true;
drawingShapeMode = 0;
inkCanvas.IsManipulationEnabled = false;
if (inkCanvas.EditingMode == InkCanvasEditingMode.Select) {
inkCanvas.Select(inkCanvas.Strokes);
} else {
inkCanvas.EditingMode = InkCanvasEditingMode.Select;
}
}
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
private void BoardChangeBackgroundColorBtn_MouseUp(object sender, RoutedEventArgs e) {
if (!isLoaded) return;
Settings.Canvas.UsingWhiteboard = !Settings.Canvas.UsingWhiteboard;
SaveSettingsToFile();
if (Settings.Canvas.UsingWhiteboard) {
if (inkColor == 5) inkColor = 0;
} else {
if (inkColor == 0) inkColor = 5;
}
CheckColorTheme(true);
}
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
private void BoardEraserIcon_Click(object sender, RoutedEventArgs e) {
if (BoardEraser.Background.ToString() == "#FF679CF4") {
AnimationHelper.ShowWithSlideFromBottomAndFade(BoardDeleteIcon);
} else {
forceEraser = true;
forcePointEraser = true;
inkCanvas.EraserShape = new EllipseStylusShape(50, 50);
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
drawingShapeMode = 0;
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
inkCanvas_EditingModeChanged(inkCanvas, null);
CancelSingleFingerDragMode();
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
HideSubPanels("eraser");
}
}
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
private void BoardEraserIconByStrokes_Click(object sender, RoutedEventArgs e) {
if (BoardEraserByStrokes.Background.ToString() == "#FF679CF4") {
AnimationHelper.ShowWithSlideFromBottomAndFade(BoardDeleteIcon);
} else {
forceEraser = true;
forcePointEraser = false;
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
inkCanvas.EraserShape = new EllipseStylusShape(5, 5);
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByStroke;
drawingShapeMode = 0;
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
inkCanvas_EditingModeChanged(inkCanvas, null);
CancelSingleFingerDragMode();
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
HideSubPanels("eraserByStrokes");
}
}
2023-04-05 16:05:03 +08:00
2023-12-22 00:14:15 +08:00
private void BoardSymbolIconDelete_MouseUp(object sender, MouseButtonEventArgs e) {
PenIcon_Click(null, null);
SymbolIconDelete_MouseUp(sender, e);
}
private void BoardLaunchEasiCamera_MouseUp(object sender, MouseButtonEventArgs e) {
ImageBlackboard_MouseUp(null, null);
SoftwareLauncher.LaunchEasiCamera("希沃视频展台");
}
private void BoardLaunchDesmos_MouseUp(object sender, MouseButtonEventArgs e) {
HideSubPanelsImmediately();
ImageBlackboard_MouseUp(null, null);
Process.Start("https://www.desmos.com/calculator?lang=zh-CN");
}
private void CollapseBorderDrawShape(bool isLongPressSelected = false) {
AnimationHelper.HideWithSlideAndFade(BorderDrawShape);
AnimationHelper.HideWithSlideAndFade(BoardBorderDrawShape);
}
private void DrawShapePromptToPen() {
if (isLongPressSelected == true) {
HideSubPanels("pen");
} else {
if (StackPanelCanvasControls.Visibility == Visibility.Visible) {
HideSubPanels("pen");
} else {
HideSubPanels("cursor");
2023-04-05 16:05:03 +08:00
}
}
}
2023-12-22 00:14:15 +08:00
private void CloseBordertools_MouseUp(object sender, MouseButtonEventArgs e) {
HideSubPanels();
}
#endregion ViewboxFloatingBar
#region TwoFingZoomBtn
private void TwoFingerGestureBorder_MouseUp(object sender, RoutedEventArgs e) {
if (TwoFingerGestureBorder.Visibility == Visibility.Visible) {
AnimationHelper.HideWithSlideAndFade(TwoFingerGestureBorder);
AnimationHelper.HideWithSlideAndFade(BoardTwoFingerGestureBorder);
} else {
AnimationHelper.ShowWithSlideFromBottomAndFade(TwoFingerGestureBorder);
AnimationHelper.ShowWithSlideFromBottomAndFade(BoardTwoFingerGestureBorder);
}
}
private void CheckEnableTwoFingerGestureBtnColorPrompt() {
EnableTwoFingerGestureBtn.Source = Settings.Gesture.IsEnableTwoFingerGesture ? new BitmapImage(new Uri("/Resources/Icons-png/twoFingelMove-Blue.png", UriKind.Relative)) : new BitmapImage(new Uri("/Resources/Icons-png/twoFingelMove.png", UriKind.Relative));
BoardEnableTwoFingerGestureBtn.Source = Settings.Gesture.IsEnableTwoFingerGesture ? new BitmapImage(new Uri("/Resources/Icons-png/twoFingelMove-Blue.png", UriKind.Relative)) : new BitmapImage(new Uri("/Resources/Icons-png/twoFingelMove.png", UriKind.Relative));
}
private void CheckEnableTwoFingerGestureBtnVisibility(bool isVisible) {
if (StackPanelCanvasControls.Visibility != Visibility.Visible
|| BorderFloatingBarMainControls.Visibility != Visibility.Visible) {
EnableTwoFingerGestureBorder.Visibility = Visibility.Collapsed;
} else if (isVisible == true) {
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) EnableTwoFingerGestureBorder.Visibility = Visibility.Collapsed;
else EnableTwoFingerGestureBorder.Visibility = Visibility.Visible;
} else EnableTwoFingerGestureBorder.Visibility = Visibility.Collapsed;
}
#endregion TwoFingZoomBtn
2023-04-05 16:05:03 +08:00
}
}