代码清理

This commit is contained in:
PrefacedCorg
2025-12-20 13:56:46 +08:00
parent 6fe34c1250
commit 3f460d7a5c
28 changed files with 809 additions and 689 deletions
+2 -2
View File
@@ -536,13 +536,13 @@ namespace Ink_Canvas
operatingGuideWindow.RefreshTheme();
}
}
// 刷新计时器控件
if (TimerControl != null)
{
TimerControl.RefreshTheme();
}
if (MinimizedTimerControl != null)
{
MinimizedTimerControl.RefreshTheme();
@@ -2,7 +2,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
+38 -30
View File
@@ -73,35 +73,40 @@ namespace Ink_Canvas
/// <summary>
/// 用於更新浮動工具欄的"手勢"按鈕和白板工具欄的"手勢"按鈕的樣式(開啟和關閉狀態)
/// </summary>
private void CheckEnableTwoFingerGestureBtnColorPrompt() {
private void CheckEnableTwoFingerGestureBtnColorPrompt()
{
// 根据主题选择手势图标和颜色
bool isDarkTheme = Settings.Appearance.Theme == 1 ||
(Settings.Appearance.Theme == 2 && !IsSystemThemeLight());
bool isLightTheme = !isDarkTheme;
string gestureIconPath = isLightTheme ? "/Resources/new-icons/gesture.png" : "/Resources/new-icons/gesture_white.png";
// 根据主题设置白板模式下的颜色
Color boardBgColor, boardIconColor, boardTextColor, boardBorderColor;
if (isLightTheme) {
if (isLightTheme)
{
// 浅色主题
boardBgColor = Color.FromRgb(244, 244, 245);
boardIconColor = Color.FromRgb(24, 24, 27);
boardTextColor = Color.FromRgb(24, 24, 27);
boardBorderColor = Color.FromRgb(161, 161, 170);
} else {
}
else
{
// 深色主题
boardBgColor = Color.FromRgb(39, 39, 42);
boardIconColor = Color.FromRgb(244, 244, 245);
boardTextColor = Color.FromRgb(244, 244, 245);
boardBorderColor = Color.FromRgb(113, 113, 122);
}
if (ToggleSwitchEnableMultiTouchMode.IsOn) {
if (ToggleSwitchEnableMultiTouchMode.IsOn)
{
TwoFingerGestureSimpleStackPanel.Opacity = 0.5;
TwoFingerGestureSimpleStackPanel.IsHitTestVisible = false;
EnableTwoFingerGestureBtn.Source =
new BitmapImage(new Uri(gestureIconPath, UriKind.Relative));
BoardGesture.Background = new SolidColorBrush(boardBgColor);
BoardGestureGeometry.Brush = new SolidColorBrush(boardIconColor);
BoardGestureGeometry2.Brush = new SolidColorBrush(boardIconColor);
@@ -110,25 +115,28 @@ namespace Ink_Canvas
BoardGestureGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.DisabledGestureIcon);
BoardGestureGeometry2.Geometry = Geometry.Parse("F0 M24,24z M0,0z");
}
else {
else
{
TwoFingerGestureSimpleStackPanel.Opacity = 1;
TwoFingerGestureSimpleStackPanel.IsHitTestVisible = true;
if (Settings.Gesture.IsEnableTwoFingerGesture) {
if (Settings.Gesture.IsEnableTwoFingerGesture)
{
EnableTwoFingerGestureBtn.Source =
new BitmapImage(new Uri("/Resources/new-icons/gesture-enabled.png", UriKind.Relative));
BoardGesture.Background = new SolidColorBrush(Color.FromRgb(37, 99, 235));
BoardGestureGeometry.Brush = new SolidColorBrush(Colors.GhostWhite);
BoardGestureGeometry2.Brush = new SolidColorBrush(Colors.GhostWhite);
BoardGestureLabel.Foreground = new SolidColorBrush(Colors.GhostWhite);
BoardGesture.BorderBrush = new SolidColorBrush(Color.FromRgb(37, 99, 235));
BoardGestureGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.EnabledGestureIcon);
BoardGestureGeometry2.Geometry = Geometry.Parse("F0 M24,24z M0,0z "+XamlGraphicsIconGeometries.EnabledGestureIconBadgeCheck);
BoardGestureGeometry2.Geometry = Geometry.Parse("F0 M24,24z M0,0z " + XamlGraphicsIconGeometries.EnabledGestureIconBadgeCheck);
}
else {
else
{
EnableTwoFingerGestureBtn.Source =
new BitmapImage(new Uri(gestureIconPath, UriKind.Relative));
BoardGesture.Background = new SolidColorBrush(boardBgColor);
BoardGestureGeometry.Brush = new SolidColorBrush(boardIconColor);
BoardGestureGeometry2.Brush = new SolidColorBrush(boardIconColor);
@@ -474,7 +482,7 @@ namespace Ink_Canvas
}
bool useLegacyUI = Settings.Appearance.UseLegacyFloatingBarUI;
switch (mode)
{
case "pen":
@@ -1958,7 +1966,7 @@ namespace Ink_Canvas
if (Settings.ModeSettings.IsPPTOnlyMode && !isRetry)
{
await Task.Delay(2000); // 等待动画完成后再检查
bool isFloatingBarVisible = false;
await Dispatcher.InvokeAsync(() =>
{
@@ -2039,10 +2047,10 @@ namespace Ink_Canvas
GridTransparencyFakeBackground.Background = Brushes.Transparent;
GridBackgroundCoverHolder.Visibility = Visibility.Collapsed;
// 点击鼠标按钮退出批注模式时的全屏还原
RestoreFullScreenOnExitAnnotationMode();
inkCanvas.Select(new StrokeCollection());
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
@@ -2167,7 +2175,7 @@ namespace Ink_Canvas
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width,
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height, true);
}), DispatcherPriority.ApplicationIdle);
isFullScreenApplied = true; // 标记已应用全屏处理
}
@@ -3015,8 +3023,8 @@ namespace Ink_Canvas
// 退出批注模式时的全屏还原处理
private void RestoreFullScreenOnExitAnnotationMode()
{
if (Settings.Advanced.IsEnableAvoidFullScreenHelper &&
isFullScreenApplied &&
if (Settings.Advanced.IsEnableAvoidFullScreenHelper &&
isFullScreenApplied &&
currentMode == 0 && // 不在白板模式
BtnPPTSlideShowEnd.Visibility != Visibility.Visible) // 不在PPT放映模式
{
@@ -3027,11 +3035,11 @@ namespace Ink_Canvas
{
// 退出批注模式,恢复到工作区域大小
var workingArea = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
MainWindow.MoveWindow(new WindowInteropHelper(this).Handle,
MainWindow.MoveWindow(new WindowInteropHelper(this).Handle,
workingArea.Left, workingArea.Top,
workingArea.Width, workingArea.Height, true);
}), DispatcherPriority.ApplicationIdle);
isFullScreenApplied = false; // 标记全屏处理已还原
}
}
@@ -3105,7 +3113,7 @@ namespace Ink_Canvas
RestoreStrokes(true);
// 退出白板模式时取消全屏(仅在非PPT模式下)
if (Settings.Advanced.IsEnableAvoidFullScreenHelper &&
if (Settings.Advanced.IsEnableAvoidFullScreenHelper &&
BtnPPTSlideShowEnd.Visibility != Visibility.Visible) // 不在PPT放映模式
{
// 恢复为非画板模式,重新启用全屏限制
@@ -3115,11 +3123,11 @@ namespace Ink_Canvas
{
// 退出白板模式,恢复到工作区域大小
var workingArea = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
MainWindow.MoveWindow(new WindowInteropHelper(this).Handle,
MainWindow.MoveWindow(new WindowInteropHelper(this).Handle,
workingArea.Left, workingArea.Top,
workingArea.Width, workingArea.Height, true);
}), DispatcherPriority.ApplicationIdle);
isFullScreenApplied = false; // 标记全屏处理已还原
}
@@ -3180,7 +3188,7 @@ namespace Ink_Canvas
RestoreStrokes();
// 进入白板模式时全屏(仅在非PPT模式下)
if (Settings.Advanced.IsEnableAvoidFullScreenHelper &&
if (Settings.Advanced.IsEnableAvoidFullScreenHelper &&
BtnPPTSlideShowEnd.Visibility != Visibility.Visible) // 不在PPT放映模式
{
// 设置为画板模式,允许全屏操作
@@ -3191,7 +3199,7 @@ namespace Ink_Canvas
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width,
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height, true);
}), DispatcherPriority.ApplicationIdle);
isFullScreenApplied = true; // 标记已应用全屏处理
}
@@ -3230,7 +3238,7 @@ namespace Ink_Canvas
}
StackPanelPPTButtons.Visibility = Visibility.Collapsed;
if (Settings.Advanced.EnableUIAccessTopMost)
{
Topmost = true;
@@ -3275,7 +3283,7 @@ namespace Ink_Canvas
}
BtnHideInkCanvas.Content = "隐藏\n画板";
// 进入批注模式时的全屏处理(仅当未应用过全屏处理时)
if (Settings.Advanced.IsEnableAvoidFullScreenHelper && !isFullScreenApplied)
{
@@ -3287,7 +3295,7 @@ namespace Ink_Canvas
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width,
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height, true);
}), DispatcherPriority.ApplicationIdle);
isFullScreenApplied = true; // 标记已应用全屏处理
}
}
+19 -19
View File
@@ -77,7 +77,7 @@ namespace Ink_Canvas
#endregion
#region PPT State Management
private bool isEnteredSlideShowEndEvent;
private bool isEnteredSlideShowEndEvent;
private bool isPresentationHaveBlackSpace;
// 长按翻页相关字段
@@ -93,7 +93,7 @@ namespace Ink_Canvas
// 上次播放位置相关字段
private int _lastPlaybackPage = 0;
private bool _shouldNavigateToLastPage = false;
// 当前播放页码跟踪
private int _currentSlideShowPosition = 0;
@@ -101,7 +101,7 @@ namespace Ink_Canvas
private DateTime _lastSlideSwitchTime = DateTime.MinValue;
private int _pendingSlideIndex = -1;
private System.Timers.Timer _slideSwitchDebounceTimer;
private const int SlideSwitchDebounceMs = 150;
private const int SlideSwitchDebounceMs = 150;
private bool _isInkClearedByButton = false;
#endregion
@@ -774,20 +774,20 @@ namespace Ink_Canvas
try
{
await Task.Delay(100);
await Application.Current.Dispatcher.InvokeAsync(() =>
{
ViewboxFloatingBar.UpdateLayout();
// 如果浮动栏宽度仍未计算好,再等待一段时间
if (ViewboxFloatingBar.ActualWidth <= 0)
{
LogHelper.WriteLogToFile("浮动栏宽度未准备好,等待布局完成", LogHelper.LogType.Trace);
}
});
await Task.Delay(100);
await Application.Current.Dispatcher.InvokeAsync(() =>
{
PureViewboxFloatingBarMarginAnimationInPPTMode(false);
@@ -795,7 +795,7 @@ namespace Ink_Canvas
}
catch (Exception)
{
try
{
await Task.Delay(100);
@@ -832,7 +832,7 @@ namespace Ink_Canvas
var totalSlides = activePresentation.Slides.Count;
// 获取之前的页码(用于保存墨迹)
var previousSlide = _currentSlideShowPosition > 0 ? _currentSlideShowPosition :
var previousSlide = _currentSlideShowPosition > 0 ? _currentSlideShowPosition :
(_pptManager?.GetCurrentSlideNumber() ?? 0);
if (_isInkClearedByButton)
@@ -988,7 +988,7 @@ namespace Ink_Canvas
if (GridTransparencyFakeBackground.Background != Brushes.Transparent)
BtnHideInkCanvas_Click(BtnHideInkCanvas, null);
SetCurrentToolMode(InkCanvasEditingMode.None);
UpdateCurrentToolMode("cursor");
SetFloatingBarHighlightPosition("cursor");
}
@@ -1237,7 +1237,7 @@ namespace Ink_Canvas
// 重置上次播放位置相关字段
_lastPlaybackPage = 0;
_shouldNavigateToLastPage = false;
// 重置当前播放页码跟踪
_currentSlideShowPosition = 0;
@@ -1289,7 +1289,7 @@ namespace Ink_Canvas
if (currentSlideIndex > 0 && currentSlideIndex != newSlideIndex)
{
bool canWrite = _singlePPTInkManager?.CanWriteInk(currentSlideIndex) == true;
if (canWrite && inkCanvas.Strokes.Count > 0)
{
_singlePPTInkManager?.SaveCurrentSlideStrokes(currentSlideIndex, inkCanvas.Strokes);
@@ -1304,7 +1304,7 @@ namespace Ink_Canvas
// 加载新页面的墨迹
StrokeCollection newStrokes = _singlePPTInkManager?.SwitchToSlide(newSlideIndex, null);
if (newStrokes != null && newStrokes.Count > 0)
{
inkCanvas.Strokes.Add(newStrokes);
@@ -1440,7 +1440,7 @@ namespace Ink_Canvas
try
{
var previousSlideBeforeNavigate = _pptManager?.GetCurrentSlideNumber() ?? 0;
StrokeCollection strokesToSave = null;
if (previousSlideBeforeNavigate > 0 && inkCanvas.Strokes.Count > 0)
{
@@ -1450,13 +1450,13 @@ namespace Ink_Canvas
if (_pptManager?.TryNavigatePrevious() == true)
{
var currentSlideAfterNavigate = _pptManager?.GetCurrentSlideNumber() ?? 0;
if (previousSlideBeforeNavigate == currentSlideAfterNavigate && previousSlideBeforeNavigate > 0)
{
Thread.Sleep(50);
currentSlideAfterNavigate = _pptManager?.GetCurrentSlideNumber() ?? 0;
}
if (previousSlideBeforeNavigate != currentSlideAfterNavigate && previousSlideBeforeNavigate > 0)
{
if (inkCanvas.Strokes.Count > 0)
@@ -1527,7 +1527,7 @@ namespace Ink_Canvas
try
{
var previousSlideBeforeNavigate = _pptManager?.GetCurrentSlideNumber() ?? 0;
StrokeCollection strokesToSave = null;
if (previousSlideBeforeNavigate > 0 && inkCanvas.Strokes.Count > 0)
{
@@ -1537,13 +1537,13 @@ namespace Ink_Canvas
if (_pptManager?.TryNavigateNext() == true)
{
var currentSlideAfterNavigate = _pptManager?.GetCurrentSlideNumber() ?? 0;
if (previousSlideBeforeNavigate == currentSlideAfterNavigate && previousSlideBeforeNavigate > 0)
{
Thread.Sleep(50);
currentSlideAfterNavigate = _pptManager?.GetCurrentSlideNumber() ?? 0;
}
if (previousSlideBeforeNavigate != currentSlideAfterNavigate && previousSlideBeforeNavigate > 0)
{
if (inkCanvas.Strokes.Count > 0)
@@ -149,7 +149,7 @@ namespace Ink_Canvas
{
}
});
// 保存元素信息
var elementInfos = new List<CanvasElementInfo>();
foreach (var child in inkCanvas.Children)
+9 -9
View File
@@ -1855,7 +1855,7 @@ namespace Ink_Canvas
// 检查是否是第一次打开(检查用户是否已设置Token)
bool hasToken = !string.IsNullOrEmpty(Settings?.Dlass?.UserToken?.Trim());
bool isFirstTime = !hasToken;
if (isFirstTime)
{
// 第一次打开,询问用户是否已注册
@@ -1866,7 +1866,7 @@ namespace Ink_Canvas
"Dlass账号注册",
MessageBoxButton.YesNo,
MessageBoxImage.Question);
if (result == MessageBoxResult.No)
{
// 用户未注册,打开浏览器
@@ -1882,14 +1882,14 @@ namespace Ink_Canvas
catch (Exception ex)
{
LogHelper.WriteLogToFile($"打开浏览器时出错: {ex.Message}", LogHelper.LogType.Error);
MessageBox.Show($"无法打开浏览器。请手动访问: https://dlass.tech/dashboard",
MessageBox.Show($"无法打开浏览器。请手动访问: https://dlass.tech/dashboard",
"提示", MessageBoxButton.OK, MessageBoxImage.Information);
}
return; // 不打开设置窗口
}
// 如果用户选择"是",继续打开设置窗口
}
// 打开设置管理窗口
var dlassSettingsWindow = new Windows.DlassSettingsWindow();
dlassSettingsWindow.Owner = this;
@@ -1945,7 +1945,7 @@ namespace Ink_Canvas
private void ComboBoxAutoSaveStrokesInterval_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (!isLoaded || ComboBoxAutoSaveStrokesInterval.SelectedItem == null) return;
var selectedItem = ComboBoxAutoSaveStrokesInterval.SelectedItem as System.Windows.Controls.ComboBoxItem;
if (selectedItem?.Tag != null && int.TryParse(selectedItem.Tag.ToString(), out int intervalMinutes))
{
@@ -2720,13 +2720,13 @@ namespace Ink_Canvas
{
if (!isLoaded) return;
Settings.RandSettings.EnableOvertimeCountUp = ToggleSwitchEnableOvertimeCountUp.IsOn;
if (!ToggleSwitchEnableOvertimeCountUp.IsOn)
{
ToggleSwitchEnableOvertimeRedText.IsOn = false;
Settings.RandSettings.EnableOvertimeRedText = false;
}
SaveSettingsToFile();
}
@@ -2739,7 +2739,7 @@ namespace Ink_Canvas
ToggleSwitchEnableOvertimeCountUp.IsOn = true;
Settings.RandSettings.EnableOvertimeCountUp = true;
}
Settings.RandSettings.EnableOvertimeRedText = ToggleSwitchEnableOvertimeRedText.IsOn;
SaveSettingsToFile();
}
@@ -2865,7 +2865,7 @@ namespace Ink_Canvas
// 保存设置到文件
SaveSettingsToFile();
// 根据设置状态显示或隐藏快抽悬浮按钮
ShowQuickDrawFloatingButton();
}
@@ -887,20 +887,20 @@ namespace Ink_Canvas
ToggleSwitchUseLegacyTimerUI.IsOn = Settings.RandSettings.UseLegacyTimerUI;
ToggleSwitchUseNewStyleUI.IsOn = Settings.RandSettings.UseNewStyleUI;
ToggleSwitchEnableOvertimeCountUp.IsOn = Settings.RandSettings.EnableOvertimeCountUp;
// 新点名UI设置
ToggleSwitchUseNewRollCallUI.IsOn = Settings.RandSettings.UseNewRollCallUI;
ToggleSwitchEnableMLAvoidance.IsOn = Settings.RandSettings.EnableMLAvoidance;
MLAvoidanceHistorySlider.Value = Settings.RandSettings.MLAvoidanceHistoryCount;
MLAvoidanceWeightSlider.Value = Settings.RandSettings.MLAvoidanceWeight;
bool canEnableRedText = Settings.RandSettings.EnableOvertimeCountUp && Settings.RandSettings.EnableOvertimeRedText;
ToggleSwitchEnableOvertimeRedText.IsOn = canEnableRedText;
if (!canEnableRedText)
{
Settings.RandSettings.EnableOvertimeRedText = false;
}
TimerVolumeSlider.Value = Settings.RandSettings.TimerVolume;
// 渐进提醒设置
@@ -929,16 +929,16 @@ namespace Ink_Canvas
ToggleSwitchUseLegacyTimerUI.IsOn = Settings.RandSettings.UseLegacyTimerUI;
ToggleSwitchUseNewStyleUI.IsOn = Settings.RandSettings.UseNewStyleUI;
ToggleSwitchEnableOvertimeCountUp.IsOn = Settings.RandSettings.EnableOvertimeCountUp;
bool canEnableRedText = Settings.RandSettings.EnableOvertimeCountUp && Settings.RandSettings.EnableOvertimeRedText;
ToggleSwitchEnableOvertimeRedText.IsOn = canEnableRedText;
if (!canEnableRedText)
{
Settings.RandSettings.EnableOvertimeRedText = false;
}
TimerVolumeSlider.Value = Settings.RandSettings.TimerVolume;
// 渐进提醒设置
ToggleSwitchEnableProgressiveReminder.IsOn = Settings.RandSettings.EnableProgressiveReminder;
ProgressiveReminderVolumeSlider.Value = Settings.RandSettings.ProgressiveReminderVolume;
+255 -132
View File
@@ -117,7 +117,8 @@ namespace Ink_Canvas
}
}
private void BtnPen_Click(object sender, RoutedEventArgs e) {
private void BtnPen_Click(object sender, RoutedEventArgs e)
{
forceEraser = false;
drawingShapeMode = 0;
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
@@ -126,8 +127,10 @@ namespace Ink_Canvas
isLongPressSelected = false;
}
private Task<bool> CheckIsDrawingShapesInMultiTouchMode() {
if (isInMultiTouchMode) {
private Task<bool> CheckIsDrawingShapesInMultiTouchMode()
{
if (isInMultiTouchMode)
{
ToggleSwitchEnableMultiTouchMode.IsOn = false;
lastIsInMultiTouchMode = true;
}
@@ -135,18 +138,21 @@ namespace Ink_Canvas
return Task.FromResult(true);
}
public async void BtnDrawLine_Click(object sender, MouseButtonEventArgs e) {
public async void BtnDrawLine_Click(object sender, MouseButtonEventArgs e)
{
await CheckIsDrawingShapesInMultiTouchMode();
if (lastMouseDownSender == sender) {
if (lastMouseDownSender == sender)
{
forceEraser = true;
drawingShapeMode = 1;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
CancelSingleFingerDragMode();
}
lastMouseDownSender = null;
if (isLongPressSelected) {
if (isLongPressSelected)
{
if (ToggleSwitchDrawShapeBorderAutoHide.IsOn) CollapseBorderDrawShape();
var dA = new DoubleAnimation(1, 1, new Duration(TimeSpan.FromMilliseconds(0)));
ImageDrawLine.BeginAnimation(OpacityProperty, dA);
@@ -155,18 +161,21 @@ namespace Ink_Canvas
DrawShapePromptToPen();
}
private async void BtnDrawDashedLine_Click(object sender, MouseButtonEventArgs e) {
private async void BtnDrawDashedLine_Click(object sender, MouseButtonEventArgs e)
{
await CheckIsDrawingShapesInMultiTouchMode();
if (lastMouseDownSender == sender) {
if (lastMouseDownSender == sender)
{
forceEraser = true;
drawingShapeMode = 8;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
CancelSingleFingerDragMode();
}
lastMouseDownSender = null;
if (isLongPressSelected) {
if (isLongPressSelected)
{
if (ToggleSwitchDrawShapeBorderAutoHide.IsOn) CollapseBorderDrawShape();
var dA = new DoubleAnimation(1, 1, new Duration(TimeSpan.FromMilliseconds(0)));
ImageDrawDashedLine.BeginAnimation(OpacityProperty, dA);
@@ -175,18 +184,21 @@ namespace Ink_Canvas
DrawShapePromptToPen();
}
private async void BtnDrawDotLine_Click(object sender, MouseButtonEventArgs e) {
private async void BtnDrawDotLine_Click(object sender, MouseButtonEventArgs e)
{
await CheckIsDrawingShapesInMultiTouchMode();
if (lastMouseDownSender == sender) {
if (lastMouseDownSender == sender)
{
forceEraser = true;
drawingShapeMode = 18;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
CancelSingleFingerDragMode();
}
lastMouseDownSender = null;
if (isLongPressSelected) {
if (isLongPressSelected)
{
if (ToggleSwitchDrawShapeBorderAutoHide.IsOn) CollapseBorderDrawShape();
var dA = new DoubleAnimation(1, 1, new Duration(TimeSpan.FromMilliseconds(0)));
ImageDrawDotLine.BeginAnimation(OpacityProperty, dA);
@@ -195,18 +207,21 @@ namespace Ink_Canvas
DrawShapePromptToPen();
}
private async void BtnDrawArrow_Click(object sender, MouseButtonEventArgs e) {
private async void BtnDrawArrow_Click(object sender, MouseButtonEventArgs e)
{
await CheckIsDrawingShapesInMultiTouchMode();
if (lastMouseDownSender == sender) {
if (lastMouseDownSender == sender)
{
forceEraser = true;
drawingShapeMode = 2;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
CancelSingleFingerDragMode();
}
lastMouseDownSender = null;
if (isLongPressSelected) {
if (isLongPressSelected)
{
if (ToggleSwitchDrawShapeBorderAutoHide.IsOn) CollapseBorderDrawShape();
var dA = new DoubleAnimation(1, 1, new Duration(TimeSpan.FromMilliseconds(0)));
ImageDrawArrow.BeginAnimation(OpacityProperty, dA);
@@ -215,18 +230,21 @@ namespace Ink_Canvas
DrawShapePromptToPen();
}
private async void BtnDrawParallelLine_Click(object sender, MouseButtonEventArgs e) {
private async void BtnDrawParallelLine_Click(object sender, MouseButtonEventArgs e)
{
await CheckIsDrawingShapesInMultiTouchMode();
if (lastMouseDownSender == sender) {
if (lastMouseDownSender == sender)
{
forceEraser = true;
drawingShapeMode = 15;
inkCanvas.EditingMode = InkCanvasEditingMode.None;
inkCanvas.IsManipulationEnabled = true;
CancelSingleFingerDragMode();
CancelSingleFingerDragMode();
}
lastMouseDownSender = null;
if (isLongPressSelected) {
if (isLongPressSelected)
{
if (ToggleSwitchDrawShapeBorderAutoHide.IsOn) CollapseBorderDrawShape();
var dA = new DoubleAnimation(1, 1, new Duration(TimeSpan.FromMilliseconds(0)));
ImageDrawParallelLine.BeginAnimation(OpacityProperty, dA);
@@ -235,7 +253,8 @@ namespace Ink_Canvas
DrawShapePromptToPen();
}
private async void BtnDrawCoordinate1_Click(object sender, MouseButtonEventArgs e) {
private async void BtnDrawCoordinate1_Click(object sender, MouseButtonEventArgs e)
{
await CheckIsDrawingShapesInMultiTouchMode();
forceEraser = true;
drawingShapeMode = 11;
@@ -245,7 +264,8 @@ namespace Ink_Canvas
DrawShapePromptToPen();
}
private async void BtnDrawCoordinate2_Click(object sender, MouseButtonEventArgs e) {
private async void BtnDrawCoordinate2_Click(object sender, MouseButtonEventArgs e)
{
await CheckIsDrawingShapesInMultiTouchMode();
forceEraser = true;
drawingShapeMode = 12;
@@ -255,7 +275,8 @@ namespace Ink_Canvas
DrawShapePromptToPen();
}
private async void BtnDrawCoordinate3_Click(object sender, MouseButtonEventArgs e) {
private async void BtnDrawCoordinate3_Click(object sender, MouseButtonEventArgs e)
{
await CheckIsDrawingShapesInMultiTouchMode();
forceEraser = true;
drawingShapeMode = 13;
@@ -265,7 +286,8 @@ namespace Ink_Canvas
DrawShapePromptToPen();
}
private async void BtnDrawCoordinate4_Click(object sender, MouseButtonEventArgs e) {
private async void BtnDrawCoordinate4_Click(object sender, MouseButtonEventArgs e)
{
await CheckIsDrawingShapesInMultiTouchMode();
forceEraser = true;
drawingShapeMode = 14;
@@ -275,7 +297,8 @@ namespace Ink_Canvas
DrawShapePromptToPen();
}
private async void BtnDrawCoordinate5_Click(object sender, MouseButtonEventArgs e) {
private async void BtnDrawCoordinate5_Click(object sender, MouseButtonEventArgs e)
{
await CheckIsDrawingShapesInMultiTouchMode();
forceEraser = true;
drawingShapeMode = 17;
@@ -285,7 +308,8 @@ namespace Ink_Canvas
DrawShapePromptToPen();
}
private async void BtnDrawRectangle_Click(object sender, MouseButtonEventArgs e) {
private async void BtnDrawRectangle_Click(object sender, MouseButtonEventArgs e)
{
await CheckIsDrawingShapesInMultiTouchMode();
forceEraser = true;
drawingShapeMode = 3;
@@ -295,7 +319,8 @@ namespace Ink_Canvas
DrawShapePromptToPen();
}
private async void BtnDrawRectangleCenter_Click(object sender, MouseButtonEventArgs e) {
private async void BtnDrawRectangleCenter_Click(object sender, MouseButtonEventArgs e)
{
await CheckIsDrawingShapesInMultiTouchMode();
forceEraser = true;
drawingShapeMode = 19;
@@ -305,7 +330,8 @@ namespace Ink_Canvas
DrawShapePromptToPen();
}
private async void BtnDrawEllipse_Click(object sender, MouseButtonEventArgs e) {
private async void BtnDrawEllipse_Click(object sender, MouseButtonEventArgs e)
{
await CheckIsDrawingShapesInMultiTouchMode();
forceEraser = true;
drawingShapeMode = 4;
@@ -315,7 +341,8 @@ namespace Ink_Canvas
DrawShapePromptToPen();
}
private async void BtnDrawCircle_Click(object sender, MouseButtonEventArgs e) {
private async void BtnDrawCircle_Click(object sender, MouseButtonEventArgs e)
{
await CheckIsDrawingShapesInMultiTouchMode();
forceEraser = true;
drawingShapeMode = 5;
@@ -325,7 +352,8 @@ namespace Ink_Canvas
DrawShapePromptToPen();
}
private async void BtnDrawCenterEllipse_Click(object sender, MouseButtonEventArgs e) {
private async void BtnDrawCenterEllipse_Click(object sender, MouseButtonEventArgs e)
{
await CheckIsDrawingShapesInMultiTouchMode();
forceEraser = true;
drawingShapeMode = 16;
@@ -335,7 +363,8 @@ namespace Ink_Canvas
DrawShapePromptToPen();
}
private async void BtnDrawCenterEllipseWithFocalPoint_Click(object sender, MouseButtonEventArgs e) {
private async void BtnDrawCenterEllipseWithFocalPoint_Click(object sender, MouseButtonEventArgs e)
{
await CheckIsDrawingShapesInMultiTouchMode();
forceEraser = true;
drawingShapeMode = 23;
@@ -345,7 +374,8 @@ namespace Ink_Canvas
DrawShapePromptToPen();
}
private async void BtnDrawDashedCircle_Click(object sender, MouseButtonEventArgs e) {
private async void BtnDrawDashedCircle_Click(object sender, MouseButtonEventArgs e)
{
await CheckIsDrawingShapesInMultiTouchMode();
forceEraser = true;
drawingShapeMode = 10;
@@ -355,7 +385,8 @@ namespace Ink_Canvas
DrawShapePromptToPen();
}
private async void BtnDrawHyperbola_Click(object sender, MouseButtonEventArgs e) {
private async void BtnDrawHyperbola_Click(object sender, MouseButtonEventArgs e)
{
await CheckIsDrawingShapesInMultiTouchMode();
forceEraser = true;
drawingShapeMode = 24;
@@ -366,7 +397,8 @@ namespace Ink_Canvas
DrawShapePromptToPen();
}
private async void BtnDrawHyperbolaWithFocalPoint_Click(object sender, MouseButtonEventArgs e) {
private async void BtnDrawHyperbolaWithFocalPoint_Click(object sender, MouseButtonEventArgs e)
{
await CheckIsDrawingShapesInMultiTouchMode();
forceEraser = true;
drawingShapeMode = 25;
@@ -377,7 +409,8 @@ namespace Ink_Canvas
DrawShapePromptToPen();
}
private async void BtnDrawParabola1_Click(object sender, MouseButtonEventArgs e) {
private async void BtnDrawParabola1_Click(object sender, MouseButtonEventArgs e)
{
await CheckIsDrawingShapesInMultiTouchMode();
forceEraser = true;
drawingShapeMode = 20;
@@ -387,7 +420,8 @@ namespace Ink_Canvas
DrawShapePromptToPen();
}
private async void BtnDrawParabolaWithFocalPoint_Click(object sender, MouseButtonEventArgs e) {
private async void BtnDrawParabolaWithFocalPoint_Click(object sender, MouseButtonEventArgs e)
{
await CheckIsDrawingShapesInMultiTouchMode();
forceEraser = true;
drawingShapeMode = 22;
@@ -397,7 +431,8 @@ namespace Ink_Canvas
DrawShapePromptToPen();
}
private async void BtnDrawParabola2_Click(object sender, MouseButtonEventArgs e) {
private async void BtnDrawParabola2_Click(object sender, MouseButtonEventArgs e)
{
await CheckIsDrawingShapesInMultiTouchMode();
forceEraser = true;
drawingShapeMode = 21;
@@ -407,7 +442,8 @@ namespace Ink_Canvas
DrawShapePromptToPen();
}
private async void BtnDrawCylinder_Click(object sender, MouseButtonEventArgs e) {
private async void BtnDrawCylinder_Click(object sender, MouseButtonEventArgs e)
{
await CheckIsDrawingShapesInMultiTouchMode();
forceEraser = true;
drawingShapeMode = 6;
@@ -417,7 +453,8 @@ namespace Ink_Canvas
DrawShapePromptToPen();
}
private async void BtnDrawCone_Click(object sender, MouseButtonEventArgs e) {
private async void BtnDrawCone_Click(object sender, MouseButtonEventArgs e)
{
await CheckIsDrawingShapesInMultiTouchMode();
forceEraser = true;
drawingShapeMode = 7;
@@ -427,7 +464,8 @@ namespace Ink_Canvas
DrawShapePromptToPen();
}
private async void BtnDrawCuboid_Click(object sender, MouseButtonEventArgs e) {
private async void BtnDrawCuboid_Click(object sender, MouseButtonEventArgs e)
{
await CheckIsDrawingShapesInMultiTouchMode();
forceEraser = true;
drawingShapeMode = 9;
@@ -442,19 +480,24 @@ namespace Ink_Canvas
#endregion
private void inkCanvas_TouchMove(object sender, TouchEventArgs e) {
private void inkCanvas_TouchMove(object sender, TouchEventArgs e)
{
if (isSingleFingerDragMode) return;
if (drawingShapeMode != 0) {
if (drawingShapeMode != 0)
{
//EraserContainer.Background = null;
//ImageEraser.Visibility = Visibility.Visible;
if (isWaitUntilNextTouchDown) return;
if (dec.Count > 1) {
if (dec.Count > 1)
{
isWaitUntilNextTouchDown = true;
try {
try
{
inkCanvas.Strokes.Remove(lastTempStroke);
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
}
catch {
catch
{
Trace.WriteLine("lastTempStrokeCollection failed.");
}
@@ -478,7 +521,8 @@ namespace Ink_Canvas
#region
private void MouseTouchMove(Point endP) {
private void MouseTouchMove(Point endP)
{
// 禁用原有的FitToCurve,使用新的高级贝塞尔曲线平滑
if (Settings.Canvas.FitToCurve) drawingAttributes.FitToCurve = false;
// 在绘制过程中禁用浮动栏交互,避免干扰绘制
@@ -498,10 +542,12 @@ namespace Ink_Canvas
new Point(endP.X, endP.Y)
};
point = new StylusPointCollection(pointList);
stroke = new Stroke(point) {
stroke = new Stroke(point)
{
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
try {
try
{
inkCanvas.Strokes.Remove(lastTempStroke);
}
catch { }
@@ -512,10 +558,12 @@ namespace Ink_Canvas
case 8:
_currentCommitType = CommitReason.ShapeDrawing;
strokes.Add(GenerateDashedLineStrokeCollection(iniP, endP));
try {
try
{
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
}
catch {
catch
{
Trace.WriteLine("lastTempStrokeCollection failed.");
}
@@ -525,10 +573,12 @@ namespace Ink_Canvas
case 18:
_currentCommitType = CommitReason.ShapeDrawing;
strokes.Add(GenerateDotLineStrokeCollection(iniP, endP));
try {
try
{
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
}
catch {
catch
{
Trace.WriteLine("lastTempStrokeCollection failed.");
}
@@ -550,10 +600,12 @@ namespace Ink_Canvas
new Point(endP.X + (w * cost + h * sint), endP.Y - (h * cost - w * sint))
};
point = new StylusPointCollection(pointList);
stroke = new Stroke(point) {
stroke = new Stroke(point)
{
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
try {
try
{
inkCanvas.Strokes.Remove(lastTempStroke);
}
catch { }
@@ -615,10 +667,12 @@ namespace Ink_Canvas
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)));
try {
try
{
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
}
catch {
catch
{
Trace.WriteLine("lastTempStrokeCollection failed.");
}
@@ -631,10 +685,12 @@ namespace Ink_Canvas
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)));
try {
try
{
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
}
catch {
catch
{
Trace.WriteLine("lastTempStrokeCollection failed.");
}
@@ -649,10 +705,12 @@ namespace Ink_Canvas
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)));
try {
try
{
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
}
catch {
catch
{
Trace.WriteLine("lastTempStrokeCollection failed.");
}
@@ -667,10 +725,12 @@ namespace Ink_Canvas
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)));
try {
try
{
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
}
catch {
catch
{
Trace.WriteLine("lastTempStrokeCollection failed.");
}
@@ -686,10 +746,12 @@ namespace Ink_Canvas
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)));
try {
try
{
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
}
catch {
catch
{
Trace.WriteLine("lastTempStrokeCollection failed.");
}
@@ -705,10 +767,12 @@ namespace Ink_Canvas
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)));
try {
try
{
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
}
catch {
catch
{
Trace.WriteLine("lastTempStrokeCollection failed.");
}
@@ -725,10 +789,12 @@ namespace Ink_Canvas
new Point(iniP.X, iniP.Y)
};
point = new StylusPointCollection(pointList);
stroke = new Stroke(point) {
stroke = new Stroke(point)
{
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
try {
try
{
inkCanvas.Strokes.Remove(lastTempStroke);
}
catch { }
@@ -748,10 +814,12 @@ namespace Ink_Canvas
new Point(iniP.X - a, iniP.Y - b)
};
point = new StylusPointCollection(pointList);
stroke = new Stroke(point) {
stroke = new Stroke(point)
{
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
try {
try
{
inkCanvas.Strokes.Remove(lastTempStroke);
}
catch { }
@@ -763,10 +831,12 @@ namespace Ink_Canvas
_currentCommitType = CommitReason.ShapeDrawing;
pointList = GenerateEllipseGeometry(iniP, endP);
point = new StylusPointCollection(pointList);
stroke = new Stroke(point) {
stroke = new Stroke(point)
{
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
try {
try
{
inkCanvas.Strokes.Remove(lastTempStroke);
}
catch { }
@@ -780,10 +850,12 @@ namespace Ink_Canvas
pointList = GenerateEllipseGeometry(new Point(iniP.X - R, iniP.Y - R),
new Point(iniP.X + R, iniP.Y + R));
point = new StylusPointCollection(pointList);
stroke = new Stroke(point) {
stroke = new Stroke(point)
{
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
try {
try
{
inkCanvas.Strokes.Remove(lastTempStroke);
}
catch { }
@@ -792,7 +864,8 @@ namespace Ink_Canvas
inkCanvas.Strokes.Add(stroke);
// 如果启用了圆心标记功能,则绘制圆心
if (Settings.Canvas.ShowCircleCenter) {
if (Settings.Canvas.ShowCircleCenter)
{
DrawCircleCenter(iniP);
}
break;
@@ -803,10 +876,12 @@ namespace Ink_Canvas
pointList = GenerateEllipseGeometry(new Point(iniP.X - halfA, iniP.Y - halfB),
new Point(iniP.X + halfA, iniP.Y + halfB));
point = new StylusPointCollection(pointList);
stroke = new Stroke(point) {
stroke = new Stroke(point)
{
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
try {
try
{
inkCanvas.Strokes.Remove(lastTempStroke);
}
catch { }
@@ -821,46 +896,54 @@ namespace Ink_Canvas
pointList = GenerateEllipseGeometry(new Point(iniP.X - a, iniP.Y - b),
new Point(iniP.X + a, iniP.Y + b));
point = new StylusPointCollection(pointList);
stroke = new Stroke(point) {
stroke = new Stroke(point)
{
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
strokes.Add(stroke);
var c = Math.Sqrt(Math.Abs(a * a - b * b));
StylusPoint stylusPoint;
if (a > b) {
if (a > b)
{
stylusPoint = new StylusPoint(iniP.X + c, iniP.Y, (float)1.0);
point = new StylusPointCollection();
point.Add(stylusPoint);
stroke = new Stroke(point) {
stroke = new Stroke(point)
{
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);
stroke = new Stroke(point) {
stroke = new Stroke(point)
{
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
strokes.Add(stroke.Clone());
}
else if (a < b) {
else if (a < b)
{
stylusPoint = new StylusPoint(iniP.X, iniP.Y - c, (float)1.0);
point = new StylusPointCollection();
point.Add(stylusPoint);
stroke = new Stroke(point) {
stroke = new Stroke(point)
{
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);
stroke = new Stroke(point) {
stroke = new Stroke(point)
{
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
strokes.Add(stroke.Clone());
}
try {
try
{
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
}
catch { }
@@ -873,10 +956,12 @@ namespace Ink_Canvas
R = GetDistance(iniP, endP);
strokes = GenerateDashedLineEllipseStrokeCollection(new Point(iniP.X - R, iniP.Y - R),
new Point(iniP.X + R, iniP.Y + R));
try {
try
{
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
}
catch {
catch
{
Trace.WriteLine("lastTempStrokeCollection failed.");
}
@@ -891,7 +976,8 @@ namespace Ink_Canvas
var pointList2 = new List<Point>();
var pointList3 = new List<Point>();
var pointList4 = new List<Point>();
if (drawMultiStepShapeCurrentStep == 0) {
if (drawMultiStepShapeCurrentStep == 0)
{
//第一笔:画渐近线
var k = Math.Abs((endP.Y - iniP.Y) / (endP.X - iniP.X));
strokes.Add(
@@ -902,24 +988,29 @@ namespace Ink_Canvas
drawMultiStepShapeSpecialParameter3 = k;
drawMultiStepShapeSpecialStrokeCollection = strokes;
}
else {
else
{
//第二笔:画双曲线
// 先将第一笔的渐近线添加到strokes中
if (drawMultiStepShapeSpecialStrokeCollection != null && drawMultiStepShapeSpecialStrokeCollection.Count > 0) {
foreach (var asymptoteStroke in drawMultiStepShapeSpecialStrokeCollection) {
if (drawMultiStepShapeSpecialStrokeCollection != null && drawMultiStepShapeSpecialStrokeCollection.Count > 0)
{
foreach (var asymptoteStroke in drawMultiStepShapeSpecialStrokeCollection)
{
strokes.Add(asymptoteStroke.Clone());
}
}
var k = drawMultiStepShapeSpecialParameter3;
var isHyperbolaFocalPointOnXAxis = Math.Abs((endP.Y - iniP.Y) / (endP.X - iniP.X)) < k;
if (isHyperbolaFocalPointOnXAxis) {
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>();
for (var i = a; i <= Math.Abs(endP.X - iniP.X); i += 0.5) {
for (var i = a; i <= Math.Abs(endP.X - iniP.X); i += 0.5)
{
var 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));
@@ -927,13 +1018,15 @@ namespace Ink_Canvas
pointList4.Add(new Point(iniP.X - i, iniP.Y + rY));
}
}
else {
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>();
for (var i = a; i <= Math.Abs(endP.Y - iniP.Y); i += 0.5) {
for (var i = a; i <= Math.Abs(endP.Y - iniP.Y); i += 0.5)
{
var 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));
@@ -942,7 +1035,8 @@ namespace Ink_Canvas
}
}
try {
try
{
point = new StylusPointCollection(pointList);
stroke = new Stroke(point)
{ DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };
@@ -959,7 +1053,8 @@ namespace Ink_Canvas
stroke = new Stroke(point)
{ DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };
strokes.Add(stroke.Clone());
if (drawingShapeMode == 25) {
if (drawingShapeMode == 25)
{
//画焦点
c = Math.Sqrt(a * a + b * b);
stylusPoint = isHyperbolaFocalPointOnXAxis
@@ -968,7 +1063,7 @@ namespace Ink_Canvas
point = new StylusPointCollection();
point.Add(stylusPoint);
stroke = new Stroke(point)
{ DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };
{ DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };
strokes.Add(stroke.Clone());
stylusPoint = isHyperbolaFocalPointOnXAxis
? new StylusPoint(iniP.X - c, iniP.Y, (float)1.0)
@@ -976,24 +1071,27 @@ namespace Ink_Canvas
point = new StylusPointCollection();
point.Add(stylusPoint);
stroke = new Stroke(point)
{ DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };
{ DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };
strokes.Add(stroke.Clone());
}
}
catch {
catch
{
return;
}
}
try {
try
{
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
}
catch {
catch
{
Trace.WriteLine("lastTempStrokeCollection failed.");
}
lastTempStrokeCollection = strokes;
inkCanvas.Strokes.Add(strokes);
lastTempStrokeCollection = strokes;
inkCanvas.Strokes.Add(strokes);
break;
case 20:
_currentCommitType = CommitReason.ShapeDrawing;
@@ -1657,8 +1755,10 @@ namespace Ink_Canvas
ViewboxFloatingBar.IsHitTestVisible = true;
BlackboardUIGridForInkReplay.IsHitTestVisible = true;
if (drawingShapeMode == 5) {
if (lastTempStroke != null) {
if (drawingShapeMode == 5)
{
if (lastTempStroke != null)
{
var 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;
@@ -1670,25 +1770,31 @@ namespace Ink_Canvas
circles.Add(circle);
}
if (lastIsInMultiTouchMode) {
if (lastIsInMultiTouchMode)
{
ToggleSwitchEnableMultiTouchMode.IsOn = true;
lastIsInMultiTouchMode = false;
}
}
if (drawingShapeMode != 9 && drawingShapeMode != 0 && drawingShapeMode != 24 && drawingShapeMode != 25) {
if (drawingShapeMode != 9 && drawingShapeMode != 0 && drawingShapeMode != 24 && drawingShapeMode != 25)
{
if (isLongPressSelected) { }
else {
else
{
BtnPen_Click(null, null); //画完一次还原到笔模式
if (lastIsInMultiTouchMode) {
if (lastIsInMultiTouchMode)
{
ToggleSwitchEnableMultiTouchMode.IsOn = true;
lastIsInMultiTouchMode = false;
}
}
}
if (drawingShapeMode == 9) {
if (isFirstTouchCuboid) {
if (drawingShapeMode == 9)
{
if (isFirstTouchCuboid)
{
if (CuboidStrokeCollection == null) CuboidStrokeCollection = new StrokeCollection();
isFirstTouchCuboid = false;
var newIniP = new Point(Math.Min(CuboidFrontRectIniP.X, CuboidFrontRectEndP.X),
@@ -1697,25 +1803,32 @@ namespace Ink_Canvas
Math.Max(CuboidFrontRectIniP.Y, CuboidFrontRectEndP.Y));
CuboidFrontRectIniP = newIniP;
CuboidFrontRectEndP = newEndP;
try {
try
{
CuboidStrokeCollection.Add(lastTempStrokeCollection);
}
catch {
catch
{
Trace.WriteLine("lastTempStrokeCollection failed.");
}
}
else {
else
{
BtnPen_Click(null, null); //画完还原到笔模式
if (lastIsInMultiTouchMode) {
if (lastIsInMultiTouchMode)
{
ToggleSwitchEnableMultiTouchMode.IsOn = true;
lastIsInMultiTouchMode = false;
}
if (_currentCommitType == CommitReason.ShapeDrawing) {
try {
if (_currentCommitType == CommitReason.ShapeDrawing)
{
try
{
CuboidStrokeCollection.Add(lastTempStrokeCollection);
}
catch {
catch
{
Trace.WriteLine("lastTempStrokeCollection failed.");
}
@@ -1726,15 +1839,20 @@ namespace Ink_Canvas
}
}
if (drawingShapeMode == 24 || drawingShapeMode == 25) {
if (drawMultiStepShapeCurrentStep == 0) {
if (drawingShapeMode == 24 || drawingShapeMode == 25)
{
if (drawMultiStepShapeCurrentStep == 0)
{
drawMultiStepShapeCurrentStep = 1;
}
else {
else
{
drawMultiStepShapeCurrentStep = 0;
if (drawMultiStepShapeSpecialStrokeCollection != null) {
if (drawMultiStepShapeSpecialStrokeCollection != null)
{
var opFlag = false;
switch (Settings.Canvas.HyperbolaAsymptoteOption) {
switch (Settings.Canvas.HyperbolaAsymptoteOption)
{
case OptionalOperation.Yes:
opFlag = true;
break;
@@ -1752,7 +1870,8 @@ namespace Ink_Canvas
}
BtnPen_Click(null, null); //画完还原到笔模式
if (lastIsInMultiTouchMode) {
if (lastIsInMultiTouchMode)
{
ToggleSwitchEnableMultiTouchMode.IsOn = true;
lastIsInMultiTouchMode = false;
}
@@ -1852,10 +1971,14 @@ namespace Ink_Canvas
Debug.WriteLine($"绘制圆心标记失败: {ex.Message}");
}
}
private void MainWindow_OnMouseMove(object sender, MouseEventArgs e) {
if (e.StylusDevice == null) {
private void MainWindow_OnMouseMove(object sender, MouseEventArgs e)
{
if (e.StylusDevice == null)
{
System.Windows.Forms.Cursor.Show();
} else {
}
else
{
System.Windows.Forms.Cursor.Hide();
}
}
@@ -847,7 +847,7 @@ namespace Ink_Canvas
if (stroke.StylusPoints.Count >= 10)
{
List<Point> checkPoints;
// 使用采样点进行更准确的判断
if (Settings.Canvas.HighPrecisionLineStraighten)
{
@@ -890,7 +890,7 @@ namespace Ink_Canvas
double quickRelativeThreshold = lineLength * quickThreshold;
// 使用平均偏差和最大偏差的综合判断
double deviationThreshold = Settings.Canvas.HighPrecisionLineStraighten
double deviationThreshold = Settings.Canvas.HighPrecisionLineStraighten
? Math.Max(avgDeviation, maxDeviation * 0.7) // 高精度模式更严格
: maxDeviation;
@@ -1310,7 +1310,7 @@ namespace Ink_Canvas
Point end = stroke.StylusPoints.Last().ToPoint();
double lineLength = GetDistance(start, end);
double adaptiveThreshold = Settings.Canvas.AutoStraightenLineThreshold * GetResolutionScale();
// 如果线条太短,不进行拉直处理
if (lineLength < adaptiveThreshold)
{
@@ -1327,7 +1327,7 @@ namespace Ink_Canvas
Point endpoint1, endpoint2;
bool shouldStraighten = TryGetStraightLineEndpoints(stroke, out endpoint1, out endpoint2);
if (shouldStraighten)
{
Debug.WriteLine($"接受拉直:判断为直线,解释方差比例满足阈值");
@@ -1559,7 +1559,7 @@ namespace Ink_Canvas
Point p1 = stroke.StylusPoints[0].ToPoint();
Point p2 = stroke.StylusPoints[1].ToPoint();
double lineLength = GetDistance(p1, p2);
if (lineLength < 10)
return false;
+4 -5
View File
@@ -5,7 +5,6 @@ using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
@@ -707,7 +706,7 @@ namespace Ink_Canvas
dec.Clear();
}
isSingleFingerDragMode = false;
if (drawingShapeMode == 0
&& inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint
&& inkCanvas.EditingMode != InkCanvasEditingMode.EraseByStroke
@@ -722,14 +721,14 @@ namespace Ink_Canvas
private void Main_Grid_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
if (isInMultiTouchMode || !Settings.Gesture.IsEnableTwoFingerGesture) return;
bool hasMultipleManipulators = e.Manipulators.Count() >= 2;
bool shouldUseTwoFingerGesture = (dec.Count >= 2 && hasMultipleManipulators &&
bool shouldUseTwoFingerGesture = (dec.Count >= 2 && hasMultipleManipulators &&
(Settings.PowerPointSettings.IsEnableTwoFingerGestureInPresentationMode ||
StackPanelPPTControls.Visibility != Visibility.Visible ||
StackPanelPPTButtons.Visibility == Visibility.Collapsed)) ||
isSingleFingerDragMode;
if (shouldUseTwoFingerGesture)
{
var md = e.DeltaManipulation;