diff --git a/Ink Canvas/App.xaml.cs b/Ink Canvas/App.xaml.cs index f524565a..1e04932d 100644 --- a/Ink Canvas/App.xaml.cs +++ b/Ink Canvas/App.xaml.cs @@ -1,19 +1,15 @@ using Hardcodet.Wpf.TaskbarNotification; using Ink_Canvas.Helpers; -using Ink_Canvas.Windows; using iNKORE.UI.WPF.Modern.Controls; using Microsoft.Win32; using Newtonsoft.Json; using System; -using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Net; using System.Reflection; using System.Runtime.InteropServices; -using System.Security; -using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows; @@ -36,7 +32,7 @@ namespace Ink_Canvas public static string[] StartArgs; public static string RootPath = Environment.GetEnvironmentVariable("APPDATA") + "\\Ink Canvas\\"; - + // 新增:标记是否通过--board参数启动 public static bool StartWithBoardMode = false; // 新增:标记是否通过--show参数启动 @@ -302,7 +298,7 @@ namespace Ink_Canvas { string reason = e.Reason == SessionEndReasons.Logoff ? "用户注销" : "系统关机"; WriteCrashLog($"系统会话即将结束: {reason}"); - + // 清理PowerPoint进程守护和悬浮窗拦截器 try { @@ -311,13 +307,13 @@ namespace Ink_Canvas if (mainWindow != null) { // 清理PowerPoint进程守护 - var method = mainWindow.GetType().GetMethod("StopPowerPointProcessMonitoring", + var method = mainWindow.GetType().GetMethod("StopPowerPointProcessMonitoring", BindingFlags.NonPublic | BindingFlags.Instance); method?.Invoke(mainWindow, null); WriteCrashLog("PowerPoint进程守护已在系统关机时清理"); - + // 清理悬浮窗拦截器 - var interceptorField = mainWindow.GetType().GetField("_floatingWindowInterceptorManager", + var interceptorField = mainWindow.GetType().GetField("_floatingWindowInterceptorManager", BindingFlags.NonPublic | BindingFlags.Instance); var interceptorManager = interceptorField?.GetValue(mainWindow); if (interceptorManager != null) @@ -331,7 +327,7 @@ namespace Ink_Canvas { WriteCrashLog($"清理资源失败: {ex.Message}"); } - + DeviceIdentifier.SaveUsageStatsOnShutdown(); } @@ -409,12 +405,12 @@ namespace Ink_Canvas public static void ShowSplashScreen() { - if (_isSplashScreenShown) + if (_isSplashScreenShown) { LogHelper.WriteLogToFile("启动画面已经显示,跳过重复显示"); return; } - + try { LogHelper.WriteLogToFile("开始创建启动画面..."); @@ -435,7 +431,7 @@ namespace Ink_Canvas public static void CloseSplashScreen() { if (!_isSplashScreenShown || _splashScreen == null) return; - + try { _splashScreen.CloseSplashScreen(); @@ -481,7 +477,7 @@ namespace Ink_Canvas return (bool)obj["appearance"]["enableSplashScreen"]; } } - + // 如果设置文件不存在或没有该设置,返回默认值false return false; } @@ -596,8 +592,8 @@ namespace Ink_Canvas ShowSplashScreen(); SetSplashMessage("正在启动 Ink Canvas..."); SetSplashProgress(20); - await Task.Delay(500); - + await Task.Delay(500); + // 强制刷新UI,确保启动画面显示 Application.Current.Dispatcher.Invoke(() => { }, DispatcherPriority.Render); } @@ -610,7 +606,7 @@ namespace Ink_Canvas // 检查是否为最终应用启动(更新后的应用) bool isFinalApp = e.Args.Contains("--final-app"); bool skipMutexCheck = e.Args.Contains("--skip-mutex-check"); - + // 检查是否通过--board参数启动 bool hasBoardArg = e.Args.Contains("--board"); if (hasBoardArg) @@ -638,8 +634,8 @@ namespace Ink_Canvas { SetSplashMessage("正在初始化组件..."); SetSplashProgress(40); - await Task.Delay(500); - } + await Task.Delay(500); + } try { IACoreDllExtractor.ExtractIACoreDlls(); @@ -654,8 +650,8 @@ namespace Ink_Canvas { SetSplashMessage("正在加载配置..."); SetSplashProgress(60); - await Task.Delay(500); - } + await Task.Delay(500); + } DeviceIdentifier.RecordAppLaunch(); LogHelper.WriteLogToFile($"App | 设备ID: {DeviceIdentifier.GetDeviceId()}"); LogHelper.WriteLogToFile($"App | 使用频率: {DeviceIdentifier.GetUsageFrequency()}"); @@ -902,11 +898,11 @@ namespace Ink_Canvas { SetSplashMessage("正在初始化主界面..."); SetSplashProgress(80); - await Task.Delay(500); - } + await Task.Delay(500); + } var mainWindow = new MainWindow(); MainWindow = mainWindow; - + // 主窗口加载完成后关闭启动画面 mainWindow.Loaded += (s, args) => { @@ -929,7 +925,7 @@ namespace Ink_Canvas }); } }; - + mainWindow.Show(); // 注册.icstk文件关联 diff --git a/Ink Canvas/FloatingWindowInterceptorManager.cs b/Ink Canvas/FloatingWindowInterceptorManager.cs index 9abd6a00..031220f5 100644 --- a/Ink Canvas/FloatingWindowInterceptorManager.cs +++ b/Ink Canvas/FloatingWindowInterceptorManager.cs @@ -1,7 +1,7 @@ +using Ink_Canvas.Helpers; using System; using System.Collections.Generic; using System.Linq; -using Ink_Canvas.Helpers; namespace Ink_Canvas { @@ -46,7 +46,7 @@ namespace Ink_Canvas { _settings = settings ?? new FloatingWindowInterceptorSettings(); _interceptor = new FloatingWindowInterceptor(); - + // 订阅事件 _interceptor.WindowIntercepted += OnWindowIntercepted; _interceptor.WindowRestored += OnWindowRestored; @@ -116,7 +116,7 @@ namespace Ink_Canvas try { _interceptor.SetInterceptRule(type, enabled); - + // 更新设置 var ruleName = type.ToString(); if (_settings.InterceptRules.ContainsKey(ruleName)) @@ -258,7 +258,7 @@ namespace Ink_Canvas try { _settings.ScanIntervalMs = intervalMs; - + // 如果正在运行,重启以应用新间隔 if (IsRunning) { diff --git a/Ink Canvas/Helpers/AdvancedBezierSmoothing.cs b/Ink Canvas/Helpers/AdvancedBezierSmoothing.cs index 51d0588f..cde8b253 100644 --- a/Ink Canvas/Helpers/AdvancedBezierSmoothing.cs +++ b/Ink Canvas/Helpers/AdvancedBezierSmoothing.cs @@ -732,9 +732,9 @@ namespace Ink_Canvas.Helpers /// public class AdvancedBezierSmoothing { - public double SmoothingStrength { get; set; } = 0.6; - public double ResampleInterval { get; set; } = 2.0; - public int InterpolationSteps { get; set; } = 12; + public double SmoothingStrength { get; set; } = 0.6; + public double ResampleInterval { get; set; } = 2.0; + public int InterpolationSteps { get; set; } = 12; public Stroke SmoothStroke(Stroke stroke) { @@ -764,7 +764,7 @@ namespace Ink_Canvas.Helpers { DrawingAttributes = stroke.DrawingAttributes.Clone() }; - + System.Diagnostics.Debug.WriteLine($"AdvancedBezierSmoothing: 创建平滑笔画成功"); return smoothedStroke; } @@ -797,7 +797,7 @@ namespace Ink_Canvas.Helpers // 只生成2-3个插值点 int steps = 2; - + // 生成贝塞尔曲线点 for (int j = 1; j <= steps; j++) { @@ -808,7 +808,7 @@ namespace Ink_Canvas.Helpers } result.Add(points[points.Length - 1]); - + // 去重处理 return RemoveDuplicatePoints(result.ToArray()); } @@ -827,10 +827,10 @@ namespace Ink_Canvas.Helpers { var lastPoint = result[result.Count - 1]; var currentPoint = points[i]; - - double distance = Math.Sqrt(Math.Pow(currentPoint.X - lastPoint.X, 2) + + + double distance = Math.Sqrt(Math.Pow(currentPoint.X - lastPoint.X, 2) + Math.Pow(currentPoint.Y - lastPoint.Y, 2)); - + if (distance > minDistance) { result.Add(currentPoint); diff --git a/Ink Canvas/Helpers/AutoBackupManager.cs b/Ink Canvas/Helpers/AutoBackupManager.cs index badd4ecf..bac26b53 100644 --- a/Ink Canvas/Helpers/AutoBackupManager.cs +++ b/Ink Canvas/Helpers/AutoBackupManager.cs @@ -1,4 +1,3 @@ -using Ink_Canvas.Helpers; using Newtonsoft.Json; using System; using System.IO; diff --git a/Ink Canvas/Helpers/CameraService.cs b/Ink Canvas/Helpers/CameraService.cs index e0c4c68c..491c9fef 100644 --- a/Ink Canvas/Helpers/CameraService.cs +++ b/Ink Canvas/Helpers/CameraService.cs @@ -31,22 +31,22 @@ namespace Ink_Canvas.Helpers public FilterInfo CurrentCamera { get; private set; } // 新增属性 - public int RotationAngle - { - get => _rotationAngle; - set => _rotationAngle = Math.Max(0, Math.Min(3, value)); + public int RotationAngle + { + get => _rotationAngle; + set => _rotationAngle = Math.Max(0, Math.Min(3, value)); } - - public int ResolutionWidth - { - get => _resolutionWidth; - set => _resolutionWidth = Math.Max(320, Math.Min(1920, value)); + + public int ResolutionWidth + { + get => _resolutionWidth; + set => _resolutionWidth = Math.Max(320, Math.Min(1920, value)); } - - public int ResolutionHeight - { - get => _resolutionHeight; - set => _resolutionHeight = Math.Max(240, Math.Min(1080, value)); + + public int ResolutionHeight + { + get => _resolutionHeight; + set => _resolutionHeight = Math.Max(240, Math.Min(1080, value)); } public CameraService() @@ -75,7 +75,7 @@ namespace Ink_Canvas.Helpers { AvailableCameras.Clear(); var videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); - + foreach (FilterInfo device in videoDevices) { AvailableCameras.Add(device); @@ -265,27 +265,27 @@ namespace Ink_Canvas.Helpers { // 释放之前的帧 _currentFrame?.Dispose(); - + // 创建新的位图,避免Clone的问题 var sourceFrame = eventArgs.Frame; - + if (sourceFrame != null) { try { var width = sourceFrame.Width; var height = sourceFrame.Height; - - if (width > 0 && height > 0) - { - // 应用旋转 - Bitmap rotatedFrame = ApplyRotation(sourceFrame); - - // 应用分辨率调整 - _currentFrame = ResizeImage(rotatedFrame, _resolutionWidth, _resolutionHeight); - - rotatedFrame?.Dispose(); - } + + if (width > 0 && height > 0) + { + // 应用旋转 + Bitmap rotatedFrame = ApplyRotation(sourceFrame); + + // 应用分辨率调整 + _currentFrame = ResizeImage(rotatedFrame, _resolutionWidth, _resolutionHeight); + + rotatedFrame?.Dispose(); + } else { _currentFrame = null; @@ -379,7 +379,7 @@ namespace Ink_Canvas.Helpers public void Dispose() { StopPreview(); - + lock (_frameLock) { _currentFrame?.Dispose(); diff --git a/Ink Canvas/Helpers/FileAssociationManager.cs b/Ink Canvas/Helpers/FileAssociationManager.cs index 89525e93..4eb2ccaf 100644 --- a/Ink Canvas/Helpers/FileAssociationManager.cs +++ b/Ink Canvas/Helpers/FileAssociationManager.cs @@ -419,7 +419,7 @@ namespace Ink_Canvas.Helpers try { string tempDir = Path.GetTempPath(); - + // 处理文件路径IPC文件 string[] ipcFiles = Directory.GetFiles(tempDir, IpcFilePrefix + "*.tmp"); foreach (string ipcFile in ipcFiles) diff --git a/Ink Canvas/Helpers/FloatingWindowInterceptor.cs b/Ink Canvas/Helpers/FloatingWindowInterceptor.cs index 1e0e9d10..ec745625 100644 --- a/Ink Canvas/Helpers/FloatingWindowInterceptor.cs +++ b/Ink Canvas/Helpers/FloatingWindowInterceptor.cs @@ -242,7 +242,7 @@ namespace Ink_Canvas.Helpers public string Description { get; set; } public InterceptType? ParentType { get; set; } public List ChildTypes { get; set; } = new List(); - + // 新增的精确匹配字段 public bool HasWindowStyle { get; set; } public uint WindowStyle { get; set; } @@ -251,7 +251,7 @@ namespace Ink_Canvas.Helpers public int WindowHeight { get; set; } public bool ExactTitleMatch { get; set; } = false; public bool ExactClassNameMatch { get; set; } = false; - + // 运行时状态字段 public bool foundHwnd { get; set; } = false; public IntPtr outHwnd { get; set; } = IntPtr.Zero; @@ -267,7 +267,7 @@ namespace Ink_Canvas.Helpers private readonly Dispatcher _dispatcher; private bool _isRunning; private bool _disposed; - + // 简化的性能统计 private int _consecutiveEmptyScans = 0; private DateTime _lastSuccessfulScan = DateTime.Now; @@ -466,15 +466,15 @@ namespace Ink_Canvas.Helpers RequiresAdmin = true, Description = "畅言智慧课堂 主栏悬浮窗", ParentType = null, - ChildTypes = new List - { - InterceptType.ChangYanBrushSettings, - InterceptType.ChangYanSwipeClear, - InterceptType.ChangYanInteraction, - InterceptType.ChangYanSubjectApp, - InterceptType.ChangYanControl, - InterceptType.ChangYanCommonTools, - InterceptType.ChangYanSceneToolbar, + ChildTypes = new List + { + InterceptType.ChangYanBrushSettings, + InterceptType.ChangYanSwipeClear, + InterceptType.ChangYanInteraction, + InterceptType.ChangYanSubjectApp, + InterceptType.ChangYanControl, + InterceptType.ChangYanCommonTools, + InterceptType.ChangYanSceneToolbar, InterceptType.ChangYanDrawWindow } }; @@ -713,7 +713,7 @@ namespace Ink_Canvas.Helpers if (_isRunning) return; _isRunning = true; - _scanTimer.Change(0, Math.Max(scanIntervalMs, 2000)); + _scanTimer.Change(0, Math.Max(scanIntervalMs, 2000)); } /// @@ -725,7 +725,7 @@ namespace Ink_Canvas.Helpers _isRunning = false; _scanTimer.Change(Timeout.Infinite, Timeout.Infinite); - + // 恢复所有被拦截的窗口 RestoreAllWindows(); } @@ -774,9 +774,9 @@ namespace Ink_Canvas.Helpers { var parentRule = _interceptRules[rule.ParentType.Value]; // 检查是否还有其他启用的子规则 - bool hasEnabledChildren = parentRule.ChildTypes.Any(childType => + bool hasEnabledChildren = parentRule.ChildTypes.Any(childType => _interceptRules.ContainsKey(childType) && _interceptRules[childType].IsEnabled); - + // 如果没有启用的子规则,则禁用父规则 if (!hasEnabledChildren) { @@ -831,7 +831,7 @@ namespace Ink_Canvas.Helpers { var windowsToRestore = new List(_interceptedWindows.Keys); var restoredCount = 0; - + foreach (var hWnd in windowsToRestore) { if (RestoreWindow(hWnd)) @@ -839,7 +839,7 @@ namespace Ink_Canvas.Helpers restoredCount++; } } - + } /// @@ -864,7 +864,7 @@ namespace Ink_Canvas.Helpers restoredCount++; } } - + } /// @@ -875,22 +875,22 @@ namespace Ink_Canvas.Helpers if (!_interceptedWindows.ContainsKey(hWnd)) return false; var interceptType = _interceptedWindows[hWnd]; - + if (IsWindow(hWnd)) { // 使用多种方法确保窗口恢复显示 ShowWindow(hWnd, SW_RESTORE); ShowWindow(hWnd, SW_SHOW); ShowWindow(hWnd, SW_SHOWNORMAL); - + // 将窗口置于前台并显示 - SetWindowPos(hWnd, IntPtr.Zero, 0, 0, 0, 0, + SetWindowPos(hWnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW); - + // 强制将窗口带到前台 BringWindowToTop(hWnd); SetForegroundWindow(hWnd); - + _interceptedWindows.Remove(hWnd); WindowRestored?.Invoke(this, new WindowRestoredEventArgs @@ -916,7 +916,7 @@ namespace Ink_Canvas.Helpers private void CleanupInvalidWindows() { var invalidWindows = new List(); - + foreach (var kvp in _interceptedWindows) { var hWnd = kvp.Key; @@ -940,7 +940,7 @@ namespace Ink_Canvas.Helpers // 简化的扫描逻辑 var interceptedCount = 0; CleanupInvalidWindows(); - + // 重置所有规则的发现状态 foreach (var rule in _interceptRules.Values) { @@ -958,9 +958,9 @@ namespace Ink_Canvas.Helpers { if (rule.IsEnabled && rule.foundHwnd && rule.outHwnd != IntPtr.Zero) { - bool shouldIntercept = !_interceptedWindows.ContainsKey(rule.outHwnd) || + bool shouldIntercept = !_interceptedWindows.ContainsKey(rule.outHwnd) || (_interceptedWindows.ContainsKey(rule.outHwnd) && IsWindowVisible(rule.outHwnd)); - + if (shouldIntercept) { InterceptWindow(rule.outHwnd, rule); @@ -1068,7 +1068,7 @@ namespace Ink_Canvas.Helpers var className = new StringBuilder(256); GetClassName(hWnd, className, className.Capacity); var classNameStr = className.ToString(); - + if (rule.ExactClassNameMatch) { if (!classNameStr.Equals(rule.ClassNamePattern, StringComparison.OrdinalIgnoreCase)) @@ -1087,7 +1087,7 @@ namespace Ink_Canvas.Helpers var windowTitle = new StringBuilder(256); GetWindowText(hWnd, windowTitle, windowTitle.Capacity); var titleStr = windowTitle.ToString(); - + if (rule.ExactTitleMatch) { if (!titleStr.Equals(rule.WindowTitlePattern, StringComparison.OrdinalIgnoreCase)) @@ -1126,7 +1126,7 @@ namespace Ink_Canvas.Helpers var horizontalDPI = GetDeviceCaps(hdc, LOGPIXELSX); var verticalDPI = GetDeviceCaps(hdc, LOGPIXELSY); ReleaseDC(IntPtr.Zero, hdc); - + var scale = (horizontalDPI + verticalDPI) / 2.0f / 96.0f; var scaledWidth = (int)(rule.WindowWidth * scale); var scaledHeight = (int)(rule.WindowHeight * scale); @@ -1164,10 +1164,10 @@ namespace Ink_Canvas.Helpers } return; } - + // 直接隐藏窗口,不发送关闭消息 ShowWindow(hWnd, SW_HIDE); - + // 记录拦截的窗口 _interceptedWindows[hWnd] = rule.Type; diff --git a/Ink Canvas/Helpers/GlobalHotkeyManager.cs b/Ink Canvas/Helpers/GlobalHotkeyManager.cs index 917ee3f8..15394752 100644 --- a/Ink Canvas/Helpers/GlobalHotkeyManager.cs +++ b/Ink Canvas/Helpers/GlobalHotkeyManager.cs @@ -6,8 +6,8 @@ using System.IO; using System.Reflection; using System.Text; using System.Windows; -using System.Windows.Input; using System.Windows.Forms; +using System.Windows.Input; namespace Ink_Canvas.Helpers { @@ -21,12 +21,12 @@ namespace Ink_Canvas.Helpers private readonly MainWindow _mainWindow; private bool _isDisposed; private bool _hotkeysShouldBeRegistered = true; // 启动时注册热键 - + // 多屏幕支持相关字段 private Screen _currentScreen; private bool _isMultiScreenMode = false; private bool _enableScreenSpecificHotkeys = true; // 是否启用基于屏幕的热键注册 - + // 智能热键管理相关字段 private bool _isWindowFocused = false; private bool _isMouseOverWindow = false; @@ -42,10 +42,10 @@ namespace Ink_Canvas.Helpers _mainWindow = mainWindow ?? throw new ArgumentNullException(nameof(mainWindow)); _registeredHotkeys = new Dictionary(); _hotkeysShouldBeRegistered = true; // 启动时注册热键 - + // 初始化多屏幕支持 InitializeMultiScreenSupport(); - + // 启动时确保配置文件存在 EnsureConfigFileExists(); } @@ -106,10 +106,10 @@ namespace Ink_Canvas.Helpers }); _registeredHotkeys[hotkeyName] = hotkeyInfo; - + // 记录注册信息 var screenInfo = _isMultiScreenMode ? $" (屏幕: {_currentScreen?.DeviceName})" : ""; - + return true; } catch (Exception ex) @@ -506,7 +506,7 @@ namespace Ink_Canvas.Helpers try { _enableScreenSpecificHotkeys = true; - + // 如果当前在多屏幕环境下,刷新热键注册 if (_isMultiScreenMode) { @@ -527,7 +527,7 @@ namespace Ink_Canvas.Helpers try { _enableScreenSpecificHotkeys = false; - + // 重新注册热键(全局模式) if (_hotkeysShouldBeRegistered) { @@ -599,15 +599,15 @@ namespace Ink_Canvas.Helpers { // 检测是否有多个屏幕 _isMultiScreenMode = ScreenDetectionHelper.HasMultipleScreens(); - + if (_isMultiScreenMode) { // 获取当前窗口所在的屏幕 _currentScreen = ScreenDetectionHelper.GetWindowScreen(_mainWindow); - + // 监听窗口位置变化事件 _mainWindow.LocationChanged += OnWindowLocationChanged; - + // 初始化智能热键管理 InitializeSmartHotkeyManagement(); } @@ -634,16 +634,16 @@ namespace Ink_Canvas.Helpers // 监听窗口焦点事件 _mainWindow.GotFocus += OnWindowGotFocus; _mainWindow.LostFocus += OnWindowLostFocus; - + // 监听鼠标进入/离开事件 _mainWindow.MouseEnter += OnMouseEnterWindow; _mainWindow.MouseLeave += OnMouseLeaveWindow; - + // 初始化鼠标位置监控定时器 _mousePositionTimer = new System.Windows.Threading.DispatcherTimer(); _mousePositionTimer.Interval = TimeSpan.FromMilliseconds(500); // 每500ms检查一次 _mousePositionTimer.Tick += OnMousePositionTimerTick; - + } catch (Exception ex) { @@ -665,7 +665,7 @@ namespace Ink_Canvas.Helpers if (newScreen != null && newScreen != _currentScreen) { _currentScreen = newScreen; - + // 重新注册热键以适应新屏幕 RefreshHotkeysForCurrentScreen(); } @@ -691,7 +691,7 @@ namespace Ink_Canvas.Helpers // 重新注册热键 LoadHotkeysFromSettings(); - + } catch (Exception ex) { @@ -776,12 +776,12 @@ namespace Ink_Canvas.Helpers // 检查鼠标是否在当前窗口所在的屏幕上 var mousePosition = Control.MousePosition; var currentScreen = Screen.FromPoint(mousePosition); - + // 无论屏幕是否变化,都检查热键状态 // 这样可以确保热键状态始终与当前上下文保持一致 bool shouldEnableHotkeys = ShouldEnableHotkeysBasedOnContext(); bool currentlyHasHotkeys = _registeredHotkeys.Count > 0; - + if (shouldEnableHotkeys && !currentlyHasHotkeys) { UpdateHotkeyStateBasedOnContext(); @@ -808,7 +808,7 @@ namespace Ink_Canvas.Helpers return; bool shouldEnableHotkeys = ShouldEnableHotkeysBasedOnContext(); - + if (shouldEnableHotkeys) { // 如果热键未注册,则注册 @@ -823,7 +823,7 @@ namespace Ink_Canvas.Helpers if (_registeredHotkeys.Count > 0) { UnregisterAllHotkeys(); - + // 注意:这里不设置 _hotkeysShouldBeRegistered = false // 因为我们需要保持热键系统的启用状态,只是暂时注销热键 // 这样当上下文变化时,热键可以重新注册 @@ -882,7 +882,7 @@ namespace Ink_Canvas.Helpers { var mousePosition = Control.MousePosition; var mouseScreen = Screen.FromPoint(mousePosition); - + if (mouseScreen == _currentScreen) { return true; @@ -1344,14 +1344,14 @@ namespace Ink_Canvas.Helpers { // 注销所有快捷键 UnregisterAllHotkeys(); - + // 停止定时器 if (_mousePositionTimer != null) { _mousePositionTimer.Stop(); _mousePositionTimer = null; } - + // 移除事件监听器 if (_mainWindow != null) { @@ -1359,7 +1359,7 @@ namespace Ink_Canvas.Helpers { _mainWindow.LocationChanged -= OnWindowLocationChanged; } - + _mainWindow.GotFocus -= OnWindowGotFocus; _mainWindow.LostFocus -= OnWindowLostFocus; _mainWindow.MouseEnter -= OnMouseEnterWindow; diff --git a/Ink Canvas/Helpers/InkSmoothingConfig.cs b/Ink Canvas/Helpers/InkSmoothingConfig.cs index c1af933d..06bc2b0f 100644 --- a/Ink Canvas/Helpers/InkSmoothingConfig.cs +++ b/Ink Canvas/Helpers/InkSmoothingConfig.cs @@ -77,40 +77,40 @@ namespace Ink_Canvas.Helpers { // 保存用户设置的异步处理偏好 bool userAsyncPreference = UseAsyncProcessing; - + switch (Quality) { case SmoothingQuality.Performance: - SmoothingStrength = 0.15; - ResampleInterval = 5.0; - InterpolationSteps = 4; + SmoothingStrength = 0.15; + ResampleInterval = 5.0; + InterpolationSteps = 4; UseAdaptiveInterpolation = false; - CurveTension = 0.15; + CurveTension = 0.15; MaxConcurrentTasks = Math.Max(1, Environment.ProcessorCount / 2); - UseHardwareAcceleration = true; - UseAsyncProcessing = userAsyncPreference; + UseHardwareAcceleration = true; + UseAsyncProcessing = userAsyncPreference; break; case SmoothingQuality.Balanced: - SmoothingStrength = 0.3; - ResampleInterval = 3.0; - InterpolationSteps = 8; + SmoothingStrength = 0.3; + ResampleInterval = 3.0; + InterpolationSteps = 8; UseAdaptiveInterpolation = true; - CurveTension = 0.25; + CurveTension = 0.25; MaxConcurrentTasks = Environment.ProcessorCount; UseHardwareAcceleration = true; - UseAsyncProcessing = userAsyncPreference; + UseAsyncProcessing = userAsyncPreference; break; case SmoothingQuality.Quality: - SmoothingStrength = 0.5; - ResampleInterval = 2.0; - InterpolationSteps = 15; + SmoothingStrength = 0.5; + ResampleInterval = 2.0; + InterpolationSteps = 15; UseAdaptiveInterpolation = true; - CurveTension = 0.35; + CurveTension = 0.35; MaxConcurrentTasks = Environment.ProcessorCount; UseHardwareAcceleration = true; - UseAsyncProcessing = userAsyncPreference; + UseAsyncProcessing = userAsyncPreference; break; } } diff --git a/Ink Canvas/Helpers/MultiPPTInkManager.cs b/Ink Canvas/Helpers/MultiPPTInkManager.cs index ec491824..02d70da2 100644 --- a/Ink Canvas/Helpers/MultiPPTInkManager.cs +++ b/Ink Canvas/Helpers/MultiPPTInkManager.cs @@ -26,7 +26,7 @@ namespace Ink_Canvas.Helpers private readonly object _lockObject = new object(); private bool _disposed; private string _currentActivePresentationId = ""; - + // 墨迹备份机制 private readonly Dictionary> _strokeBackups; private DateTime _lastBackupTime = DateTime.MinValue; @@ -55,7 +55,7 @@ namespace Ink_Canvas.Helpers try { var presentationId = GeneratePresentationId(presentation); - + // 如果已存在该演示文稿的管理器,先清理 if (_presentationManagers.ContainsKey(presentationId)) { @@ -104,11 +104,11 @@ namespace Ink_Canvas.Helpers try { var presentationId = GeneratePresentationId(presentation); - + if (_presentationManagers.ContainsKey(presentationId)) { // 如果切换的是不同的演示文稿,先保存当前活跃演示文稿的墨迹 - if (!string.IsNullOrEmpty(_currentActivePresentationId) && + if (!string.IsNullOrEmpty(_currentActivePresentationId) && _currentActivePresentationId != presentationId) { var currentManager = GetCurrentManager(); @@ -132,7 +132,7 @@ namespace Ink_Canvas.Helpers } _currentActivePresentationId = presentationId; - + // 更新最后访问时间 if (_presentationInfos.ContainsKey(presentationId)) { @@ -176,13 +176,13 @@ namespace Ink_Canvas.Helpers { // 保存到管理器 manager.SaveCurrentSlideStrokes(slideIndex, strokes); - + // 只有在保存成功后才创建备份 if (!string.IsNullOrEmpty(_currentActivePresentationId)) { CreateStrokeBackup(_currentActivePresentationId, slideIndex, strokes); } - + // 检查是否需要执行定期备份 CheckAndPerformBackup(); } @@ -233,7 +233,7 @@ namespace Ink_Canvas.Helpers if (manager != null) { var strokes = manager.LoadSlideStrokes(slideIndex); - + // 如果从管理器加载失败,尝试从备份恢复 if (strokes == null || strokes.Count == 0) { @@ -242,14 +242,14 @@ namespace Ink_Canvas.Helpers strokes = RestoreStrokeFromBackup(_currentActivePresentationId, slideIndex); } } - + return strokes ?? new StrokeCollection(); } } catch (Exception ex) { LogHelper.WriteLogToFile($"加载页面墨迹失败: {ex}", LogHelper.LogType.Error); - + // 尝试从备份恢复 if (!string.IsNullOrEmpty(_currentActivePresentationId)) { @@ -464,12 +464,12 @@ namespace Ink_Canvas.Helpers try { var presentationId = GeneratePresentationId(presentation); - + if (_presentationManagers.ContainsKey(presentationId)) { // 保存墨迹到文件 _presentationManagers[presentationId].SaveAllStrokesToFile(presentation); - + // 释放资源 _presentationManagers[presentationId].Dispose(); _presentationManagers.Remove(presentationId); @@ -550,13 +550,13 @@ namespace Ink_Canvas.Helpers _presentationManagers.Remove(id); } _presentationInfos.Remove(id); - + // 清理备份数据 if (_strokeBackups.ContainsKey(id)) { _strokeBackups.Remove(id); } - + LogHelper.WriteLogToFile($"已清理非活跃演示文稿: {id}", LogHelper.LogType.Trace); } } @@ -589,7 +589,7 @@ namespace Ink_Canvas.Helpers // 创建新的备份 _strokeBackups[presentationId][slideIndex] = strokes.Clone(); - + } catch (Exception ex) { @@ -604,7 +604,7 @@ namespace Ink_Canvas.Helpers { try { - if (_strokeBackups.ContainsKey(presentationId) && + if (_strokeBackups.ContainsKey(presentationId) && _strokeBackups[presentationId].ContainsKey(slideIndex)) { var backup = _strokeBackups[presentationId][slideIndex]; @@ -631,7 +631,7 @@ namespace Ink_Canvas.Helpers try { var now = DateTime.Now; - + // 检查是否需要执行备份 if (now - _lastBackupTime < TimeSpan.FromMinutes(BackupIntervalMinutes)) { @@ -639,7 +639,7 @@ namespace Ink_Canvas.Helpers } // 备份当前活跃演示文稿的所有墨迹 - if (!string.IsNullOrEmpty(_currentActivePresentationId) && + if (!string.IsNullOrEmpty(_currentActivePresentationId) && _presentationManagers.ContainsKey(_currentActivePresentationId)) { var manager = _presentationManagers[_currentActivePresentationId]; @@ -661,7 +661,7 @@ namespace Ink_Canvas.Helpers #region Private Methods private PPTInkManager GetCurrentManager() { - if (string.IsNullOrEmpty(_currentActivePresentationId) || + if (string.IsNullOrEmpty(_currentActivePresentationId) || !_presentationManagers.ContainsKey(_currentActivePresentationId)) { return null; @@ -780,7 +780,7 @@ namespace Ink_Canvas.Helpers } _presentationManagers.Clear(); _presentationInfos.Clear(); - + // 清理备份数据 foreach (var backupDict in _strokeBackups.Values) { diff --git a/Ink Canvas/Helpers/MultiTouchInput.cs b/Ink Canvas/Helpers/MultiTouchInput.cs index 9764d2ca..33219c5f 100644 --- a/Ink Canvas/Helpers/MultiTouchInput.cs +++ b/Ink Canvas/Helpers/MultiTouchInput.cs @@ -31,7 +31,7 @@ namespace Ink_Canvas.Helpers { private bool _needsRedraw = true; private int _lastPointCount = 0; - private const int REDRAW_THRESHOLD = 3; + private const int REDRAW_THRESHOLD = 3; /// /// 创建显示笔迹的类 @@ -53,7 +53,7 @@ namespace Ink_Canvas.Helpers public StrokeVisual(DrawingAttributes drawingAttributes) { _drawingAttributes = drawingAttributes; - + // 启用硬件加速 RenderOptions.SetBitmapScalingMode(this, BitmapScalingMode.HighQuality); RenderOptions.SetEdgeMode(this, EdgeMode.Aliased); @@ -82,7 +82,7 @@ namespace Ink_Canvas.Helpers Stroke.StylusPoints.Add(point); _lastPointCount++; } - + // 标记需要重绘 _needsRedraw = true; } @@ -93,7 +93,7 @@ namespace Ink_Canvas.Helpers public void Redraw() { if (!_needsRedraw || Stroke == null) return; - + if (_lastPointCount % REDRAW_THRESHOLD != 0 && _lastPointCount > REDRAW_THRESHOLD) { return; diff --git a/Ink Canvas/Helpers/PPTInkManager.cs b/Ink Canvas/Helpers/PPTInkManager.cs index 2fee446c..cad06029 100644 --- a/Ink Canvas/Helpers/PPTInkManager.cs +++ b/Ink Canvas/Helpers/PPTInkManager.cs @@ -30,12 +30,12 @@ namespace Ink_Canvas.Helpers private DateTime _inkLockUntil = DateTime.MinValue; private int _lockedSlideIndex = -1; private const int InkLockMilliseconds = 500; - + // 添加快速切换保护机制 private DateTime _lastSwitchTime = DateTime.MinValue; private int _lastSwitchSlideIndex = -1; private const int MinSwitchIntervalMs = 100; // 最小切换间隔100毫秒 - + // 内存管理相关字段 private long _totalMemoryUsage = 0; private const long MaxMemoryUsageBytes = 100 * 1024 * 1024; // 100MB限制 @@ -90,7 +90,7 @@ namespace Ink_Canvas.Helpers { return; } - throw; + throw; } _memoryStreams = new MemoryStream[slideCount + 2]; @@ -238,7 +238,7 @@ namespace Ink_Canvas.Helpers { // 检查快速切换保护 var now = DateTime.Now; - if (now - _lastSwitchTime < TimeSpan.FromMilliseconds(MinSwitchIntervalMs) && + if (now - _lastSwitchTime < TimeSpan.FromMilliseconds(MinSwitchIntervalMs) && _lastSwitchSlideIndex == slideIndex) { LogHelper.WriteLogToFile($"快速切换保护:忽略重复的页面切换请求 {slideIndex}", LogHelper.LogType.Warning); @@ -251,11 +251,11 @@ namespace Ink_Canvas.Helpers // 加载新页面的墨迹 var newStrokes = LoadSlideStrokes(slideIndex); - + // 更新切换记录 _lastSwitchTime = now; _lastSwitchSlideIndex = slideIndex; - + if (newStrokes.Count > 0) { } @@ -300,7 +300,7 @@ namespace Ink_Canvas.Helpers // 保存所有页面的墨迹 int savedCount = 0; int slideCount = 0; - + try { slideCount = presentation.Slides.Count; @@ -308,13 +308,13 @@ namespace Ink_Canvas.Helpers catch (COMException comEx) { var hr = (uint)comEx.HResult; - if (hr == 0x80048010) + if (hr == 0x80048010) { return; } - throw; + throw; } - + for (int i = 1; i <= slideCount && i < _memoryStreams.Length; i++) { if (_memoryStreams[i] != null) @@ -430,7 +430,7 @@ namespace Ink_Canvas.Helpers _memoryStreams[i] = null; } } - + // 重新初始化数组 _memoryStreams = new MemoryStream[_maxSlides + 2]; } @@ -464,20 +464,20 @@ namespace Ink_Canvas.Helpers { return true; } - + // 如果当前页面与锁定页面相同,允许写入(用户在当前页面绘制) if (currentSlideIndex == _lockedSlideIndex) { return true; } - + // 如果当前页面不是锁定页面,但锁定时间很短(小于50ms),允许写入 // 这样可以确保旧页面的墨迹能够及时保存 if (DateTime.Now - (_inkLockUntil.AddMilliseconds(-InkLockMilliseconds)) < TimeSpan.FromMilliseconds(50)) { return true; } - + // 只有在快速切换且页面不同时才锁定 return false; } @@ -504,7 +504,7 @@ namespace Ink_Canvas.Helpers try { var now = DateTime.Now; - + // 检查是否需要执行内存清理 if (now - _lastMemoryCleanup < TimeSpan.FromMinutes(MemoryCleanupIntervalMinutes)) { @@ -530,10 +530,10 @@ namespace Ink_Canvas.Helpers if (currentMemoryUsage > MaxMemoryUsageBytes) { LogHelper.WriteLogToFile($"内存使用量超限 ({currentMemoryUsage / 1024 / 1024}MB),开始清理", LogHelper.LogType.Warning); - + // 清理非当前页面的墨迹 CleanupInactiveSlideStrokes(); - + _lastMemoryCleanup = now; LogHelper.WriteLogToFile($"内存清理完成,当前使用量: {_totalMemoryUsage / 1024 / 1024}MB", LogHelper.LogType.Trace); } @@ -571,7 +571,7 @@ namespace Ink_Canvas.Helpers if (_memoryStreams[i] != null) { long memorySize = _memoryStreams[i].Length; - + try { _memoryStreams[i].Dispose(); diff --git a/Ink Canvas/Helpers/PPTUIManager.cs b/Ink Canvas/Helpers/PPTUIManager.cs index dc5c2b86..1c65e9ef 100644 --- a/Ink Canvas/Helpers/PPTUIManager.cs +++ b/Ink Canvas/Helpers/PPTUIManager.cs @@ -104,8 +104,8 @@ namespace Ink_Canvas.Helpers _dispatcher.BeginInvoke(new Action(() => { MainWindow.MoveWindow(new WindowInteropHelper(_mainWindow).Handle, 0, 0, - System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, - System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height, true); + System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, + System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height, true); }), DispatcherPriority.ApplicationIdle); } } @@ -118,12 +118,12 @@ namespace Ink_Canvas.Helpers { // 恢复为非画板模式,重新启用全屏限制 AvoidFullScreenHelper.SetBoardMode(false); - + _dispatcher.BeginInvoke(new Action(() => { // 退出PPT放映模式,恢复到工作区域大小 var workingArea = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea; - MainWindow.MoveWindow(new WindowInteropHelper(_mainWindow).Handle, + MainWindow.MoveWindow(new WindowInteropHelper(_mainWindow).Handle, workingArea.X, workingArea.Y, workingArea.Width, workingArea.Height, true); }), DispatcherPriority.ApplicationIdle); diff --git a/Ink Canvas/Helpers/ScreenDetectionHelper.cs b/Ink Canvas/Helpers/ScreenDetectionHelper.cs index 5d048a7f..52c0c477 100644 --- a/Ink Canvas/Helpers/ScreenDetectionHelper.cs +++ b/Ink Canvas/Helpers/ScreenDetectionHelper.cs @@ -31,7 +31,7 @@ namespace Ink_Canvas.Helpers // 获取窗口在屏幕上的位置 var windowRect = GetWindowScreenBounds(window); - + // 查找与窗口重叠最多的屏幕 Screen targetScreen = null; double maxIntersection = 0; @@ -66,10 +66,10 @@ namespace Ink_Canvas.Helpers { // 获取窗口左上角在屏幕上的位置 var topLeft = window.PointToScreen(new Point(0, 0)); - + // 获取窗口右下角在屏幕上的位置 var bottomRight = window.PointToScreen(new Point(window.ActualWidth, window.ActualHeight)); - + return new Rectangle( (int)topLeft.X, (int)topLeft.Y, diff --git a/Ink Canvas/MainWindow.xaml.cs b/Ink Canvas/MainWindow.xaml.cs index 8ca6fb60..79c2e7da 100644 --- a/Ink Canvas/MainWindow.xaml.cs +++ b/Ink Canvas/MainWindow.xaml.cs @@ -391,7 +391,7 @@ namespace Ink_Canvas //加载设置 LoadSettings(true); AutoBackupManager.Initialize(Settings); - + // 检查保存路径是否可用,不可用则修正 try { @@ -549,7 +549,7 @@ namespace Ink_Canvas ApplyNoFocusMode(); ToggleSwitchAlwaysOnTop.IsOn = Settings.Advanced.IsAlwaysOnTop; ApplyAlwaysOnTop(); - + // 初始化剪贴板监控 InitializeClipboardMonitoring(); @@ -2696,7 +2696,7 @@ namespace Ink_Canvas if (toggle != null) { Settings.ModeSettings.IsPPTOnlyMode = toggle.IsOn; - + // 保存设置到文件 SaveSettingsToFile(); @@ -2788,20 +2788,20 @@ namespace Ink_Canvas private void ComboBoxTheme_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (!isLoaded) return; - + try { System.Windows.Controls.ComboBox comboBox = sender as System.Windows.Controls.ComboBox; if (comboBox != null) { Settings.Appearance.Theme = comboBox.SelectedIndex; - + // 应用新主题 ApplyTheme(comboBox.SelectedIndex); - + // 保存设置 SaveSettingsToFile(); - + // 显示通知 string themeName; switch (comboBox.SelectedIndex) @@ -2819,7 +2819,7 @@ namespace Ink_Canvas themeName = "未知主题"; break; } - + ShowNotification($"已切换到{themeName}"); } } @@ -2863,7 +2863,7 @@ namespace Ink_Canvas } break; } - + // 强制刷新通知框的颜色资源 RefreshNotificationColors(); } @@ -2872,7 +2872,7 @@ namespace Ink_Canvas LogHelper.WriteLogToFile($"应用主题时出错: {ex.Message}", LogHelper.LogType.Error); } } - + /// /// 刷新通知框的颜色资源 /// @@ -2887,7 +2887,7 @@ namespace Ink_Canvas border.Background = (Brush)Application.Current.FindResource("SettingsPageBackground"); border.BorderBrush = new SolidColorBrush(Color.FromRgb(185, 28, 28)); // 保持红色边框 } - + TextBlockNotice.Foreground = (Brush)Application.Current.FindResource("SettingsPageForeground"); } catch (Exception ex) diff --git a/Ink Canvas/MainWindow_cs/MW_AutoTheme.cs b/Ink Canvas/MainWindow_cs/MW_AutoTheme.cs index a797d793..adcf5cad 100644 --- a/Ink Canvas/MainWindow_cs/MW_AutoTheme.cs +++ b/Ink Canvas/MainWindow_cs/MW_AutoTheme.cs @@ -18,14 +18,14 @@ namespace Ink_Canvas var resourcesToRemove = new List(); foreach (var dict in Application.Current.Resources.MergedDictionaries) { - if (dict.Source != null && - (dict.Source.ToString().Contains("Light.xaml") || + if (dict.Source != null && + (dict.Source.ToString().Contains("Light.xaml") || dict.Source.ToString().Contains("Dark.xaml"))) { resourcesToRemove.Add(dict); } } - + foreach (var dict in resourcesToRemove) { Application.Current.Resources.MergedDictionaries.Remove(dict); @@ -36,7 +36,7 @@ namespace Ink_Canvas var rd1 = new ResourceDictionary { Source = new Uri("Resources/Styles/Light.xaml", UriKind.Relative) }; Application.Current.Resources.MergedDictionaries.Add(rd1); - + // 在主题资源之后添加其他资源 var rd2 = new ResourceDictionary { Source = new Uri("Resources/DrawShapeImageDictionary.xaml", UriKind.Relative) }; @@ -53,10 +53,10 @@ namespace Ink_Canvas ThemeManager.SetRequestedTheme(window, ElementTheme.Light); InitializeFloatBarForegroundColor(); - + // 刷新快速面板图标 RefreshQuickPanelIcons(); - + // 强制刷新UI window.InvalidateVisual(); } @@ -64,7 +64,7 @@ namespace Ink_Canvas { var rd1 = new ResourceDictionary { Source = new Uri("Resources/Styles/Dark.xaml", UriKind.Relative) }; Application.Current.Resources.MergedDictionaries.Add(rd1); - + // 在主题资源之后添加其他资源 var rd2 = new ResourceDictionary { Source = new Uri("Resources/DrawShapeImageDictionary.xaml", UriKind.Relative) }; @@ -81,10 +81,10 @@ namespace Ink_Canvas ThemeManager.SetRequestedTheme(window, ElementTheme.Dark); InitializeFloatBarForegroundColor(); - + // 刷新快速面板图标 RefreshQuickPanelIcons(); - + // 强制刷新UI window.InvalidateVisual(); } @@ -98,17 +98,17 @@ namespace Ink_Canvas try { FloatBarForegroundColor = (Color)Application.Current.FindResource("FloatBarForegroundColor"); - + // 强制刷新浮动工具栏按钮颜色 RefreshFloatingBarButtonColors(); } catch (Exception) { // 如果无法从资源中加载,使用默认颜色 - FloatBarForegroundColor = Color.FromRgb(0, 0, 0); + FloatBarForegroundColor = Color.FromRgb(0, 0, 0); } } - + /// /// 刷新快速面板图标 /// @@ -147,7 +147,7 @@ namespace Ink_Canvas { // 选中状态的颜色(蓝底) var selectedColor = Color.FromRgb(30, 58, 138); - + // 根据当前模式设置按钮颜色 switch (_currentToolMode) { diff --git a/Ink Canvas/MainWindow_cs/MW_BoardControls.cs b/Ink Canvas/MainWindow_cs/MW_BoardControls.cs index e4262503..e315fbf5 100644 --- a/Ink Canvas/MainWindow_cs/MW_BoardControls.cs +++ b/Ink Canvas/MainWindow_cs/MW_BoardControls.cs @@ -17,8 +17,8 @@ namespace Ink_Canvas private StrokeCollection lastTouchDownStrokeCollection = new StrokeCollection(); private int CurrentWhiteboardIndex = 1; private int WhiteboardTotalCount = 1; - private TimeMachineHistory[][] TimeMachineHistories = new TimeMachineHistory[101][]; - private bool[] savedMultiTouchModeStates = new bool[101]; + private TimeMachineHistory[][] TimeMachineHistories = new TimeMachineHistory[101][]; + private bool[] savedMultiTouchModeStates = new bool[101]; // 保存每页白板图片信息 private void SaveStrokes(bool isBackupMain = false) @@ -197,20 +197,20 @@ namespace Ink_Canvas { // 恢复多指书写模式 EnterMultiTouchModeIfNeeded(); - + // 更新UI状态 if (ToggleSwitchEnableMultiTouchMode != null) { ToggleSwitchEnableMultiTouchMode.IsOn = true; } - + LogHelper.WriteLogToFile($"恢复多指书写模式状态 - 页面索引: {pageIndex}", LogHelper.LogType.Info); } else { // 确保多指书写模式关闭 ExitMultiTouchModeIfNeeded(); - + // 更新UI状态 if (ToggleSwitchEnableMultiTouchMode != null) { diff --git a/Ink Canvas/MainWindow_cs/MW_ElementsControls.cs b/Ink Canvas/MainWindow_cs/MW_ElementsControls.cs index ac6b6b0e..5a723a76 100644 --- a/Ink Canvas/MainWindow_cs/MW_ElementsControls.cs +++ b/Ink Canvas/MainWindow_cs/MW_ElementsControls.cs @@ -1585,7 +1585,7 @@ namespace Ink_Canvas { isResizingImage = true; imageResizeStartPoint = e.GetPosition(inkCanvas); - + // 确定是哪个控制点 activeResizeHandle = ellipse.Name; diff --git a/Ink Canvas/MainWindow_cs/MW_Eraser.cs b/Ink Canvas/MainWindow_cs/MW_Eraser.cs index e5d21a04..154729a0 100644 --- a/Ink Canvas/MainWindow_cs/MW_Eraser.cs +++ b/Ink Canvas/MainWindow_cs/MW_Eraser.cs @@ -1,5 +1,4 @@ -using Ink_Canvas.Helpers; -using System; +using System; using System.Diagnostics; using System.Linq; using System.Windows; @@ -46,29 +45,35 @@ namespace Ink_Canvas } // 绑定事件处理 - canvas.StylusDown += ((o, args) => { + canvas.StylusDown += ((o, args) => + { e.Handled = true; if (args.StylusDevice.TabletDevice.Type == TabletDeviceType.Stylus) canvas.CaptureStylus(); EraserOverlay_PointerDown(sender); }); - canvas.StylusUp += ((o, args) => { + canvas.StylusUp += ((o, args) => + { e.Handled = true; if (args.StylusDevice.TabletDevice.Type == TabletDeviceType.Stylus) canvas.ReleaseStylusCapture(); EraserOverlay_PointerUp(sender); }); - canvas.StylusMove += ((o, args) => { + canvas.StylusMove += ((o, args) => + { e.Handled = true; EraserOverlay_PointerMove(sender, args.GetPosition(inkCanvas)); }); - canvas.MouseDown += ((o, args) => { + canvas.MouseDown += ((o, args) => + { canvas.CaptureMouse(); EraserOverlay_PointerDown(sender); }); - canvas.MouseUp += ((o, args) => { + canvas.MouseUp += ((o, args) => + { canvas.ReleaseMouseCapture(); EraserOverlay_PointerUp(sender); }); - canvas.MouseMove += ((o, args) => { + canvas.MouseMove += ((o, args) => + { EraserOverlay_PointerMove(sender, args.GetPosition(inkCanvas)); }); @@ -86,7 +91,7 @@ namespace Ink_Canvas // 根据橡皮擦形状选择对应的图像资源 string resourceKey = isEraserCircleShape ? "EllipseEraserImageSource" : "RectangleEraserImageSource"; var imageSource = TryFindResource(resourceKey) as DrawingImage; - + if (imageSource != null) { eraserFeedback.Source = imageSource; @@ -301,8 +306,8 @@ namespace Ink_Canvas if (isEraserCircleShape) { eraserWidth = k * 90; // 圆形橡皮擦 - } - else + } + else { eraserWidth = k * 90 * 0.6; // 矩形橡皮擦宽度 } diff --git a/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs b/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs index f2d40ab7..8532e5c6 100644 --- a/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs +++ b/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs @@ -86,19 +86,19 @@ namespace Ink_Canvas // 根据主题设置颜色 if (Settings.Appearance.Theme == 1) // 深色主题 { - BoardGesture.Background = new SolidColorBrush(Color.FromRgb(42, 42, 42)); - BoardGestureGeometry.Brush = new SolidColorBrush(Color.FromRgb(255, 255, 255)); - BoardGestureGeometry2.Brush = new SolidColorBrush(Color.FromRgb(255, 255, 255)); - BoardGestureLabel.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255)); - BoardGesture.BorderBrush = new SolidColorBrush(Color.FromRgb(85, 85, 85)); + BoardGesture.Background = new SolidColorBrush(Color.FromRgb(42, 42, 42)); + BoardGestureGeometry.Brush = new SolidColorBrush(Color.FromRgb(255, 255, 255)); + BoardGestureGeometry2.Brush = new SolidColorBrush(Color.FromRgb(255, 255, 255)); + BoardGestureLabel.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255)); + BoardGesture.BorderBrush = new SolidColorBrush(Color.FromRgb(85, 85, 85)); } else // 浅色主题或跟随系统 { - BoardGesture.Background = new SolidColorBrush(Color.FromRgb(244, 244, 245)); - BoardGestureGeometry.Brush = new SolidColorBrush(Color.FromRgb(24, 24, 27)); - BoardGestureGeometry2.Brush = new SolidColorBrush(Color.FromRgb(24, 24, 27)); - BoardGestureLabel.Foreground = new SolidColorBrush(Color.FromRgb(24, 24, 27)); - BoardGesture.BorderBrush = new SolidColorBrush(Color.FromRgb(161, 161, 170)); + BoardGesture.Background = new SolidColorBrush(Color.FromRgb(244, 244, 245)); + BoardGestureGeometry.Brush = new SolidColorBrush(Color.FromRgb(24, 24, 27)); + BoardGestureGeometry2.Brush = new SolidColorBrush(Color.FromRgb(24, 24, 27)); + BoardGestureLabel.Foreground = new SolidColorBrush(Color.FromRgb(24, 24, 27)); + BoardGesture.BorderBrush = new SolidColorBrush(Color.FromRgb(161, 161, 170)); } BoardGestureGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.DisabledGestureIcon); BoardGestureGeometry2.Geometry = Geometry.Parse("F0 M24,24z M0,0z"); @@ -111,10 +111,10 @@ namespace Ink_Canvas // 多指书写模式禁用时,根据实际手势功能状态显示 TwoFingerGestureSimpleStackPanel.Opacity = 1; TwoFingerGestureSimpleStackPanel.IsHitTestVisible = true; - + // 检查是否有任何手势功能启用 bool hasGestureEnabled = Settings.Gesture.IsEnableTwoFingerGesture; - + if (hasGestureEnabled) { EnableTwoFingerGestureBtn.Source = @@ -136,19 +136,19 @@ namespace Ink_Canvas // 根据主题设置颜色 if (Settings.Appearance.Theme == 1) // 深色主题 { - BoardGesture.Background = new SolidColorBrush(Color.FromRgb(42, 42, 42)); - BoardGestureGeometry.Brush = new SolidColorBrush(Color.FromRgb(255, 255, 255)); - BoardGestureGeometry2.Brush = new SolidColorBrush(Color.FromRgb(255, 255, 255)); - BoardGestureLabel.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255)); - BoardGesture.BorderBrush = new SolidColorBrush(Color.FromRgb(85, 85, 85)); + BoardGesture.Background = new SolidColorBrush(Color.FromRgb(42, 42, 42)); + BoardGestureGeometry.Brush = new SolidColorBrush(Color.FromRgb(255, 255, 255)); + BoardGestureGeometry2.Brush = new SolidColorBrush(Color.FromRgb(255, 255, 255)); + BoardGestureLabel.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255)); + BoardGesture.BorderBrush = new SolidColorBrush(Color.FromRgb(85, 85, 85)); } else // 浅色主题或跟随系统 { BoardGesture.Background = new SolidColorBrush(Color.FromRgb(244, 244, 245)); - BoardGestureGeometry.Brush = new SolidColorBrush(Color.FromRgb(24, 24, 27)); - BoardGestureGeometry2.Brush = new SolidColorBrush(Color.FromRgb(24, 24, 27)); - BoardGestureLabel.Foreground = new SolidColorBrush(Color.FromRgb(24, 24, 27)); - BoardGesture.BorderBrush = new SolidColorBrush(Color.FromRgb(161, 161, 170)); + BoardGestureGeometry.Brush = new SolidColorBrush(Color.FromRgb(24, 24, 27)); + BoardGestureGeometry2.Brush = new SolidColorBrush(Color.FromRgb(24, 24, 27)); + BoardGestureLabel.Foreground = new SolidColorBrush(Color.FromRgb(24, 24, 27)); + BoardGesture.BorderBrush = new SolidColorBrush(Color.FromRgb(161, 161, 170)); } BoardGestureGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.DisabledGestureIcon); BoardGestureGeometry2.Geometry = Geometry.Parse("F0 M24,24z M0,0z"); @@ -443,33 +443,33 @@ namespace Ink_Canvas // 根据主题设置颜色 if (Settings.Appearance.Theme == 1) // 深色主题 { - BoardPen.Background = new SolidColorBrush(Color.FromRgb(42, 42, 42)); - BoardSelect.Background = new SolidColorBrush(Color.FromRgb(42, 42, 42)); - BoardEraser.Background = new SolidColorBrush(Color.FromRgb(42, 42, 42)); - BoardSelectGeometry.Brush = new SolidColorBrush(Color.FromRgb(255, 255, 255)); - BoardPenGeometry.Brush = new SolidColorBrush(Color.FromRgb(255, 255, 255)); - BoardEraserGeometry.Brush = new SolidColorBrush(Color.FromRgb(255, 255, 255)); - BoardPenLabel.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255)); - BoardSelectLabel.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255)); - BoardEraserLabel.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255)); - BoardSelect.BorderBrush = new SolidColorBrush(Color.FromRgb(85, 85, 85)); - BoardEraser.BorderBrush = new SolidColorBrush(Color.FromRgb(85, 85, 85)); - BoardPen.BorderBrush = new SolidColorBrush(Color.FromRgb(85, 85, 85)); + BoardPen.Background = new SolidColorBrush(Color.FromRgb(42, 42, 42)); + BoardSelect.Background = new SolidColorBrush(Color.FromRgb(42, 42, 42)); + BoardEraser.Background = new SolidColorBrush(Color.FromRgb(42, 42, 42)); + BoardSelectGeometry.Brush = new SolidColorBrush(Color.FromRgb(255, 255, 255)); + BoardPenGeometry.Brush = new SolidColorBrush(Color.FromRgb(255, 255, 255)); + BoardEraserGeometry.Brush = new SolidColorBrush(Color.FromRgb(255, 255, 255)); + BoardPenLabel.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255)); + BoardSelectLabel.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255)); + BoardEraserLabel.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255)); + BoardSelect.BorderBrush = new SolidColorBrush(Color.FromRgb(85, 85, 85)); + BoardEraser.BorderBrush = new SolidColorBrush(Color.FromRgb(85, 85, 85)); + BoardPen.BorderBrush = new SolidColorBrush(Color.FromRgb(85, 85, 85)); } else // 浅色主题或跟随系统 { - BoardPen.Background = new SolidColorBrush(Color.FromRgb(244, 244, 245)); - BoardSelect.Background = new SolidColorBrush(Color.FromRgb(244, 244, 245)); - BoardEraser.Background = new SolidColorBrush(Color.FromRgb(244, 244, 245)); - BoardSelectGeometry.Brush = new SolidColorBrush(Color.FromRgb(24, 24, 27)); - BoardPenGeometry.Brush = new SolidColorBrush(Color.FromRgb(24, 24, 27)); - BoardEraserGeometry.Brush = new SolidColorBrush(Color.FromRgb(24, 24, 27)); - BoardPenLabel.Foreground = new SolidColorBrush(Color.FromRgb(24, 24, 27)); - BoardSelectLabel.Foreground = new SolidColorBrush(Color.FromRgb(24, 24, 27)); - BoardEraserLabel.Foreground = new SolidColorBrush(Color.FromRgb(24, 24, 27)); - BoardSelect.BorderBrush = new SolidColorBrush(Color.FromRgb(161, 161, 170)); - BoardEraser.BorderBrush = new SolidColorBrush(Color.FromRgb(161, 161, 170)); - BoardPen.BorderBrush = new SolidColorBrush(Color.FromRgb(161, 161, 170)); + BoardPen.Background = new SolidColorBrush(Color.FromRgb(244, 244, 245)); + BoardSelect.Background = new SolidColorBrush(Color.FromRgb(244, 244, 245)); + BoardEraser.Background = new SolidColorBrush(Color.FromRgb(244, 244, 245)); + BoardSelectGeometry.Brush = new SolidColorBrush(Color.FromRgb(24, 24, 27)); + BoardPenGeometry.Brush = new SolidColorBrush(Color.FromRgb(24, 24, 27)); + BoardEraserGeometry.Brush = new SolidColorBrush(Color.FromRgb(24, 24, 27)); + BoardPenLabel.Foreground = new SolidColorBrush(Color.FromRgb(24, 24, 27)); + BoardSelectLabel.Foreground = new SolidColorBrush(Color.FromRgb(24, 24, 27)); + BoardEraserLabel.Foreground = new SolidColorBrush(Color.FromRgb(24, 24, 27)); + BoardSelect.BorderBrush = new SolidColorBrush(Color.FromRgb(161, 161, 170)); + BoardEraser.BorderBrush = new SolidColorBrush(Color.FromRgb(161, 161, 170)); + BoardPen.BorderBrush = new SolidColorBrush(Color.FromRgb(161, 161, 170)); } HideFloatingBarHighlight(); @@ -537,17 +537,17 @@ namespace Ink_Canvas // 根据主题设置颜色 if (Settings.Appearance.Theme == 1) // 深色主题 { - BoardPen.Background = new SolidColorBrush(Color.FromRgb(42, 42, 42)); - BoardPen.BorderBrush = new SolidColorBrush(Color.FromRgb(85, 85, 85)); - BoardPenGeometry.Brush = new SolidColorBrush(Color.FromRgb(255, 255, 255)); - BoardPenLabel.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255)); + BoardPen.Background = new SolidColorBrush(Color.FromRgb(42, 42, 42)); + BoardPen.BorderBrush = new SolidColorBrush(Color.FromRgb(85, 85, 85)); + BoardPenGeometry.Brush = new SolidColorBrush(Color.FromRgb(255, 255, 255)); + BoardPenLabel.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255)); } else // 浅色主题或跟随系统 { - BoardPen.Background = new SolidColorBrush(Color.FromRgb(244, 244, 245)); - BoardPen.BorderBrush = new SolidColorBrush(Color.FromRgb(161, 161, 170)); - BoardPenGeometry.Brush = new SolidColorBrush(Color.FromRgb(24, 24, 27)); - BoardPenLabel.Foreground = new SolidColorBrush(Color.FromRgb(24, 24, 27)); + BoardPen.Background = new SolidColorBrush(Color.FromRgb(244, 244, 245)); + BoardPen.BorderBrush = new SolidColorBrush(Color.FromRgb(161, 161, 170)); + BoardPenGeometry.Brush = new SolidColorBrush(Color.FromRgb(24, 24, 27)); + BoardPenLabel.Foreground = new SolidColorBrush(Color.FromRgb(24, 24, 27)); } SetFloatingBarHighlightPosition("cursor"); @@ -1357,12 +1357,12 @@ namespace Ink_Canvas BlackboardUIGridForInkReplay.IsHitTestVisible = true; inkCanvas.IsHitTestVisible = true; inkCanvas.IsManipulationEnabled = true; - + if (inkCanvas.EditingMode == InkCanvasEditingMode.None) { inkCanvas.EditingMode = InkCanvasEditingMode.Ink; } - + ResetTouchStates(); }); }).Start(); @@ -1388,12 +1388,12 @@ namespace Ink_Canvas isStopInkReplay = true; inkCanvas.IsHitTestVisible = true; inkCanvas.IsManipulationEnabled = true; - + if (inkCanvas.EditingMode == InkCanvasEditingMode.None) { inkCanvas.EditingMode = InkCanvasEditingMode.Ink; } - + ResetTouchStates(); } } @@ -1975,7 +1975,7 @@ namespace Ink_Canvas } // 禁用高级橡皮擦系统 - DisableEraserOverlay(); + DisableEraserOverlay(); ExitMultiTouchModeIfNeeded(); @@ -2222,7 +2222,7 @@ namespace Ink_Canvas } // 启用新的高级橡皮擦系统 - EnableEraserOverlay(); + EnableEraserOverlay(); // 使用新的高级橡皮擦系统 // 使用集中化的工具模式切换方法 @@ -2234,7 +2234,7 @@ namespace Ink_Canvas ApplyAdvancedEraserShape(); // 使用新的橡皮擦形状应用方法 SetCursorBasedOnEditingMode(inkCanvas); HideSubPanels("eraser"); // 高亮橡皮按钮 - Trace.WriteLine($"Eraser: Eraser button clicked, current size: {eraserWidth}, circle: {isEraserCircleShape}"); + Trace.WriteLine($"Eraser: Eraser button clicked, current size: {eraserWidth}, circle: {isEraserCircleShape}"); if (isAlreadyEraser) { @@ -2263,7 +2263,7 @@ namespace Ink_Canvas drawingShapeMode = 0; // 启用新的高级橡皮擦系统 - EnableEraserOverlay(); + EnableEraserOverlay(); // 使用新的高级橡皮擦系统 // 使用集中化的工具模式切换方法 @@ -2578,7 +2578,7 @@ namespace Ink_Canvas private void SelectIcon_MouseUp(object sender, RoutedEventArgs e) { // 禁用高级橡皮擦系统 - DisableEraserOverlay(); + DisableEraserOverlay(); forceEraser = true; drawingShapeMode = 0; @@ -2687,12 +2687,12 @@ namespace Ink_Canvas if (!userChangedNoFocusModeInSettings && wasNoFocusModeBeforeSettings) { Settings.Advanced.IsNoFocusMode = true; - ToggleSwitchNoFocusMode.IsOn = true; + ToggleSwitchNoFocusMode.IsOn = true; ApplyNoFocusMode(); } SaveSettingsToFile(); } - + App.IsAppExitByUser = true; // 不设置 CloseIsFromButton = true,让它也经过确认流程 Close(); @@ -2706,12 +2706,12 @@ namespace Ink_Canvas if (!userChangedNoFocusModeInSettings && wasNoFocusModeBeforeSettings) { Settings.Advanced.IsNoFocusMode = true; - ToggleSwitchNoFocusMode.IsOn = true; + ToggleSwitchNoFocusMode.IsOn = true; ApplyNoFocusMode(); } SaveSettingsToFile(); } - + Process.Start(System.Windows.Forms.Application.ExecutablePath, "-m"); App.IsAppExitByUser = true; // 不设置 CloseIsFromButton = true,让它也经过确认流程 @@ -2847,7 +2847,7 @@ namespace Ink_Canvas { // 先关闭多指书写模式 ToggleSwitchEnableMultiTouchMode.IsOn = false; - + // 使用Dispatcher.BeginInvoke确保UI更新完成后再重新开启 Dispatcher.BeginInvoke(new Action(() => { @@ -2873,7 +2873,7 @@ namespace Ink_Canvas ResetTouchStates(); } - + /// /// 重置所有触摸相关状态, /// @@ -2883,8 +2883,8 @@ namespace Ink_Canvas { // 清空触摸点计数器 dec.Clear(); - - + + // 重置单指拖动模式状态 if (isSingleFingerDragMode) { @@ -2894,25 +2894,25 @@ namespace Ink_Canvas BtnFingerDragMode.Content = "单指\n拖动"; } } - + // 重置手掌擦状态 if (isPalmEraserActive) { isPalmEraserActive = false; } - + // 确保触摸事件能正常响应 inkCanvas.IsHitTestVisible = true; inkCanvas.IsManipulationEnabled = true; - + // 释放所有触摸捕获 inkCanvas.ReleaseAllTouchCaptures(); - + // 恢复UI元素的触摸响应 ViewboxFloatingBar.IsHitTestVisible = true; BlackboardUIGridForInkReplay.IsHitTestVisible = true; - - + + } catch (Exception ex) { @@ -3007,7 +3007,7 @@ namespace Ink_Canvas // 使用异步延迟,等待浮动栏展开动画完成后再收纳 Task.Run(async () => { - await Task.Delay(700); + await Task.Delay(700); await Dispatcher.InvokeAsync(() => { FoldFloatingBar_MouseUp(new object(), null); diff --git a/Ink Canvas/MainWindow_cs/MW_FloatingWindowInterceptor.cs b/Ink Canvas/MainWindow_cs/MW_FloatingWindowInterceptor.cs index 1df2cdf7..b1d228e1 100644 --- a/Ink Canvas/MainWindow_cs/MW_FloatingWindowInterceptor.cs +++ b/Ink Canvas/MainWindow_cs/MW_FloatingWindowInterceptor.cs @@ -18,17 +18,17 @@ namespace Ink_Canvas try { _floatingWindowInterceptorManager = new FloatingWindowInterceptorManager(); - + // 订阅事件 _floatingWindowInterceptorManager.WindowIntercepted += OnFloatingWindowIntercepted; _floatingWindowInterceptorManager.WindowRestored += OnFloatingWindowRestored; - + // 初始化拦截器 _floatingWindowInterceptorManager.Initialize(Settings.Automation.FloatingWindowInterceptor); - + // 加载UI状态 LoadFloatingWindowInterceptorUI(); - + LogHelper.WriteLogToFile("悬浮窗拦截管理器初始化完成", LogHelper.LogType.Event); } catch (Exception ex) @@ -48,7 +48,7 @@ namespace Ink_Canvas // 设置主开关状态 ToggleSwitchFloatingWindowInterceptorEnabled.IsOn = Settings.Automation.FloatingWindowInterceptor.IsEnabled; - + // 设置各个拦截规则的状态 foreach (var kvp in Settings.Automation.FloatingWindowInterceptor.InterceptRules) { @@ -59,7 +59,7 @@ namespace Ink_Canvas toggle.IsOn = kvp.Value; } } - + // 更新UI可见性 UpdateFloatingWindowInterceptorUI(); } @@ -78,16 +78,16 @@ namespace Ink_Canvas { var isEnabled = Settings.Automation.FloatingWindowInterceptor.IsEnabled; FloatingWindowInterceptorGrid.Visibility = isEnabled ? Visibility.Visible : Visibility.Collapsed; - + // 计算启用的规则数量 var enabledRulesCount = Settings.Automation.FloatingWindowInterceptor.InterceptRules.Where(kvp => kvp.Value).Count(); var totalRulesCount = Settings.Automation.FloatingWindowInterceptor.InterceptRules.Count; - + // 更新状态文本 if (_floatingWindowInterceptorManager != null) { var stats = _floatingWindowInterceptorManager.GetStatistics(); - TextBlockFloatingWindowInterceptorStatus.Text = stats.IsRunning + TextBlockFloatingWindowInterceptorStatus.Text = stats.IsRunning ? $"拦截器运行中 - 已启用 {enabledRulesCount}/{totalRulesCount} 个规则" : $"拦截器未启动 - 已启用 {enabledRulesCount}/{totalRulesCount} 个规则"; } @@ -150,11 +150,11 @@ namespace Ink_Canvas private void ToggleSwitchFloatingWindowInterceptorEnabled_Toggled(object sender, RoutedEventArgs e) { if (!isLoaded) return; - + try { Settings.Automation.FloatingWindowInterceptor.IsEnabled = ToggleSwitchFloatingWindowInterceptorEnabled.IsOn; - + if (_floatingWindowInterceptorManager != null) { if (Settings.Automation.FloatingWindowInterceptor.IsEnabled) @@ -166,7 +166,7 @@ namespace Ink_Canvas _floatingWindowInterceptorManager.Stop(); } } - + UpdateFloatingWindowInterceptorUI(); SaveSettingsToFile(); } @@ -304,7 +304,7 @@ namespace Ink_Canvas { _floatingWindowInterceptorManager.SetInterceptRule(type, enabled); } - + // 更新设置 var ruleName = type.ToString(); if (Settings.Automation.FloatingWindowInterceptor.InterceptRules.ContainsKey(ruleName)) @@ -342,10 +342,10 @@ namespace Ink_Canvas } } } - + // 更新UI显示 UpdateFloatingWindowInterceptorUI(); - + SaveSettingsToFile(); } catch (Exception ex) diff --git a/Ink Canvas/MainWindow_cs/MW_ImageInsert.cs b/Ink Canvas/MainWindow_cs/MW_ImageInsert.cs index 42514b07..a4c39769 100644 --- a/Ink Canvas/MainWindow_cs/MW_ImageInsert.cs +++ b/Ink Canvas/MainWindow_cs/MW_ImageInsert.cs @@ -260,7 +260,7 @@ namespace Ink_Canvas // 将Bitmap转换为WPF BitmapSource var bitmapSource = ConvertBitmapToBitmapSource(bitmap); - + if (bitmapSource == null) { ShowNotification("转换截图失败"); @@ -649,7 +649,7 @@ namespace Ink_Canvas catch (Exception ex) { LogHelper.WriteLogToFile($"转换位图失败: {ex.Message}", LogHelper.LogType.Error); - + // 尝试使用备用方法:内存流转换 try { @@ -658,7 +658,7 @@ namespace Ink_Canvas catch (Exception fallbackEx) { LogHelper.WriteLogToFile($"备用转换方法也失败: {fallbackEx.Message}", LogHelper.LogType.Error); - + // 最后尝试:使用最简单的转换方法 try { @@ -723,18 +723,18 @@ namespace Ink_Canvas // 使用最基础的方法:直接保存为PNG然后加载 var tempFile = Path.GetTempFileName() + ".png"; - + try { bitmap.Save(tempFile, ImageFormat.Png); - + var bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.UriSource = new Uri(tempFile); bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.EndInit(); bitmapImage.Freeze(); - + return bitmapImage; } finally diff --git a/Ink Canvas/MainWindow_cs/MW_PPT.cs b/Ink Canvas/MainWindow_cs/MW_PPT.cs index ea416ff7..52124a35 100644 --- a/Ink Canvas/MainWindow_cs/MW_PPT.cs +++ b/Ink Canvas/MainWindow_cs/MW_PPT.cs @@ -89,11 +89,11 @@ namespace Ink_Canvas // PowerPoint应用程序守护相关字段 private DispatcherTimer _powerPointProcessMonitorTimer; private const int ProcessMonitorInterval = 1000; // 应用程序监控间隔(毫秒) - + // 上次播放位置相关字段 private int _lastPlaybackPage = 0; private bool _shouldNavigateToLastPage = false; - + // 页面切换防抖机制 private DateTime _lastSlideSwitchTime = DateTime.MinValue; private int _pendingSlideIndex = -1; @@ -800,7 +800,7 @@ namespace Ink_Canvas { if (Settings.Automation.IsAutoFoldInPPTSlideShow) { - if (isFloatingBarFolded) + if (isFloatingBarFolded) { await UnFoldFloatingBar(new object()); } @@ -808,7 +808,7 @@ namespace Ink_Canvas else { // 如果两个功能都关闭,确保浮动栏展开 - if (isFloatingBarFolded) + if (isFloatingBarFolded) { await UnFoldFloatingBar(new object()); } @@ -819,7 +819,7 @@ namespace Ink_Canvas isEnteredSlideShowEndEvent = true; // 保存所有墨迹 - _multiPPTInkManager?.SaveAllStrokesToFile(pres); + _multiPPTInkManager?.SaveAllStrokesToFile(pres); await Application.Current.Dispatcher.InvokeAsync(() => { @@ -1086,7 +1086,7 @@ namespace Ink_Canvas { // 切换到对应的墨迹管理器 _multiPPTInkManager?.SwitchToPresentation(activePresentation); - + // 重置锁定状态 _multiPPTInkManager?.ResetCurrentPresentationLockState(); } @@ -1106,21 +1106,21 @@ namespace Ink_Canvas { // 重置进入PPT时的浮动栏收纳状态记录 wasFloatingBarFoldedWhenEnterSlideShow = false; - + // 重置PPT放映结束事件标志 isEnteredSlideShowEndEvent = false; - + // 重置演示文稿黑边状态 isPresentationHaveBlackSpace = false; - + // 重置上次播放位置相关字段 _lastPlaybackPage = 0; _shouldNavigateToLastPage = false; - + // 重置页面切换防抖机制 _lastSlideSwitchTime = DateTime.MinValue; _pendingSlideIndex = -1; - + LogHelper.WriteLogToFile("PPT状态变量已重置", LogHelper.LogType.Trace); } catch (Exception ex) @@ -1137,15 +1137,15 @@ namespace Ink_Canvas try { var now = DateTime.Now; - + // 如果距离上次切换时间太短,使用防抖机制 if (now - _lastSlideSwitchTime < TimeSpan.FromMilliseconds(SlideSwitchDebounceMs)) { _pendingSlideIndex = currentSlide; - + // 停止之前的定时器 _slideSwitchDebounceTimer?.Stop(); - + // 创建新的定时器 _slideSwitchDebounceTimer = new System.Timers.Timer(SlideSwitchDebounceMs); _slideSwitchDebounceTimer.Elapsed += (sender, e) => @@ -1169,7 +1169,7 @@ namespace Ink_Canvas SwitchSlideInk(currentSlide); _pptUIManager?.UpdateCurrentSlideNumber(currentSlide, totalSlides); } - + _lastSlideSwitchTime = now; } catch (Exception ex) @@ -1190,21 +1190,21 @@ namespace Ink_Canvas // 获取当前页面索引 var currentSlideIndex = _pptManager?.GetCurrentSlideNumber() ?? 0; - - + + // 验证页面索引的有效性 if (newSlideIndex <= 0) { LogHelper.WriteLogToFile($"无效的新页面索引: {newSlideIndex},跳过页面切换", LogHelper.LogType.Warning); return; } - + // 如果有当前墨迹且不是第一次切换,先保存到当前页面 if (inkCanvas.Strokes.Count > 0 && currentSlideIndex > 0 && currentSlideIndex != newSlideIndex) { // 检查是否可以写入墨迹 bool canWrite = _multiPPTInkManager?.CanWriteInk(currentSlideIndex) == true; - + if (canWrite) { // 正常保存 @@ -1219,7 +1219,7 @@ namespace Ink_Canvas { // 无法获取当前页面索引时,不保存墨迹,直接清空 } - + // 切换到新页面并加载墨迹 var newStrokes = _multiPPTInkManager?.SwitchToSlide(newSlideIndex, null); if (newStrokes != null) @@ -1590,7 +1590,7 @@ namespace Ink_Canvas HideSubPanels("cursor"); SetCurrentToolMode(InkCanvasEditingMode.None); - + await Task.Delay(150); if (Settings.Automation.IsAutoFoldAfterPPTSlideShow) { @@ -1628,7 +1628,7 @@ namespace Ink_Canvas // 异常情况下也手动处理收纳状态恢复 await HandleManualSlideShowEnd(); - + // 异常情况下也要根据设置决定浮动栏边距 await Task.Delay(150); if (Settings.Automation.IsAutoFoldAfterPPTSlideShow) @@ -1678,7 +1678,7 @@ namespace Ink_Canvas { if (Settings.Automation.IsAutoFoldInPPTSlideShow) { - if (isFloatingBarFolded) + if (isFloatingBarFolded) { await UnFoldFloatingBar(new object()); } @@ -1686,7 +1686,7 @@ namespace Ink_Canvas else { // 如果两个功能都关闭,确保浮动栏展开 - if (isFloatingBarFolded) + if (isFloatingBarFolded) { await UnFoldFloatingBar(new object()); } diff --git a/Ink Canvas/MainWindow_cs/MW_PageListView.cs b/Ink Canvas/MainWindow_cs/MW_PageListView.cs index 395d0058..104d7cb6 100644 --- a/Ink Canvas/MainWindow_cs/MW_PageListView.cs +++ b/Ink Canvas/MainWindow_cs/MW_PageListView.cs @@ -80,7 +80,7 @@ namespace Ink_Canvas { return; } - + var tarPos = transform.Transform(point); scrollViewer.ScrollToVerticalOffset(tarPos.Y); } diff --git a/Ink Canvas/MainWindow_cs/MW_Settings.cs b/Ink Canvas/MainWindow_cs/MW_Settings.cs index 72b8ae29..5c06d12f 100644 --- a/Ink Canvas/MainWindow_cs/MW_Settings.cs +++ b/Ink Canvas/MainWindow_cs/MW_Settings.cs @@ -1029,41 +1029,41 @@ namespace Ink_Canvas // 获取当前屏幕的实际尺寸(考虑DPI缩放) var actualScreenWidth = SystemParameters.PrimaryScreenWidth; var actualScreenHeight = SystemParameters.PrimaryScreenHeight; - + // 预览区域固定尺寸 const double previewWidth = 324.0; const double previewHeight = 182.0; - + // 计算缩放比例(预览区域与实际屏幕的比例) double scaleX = previewWidth / actualScreenWidth; double scaleY = previewHeight / actualScreenHeight; - + // 获取按钮位置设置 double rsPosition = Settings.PowerPointSettings.PPTRSButtonPosition; double lsPosition = Settings.PowerPointSettings.PPTLSButtonPosition; double lbPosition = Settings.PowerPointSettings.PPTLBButtonPosition; double rbPosition = Settings.PowerPointSettings.PPTRBButtonPosition; - + bool showSidePageButton = sopt.Length >= 1 && sopt[0] == '2'; bool showBottomPageButton = bopt.Length >= 1 && bopt[0] == '2'; - + // 页码按钮的实际尺寸 - const double pageButtonWidth = 50.0; - const double pageButtonHeight = 50.0; - + const double pageButtonWidth = 50.0; + const double pageButtonHeight = 50.0; + // 计算侧边按钮位置(Y轴偏移) double sideOffsetY = showSidePageButton ? pageButtonHeight * scaleY : 0; PPTBtnPreviewRSTransform.Y = -(rsPosition * scaleY) - sideOffsetY; PPTBtnPreviewLSTransform.Y = -(lsPosition * scaleY) - sideOffsetY; - + // 计算底部按钮位置(X轴偏移) - const double bottomMarginOffset = 6.0; + const double bottomMarginOffset = 6.0; double scaledMarginOffset = bottomMarginOffset * scaleX; - + double bottomOffsetX = showBottomPageButton ? pageButtonWidth * scaleX : 0; PPTBtnPreviewLBTransform.X = scaledMarginOffset + (lbPosition * scaleX) + bottomOffsetX; PPTBtnPreviewRBTransform.X = -(scaledMarginOffset + (rbPosition * scaleX) + bottomOffsetX); - + // 计算工具栏尺寸 var dpiScaleX = 1.0; var dpiScaleY = 1.0; @@ -1082,17 +1082,17 @@ namespace Ink_Canvas dpiScaleX = 1.0; dpiScaleY = 1.0; } - + // 计算工具栏的实际尺寸 - const double baseToolbarHeight = 24.0; - + const double baseToolbarHeight = 24.0; + double actualToolbarHeight = baseToolbarHeight * dpiScaleY; double scaledToolbarHeight = actualToolbarHeight * scaleY; double scaledToolbarWidth = previewWidth; - + // 设置工具栏尺寸 PPTBtnPreviewToolbar.Height = scaledToolbarHeight; - PPTBtnPreviewToolbar.Width = scaledToolbarWidth; + PPTBtnPreviewToolbar.Width = scaledToolbarWidth; } private void ToggleSwitchShowCursor_Toggled(object sender, RoutedEventArgs e) @@ -1495,18 +1495,18 @@ namespace Ink_Canvas private void ToggleSwitchAutoFoldInPPTSlideShow_Toggled(object sender, RoutedEventArgs e) { if (!isLoaded) return; - + // 记录设置变更前的状态 bool previousState = Settings.Automation.IsAutoFoldInPPTSlideShow; Settings.Automation.IsAutoFoldInPPTSlideShow = ToggleSwitchAutoFoldInPPTSlideShow.IsOn; - + // 如果设置状态发生变化,重置PPT相关状态变量 if (previousState != Settings.Automation.IsAutoFoldInPPTSlideShow) { ResetPPTStateVariables(); LogHelper.WriteLogToFile($"PPT自动收纳设置已变更: {Settings.Automation.IsAutoFoldInPPTSlideShow}, 已重置相关状态变量", LogHelper.LogType.Trace); } - + if (Settings.Automation.IsAutoFoldInPPTSlideShow) { SettingsPPTInkingAndAutoFoldExplictBorder.Visibility = Visibility.Visible; @@ -1887,7 +1887,7 @@ namespace Ink_Canvas private void ToggleSwitchEnableTwoFingerZoom_Toggled(object sender, RoutedEventArgs e) { if (!isLoaded) return; - + // 如果多指书写模式启用,强制禁用双指手势 if (ToggleSwitchEnableMultiTouchMode.IsOn) { @@ -1898,7 +1898,7 @@ namespace Ink_Canvas SaveSettingsToFile(); return; } - + if (sender == ToggleSwitchEnableTwoFingerZoom) BoardToggleSwitchEnableTwoFingerZoom.IsOn = ToggleSwitchEnableTwoFingerZoom.IsOn; else @@ -1978,7 +1978,7 @@ namespace Ink_Canvas } Settings.Gesture.IsEnableMultiTouchMode = ToggleSwitchEnableMultiTouchMode.IsOn; - + // 如果启用多指书写模式,强制禁用所有双指手势 if (ToggleSwitchEnableMultiTouchMode.IsOn) { @@ -2003,7 +2003,7 @@ namespace Ink_Canvas if (BoardToggleSwitchEnableTwoFingerRotation != null) BoardToggleSwitchEnableTwoFingerRotation.IsOn = false; } - + CheckEnableTwoFingerGestureBtnColorPrompt(); SaveSettingsToFile(); } @@ -2011,7 +2011,7 @@ namespace Ink_Canvas private void ToggleSwitchEnableTwoFingerTranslate_Toggled(object sender, RoutedEventArgs e) { if (!isLoaded) return; - + // 如果多指书写模式启用,强制禁用双指手势 if (ToggleSwitchEnableMultiTouchMode.IsOn) { @@ -2022,7 +2022,7 @@ namespace Ink_Canvas SaveSettingsToFile(); return; } - + if (sender == ToggleSwitchEnableTwoFingerTranslate) BoardToggleSwitchEnableTwoFingerTranslate.IsOn = ToggleSwitchEnableTwoFingerTranslate.IsOn; else @@ -3074,7 +3074,7 @@ namespace Ink_Canvas { Directory.CreateDirectory(configsDir); } - + File.WriteAllText(App.RootPath + settingsFileName, text); } catch { } diff --git a/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs b/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs index 7234e5eb..d9741c4f 100644 --- a/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs +++ b/Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs @@ -11,9 +11,9 @@ using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Threading; -using WinForms = System.Windows.Forms; using File = System.IO.File; using OperatingSystem = OSVersionExtension.OperatingSystem; +using WinForms = System.Windows.Forms; namespace Ink_Canvas { @@ -30,7 +30,7 @@ namespace Ink_Canvas { string text = File.ReadAllText(App.RootPath + settingsFileName); Settings = JsonConvert.DeserializeObject(text); - + // 验证设置是否成功加载 if (Settings == null) { @@ -44,7 +44,7 @@ namespace Ink_Canvas { } } - + // 如果仍然失败,使用默认设置 if (Settings == null) { @@ -56,7 +56,7 @@ namespace Ink_Canvas catch (Exception ex) { LogHelper.WriteLogToFile($"配置文件加载失败: {ex.Message}", LogHelper.LogType.Error); - + // 尝试从备份恢复 LogHelper.WriteLogToFile("尝试从备份恢复配置文件", LogHelper.LogType.Warning); if (AutoBackupManager.TryRestoreFromBackup()) @@ -75,7 +75,7 @@ namespace Ink_Canvas BtnResetToSuggestion_Click(null, null); } } - + // 如果仍然失败,使用默认设置 if (Settings == null) { @@ -109,7 +109,7 @@ namespace Ink_Canvas LogHelper.WriteLogToFile("备份恢复失败,使用默认设置", LogHelper.LogType.Warning); BtnResetToSuggestion_Click(null, null); } - + // 如果仍然失败,使用默认设置 if (Settings == null) { @@ -427,7 +427,7 @@ namespace Ink_Canvas // 应用浮动栏按钮可见性设置 UpdateFloatingBarButtonsVisibility(); - + // 更新浮动栏图标 UpdateFloatingBarIcons(); @@ -806,7 +806,7 @@ namespace Ink_Canvas ToggleSwitchIsEnableAvoidFullScreenHelper.IsOn = Settings.Advanced.IsEnableAvoidFullScreenHelper; ToggleSwitchIsAutoBackupBeforeUpdate.IsOn = Settings.Advanced.IsAutoBackupBeforeUpdate; ToggleSwitchIsAutoBackupEnabled.IsOn = Settings.Advanced.IsAutoBackupEnabled; - + // 设置备份间隔下拉框 foreach (ComboBoxItem item in ComboBoxAutoBackupInterval.Items) { @@ -911,7 +911,7 @@ namespace Ink_Canvas if (Settings.ModeSettings != null) { ToggleSwitchMode.IsOn = Settings.ModeSettings.IsPPTOnlyMode; - + // 根据加载的配置状态执行相应的窗口显示/隐藏逻辑 if (isStartup && Settings.ModeSettings.IsPPTOnlyMode) { @@ -1026,7 +1026,7 @@ namespace Ink_Canvas // 加载退出收纳模式自动切换至批注模式设置 ToggleSwitchAutoEnterAnnotationModeWhenExitFoldMode.IsOn = Settings.Automation.IsAutoEnterAnnotationModeWhenExitFoldMode; - + // 加载退出白板时自动收纳设置 ToggleSwitchAutoFoldWhenExitWhiteboard.IsOn = Settings.Automation.IsAutoFoldWhenExitWhiteboard; } diff --git a/Ink Canvas/MainWindow_cs/MW_ShapeDrawing.cs b/Ink Canvas/MainWindow_cs/MW_ShapeDrawing.cs index 85fe0501..22c017de 100644 --- a/Ink Canvas/MainWindow_cs/MW_ShapeDrawing.cs +++ b/Ink Canvas/MainWindow_cs/MW_ShapeDrawing.cs @@ -343,7 +343,7 @@ namespace Ink_Canvas await CheckIsDrawingShapesInMultiTouchMode(); EnterShapeDrawingMode(3); CancelSingleFingerDragMode(); - isLongPressSelected = false; + isLongPressSelected = false; lastMouseDownSender = null; DrawShapePromptToPen(); } @@ -496,7 +496,7 @@ namespace Ink_Canvas if (!isTouchDown) return; if (isWaitUntilNextTouchDown && dec.Count > 1) return; - + // 对于多笔图形绘制,允许第二笔绘制,即使dec.Count > 1 if (dec.Count > 1 && !((drawingShapeMode == 24 || drawingShapeMode == 25) && drawMultiStepShapeCurrentStep == 1)) { @@ -512,7 +512,7 @@ namespace Ink_Canvas } return; } - + // 第二笔绘制双曲线时,只删除第二笔的临时笔画,保留第一笔的辅助线 if ((drawingShapeMode == 24 || drawingShapeMode == 25) && drawMultiStepShapeCurrentStep == 1) { @@ -584,19 +584,19 @@ namespace Ink_Canvas { DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() }; - + UpdateTempStrokeSafely(stroke); break; case 8: _currentCommitType = CommitReason.ShapeDrawing; strokes.Add(GenerateDashedLineStrokeCollection(iniP, endP)); - + UpdateTempStrokeCollectionSafely(strokes); break; case 18: _currentCommitType = CommitReason.ShapeDrawing; strokes.Add(GenerateDotLineStrokeCollection(iniP, endP)); - + UpdateTempStrokeCollectionSafely(strokes); break; case 2: @@ -618,7 +618,7 @@ namespace Ink_Canvas { DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() }; - + // 优化:使用更安全的临时笔画更新方式,减少闪烁 UpdateTempStrokeSafely(stroke); break; @@ -1503,12 +1503,12 @@ namespace Ink_Canvas { // 先添加新笔画,再删除旧笔画,减少视觉闪烁 inkCanvas.Strokes.Add(newStroke); - + if (lastTempStroke != null && inkCanvas.Strokes.Contains(lastTempStroke)) { inkCanvas.Strokes.Remove(lastTempStroke); } - + lastTempStroke = newStroke; } catch (Exception ex) @@ -1553,7 +1553,7 @@ namespace Ink_Canvas { // 先添加新笔画集合,再删除旧笔画集合,减少视觉闪烁 inkCanvas.Strokes.Add(newStrokeCollection); - + if (lastTempStrokeCollection != null && lastTempStrokeCollection.Count > 0) { foreach (var stroke in lastTempStrokeCollection) @@ -1564,7 +1564,7 @@ namespace Ink_Canvas } } } - + lastTempStrokeCollection = newStrokeCollection; } catch (Exception ex) diff --git a/Ink Canvas/MainWindow_cs/MW_SimulatePressure&InkToShape.cs b/Ink Canvas/MainWindow_cs/MW_SimulatePressure&InkToShape.cs index b822a5bb..058fc518 100644 --- a/Ink Canvas/MainWindow_cs/MW_SimulatePressure&InkToShape.cs +++ b/Ink Canvas/MainWindow_cs/MW_SimulatePressure&InkToShape.cs @@ -744,13 +744,13 @@ namespace Ink_Canvas // 应用高级贝塞尔曲线平滑(仅在未进行直线拉直时) Debug.WriteLine($"墨迹平滑检查: UseAdvancedBezierSmoothing={Settings.Canvas.UseAdvancedBezierSmoothing}, wasStraightened={wasStraightened}"); Debug.WriteLine($"异步平滑设置: UseAsyncInkSmoothing={Settings.Canvas.UseAsyncInkSmoothing}, _inkSmoothingManager={_inkSmoothingManager != null}"); - + if (Settings.Canvas.UseAdvancedBezierSmoothing && !wasStraightened) { try { Debug.WriteLine($"开始墨迹平滑处理: 原始点数={e.Stroke.StylusPoints.Count}, 直线拉直={wasStraightened}"); - + // 检查原始笔画是否仍然存在于画布中 if (inkCanvas.Strokes.Contains(e.Stroke)) { @@ -807,7 +807,7 @@ namespace Ink_Canvas Debug.WriteLine($"异步平滑完成: 原始点数={original.StylusPoints.Count}, 平滑后点数={smoothed.StylusPoints.Count}"); Debug.WriteLine($"墨迹比较: smoothed != original = {smoothed != original}"); Debug.WriteLine($"画布包含原始墨迹: {inkCanvas.Strokes.Contains(original)}"); - + // 在UI线程上执行笔画替换 if (inkCanvas.Strokes.Contains(original) && smoothed != original) { @@ -1424,7 +1424,7 @@ namespace Ink_Canvas // 修复灵敏度逻辑:灵敏度越大,容许的偏差越大,更容易将线条识别为直线 // 将灵敏度转换为阈值:灵敏度0.05-1.0映射到阈值0.01-0.2 double threshold = Math.Max(0.01, sensitivity * 0.2); // 确保最小阈值为0.01 - + if ((maxDeviation / lineLength) > threshold) { Debug.WriteLine($"拒绝拉直:最大偏差过大 {maxDeviation / lineLength:F3} > {threshold:F3}"); diff --git a/Ink Canvas/MainWindow_cs/MW_Timer.cs b/Ink Canvas/MainWindow_cs/MW_Timer.cs index 309f239b..c8d97dd9 100644 --- a/Ink Canvas/MainWindow_cs/MW_Timer.cs +++ b/Ink Canvas/MainWindow_cs/MW_Timer.cs @@ -70,8 +70,8 @@ namespace Ink_Canvas private TimeViewModel nowTimeVM = new TimeViewModel(); private DateTime cachedNetworkTime = DateTime.Now; private DateTime lastNtpSyncTime = DateTime.MinValue; - private string lastDisplayedTime = ""; - private bool useNetworkTime = false; + private string lastDisplayedTime = ""; + private bool useNetworkTime = false; private TimeSpan networkTimeOffset = TimeSpan.Zero; private DateTime lastLocalTime = DateTime.Now; // 记录上次的本地时间,用于检测时间跳跃 private bool isNtpSyncing = false; // 防止重复NTP同步的标志 @@ -87,7 +87,7 @@ namespace Ink_Canvas var ipEndPoint = new IPEndPoint(addresses[0], 123); using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)) { - socket.ReceiveTimeout = 5000; + socket.ReceiveTimeout = 5000; socket.Connect(ipEndPoint); await Task.Factory.FromAsync(socket.BeginSend(ntpData, 0, ntpData.Length, SocketFlags.None, null, socket), socket.EndSend); await Task.Factory.FromAsync(socket.BeginReceive(ntpData, 0, ntpData.Length, SocketFlags.None, null, socket), socket.EndReceive); @@ -131,7 +131,7 @@ namespace Ink_Canvas timerKillProcess.Start(); nowTimeVM.nowDate = DateTime.Now.ToString("yyyy'年'MM'月'dd'日' dddd"); nowTimeVM.nowTime = DateTime.Now.ToString("tt hh'时'mm'分'ss'秒'"); - + // 程序启动时立即进行一次NTP同步 Task.Run(async () => { @@ -151,17 +151,17 @@ namespace Ink_Canvas { // 防止重复同步 if (isNtpSyncing) return; - + isNtpSyncing = true; try { - + // 添加超时机制,最多等待10秒 var timeoutTask = Task.Delay(10000); var ntpTask = GetNetworkTimeAsync(); - + var completedTask = await Task.WhenAny(ntpTask, timeoutTask); - + if (completedTask == timeoutTask) { cachedNetworkTime = DateTime.Now; @@ -170,20 +170,20 @@ namespace Ink_Canvas networkTimeOffset = TimeSpan.Zero; return; } - + DateTime networkTime = await ntpTask; DateTime localTime = DateTime.Now; - + cachedNetworkTime = networkTime; lastNtpSyncTime = localTime; - + // 计算网络时间与本地时间的偏移量 networkTimeOffset = networkTime - localTime; - + // 如果时间差超过3分钟,则使用网络时间 useNetworkTime = Math.Abs(networkTimeOffset.TotalMinutes) > 3.0; - - } + + } catch (Exception ex) { // NTP同步失败时,保持使用本地时间 @@ -191,7 +191,7 @@ namespace Ink_Canvas lastNtpSyncTime = DateTime.Now; useNetworkTime = false; networkTimeOffset = TimeSpan.Zero; - + LogHelper.WriteLogToFile($"NTP同步失败: {ex.Message}", LogHelper.LogType.Warning); } finally @@ -209,7 +209,7 @@ namespace Ink_Canvas // 检测系统时间是否发生重大跳跃(超过2分钟) TimeSpan timeJump = localTime - lastLocalTime; double timeJumpMinutes = Math.Abs(timeJump.TotalMinutes); - + if (timeJumpMinutes > 3 && !isNtpSyncing) { // 系统时间发生重大变化(超过3分钟),立即触发NTP同步 @@ -237,12 +237,12 @@ namespace Ink_Canvas // 格式化时间字符串 string timeString = displayTime.ToString("tt hh'时'mm'分'ss'秒'"); - + // 只有当时间字符串发生变化时才更新UI,避免不必要的UI刷新 if (timeString != lastDisplayedTime) { lastDisplayedTime = timeString; - + // 使用BeginInvoke异步更新UI,避免阻塞 Dispatcher.BeginInvoke(new Action(() => { @@ -477,7 +477,7 @@ namespace Ink_Canvas { // EasiNote5 // 检查是否是桌面批注窗口 bool isAnnotationWindow = windowTitle.Length == 0 && ForegroundWindowInfo.WindowRect().Height < 500; - + // 如果启用了忽略桌面批注窗口功能,且当前是批注窗口 if (Settings.Automation.IsAutoFoldInEasiNoteIgnoreDesktopAnno && isAnnotationWindow) { diff --git a/Ink Canvas/MainWindow_cs/MW_TouchEvents.cs b/Ink Canvas/MainWindow_cs/MW_TouchEvents.cs index 6a1c758f..422ceeec 100644 --- a/Ink Canvas/MainWindow_cs/MW_TouchEvents.cs +++ b/Ink Canvas/MainWindow_cs/MW_TouchEvents.cs @@ -23,9 +23,9 @@ namespace Ink_Canvas private Point centerPoint = new Point(0, 0); private InkCanvasEditingMode lastInkCanvasEditingMode = InkCanvasEditingMode.Ink; private DateTime lastTouchDownTime = DateTime.MinValue; - private const double MULTI_TOUCH_DELAY_MS = 100; + private const double MULTI_TOUCH_DELAY_MS = 100; private bool isMultiTouchTimerActive = false; - + /// /// 保存画布上的非笔画元素(如图片、媒体元素等) /// @@ -64,13 +64,13 @@ namespace Ink_Canvas if (originalElement is Image originalImage) { var clonedImage = new Image(); - + // 复制图片源 if (originalImage.Source is BitmapSource bitmapSource) { clonedImage.Source = bitmapSource; } - + // 复制属性 clonedImage.Width = originalImage.Width; clonedImage.Height = originalImage.Height; @@ -81,23 +81,23 @@ namespace Ink_Canvas clonedImage.Focusable = originalImage.Focusable; clonedImage.Cursor = originalImage.Cursor; clonedImage.IsManipulationEnabled = originalImage.IsManipulationEnabled; - + // 复制位置 InkCanvas.SetLeft(clonedImage, InkCanvas.GetLeft(originalImage)); InkCanvas.SetTop(clonedImage, InkCanvas.GetTop(originalImage)); - + // 复制变换 if (originalImage.RenderTransform != null) { clonedImage.RenderTransform = originalImage.RenderTransform.Clone(); } - + return clonedImage; } else if (originalElement is MediaElement originalMedia) { var clonedMedia = new MediaElement(); - + // 复制媒体属性 clonedMedia.Source = originalMedia.Source; clonedMedia.Width = originalMedia.Width; @@ -105,23 +105,23 @@ namespace Ink_Canvas clonedMedia.Name = originalMedia.Name; clonedMedia.IsHitTestVisible = originalMedia.IsHitTestVisible; clonedMedia.Focusable = originalMedia.Focusable; - + // 复制位置 InkCanvas.SetLeft(clonedMedia, InkCanvas.GetLeft(originalMedia)); InkCanvas.SetTop(clonedMedia, InkCanvas.GetTop(originalMedia)); - + // 复制变换 if (originalMedia.RenderTransform != null) { clonedMedia.RenderTransform = originalMedia.RenderTransform.Clone(); } - + return clonedMedia; } else if (originalElement is Border originalBorder) { var clonedBorder = new Border(); - + // 复制边框属性 clonedBorder.Width = originalBorder.Width; clonedBorder.Height = originalBorder.Height; @@ -132,17 +132,17 @@ namespace Ink_Canvas clonedBorder.BorderBrush = originalBorder.BorderBrush; clonedBorder.BorderThickness = originalBorder.BorderThickness; clonedBorder.CornerRadius = originalBorder.CornerRadius; - + // 复制位置 InkCanvas.SetLeft(clonedBorder, InkCanvas.GetLeft(originalBorder)); InkCanvas.SetTop(clonedBorder, InkCanvas.GetTop(originalBorder)); - + // 复制变换 if (originalBorder.RenderTransform != null) { clonedBorder.RenderTransform = originalBorder.RenderTransform.Clone(); } - + return clonedBorder; } } @@ -150,7 +150,7 @@ namespace Ink_Canvas { LogHelper.WriteLogToFile($"克隆UI元素失败: {ex.Message}", LogHelper.LogType.Error); } - + return null; } @@ -246,14 +246,14 @@ namespace Ink_Canvas if (drawingShapeMode != 0) { inkCanvas.EditingMode = InkCanvasEditingMode.None; - + isTouchDown = true; ViewboxFloatingBar.IsHitTestVisible = false; BlackboardUIGridForInkReplay.IsHitTestVisible = false; - + // 设置起始点 if (NeedUpdateIniP()) iniP = e.GetTouchPoint(inkCanvas).Position; - + return; } @@ -292,14 +292,14 @@ namespace Ink_Canvas if (drawingShapeMode != 0) { inkCanvas.EditingMode = InkCanvasEditingMode.None; - + isTouchDown = true; ViewboxFloatingBar.IsHitTestVisible = false; BlackboardUIGridForInkReplay.IsHitTestVisible = false; - + // 设置起始点 if (NeedUpdateIniP()) iniP = e.GetPosition(inkCanvas); - + return; } if (inkCanvas.EditingMode != InkCanvasEditingMode.EraseByStroke) @@ -354,7 +354,7 @@ namespace Ink_Canvas isTouchDown = false; ViewboxFloatingBar.IsHitTestVisible = true; BlackboardUIGridForInkReplay.IsHitTestVisible = true; - + // 对于双曲线等需要多步绘制的图形,手写笔抬起时应该进入下一步 if (drawingShapeMode == 24 || drawingShapeMode == 25) { @@ -384,7 +384,7 @@ namespace Ink_Canvas }; inkCanvas_MouseUp(inkCanvas, mouseArgs); } - + return; } @@ -393,7 +393,7 @@ namespace Ink_Canvas var stroke = GetStrokeVisual(e.StylusDevice.Id).Stroke; inkCanvas.Strokes.Add(stroke); - await Task.Delay(5); + await Task.Delay(5); inkCanvas.Children.Remove(GetVisualCanvas(e.StylusDevice.Id)); inkCanvas_StrokeCollected(inkCanvas, @@ -464,7 +464,7 @@ namespace Ink_Canvas var strokeVisual = GetStrokeVisual(e.StylusDevice.Id); var stylusPointCollection = e.GetStylusPoints(this); foreach (var stylusPoint in stylusPointCollection) - strokeVisual.Add(new StylusPoint(stylusPoint.X, stylusPoint.Y, stylusPoint.PressureFactor)); + strokeVisual.Add(new StylusPoint(stylusPoint.X, stylusPoint.Y, stylusPoint.PressureFactor)); strokeVisual.Redraw(); } catch { } @@ -538,15 +538,15 @@ namespace Ink_Canvas if (drawingShapeMode != 0) { inkCanvas.EditingMode = InkCanvasEditingMode.None; - + // 设置触摸状态,类似鼠标事件处理 isTouchDown = true; ViewboxFloatingBar.IsHitTestVisible = false; BlackboardUIGridForInkReplay.IsHitTestVisible = false; - + // 设置起始点 if (NeedUpdateIniP()) iniP = e.GetTouchPoint(inkCanvas).Position; - + return; } if (inkCanvas.EditingMode == InkCanvasEditingMode.Ink) @@ -604,7 +604,7 @@ namespace Ink_Canvas inkCanvas.CaptureTouch(e.TouchDevice); ViewboxFloatingBar.IsHitTestVisible = false; BlackboardUIGridForInkReplay.IsHitTestVisible = false; - + isTouchDown = true; if (dec.Count == 0) @@ -646,7 +646,7 @@ namespace Ink_Canvas double boundWidth = GetTouchBoundWidth(e); - if ((Settings.Advanced.TouchMultiplier != 0 || !Settings.Advanced.IsSpecialScreen) + if ((Settings.Advanced.TouchMultiplier != 0 || !Settings.Advanced.IsSpecialScreen) && (boundWidth > BoundsWidth)) { // 根据敏感度调整阈值倍数 @@ -665,10 +665,10 @@ namespace Ink_Canvas break; } - double EraserThresholdValue = Settings.Startup.IsEnableNibMode ? - Settings.Advanced.NibModeBoundsWidthThresholdValue : + double EraserThresholdValue = Settings.Startup.IsEnableNibMode ? + Settings.Advanced.NibModeBoundsWidthThresholdValue : Settings.Advanced.FingerModeBoundsWidthThresholdValue; - + if (boundWidth > BoundsWidth * EraserThresholdValue * thresholdMultiplier) { // 记录当前编辑模式和高光状态 @@ -676,17 +676,17 @@ namespace Ink_Canvas palmEraserLastIsHighlighter = drawingAttributes.IsHighlighter; // 动态调整橡皮大小 - boundWidth *= (Settings.Startup.IsEnableNibMode ? - Settings.Advanced.NibModeBoundsWidthEraserSize : + boundWidth *= (Settings.Startup.IsEnableNibMode ? + Settings.Advanced.NibModeBoundsWidthEraserSize : Settings.Advanced.FingerModeBoundsWidthEraserSize); - - if (Settings.Advanced.IsSpecialScreen) + + if (Settings.Advanced.IsSpecialScreen) boundWidth *= Settings.Advanced.TouchMultiplier; - + inkCanvas.EraserShape = new EllipseStylusShape(boundWidth, boundWidth); inkCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint; isPalmEraserActive = true; - + // 启用橡皮擦覆盖层显示手掌擦样式 EnableEraserOverlay(); // 更新橡皮擦大小以匹配手掌擦面积 @@ -746,7 +746,7 @@ namespace Ink_Canvas { isMultiTouchTimerActive = true; var remainingTime = MULTI_TOUCH_DELAY_MS - timeSinceLastTouch; - System.Threading.Tasks.Task.Delay((int)remainingTime).ContinueWith(_ => + System.Threading.Tasks.Task.Delay((int)remainingTime).ContinueWith(_ => { Dispatcher.Invoke(() => { @@ -760,7 +760,7 @@ namespace Ink_Canvas } return; } - + lastInkCanvasEditingMode = inkCanvas.EditingMode; if (inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint && inkCanvas.EditingMode != InkCanvasEditingMode.EraseByStroke @@ -773,7 +773,7 @@ namespace Ink_Canvas private void inkCanvas_PreviewTouchMove(object sender, TouchEventArgs e) { - + // 如果手掌擦激活,更新橡皮擦反馈位置 if (isPalmEraserActive) { @@ -795,13 +795,13 @@ namespace Ink_Canvas // Palm Eraser 逻辑 dec.Remove(e.TouchDevice.Id); - + // 重置多触控点定时器状态 if (dec.Count <= 1) { isMultiTouchTimerActive = false; } - + // 当手掌擦激活且所有触摸点都抬起时,恢复原编辑模式 if (isPalmEraserActive && dec.Count == 0) @@ -842,7 +842,7 @@ namespace Ink_Canvas // 重置手掌擦状态 isPalmEraserActive = false; - + // 禁用橡皮擦覆盖层 DisableEraserOverlay(); if (Settings.Canvas.IsShowCursor) @@ -859,7 +859,7 @@ namespace Ink_Canvas isTouchDown = false; ViewboxFloatingBar.IsHitTestVisible = true; BlackboardUIGridForInkReplay.IsHitTestVisible = true; - + // 对于双曲线等需要多步绘制的图形,触摸抬手时应该进入下一步 if (drawingShapeMode == 24 || drawingShapeMode == 25) { @@ -917,7 +917,7 @@ namespace Ink_Canvas inkCanvas.EditingMode = lastInkCanvasEditingMode; } - if (isPalmEraserActive) + if (isPalmEraserActive) { LogHelper.WriteLogToFile("Palm eraser force recovery - all touch points cleared"); @@ -1010,7 +1010,7 @@ namespace Ink_Canvas bool disableScale = dec.Count >= 3; if (isInMultiTouchMode) return; - + if (dec.Count == 0 && (isSingleFingerDragMode || isInMultiTouchMode)) { ResetTouchStates(); @@ -1113,7 +1113,7 @@ namespace Ink_Canvas else { foreach (var stroke in inkCanvas.Strokes) stroke.Transform(m, false); - + // 同时变换画布上的图片元素 TransformCanvasImages(m); } @@ -1144,7 +1144,7 @@ namespace Ink_Canvas for (int i = inkCanvas.Children.Count - 1; i >= 0; i--) { var child = inkCanvas.Children[i]; - + if (child is Image image) { // 应用矩阵变换到图片 diff --git a/Ink Canvas/MainWindow_cs/MW_TrayIcon.cs b/Ink Canvas/MainWindow_cs/MW_TrayIcon.cs index 678f8232..2b64622b 100644 --- a/Ink Canvas/MainWindow_cs/MW_TrayIcon.cs +++ b/Ink Canvas/MainWindow_cs/MW_TrayIcon.cs @@ -209,15 +209,15 @@ namespace Ink_Canvas try { // 获取全局快捷键管理器 - var hotkeyManagerField = typeof(MainWindow).GetField("_globalHotkeyManager", + var hotkeyManagerField = typeof(MainWindow).GetField("_globalHotkeyManager", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); var hotkeyManager = hotkeyManagerField?.GetValue(mainWin) as GlobalHotkeyManager; - + if (hotkeyManager != null) { // 禁用所有快捷键 hotkeyManager.DisableHotkeyRegistration(); - + // 更新菜单项文本和状态 var menuItem = sender as MenuItem; if (menuItem != null) diff --git a/Ink Canvas/Resources/Settings.cs b/Ink Canvas/Resources/Settings.cs index 47cf85dd..8e789f0a 100644 --- a/Ink Canvas/Resources/Settings.cs +++ b/Ink Canvas/Resources/Settings.cs @@ -101,7 +101,7 @@ namespace Ink_Canvas // 墨迹渐隐功能设置 [JsonProperty("enableInkFade")] - public bool EnableInkFade { get; set; } = false; + public bool EnableInkFade { get; set; } = false; [JsonProperty("inkFadeTime")] public int InkFadeTime { get; set; } = 3000; // 墨迹渐隐时间(毫秒) @@ -472,7 +472,7 @@ namespace Ink_Canvas public bool IsEnabled { get; set; } = false; [JsonProperty("scanIntervalMs")] - public int ScanIntervalMs { get; set; } = 5000; + public int ScanIntervalMs { get; set; } = 5000; [JsonProperty("autoStart")] public bool AutoStart { get; set; } = false; @@ -624,7 +624,7 @@ namespace Ink_Canvas [JsonProperty("directCallCiRand")] public bool DirectCallCiRand { get; set; } [JsonProperty("externalCallerType")] - public int ExternalCallerType { get; set; } = 0; + public int ExternalCallerType { get; set; } = 0; [JsonProperty("selectedBackgroundIndex")] public int SelectedBackgroundIndex { get; set; } [JsonProperty("customPickNameBackgrounds")] @@ -682,15 +682,15 @@ namespace Ink_Canvas public class CameraSettings { [JsonProperty("rotationAngle")] - public int RotationAngle { get; set; } = 0; + public int RotationAngle { get; set; } = 0; [JsonProperty("resolutionWidth")] - public int ResolutionWidth { get; set; } = 1920; + public int ResolutionWidth { get; set; } = 1920; [JsonProperty("resolutionHeight")] - public int ResolutionHeight { get; set; } = 1080; + public int ResolutionHeight { get; set; } = 1080; [JsonProperty("selectedCameraIndex")] - public int SelectedCameraIndex { get; set; } = 0; + public int SelectedCameraIndex { get; set; } = 0; } } diff --git a/Ink Canvas/Windows/CountdownTimerWindow.xaml.cs b/Ink Canvas/Windows/CountdownTimerWindow.xaml.cs index f3fd787f..5daaf318 100644 --- a/Ink Canvas/Windows/CountdownTimerWindow.xaml.cs +++ b/Ink Canvas/Windows/CountdownTimerWindow.xaml.cs @@ -1,5 +1,4 @@ using Ink_Canvas.Helpers; -using Ink_Canvas.Resources; using System; using System.Media; using System.Timers; @@ -7,7 +6,6 @@ using System.Windows; using System.Windows.Input; using System.Windows.Interop; using System.Windows.Media; -using System.Windows.Media.Imaging; namespace Ink_Canvas { @@ -362,12 +360,12 @@ namespace Ink_Canvas HourPlus1Text.Text = "+1"; HourMinus1Text.Text = "-1"; HourMinus5Text.Text = "-5"; - + MinutePlus5Text.Text = "+5"; MinutePlus1Text.Text = "+1"; MinuteMinus1Text.Text = "-1"; MinuteMinus5Text.Text = "-5"; - + SecondPlus5Text.Text = "+5"; SecondPlus1Text.Text = "+1"; SecondMinus1Text.Text = "-1"; @@ -380,12 +378,12 @@ namespace Ink_Canvas HourPlus1Text.Text = "∧"; HourMinus1Text.Text = "∨"; HourMinus5Text.Text = "∨∨"; - + MinutePlus5Text.Text = "∧∧"; MinutePlus1Text.Text = "∧"; MinuteMinus1Text.Text = "∨"; MinuteMinus5Text.Text = "∨∨"; - + SecondPlus5Text.Text = "∧∧"; SecondPlus1Text.Text = "∧"; SecondMinus1Text.Text = "∨"; @@ -399,8 +397,8 @@ namespace Ink_Canvas { double volume = MainWindow.Settings.RandSettings?.TimerVolume ?? 1.0; mediaPlayer.Volume = volume; - - if (!string.IsNullOrEmpty(MainWindow.Settings.RandSettings?.CustomTimerSoundPath) && + + if (!string.IsNullOrEmpty(MainWindow.Settings.RandSettings?.CustomTimerSoundPath) && System.IO.File.Exists(MainWindow.Settings.RandSettings.CustomTimerSoundPath)) { // 播放自定义铃声 @@ -419,7 +417,7 @@ namespace Ink_Canvas } mediaPlayer.Open(new Uri(tempPath)); } - + mediaPlayer.Play(); } catch (Exception ex) diff --git a/Ink Canvas/Windows/HasNewUpdateWindow.xaml.cs b/Ink Canvas/Windows/HasNewUpdateWindow.xaml.cs index 8b04bf1e..9622e2e6 100644 --- a/Ink Canvas/Windows/HasNewUpdateWindow.xaml.cs +++ b/Ink Canvas/Windows/HasNewUpdateWindow.xaml.cs @@ -92,7 +92,7 @@ namespace Ink_Canvas LogHelper.WriteLogToFile($"应用主题时出错: {ex.Message}", LogHelper.LogType.Error); } } - + /// /// 更新为浅色主题颜色 /// @@ -109,7 +109,7 @@ namespace Ink_Canvas Resources["UpdateWindowTextPrimaryBrush"] = new SolidColorBrush(Color.FromRgb(0x1f, 0x29, 0x37)); Resources["UpdateWindowTextSecondaryBrush"] = new SolidColorBrush(Color.FromRgb(0x6b, 0x72, 0x80)); Resources["UpdateWindowCloseButtonBrush"] = new SolidColorBrush(Color.FromRgb(0x66, 0x66, 0x66)); - + // 更新渐变背景 var gradient = new LinearGradientBrush(); gradient.StartPoint = new Point(0, 0); @@ -123,7 +123,7 @@ namespace Ink_Canvas LogHelper.WriteLogToFile($"更新浅色主题颜色时出错: {ex.Message}", LogHelper.LogType.Error); } } - + /// /// 更新为深色主题颜色 /// @@ -140,7 +140,7 @@ namespace Ink_Canvas Resources["UpdateWindowTextPrimaryBrush"] = new SolidColorBrush(Color.FromRgb(0xf9, 0xfa, 0xfb)); Resources["UpdateWindowTextSecondaryBrush"] = new SolidColorBrush(Color.FromRgb(0x9c, 0xa3, 0xaf)); Resources["UpdateWindowCloseButtonBrush"] = new SolidColorBrush(Color.FromRgb(0x9c, 0xa3, 0xaf)); - + // 更新渐变背景 var gradient = new LinearGradientBrush(); gradient.StartPoint = new Point(0, 0); @@ -154,7 +154,7 @@ namespace Ink_Canvas LogHelper.WriteLogToFile($"更新深色主题颜色时出错: {ex.Message}", LogHelper.LogType.Error); } } - + /// /// 检查系统是否为浅色主题 /// @@ -270,7 +270,7 @@ namespace Ink_Canvas UpdateLaterButton.IsEnabled = false; SkipVersionButton.IsEnabled = false; DownloadProgressPanel.Visibility = Visibility.Visible; - + // 重置进度条 var progressFill = FindName("ProgressFill") as Border; if (progressFill != null) diff --git a/Ink Canvas/Windows/HistoryRollbackWindow.xaml.cs b/Ink Canvas/Windows/HistoryRollbackWindow.xaml.cs index 1e402565..34d64f47 100644 --- a/Ink Canvas/Windows/HistoryRollbackWindow.xaml.cs +++ b/Ink Canvas/Windows/HistoryRollbackWindow.xaml.cs @@ -33,12 +33,12 @@ namespace Ink_Canvas { InitializeComponent(); this.channel = channel; - + // 应用当前主题 ApplyCurrentTheme(); - + LoadVersions(); - + // 添加窗口拖动功能 MouseDown += (sender, e) => { @@ -48,7 +48,7 @@ namespace Ink_Canvas } }; } - + /// /// 应用当前主题设置 /// @@ -86,7 +86,7 @@ namespace Ink_Canvas LogHelper.WriteLogToFile($"应用主题时出错: {ex.Message}", LogHelper.LogType.Error); } } - + /// /// 更新为浅色主题颜色 /// @@ -104,7 +104,7 @@ namespace Ink_Canvas LogHelper.WriteLogToFile($"更新浅色主题颜色时出错: {ex.Message}", LogHelper.LogType.Error); } } - + /// /// 更新为深色主题颜色 /// @@ -122,7 +122,7 @@ namespace Ink_Canvas LogHelper.WriteLogToFile($"更新深色主题颜色时出错: {ex.Message}", LogHelper.LogType.Error); } } - + /// /// 检查系统是否为浅色主题 /// diff --git a/Ink Canvas/Windows/ScreenshotSelectorWindow.xaml.cs b/Ink Canvas/Windows/ScreenshotSelectorWindow.xaml.cs index 551c8bca..48f6df43 100644 --- a/Ink Canvas/Windows/ScreenshotSelectorWindow.xaml.cs +++ b/Ink Canvas/Windows/ScreenshotSelectorWindow.xaml.cs @@ -1,5 +1,7 @@ -using System; +using Ink_Canvas.Helpers; +using System; using System.Collections.Generic; +using System.Drawing; using System.Windows; using System.Windows.Controls; using System.Windows.Forms; @@ -7,15 +9,13 @@ using System.Windows.Input; using System.Windows.Media; using System.Windows.Shapes; using System.Windows.Threading; -using System.Drawing; -using Ink_Canvas.Helpers; using Brushes = System.Windows.Media.Brushes; using Color = System.Windows.Media.Color; using DrawingRectangle = System.Drawing.Rectangle; -using WpfPoint = System.Windows.Point; using KeyEventArgs = System.Windows.Input.KeyEventArgs; using MouseEventArgs = System.Windows.Input.MouseEventArgs; using WpfCanvas = System.Windows.Controls.Canvas; +using WpfPoint = System.Windows.Point; namespace Ink_Canvas { @@ -115,7 +115,7 @@ namespace Ink_Canvas // 初始化摄像头选择下拉框 RefreshCameraComboBox(); - + // 初始化旋转和分辨率显示 InitializeCameraControls(); } @@ -131,7 +131,7 @@ namespace Ink_Canvas { // 更新旋转角度显示 UpdateRotationDisplay(); - + // 设置分辨率下拉框 var currentResolution = $"{_cameraService.ResolutionWidth}x{_cameraService.ResolutionHeight}"; foreach (ComboBoxItem item in ResolutionComboBox.Items) @@ -150,7 +150,7 @@ namespace Ink_Canvas try { CameraSelectionComboBox.Items.Clear(); - + if (_cameraService.HasAvailableCameras()) { var cameraNames = _cameraService.GetCameraNames(); @@ -158,7 +158,7 @@ namespace Ink_Canvas { CameraSelectionComboBox.Items.Add(name); } - + if (cameraNames.Count > 0) { CameraSelectionComboBox.SelectedIndex = 0; @@ -203,7 +203,7 @@ namespace Ink_Canvas CameraPreviewImage.Source = bitmapSource; CameraStatusText.Text = "摄像头已连接"; } - + // 释放临时位图 clonedFrame.Dispose(); } @@ -393,10 +393,10 @@ namespace Ink_Canvas RectangleModeButton.Background = new SolidColorBrush(Color.FromRgb(107, 114, 128)); // 灰色 FreehandModeButton.Background = new SolidColorBrush(Color.FromRgb(107, 114, 128)); // 灰色 CameraModeButton.Background = new SolidColorBrush(Color.FromRgb(107, 114, 128)); // 灰色 - + // 隐藏摄像头预览 CameraPreviewBorder.Visibility = Visibility.Collapsed; - + // 直接执行全屏截图 PerformFullScreenCapture(); } @@ -512,10 +512,10 @@ namespace Ink_Canvas { // 保存BitmapSource而不是Bitmap CameraBitmapSource = bitmapSource; - + // 停止摄像头预览 _cameraService.StopPreview(); - + // 设置结果并关闭窗口 DialogResult = true; Close(); @@ -1164,11 +1164,11 @@ namespace Ink_Canvas { // 获取虚拟屏幕边界 var virtualScreen = SystemInformation.VirtualScreen; - + // 设置全屏截图区域 SelectedArea = new DrawingRectangle(virtualScreen.X, virtualScreen.Y, virtualScreen.Width, virtualScreen.Height); SelectedPath = null; // 全屏截图不需要路径 - + // 直接关闭窗口并返回结果 DialogResult = true; Close(); @@ -1271,8 +1271,8 @@ namespace Ink_Canvas if (!string.IsNullOrEmpty(resolution)) { var parts = resolution.Split(','); - if (parts.Length == 2 && - int.TryParse(parts[0], out int width) && + if (parts.Length == 2 && + int.TryParse(parts[0], out int width) && int.TryParse(parts[1], out int height)) { _cameraService.ResolutionWidth = width; diff --git a/Ink Canvas/Windows/SplashScreen.xaml.cs b/Ink Canvas/Windows/SplashScreen.xaml.cs index e4e91da7..3d68d5ff 100644 --- a/Ink Canvas/Windows/SplashScreen.xaml.cs +++ b/Ink Canvas/Windows/SplashScreen.xaml.cs @@ -1,13 +1,12 @@ +using Newtonsoft.Json; using System; +using System.IO; using System.Reflection; -using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Threading; -using System.IO; -using Newtonsoft.Json; namespace Ink_Canvas.Windows { @@ -18,7 +17,7 @@ namespace Ink_Canvas.Windows { private DispatcherTimer _timer; private int _loadingStep = 0; - private int _actualSplashStyle = 1; + private int _actualSplashStyle = 1; private readonly string[] _loadingMessages = { "正在启动 Ink Canvas...", "正在初始化组件...", @@ -37,13 +36,13 @@ namespace Ink_Canvas.Windows { // 设置窗口居中 WindowStartupLocation = WindowStartupLocation.CenterScreen; - + // 设置版本号 SetVersionText(); - + // 加载启动图片并获取实际样式 _actualSplashStyle = LoadSplashImageWithStyle(); - + // 启动加载动画 StartLoadingAnimation(); } @@ -52,7 +51,7 @@ namespace Ink_Canvas.Windows { _timer = new DispatcherTimer { - Interval = TimeSpan.FromMilliseconds(1200) + Interval = TimeSpan.FromMilliseconds(1200) }; _timer.Tick += Timer_Tick; _timer.Start(); @@ -83,7 +82,7 @@ namespace Ink_Canvas.Windows EasingFunction = new CubicEase { EasingMode = EasingMode.EaseIn } }; - fadeOutAnimation.Completed += (s, e) => + fadeOutAnimation.Completed += (s, e) => { this.Close(); }; @@ -101,7 +100,7 @@ namespace Ink_Canvas.Windows { // 设置进度条颜色 SetProgressBarColor(); - + // 获取进度条容器的实际宽度 double containerWidth = ProgressBarBackground.ActualWidth; if (containerWidth <= 0) @@ -109,13 +108,13 @@ namespace Ink_Canvas.Windows // 如果ActualWidth为0,使用设计时宽度 containerWidth = 530; } - + // 计算目标宽度 double targetWidth = containerWidth * (progress / 100.0); - + // 创建Storyboard动画 var storyboard = new Storyboard(); - + // 创建宽度动画 var widthAnimation = new DoubleAnimation { @@ -124,20 +123,20 @@ namespace Ink_Canvas.Windows Duration = TimeSpan.FromMilliseconds(300), EasingFunction = new CubicEase { EasingMode = EasingMode.EaseOut } }; - + // 设置动画目标 Storyboard.SetTarget(widthAnimation, ProgressBarFill); Storyboard.SetTargetProperty(widthAnimation, new PropertyPath(Border.WidthProperty)); - + // 添加动画到Storyboard storyboard.Children.Add(widthAnimation); - + // 添加动画完成事件 storyboard.Completed += (s, e) => { // 确保最终值正确设置 ProgressBarFill.Width = targetWidth; - + // 根据进度调整圆角 if (progress >= 100) { @@ -150,7 +149,7 @@ namespace Ink_Canvas.Windows ProgressBarFill.CornerRadius = new CornerRadius(0, 0, 0, 7); } }; - + // 开始动画 storyboard.Begin(); }); @@ -171,7 +170,7 @@ namespace Ink_Canvas.Windows Dispatcher.Invoke(() => { LoadingText.Text = message; - + // 根据实际启动动画样式调整加载文本样式 if (actualSplashStyle == 6) // 马年限定 { @@ -180,7 +179,7 @@ namespace Ink_Canvas.Windows LoadingText.FontWeight = FontWeights.SemiBold; LoadingText.Foreground = Brushes.White; LoadingText.HorizontalAlignment = HorizontalAlignment.Center; - LoadingText.Margin = new Thickness(0,200,140,4); + LoadingText.Margin = new Thickness(0, 200, 140, 4); } else { @@ -189,7 +188,7 @@ namespace Ink_Canvas.Windows LoadingText.FontWeight = FontWeights.SemiBold; LoadingText.Foreground = Brushes.White; LoadingText.HorizontalAlignment = HorizontalAlignment.Center; - LoadingText.Margin = new Thickness(0,200,0,0); + LoadingText.Margin = new Thickness(0, 200, 0, 0); } }); } @@ -282,7 +281,7 @@ namespace Ink_Canvas.Windows catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"加载启动图片失败: {ex.Message}"); - return GetActualStyle(1); + return GetActualStyle(1); } } @@ -296,7 +295,7 @@ namespace Ink_Canvas.Windows // 读取设置 var settingsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configs", "Settings.json"); int splashStyle = 1; // 默认跟随四季 - + if (File.Exists(settingsPath)) { var json = File.ReadAllText(settingsPath); @@ -313,7 +312,7 @@ namespace Ink_Canvas.Windows } catch { - string imageName = GetImageNameByStyle(1); + string imageName = GetImageNameByStyle(1); return $"pack://application:,,,/Resources/Startup-animation/{imageName}"; } } @@ -330,7 +329,7 @@ namespace Ink_Canvas.Windows // 读取设置 var settingsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configs", "Settings.json"); int splashStyle = 1; // 默认跟随四季 - + if (File.Exists(settingsPath)) { var json = File.ReadAllText(settingsPath); @@ -349,7 +348,7 @@ namespace Ink_Canvas.Windows catch { actualStyle = GetActualStyle(1); - string imageName = GetImageNameByStyle(1); + string imageName = GetImageNameByStyle(1); return $"pack://application:,,,/Resources/Startup-animation/{imageName}"; } } @@ -367,16 +366,16 @@ namespace Ink_Canvas.Windows var random = new Random(); var randomStyles = new[] { 2, 3, 4, 5, 6 }; // 春季、夏季、秋季、冬季、马年限定 return randomStyles[random.Next(randomStyles.Length)]; - + case 1: // 跟随四季 var month = DateTime.Now.Month; if (month >= 3 && month <= 5) return 2; // 春季 if (month >= 6 && month <= 8) return 3; // 夏季 if (month >= 9 && month <= 11) return 4; // 秋季 return 5; // 冬季 - + default: - return style; + return style; } } @@ -391,14 +390,14 @@ namespace Ink_Canvas.Windows var random = new Random(); var randomStyles = new[] { 2, 3, 4, 5, 6 }; // 春季、夏季、秋季、冬季、马年限定 return GetImageNameByStyle(randomStyles[random.Next(randomStyles.Length)]); - + case 1: // 跟随四季 var month = DateTime.Now.Month; if (month >= 3 && month <= 5) return GetImageNameByStyle(2); // 春季 if (month >= 6 && month <= 8) return GetImageNameByStyle(3); // 夏季 if (month >= 9 && month <= 11) return GetImageNameByStyle(4); // 秋季 return GetImageNameByStyle(5); // 冬季 - + case 2: // 春季 return "ICC Spring.png"; case 3: // 夏季 @@ -410,7 +409,7 @@ namespace Ink_Canvas.Windows case 6: // 马年限定 return "ICC Horse.png"; default:// 默认返回 - return "ICC Horse.png"; + return "ICC Horse.png"; } } @@ -420,7 +419,7 @@ namespace Ink_Canvas.Windows private void SetProgressBarColor() { Color progressColor; - + switch (_actualSplashStyle) { case 2: // 春季 - H=136, S=15, L=22 @@ -442,14 +441,14 @@ namespace Ink_Canvas.Windows progressColor = Colors.White; break; } - + // 创建渐变画刷 var gradientBrush = new LinearGradientBrush { StartPoint = new System.Windows.Point(0, 0), EndPoint = new System.Windows.Point(1, 0) }; - + // 根据颜色类型设置渐变 if (_actualSplashStyle == 6) // 马年限定使用白色渐变 { @@ -459,7 +458,7 @@ namespace Ink_Canvas.Windows } else // 其他样式使用HSL颜色的渐变 { - var lighterColor = Color.FromArgb(255, + var lighterColor = Color.FromArgb(255, (byte)Math.Min(255, progressColor.R + 30), (byte)Math.Min(255, progressColor.G + 30), (byte)Math.Min(255, progressColor.B + 30)); @@ -467,12 +466,12 @@ namespace Ink_Canvas.Windows (byte)Math.Max(0, progressColor.R - 30), (byte)Math.Max(0, progressColor.G - 30), (byte)Math.Max(0, progressColor.B - 30)); - + gradientBrush.GradientStops.Add(new GradientStop(lighterColor, 0)); gradientBrush.GradientStops.Add(new GradientStop(progressColor, 0.5)); gradientBrush.GradientStops.Add(new GradientStop(darkerColor, 1)); } - + ProgressBarFill.Background = gradientBrush; }