diff --git a/Ink Canvas/App.xaml.cs b/Ink Canvas/App.xaml.cs index b662a247..da118e9f 100644 --- a/Ink Canvas/App.xaml.cs +++ b/Ink Canvas/App.xaml.cs @@ -1,3 +1,8 @@ +using Hardcodet.Wpf.TaskbarNotification; +using Ink_Canvas.Helpers; +using iNKORE.UI.WPF.Modern.Controls; +using Microsoft.Win32; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Diagnostics; @@ -13,11 +18,6 @@ using System.Windows; using System.Windows.Forms; using System.Windows.Input; using System.Windows.Threading; -using Hardcodet.Wpf.TaskbarNotification; -using Ink_Canvas.Helpers; -using iNKORE.UI.WPF.Modern.Controls; -using Microsoft.Win32; -using Newtonsoft.Json; using Application = System.Windows.Application; using MessageBox = System.Windows.MessageBox; using Timer = System.Threading.Timer; @@ -80,7 +80,7 @@ namespace Ink_Canvas args = Environment.GetCommandLineArgs(); bool isUpdateMode = args.Contains("--update-mode"); bool isFinalApp = args.Contains("--final-app"); - + if (CrashAction == CrashActionType.SilentRestart && !isUpdateMode && !isFinalApp) { StartWatchdogIfNeeded(); @@ -465,16 +465,16 @@ namespace Ink_Canvas { // 初始化应用启动时间 appStartTime = DateTime.Now; - + /*if (!StoreHelper.IsStoreApp) */ RootPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; LogHelper.NewLog(string.Format("Ink Canvas Starting (Version: {0})", Assembly.GetExecutingAssembly().GetName().Version)); - + // 检查是否为最终应用启动(更新后的应用) bool isFinalApp = e.Args.Contains("--final-app"); bool skipMutexCheck = e.Args.Contains("--skip-mutex-check"); - + // 记录最终应用启动状态 if (isFinalApp) { @@ -499,7 +499,7 @@ namespace Ink_Canvas // 处理更新模式启动 bool isUpdateMode = AutoUpdateHelper.HandleUpdateModeStartup(e.Args); - + // 如果是更新模式,不显示主窗口但保持应用运行 if (isUpdateMode) { @@ -510,10 +510,10 @@ namespace Ink_Canvas // 检查是否存在更新标记文件 string updateMarkerFile = Path.Combine(RootPath, "update_in_progress.tmp"); bool isUpdateInProgress = false; - + // 检查是否以更新模式启动 isUpdateMode = e.Args.Contains("--update-mode"); - + // 如果是最终应用启动,立即清理更新标记文件 if (isFinalApp) { @@ -530,7 +530,7 @@ namespace Ink_Canvas LogHelper.WriteLogToFile($"App | 清理更新标记文件失败: {ex.Message}", LogHelper.LogType.Warning); } } - + // 如果不是最终应用启动,才检查更新标记文件 if (!isFinalApp && File.Exists(updateMarkerFile)) { @@ -540,7 +540,7 @@ namespace Ink_Canvas if (int.TryParse(updateProcessIdStr, out int updateProcessId)) { LogHelper.WriteLogToFile($"App | 检测到更新标记文件,更新进程ID: {updateProcessId}"); - + // 检查更新进程是否还在运行 try { @@ -549,18 +549,18 @@ namespace Ink_Canvas { LogHelper.WriteLogToFile("App | 更新进程仍在运行,等待更新完成"); isUpdateInProgress = true; - + // 等待更新进程完成 int waitCount = 0; const int maxWaitCount = 10; // 减少等待时间到10秒 - + while (waitCount < maxWaitCount && !updateProcess.HasExited) { Thread.Sleep(500); // 减少等待间隔到500ms waitCount++; LogHelper.WriteLogToFile($"App | 等待更新进程完成... ({waitCount}/{maxWaitCount})"); } - + if (updateProcess.HasExited) { LogHelper.WriteLogToFile("App | 更新进程已结束"); @@ -592,7 +592,7 @@ namespace Ink_Canvas { LogHelper.WriteLogToFile("App | 更新进程已不存在"); } - + // 无论更新进程是否还在运行,都清理标记文件 try { @@ -668,11 +668,11 @@ namespace Ink_Canvas { LogHelper.WriteLogToFile("App | 更新过程中,跳过重复运行检测"); } - + // 在特殊模式下,创建一个临时的Mutex以避免其他检查出错 string mutexName = isFinalApp ? "InkCanvasForClass CE Final" : "InkCanvasForClass CE Update"; mutex = new Mutex(true, mutexName, out bool tempRet); - + // 额外等待一小段时间确保更新进程完全退出 Thread.Sleep(1000); LogHelper.WriteLogToFile("App | 特殊模式等待完成,继续启动"); @@ -681,7 +681,7 @@ namespace Ink_Canvas _taskbar = (TaskbarIcon)FindResource("TaskbarTrayIcon"); StartArgs = e.Args; - + // 在非更新模式下创建主窗口 var mainWindow = new MainWindow(); MainWindow = mainWindow; diff --git a/Ink Canvas/Helpers/AdvancedBezierSmoothing.cs b/Ink Canvas/Helpers/AdvancedBezierSmoothing.cs index 0948fa44..2c61c0cf 100644 --- a/Ink Canvas/Helpers/AdvancedBezierSmoothing.cs +++ b/Ink Canvas/Helpers/AdvancedBezierSmoothing.cs @@ -128,7 +128,7 @@ namespace Ink_Canvas.Helpers if (points.Length < 4) return points; var result = new List(); - + // 添加第一个点 result.Add(points[0]); @@ -142,9 +142,9 @@ namespace Ink_Canvas.Helpers // 计算改进的控制点 var controlPoints = CalculateImprovedControlPoints(p0, p1, p2, p3); - + // 限制插值步数,避免点数爆炸 - int steps = Math.Min(UseAdaptiveInterpolation ? + int steps = Math.Min(UseAdaptiveInterpolation ? CalculateAdaptiveSteps(p0, p1, p2, p3) : InterpolationSteps, 16); // 生成贝塞尔曲线点,但跳过第一个点避免重复 @@ -179,7 +179,7 @@ namespace Ink_Canvas.Helpers // 计算控制点距离(基于点间距离) double dist1 = Math.Sqrt((p1.X - p0.X) * (p1.X - p0.X) + (p1.Y - p0.Y) * (p1.Y - p0.Y)); double dist2 = Math.Sqrt((p3.X - p2.X) * (p3.X - p2.X) + (p3.Y - p2.Y) * (p3.Y - p2.Y)); - + double controlDist1 = dist1 * CurveTension; double controlDist2 = dist2 * CurveTension; @@ -214,7 +214,7 @@ namespace Ink_Canvas.Helpers // 基于长度和曲率计算步数 int baseSteps = Math.Max(8, Math.Min(20, (int)(totalLength / 10))); int curvatureSteps = (int)(curvature * 10); - + return Math.Max(InterpolationSteps, Math.Min(24, baseSteps + curvatureSteps)); } diff --git a/Ink Canvas/Helpers/AutoUpdateHelper.cs b/Ink Canvas/Helpers/AutoUpdateHelper.cs index 397a381b..d860f4b8 100644 --- a/Ink Canvas/Helpers/AutoUpdateHelper.cs +++ b/Ink Canvas/Helpers/AutoUpdateHelper.cs @@ -1,3 +1,5 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -15,8 +17,6 @@ using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; namespace Ink_Canvas.Helpers { @@ -1238,7 +1238,7 @@ namespace Ink_Canvas.Helpers // 查找解压后的主程序文件 string newAppPath = null; string[] possibleExeNames = { "InkCanvasForClass.exe", "Ink Canvas.exe", "InkCanvas.exe" }; - + foreach (string exeName in possibleExeNames) { string testPath = Path.Combine(extractPath, exeName); @@ -1260,12 +1260,12 @@ namespace Ink_Canvas.Helpers try { LogHelper.WriteLogToFile($"AutoUpdate | 准备启动新版本进程: {newAppPath}"); - + // 启动新版本进程(以更新模式) string arguments = $"--update-mode --old-process-id={currentProcessId} --extract-path=\"{extractPath}\" --target-path=\"{currentAppDir}\" --is-silence={isInSilence}"; - + LogHelper.WriteLogToFile($"AutoUpdate | 启动新进程的命令行: {newAppPath} {arguments}"); - + ProcessStartInfo startInfo = new ProcessStartInfo { FileName = newAppPath, @@ -1276,10 +1276,10 @@ namespace Ink_Canvas.Helpers Process.Start(startInfo); LogHelper.WriteLogToFile("AutoUpdate | 新版本进程启动命令已执行"); - + // 等待一小段时间确保新进程启动 Thread.Sleep(2000); - + // 关闭当前旧软件进程 LogHelper.WriteLogToFile("AutoUpdate | 关闭当前旧软件进程"); App.IsAppExitByUser = true; @@ -1312,7 +1312,7 @@ namespace Ink_Canvas.Helpers if (args.Contains("--update-mode")) { LogHelper.WriteLogToFile("AutoUpdate | 检测到更新模式启动"); - + // 解析命令行参数 int oldProcessId = -1; string extractPath = null; @@ -1326,7 +1326,7 @@ namespace Ink_Canvas.Helpers { string arg = args[i]; LogHelper.WriteLogToFile($"AutoUpdate | 处理参数 {i}: {arg}"); - + if (arg.StartsWith("--old-process-id=")) { string processIdStr = arg.Substring("--old-process-id=".Length); @@ -1365,7 +1365,7 @@ namespace Ink_Canvas.Helpers // 启动更新任务 Task.Run(async () => await PerformUpdate(oldProcessId, extractPath, targetPath, isSilence)); return true; // 返回true表示是更新模式 - } + } LogHelper.WriteLogToFile($"AutoUpdate | 参数验证失败 - 老进程ID: {oldProcessId}, 解压路径: {extractPath}, 目标路径: {targetPath}", LogHelper.LogType.Error); return false; @@ -1437,7 +1437,7 @@ namespace Ink_Canvas.Helpers // 复制文件到目标目录 LogHelper.WriteLogToFile($"AutoUpdate | 开始复制文件从 {extractPath} 到 {targetPath}"); - + try { // 使用递归复制方法,支持重试机制 @@ -1445,11 +1445,11 @@ namespace Ink_Canvas.Helpers if (copySuccess) { LogHelper.WriteLogToFile("AutoUpdate | 文件复制完成"); - } - else - { + } + else + { LogHelper.WriteLogToFile("AutoUpdate | 文件复制失败,部分文件可能无法覆盖", LogHelper.LogType.Error); - + if (!isSilence) { MessageBox.Show("更新失败:部分文件无法覆盖,可能是文件正在使用中。\n请关闭所有相关程序后重试。", "更新失败", MessageBoxButton.OK, MessageBoxImage.Error); @@ -1460,7 +1460,7 @@ namespace Ink_Canvas.Helpers catch (Exception ex) { LogHelper.WriteLogToFile($"AutoUpdate | 文件复制失败: {ex.Message}", LogHelper.LogType.Error); - + if (!isSilence) { MessageBox.Show($"更新失败:文件复制时出错\n{ex.Message}", "更新失败", MessageBoxButton.OK, MessageBoxImage.Error); @@ -1472,7 +1472,7 @@ namespace Ink_Canvas.Helpers try { LogHelper.WriteLogToFile("AutoUpdate | 清理临时文件"); - + // 删除解压目录 if (Directory.Exists(extractPath)) { @@ -1503,23 +1503,23 @@ namespace Ink_Canvas.Helpers LogHelper.WriteLogToFile("AutoUpdate | 更新操作完成"); - // 启动更新后的应用程序 + // 启动更新后的应用程序 string newAppPath = Path.Combine(targetPath, "InkCanvasForClass.exe"); if (File.Exists(newAppPath)) { try { LogHelper.WriteLogToFile($"AutoUpdate | 准备启动更新后的应用程序: {newAppPath}"); - + // 获取当前更新进程ID int currentUpdateProcessId = Process.GetCurrentProcess().Id; LogHelper.WriteLogToFile($"AutoUpdate | 当前更新进程ID: {currentUpdateProcessId}"); - + // 创建一个临时标记文件,用于新进程检测更新状态 string updateMarkerFile = Path.Combine(targetPath, "update_in_progress.tmp"); File.WriteAllText(updateMarkerFile, currentUpdateProcessId.ToString()); LogHelper.WriteLogToFile($"AutoUpdate | 创建更新标记文件: {updateMarkerFile}"); - + // 启动更新后的应用程序(标记为最终应用,不受相同进程影响) ProcessStartInfo startInfo = new ProcessStartInfo { @@ -1528,24 +1528,24 @@ namespace Ink_Canvas.Helpers WorkingDirectory = targetPath, UseShellExecute = false }; - + Process newProcess = Process.Start(startInfo); LogHelper.WriteLogToFile($"AutoUpdate | 最终应用程序启动成功,PID: {newProcess?.Id},已标记为最终应用"); - + // 等待一小段时间确保最终应用程序启动 Thread.Sleep(2000); - + // 结束当前更新进程 LogHelper.WriteLogToFile("AutoUpdate | 更新流程完成,结束更新进程"); - + // 强制结束当前更新进程 try { LogHelper.WriteLogToFile("AutoUpdate | 强制结束更新进程"); - + // 标记为应用主动退出,避免看门狗重启 App.IsAppExitByUser = true; - + // 写入退出信号文件,确保看门狗不会重启 try { @@ -1557,7 +1557,7 @@ namespace Ink_Canvas.Helpers { LogHelper.WriteLogToFile($"AutoUpdate | 写入看门狗退出信号文件失败: {ex.Message}", LogHelper.LogType.Warning); } - + Environment.Exit(0); } catch (Exception ex) @@ -1569,7 +1569,7 @@ namespace Ink_Canvas.Helpers catch (Exception ex) { LogHelper.WriteLogToFile($"AutoUpdate | 启动更新后的应用程序失败: {ex.Message}", LogHelper.LogType.Error); - + if (!isSilence) { MessageBox.Show($"更新完成,但启动应用程序失败:{ex.Message}\n请手动启动应用程序。", "启动失败", MessageBoxButton.OK, MessageBoxImage.Warning); @@ -1579,7 +1579,7 @@ namespace Ink_Canvas.Helpers else { LogHelper.WriteLogToFile($"AutoUpdate | 更新后的应用程序文件不存在: {newAppPath}", LogHelper.LogType.Error); - + if (!isSilence) { MessageBox.Show($"更新完成,但未找到应用程序文件:{newAppPath}\n请检查更新是否成功。", "文件缺失", MessageBoxButton.OK, MessageBoxImage.Error); @@ -1589,7 +1589,7 @@ namespace Ink_Canvas.Helpers catch (Exception ex) { LogHelper.WriteLogToFile($"AutoUpdate | 执行更新操作时出错: {ex.Message}", LogHelper.LogType.Error); - + if (!isSilence) { MessageBox.Show($"更新失败:{ex.Message}", "更新失败", MessageBoxButton.OK, MessageBoxImage.Error); @@ -1615,7 +1615,7 @@ namespace Ink_Canvas.Helpers { string targetFilePath = Path.Combine(destinationDir, file.Name); bool fileCopied = false; - + // 重试机制,最多重试3次 for (int retry = 0; retry < 3; retry++) { @@ -1638,7 +1638,7 @@ namespace Ink_Canvas.Helpers } } } - + await Task.Run(() => file.CopyTo(targetFilePath)); fileCopied = true; break; @@ -1646,14 +1646,14 @@ namespace Ink_Canvas.Helpers catch (Exception ex) { LogHelper.WriteLogToFile($"AutoUpdate | 复制文件失败 (重试 {retry + 1}/3) {file.FullName} -> {targetFilePath}: {ex.Message}", LogHelper.LogType.Warning); - + if (retry < 2) { Thread.Sleep(1000); // 等待1秒后重试 } } } - + if (!fileCopied) { allFilesCopied = false; @@ -1698,7 +1698,7 @@ namespace Ink_Canvas.Helpers { File.Delete(targetFilePath); } - + await Task.Run(() => file.CopyTo(targetFilePath)); } catch (Exception ex) @@ -1866,7 +1866,7 @@ namespace Ink_Canvas.Helpers } // 执行安装,静默模式 - InstallNewVersionApp(remoteVersion, true); + InstallNewVersionApp(remoteVersion, true); App.IsAppExitByUser = true; Application.Current.Dispatcher.Invoke(() => { @@ -1996,7 +1996,7 @@ namespace Ink_Canvas.Helpers return false; } LogHelper.WriteLogToFile($"AutoUpdate | 手动安装版本: {version}"); - InstallNewVersionApp(version, true); + InstallNewVersionApp(version, true); App.IsAppExitByUser = true; Application.Current.Dispatcher.Invoke(() => { diff --git a/Ink Canvas/Helpers/DeviceIdentifier.cs b/Ink Canvas/Helpers/DeviceIdentifier.cs index f67b5387..c079bc98 100644 --- a/Ink Canvas/Helpers/DeviceIdentifier.cs +++ b/Ink Canvas/Helpers/DeviceIdentifier.cs @@ -1,3 +1,4 @@ +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; @@ -5,7 +6,6 @@ using System.Linq; using System.Reflection; using System.Security.Cryptography; using System.Text; -using Newtonsoft.Json; namespace Ink_Canvas.Helpers { @@ -758,26 +758,26 @@ namespace Ink_Canvas.Helpers // 如果所有文件都不存在或损坏,返回新的统计对象 - var newStats = new UsageStats - { - DeviceId = DeviceId, - LastLaunchTime = DateTime.Now, - LaunchCount = 0, - TotalUsageSeconds = 0, - AverageSessionSeconds = 0, - LastUpdateCheck = DateTime.MinValue, - UpdatePriority = UpdatePriority.Medium, - UsageFrequency = UsageFrequency.Medium - }; + var newStats = new UsageStats + { + DeviceId = DeviceId, + LastLaunchTime = DateTime.Now, + LaunchCount = 0, + TotalUsageSeconds = 0, + AverageSessionSeconds = 0, + LastUpdateCheck = DateTime.MinValue, + UpdatePriority = UpdatePriority.Medium, + UsageFrequency = UsageFrequency.Medium + }; // 保存新统计到文件 SaveUsageStatsToFile(UsageStatsFilePath, newStats); - return newStats; + return newStats; } catch (Exception ex) { LogHelper.WriteLogToFile($"DeviceIdentifier | 加载使用统计失败: {ex.Message}", LogHelper.LogType.Error); - + // 返回默认统计对象 return new UsageStats { @@ -800,7 +800,7 @@ namespace Ink_Canvas.Helpers { // 保存到主文件 SaveUsageStatsToFile(UsageStatsFilePath, stats); - + // 保存到备份文件 SaveUsageStatsToFile(UsageStatsBackupPath, stats); } @@ -822,7 +822,7 @@ namespace Ink_Canvas.Helpers { return stats; } - + } } @@ -843,31 +843,31 @@ namespace Ink_Canvas.Helpers if (File.Exists(filePath)) { byte[] encryptedData = File.ReadAllBytes(filePath); - + if (encryptedData.Length < 32) // SHA256校验和长度为32字节 { LogHelper.WriteLogToFile($"DeviceIdentifier | 加密文件格式错误: {filePath}", LogHelper.LogType.Error); return null; } - + // 提取校验和和加密数据 byte[] checksum = new byte[32]; byte[] data = new byte[encryptedData.Length - 32]; Array.Copy(encryptedData, 0, checksum, 0, 32); Array.Copy(encryptedData, 32, data, 0, data.Length); - + // 使用SHA256生成解密密钥 using (var sha256 = SHA256.Create()) { byte[] keyBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(DeviceId + "ICC_Usage_Stats_Salt")); - + // XOR解密 byte[] decryptedData = new byte[data.Length]; for (int i = 0; i < data.Length; i++) { decryptedData[i] = (byte)(data[i] ^ keyBytes[i % keyBytes.Length]); } - + // 验证校验和 byte[] computedChecksum = sha256.ComputeHash(decryptedData); if (!checksum.SequenceEqual(computedChecksum)) @@ -875,7 +875,7 @@ namespace Ink_Canvas.Helpers LogHelper.WriteLogToFile($"DeviceIdentifier | 加密文件校验和验证失败: {filePath}", LogHelper.LogType.Error); return null; } - + string json = Encoding.UTF8.GetString(decryptedData); var stats = JsonConvert.DeserializeObject(json); if (stats != null && !string.IsNullOrEmpty(stats.DeviceId)) @@ -909,27 +909,27 @@ namespace Ink_Canvas.Helpers string json = JsonConvert.SerializeObject(stats, Formatting.Indented); byte[] data = Encoding.UTF8.GetBytes(json); - + // 使用SHA256生成加密密钥(基于设备ID) using (var sha256 = SHA256.Create()) { byte[] keyBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(DeviceId + "ICC_Usage_Stats_Salt")); - + // 简单的XOR加密 byte[] encryptedData = new byte[data.Length]; for (int i = 0; i < data.Length; i++) { encryptedData[i] = (byte)(data[i] ^ keyBytes[i % keyBytes.Length]); } - + // 添加SHA256校验和 byte[] checksum = sha256.ComputeHash(data); byte[] finalData = new byte[checksum.Length + encryptedData.Length]; checksum.CopyTo(finalData, 0); encryptedData.CopyTo(finalData, checksum.Length); - + File.WriteAllBytes(filePath, finalData); - + LogHelper.WriteLogToFile($"DeviceIdentifier | 加密使用统计已保存到: {filePath}"); } } @@ -958,7 +958,7 @@ namespace Ink_Canvas.Helpers LogHelper.WriteLogToFile($"DeviceIdentifier | 记录更新检查失败: {ex.Message}", LogHelper.LogType.Error); } } - + /// /// 从备份文件恢复使用统计数据 @@ -997,7 +997,7 @@ namespace Ink_Canvas.Helpers try { var status = new List(); - + // 检查主文件 if (File.Exists(UsageStatsFilePath)) { @@ -1339,7 +1339,7 @@ namespace Ink_Canvas.Helpers return descriptions.Count > 0 ? string.Join(", ", descriptions) : "普通用户"; } - + /// /// 关机时保存使用时间数据 /// @@ -1360,7 +1360,7 @@ namespace Ink_Canvas.Helpers // 2. 计算本次会话时长(防止异常值) TimeSpan sessionDuration = DateTime.Now - App.appStartTime; long sessionSeconds = Math.Max(0, (long)sessionDuration.TotalSeconds); - + // 防止异常大的会话时长(超过24小时) if (sessionSeconds > 86400) { @@ -1373,10 +1373,10 @@ namespace Ink_Canvas.Helpers stats.LaunchCount++; stats.AverageSessionSeconds = stats.TotalUsageSeconds / (double)Math.Max(1, stats.LaunchCount); stats.LastLaunchTime = DateTime.Now; - + // 4. 保存数据 SaveUsageStats(stats); - + LogHelper.WriteLogToFile("DeviceIdentifier | 关机保存完成"); } catch (Exception ex) diff --git a/Ink Canvas/Helpers/GlobalHotkeyManager.cs b/Ink Canvas/Helpers/GlobalHotkeyManager.cs index b1f1eefe..b5ba3f40 100644 --- a/Ink Canvas/Helpers/GlobalHotkeyManager.cs +++ b/Ink Canvas/Helpers/GlobalHotkeyManager.cs @@ -1,11 +1,11 @@ +using Newtonsoft.Json; +using NHotkey.Wpf; using System; using System.Collections.Generic; using System.IO; using System.Reflection; using System.Text; using System.Windows.Input; -using Newtonsoft.Json; -using NHotkey.Wpf; namespace Ink_Canvas.Helpers { @@ -19,7 +19,7 @@ namespace Ink_Canvas.Helpers private readonly MainWindow _mainWindow; private bool _isDisposed; private bool _hotkeysShouldBeRegistered = true; // 启动时注册热键 - + // 配置文件路径 private static readonly string HotkeyConfigFile = Path.Combine(App.RootPath, "HotkeyConfig.json"); #endregion @@ -227,7 +227,7 @@ namespace Ink_Canvas.Helpers try { // 开始注册默认快捷键集合 - + // 基本操作快捷键 RegisterHotkey("Undo", Key.Z, ModifierKeys.Control, () => _mainWindow.SymbolIconUndo_MouseUp(null, null)); RegisterHotkey("Redo", Key.Y, ModifierKeys.Control, () => _mainWindow.SymbolIconRedo_MouseUp(null, null)); @@ -272,14 +272,14 @@ namespace Ink_Canvas.Helpers try { // 开始从配置文件加载快捷键设置 - + // 检查是否应该注册快捷键 if (!_hotkeysShouldBeRegistered) { // 当前状态不允许注册快捷键,跳过加载 return; } - + // 尝试从配置文件加载 if (LoadHotkeysFromConfigFile()) { @@ -319,7 +319,7 @@ namespace Ink_Canvas.Helpers try { LogHelper.WriteLogToFile("开始保存快捷键配置到配置文件", LogHelper.LogType.Event); - + if (SaveHotkeysToConfigFile()) { LogHelper.WriteLogToFile("快捷键配置已成功保存到配置文件", LogHelper.LogType.Event); @@ -347,7 +347,7 @@ namespace Ink_Canvas.Helpers { _hotkeysShouldBeRegistered = true; LogHelper.WriteLogToFile("启用快捷键注册功能"); - + // 立即加载快捷键设置 LoadHotkeysFromSettings(); } @@ -376,7 +376,7 @@ namespace Ink_Canvas.Helpers { _hotkeysShouldBeRegistered = false; LogHelper.WriteLogToFile("禁用快捷键注册功能"); - + // 注销所有快捷键 UnregisterAllHotkeys(); } @@ -438,20 +438,20 @@ namespace Ink_Canvas.Helpers // 获取原有的动作 var originalAction = _registeredHotkeys[hotkeyName].Action; - + // 注销原有快捷键 UnregisterHotkey(hotkeyName); - + // 注册新的快捷键 var success = RegisterHotkey(hotkeyName, key, modifiers, originalAction); - + if (success) { LogHelper.WriteLogToFile($"成功更新快捷键 {hotkeyName}: {modifiers}+{key}", LogHelper.LogType.Event); // 自动保存配置 SaveHotkeysToSettings(); } - + return success; } catch (Exception ex) @@ -472,17 +472,17 @@ namespace Ink_Canvas.Helpers try { // 通过反射访问主窗口的penType字段 - var penTypeField = _mainWindow.GetType().GetField("penType", + var penTypeField = _mainWindow.GetType().GetField("penType", BindingFlags.NonPublic | BindingFlags.Instance); - + if (penTypeField != null) { penTypeField.SetValue(_mainWindow, penTypeIndex); - + // 调用CheckPenTypeUIState方法更新UI状态 - var checkPenTypeMethod = _mainWindow.GetType().GetMethod("CheckPenTypeUIState", + var checkPenTypeMethod = _mainWindow.GetType().GetMethod("CheckPenTypeUIState", BindingFlags.NonPublic | BindingFlags.Instance); - + if (checkPenTypeMethod != null) { checkPenTypeMethod.Invoke(_mainWindow, null); @@ -604,7 +604,7 @@ namespace Ink_Canvas.Helpers { Formatting = Formatting.Indented }; - + string jsonContent = JsonConvert.SerializeObject(config, settings); // 直接写入原文件,覆盖原有内容 @@ -688,9 +688,9 @@ namespace Ink_Canvas.Helpers try { // 通过反射访问主窗口的FloatingbarSelectionBG字段 - var floatingbarSelectionBGField = _mainWindow.GetType().GetField("FloatingbarSelectionBG", + var floatingbarSelectionBGField = _mainWindow.GetType().GetField("FloatingbarSelectionBG", BindingFlags.NonPublic | BindingFlags.Instance); - + if (floatingbarSelectionBGField != null) { var floatingbarSelectionBG = floatingbarSelectionBGField.GetValue(_mainWindow); @@ -707,7 +707,7 @@ namespace Ink_Canvas.Helpers return true; // 返回true表示应该注销快捷键 } } - + // 通过反射访问Canvas.GetLeft方法来获取高光位置 var canvasType = Type.GetType("System.Windows.Controls.Canvas, PresentationFramework"); if (canvasType != null) @@ -719,7 +719,7 @@ namespace Ink_Canvas.Helpers if (leftPosition != null) { var position = Convert.ToDouble(leftPosition); - + // 根据高光位置判断当前选中的工具 // 位置计算基于SetFloatingBarHighlightPosition方法中的逻辑 bool isMouseMode; @@ -739,20 +739,20 @@ namespace Ink_Canvas.Helpers { isMouseMode = false; } - + return isMouseMode; } } } } } - + // 如果无法获取高光状态,则回退到inkCanvas.EditingMode判断 - + // 通过反射访问主窗口的inkCanvas字段 - var inkCanvasField = _mainWindow.GetType().GetField("inkCanvas", + var inkCanvasField = _mainWindow.GetType().GetField("inkCanvas", BindingFlags.NonPublic | BindingFlags.Instance); - + if (inkCanvasField != null) { var inkCanvas = inkCanvasField.GetValue(_mainWindow); @@ -768,23 +768,23 @@ namespace Ink_Canvas.Helpers // 检查是否为批注模式 var isInkMode = editingMode.ToString().Contains("Ink"); var isSelectMode = editingMode.ToString().Contains("Select"); - + // 如果是批注模式或选择模式,则应该注册快捷键(返回false) // 如果是橡皮擦模式或其他模式,则不应该注册快捷键(返回true) var shouldNotRegisterHotkeys = !isInkMode && !isSelectMode; - + return shouldNotRegisterHotkeys; } } } } - + // 如果无法获取任何状态信息,则回退到原来的判断逻辑 - + // 通过反射访问主窗口的currentMode字段(作为最后的备用方案) - var currentModeField = _mainWindow.GetType().GetField("currentMode", + var currentModeField = _mainWindow.GetType().GetField("currentMode", BindingFlags.NonPublic | BindingFlags.Instance); - + if (currentModeField != null) { var currentMode = currentModeField.GetValue(_mainWindow); @@ -798,7 +798,7 @@ namespace Ink_Canvas.Helpers return isSelectMode; } } - + return false; // 默认允许快捷键 } catch (Exception ex) @@ -816,7 +816,7 @@ namespace Ink_Canvas.Helpers { if (!_isDisposed) { - + _isDisposed = true; } } @@ -861,4 +861,4 @@ namespace Ink_Canvas.Helpers } #endregion } -} +} diff --git a/Ink Canvas/Helpers/ImprovedBezierSmoothing.cs b/Ink Canvas/Helpers/ImprovedBezierSmoothing.cs index f249885d..0e4143d3 100644 --- a/Ink Canvas/Helpers/ImprovedBezierSmoothing.cs +++ b/Ink Canvas/Helpers/ImprovedBezierSmoothing.cs @@ -28,13 +28,13 @@ namespace Ink_Canvas.Helpers return originalStroke; var originalPoints = originalStroke.StylusPoints.ToArray(); - + // 预处理:去除噪声点 var cleanedPoints = RemoveNoisePoints(originalPoints); - + // 使用改进的贝塞尔曲线拟合 var smoothedPoints = ApplyCubicBezierSmoothing(cleanedPoints); - + // 后处理:重采样和优化 var finalPoints = PostProcessPoints(smoothedPoints); @@ -61,7 +61,7 @@ namespace Ink_Canvas.Helpers var next = points[i + 1]; // 计算到前一个点的距离 - double distToPrev = Math.Sqrt((curr.X - prev.X) * (curr.X - prev.X) + + double distToPrev = Math.Sqrt((curr.X - prev.X) * (curr.X - prev.X) + (curr.Y - prev.Y) * (curr.Y - prev.Y)); // 如果距离太近,跳过这个点 @@ -148,7 +148,7 @@ namespace Ink_Canvas.Helpers // 计算控制点距离 double dist1 = CalculateDistance(p0, p1); double dist2 = CalculateDistance(p2, p3); - + double controlDist1 = dist1 * _config.CurveTension; double controlDist2 = dist2 * _config.CurveTension; @@ -322,4 +322,4 @@ namespace Ink_Canvas.Helpers return result.ToArray(); } } -} \ No newline at end of file +} \ No newline at end of file diff --git a/Ink Canvas/Helpers/InkFadeManager.cs b/Ink Canvas/Helpers/InkFadeManager.cs index 6f8188f8..4490b721 100644 --- a/Ink Canvas/Helpers/InkFadeManager.cs +++ b/Ink Canvas/Helpers/InkFadeManager.cs @@ -63,7 +63,7 @@ namespace Ink_Canvas.Helpers /// 抬笔点 public void AddFadingStroke(Stroke stroke, Point startPoint, Point endPoint) { - if (!IsEnabled || stroke == null) + if (!IsEnabled || stroke == null) { return; } @@ -238,12 +238,12 @@ namespace Ink_Canvas.Helpers public void UpdateFadeTime(int fadeTime) { FadeTime = fadeTime; - + foreach (var kvp in _fadeTimers) { var stroke = kvp.Key; var timer = kvp.Value; - + timer.Stop(); timer.Interval = TimeSpan.FromMilliseconds(FadeTime); timer.Start(); @@ -283,14 +283,14 @@ namespace Ink_Canvas.Helpers { // 创建路径几何,使用墨迹的实际位置 var geometry = stroke.GetGeometry(); - if (geometry == null) + if (geometry == null) { return null; } // 获取绘画属性 var drawingAttribs = stroke.DrawingAttributes; - + // 创建路径元素,确保使用正确的绘画属性 var path = new Path { @@ -302,7 +302,7 @@ namespace Ink_Canvas.Helpers StrokeLineJoin = PenLineJoin.Round, Fill = drawingAttribs.IsHighlighter ? new SolidColorBrush(drawingAttribs.Color) : null, // 高亮笔需要填充 Opacity = 0.95, // 初始透明度更高,显得更自然 - + // 优化渲染质量 UseLayoutRounding = false, SnapsToDevicePixels = false @@ -312,19 +312,19 @@ namespace Ink_Canvas.Helpers if (drawingAttribs.IsHighlighter) { path.Opacity = 0.4; // 高亮笔初始透明度更低,更符合荧光笔特性 - + // 为高亮笔添加特殊的混合效果 // 使用更柔和的笔触样式 path.StrokeStartLineCap = PenLineCap.Flat; path.StrokeEndLineCap = PenLineCap.Flat; path.StrokeLineJoin = PenLineJoin.Miter; - - // 高亮笔通常需要更宽的笔触来覆盖下面的内容 - if (drawingAttribs.Width < 20) - { - path.StrokeThickness = Math.Max(drawingAttribs.Width * 1.5, 20); - } - } + + // 高亮笔通常需要更宽的笔触来覆盖下面的内容 + if (drawingAttribs.Width < 20) + { + path.StrokeThickness = Math.Max(drawingAttribs.Width * 1.5, 20); + } + } // 不设置任何变换,保持墨迹原有粗细 var bounds = geometry.Bounds; @@ -356,7 +356,7 @@ namespace Ink_Canvas.Helpers // 获取当前透明度和判断是否为高亮笔 var currentOpacity = visual.Opacity; var isHighlighter = stroke.DrawingAttributes.IsHighlighter; - + // 根据墨迹类型选择不同的动画效果 if (isHighlighter) { @@ -439,19 +439,19 @@ namespace Ink_Canvas.Helpers { var stylusPoints = stroke.StylusPoints; var totalPoints = stylusPoints.Count; - + // 分段算法 - 确保所有墨迹都有足够的动画效果 var strokeLength = CalculateStrokeLength(stylusPoints); var segmentCount = CalculateOptimalSegmentCount(totalPoints, strokeLength); - + // 强制最小分段数量,确保短墨迹也有动画效果 segmentCount = Math.Max(segmentCount, 4); - + var pointsPerSegment = Math.Max(1, totalPoints / segmentCount); // 隐藏原始视觉元素 originalVisual.Visibility = Visibility.Hidden; - + var segments = new List(); var parent = _mainWindow.inkCanvas?.Parent as Panel; if (parent == null) @@ -465,7 +465,7 @@ namespace Ink_Canvas.Helpers { var startIndex = i * pointsPerSegment; var endIndex = (i == segmentCount - 1) ? totalPoints - 1 : (i + 1) * pointsPerSegment; - + // 确保有足够的点来创建分段,对于短墨迹特殊处理 if (endIndex <= startIndex && totalPoints > 1) { @@ -473,12 +473,12 @@ namespace Ink_Canvas.Helpers startIndex = i; endIndex = Math.Min(i + 1, totalPoints - 1); } - + // 为每个分段添加重叠,确保连接处平滑 var overlap = Math.Max(1, pointsPerSegment / 6); // 15%的重叠,平衡平滑与速度 var actualStartIndex = Math.Max(0, startIndex - overlap); var actualEndIndex = Math.Min(totalPoints - 1, endIndex + overlap); - + var segment = CreateStrokeSegment(stroke, actualStartIndex, actualEndIndex, opacity); if (segment != null) { @@ -576,10 +576,10 @@ namespace Ink_Canvas.Helpers for (int i = 0; i < segments.Count; i++) { var segment = segments[i]; - + // 使用预计算的动画曲线获取延迟时间 var delay = animationCurve[i]; - + // 使用定时器延迟启动每个分段的动画 var timer = new DispatcherTimer { @@ -595,7 +595,7 @@ namespace Ink_Canvas.Helpers lock (completedSegments) { completedSegments.Add(segment); - + // 检查是否所有分段都完成了 if (completedSegments.Count >= totalSegments) { @@ -676,7 +676,7 @@ namespace Ink_Canvas.Helpers { // 移除所有分段 var parent = _mainWindow.inkCanvas?.Parent as Panel; - + foreach (var segment in segments) { if (parent != null && parent.Children.Contains(segment)) @@ -729,7 +729,7 @@ namespace Ink_Canvas.Helpers private double CalculateStrokeLength(StylusPointCollection points) { if (points.Count < 2) return 0; - + double totalLength = 0; for (int i = 1; i < points.Count; i++) { @@ -749,22 +749,22 @@ namespace Ink_Canvas.Helpers const double PIXELS_PER_SEGMENT = 12.0; // 每段适中长度,平衡效果与速度 const int MIN_SEGMENTS = 5; // 适当的最小分段数,确保动画效果 const int MAX_SEGMENTS = 100; // 适中的最大分段数,平衡性能与效果 - + // 根据长度计算基础分段数 var lengthBasedSegments = Math.Max(MIN_SEGMENTS, (int)(strokeLength / PIXELS_PER_SEGMENT)); - + // 根据点密度调整,平衡效果与速度 var density = pointCount > 0 ? strokeLength / pointCount : 1; var densityFactor = Math.Max(0.4, Math.Min(2.5, density / 1.8)); - + var finalSegments = (int)(lengthBasedSegments * densityFactor); - + // 对于短墨迹,确保至少有4个分段 if (pointCount <= 5) { finalSegments = Math.Max(finalSegments, 4); } - + // 限制在合理范围内 return Math.Min(MAX_SEGMENTS, Math.Max(MIN_SEGMENTS, finalSegments)); } @@ -778,7 +778,7 @@ namespace Ink_Canvas.Helpers var baseDuration = totalDuration / Math.Max(segmentCount, 1); var minDuration = 150; // 每段最少150ms,确保动画完整显示 var maxDuration = 500; // 每段最多500ms,平衡速度与完整性 - + return Math.Max(minDuration, Math.Min(maxDuration, baseDuration)); } @@ -788,17 +788,17 @@ namespace Ink_Canvas.Helpers private int[] CreateAppleStyleAnimationCurve(int segmentCount, int totalDuration) { var curve = new int[segmentCount]; - + // 平衡速度与完整性,确保动画有足够时间播放 var availableTime = totalDuration * 0.6; // 使用60%的总时间,给动画留足够缓冲 var delayBetweenSegments = Math.Max(60, availableTime / Math.Max(segmentCount, 1)); - + for (int i = 0; i < segmentCount; i++) { // 线性延迟,确保每个分段都有足够时间 curve[i] = (int)(i * delayBetweenSegments); } - + return curve; } @@ -829,4 +829,4 @@ namespace Ink_Canvas.Helpers } #endregion } -} \ No newline at end of file +} \ No newline at end of file diff --git a/Ink Canvas/Helpers/InkSmoothingConfig.cs b/Ink Canvas/Helpers/InkSmoothingConfig.cs index 83533f0e..dea1df70 100644 --- a/Ink Canvas/Helpers/InkSmoothingConfig.cs +++ b/Ink Canvas/Helpers/InkSmoothingConfig.cs @@ -12,22 +12,22 @@ namespace Ink_Canvas.Helpers public double SmoothingStrength { get; set; } = 0.4; public double ResampleInterval { get; set; } = 2.5; public int InterpolationSteps { get; set; } = 12; - + // 贝塞尔曲线参数 public bool UseAdaptiveInterpolation { get; set; } = true; public double CurveTension { get; set; } = 0.3; public double MinCurvatureThreshold { get; set; } = 0.1; public double MaxCurvatureThreshold { get; set; } = 0.8; - + // 性能参数 public bool UseHardwareAcceleration { get; set; } = true; public bool UseAsyncProcessing { get; set; } = true; public int MaxConcurrentTasks { get; set; } = Environment.ProcessorCount; public int MaxPointsPerStroke { get; set; } = 10000; - + // 质量设置 public SmoothingQuality Quality { get; set; } = SmoothingQuality.Balanced; - + public enum SmoothingQuality { Performance, // 性能优先 @@ -49,7 +49,7 @@ namespace Ink_Canvas.Helpers public static InkSmoothingConfig FromSettings() { var config = new InkSmoothingConfig(); - + try { // 尝试从MainWindow.Settings加载配置(兼容性) @@ -66,7 +66,7 @@ namespace Ink_Canvas.Helpers { Debug.WriteLine($"加载平滑配置失败: {ex.Message}"); } - + return config; } @@ -85,7 +85,7 @@ namespace Ink_Canvas.Helpers CurveTension = 0.2; MaxConcurrentTasks = Math.Max(1, Environment.ProcessorCount / 2); break; - + case SmoothingQuality.Balanced: SmoothingStrength = 0.4; ResampleInterval = 2.5; @@ -94,7 +94,7 @@ namespace Ink_Canvas.Helpers CurveTension = 0.3; MaxConcurrentTasks = Environment.ProcessorCount; break; - + case SmoothingQuality.Quality: SmoothingStrength = 0.6; ResampleInterval = 1.5; @@ -120,7 +120,7 @@ namespace Ink_Canvas.Helpers MainWindow.Settings.Canvas.UseHardwareAcceleration = UseHardwareAcceleration; MainWindow.Settings.Canvas.UseAsyncInkSmoothing = UseAsyncProcessing; MainWindow.Settings.Canvas.MaxConcurrentSmoothingTasks = MaxConcurrentTasks; - + } } catch (Exception ex) @@ -152,4 +152,4 @@ namespace Ink_Canvas.Helpers $"张力: {CurveTension:F2}, 硬件加速: {UseHardwareAcceleration}"; } } -} \ No newline at end of file +} \ No newline at end of file diff --git a/Ink Canvas/Helpers/PPTInkManager.cs b/Ink Canvas/Helpers/PPTInkManager.cs index fd43b18f..436f5d71 100644 --- a/Ink Canvas/Helpers/PPTInkManager.cs +++ b/Ink Canvas/Helpers/PPTInkManager.cs @@ -1,9 +1,9 @@ -using System; +using Microsoft.Office.Interop.PowerPoint; +using System; using System.IO; using System.Security.Cryptography; using System.Text; using System.Windows.Ink; -using Microsoft.Office.Interop.PowerPoint; namespace Ink_Canvas.Helpers { @@ -57,11 +57,11 @@ namespace Ink_Canvas.Helpers { // 完全清理之前的墨迹状态 ClearAllStrokes(); - + // 重置墨迹锁定状态 _inkLockUntil = DateTime.MinValue; _lockedSlideIndex = -1; - + // 生成演示文稿唯一标识符 _currentPresentationId = GeneratePresentationId(presentation); @@ -164,7 +164,7 @@ namespace Ink_Canvas.Helpers { // 确定要保存的页面索引 int saveToSlideIndex = _lockedSlideIndex > 0 ? _lockedSlideIndex : slideIndex; - + // 确保页面索引有效 if (saveToSlideIndex > 0 && saveToSlideIndex < _memoryStreams.Length) { @@ -179,7 +179,7 @@ namespace Ink_Canvas.Helpers // 加载新页面的墨迹 var newStrokes = LoadSlideStrokes(slideIndex); LogHelper.WriteLogToFile($"已切换到第{slideIndex}页,加载墨迹数量: {newStrokes.Count}", LogHelper.LogType.Trace); - + return newStrokes; } catch (Exception ex) diff --git a/Ink Canvas/Helpers/PPTManager.cs b/Ink Canvas/Helpers/PPTManager.cs index fb57c16f..d8a03bd4 100644 --- a/Ink Canvas/Helpers/PPTManager.cs +++ b/Ink Canvas/Helpers/PPTManager.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.Office.Interop.PowerPoint; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; @@ -7,7 +8,6 @@ using System.Text; using System.Threading; using System.Timers; using System.Windows.Threading; -using Microsoft.Office.Interop.PowerPoint; using Application = System.Windows.Application; using Timer = System.Timers.Timer; @@ -219,7 +219,7 @@ namespace Ink_Canvas.Helpers { _lastSlideShowState = currentSlideShowState; SlideShowStateChanged?.Invoke(currentSlideShowState); - + if (!currentSlideShowState) { LogHelper.WriteLogToFile("检测到PPT放映已结束", LogHelper.LogType.Trace); diff --git a/Ink Canvas/Helpers/PPTUIManager.cs b/Ink Canvas/Helpers/PPTUIManager.cs index 5bf4b636..b022a29b 100644 --- a/Ink Canvas/Helpers/PPTUIManager.cs +++ b/Ink Canvas/Helpers/PPTUIManager.cs @@ -157,7 +157,7 @@ namespace Ink_Canvas.Helpers { // 检查是否应该显示PPT按钮 // 不仅要检查按钮设置,还要确保确实在PPT放映模式下 - bool shouldShowButtons = ShowPPTButton && + bool shouldShowButtons = ShowPPTButton && _mainWindow.BtnPPTSlideShowEnd.Visibility == Visibility.Visible && _mainWindow.PPTManager?.IsInSlideShow == true; diff --git a/Ink Canvas/Helpers/Plugins/BuiltIn/SuperLauncher/LauncherButton.cs b/Ink Canvas/Helpers/Plugins/BuiltIn/SuperLauncher/LauncherButton.cs index 1e91a7de..54eb84bd 100644 --- a/Ink Canvas/Helpers/Plugins/BuiltIn/SuperLauncher/LauncherButton.cs +++ b/Ink Canvas/Helpers/Plugins/BuiltIn/SuperLauncher/LauncherButton.cs @@ -1,9 +1,9 @@ +using iNKORE.UI.WPF.Modern.Controls; using System; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; -using iNKORE.UI.WPF.Modern.Controls; namespace Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher { diff --git a/Ink Canvas/Helpers/Plugins/BuiltIn/SuperLauncher/LauncherModels.cs b/Ink Canvas/Helpers/Plugins/BuiltIn/SuperLauncher/LauncherModels.cs index 2089ca6c..9b6ac63b 100644 --- a/Ink Canvas/Helpers/Plugins/BuiltIn/SuperLauncher/LauncherModels.cs +++ b/Ink Canvas/Helpers/Plugins/BuiltIn/SuperLauncher/LauncherModels.cs @@ -1,3 +1,5 @@ +using Microsoft.Win32; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Diagnostics; @@ -8,8 +10,6 @@ using System.Windows; using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Imaging; -using Microsoft.Win32; -using Newtonsoft.Json; namespace Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher { diff --git a/Ink Canvas/Helpers/Plugins/BuiltIn/SuperLauncher/LauncherSettingsControl.xaml.cs b/Ink Canvas/Helpers/Plugins/BuiltIn/SuperLauncher/LauncherSettingsControl.xaml.cs index 4b6cda6c..6666f10d 100644 --- a/Ink Canvas/Helpers/Plugins/BuiltIn/SuperLauncher/LauncherSettingsControl.xaml.cs +++ b/Ink Canvas/Helpers/Plugins/BuiltIn/SuperLauncher/LauncherSettingsControl.xaml.cs @@ -1,10 +1,10 @@ +using Ink_Canvas.Windows; +using Microsoft.Win32; using System; using System.ComponentModel; using System.IO; using System.Windows; using System.Windows.Controls; -using Ink_Canvas.Windows; -using Microsoft.Win32; namespace Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher { diff --git a/Ink Canvas/Helpers/Plugins/BuiltIn/SuperLauncherPlugin.cs b/Ink Canvas/Helpers/Plugins/BuiltIn/SuperLauncherPlugin.cs index 2c504bd0..555c7bf9 100644 --- a/Ink Canvas/Helpers/Plugins/BuiltIn/SuperLauncherPlugin.cs +++ b/Ink Canvas/Helpers/Plugins/BuiltIn/SuperLauncherPlugin.cs @@ -1,3 +1,5 @@ +using Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -5,8 +7,6 @@ using System.IO; using System.Windows; using System.Windows.Controls; using System.Windows.Media; -using Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher; -using Newtonsoft.Json; namespace Ink_Canvas.Helpers.Plugins.BuiltIn { diff --git a/Ink Canvas/Helpers/Plugins/EnhancedPluginBase.cs b/Ink Canvas/Helpers/Plugins/EnhancedPluginBase.cs index 3b62137f..d22ca80e 100644 --- a/Ink Canvas/Helpers/Plugins/EnhancedPluginBase.cs +++ b/Ink Canvas/Helpers/Plugins/EnhancedPluginBase.cs @@ -89,4 +89,4 @@ namespace Ink_Canvas.Helpers.Plugins base.Cleanup(); } } -} \ No newline at end of file +} \ No newline at end of file diff --git a/Ink Canvas/Helpers/Plugins/IEnhancedPlugin.cs b/Ink Canvas/Helpers/Plugins/IEnhancedPlugin.cs index 6ee5e9d5..312eb10c 100644 --- a/Ink Canvas/Helpers/Plugins/IEnhancedPlugin.cs +++ b/Ink Canvas/Helpers/Plugins/IEnhancedPlugin.cs @@ -45,4 +45,4 @@ namespace Ink_Canvas.Helpers.Plugins /// void OnConfigurationChanged(); } -} \ No newline at end of file +} \ No newline at end of file diff --git a/Ink Canvas/Helpers/Plugins/IPluginService.cs b/Ink Canvas/Helpers/Plugins/IPluginService.cs index 2df665f5..ff24ec2b 100644 --- a/Ink Canvas/Helpers/Plugins/IPluginService.cs +++ b/Ink Canvas/Helpers/Plugins/IPluginService.cs @@ -554,4 +554,4 @@ namespace Ink_Canvas.Helpers.Plugins /// Error } -} \ No newline at end of file +} \ No newline at end of file diff --git a/Ink Canvas/Helpers/Plugins/PluginConfigurationManager.cs b/Ink Canvas/Helpers/Plugins/PluginConfigurationManager.cs index be1efddc..9688cd31 100644 --- a/Ink Canvas/Helpers/Plugins/PluginConfigurationManager.cs +++ b/Ink Canvas/Helpers/Plugins/PluginConfigurationManager.cs @@ -1,8 +1,8 @@ +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; -using Newtonsoft.Json; namespace Ink_Canvas.Helpers.Plugins { @@ -270,4 +270,4 @@ namespace Ink_Canvas.Helpers.Plugins } } } -} \ No newline at end of file +} \ No newline at end of file diff --git a/Ink Canvas/Helpers/Plugins/PluginManager.cs b/Ink Canvas/Helpers/Plugins/PluginManager.cs index d1a6559f..27b7742e 100644 --- a/Ink Canvas/Helpers/Plugins/PluginManager.cs +++ b/Ink Canvas/Helpers/Plugins/PluginManager.cs @@ -1,3 +1,5 @@ +using Ink_Canvas.Windows; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -8,8 +10,6 @@ using System.Security.Cryptography; using System.Threading; using System.Threading.Tasks; using System.Windows; -using Ink_Canvas.Windows; -using Newtonsoft.Json; using Timer = System.Timers.Timer; namespace Ink_Canvas.Helpers.Plugins diff --git a/Ink Canvas/Helpers/Plugins/PluginServiceManager.cs b/Ink Canvas/Helpers/Plugins/PluginServiceManager.cs index fd1b1bf7..3f7ec460 100644 --- a/Ink Canvas/Helpers/Plugins/PluginServiceManager.cs +++ b/Ink Canvas/Helpers/Plugins/PluginServiceManager.cs @@ -452,4 +452,4 @@ namespace Ink_Canvas.Helpers.Plugins #endregion } -} \ No newline at end of file +} \ No newline at end of file diff --git a/Ink Canvas/Helpers/SoftwareLauncher.cs b/Ink Canvas/Helpers/SoftwareLauncher.cs index 5f2e405d..e3dc7188 100644 --- a/Ink Canvas/Helpers/SoftwareLauncher.cs +++ b/Ink Canvas/Helpers/SoftwareLauncher.cs @@ -1,8 +1,8 @@ -using System; +using Microsoft.Win32; +using System; using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; -using Microsoft.Win32; namespace Ink_Canvas.Helpers { diff --git a/Ink Canvas/MainWindow.xaml.cs b/Ink Canvas/MainWindow.xaml.cs index c3ace02e..aceb055a 100644 --- a/Ink Canvas/MainWindow.xaml.cs +++ b/Ink Canvas/MainWindow.xaml.cs @@ -1,3 +1,9 @@ +using Ink_Canvas.Helpers; +using Ink_Canvas.Helpers.Plugins; +using Ink_Canvas.Windows; +using iNKORE.UI.WPF.Modern; +using iNKORE.UI.WPF.Modern.Controls; +using Microsoft.Win32; using System; using System.Collections.Generic; using System.ComponentModel; @@ -16,12 +22,6 @@ using System.Windows.Input; using System.Windows.Interop; using System.Windows.Media; using System.Windows.Threading; -using Ink_Canvas.Helpers; -using Ink_Canvas.Helpers.Plugins; -using Ink_Canvas.Windows; -using iNKORE.UI.WPF.Modern; -using iNKORE.UI.WPF.Modern.Controls; -using Microsoft.Win32; using Application = System.Windows.Application; using Brushes = System.Windows.Media.Brushes; using Button = System.Windows.Controls.Button; @@ -42,7 +42,7 @@ namespace Ink_Canvas private int currentPageIndex; private System.Windows.Controls.Canvas currentCanvas; private AutoUpdateHelper.UpdateLineGroup AvailableLatestLineGroup; - + // 全局快捷键管理器 private GlobalHotkeyManager _globalHotkeyManager; @@ -239,11 +239,11 @@ namespace Ink_Canvas // 初始化窗口置顶开关 ToggleSwitchAlwaysOnTop.IsOn = Settings.Advanced.IsAlwaysOnTop; ApplyAlwaysOnTop(); - + // 添加窗口激活事件处理,确保置顶状态在窗口重新激活时得到保持 Activated += Window_Activated; Deactivated += Window_Deactivated; - + // 为浮动栏按钮添加触摸事件支持 AddTouchSupportToFloatingBarButtons(); } @@ -517,7 +517,7 @@ namespace Ink_Canvas // 初始化剪贴板监控 InitializeClipboardMonitoring(); - + // 初始化全局快捷键管理器 InitializeGlobalHotkeyManager(); @@ -651,7 +651,7 @@ namespace Ink_Canvas // 清理剪贴板监控 CleanupClipboardMonitoring(); ClipboardNotification.Stop(); - + // 清理全局快捷键管理器 if (_globalHotkeyManager != null) { @@ -1679,7 +1679,7 @@ namespace Ink_Canvas [DllImport("kernel32.dll")] private static extern uint GetCurrentProcessId(); - + private const int GWL_EXSTYLE = -20; private const int WS_EX_NOACTIVATE = 0x08000000; private const int WS_EX_TOPMOST = 0x00000008; @@ -1718,16 +1718,16 @@ namespace Ink_Canvas { // 先设置WPF的Topmost属性 Topmost = true; - + // 使用更强的Win32 API调用来确保置顶 // 1. 设置窗口样式为置顶 int exStyle = GetWindowLong(hwnd, GWL_EXSTYLE); SetWindowLong(hwnd, GWL_EXSTYLE, exStyle | WS_EX_TOPMOST); - + // 2. 使用SetWindowPos确保窗口在最顶层 - SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, + SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOOWNERZORDER); - + // 3. 如果启用了无焦点模式,需要特殊处理 if (Settings.Advanced.IsNoFocusMode) { @@ -1744,18 +1744,18 @@ namespace Ink_Canvas { // 取消置顶时 // 1. 先使用Win32 API取消置顶 - SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, + SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOOWNERZORDER); - + // 2. 移除置顶窗口样式 int exStyle = GetWindowLong(hwnd, GWL_EXSTYLE); SetWindowLong(hwnd, GWL_EXSTYLE, exStyle & ~WS_EX_TOPMOST); - + // 3. 停止置顶维护定时器 StopTopmostMaintenance(); - + // 注意:这里不直接设置Topmost,让其他代码根据模式决定 - + // 添加调试日志 LogHelper.WriteLogToFile("应用窗口置顶: 取消置顶", LogHelper.LogType.Trace); } @@ -1772,14 +1772,14 @@ namespace Ink_Canvas private void StartTopmostMaintenance() { if (isTopmostMaintenanceEnabled) return; - + if (topmostMaintenanceTimer == null) { topmostMaintenanceTimer = new DispatcherTimer(); topmostMaintenanceTimer.Interval = TimeSpan.FromMilliseconds(500); // 每500ms检查一次 topmostMaintenanceTimer.Tick += TopmostMaintenanceTimer_Tick; } - + topmostMaintenanceTimer.Start(); isTopmostMaintenanceEnabled = true; LogHelper.WriteLogToFile("启动置顶维护定时器", LogHelper.LogType.Trace); @@ -1827,17 +1827,17 @@ namespace Ink_Canvas // 检查前景窗口是否是当前应用程序的子窗口 var foregroundWindowProcessId = GetWindowThreadProcessId(foregroundWindow, out uint processId); var currentProcessId = GetCurrentProcessId(); - + if (processId == currentProcessId) { // 如果有子窗口在前景,暂停置顶维护 return; } - + // 如果窗口不在最顶层且没有子窗口,重新设置置顶 - SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, + SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOOWNERZORDER); - + // 确保窗口样式正确 int exStyle = GetWindowLong(hwnd, GWL_EXSTYLE); if ((exStyle & WS_EX_TOPMOST) == 0) @@ -1882,7 +1882,7 @@ namespace Ink_Canvas Settings.Advanced.IsNoFocusMode = toggle != null && toggle.IsOn; SaveSettingsToFile(); ApplyNoFocusMode(); - + // 如果启用了窗口置顶,需要重新应用置顶设置以处理无焦点模式的变化 if (Settings.Advanced.IsAlwaysOnTop) { @@ -1898,7 +1898,7 @@ namespace Ink_Canvas SaveSettingsToFile(); ApplyAlwaysOnTop(); } - + private void Window_Activated(object sender, EventArgs e) { // 窗口激活时,如果启用了置顶功能,重新应用置顶设置 @@ -1911,7 +1911,7 @@ namespace Ink_Canvas }), DispatcherPriority.Loaded); } } - + /// /// 窗口失去焦点时的处理 /// @@ -2010,7 +2010,7 @@ namespace Ink_Canvas { Settings.Canvas.EnableInkFade = ToggleSwitchEnableInkFade.IsOn; _inkFadeManager.IsEnabled = Settings.Canvas.EnableInkFade; - + // 同步批注子面板中的开关状态 if (ToggleSwitchInkFadeInPanel != null) { @@ -2022,7 +2022,7 @@ namespace Ink_Canvas { ToggleSwitchInkFadeInPanel2.IsOn = Settings.Canvas.EnableInkFade; } - + LogHelper.WriteLogToFile($"墨迹渐隐功能已{(Settings.Canvas.EnableInkFade ? "启用" : "禁用")}", LogHelper.LogType.Event); } catch (Exception ex) @@ -2062,7 +2062,7 @@ namespace Ink_Canvas { Settings.Canvas.EnableInkFade = ToggleSwitchInkFadeInPanel.IsOn; _inkFadeManager.IsEnabled = Settings.Canvas.EnableInkFade; - + // 同步设置面板中的开关状态 if (ToggleSwitchEnableInkFade != null) { @@ -2074,7 +2074,7 @@ namespace Ink_Canvas { ToggleSwitchInkFadeInPanel2.IsOn = Settings.Canvas.EnableInkFade; } - + LogHelper.WriteLogToFile($"批注子面板中墨迹渐隐功能已{(Settings.Canvas.EnableInkFade ? "启用" : "禁用")}", LogHelper.LogType.Event); } catch (Exception ex) @@ -2096,21 +2096,21 @@ namespace Ink_Canvas // 查找PPT放映窗口并发送按键 var pptWindows = Process.GetProcessesByName("POWERPNT"); var wpsWindows = Process.GetProcessesByName("wpp"); - + foreach (var process in pptWindows.Concat(wpsWindows)) { if (process.MainWindowHandle != IntPtr.Zero) { // 激活PPT窗口 SetForegroundWindow(process.MainWindowHandle); - + // 发送翻页按键消息 int keyCode = isPrevious ? 0x21 : 0x22; // VK_PRIOR : VK_NEXT - + // 发送按键按下和释放消息 PostMessage(process.MainWindowHandle, 0x0100, (IntPtr)keyCode, IntPtr.Zero); // WM_KEYDOWN PostMessage(process.MainWindowHandle, 0x0101, (IntPtr)keyCode, IntPtr.Zero); // WM_KEYUP - + break; } } @@ -2138,19 +2138,19 @@ namespace Ink_Canvas { // 执行模式切换 inkCanvas.EditingMode = newMode; - + // 根据模式确定是否为鼠标模式(无工具模式) bool isMouseMode = newMode == InkCanvasEditingMode.None; - + // 更新快捷键状态 if (_globalHotkeyManager != null) { _globalHotkeyManager.UpdateHotkeyStateForToolMode(isMouseMode); } - + // 执行额外的操作(如果有) additionalActions?.Invoke(); - + LogHelper.WriteLogToFile($"工具模式已切换到: {newMode}, 鼠标模式: {isMouseMode}", LogHelper.LogType.Trace); } catch (Exception ex) diff --git a/Ink Canvas/MainWindow_cs/MW_AutoFold.cs b/Ink Canvas/MainWindow_cs/MW_AutoFold.cs index a92b0394..76b3bf37 100644 --- a/Ink Canvas/MainWindow_cs/MW_AutoFold.cs +++ b/Ink Canvas/MainWindow_cs/MW_AutoFold.cs @@ -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 { diff --git a/Ink Canvas/MainWindow_cs/MW_AutoStart.cs b/Ink Canvas/MainWindow_cs/MW_AutoStart.cs index e38c74d1..a86808cc 100644 --- a/Ink Canvas/MainWindow_cs/MW_AutoStart.cs +++ b/Ink Canvas/MainWindow_cs/MW_AutoStart.cs @@ -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; diff --git a/Ink Canvas/MainWindow_cs/MW_AutoTheme.cs b/Ink Canvas/MainWindow_cs/MW_AutoTheme.cs index e41f79fb..f908c2ad 100644 --- a/Ink Canvas/MainWindow_cs/MW_AutoTheme.cs +++ b/Ink Canvas/MainWindow_cs/MW_AutoTheme.cs @@ -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 diff --git a/Ink Canvas/MainWindow_cs/MW_BoardControls.cs b/Ink Canvas/MainWindow_cs/MW_BoardControls.cs index 6c1510e3..934c7e25 100644 --- a/Ink Canvas/MainWindow_cs/MW_BoardControls.cs +++ b/Ink Canvas/MainWindow_cs/MW_BoardControls.cs @@ -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) diff --git a/Ink Canvas/MainWindow_cs/MW_BoardIcons.cs b/Ink Canvas/MainWindow_cs/MW_BoardIcons.cs index 6f956a9f..4e41ca79 100644 --- a/Ink Canvas/MainWindow_cs/MW_BoardIcons.cs +++ b/Ink Canvas/MainWindow_cs/MW_BoardIcons.cs @@ -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 { diff --git a/Ink Canvas/MainWindow_cs/MW_ClipboardHandler.cs b/Ink Canvas/MainWindow_cs/MW_ClipboardHandler.cs index 99053852..7ff64b76 100644 --- a/Ink Canvas/MainWindow_cs/MW_ClipboardHandler.cs +++ b/Ink Canvas/MainWindow_cs/MW_ClipboardHandler.cs @@ -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) { diff --git a/Ink Canvas/MainWindow_cs/MW_Colors.cs b/Ink Canvas/MainWindow_cs/MW_Colors.cs index c55e306c..00eee032 100644 --- a/Ink Canvas/MainWindow_cs/MW_Colors.cs +++ b/Ink Canvas/MainWindow_cs/MW_Colors.cs @@ -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(); } diff --git a/Ink Canvas/MainWindow_cs/MW_ElementsControls.cs b/Ink Canvas/MainWindow_cs/MW_ElementsControls.cs index 378dc86f..1e356ec7 100644 --- a/Ink Canvas/MainWindow_cs/MW_ElementsControls.cs +++ b/Ink Canvas/MainWindow_cs/MW_ElementsControls.cs @@ -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) diff --git a/Ink Canvas/MainWindow_cs/MW_Eraser.cs b/Ink Canvas/MainWindow_cs/MW_Eraser.cs index 4295d9ce..d49cfe1a 100644 --- a/Ink Canvas/MainWindow_cs/MW_Eraser.cs +++ b/Ink Canvas/MainWindow_cs/MW_Eraser.cs @@ -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 { diff --git a/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs b/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs index 35b1f2a5..7ac341a1 100644 --- a/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs +++ b/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs @@ -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; + // 快捷调色盘的Margin:Margin="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); diff --git a/Ink Canvas/MainWindow_cs/MW_Hotkeys.cs b/Ink Canvas/MainWindow_cs/MW_Hotkeys.cs index 81df3421..61fbaaf7 100644 --- a/Ink Canvas/MainWindow_cs/MW_Hotkeys.cs +++ b/Ink Canvas/MainWindow_cs/MW_Hotkeys.cs @@ -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) { diff --git a/Ink Canvas/MainWindow_cs/MW_ImageInsert.cs b/Ink Canvas/MainWindow_cs/MW_ImageInsert.cs index 9b1a6592..9e7c89d5 100644 --- a/Ink Canvas/MainWindow_cs/MW_ImageInsert.cs +++ b/Ink Canvas/MainWindow_cs/MW_ImageInsert.cs @@ -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 } } -} \ No newline at end of file +} \ No newline at end of file diff --git a/Ink Canvas/MainWindow_cs/MW_Notification.cs b/Ink Canvas/MainWindow_cs/MW_Notification.cs index c473b859..e1e69945 100644 --- a/Ink Canvas/MainWindow_cs/MW_Notification.cs +++ b/Ink Canvas/MainWindow_cs/MW_Notification.cs @@ -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 { diff --git a/Ink Canvas/MainWindow_cs/MW_PPT.cs b/Ink Canvas/MainWindow_cs/MW_PPT.cs index 065def08..ce8bdd48 100644 --- a/Ink Canvas/MainWindow_cs/MW_PPT.cs +++ b/Ink Canvas/MainWindow_cs/MW_PPT.cs @@ -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); }); } diff --git a/Ink Canvas/MainWindow_cs/MW_PageListView.cs b/Ink Canvas/MainWindow_cs/MW_PageListView.cs index c7ea6c80..27d0e8e7 100644 --- a/Ink Canvas/MainWindow_cs/MW_PageListView.cs +++ b/Ink Canvas/MainWindow_cs/MW_PageListView.cs @@ -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; diff --git a/Ink Canvas/MainWindow_cs/MW_Save&OpenStrokes.cs b/Ink Canvas/MainWindow_cs/MW_Save&OpenStrokes.cs index fb242d97..347c8644 100644 --- a/Ink Canvas/MainWindow_cs/MW_Save&OpenStrokes.cs +++ b/Ink Canvas/MainWindow_cs/MW_Save&OpenStrokes.cs @@ -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; diff --git a/Ink Canvas/MainWindow_cs/MW_SelectionGestures.cs b/Ink Canvas/MainWindow_cs/MW_SelectionGestures.cs index f8547b85..e3ea3b83 100644 --- a/Ink Canvas/MainWindow_cs/MW_SelectionGestures.cs +++ b/Ink Canvas/MainWindow_cs/MW_SelectionGestures.cs @@ -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) diff --git a/Ink Canvas/MainWindow_cs/MW_Settings.cs b/Ink Canvas/MainWindow_cs/MW_Settings.cs index 803000f5..0094a72c 100644 --- a/Ink Canvas/MainWindow_cs/MW_Settings.cs +++ b/Ink Canvas/MainWindow_cs/MW_Settings.cs @@ -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) // 新增:只在屏幕模式下重新计算浮动栏位置 { diff --git a/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs b/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs index 5501b884..e4c5c6b1 100644 --- a/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs +++ b/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs @@ -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(); diff --git a/Ink Canvas/MainWindow_cs/MW_ShapeDrawing.cs b/Ink Canvas/MainWindow_cs/MW_ShapeDrawing.cs index 4b8ca738..0644f141 100644 --- a/Ink Canvas/MainWindow_cs/MW_ShapeDrawing.cs +++ b/Ink Canvas/MainWindow_cs/MW_ShapeDrawing.cs @@ -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(); 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); } diff --git a/Ink Canvas/MainWindow_cs/MW_SimulatePressure&InkToShape.cs b/Ink Canvas/MainWindow_cs/MW_SimulatePressure&InkToShape.cs index 8e14c503..15f866e3 100644 --- a/Ink Canvas/MainWindow_cs/MW_SimulatePressure&InkToShape.cs +++ b/Ink Canvas/MainWindow_cs/MW_SimulatePressure&InkToShape.cs @@ -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; diff --git a/Ink Canvas/MainWindow_cs/MW_TimeMachine.cs b/Ink Canvas/MainWindow_cs/MW_TimeMachine.cs index 541d2068..1ad265d0 100644 --- a/Ink Canvas/MainWindow_cs/MW_TimeMachine.cs +++ b/Ink Canvas/MainWindow_cs/MW_TimeMachine.cs @@ -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); } diff --git a/Ink Canvas/MainWindow_cs/MW_Timer.cs b/Ink Canvas/MainWindow_cs/MW_Timer.cs index 4988c444..3c9e0e4b 100644 --- a/Ink Canvas/MainWindow_cs/MW_Timer.cs +++ b/Ink Canvas/MainWindow_cs/MW_Timer.cs @@ -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 { diff --git a/Ink Canvas/MainWindow_cs/MW_TouchEvents.cs b/Ink Canvas/MainWindow_cs/MW_TouchEvents.cs index 7aedfd43..bfba3b73 100644 --- a/Ink Canvas/MainWindow_cs/MW_TouchEvents.cs +++ b/Ink Canvas/MainWindow_cs/MW_TouchEvents.cs @@ -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; } } - + /// /// 启动手掌擦恢复定时器,防止卡死状态 /// @@ -988,10 +988,10 @@ namespace Ink_Canvas palmEraserRecoveryTimer.Interval = TimeSpan.FromMilliseconds(1000); // 每秒检查一次 palmEraserRecoveryTimer.Tick += PalmEraserRecoveryTimer_Tick; } - + palmEraserRecoveryTimer.Start(); } - + /// /// 停止手掌擦恢复定时器 /// @@ -1002,20 +1002,20 @@ namespace Ink_Canvas palmEraserRecoveryTimer.Stop(); } } - + /// /// 手掌擦恢复定时器事件处理 /// 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"); } } diff --git a/Ink Canvas/MainWindow_cs/MW_TrayIcon.cs b/Ink Canvas/MainWindow_cs/MW_TrayIcon.cs index b20cb2d7..96796023 100644 --- a/Ink Canvas/MainWindow_cs/MW_TrayIcon.cs +++ b/Ink Canvas/MainWindow_cs/MW_TrayIcon.cs @@ -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; diff --git a/Ink Canvas/Resources/Settings.cs b/Ink Canvas/Resources/Settings.cs index 8efdf432..2216016d 100644 --- a/Ink Canvas/Resources/Settings.cs +++ b/Ink Canvas/Resources/Settings.cs @@ -1,7 +1,7 @@ -using System; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.IO; -using Newtonsoft.Json; namespace Ink_Canvas { @@ -93,14 +93,14 @@ namespace Ink_Canvas [JsonProperty("clearCanvasAlsoClearImages")] public bool ClearCanvasAlsoClearImages { get; set; } = true; [JsonProperty("showCircleCenter")] - public bool ShowCircleCenter { get; set; } + public bool ShowCircleCenter { get; set; } // 墨迹渐隐功能设置 [JsonProperty("enableInkFade")] public bool EnableInkFade { get; set; } // 是否启用墨迹渐隐功能 [JsonProperty("inkFadeTime")] public int InkFadeTime { get; set; } = 3000; // 墨迹渐隐时间(毫秒) - + } public enum OptionalOperation @@ -152,7 +152,7 @@ namespace Ink_Canvas [JsonProperty("skippedVersion")] public string SkippedVersion { get; set; } = ""; [JsonProperty("isEnableNibMode")] - public bool IsEnableNibMode { get; set; } + public bool IsEnableNibMode { get; set; } [JsonProperty("isFoldAtStartup")] public bool IsFoldAtStartup { get; set; } [JsonProperty("crashAction")] @@ -205,7 +205,7 @@ namespace Ink_Canvas public bool IsShowModeFingerToggleSwitch { get; set; } = true; [JsonProperty("theme")] public int Theme { get; set; } - + // 浮动栏按钮显示控制 [JsonProperty("isShowShapeButton")] public bool IsShowShapeButton { get; set; } = true; @@ -218,7 +218,7 @@ namespace Ink_Canvas [JsonProperty("isShowWhiteboardButton")] public bool IsShowWhiteboardButton { get; set; } = true; [JsonProperty("isShowHideButton")] - public bool IsShowHideButton { get; set; } = true; + public bool IsShowHideButton { get; set; } = true; [JsonProperty("isShowLassoSelectButton")] public bool IsShowLassoSelectButton { get; set; } = true; [JsonProperty("isShowClearAndMouseButton")] @@ -226,12 +226,12 @@ namespace Ink_Canvas [JsonProperty("eraserDisplayOption")] public int EraserDisplayOption { get; set; } - + [JsonProperty("isShowQuickColorPalette")] public bool IsShowQuickColorPalette { get; set; } - + [JsonProperty("quickColorPaletteDisplayMode")] - public int QuickColorPaletteDisplayMode { get; set; } = 1; + public int QuickColorPaletteDisplayMode { get; set; } = 1; } diff --git a/Ink Canvas/Windows/AddCustomIconWindow.xaml.cs b/Ink Canvas/Windows/AddCustomIconWindow.xaml.cs index 060c5b9d..a214c9f2 100644 --- a/Ink Canvas/Windows/AddCustomIconWindow.xaml.cs +++ b/Ink Canvas/Windows/AddCustomIconWindow.xaml.cs @@ -1,8 +1,8 @@ +using Microsoft.Win32; using System; using System.IO; using System.Windows; using System.Windows.Media.Imaging; -using Microsoft.Win32; namespace Ink_Canvas { diff --git a/Ink Canvas/Windows/AddPickNameBackgroundWindow.xaml.cs b/Ink Canvas/Windows/AddPickNameBackgroundWindow.xaml.cs index f9aa8951..bc602748 100644 --- a/Ink Canvas/Windows/AddPickNameBackgroundWindow.xaml.cs +++ b/Ink Canvas/Windows/AddPickNameBackgroundWindow.xaml.cs @@ -1,8 +1,8 @@ +using Microsoft.Win32; using System; using System.IO; using System.Windows; using System.Windows.Media.Imaging; -using Microsoft.Win32; namespace Ink_Canvas { diff --git a/Ink Canvas/Windows/CountdownTimerWindow.xaml.cs b/Ink Canvas/Windows/CountdownTimerWindow.xaml.cs index 6e00b4c5..03e38cc6 100644 --- a/Ink Canvas/Windows/CountdownTimerWindow.xaml.cs +++ b/Ink Canvas/Windows/CountdownTimerWindow.xaml.cs @@ -1,4 +1,5 @@ -using System; +using Ink_Canvas.Helpers; +using System; using System.ComponentModel; using System.Media; using System.Timers; @@ -7,7 +8,6 @@ using System.Windows.Forms; using System.Windows.Input; using System.Windows.Interop; using System.Windows.Media; -using Ink_Canvas.Helpers; using Application = System.Windows.Application; using MouseEventArgs = System.Windows.Input.MouseEventArgs; using Timer = System.Timers.Timer; diff --git a/Ink Canvas/Windows/HasNewUpdateWindow.xaml.cs b/Ink Canvas/Windows/HasNewUpdateWindow.xaml.cs index 41a7b7c8..09b0010b 100644 --- a/Ink Canvas/Windows/HasNewUpdateWindow.xaml.cs +++ b/Ink Canvas/Windows/HasNewUpdateWindow.xaml.cs @@ -1,4 +1,7 @@ -using System; +using Ink_Canvas.Helpers; +using iNKORE.UI.WPF.Modern.Controls; +using MdXaml; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -10,9 +13,6 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Interop; using System.Windows.Media; -using Ink_Canvas.Helpers; -using iNKORE.UI.WPF.Modern.Controls; -using MdXaml; namespace Ink_Canvas { @@ -340,7 +340,7 @@ namespace Ink_Canvas downloadUrl = Path.Combine(updatesFolderPath, $"InkCanvasForClass.CE.{version}.zip"); } LogHelper.WriteLogToFile($"AutoUpdate | 开始安装版本: {version}"); - AutoUpdateHelper.InstallNewVersionApp(version, true); + AutoUpdateHelper.InstallNewVersionApp(version, true); App.IsAppExitByUser = true; Application.Current.Dispatcher.Invoke(() => { diff --git a/Ink Canvas/Windows/HistoryRollbackWindow.xaml.cs b/Ink Canvas/Windows/HistoryRollbackWindow.xaml.cs index b9a749a4..1fb83a07 100644 --- a/Ink Canvas/Windows/HistoryRollbackWindow.xaml.cs +++ b/Ink Canvas/Windows/HistoryRollbackWindow.xaml.cs @@ -1,3 +1,4 @@ +using Ink_Canvas.Helpers; using System; using System.Collections.Generic; using System.ComponentModel; @@ -7,7 +8,6 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Input; -using Ink_Canvas.Helpers; // Added for OrderByDescending diff --git a/Ink Canvas/Windows/HotkeyItem.xaml.cs b/Ink Canvas/Windows/HotkeyItem.xaml.cs index 146791e3..47bce516 100644 --- a/Ink Canvas/Windows/HotkeyItem.xaml.cs +++ b/Ink Canvas/Windows/HotkeyItem.xaml.cs @@ -33,7 +33,7 @@ namespace Ink_Canvas.Windows public string DefaultKey { get; set; } public string DefaultModifiers { get; set; } - + /// /// 快捷键名称(用于标识,如"Undo") /// @@ -94,10 +94,10 @@ namespace Ink_Canvas.Windows { BtnSetHotkey.Content = "请按键..."; BtnSetHotkey.Background = Brushes.Orange; - + // 设置焦点以捕获键盘事件 Focus(); - + // 添加键盘事件处理器 KeyDown += HotkeyItem_KeyDown; KeyUp += HotkeyItem_KeyUp; @@ -107,7 +107,7 @@ namespace Ink_Canvas.Windows { BtnSetHotkey.Content = "设置"; BtnSetHotkey.Background = Brushes.DodgerBlue; - + // 移除键盘事件处理器 KeyDown -= HotkeyItem_KeyDown; KeyUp -= HotkeyItem_KeyUp; @@ -116,7 +116,7 @@ namespace Ink_Canvas.Windows private void HotkeyItem_KeyDown(object sender, KeyEventArgs e) { e.Handled = true; - + // 忽略某些特殊键 if (e.Key == Key.LeftShift || e.Key == Key.RightShift || e.Key == Key.LeftCtrl || e.Key == Key.RightCtrl || @@ -140,10 +140,10 @@ namespace Ink_Canvas.Windows // 设置新的快捷键 var oldKey = _currentKey; var oldModifiers = _currentModifiers; - + _currentKey = e.Key; _currentModifiers = modifiers; - + UpdateHotkeyDisplay(); StopHotkeyCapture(); @@ -169,4 +169,4 @@ namespace Ink_Canvas.Windows } #endregion } -} \ No newline at end of file +} \ No newline at end of file diff --git a/Ink Canvas/Windows/HotkeySettingsWindow.xaml.cs b/Ink Canvas/Windows/HotkeySettingsWindow.xaml.cs index b21ee2c5..f4d1895e 100644 --- a/Ink Canvas/Windows/HotkeySettingsWindow.xaml.cs +++ b/Ink Canvas/Windows/HotkeySettingsWindow.xaml.cs @@ -1,10 +1,10 @@ +using Ink_Canvas.Helpers; using System; using System.Collections.Generic; using System.Reflection; using System.Windows; using System.Windows.Controls; using System.Windows.Input; -using Ink_Canvas.Helpers; namespace Ink_Canvas.Windows { @@ -30,15 +30,15 @@ namespace Ink_Canvas.Windows // 隐藏主窗口的设置页面 HideMainWindowSettings(); InitializeHotkeyItems(); - + // 延迟加载快捷键,确保快捷键管理器已完全初始化 - Loaded += (s, e) => + Loaded += (s, e) => { try { // 不启用快捷键注册功能,只读取配置文件中的快捷键信息用于显示 // 这样用户可以看到配置文件中保存的快捷键,但不会自动注册 - + // 加载当前快捷键(包括配置文件中的) LoadCurrentHotkeys(); SetupEventHandlers(); @@ -60,62 +60,62 @@ namespace Ink_Canvas.Windows try { LogHelper.WriteLogToFile("开始初始化快捷键项"); - + // 初始化快捷键项并设置HotkeyName _hotkeyItems["Undo"] = UndoHotkey; UndoHotkey.HotkeyName = "Undo"; - + _hotkeyItems["Redo"] = RedoHotkey; RedoHotkey.HotkeyName = "Redo"; - + _hotkeyItems["Clear"] = ClearHotkey; ClearHotkey.HotkeyName = "Clear"; - + _hotkeyItems["Paste"] = PasteHotkey; PasteHotkey.HotkeyName = "Paste"; - + _hotkeyItems["SelectTool"] = SelectToolHotkey; SelectToolHotkey.HotkeyName = "SelectTool"; - + _hotkeyItems["DrawTool"] = DrawToolHotkey; DrawToolHotkey.HotkeyName = "DrawTool"; - + _hotkeyItems["EraserTool"] = EraserToolHotkey; EraserToolHotkey.HotkeyName = "EraserTool"; - + _hotkeyItems["BlackboardTool"] = BlackboardToolHotkey; BlackboardToolHotkey.HotkeyName = "BlackboardTool"; - + _hotkeyItems["QuitDrawTool"] = QuitDrawToolHotkey; QuitDrawToolHotkey.HotkeyName = "QuitDrawTool"; - + _hotkeyItems["Pen1"] = Pen1Hotkey; Pen1Hotkey.HotkeyName = "Pen1"; - + _hotkeyItems["Pen2"] = Pen2Hotkey; Pen2Hotkey.HotkeyName = "Pen2"; - + _hotkeyItems["Pen3"] = Pen3Hotkey; Pen3Hotkey.HotkeyName = "Pen3"; - + _hotkeyItems["Pen4"] = Pen4Hotkey; Pen4Hotkey.HotkeyName = "Pen4"; - + _hotkeyItems["Pen5"] = Pen5Hotkey; Pen5Hotkey.HotkeyName = "Pen5"; - + _hotkeyItems["DrawLine"] = DrawLineHotkey; DrawLineHotkey.HotkeyName = "DrawLine"; - + _hotkeyItems["Screenshot"] = ScreenshotHotkey; ScreenshotHotkey.HotkeyName = "Screenshot"; - + _hotkeyItems["Hide"] = HideHotkey; HideHotkey.HotkeyName = "Hide"; - + _hotkeyItems["Exit"] = ExitHotkey; ExitHotkey.HotkeyName = "Exit"; - + LogHelper.WriteLogToFile($"成功初始化 {_hotkeyItems.Count} 个快捷键项"); } catch (Exception ex) @@ -131,7 +131,7 @@ namespace Ink_Canvas.Windows // 首先尝试从配置文件获取快捷键信息 var configHotkeys = _hotkeyManager.GetHotkeysFromConfigFile(); LogHelper.WriteLogToFile($"配置文件中的快捷键数量: {configHotkeys.Count}"); - + // 显示配置文件中的快捷键 foreach (var hotkey in configHotkeys) { @@ -141,7 +141,7 @@ namespace Ink_Canvas.Windows LogHelper.WriteLogToFile($"从配置文件设置快捷键项: {hotkey.Name} -> {hotkey.Modifiers}+{hotkey.Key}"); } } - + // 为没有快捷键的项目设置默认显示值(仅用于UI显示,不实际注册) foreach (var kvp in _hotkeyItems) { @@ -246,11 +246,11 @@ namespace Ink_Canvas.Windows try { LogHelper.WriteLogToFile($"收到快捷键变更事件: {e.HotkeyName} -> {e.Modifiers}+{e.Key}"); - + // 检查快捷键冲突 if (IsHotkeyConflict(e.Key, e.Modifiers, e.HotkeyName)) { - MessageBox.Show($"快捷键 {e.Modifiers}+{e.Key} 已被其他功能使用,请选择其他组合。", + MessageBox.Show($"快捷键 {e.Modifiers}+{e.Key} 已被其他功能使用,请选择其他组合。", "快捷键冲突", MessageBoxButton.OK, MessageBoxImage.Warning); return; } @@ -270,14 +270,14 @@ namespace Ink_Canvas.Windows var registeredHotkeys = _hotkeyManager.GetRegisteredHotkeys(); foreach (var hotkey in registeredHotkeys) { - if (hotkey.Name != excludeHotkeyName && - hotkey.Key == key && + if (hotkey.Name != excludeHotkeyName && + hotkey.Key == key && hotkey.Modifiers == modifiers) { return true; } } - + // 检查是否与默认快捷键冲突(如果当前快捷键项还没有注册) if (excludeHotkeyName != null && _hotkeyItems.TryGetValue(excludeHotkeyName, out var currentItem)) { @@ -299,7 +299,7 @@ namespace Ink_Canvas.Windows } } } - + return false; } @@ -308,30 +308,30 @@ namespace Ink_Canvas.Windows try { LogHelper.WriteLogToFile($"开始更新快捷键: {hotkeyName} -> {modifiers}+{key}"); - + // 先注销原有的快捷键(如果存在) _hotkeyManager.UnregisterHotkey(hotkeyName); LogHelper.WriteLogToFile($"已注销原有快捷键: {hotkeyName}"); - + // 根据快捷键名称获取对应的动作 var action = GetActionForHotkey(hotkeyName); if (action != null) { LogHelper.WriteLogToFile($"找到快捷键动作: {hotkeyName}"); - + // 直接注册新的快捷键 if (_hotkeyManager.RegisterHotkey(hotkeyName, key, modifiers, action)) { LogHelper.WriteLogToFile($"成功注册新快捷键: {hotkeyName} -> {modifiers}+{key}"); - + // 立即保存到配置文件 _hotkeyManager.SaveHotkeysToSettings(); LogHelper.WriteLogToFile("已保存快捷键配置"); - + // 更新UI显示 LoadCurrentHotkeys(); LogHelper.WriteLogToFile("已更新UI显示"); - + LogHelper.WriteLogToFile($"快捷键 {hotkeyName} 已更新为 {modifiers}+{key} 并保存", LogHelper.LogType.Event); } else @@ -404,17 +404,17 @@ namespace Ink_Canvas.Windows try { // 通过反射访问主窗口的penType字段 - var penTypeField = _mainWindow.GetType().GetField("penType", + var penTypeField = _mainWindow.GetType().GetField("penType", BindingFlags.NonPublic | BindingFlags.Instance); - + if (penTypeField != null) { penTypeField.SetValue(_mainWindow, penTypeIndex); - + // 调用CheckPenTypeUIState方法更新UI状态 - var checkPenTypeMethod = _mainWindow.GetType().GetMethod("CheckPenTypeUIState", + var checkPenTypeMethod = _mainWindow.GetType().GetMethod("CheckPenTypeUIState", BindingFlags.NonPublic | BindingFlags.Instance); - + if (checkPenTypeMethod != null) { checkPenTypeMethod.Invoke(_mainWindow, null); @@ -437,18 +437,18 @@ namespace Ink_Canvas.Windows try { // 通过反射访问主窗口的设置面板 - var settingsBorder = _mainWindow.GetType().GetField("BorderSettings", + var settingsBorder = _mainWindow.GetType().GetField("BorderSettings", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(_mainWindow) as Border; - + if (settingsBorder != null) { settingsBorder.Visibility = Visibility.Collapsed; } // 隐藏设置蒙版 - var settingsMask = _mainWindow.GetType().GetField("BorderSettingsMask", + var settingsMask = _mainWindow.GetType().GetField("BorderSettingsMask", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(_mainWindow) as Border; - + if (settingsMask != null) { settingsMask.Visibility = Visibility.Collapsed; @@ -468,18 +468,18 @@ namespace Ink_Canvas.Windows try { // 通过反射访问主窗口的设置面板 - var settingsBorder = _mainWindow.GetType().GetField("BorderSettings", + var settingsBorder = _mainWindow.GetType().GetField("BorderSettings", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(_mainWindow) as Border; - + if (settingsBorder != null) { settingsBorder.Visibility = Visibility.Visible; } // 显示设置蒙版 - var settingsMask = _mainWindow.GetType().GetField("BorderSettingsMask", + var settingsMask = _mainWindow.GetType().GetField("BorderSettingsMask", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(_mainWindow) as Border; - + if (settingsMask != null) { settingsMask.Visibility = Visibility.Visible; @@ -513,22 +513,22 @@ namespace Ink_Canvas.Windows { try { - var result = MessageBox.Show("确定要重置所有快捷键为默认设置吗?", + var result = MessageBox.Show("确定要重置所有快捷键为默认设置吗?", "确认重置", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { // 先注销所有现有快捷键 _hotkeyManager.UnregisterAllHotkeys(); - + // 重置为默认快捷键 _hotkeyManager.RegisterDefaultHotkeys(); - + // 立即保存到配置文件 _hotkeyManager.SaveHotkeysToSettings(); - + // 更新UI显示 LoadCurrentHotkeys(); - + MessageBox.Show("快捷键已重置为默认设置。", "重置完成", MessageBoxButton.OK, MessageBoxImage.Information); } } @@ -545,7 +545,7 @@ namespace Ink_Canvas.Windows { // 保存快捷键配置 _hotkeyManager.SaveHotkeysToSettings(); - + MessageBox.Show("快捷键设置已保存。", "保存成功", MessageBoxButton.OK, MessageBoxImage.Information); Close(); } @@ -569,4 +569,4 @@ namespace Ink_Canvas.Windows public ModifierKeys Modifiers { get; set; } } #endregion -} \ No newline at end of file +} \ No newline at end of file diff --git a/Ink Canvas/Windows/NamesInputWindow.xaml.cs b/Ink Canvas/Windows/NamesInputWindow.xaml.cs index 9e9a637a..ab020adc 100644 --- a/Ink Canvas/Windows/NamesInputWindow.xaml.cs +++ b/Ink Canvas/Windows/NamesInputWindow.xaml.cs @@ -1,7 +1,7 @@ -using System.ComponentModel; +using Ink_Canvas.Helpers; +using System.ComponentModel; using System.IO; using System.Windows; -using Ink_Canvas.Helpers; namespace Ink_Canvas { diff --git a/Ink Canvas/Windows/OperatingGuideWindow.xaml.cs b/Ink Canvas/Windows/OperatingGuideWindow.xaml.cs index 566ab053..68db15de 100644 --- a/Ink Canvas/Windows/OperatingGuideWindow.xaml.cs +++ b/Ink Canvas/Windows/OperatingGuideWindow.xaml.cs @@ -1,6 +1,6 @@ -using System.Windows; +using Ink_Canvas.Helpers; +using System.Windows; using System.Windows.Input; -using Ink_Canvas.Helpers; namespace Ink_Canvas { diff --git a/Ink Canvas/Windows/PluginSettingsWindow.xaml.cs b/Ink Canvas/Windows/PluginSettingsWindow.xaml.cs index 96395e9b..cdaecc4e 100644 --- a/Ink Canvas/Windows/PluginSettingsWindow.xaml.cs +++ b/Ink Canvas/Windows/PluginSettingsWindow.xaml.cs @@ -1,3 +1,9 @@ +using Ink_Canvas.Helpers; +using Ink_Canvas.Helpers.Plugins; +using Ink_Canvas.Helpers.Plugins.BuiltIn; +using Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher; +using iNKORE.UI.WPF.Modern.Controls; +using Microsoft.Win32; using System; using System.Collections.ObjectModel; using System.ComponentModel; @@ -6,12 +12,6 @@ using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Threading; -using Ink_Canvas.Helpers; -using Ink_Canvas.Helpers.Plugins; -using Ink_Canvas.Helpers.Plugins.BuiltIn; -using Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher; -using iNKORE.UI.WPF.Modern.Controls; -using Microsoft.Win32; using MessageBox = System.Windows.MessageBox; namespace Ink_Canvas.Windows diff --git a/Ink Canvas/Windows/RandWindow.xaml.cs b/Ink Canvas/Windows/RandWindow.xaml.cs index c4e07ac7..26810734 100644 --- a/Ink Canvas/Windows/RandWindow.xaml.cs +++ b/Ink Canvas/Windows/RandWindow.xaml.cs @@ -1,4 +1,6 @@ -using System; +using Ink_Canvas.Helpers; +using Microsoft.VisualBasic; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -8,8 +10,6 @@ using System.Windows; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; -using Ink_Canvas.Helpers; -using Microsoft.VisualBasic; using MessageBox = iNKORE.UI.WPF.Modern.Controls.MessageBox; namespace Ink_Canvas diff --git a/Ink Canvas/Windows/ScreenshotSelectorWindow.xaml.cs b/Ink Canvas/Windows/ScreenshotSelectorWindow.xaml.cs index 454a79e3..1dab3dc2 100644 --- a/Ink Canvas/Windows/ScreenshotSelectorWindow.xaml.cs +++ b/Ink Canvas/Windows/ScreenshotSelectorWindow.xaml.cs @@ -81,7 +81,7 @@ namespace Ink_Canvas private void BindControlPointEvents() { // 绑定所有控制点的鼠标事件 - var controlPoints = new[] + var controlPoints = new[] { TopLeftControl, TopRightControl, BottomLeftControl, BottomRightControl, TopControl, BottomControl, LeftControl, RightControl @@ -92,11 +92,11 @@ namespace Ink_Canvas control.MouseLeftButtonDown += ControlPoint_MouseLeftButtonDown; control.MouseLeftButtonUp += ControlPoint_MouseLeftButtonUp; control.MouseMove += ControlPoint_MouseMove; - + // 确保控制点能够接收鼠标事件 control.IsHitTestVisible = true; control.Focusable = false; - + // 设置控制点的Z-index,确保它们在最上层 WpfCanvas.SetZIndex(control, 1003); } @@ -142,7 +142,7 @@ namespace Ink_Canvas { // 重置所有选择状态 ResetSelectionState(); - + _isFreehandMode = false; RectangleModeButton.Background = new SolidColorBrush(Color.FromRgb(37, 99, 235)); // 蓝色 FreehandModeButton.Background = new SolidColorBrush(Color.FromRgb(107, 114, 128)); // 灰色 @@ -154,7 +154,7 @@ namespace Ink_Canvas { // 重置所有选择状态 ResetSelectionState(); - + _isFreehandMode = true; FreehandModeButton.Background = new SolidColorBrush(Color.FromRgb(37, 99, 235)); // 蓝色 RectangleModeButton.Background = new SolidColorBrush(Color.FromRgb(107, 114, 128)); // 灰色 @@ -169,7 +169,7 @@ namespace Ink_Canvas { return; } - + ConfirmSelection(); } @@ -183,10 +183,10 @@ namespace Ink_Canvas // 检查是否点击了UI元素,如果是则不处理选择 var hitElement = e.Source as FrameworkElement; if (hitElement != null && ( - hitElement is Ellipse || - hitElement is System.Windows.Controls.Button || - hitElement is Border || - hitElement is TextBlock || + hitElement is Ellipse || + hitElement is System.Windows.Controls.Button || + hitElement is Border || + hitElement is TextBlock || hitElement is StackPanel || hitElement is Separator || hitElement.Name == "SizeInfoBorder" || @@ -221,7 +221,7 @@ namespace Ink_Canvas _freehandPolyline.Points.Clear(); _freehandPoints.Add(_startPoint); _freehandPolyline.Points.Add(_startPoint); - + // 确保自由绘制路径可见 _freehandPolyline.Visibility = Visibility.Visible; } @@ -252,7 +252,7 @@ namespace Ink_Canvas // 自由绘制模式:添加点到路径 _freehandPoints.Add(_currentPoint); _freehandPolyline.Points.Add(_currentPoint); - + // 确保自由绘制路径可见 _freehandPolyline.Visibility = Visibility.Visible; } @@ -278,7 +278,7 @@ namespace Ink_Canvas { // 创建路径的副本,避免修改原始列表 var pathPoints = new List(_freehandPoints); - + // 简化路径处理,不强制闭合 // 如果路径没有闭合,自动添加起始点 if (pathPoints.Count > 0) @@ -288,13 +288,13 @@ namespace Ink_Canvas // 优化路径:移除重复点和过于接近的点,提高路径质量 var optimizedPath = OptimizePath(pathPoints); - + // 保存选择的路径 SelectedPath = optimizedPath; // 计算边界矩形用于截图 var bounds = CalculatePathBounds(optimizedPath); - + // 确保边界矩形有效 if (bounds.Width >= 0 && bounds.Height >= 0) { @@ -312,7 +312,7 @@ namespace Ink_Canvas return; } } - + // 如果自由绘制失败,清除路径并继续 _freehandPoints.Clear(); _freehandPolyline.Points.Clear(); @@ -350,7 +350,7 @@ namespace Ink_Canvas _isMoving = true; _lastMousePosition = e.GetPosition(this); - + // 确定当前控制点类型 var ellipse = sender as Ellipse; if (ellipse == TopLeftControl) _activeControlPoint = ControlPointType.TopLeft; @@ -467,26 +467,26 @@ namespace Ink_Canvas // 更新角控制点位置 WpfCanvas.SetLeft(TopLeftControl, rect.Left - 4); WpfCanvas.SetTop(TopLeftControl, rect.Top - 4); - + WpfCanvas.SetLeft(TopRightControl, rect.Right - 4); WpfCanvas.SetTop(TopRightControl, rect.Top - 4); - + WpfCanvas.SetLeft(BottomLeftControl, rect.Left - 4); WpfCanvas.SetTop(BottomLeftControl, rect.Bottom - 4); - + WpfCanvas.SetLeft(BottomRightControl, rect.Right - 4); WpfCanvas.SetTop(BottomRightControl, rect.Bottom - 4); // 更新边控制点位置 WpfCanvas.SetLeft(TopControl, rect.Left + rect.Width / 2 - 4); WpfCanvas.SetTop(TopControl, rect.Top - 4); - + WpfCanvas.SetLeft(BottomControl, rect.Left + rect.Width / 2 - 4); WpfCanvas.SetTop(BottomControl, rect.Bottom - 4); - + WpfCanvas.SetLeft(LeftControl, rect.Left - 4); WpfCanvas.SetTop(LeftControl, rect.Top + rect.Height / 2 - 4); - + WpfCanvas.SetLeft(RightControl, rect.Right - 4); WpfCanvas.SetTop(RightControl, rect.Top + rect.Height / 2 - 4); } @@ -522,7 +522,7 @@ namespace Ink_Canvas { // 更新选择区域的几何体 SelectionClipGeometry.Rect = selectionRect; - + // 显示透明遮罩,隐藏原始遮罩 TransparentSelectionMask.Visibility = Visibility.Visible; OverlayRectangle.Visibility = Visibility.Collapsed; @@ -580,7 +580,7 @@ namespace Ink_Canvas { return; } - + if (_isAdjusting) { // 转换为屏幕坐标,考虑DPI缩放 @@ -701,29 +701,29 @@ namespace Ink_Canvas _isAdjusting = false; _isMoving = false; _activeControlPoint = ControlPointType.None; - + // 清除自由绘制的内容 _freehandPoints.Clear(); _freehandPolyline.Points.Clear(); _freehandPolyline.Visibility = Visibility.Collapsed; - + // 清除矩形选择的内容 SelectionRectangle.Visibility = Visibility.Collapsed; ControlPointsCanvas.Visibility = Visibility.Collapsed; SizeInfoBorder.Visibility = Visibility.Collapsed; SelectionPath.Visibility = Visibility.Collapsed; AdjustModeHint.Visibility = Visibility.Collapsed; - + // 重置遮罩 TransparentSelectionMask.Visibility = Visibility.Collapsed; OverlayRectangle.Visibility = Visibility.Visible; - + // 释放鼠标捕获 if (IsMouseCaptured) { ReleaseMouseCapture(); } - + // 重置选择区域 _currentSelection = new Rect(); SelectedArea = null; diff --git a/Ink Canvas/obj/Debug/net472/InkCanvasForClass.csproj.AssemblyReference.cache b/Ink Canvas/obj/Debug/net472/InkCanvasForClass.csproj.AssemblyReference.cache index 09499edb..e30091c8 100644 Binary files a/Ink Canvas/obj/Debug/net472/InkCanvasForClass.csproj.AssemblyReference.cache and b/Ink Canvas/obj/Debug/net472/InkCanvasForClass.csproj.AssemblyReference.cache differ