代码清理

This commit is contained in:
PrefacedCorg
2025-08-31 11:43:52 +08:00
parent a2b711da05
commit ff086e497c
62 changed files with 826 additions and 825 deletions
+3 -3
View File
@@ -1,4 +1,6 @@
using System;
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern;
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
@@ -6,8 +8,6 @@ using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern;
namespace Ink_Canvas
{
+2 -2
View File
@@ -1,6 +1,6 @@
using System;
using IWshRuntimeLibrary;
using System;
using System.Windows;
using IWshRuntimeLibrary;
using Application = System.Windows.Forms.Application;
using File = System.IO.File;
+3 -3
View File
@@ -1,8 +1,8 @@
using System;
using iNKORE.UI.WPF.Modern;
using Microsoft.Win32;
using System;
using System.Windows;
using System.Windows.Media;
using iNKORE.UI.WPF.Modern;
using Microsoft.Win32;
using Application = System.Windows.Application;
namespace Ink_Canvas
+7 -7
View File
@@ -1,4 +1,5 @@
using System;
using Ink_Canvas.Helpers;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
@@ -6,7 +7,6 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Media;
using Ink_Canvas.Helpers;
namespace Ink_Canvas
{
@@ -140,7 +140,7 @@ namespace Ink_Canvas
inkCanvas.EditingMode = previousEditingMode;
currentSelectedElement = null;
}
var targetIndex = isBackupMain ? 0 : CurrentWhiteboardIndex;
// 先清空当前画布的墨迹
@@ -253,7 +253,7 @@ namespace Ink_Canvas
BtnWhiteBoardAdd_Click(sender, e);
return;
}
// 隐藏图片选择工具栏
if (currentSelectedElement != null)
{
@@ -280,7 +280,7 @@ namespace Ink_Canvas
if (WhiteboardTotalCount >= 99) return;
if (Settings.Automation.IsAutoSaveStrokesAtClear &&
inkCanvas.Strokes.Count > Settings.Automation.MinimumAutomationStrokeNumber) SaveScreenShot(true);
// 隐藏图片选择工具栏
if (currentSelectedElement != null)
{
@@ -291,7 +291,7 @@ namespace Ink_Canvas
inkCanvas.EditingMode = previousEditingMode;
currentSelectedElement = null;
}
SaveStrokes();
ClearStrokes(true);
@@ -330,7 +330,7 @@ namespace Ink_Canvas
inkCanvas.EditingMode = previousEditingMode;
currentSelectedElement = null;
}
ClearStrokes(true);
if (CurrentWhiteboardIndex != WhiteboardTotalCount)
+2 -2
View File
@@ -1,4 +1,5 @@
using System;
using Ink_Canvas.Helpers;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
@@ -6,7 +7,6 @@ using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Ink_Canvas.Helpers;
namespace Ink_Canvas
{
@@ -1,4 +1,5 @@
using System;
using Ink_Canvas.Helpers;
using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
@@ -9,7 +10,6 @@ using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using Ink_Canvas.Helpers;
using Clipboard = System.Windows.Clipboard;
using ContextMenu = System.Windows.Controls.ContextMenu;
using Cursors = System.Windows.Input.Cursors;
@@ -151,7 +151,7 @@ namespace Ink_Canvas
// 设置图片属性,避免被InkCanvas选择系统处理
image.IsHitTestVisible = true;
image.Focusable = false;
// 初始化InkCanvas选择设置
if (inkCanvas != null)
{
@@ -173,7 +173,7 @@ namespace Ink_Canvas
{
// 先进行缩放居中处理
CenterAndScaleElement(image);
// 如果有指定位置,调整到指定位置
if (position.HasValue)
{
@@ -181,7 +181,7 @@ namespace Ink_Canvas
InkCanvas.SetLeft(image, position.Value.X - image.Width / 2);
InkCanvas.SetTop(image, position.Value.Y - image.Height / 2);
}
// 绑定事件处理器
if (image is FrameworkElement elementForEvents)
{
+5 -5
View File
@@ -1,4 +1,5 @@
using System;
using Ink_Canvas.Helpers;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows;
@@ -8,7 +9,6 @@ using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using Ink_Canvas.Helpers;
namespace Ink_Canvas
{
@@ -28,7 +28,7 @@ namespace Ink_Canvas
AnimationsHelper.HideWithSlideAndFade(BlackboardLeftSide);
AnimationsHelper.HideWithSlideAndFade(BlackboardCenterSide);
AnimationsHelper.HideWithSlideAndFade(BlackboardRightSide);
// 在PPT模式下隐藏手势面板和手势按钮
AnimationsHelper.HideWithSlideAndFade(TwoFingerGestureBorder);
AnimationsHelper.HideWithSlideAndFade(BoardTwoFingerGestureBorder);
@@ -423,7 +423,7 @@ namespace Ink_Canvas
}
// 更新快捷调色盘选择指示器
if (penType == 0)
if (penType == 0)
{
UpdateQuickColorPaletteIndicator(inkCanvas.DefaultDrawingAttributes.Color);
}
@@ -601,7 +601,7 @@ namespace Ink_Canvas
drawingAttributes.Height = Settings.Canvas.HighlighterWidth;
drawingAttributes.StylusTip = StylusTip.Rectangle;
drawingAttributes.IsHighlighter = true;
// 确保荧光笔模式切换后正确更新颜色和快捷调色板指示器
ColorSwitchCheck();
}
+80 -80
View File
@@ -1,4 +1,6 @@
using System;
using Ink_Canvas.Helpers;
using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
@@ -10,8 +12,6 @@ using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using Ink_Canvas.Helpers;
using Microsoft.Win32;
namespace Ink_Canvas
{
@@ -42,10 +42,10 @@ namespace Ink_Canvas
// 设置图片属性,避免被InkCanvas选择系统处理
image.IsHitTestVisible = true;
image.Focusable = false;
// 初始化InkCanvas选择设置
InitializeInkCanvasSelectionSettings();
// 先添加到画布
inkCanvas.Children.Add(image);
@@ -62,7 +62,7 @@ namespace Ink_Canvas
// 最后绑定事件处理器
BindElementEvents(image);
LogHelper.WriteLogToFile($"图片插入完成: {image.Name}");
}), DispatcherPriority.Loaded);
};
@@ -98,7 +98,7 @@ namespace Ink_Canvas
// 设置光标
element.Cursor = Cursors.Hand;
// 禁用InkCanvas对图片的选择处理
element.IsHitTestVisible = true;
element.Focusable = false;
@@ -121,7 +121,7 @@ namespace Ink_Canvas
// 选中当前元素
SelectElement(element);
// 开始拖动
isDragging = true;
dragStartPoint = e.GetPosition(inkCanvas);
@@ -151,7 +151,7 @@ namespace Ink_Canvas
if (sender is FrameworkElement element && isDragging && element.IsMouseCaptured)
{
var currentPoint = e.GetPosition(inkCanvas);
// 使用鼠标拖动的完整实现机制
ApplyMouseDragTransform(element, currentPoint, dragStartPoint);
@@ -172,7 +172,7 @@ namespace Ink_Canvas
if (sender is FrameworkElement element)
{
// 使用滚轮缩放的核心机制
ApplyWheelScaleTransform(element, e);
@@ -264,7 +264,7 @@ namespace Ink_Canvas
private void SelectElement(FrameworkElement element)
{
currentSelectedElement = element;
// 根据元素类型显示不同的选择工具栏
if (element is Image)
{
@@ -275,7 +275,7 @@ namespace Ink_Canvas
UpdateImageSelectionToolbarPosition(element);
BorderImageSelectionControl.Visibility = Visibility.Visible;
}
// 隐藏笔画选择工具栏
if (BorderStrokeSelectionControl != null)
{
@@ -289,20 +289,20 @@ namespace Ink_Canvas
{
BorderStrokeSelectionControl.Visibility = Visibility.Visible;
}
// 隐藏图片选择工具栏
if (BorderImageSelectionControl != null)
{
BorderImageSelectionControl.Visibility = Visibility.Collapsed;
}
}
// 确保选择框不显示,避免蓝色边框
if (GridInkCanvasSelectionCover != null)
{
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
}
// 禁用InkCanvas的选择功能,去除控制点
if (inkCanvas != null)
{
@@ -317,24 +317,24 @@ namespace Ink_Canvas
private void UnselectElement(FrameworkElement element)
{
// 去除选中效果
// 隐藏所有选择工具栏
if (BorderImageSelectionControl != null)
{
BorderImageSelectionControl.Visibility = Visibility.Collapsed;
}
if (BorderStrokeSelectionControl != null)
{
BorderStrokeSelectionControl.Visibility = Visibility.Collapsed;
}
// 确保选择框隐藏
if (GridInkCanvasSelectionCover != null)
{
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
}
}
@@ -345,7 +345,7 @@ namespace Ink_Canvas
{
// 创建MatrixTransform
var matrixTransform = new MatrixTransform(matrix);
// 将MatrixTransform添加到TransformGroup
transformGroup.Children.Add(matrixTransform);
}
@@ -358,25 +358,25 @@ namespace Ink_Canvas
{
// 根据滚轮方向确定缩放比例(向上1.1倍,向下0.9倍)
double scaleFactor = e.Delta > 0 ? 1.1 : 0.9;
// 计算选中元素的中心点作为缩放中心
var elementCenter = new Point(element.ActualWidth / 2, element.ActualHeight / 2);
// 创建 Matrix 对象并应用 ScaleAt 变换
var matrix = new Matrix();
matrix.ScaleAt(scaleFactor, scaleFactor, elementCenter.X, elementCenter.Y);
// 对选中的图片元素调用 ApplyElementMatrixTransform
ApplyElementMatrixTransform(element, matrix);
// 对选中的笔画应用 Transform 方法(如果有选中的笔画)
var selectedStrokes = inkCanvas.GetSelectedStrokes();
foreach (var stroke in selectedStrokes)
{
stroke.Transform(matrix, false);
}
}
catch (Exception ex)
{
@@ -399,20 +399,20 @@ namespace Ink_Canvas
// 保存初始变换状态用于历史记录
var initialTransform = transformGroup.Clone();
// 创建新的 TransformGroup 并添加 MatrixTransform
var newTransformGroup = new TransformGroup();
newTransformGroup.Children.Add(new MatrixTransform(matrix));
// 将新的变换组添加到现有的变换组中
transformGroup.Children.Add(newTransformGroup);
// 如果启用了历史记录,提交变换历史
if (saveHistory)
{
CommitTransformHistory(element, initialTransform, transformGroup);
}
}
catch (Exception ex)
@@ -428,24 +428,24 @@ namespace Ink_Canvas
{
// 计算鼠标移动的位移向量
var delta = currentPoint - startPoint;
// 创建 Matrix 对象并应用 Translate 变换
var matrix = new Matrix();
matrix.Translate(delta.X, delta.Y);
// 对选中的图片元素应用矩阵变换
ApplyMatrixTransformToElement(element, matrix, false);
// 对选中的笔画应用变换
var selectedStrokes = inkCanvas.GetSelectedStrokes();
foreach (var stroke in selectedStrokes)
{
stroke.Transform(matrix, false);
}
// 更新选择框的位置(如果有选择框)
UpdateSelectionBorderPosition(delta);
}
catch (Exception ex)
@@ -503,7 +503,7 @@ namespace Ink_Canvas
// 支持单指拖动和多指手势
// 可以同时进行平移、旋转和缩放
// 通过 ManipulationDelta 获取手势变化信息
var translation = md.Translation;
var rotation = md.Rotation;
@@ -519,13 +519,13 @@ namespace Ink_Canvas
if (e.Manipulators.Count() >= 2)
{
var center = e.ManipulationOrigin;
// 应用缩放
if (scale.X != 1.0 || scale.Y != 1.0)
{
matrix.ScaleAt(scale.X, scale.Y, center.X, center.Y);
}
// 应用旋转
if (rotation != 0)
{
@@ -535,15 +535,15 @@ namespace Ink_Canvas
// 应用变换到元素
ApplyMatrixTransformToElement(element, matrix, false);
// 应用变换到选中的笔画
var selectedStrokes = inkCanvas.GetSelectedStrokes();
foreach (var stroke in selectedStrokes)
{
stroke.Transform(matrix, false);
}
}
catch (Exception ex)
{
@@ -1087,19 +1087,19 @@ namespace Ink_Canvas
{
// 创建克隆图片
Image clonedImage = CloneImage(originalImage);
// 添加到画布
inkCanvas.Children.Add(clonedImage);
// 初始化变换
InitializeElementTransform(clonedImage);
// 绑定事件
BindElementEvents(clonedImage);
// 记录历史
timeMachine.CommitElementInsertHistory(clonedImage);
LogHelper.WriteLogToFile($"图片克隆完成: {clonedImage.Name}");
}
}
@@ -1118,10 +1118,10 @@ namespace Ink_Canvas
{
// 创建新页面
BtnWhiteBoardAdd_Click(null, null);
// 创建克隆图片(不添加到当前画布,因为已经创建了新页面)
Image clonedImage = CreateClonedImage(originalImage);
if (clonedImage != null)
{
// 设置图片属性,避免被InkCanvas选择系统处理
@@ -1139,7 +1139,7 @@ namespace Ink_Canvas
// 记录历史
timeMachine.CommitElementInsertHistory(clonedImage);
LogHelper.WriteLogToFile($"图片克隆到新页面完成: {clonedImage.Name}");
}
}
@@ -1158,13 +1158,13 @@ namespace Ink_Canvas
if (currentSelectedElement != null)
{
ApplyRotateTransform(currentSelectedElement, -45);
// 更新工具栏位置
if (currentSelectedElement is Image && BorderImageSelectionControl?.Visibility == Visibility.Visible)
{
UpdateImageSelectionToolbarPosition(currentSelectedElement);
}
LogHelper.WriteLogToFile("图片左旋转完成");
}
}
@@ -1182,13 +1182,13 @@ namespace Ink_Canvas
if (currentSelectedElement != null)
{
ApplyRotateTransform(currentSelectedElement, 45);
// 更新工具栏位置
if (currentSelectedElement is Image && BorderImageSelectionControl?.Visibility == Visibility.Visible)
{
UpdateImageSelectionToolbarPosition(currentSelectedElement);
}
LogHelper.WriteLogToFile("图片右旋转完成");
}
}
@@ -1207,13 +1207,13 @@ namespace Ink_Canvas
{
var elementCenter = new Point(currentSelectedElement.ActualWidth / 2, currentSelectedElement.ActualHeight / 2);
ApplyScaleTransform(currentSelectedElement, 0.9, elementCenter);
// 更新工具栏位置
if (currentSelectedElement is Image && BorderImageSelectionControl?.Visibility == Visibility.Visible)
{
UpdateImageSelectionToolbarPosition(currentSelectedElement);
}
LogHelper.WriteLogToFile("图片缩放减小完成");
}
}
@@ -1229,23 +1229,23 @@ namespace Ink_Canvas
try
{
if (currentSelectedElement != null)
{
var elementCenter = new Point(currentSelectedElement.ActualWidth / 2, currentSelectedElement.ActualHeight / 2);
ApplyScaleTransform(currentSelectedElement, 1.1, elementCenter);
// 更新工具栏位置
if (currentSelectedElement is Image && BorderImageSelectionControl?.Visibility == Visibility.Visible)
{
UpdateImageSelectionToolbarPosition(currentSelectedElement);
var elementCenter = new Point(currentSelectedElement.ActualWidth / 2, currentSelectedElement.ActualHeight / 2);
ApplyScaleTransform(currentSelectedElement, 1.1, elementCenter);
// 更新工具栏位置
if (currentSelectedElement is Image && BorderImageSelectionControl?.Visibility == Visibility.Visible)
{
UpdateImageSelectionToolbarPosition(currentSelectedElement);
}
LogHelper.WriteLogToFile("图片缩放增大完成");
}
LogHelper.WriteLogToFile("图片缩放增大完成");
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"图片缩放增大失败: {ex.Message}", LogHelper.LogType.Error);
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"图片缩放增大失败: {ex.Message}", LogHelper.LogType.Error);
}
}
// 图片删除
@@ -1257,20 +1257,20 @@ namespace Ink_Canvas
{
// 保存删除前的编辑模式
var previousEditingMode = inkCanvas.EditingMode;
// 记录删除历史
timeMachine.CommitElementRemoveHistory(currentSelectedElement);
// 从画布中移除
inkCanvas.Children.Remove(currentSelectedElement);
// 清除选中状态
UnselectElement(currentSelectedElement);
currentSelectedElement = null;
// 恢复到删除前的编辑模式
inkCanvas.EditingMode = previousEditingMode;
LogHelper.WriteLogToFile($"图片删除完成,已恢复到编辑模式: {previousEditingMode}");
}
}
@@ -1286,35 +1286,35 @@ namespace Ink_Canvas
try
{
Image clonedImage = new Image();
// 复制图片源
if (originalImage.Source is BitmapSource bitmapSource)
{
clonedImage.Source = bitmapSource;
}
// 复制属性
clonedImage.Width = originalImage.Width;
clonedImage.Height = originalImage.Height;
clonedImage.Stretch = originalImage.Stretch;
clonedImage.StretchDirection = originalImage.StretchDirection;
// 复制位置(在新页面中居中显示)
double left = InkCanvas.GetLeft(originalImage);
double top = InkCanvas.GetTop(originalImage);
InkCanvas.SetLeft(clonedImage, left + 20); // 稍微偏移位置
InkCanvas.SetTop(clonedImage, top + 20);
// 复制变换
if (originalImage.RenderTransform is TransformGroup originalTransformGroup)
{
clonedImage.RenderTransform = originalTransformGroup.Clone();
}
// 设置名称
string timestamp = "img_" + DateTime.Now.ToString("yyyyMMdd_HH_mm_ss_fff");
clonedImage.Name = timestamp;
return clonedImage;
}
catch (Exception ex)
+2 -2
View File
@@ -1,4 +1,5 @@
using System;
using Ink_Canvas.Helpers;
using System;
using System.Diagnostics;
using System.Linq;
using System.Windows;
@@ -6,7 +7,6 @@ using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using Ink_Canvas.Helpers;
namespace Ink_Canvas
{
+81 -80
View File
@@ -1,3 +1,5 @@
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern;
using System;
using System.Diagnostics;
using System.Threading;
@@ -11,8 +13,6 @@ using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern;
using Application = System.Windows.Application;
using Button = System.Windows.Controls.Button;
using Cursors = System.Windows.Input.Cursors;
@@ -441,7 +441,7 @@ namespace Ink_Canvas
case "select":
{
LassoSelectIconGeometry.Brush = new SolidColorBrush(Color.FromRgb(30, 58, 138));
LassoSelectIconGeometry.Geometry =
LassoSelectIconGeometry.Geometry =
Geometry.Parse(XamlGraphicsIconGeometries.SolidLassoSelectIcon);
BoardSelect.Background = new SolidColorBrush(Color.FromRgb(37, 99, 235));
BoardSelect.BorderBrush = new SolidColorBrush(Color.FromRgb(37, 99, 235));
@@ -454,7 +454,7 @@ namespace Ink_Canvas
case "cursor":
{
CursorIconGeometry.Brush = new SolidColorBrush(Color.FromRgb(30, 58, 138));
CursorIconGeometry.Geometry =
CursorIconGeometry.Geometry =
Geometry.Parse(XamlGraphicsIconGeometries.LinedCursorIcon);
BoardPen.Background = new SolidColorBrush(Color.FromRgb(244, 244, 245));
BoardPen.BorderBrush = new SolidColorBrush(Color.FromRgb(161, 161, 170));
@@ -873,7 +873,7 @@ namespace Ink_Canvas
break;
case "QuickColorGreen":
case "QuickColorGreenSingle":
border.Background = new SolidColorBrush(Color.FromRgb(22, 163, 74));
border.Background = new SolidColorBrush(Color.FromRgb(22, 163, 74));
break;
case "QuickColorPurple":
border.Background = new SolidColorBrush(Color.FromRgb(147, 51, 234));
@@ -893,7 +893,8 @@ namespace Ink_Canvas
HideSubPanels();
BtnSettings_Click(null, null);
}
private async void SymbolIconScreenshot_MouseUp(object sender, MouseButtonEventArgs e) {
private async void SymbolIconScreenshot_MouseUp(object sender, MouseButtonEventArgs e)
{
HideSubPanelsImmediately();
await Task.Delay(50);
SaveScreenShotToDesktop();
@@ -1326,10 +1327,10 @@ namespace Ink_Canvas
double screenWidth = screen.Bounds.Width / dpiScaleX, screenHeight = screen.Bounds.Height / dpiScaleY;
// 仅计算Windows任务栏高度,不考虑其他程序对工作区的影响
var toolbarHeight = ForegroundWindowInfo.GetTaskbarHeight(screen, dpiScaleY);
// 计算浮动栏位置,考虑快捷调色盘的显示状态
double floatingBarWidth = ViewboxFloatingBar.ActualWidth * ViewboxFloatingBarScaleTransform.ScaleX;
// 如果快捷调色盘显示,确保有足够空间
if ((QuickColorPalettePanel != null && QuickColorPalettePanel.Visibility == Visibility.Visible) ||
(QuickColorPaletteSingleRowPanel != null && QuickColorPaletteSingleRowPanel.Visibility == Visibility.Visible))
@@ -1346,7 +1347,7 @@ namespace Ink_Canvas
floatingBarWidth = Math.Max(floatingBarWidth, 820 * ViewboxFloatingBarScaleTransform.ScaleX);
}
}
pos.X = (screenWidth - floatingBarWidth) / 2;
if (!PosXCaculatedWithTaskbarHeight)
@@ -1447,10 +1448,10 @@ namespace Ink_Canvas
double screenWidth = screen.Bounds.Width / dpiScaleX, screenHeight = screen.Bounds.Height / dpiScaleY;
// 仅计算Windows任务栏高度,不考虑其他程序对工作区的影响
var toolbarHeight = ForegroundWindowInfo.GetTaskbarHeight(screen, dpiScaleY);
// 计算浮动栏位置,考虑快捷调色盘的显示状态
double floatingBarWidth = ViewboxFloatingBar.ActualWidth * ViewboxFloatingBarScaleTransform.ScaleX;
// 如果快捷调色盘显示,确保有足够空间
if ((QuickColorPalettePanel != null && QuickColorPalettePanel.Visibility == Visibility.Visible) ||
(QuickColorPaletteSingleRowPanel != null && QuickColorPaletteSingleRowPanel.Visibility == Visibility.Visible))
@@ -1467,7 +1468,7 @@ namespace Ink_Canvas
floatingBarWidth = Math.Max(floatingBarWidth, 850 * ViewboxFloatingBarScaleTransform.ScaleX);
}
}
pos.X = (screenWidth - floatingBarWidth) / 2;
// 如果任务栏高度为0(隐藏状态),则使用固定边距
@@ -1529,10 +1530,10 @@ namespace Ink_Canvas
double screenWidth = screen.Bounds.Width / dpiScaleX, screenHeight = screen.Bounds.Height / dpiScaleY;
// 仅计算Windows任务栏高度,不考虑其他程序对工作区的影响
var toolbarHeight = ForegroundWindowInfo.GetTaskbarHeight(screen, dpiScaleY);
// 计算浮动栏位置,考虑快捷调色盘的显示状态
double floatingBarWidth = ViewboxFloatingBar.ActualWidth * ViewboxFloatingBarScaleTransform.ScaleX;
// 如果快捷调色盘显示,确保有足够空间
if ((QuickColorPalettePanel != null && QuickColorPalettePanel.Visibility == Visibility.Visible) ||
(QuickColorPaletteSingleRowPanel != null && QuickColorPaletteSingleRowPanel.Visibility == Visibility.Visible))
@@ -1549,7 +1550,7 @@ namespace Ink_Canvas
floatingBarWidth = Math.Max(floatingBarWidth, 820 * ViewboxFloatingBarScaleTransform.ScaleX);
}
}
pos.X = (screenWidth - floatingBarWidth) / 2;
pos.Y = screenHeight - 55 * ViewboxFloatingBarScaleTransform.ScaleY;
@@ -1664,7 +1665,7 @@ namespace Ink_Canvas
StackPanelCanvasControls.Visibility = Visibility.Collapsed;
// 在鼠标模式下隐藏快捷调色盘
if (QuickColorPalettePanel != null)
{
@@ -1751,7 +1752,7 @@ namespace Ink_Canvas
CheckEnableTwoFingerGestureBtnVisibility(true);
// 使用集中化的工具模式切换方法
SetCurrentToolMode(InkCanvasEditingMode.Ink);
// 在批注模式下显示快捷调色盘(如果设置中启用了)
if (Settings.Appearance.IsShowQuickColorPalette && QuickColorPalettePanel != null && QuickColorPaletteSingleRowPanel != null)
{
@@ -1775,7 +1776,7 @@ namespace Ink_Canvas
forceEraser = false;
forcePointEraser = false;
drawingShapeMode = 0;
// 保持之前的笔类型状态,而不是强制重置
if (!wasHighlighter)
{
@@ -1806,7 +1807,7 @@ namespace Ink_Canvas
forceEraser = false;
forcePointEraser = false;
drawingShapeMode = 0;
// 保持之前的笔类型状态,而不是强制重置
if (!wasHighlighter)
{
@@ -1878,7 +1879,7 @@ namespace Ink_Canvas
forceEraser = false;
forcePointEraser = false;
drawingShapeMode = 0;
// 保持之前的笔类型状态,而不是强制重置
if (!wasHighlighter)
{
@@ -1899,7 +1900,7 @@ namespace Ink_Canvas
HideSubPanels("pen", true);
}
}
// 修复:从线擦切换到批注时,保持之前的笔类型状态
forceEraser = false;
@@ -2044,7 +2045,7 @@ namespace Ink_Canvas
private void QuickColorOrange_Click(object sender, RoutedEventArgs e)
{
SetQuickColor(Color.FromRgb(251, 150, 80)); // 橙色
SetQuickColor(Color.FromRgb(251, 150, 80)); // 橙色
}
private void QuickColorYellow_Click(object sender, RoutedEventArgs e)
@@ -2067,14 +2068,14 @@ namespace Ink_Canvas
SetQuickColor(Colors.Red);
}
private void QuickColorGreen_Click(object sender, RoutedEventArgs e)
private void QuickColorGreen_Click(object sender, RoutedEventArgs e)
{
SetQuickColor(Color.FromRgb(22, 163, 74));
}
private void QuickColorPurple_Click(object sender, RoutedEventArgs e)
{
SetQuickColor(Color.FromRgb(147, 51, 234));
SetQuickColor(Color.FromRgb(147, 51, 234));
}
private void SetQuickColor(Color color)
@@ -2137,12 +2138,12 @@ namespace Ink_Canvas
drawingAttributes.Height = Settings.Canvas.HighlighterWidth;
drawingAttributes.StylusTip = StylusTip.Rectangle;
drawingAttributes.IsHighlighter = true;
inkCanvas.DefaultDrawingAttributes.Width = Settings.Canvas.HighlighterWidth / 2;
inkCanvas.DefaultDrawingAttributes.Height = Settings.Canvas.HighlighterWidth;
inkCanvas.DefaultDrawingAttributes.StylusTip = StylusTip.Rectangle;
inkCanvas.DefaultDrawingAttributes.IsHighlighter = true;
// 确保荧光笔颜色索引正确更新
inkCanvas.DefaultDrawingAttributes.Color = drawingAttributes.Color;
}
@@ -2157,7 +2158,7 @@ namespace Ink_Canvas
else if (color == Colors.Black) lastDesktopInkColor = 0;
else if (color == Color.FromRgb(37, 99, 235)) lastDesktopInkColor = 3; // 蓝色
else if (color == Colors.Red) lastDesktopInkColor = 1;
else if (color == Colors.Green || color == Color.FromRgb(22, 163, 74)) lastDesktopInkColor = 2;
else if (color == Colors.Green || color == Color.FromRgb(22, 163, 74)) lastDesktopInkColor = 2;
else if (color == Color.FromRgb(147, 51, 234)) lastDesktopInkColor = 6; // 紫色
}
else
@@ -2169,7 +2170,7 @@ namespace Ink_Canvas
else if (color == Colors.Black) lastBoardInkColor = 0;
else if (color == Color.FromRgb(37, 99, 235)) lastBoardInkColor = 3; // 蓝色
else if (color == Colors.Red) lastBoardInkColor = 1;
else if (color == Colors.Green || color == Color.FromRgb(22, 163, 74)) lastBoardInkColor = 2;
else if (color == Colors.Green || color == Color.FromRgb(22, 163, 74)) lastBoardInkColor = 2;
else if (color == Color.FromRgb(147, 51, 234)) lastBoardInkColor = 6; // 紫色
}
@@ -2178,7 +2179,7 @@ namespace Ink_Canvas
// 更新颜色显示
ColorSwitchCheck();
// 如果当前是荧光笔模式,调用ColorSwitchCheck确保颜色索引正确更新
if (penType == 1)
{
@@ -2197,7 +2198,7 @@ namespace Ink_Canvas
QuickColorRedCheck.Visibility = Visibility.Collapsed;
QuickColorGreenCheck.Visibility = Visibility.Collapsed;
QuickColorPurpleCheck.Visibility = Visibility.Collapsed;
// 隐藏所有check图标(单行显示)
QuickColorWhiteCheckSingle.Visibility = Visibility.Collapsed;
QuickColorOrangeCheckSingle.Visibility = Visibility.Collapsed;
@@ -2209,7 +2210,7 @@ namespace Ink_Canvas
// 显示当前选中颜色的check图标
// 在荧光笔模式下,使用更宽松的颜色匹配
int tolerance = (penType == 1) ? 25 : 15; // 荧光笔模式使用更大的容差
if (IsColorSimilar(selectedColor, Colors.White, tolerance) || IsColorSimilar(selectedColor, Color.FromRgb(250, 250, 250), tolerance))
{
QuickColorWhiteCheck.Visibility = Visibility.Visible;
@@ -2220,7 +2221,7 @@ namespace Ink_Canvas
QuickColorBlackCheck.Visibility = Visibility.Visible;
QuickColorBlackCheckSingle.Visibility = Visibility.Visible;
}
else if (IsColorSimilar(selectedColor, Colors.Yellow, tolerance) ||
else if (IsColorSimilar(selectedColor, Colors.Yellow, tolerance) ||
IsColorSimilar(selectedColor, Color.FromRgb(234, 179, 8), tolerance) ||
IsColorSimilar(selectedColor, Color.FromRgb(250, 204, 21), tolerance) ||
IsColorSimilar(selectedColor, Color.FromRgb(253, 224, 71), tolerance))
@@ -2228,7 +2229,7 @@ namespace Ink_Canvas
QuickColorYellowCheck.Visibility = Visibility.Visible;
QuickColorYellowCheckSingle.Visibility = Visibility.Visible;
}
else if (IsColorSimilar(selectedColor, Color.FromRgb(255, 165, 0), tolerance) ||
else if (IsColorSimilar(selectedColor, Color.FromRgb(255, 165, 0), tolerance) ||
IsColorSimilar(selectedColor, Color.FromRgb(251, 150, 80), tolerance) ||
IsColorSimilar(selectedColor, Color.FromRgb(249, 115, 22), tolerance) ||
IsColorSimilar(selectedColor, Color.FromRgb(234, 88, 12), tolerance) ||
@@ -2243,7 +2244,7 @@ namespace Ink_Canvas
QuickColorBlueCheck.Visibility = Visibility.Visible;
// 单行显示模式没有蓝色,所以不设置单行的check
}
else if (IsColorSimilar(selectedColor, Colors.Red, tolerance) ||
else if (IsColorSimilar(selectedColor, Colors.Red, tolerance) ||
IsColorSimilar(selectedColor, Color.FromRgb(220, 38, 38), tolerance) ||
IsColorSimilar(selectedColor, Color.FromRgb(239, 68, 68), tolerance))
{
@@ -2270,7 +2271,7 @@ namespace Ink_Canvas
int rDiff = Math.Abs(color1.R - color2.R);
int gDiff = Math.Abs(color1.G - color2.G);
int bDiff = Math.Abs(color1.B - color2.B);
return rDiff <= tolerance && gDiff <= tolerance && bDiff <= tolerance;
}
@@ -2767,7 +2768,7 @@ namespace Ink_Canvas
StackPanelCanvasControls.Visibility = Visibility.Collapsed;
CheckEnableTwoFingerGestureBtnVisibility(false);
HideSubPanels("cursor");
// 新增:在屏幕模式下显示基础浮动栏
if (currentMode == 0)
{
@@ -2778,7 +2779,7 @@ namespace Ink_Canvas
{
AnimationsHelper.ShowWithSlideFromLeftAndFade(StackPanelCanvasControls);
CheckEnableTwoFingerGestureBtnVisibility(true);
// 新增:在批注模式下显示基础浮动栏
if (currentMode == 0)
{
@@ -2815,7 +2816,7 @@ namespace Ink_Canvas
{
// Check if the image options panel is currently visible
bool isImagePanelVisible = BoardImageOptionsPanel.Visibility == Visibility.Visible;
// Toggle the image options panel
if (isImagePanelVisible)
{
@@ -2877,11 +2878,11 @@ namespace Ink_Canvas
}
CenterAndScaleElement(image);
// 设置图片属性,避免被InkCanvas选择系统处理
image.IsHitTestVisible = true;
image.Focusable = false;
// 初始化InkCanvas选择设置
if (inkCanvas != null)
{
@@ -2890,7 +2891,7 @@ namespace Ink_Canvas
// 同时通过图片的IsHitTestVisible和Focusable属性来避免InkCanvas选择系统的干扰
inkCanvas.EditingMode = InkCanvasEditingMode.None;
}
inkCanvas.Children.Add(image);
// 绑定事件处理器
@@ -2943,11 +2944,11 @@ namespace Ink_Canvas
}
CenterAndScaleElement(image);
// 设置图片属性,避免被InkCanvas选择系统处理
image.IsHitTestVisible = true;
image.Focusable = false;
// 初始化InkCanvas选择设置
if (inkCanvas != null)
{
@@ -2956,7 +2957,7 @@ namespace Ink_Canvas
// 设置编辑模式为非选择模式
inkCanvas.EditingMode = InkCanvasEditingMode.None;
}
inkCanvas.Children.Add(image);
// 绑定事件处理器
@@ -3009,11 +3010,11 @@ namespace Ink_Canvas
}
CenterAndScaleElement(image);
// 设置图片属性,避免被InkCanvas选择系统处理
image.IsHitTestVisible = true;
image.Focusable = false;
// 初始化InkCanvas选择设置
if (inkCanvas != null)
{
@@ -3022,7 +3023,7 @@ namespace Ink_Canvas
// 设置编辑模式为非选择模式
inkCanvas.EditingMode = InkCanvasEditingMode.None;
}
inkCanvas.Children.Add(image);
// 绑定事件处理器
@@ -3064,7 +3065,7 @@ namespace Ink_Canvas
if (floatingBarPanel == null) return 0;
double currentPosition = 0;
// 遍历浮动栏中的所有子元素
foreach (var child in floatingBarPanel.Children)
{
@@ -3075,12 +3076,12 @@ namespace Ink_Canvas
{
return currentPosition;
}
// 累加当前元素的位置
currentPosition += GetElementWidth(element);
}
}
return 0;
}
catch (Exception ex)
@@ -3114,7 +3115,7 @@ namespace Ink_Canvas
{
return fe.ActualWidth > 0 ? fe.ActualWidth : 28; // 默认宽度28
}
// 对于其他元素,使用其宽度或默认宽度
return fe.ActualWidth > 0 ? fe.ActualWidth : 28;
}
@@ -3134,7 +3135,7 @@ namespace Ink_Canvas
double position = 0;
double buttonWidth = 28; // 每个按钮的默认宽度
double highlightWidth = 28; // 高光的默认宽度
// 检查快捷调色盘是否显示及其实际宽度
bool isQuickColorPaletteVisible = false;
double quickColorPaletteWidth = 0;
@@ -3160,12 +3161,12 @@ namespace Ink_Canvas
// 获取高光的实际宽度
double actualHighlightWidth = FloatingbarSelectionBG.ActualWidth > 0 ? FloatingbarSelectionBG.ActualWidth : highlightWidth;
double marginOffset = 0;
double marginOffset = 0;
// 快捷调色盘的MarginMargin="4,0,4,0",所以总宽度需要加上8像素
double quickColorPaletteTotalWidth = isQuickColorPaletteVisible ? quickColorPaletteWidth + 8 : 0;
// 根据模式计算位置,确保高光居中对齐按钮
switch (mode)
{
@@ -3304,7 +3305,7 @@ namespace Ink_Canvas
{
LogHelper.WriteLogToFile($"获取当前选中模式失败: {ex.Message}", LogHelper.LogType.Error);
}
return string.Empty;
}
@@ -3323,134 +3324,134 @@ namespace Ink_Canvas
SymbolIconSelect.TouchDown += (s, e) => SymbolIconSelect_MouseUp(s, null);
SymbolIconSelect.StylusDown += (s, e) => SymbolIconSelect_MouseUp(s, null);
}
if (SymbolIconUndo != null)
{
SymbolIconUndo.TouchDown += (s, e) => SymbolIconUndo_MouseUp(s, null);
SymbolIconUndo.StylusDown += (s, e) => SymbolIconUndo_MouseUp(s, null);
}
if (SymbolIconRedo != null)
{
SymbolIconRedo.TouchDown += (s, e) => SymbolIconRedo_MouseUp(s, null);
SymbolIconRedo.StylusDown += (s, e) => SymbolIconRedo_MouseUp(s, null);
}
if (SymbolIconDelete != null)
{
SymbolIconDelete.TouchDown += (s, e) => SymbolIconDelete_MouseUp(s, null);
SymbolIconDelete.StylusDown += (s, e) => SymbolIconDelete_MouseUp(s, null);
}
if (ToolsFloatingBarBtn != null)
{
ToolsFloatingBarBtn.TouchDown += (s, e) => SymbolIconTools_MouseUp(s, null);
ToolsFloatingBarBtn.StylusDown += (s, e) => SymbolIconTools_MouseUp(s, null);
}
if (RandomDrawPanel != null)
{
RandomDrawPanel.TouchDown += (s, e) => SymbolIconRand_MouseUp(s, null);
RandomDrawPanel.StylusDown += (s, e) => SymbolIconRand_MouseUp(s, null);
}
if (SingleDrawPanel != null)
{
SingleDrawPanel.TouchDown += (s, e) => SymbolIconRandOne_MouseUp(s, null);
SingleDrawPanel.StylusDown += (s, e) => SymbolIconRandOne_MouseUp(s, null);
}
// 注意:Screenshot和Settings按钮在XAML中没有直接的Name属性,需要通过其他方式绑定
// 这些按钮的事件处理已经在XAML中通过MouseUp绑定
if (BorderFloatingBarMoveControls != null)
{
BorderFloatingBarMoveControls.TouchDown += (s, e) => SymbolIconEmoji_MouseUp(s, null);
BorderFloatingBarMoveControls.StylusDown += (s, e) => SymbolIconEmoji_MouseUp(s, null);
}
// 白板模式下的按钮不添加触摸事件支持,保持原有的鼠标事件处理
// 为快捷调色盘按钮添加触摸和手写笔事件支持
if (QuickColorWhite != null)
{
QuickColorWhite.TouchDown += (s, e) => QuickColorWhite_Click(s, null);
QuickColorWhite.StylusDown += (s, e) => QuickColorWhite_Click(s, null);
}
if (QuickColorOrange != null)
{
QuickColorOrange.TouchDown += (s, e) => QuickColorOrange_Click(s, null);
QuickColorOrange.StylusDown += (s, e) => QuickColorOrange_Click(s, null);
}
if (QuickColorYellow != null)
{
QuickColorYellow.TouchDown += (s, e) => QuickColorYellow_Click(s, null);
QuickColorYellow.StylusDown += (s, e) => QuickColorYellow_Click(s, null);
}
if (QuickColorBlack != null)
{
QuickColorBlack.TouchDown += (s, e) => QuickColorBlack_Click(s, null);
QuickColorBlack.StylusDown += (s, e) => QuickColorBlack_Click(s, null);
}
if (QuickColorBlue != null)
{
QuickColorBlue.TouchDown += (s, e) => QuickColorBlue_Click(s, null);
QuickColorBlue.StylusDown += (s, e) => QuickColorBlue_Click(s, null);
}
if (QuickColorRed != null)
{
QuickColorRed.TouchDown += (s, e) => QuickColorRed_Click(s, null);
QuickColorRed.StylusDown += (s, e) => QuickColorRed_Click(s, null);
}
if (QuickColorGreen != null)
{
QuickColorGreen.TouchDown += (s, e) => QuickColorGreen_Click(s, null);
QuickColorGreen.StylusDown += (s, e) => QuickColorGreen_Click(s, null);
}
if (QuickColorPurple != null)
{
QuickColorPurple.TouchDown += (s, e) => QuickColorPurple_Click(s, null);
QuickColorPurple.StylusDown += (s, e) => QuickColorPurple_Click(s, null);
}
// 单行快捷调色盘
if (QuickColorWhiteSingle != null)
{
QuickColorWhiteSingle.TouchDown += (s, e) => QuickColorWhite_Click(s, null);
QuickColorWhiteSingle.StylusDown += (s, e) => QuickColorWhite_Click(s, null);
}
if (QuickColorOrangeSingle != null)
{
QuickColorOrangeSingle.TouchDown += (s, e) => QuickColorOrange_Click(s, null);
QuickColorOrangeSingle.StylusDown += (s, e) => QuickColorOrange_Click(s, null);
}
if (QuickColorYellowSingle != null)
{
QuickColorYellowSingle.TouchDown += (s, e) => QuickColorYellow_Click(s, null);
QuickColorYellowSingle.StylusDown += (s, e) => QuickColorYellow_Click(s, null);
}
if (QuickColorBlackSingle != null)
{
QuickColorBlackSingle.TouchDown += (s, e) => QuickColorBlack_Click(s, null);
QuickColorBlackSingle.StylusDown += (s, e) => QuickColorBlack_Click(s, null);
}
if (QuickColorRedSingle != null)
{
QuickColorRedSingle.TouchDown += (s, e) => QuickColorRed_Click(s, null);
QuickColorRedSingle.StylusDown += (s, e) => QuickColorRed_Click(s, null);
}
if (QuickColorGreenSingle != null)
{
QuickColorGreenSingle.TouchDown += (s, e) => QuickColorGreen_Click(s, null);
+1 -1
View File
@@ -8,7 +8,7 @@ namespace Ink_Canvas
private void Window_MouseWheel(object sender, MouseWheelEventArgs e)
{
if (StackPanelPPTControls.Visibility != Visibility.Visible || currentMode != 0) return;
// 直接发送翻页请求到PPT放映软件,不通过软件处理
if (e.Delta >= 120)
{
+8 -8
View File
@@ -1,3 +1,4 @@
using Ink_Canvas.Helpers;
using System;
using System.Collections.Generic;
using System.Drawing;
@@ -11,7 +12,6 @@ using System.Windows.Forms;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using Ink_Canvas.Helpers;
using Application = System.Windows.Application;
using Color = System.Drawing.Color;
using Cursors = System.Windows.Input.Cursors;
@@ -190,11 +190,11 @@ namespace Ink_Canvas
// 初始化TransformGroup
InitializeScreenshotTransform(image);
// 设置截图属性,避免被InkCanvas选择系统处理
image.IsHitTestVisible = true;
image.Focusable = false;
// 初始化InkCanvas选择设置
InitializeInkCanvasSelectionSettings();
@@ -251,7 +251,7 @@ namespace Ink_Canvas
// 设置光标
image.Cursor = Cursors.Hand;
// 禁用InkCanvas对截图的选择处理
image.IsHitTestVisible = true;
image.Focusable = false;
@@ -360,13 +360,13 @@ namespace Ink_Canvas
// 创建结果位图,确保支持透明度
var resultBitmap = new Bitmap(bitmap.Width, bitmap.Height, PixelFormat.Format32bppArgb);
// 首先将整个位图设置为透明
using (var resultGraphics = Graphics.FromImage(resultBitmap))
{
// 清除位图,设置为完全透明
resultGraphics.Clear(Color.Transparent);
// 设置高质量渲染
resultGraphics.SmoothingMode = SmoothingMode.AntiAlias;
resultGraphics.CompositingQuality = CompositingQuality.HighQuality;
@@ -406,7 +406,7 @@ namespace Ink_Canvas
// 在裁剪区域内绘制原始图像
resultGraphics.DrawImage(bitmap, 0, 0);
// 重置裁剪区域,确保后续操作不受影响
resultGraphics.ResetClip();
}
@@ -466,4 +466,4 @@ namespace Ink_Canvas
return 1.0; // 默认DPI
}
}
}
}
+2 -2
View File
@@ -1,8 +1,8 @@
using System;
using Ink_Canvas.Helpers;
using System;
using System.Linq;
using System.Threading;
using System.Windows;
using Ink_Canvas.Helpers;
namespace Ink_Canvas
{
+8 -8
View File
@@ -1,4 +1,8 @@
using System;
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
@@ -8,10 +12,6 @@ using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Threading;
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
using Application = System.Windows.Application;
using File = System.IO.File;
using MessageBox = System.Windows.MessageBox;
@@ -265,13 +265,13 @@ namespace Ink_Canvas
{
// 在初始化墨迹管理器之前,先清理画布上的所有墨迹
ClearStrokes(true);
// 清理备份历史记录,防止旧演示文稿的墨迹影响新演示文稿
if (TimeMachineHistories != null && TimeMachineHistories.Length > 0)
{
TimeMachineHistories[0] = null;
}
// 初始化墨迹管理器
_pptInkManager?.InitializePresentation(pres);
@@ -291,7 +291,7 @@ namespace Ink_Canvas
}
_pptUIManager?.UpdateConnectionStatus(true);
LogHelper.WriteLogToFile($"已打开新演示文稿: {pres.Name},墨迹状态已清理", LogHelper.LogType.Event);
});
}
+4 -4
View File
@@ -1,10 +1,10 @@
using System.Collections.ObjectModel;
using Ink_Canvas.Helpers;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Input;
using Ink_Canvas.Helpers;
namespace Ink_Canvas
{
@@ -96,7 +96,7 @@ namespace Ink_Canvas
inkCanvas.EditingMode = previousEditingMode;
currentSelectedElement = null;
}
SaveStrokes();
ClearStrokes(true);
CurrentWhiteboardIndex = index + 1;
@@ -129,7 +129,7 @@ namespace Ink_Canvas
inkCanvas.EditingMode = previousEditingMode;
currentSelectedElement = null;
}
SaveStrokes();
ClearStrokes(true);
CurrentWhiteboardIndex = index + 1;
@@ -1,3 +1,5 @@
using Ink_Canvas.Helpers;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Drawing;
@@ -12,8 +14,6 @@ using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Ink_Canvas.Helpers;
using Newtonsoft.Json;
using Color = System.Drawing.Color;
using File = System.IO.File;
using Image = System.Windows.Controls.Image;
@@ -1,3 +1,4 @@
using iNKORE.UI.WPF.Modern.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -6,7 +7,6 @@ using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using iNKORE.UI.WPF.Modern.Controls;
using Point = System.Windows.Point;
namespace Ink_Canvas
@@ -305,18 +305,18 @@ namespace Ink_Canvas
private void inkCanvas_SelectionChanged(object sender, EventArgs e)
{
if (isProgramChangeStrokeSelection) return;
// 检查是否有图片元素被选中
var selectedElements = inkCanvas.GetSelectedElements();
bool hasImageElement = selectedElements.Any(element => element is Image);
// 如果有图片元素被选中,不显示选择框
if (hasImageElement)
{
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
return;
}
if (inkCanvas.GetSelectedStrokes().Count == 0)
{
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
@@ -520,7 +520,7 @@ namespace Ink_Canvas
}
#region UIElement Selection and Resize
private Rect GetUIElementBounds(UIElement element)
{
if (element is FrameworkElement fe)
+25 -25
View File
@@ -1,3 +1,7 @@
using Hardcodet.Wpf.TaskbarNotification;
using Ink_Canvas.Helpers;
using Newtonsoft.Json;
using OSVersionExtension;
using System;
using System.Diagnostics;
using System.IO;
@@ -10,10 +14,6 @@ using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using Hardcodet.Wpf.TaskbarNotification;
using Ink_Canvas.Helpers;
using Newtonsoft.Json;
using OSVersionExtension;
using Application = System.Windows.Application;
using CheckBox = System.Windows.Controls.CheckBox;
using ComboBox = System.Windows.Controls.ComboBox;
@@ -984,7 +984,7 @@ namespace Ink_Canvas
PPTBtnPreviewRSTransform.Y = -(Settings.PowerPointSettings.PPTRSButtonPosition * 0.5);
PPTBtnPreviewLSTransform.Y = -(Settings.PowerPointSettings.PPTLSButtonPosition * 0.5);
PPTBtnPreviewLBTransform.X = -(Settings.PowerPointSettings.PPTLBButtonPosition * 0.5);
PPTBtnPreviewRBTransform.X = -(Settings.PowerPointSettings.PPTRBButtonPosition * 0.5);
}
@@ -1918,7 +1918,7 @@ namespace Ink_Canvas
Settings.Appearance.ViewboxFloatingBarOpacityValue = 1.0;
Settings.Appearance.ViewboxFloatingBarOpacityInPPTValue = 1.0;
Settings.Appearance.EnableTrayIcon = true;
// 浮动栏按钮显示控制默认值
Settings.Appearance.IsShowShapeButton = true;
Settings.Appearance.IsShowUndoButton = true;
@@ -1929,8 +1929,8 @@ namespace Ink_Canvas
Settings.Appearance.IsShowLassoSelectButton = true;
Settings.Appearance.IsShowClearAndMouseButton = true;
Settings.Appearance.IsShowQuickColorPalette = false;
Settings.Appearance.QuickColorPaletteDisplayMode = 1;
Settings.Appearance.EraserDisplayOption = 0;
Settings.Appearance.QuickColorPaletteDisplayMode = 1;
Settings.Appearance.EraserDisplayOption = 0;
Settings.Automation.IsAutoFoldInEasiNote = true;
Settings.Automation.IsAutoFoldInEasiNoteIgnoreDesktopAnno = true;
@@ -2032,7 +2032,7 @@ namespace Ink_Canvas
LoadSettings();
isLoaded = true;
ToggleSwitchRunAtStartup.IsOn = false;
ToggleSwitchRunAtStartup.IsOn = false;
}
catch { }
@@ -2488,7 +2488,7 @@ namespace Ink_Canvas
UpdateFloatingBarButtonsVisibility();
SaveSettingsToFile();
}
private void CheckBoxShowLassoSelectButton_Checked(object sender, RoutedEventArgs e)
{
if (!isLoaded) return;
@@ -2577,33 +2577,33 @@ namespace Ink_Canvas
// 形状按钮
if (ShapeDrawFloatingBarBtn != null)
ShapeDrawFloatingBarBtn.Visibility = Settings.Appearance.IsShowShapeButton ? Visibility.Visible : Visibility.Collapsed;
// 撤销按钮
if (SymbolIconUndo != null)
SymbolIconUndo.Visibility = Settings.Appearance.IsShowUndoButton ? Visibility.Visible : Visibility.Collapsed;
// 重做按钮
if (SymbolIconRedo != null)
SymbolIconRedo.Visibility = Settings.Appearance.IsShowRedoButton ? Visibility.Visible : Visibility.Collapsed;
// 清空按钮
if (SymbolIconDelete != null)
SymbolIconDelete.Visibility = Settings.Appearance.IsShowClearButton ? Visibility.Visible : Visibility.Collapsed;
// 白板按钮
if (WhiteboardFloatingBarBtn != null)
WhiteboardFloatingBarBtn.Visibility = Settings.Appearance.IsShowWhiteboardButton ? Visibility.Visible : Visibility.Collapsed;
// 隐藏按钮
if (Fold_Icon != null)
Fold_Icon.Visibility = Settings.Appearance.IsShowHideButton ? Visibility.Visible : Visibility.Collapsed;
// 快捷调色盘
// 快捷调色盘
if (QuickColorPalettePanel != null && QuickColorPaletteSingleRowPanel != null)
{
bool shouldShow = Settings.Appearance.IsShowQuickColorPalette && inkCanvas.EditingMode == InkCanvasEditingMode.Ink;
bool wasVisible = QuickColorPalettePanel.Visibility == Visibility.Visible || QuickColorPaletteSingleRowPanel.Visibility == Visibility.Visible;
if (shouldShow)
{
// 根据显示模式选择显示哪个面板
@@ -2625,7 +2625,7 @@ namespace Ink_Canvas
QuickColorPalettePanel.Visibility = Visibility.Collapsed;
QuickColorPaletteSingleRowPanel.Visibility = Visibility.Collapsed;
}
// 如果快捷调色盘的可见性发生变化,重新计算浮动栏位置
if (wasVisible != shouldShow && !isFloatingBarFolded)
{
@@ -2647,15 +2647,15 @@ namespace Ink_Canvas
}
}
}
// 套索选择按钮
if (SymbolIconSelect != null)
SymbolIconSelect.Visibility = Settings.Appearance.IsShowLassoSelectButton ? Visibility.Visible : Visibility.Collapsed;
// 清并鼠按钮
if (CursorWithDelFloatingBarBtn != null)
CursorWithDelFloatingBarBtn.Visibility = Settings.Appearance.IsShowClearAndMouseButton ? Visibility.Visible : Visibility.Collapsed;
// 橡皮按钮显示控制
if (Eraser_Icon != null && EraserByStrokes_Icon != null)
{
@@ -2679,7 +2679,7 @@ namespace Ink_Canvas
break;
}
}
// 在按钮可见性更新后,重新计算当前高光位置
// 延迟执行以确保UI更新完成
Dispatcher.BeginInvoke(new Action(async () =>
@@ -2688,14 +2688,14 @@ namespace Ink_Canvas
{
// 等待UI完全更新
await Task.Delay(100);
// 获取当前选中的模式并重新设置高光位置
string selectedToolMode = GetCurrentSelectedMode();
if (!string.IsNullOrEmpty(selectedToolMode))
{
SetFloatingBarHighlightPosition(selectedToolMode);
}
// 重新计算浮动栏位置,因为按钮可见性变化会影响浮动栏宽度
if (!isFloatingBarFolded && currentMode == 0) // 新增:只在屏幕模式下重新计算浮动栏位置
{
@@ -1,4 +1,8 @@
using System;
using Hardcodet.Wpf.TaskbarNotification;
using Ink_Canvas.Helpers;
using Newtonsoft.Json;
using OSVersionExtension;
using System;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
@@ -6,10 +10,6 @@ using System.Windows.Ink;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Hardcodet.Wpf.TaskbarNotification;
using Ink_Canvas.Helpers;
using Newtonsoft.Json;
using OSVersionExtension;
using File = System.IO.File;
using OperatingSystem = OSVersionExtension.OperatingSystem;
@@ -327,10 +327,10 @@ namespace Ink_Canvas
CheckBoxShowClearAndMouseButton.IsChecked = Settings.Appearance.IsShowClearAndMouseButton;
ComboBoxEraserDisplayOption.SelectedIndex = Settings.Appearance.EraserDisplayOption;
ComboBoxQuickColorPaletteDisplayMode.SelectedIndex = Settings.Appearance.QuickColorPaletteDisplayMode;
// 初始化快捷调色盘指示器
UpdateQuickColorPaletteIndicator(inkCanvas.DefaultDrawingAttributes.Color);
// 应用浮动栏按钮可见性设置
UpdateFloatingBarButtonsVisibility();
+36 -36
View File
@@ -1,4 +1,6 @@
using System;
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern.Controls;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
@@ -8,8 +10,6 @@ using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern.Controls;
using MessageBox = System.Windows.MessageBox;
using Point = System.Windows.Point;
@@ -178,12 +178,12 @@ namespace Ink_Canvas
await CheckIsDrawingShapesInMultiTouchMode();
EnterShapeDrawingMode(1);
lastMouseDownSender = null;
// 先保存长按状态,避免被CancelSingleFingerDragMode重置
bool wasLongPressed = isLongPressSelected;
CancelSingleFingerDragMode();
if (wasLongPressed)
{
if (ToggleSwitchDrawShapeBorderAutoHide.IsOn) CollapseBorderDrawShape();
@@ -200,12 +200,12 @@ namespace Ink_Canvas
await CheckIsDrawingShapesInMultiTouchMode();
EnterShapeDrawingMode(8);
lastMouseDownSender = null;
// 先保存长按状态,避免被CancelSingleFingerDragMode重置
bool wasLongPressed = isLongPressSelected;
CancelSingleFingerDragMode();
if (wasLongPressed)
{
if (ToggleSwitchDrawShapeBorderAutoHide.IsOn) CollapseBorderDrawShape();
@@ -222,12 +222,12 @@ namespace Ink_Canvas
await CheckIsDrawingShapesInMultiTouchMode();
EnterShapeDrawingMode(18);
lastMouseDownSender = null;
// 先保存长按状态,避免被CancelSingleFingerDragMode重置
bool wasLongPressed = isLongPressSelected;
CancelSingleFingerDragMode();
if (wasLongPressed)
{
if (ToggleSwitchDrawShapeBorderAutoHide.IsOn) CollapseBorderDrawShape();
@@ -244,12 +244,12 @@ namespace Ink_Canvas
await CheckIsDrawingShapesInMultiTouchMode();
EnterShapeDrawingMode(2);
lastMouseDownSender = null;
// 先保存长按状态,避免被CancelSingleFingerDragMode重置
bool wasLongPressed = isLongPressSelected;
CancelSingleFingerDragMode();
if (wasLongPressed)
{
if (ToggleSwitchDrawShapeBorderAutoHide.IsOn) CollapseBorderDrawShape();
@@ -266,12 +266,12 @@ namespace Ink_Canvas
await CheckIsDrawingShapesInMultiTouchMode();
EnterShapeDrawingMode(15);
lastMouseDownSender = null;
// 先保存长按状态,避免被CancelSingleFingerDragMode重置
bool wasLongPressed = isLongPressSelected;
CancelSingleFingerDragMode();
if (wasLongPressed)
{
if (ToggleSwitchDrawShapeBorderAutoHide.IsOn) CollapseBorderDrawShape();
@@ -484,7 +484,7 @@ namespace Ink_Canvas
{
// 确保几何绘制模式下不切换到Ink模式,避免触摸轨迹被收集
inkCanvas.EditingMode = InkCanvasEditingMode.None;
if (isWaitUntilNextTouchDown && dec.Count > 1) return;
if (dec.Count > 1)
{
@@ -512,7 +512,7 @@ namespace Ink_Canvas
}
return;
}
// 修复:双曲线绘制时,第二笔应该基于第一笔的起点,而不是触摸实时位置
Point touchPoint = e.GetTouchPoint(inkCanvas).Position;
if ((drawingShapeMode == 24 || drawingShapeMode == 25) && drawMultiStepShapeCurrentStep == 1)
@@ -526,7 +526,7 @@ namespace Ink_Canvas
// 其他情况正常处理
MouseTouchMove(touchPoint);
}
return; // 处理完几何绘制后直接返回,不执行后面的代码
}
@@ -890,7 +890,7 @@ namespace Ink_Canvas
lastTempStroke = stroke;
inkCanvas.Strokes.Add(stroke);
// 如果启用了圆心标记功能,则绘制圆心
if (Settings.Canvas.ShowCircleCenter)
{
@@ -995,7 +995,7 @@ namespace Ink_Canvas
lastTempStrokeCollection = strokes;
inkCanvas.Strokes.Add(strokes);
// 如果启用了圆心标记功能,则绘制圆心
if (Settings.Canvas.ShowCircleCenter)
{
@@ -1021,7 +1021,7 @@ namespace Ink_Canvas
new Point(endP.X, 2 * iniP.Y - endP.Y)));
drawMultiStepShapeSpecialParameter3 = k;
drawMultiStepShapeSpecialStrokeCollection = strokes;
// 修复:第一笔绘制的辅助线应该立即显示在画布上
try
{
@@ -1120,10 +1120,10 @@ namespace Ink_Canvas
{
// 删除第二笔的临时笔画
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
// 创建包含辅助线和双曲线的完整笔画集合
var completeStrokes = new StrokeCollection();
// 添加第一笔的辅助线
if (drawMultiStepShapeSpecialStrokeCollection != null && drawMultiStepShapeSpecialStrokeCollection.Count > 0)
{
@@ -1132,13 +1132,13 @@ namespace Ink_Canvas
completeStrokes.Add(stroke1.Clone());
}
}
// 添加第二笔的双曲线
foreach (var stroke1 in strokes)
{
completeStrokes.Add(stroke1.Clone());
}
lastTempStrokeCollection = completeStrokes;
inkCanvas.Strokes.Add(completeStrokes);
}
@@ -1523,7 +1523,7 @@ namespace Ink_Canvas
return pointList;
}
private StrokeCollection GenerateDashedLineEllipseStrokeCollection(Point st, Point ed, bool isDrawTop = true,
bool isDrawBottom = true)
{
@@ -1671,14 +1671,14 @@ namespace Ink_Canvas
var mousePoint = e.GetPosition(this);
var floatingBarBounds = ViewboxFloatingBar.TransformToAncestor(this).TransformBounds(
new Rect(0, 0, ViewboxFloatingBar.ActualWidth, ViewboxFloatingBar.ActualHeight));
// 如果鼠标点击发生在浮动栏区域,不阻止事件传播,让浮动栏按钮能够接收鼠标事件
if (floatingBarBounds.Contains(mousePoint))
{
// 不设置 ViewboxFloatingBar.IsHitTestVisible = false,让浮动栏按钮能够接收鼠标事件
return;
}
inkCanvas.CaptureMouse();
ViewboxFloatingBar.IsHitTestVisible = false;
BlackboardUIGridForInkReplay.IsHitTestVisible = false;
@@ -1968,7 +1968,7 @@ namespace Ink_Canvas
}
}
}
private void EnterShapeDrawingMode(int mode)
{
forceEraser = true;
@@ -1988,7 +1988,7 @@ namespace Ink_Canvas
{
// 创建一个点作为圆心标记
var centerSize = 0.5; // 圆心标记的大小
// 创建一个小圆作为圆心标记
var circlePoints = new List<Point>();
for (double angle = 0; angle <= 2 * Math.PI; angle += 0.1)
@@ -1998,18 +1998,18 @@ namespace Ink_Canvas
centerPoint.Y + centerSize * Math.Sin(angle)
));
}
// 绘制圆心点
var point = new StylusPointCollection(circlePoints);
var stroke = new Stroke(point)
{
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
};
// 设置圆心点的样式
stroke.DrawingAttributes.Width = 2.0;
stroke.DrawingAttributes.Height = 2.0;
// 添加到画布
inkCanvas.Strokes.Add(stroke);
}
@@ -1,4 +1,5 @@
using System;
using Ink_Canvas.Helpers;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
@@ -8,7 +9,6 @@ using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using Ink_Canvas.Helpers;
using Point = System.Windows.Point;
namespace Ink_Canvas
@@ -62,13 +62,13 @@ namespace Ink_Canvas
// 获取墨迹的起点和终点
var startPoint = e.Stroke.StylusPoints.Count > 0 ? e.Stroke.StylusPoints[0].ToPoint() : new Point();
var endPoint = e.Stroke.StylusPoints.Count > 0 ? e.Stroke.StylusPoints[e.Stroke.StylusPoints.Count - 1].ToPoint() : new Point();
// 从InkCanvas中移除墨迹,因为我们要用渐隐管理器来管理它
if (inkCanvas.Strokes.Contains(e.Stroke))
{
inkCanvas.Strokes.Remove(e.Stroke);
}
// 添加到墨迹渐隐管理器
if (_inkFadeManager != null)
{
@@ -78,11 +78,11 @@ namespace Ink_Canvas
{
LogHelper.WriteLogToFile("StrokeCollected: 墨迹渐隐管理器为空,无法添加墨迹", LogHelper.LogType.Error);
}
// 墨迹渐隐模式下不参与墨迹纠正和其他处理,直接返回
return;
}
// 标记是否进行了直线拉直
bool wasStraightened = false;
+6 -6
View File
@@ -1,4 +1,5 @@
using System;
using Ink_Canvas.Helpers;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
@@ -6,7 +7,6 @@ using System.Windows.Controls;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using Ink_Canvas.Helpers;
namespace Ink_Canvas
{
@@ -193,13 +193,13 @@ namespace Ink_Canvas
// 检查图片是否有位置信息,如果没有则应用居中
double left = InkCanvas.GetLeft(img);
double top = InkCanvas.GetTop(img);
if (double.IsNaN(left) || double.IsNaN(top))
{
// 图片没有位置信息,应用居中
CenterAndScaleElement(img);
}
// 重新绑定事件处理器
BindElementEvents(img);
}
@@ -208,13 +208,13 @@ namespace Ink_Canvas
// 检查媒体元素是否有位置信息,如果没有则应用居中
double left = InkCanvas.GetLeft(media);
double top = InkCanvas.GetTop(media);
if (double.IsNaN(left) || double.IsNaN(top))
{
// 媒体元素没有位置信息,应用居中
CenterAndScaleElement(media);
}
// 重新绑定事件处理器
BindElementEvents(media);
}
+2 -2
View File
@@ -1,4 +1,5 @@
using System;
using Ink_Canvas.Helpers;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
@@ -11,7 +12,6 @@ using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using Ink_Canvas.Helpers;
namespace Ink_Canvas
{
+135 -135
View File
@@ -1,3 +1,4 @@
using Ink_Canvas.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -8,7 +9,6 @@ using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using Ink_Canvas.Helpers;
using Point = System.Windows.Point;
namespace Ink_Canvas
@@ -113,14 +113,14 @@ namespace Ink_Canvas
var touchPoint = e.GetTouchPoint(this);
var floatingBarBounds = ViewboxFloatingBar.TransformToAncestor(this).TransformBounds(
new Rect(0, 0, ViewboxFloatingBar.ActualWidth, ViewboxFloatingBar.ActualHeight));
// 如果触摸发生在浮动栏区域,不阻止事件传播,让浮动栏按钮能够接收触摸事件
if (floatingBarBounds.Contains(touchPoint.Position))
{
// 不设置 ViewboxFloatingBar.IsHitTestVisible = false,让浮动栏按钮能够接收触摸事件
return;
}
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint
|| inkCanvas.EditingMode == InkCanvasEditingMode.EraseByStroke
|| inkCanvas.EditingMode == InkCanvasEditingMode.Select) return;
@@ -142,7 +142,7 @@ namespace Ink_Canvas
// 只保留普通橡皮逻辑
TouchDownPointsList[e.TouchDevice.Id] = InkCanvasEditingMode.None;
inkCanvas.EraserShape = new EllipseStylusShape(50, 50);
if (inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint
if (inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint
&& inkCanvas.EditingMode != InkCanvasEditingMode.EraseByStroke)
{
inkCanvas.EditingMode = InkCanvasEditingMode.None;
@@ -155,16 +155,16 @@ namespace Ink_Canvas
var stylusPoint = e.GetPosition(this);
var floatingBarBounds = ViewboxFloatingBar.TransformToAncestor(this).TransformBounds(
new Rect(0, 0, ViewboxFloatingBar.ActualWidth, ViewboxFloatingBar.ActualHeight));
// 如果手写笔点击发生在浮动栏区域,不阻止事件传播,让浮动栏按钮能够接收手写笔事件
if (floatingBarBounds.Contains(stylusPoint))
{
// 不设置 ViewboxFloatingBar.IsHitTestVisible = false,让浮动栏按钮能够接收手写笔事件
return;
}
LogHelper.WriteLogToFile($"MainWindow_StylusDown 被调用,笔尾状态: {e.StylusDevice.Inverted}, 当前 drawingShapeMode: {drawingShapeMode}, 当前 EditingMode: {inkCanvas.EditingMode}");
// 新增:根据是否为笔尾自动切换橡皮擦/画笔模式
if (e.StylusDevice.Inverted)
{
@@ -232,14 +232,14 @@ namespace Ink_Canvas
try
{
LogHelper.WriteLogToFile($"MainWindow_StylusUp 被调用,EditingMode: {inkCanvas.EditingMode}, EnableInkFade: {Settings.Canvas.EnableInkFade}");
var stroke = GetStrokeVisual(e.StylusDevice.Id).Stroke;
LogHelper.WriteLogToFile($"获取到墨迹,StylusPoints数量: {stroke.StylusPoints.Count}");
// 正常模式:添加到画布并参与墨迹纠正
// 墨迹渐隐功能现在在 StrokeCollected 事件中统一处理所有输入方式
LogHelper.WriteLogToFile("StylusUp: 添加墨迹到画布");
inkCanvas.Strokes.Add(stroke);
await Task.Delay(5); // 避免渲染墨迹完成前预览墨迹被删除导致墨迹闪烁
inkCanvas.Children.Remove(GetVisualCanvas(e.StylusDevice.Id));
@@ -351,14 +351,14 @@ namespace Ink_Canvas
var touchPoint = e.GetTouchPoint(this);
var floatingBarBounds = ViewboxFloatingBar.TransformToAncestor(this).TransformBounds(
new Rect(0, 0, ViewboxFloatingBar.ActualWidth, ViewboxFloatingBar.ActualHeight));
// 如果触摸发生在浮动栏区域,不阻止事件传播,让浮动栏按钮能够接收触摸事件
if (floatingBarBounds.Contains(touchPoint.Position))
{
// 不设置 ViewboxFloatingBar.IsHitTestVisible = false,让浮动栏按钮能够接收触摸事件
return;
}
SetCursorBasedOnEditingMode(inkCanvas);
inkCanvas.CaptureTouch(e.TouchDevice);
@@ -411,14 +411,14 @@ namespace Ink_Canvas
var touchPoint = e.GetTouchPoint(this);
var floatingBarBounds = ViewboxFloatingBar.TransformToAncestor(this).TransformBounds(
new Rect(0, 0, ViewboxFloatingBar.ActualWidth, ViewboxFloatingBar.ActualHeight));
// 如果触摸发生在浮动栏区域,不阻止事件传播,让浮动栏按钮能够接收触摸事件
if (floatingBarBounds.Contains(touchPoint.Position))
{
// 不设置 ViewboxFloatingBar.IsHitTestVisible = false,让浮动栏按钮能够接收触摸事件
return;
}
// 橡皮状态下不做任何切换,直接return,保证橡皮可持续
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint
|| inkCanvas.EditingMode == InkCanvasEditingMode.EraseByStroke)
@@ -435,7 +435,7 @@ namespace Ink_Canvas
inkCanvas.CaptureTouch(e.TouchDevice);
ViewboxFloatingBar.IsHitTestVisible = false;
BlackboardUIGridForInkReplay.IsHitTestVisible = false;
// 修复:几何绘制模式下,只记录几何绘制的起点,不记录触摸轨迹
if (dec.Count == 0)
{
@@ -460,108 +460,108 @@ namespace Ink_Canvas
dec.Add(e.TouchDevice.Id);
return;
}
// 非几何绘制模式下的正常触摸处理
SetCursorBasedOnEditingMode(inkCanvas);
inkCanvas.CaptureTouch(e.TouchDevice);
ViewboxFloatingBar.IsHitTestVisible = false;
BlackboardUIGridForInkReplay.IsHitTestVisible = false;
dec.Add(e.TouchDevice.Id);
// Palm Eraser 逻辑 - 优化:改进手掌判定条件,提高精度
if (Settings.Canvas.EnablePalmEraser && dec.Count >= 2 && !isPalmEraserActive && !palmEraserTouchDownHandled)
{
var bounds = e.GetTouchPoint(inkCanvas).Bounds;
// 根据敏感度设置调整判定参数
double palmThreshold;
double aspectRatioThreshold;
int minTouchPoints;
switch (Settings.Canvas.PalmEraserSensitivity)
{
case 0: // 低敏感度 - 更严格的判定
palmThreshold = 80;
aspectRatioThreshold = 0.4;
minTouchPoints = 4;
break;
case 1: // 中敏感度 - 平衡的判定
palmThreshold = 60;
aspectRatioThreshold = 0.3;
minTouchPoints = 3;
break;
case 2: // 高敏感度 - 较宽松的判定
default:
palmThreshold = 50;
aspectRatioThreshold = 0.25;
minTouchPoints = 2;
break;
}
// 计算宽高比
double aspectRatio = Math.Min(bounds.Width, bounds.Height) / Math.Max(bounds.Width, bounds.Height);
// 更严格的手掌判定条件
bool isLargeTouch = bounds.Width >= palmThreshold && bounds.Height >= palmThreshold;
bool isPalmLikeShape = aspectRatio >= aspectRatioThreshold;
bool hasMultipleTouchPoints = dec.Count >= minTouchPoints;
if (isLargeTouch && isPalmLikeShape && hasMultipleTouchPoints)
{
// 记录当前编辑模式和高光状态
palmEraserLastEditingMode = inkCanvas.EditingMode;
palmEraserLastIsHighlighter = drawingAttributes.IsHighlighter;
// 记录参与手掌擦的触摸点ID
palmEraserTouchIds.Clear();
foreach (int touchId in dec)
{
palmEraserTouchIds.Add(touchId);
}
// 切换为橡皮擦
EraserIcon_Click(null, null);
isPalmEraserActive = true;
palmEraserActivationTime = DateTime.Now; // 记录激活时间
palmEraserTouchDownHandled = true; // 标记已处理
// 启动恢复定时器,防止卡死
StartPalmEraserRecoveryTimer();
// 记录日志
LogHelper.WriteLogToFile($"Palm eraser activated - Sensitivity: {Settings.Canvas.PalmEraserSensitivity}, Touch bounds: {bounds.Width}x{bounds.Height}, Aspect ratio: {aspectRatio:F2}, Touch points: {dec.Count}");
}
}
// 设备1个的时候,记录中心点
if (dec.Count == 1)
{
touchPoint = e.GetTouchPoint(inkCanvas);
centerPoint = touchPoint.Position;
// 修复:只允许在此处赋值iniP,防止TouchMove等其他地方覆盖,保证几何绘制起点一致
if (drawingShapeMode != 0)
// Palm Eraser 逻辑 - 优化:改进手掌判定条件,提高精度
if (Settings.Canvas.EnablePalmEraser && dec.Count >= 2 && !isPalmEraserActive && !palmEraserTouchDownHandled)
{
// 对于双曲线绘制,第一笔时记录起点,第二笔时不更新起点
if (drawingShapeMode == 24 || drawingShapeMode == 25)
var bounds = e.GetTouchPoint(inkCanvas).Bounds;
// 根据敏感度设置调整判定参数
double palmThreshold;
double aspectRatioThreshold;
int minTouchPoints;
switch (Settings.Canvas.PalmEraserSensitivity)
{
// 双曲线绘制:第一笔记录起点,第二笔保持第一笔的起点
if (drawMultiStepShapeCurrentStep == 0)
case 0: // 低敏感度 - 更严格的判定
palmThreshold = 80;
aspectRatioThreshold = 0.4;
minTouchPoints = 4;
break;
case 1: // 中敏感度 - 平衡的判定
palmThreshold = 60;
aspectRatioThreshold = 0.3;
minTouchPoints = 3;
break;
case 2: // 高敏感度 - 较宽松的判定
default:
palmThreshold = 50;
aspectRatioThreshold = 0.25;
minTouchPoints = 2;
break;
}
// 计算宽高比
double aspectRatio = Math.Min(bounds.Width, bounds.Height) / Math.Max(bounds.Width, bounds.Height);
// 更严格的手掌判定条件
bool isLargeTouch = bounds.Width >= palmThreshold && bounds.Height >= palmThreshold;
bool isPalmLikeShape = aspectRatio >= aspectRatioThreshold;
bool hasMultipleTouchPoints = dec.Count >= minTouchPoints;
if (isLargeTouch && isPalmLikeShape && hasMultipleTouchPoints)
{
// 记录当前编辑模式和高光状态
palmEraserLastEditingMode = inkCanvas.EditingMode;
palmEraserLastIsHighlighter = drawingAttributes.IsHighlighter;
// 记录参与手掌擦的触摸点ID
palmEraserTouchIds.Clear();
foreach (int touchId in dec)
{
palmEraserTouchIds.Add(touchId);
}
// 切换为橡皮擦
EraserIcon_Click(null, null);
isPalmEraserActive = true;
palmEraserActivationTime = DateTime.Now; // 记录激活时间
palmEraserTouchDownHandled = true; // 标记已处理
// 启动恢复定时器,防止卡死
StartPalmEraserRecoveryTimer();
// 记录日志
LogHelper.WriteLogToFile($"Palm eraser activated - Sensitivity: {Settings.Canvas.PalmEraserSensitivity}, Touch bounds: {bounds.Width}x{bounds.Height}, Aspect ratio: {aspectRatio:F2}, Touch points: {dec.Count}");
}
}
// 设备1个的时候,记录中心点
if (dec.Count == 1)
{
touchPoint = e.GetTouchPoint(inkCanvas);
centerPoint = touchPoint.Position;
// 修复:只允许在此处赋值iniP,防止TouchMove等其他地方覆盖,保证几何绘制起点一致
if (drawingShapeMode != 0)
{
// 对于双曲线绘制,第一笔时记录起点,第二笔时不更新起点
if (drawingShapeMode == 24 || drawingShapeMode == 25)
{
// 双曲线绘制:第一笔记录起点,第二笔保持第一笔的起点
if (drawMultiStepShapeCurrentStep == 0)
{
iniP = touchPoint.Position;
}
// 第二笔时不更新iniP,保持第一笔的起点
}
else
{
// 其他图形正常记录起点
iniP = touchPoint.Position;
}
// 第二笔时不更新iniP,保持第一笔的起点
}
else
{
// 其他图形正常记录起点
iniP = touchPoint.Position;
}
}
// 记录第一根手指点击时的 StrokeCollection
lastTouchDownStrokeCollection = inkCanvas.Strokes.Clone();
}
// 记录第一根手指点击时的 StrokeCollection
lastTouchDownStrokeCollection = inkCanvas.Strokes.Clone();
}
//设备两个及两个以上,将画笔功能关闭
if (dec.Count > 1 || isSingleFingerDragMode || !Settings.Gesture.IsEnableTwoFingerGesture)
{
@@ -571,7 +571,7 @@ namespace Ink_Canvas
lastInkCanvasEditingMode = inkCanvas.EditingMode;
// 修复:几何绘制模式下禁止切回Ink
if (inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint
&& inkCanvas.EditingMode != InkCanvasEditingMode.EraseByStroke
&& inkCanvas.EditingMode != InkCanvasEditingMode.EraseByStroke
&& drawingShapeMode == 0)
{
inkCanvas.EditingMode = InkCanvasEditingMode.None;
@@ -592,19 +592,19 @@ namespace Ink_Canvas
// Palm Eraser 逻辑:优化状态恢复机制
dec.Remove(e.TouchDevice.Id);
// 如果是手掌擦的触摸点,从记录中移除
if (palmEraserTouchIds.Contains(e.TouchDevice.Id))
{
palmEraserTouchIds.Remove(e.TouchDevice.Id);
}
// 当所有手掌擦触摸点都抬起时,恢复原编辑模式
if (isPalmEraserActive && palmEraserTouchIds.Count == 0)
{
// 恢复高光状态
drawingAttributes.IsHighlighter = palmEraserLastIsHighlighter;
// 恢复编辑模式 - 优化:改进状态恢复逻辑
try
{
@@ -623,7 +623,7 @@ namespace Ink_Canvas
inkCanvas.EditingMode = palmEraserLastEditingMode;
break;
}
LogHelper.WriteLogToFile($"Palm eraser recovered to mode: {palmEraserLastEditingMode}");
}
}
@@ -633,25 +633,25 @@ namespace Ink_Canvas
LogHelper.WriteLogToFile($"Palm eraser recovery failed: {ex.Message}, forcing to Ink mode", LogHelper.LogType.Error);
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
}
// 重置手掌擦状态
isPalmEraserActive = false;
palmEraserTouchDownHandled = false;
palmEraserTouchIds.Clear();
// 停止恢复定时器
StopPalmEraserRecoveryTimer();
// 确保触摸事件能正常响应
inkCanvas.IsHitTestVisible = true;
inkCanvas.IsManipulationEnabled = true;
ViewboxFloatingBar.IsHitTestVisible = true;
BlackboardUIGridForInkReplay.IsHitTestVisible = true;
LogHelper.WriteLogToFile("Palm eraser state reset completed");
}
// 新增:超时检测 - 如果手掌擦激活时间过长,强制重置状态
if (isPalmEraserActive)
{
@@ -659,7 +659,7 @@ namespace Ink_Canvas
if (timeSinceActivation.TotalMilliseconds > PALM_ERASER_TIMEOUT_MS)
{
LogHelper.WriteLogToFile($"Palm eraser timeout detected ({timeSinceActivation.TotalMilliseconds}ms), forcing recovery", LogHelper.LogType.Warning);
// 强制恢复状态
try
{
@@ -684,20 +684,20 @@ namespace Ink_Canvas
LogHelper.WriteLogToFile($"Palm eraser timeout recovery failed: {ex.Message}, forcing to Ink mode", LogHelper.LogType.Error);
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
}
// 重置所有手掌擦状态
isPalmEraserActive = false;
palmEraserTouchDownHandled = false;
palmEraserTouchIds.Clear();
inkCanvas.IsHitTestVisible = true;
inkCanvas.IsManipulationEnabled = true;
ViewboxFloatingBar.IsHitTestVisible = true;
BlackboardUIGridForInkReplay.IsHitTestVisible = true;
// 停止恢复定时器
StopPalmEraserRecoveryTimer();
LogHelper.WriteLogToFile("Palm eraser timeout recovery completed");
}
}
@@ -760,7 +760,7 @@ namespace Ink_Canvas
{
inkCanvas.EditingMode = lastInkCanvasEditingMode;
}
// 修复:确保手掌擦除后触摸事件能正常响应
if (isPalmEraserActive)
{
@@ -770,7 +770,7 @@ namespace Ink_Canvas
palmEraserTouchIds.Clear(); // 确保清空触摸点ID
inkCanvas.IsHitTestVisible = true;
inkCanvas.IsManipulationEnabled = true;
ViewboxFloatingBar.IsHitTestVisible = true;
BlackboardUIGridForInkReplay.IsHitTestVisible = true;
}
@@ -799,7 +799,7 @@ namespace Ink_Canvas
{
if (e.Manipulators.Count() != 0) return;
// 修复:几何绘制模式下不自动切换到Ink模式,避免触摸轨迹被收集
if (drawingShapeMode == 0
if (drawingShapeMode == 0
&& inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint
&& inkCanvas.EditingMode != InkCanvasEditingMode.EraseByStroke)
{
@@ -924,7 +924,7 @@ namespace Ink_Canvas
inkCanvas.TouchDown -= MainWindow_TouchDown;
inkCanvas.TouchDown += Main_Grid_TouchDown;
// 修复:几何绘制模式下不自动切换到Ink模式,避免触摸轨迹被收集
if (inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint
if (inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint
&& inkCanvas.EditingMode != InkCanvasEditingMode.EraseByStroke
&& drawingShapeMode == 0)
{
@@ -958,7 +958,7 @@ namespace Ink_Canvas
inkCanvas.TouchDown -= Main_Grid_TouchDown;
// 修复:几何绘制模式下不自动切换到Ink模式,避免触摸轨迹被收集
if (inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint
&& inkCanvas.EditingMode != InkCanvasEditingMode.EraseByStroke
&& inkCanvas.EditingMode != InkCanvasEditingMode.EraseByStroke
&& drawingShapeMode == 0)
{
inkCanvas.EditingMode = InkCanvasEditingMode.None;
@@ -976,7 +976,7 @@ namespace Ink_Canvas
ToggleSwitchEnablePalmEraser.IsOn = false;
}
}
/// <summary>
/// 启动手掌擦恢复定时器,防止卡死状态
/// </summary>
@@ -988,10 +988,10 @@ namespace Ink_Canvas
palmEraserRecoveryTimer.Interval = TimeSpan.FromMilliseconds(1000); // 每秒检查一次
palmEraserRecoveryTimer.Tick += PalmEraserRecoveryTimer_Tick;
}
palmEraserRecoveryTimer.Start();
}
/// <summary>
/// 停止手掌擦恢复定时器
/// </summary>
@@ -1002,20 +1002,20 @@ namespace Ink_Canvas
palmEraserRecoveryTimer.Stop();
}
}
/// <summary>
/// 手掌擦恢复定时器事件处理
/// </summary>
private void PalmEraserRecoveryTimer_Tick(object sender, EventArgs e)
{
if (!isPalmEraserActive) return;
// 检查是否超时
var timeSinceActivation = DateTime.Now - palmEraserActivationTime;
if (timeSinceActivation.TotalMilliseconds > PALM_ERASER_TIMEOUT_MS)
{
LogHelper.WriteLogToFile($"Palm eraser recovery timer triggered, forcing recovery after {timeSinceActivation.TotalMilliseconds}ms", LogHelper.LogType.Warning);
// 强制恢复状态
try
{
@@ -1033,7 +1033,7 @@ namespace Ink_Canvas
inkCanvas.EditingMode = palmEraserLastEditingMode;
break;
}
LogHelper.WriteLogToFile($"Palm eraser timer recovery to mode: {palmEraserLastEditingMode}");
}
}
@@ -1042,20 +1042,20 @@ namespace Ink_Canvas
LogHelper.WriteLogToFile($"Palm eraser recovery timer failed: {ex.Message}, forcing to Ink mode", LogHelper.LogType.Error);
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
}
// 重置所有手掌擦状态
isPalmEraserActive = false;
palmEraserTouchDownHandled = false;
palmEraserTouchIds.Clear();
inkCanvas.IsHitTestVisible = true;
inkCanvas.IsManipulationEnabled = true;
ViewboxFloatingBar.IsHitTestVisible = true;
BlackboardUIGridForInkReplay.IsHitTestVisible = true;
// 停止定时器
StopPalmEraserRecoveryTimer();
LogHelper.WriteLogToFile("Palm eraser timer recovery completed");
}
}
+4 -4
View File
@@ -1,12 +1,12 @@
using System;
using Hardcodet.Wpf.TaskbarNotification;
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern.Controls;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Interop;
using Hardcodet.Wpf.TaskbarNotification;
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern.Controls;
using Application = System.Windows.Application;
using ContextMenu = System.Windows.Controls.ContextMenu;
using MenuItem = System.Windows.Controls.MenuItem;