From 07a62d2f78d5de758dcdbebf2780a88d2e6ab065 Mon Sep 17 00:00:00 2001 From: CJKmkp <2564608840@qq.com> Date: Wed, 1 Oct 2025 00:49:12 +0800 Subject: [PATCH] add:issue #224 --- Ink Canvas/App.xaml.cs | 2 +- .../Helpers/FloatingWindowInterceptor.cs | 2 +- Ink Canvas/Helpers/GlobalHotkeyManager.cs | 6 +- Ink Canvas/Helpers/MultiTouchInput.cs | 2 +- Ink Canvas/Helpers/PPTInkManager.cs | 2 +- Ink Canvas/MainWindow.xaml | 33 ++++++ .../MainWindow_cs/MW_ElementsControls.cs | 2 +- Ink Canvas/MainWindow_cs/MW_Eraser.cs | 10 +- Ink Canvas/MainWindow_cs/MW_PPT.cs | 4 +- .../MainWindow_cs/MW_SelectionGestures.cs | 4 +- Ink Canvas/MainWindow_cs/MW_Settings.cs | 38 ++++++ Ink Canvas/MainWindow_cs/MW_SettingsToLoad.cs | 6 + Ink Canvas/MainWindow_cs/MW_Timer.cs | 4 +- Ink Canvas/MainWindow_cs/MW_TouchEvents.cs | 3 +- Ink Canvas/Resources/Settings.cs | 26 +++-- Ink Canvas/Windows/CountdownTimerWindow.xaml | 24 ++-- .../Windows/CountdownTimerWindow.xaml.cs | 109 ++++++++++++++++-- .../SettingsViews/SettingsWindow.xaml.cs | 4 +- 18 files changed, 229 insertions(+), 52 deletions(-) diff --git a/Ink Canvas/App.xaml.cs b/Ink Canvas/App.xaml.cs index 2e4f8e12..0bfdd393 100644 --- a/Ink Canvas/App.xaml.cs +++ b/Ink Canvas/App.xaml.cs @@ -35,7 +35,7 @@ namespace Ink_Canvas public static string RootPath = Environment.GetEnvironmentVariable("APPDATA") + "\\Ink Canvas\\"; // 新增:标记是否通过--board参数启动 - public static bool StartWithBoardMode = false; + public static bool StartWithBoardMode; // 新增:保存看门狗进程对象 private static Process watchdogProcess; // 新增:标记是否为软件内主动退出 diff --git a/Ink Canvas/Helpers/FloatingWindowInterceptor.cs b/Ink Canvas/Helpers/FloatingWindowInterceptor.cs index 665099e2..e6a63c31 100644 --- a/Ink Canvas/Helpers/FloatingWindowInterceptor.cs +++ b/Ink Canvas/Helpers/FloatingWindowInterceptor.cs @@ -229,7 +229,7 @@ namespace Ink_Canvas.Helpers private readonly Dictionary _lastScanTime = new Dictionary(); private readonly HashSet _knownWindows = new HashSet(); private readonly Dictionary _processLastScanTime = new Dictionary(); - private int _consecutiveEmptyScans = 0; + private int _consecutiveEmptyScans; private DateTime _lastSuccessfulScan = DateTime.Now; private readonly object _scanLock = new object(); diff --git a/Ink Canvas/Helpers/GlobalHotkeyManager.cs b/Ink Canvas/Helpers/GlobalHotkeyManager.cs index 917ee3f8..ffd2a48b 100644 --- a/Ink Canvas/Helpers/GlobalHotkeyManager.cs +++ b/Ink Canvas/Helpers/GlobalHotkeyManager.cs @@ -24,12 +24,12 @@ namespace Ink_Canvas.Helpers // 多屏幕支持相关字段 private Screen _currentScreen; - private bool _isMultiScreenMode = false; + private bool _isMultiScreenMode; private bool _enableScreenSpecificHotkeys = true; // 是否启用基于屏幕的热键注册 // 智能热键管理相关字段 - private bool _isWindowFocused = false; - private bool _isMouseOverWindow = false; + private bool _isWindowFocused; + private bool _isMouseOverWindow; private System.Windows.Threading.DispatcherTimer _mousePositionTimer; // 配置文件路径 diff --git a/Ink Canvas/Helpers/MultiTouchInput.cs b/Ink Canvas/Helpers/MultiTouchInput.cs index 9764d2ca..4cc6f680 100644 --- a/Ink Canvas/Helpers/MultiTouchInput.cs +++ b/Ink Canvas/Helpers/MultiTouchInput.cs @@ -30,7 +30,7 @@ namespace Ink_Canvas.Helpers public class StrokeVisual : DrawingVisual { private bool _needsRedraw = true; - private int _lastPointCount = 0; + private int _lastPointCount; private const int REDRAW_THRESHOLD = 3; /// diff --git a/Ink Canvas/Helpers/PPTInkManager.cs b/Ink Canvas/Helpers/PPTInkManager.cs index 2fee446c..57aa05b5 100644 --- a/Ink Canvas/Helpers/PPTInkManager.cs +++ b/Ink Canvas/Helpers/PPTInkManager.cs @@ -37,7 +37,7 @@ namespace Ink_Canvas.Helpers private const int MinSwitchIntervalMs = 100; // 最小切换间隔100毫秒 // 内存管理相关字段 - private long _totalMemoryUsage = 0; + private long _totalMemoryUsage; private const long MaxMemoryUsageBytes = 100 * 1024 * 1024; // 100MB限制 private DateTime _lastMemoryCleanup = DateTime.MinValue; private const int MemoryCleanupIntervalMinutes = 5; // 5分钟清理一次 diff --git a/Ink Canvas/MainWindow.xaml b/Ink Canvas/MainWindow.xaml index 49b07dd6..e9512fcb 100644 --- a/Ink Canvas/MainWindow.xaml +++ b/Ink Canvas/MainWindow.xaml @@ -3242,6 +3242,39 @@ FontFamily="Consolas" Text="{Binding ElementName=RandWindowOnceMaxStudentsSlider, Path=Value, Converter={StaticResource IntNumberToString}}" /> + + + + + + + + + + + + + + /// 保存画布上的非笔画元素(如图片、媒体元素等) diff --git a/Ink Canvas/Resources/Settings.cs b/Ink Canvas/Resources/Settings.cs index 5b62785b..690e657c 100644 --- a/Ink Canvas/Resources/Settings.cs +++ b/Ink Canvas/Resources/Settings.cs @@ -91,7 +91,7 @@ namespace Ink_Canvas [JsonProperty("enablePalmEraser")] public bool EnablePalmEraser { get; set; } = true; [JsonProperty("palmEraserSensitivity")] - public int PalmEraserSensitivity { get; set; } = 0; // 0-低敏感度, 1-中敏感度, 2-高敏感度 + public int PalmEraserSensitivity { get; set; } // 0-低敏感度, 1-中敏感度, 2-高敏感度 [JsonProperty("clearCanvasAlsoClearImages")] public bool ClearCanvasAlsoClearImages { get; set; } = true; [JsonProperty("showCircleCenter")] @@ -99,7 +99,7 @@ namespace Ink_Canvas // 墨迹渐隐功能设置 [JsonProperty("enableInkFade")] - public bool EnableInkFade { get; set; } = false; + public bool EnableInkFade { get; set; } [JsonProperty("inkFadeTime")] public int InkFadeTime { get; set; } = 3000; // 墨迹渐隐时间(毫秒) @@ -236,7 +236,7 @@ namespace Ink_Canvas public int QuickColorPaletteDisplayMode { get; set; } = 1; [JsonProperty("enableHotkeysInMouseMode")] - public bool EnableHotkeysInMouseMode { get; set; } = false; + public bool EnableHotkeysInMouseMode { get; set; } } @@ -310,9 +310,9 @@ namespace Ink_Canvas [JsonProperty("isAlwaysGoToFirstPageOnReenter")] public bool IsAlwaysGoToFirstPageOnReenter { get; set; } [JsonProperty("enablePowerPointEnhancement")] - public bool EnablePowerPointEnhancement { get; set; } = false; + public bool EnablePowerPointEnhancement { get; set; } [JsonProperty("showGestureButtonInSlideShow")] - public bool ShowGestureButtonInSlideShow { get; set; } = false; + public bool ShowGestureButtonInSlideShow { get; set; } } public class Automation @@ -452,7 +452,7 @@ namespace Ink_Canvas public int AutoDelSavedFilesDaysThreshold = 15; [JsonProperty("keepFoldAfterSoftwareExit")] - public bool KeepFoldAfterSoftwareExit { get; set; } = false; + public bool KeepFoldAfterSoftwareExit { get; set; } [JsonProperty("isSaveFullPageStrokes")] public bool IsSaveFullPageStrokes; @@ -467,13 +467,13 @@ namespace Ink_Canvas public class FloatingWindowInterceptorSettings { [JsonProperty("isEnabled")] - public bool IsEnabled { get; set; } = false; + public bool IsEnabled { get; set; } [JsonProperty("scanIntervalMs")] public int ScanIntervalMs { get; set; } = 5000; [JsonProperty("autoStart")] - public bool AutoStart { get; set; } = false; + public bool AutoStart { get; set; } [JsonProperty("showNotifications")] public bool ShowNotifications { get; set; } = true; @@ -622,11 +622,17 @@ namespace Ink_Canvas [JsonProperty("directCallCiRand")] public bool DirectCallCiRand { get; set; } [JsonProperty("externalCallerType")] - public int ExternalCallerType { get; set; } = 0; + public int ExternalCallerType { get; set; } [JsonProperty("selectedBackgroundIndex")] public int SelectedBackgroundIndex { get; set; } [JsonProperty("customPickNameBackgrounds")] public List CustomPickNameBackgrounds { get; set; } = new List(); + [JsonProperty("useLegacyTimerUI")] + public bool UseLegacyTimerUI { get; set; } + [JsonProperty("timerVolume")] + public double TimerVolume { get; set; } = 1.0; + [JsonProperty("customTimerSoundPath")] + public string CustomTimerSoundPath { get; set; } = ""; } public class CustomPickNameBackground @@ -668,6 +674,6 @@ namespace Ink_Canvas public class ModeSettings { [JsonProperty("isPPTOnlyMode")] - public bool IsPPTOnlyMode { get; set; } = false; // 是否为仅PPT模式,默认为false(正常模式) + public bool IsPPTOnlyMode { get; set; } // 是否为仅PPT模式,默认为false(正常模式) } } diff --git a/Ink Canvas/Windows/CountdownTimerWindow.xaml b/Ink Canvas/Windows/CountdownTimerWindow.xaml index 6fed4d88..0f820a2d 100644 --- a/Ink Canvas/Windows/CountdownTimerWindow.xaml +++ b/Ink Canvas/Windows/CountdownTimerWindow.xaml @@ -44,18 +44,18 @@ @@ -91,18 +91,18 @@ diff --git a/Ink Canvas/Windows/CountdownTimerWindow.xaml.cs b/Ink Canvas/Windows/CountdownTimerWindow.xaml.cs index a90e6b1d..588af4b9 100644 --- a/Ink Canvas/Windows/CountdownTimerWindow.xaml.cs +++ b/Ink Canvas/Windows/CountdownTimerWindow.xaml.cs @@ -1,4 +1,5 @@ using Ink_Canvas.Helpers; +using Ink_Canvas.Resources; using System; using System.Media; using System.Timers; @@ -6,6 +7,7 @@ using System.Windows; using System.Windows.Input; using System.Windows.Interop; using System.Windows.Media; +using System.Windows.Media.Imaging; namespace Ink_Canvas { @@ -21,6 +23,7 @@ namespace Ink_Canvas timer.Elapsed += Timer_Elapsed; timer.Interval = 50; + InitializeUI(); } private void Timer_Elapsed(object sender, ElapsedEventArgs e) @@ -62,24 +65,25 @@ namespace Ink_Canvas Application.Current.Dispatcher.Invoke(() => { //Play sound - player.Stream = Properties.Resources.TimerDownNotice; - player.Play(); + PlayTimerSound(); }); } } SoundPlayer player = new SoundPlayer(); + MediaPlayer mediaPlayer = new MediaPlayer(); - int hour = 0; + int hour; int minute = 1; - int second = 0; + int second; int totalSeconds = 60; DateTime startTime = DateTime.Now; DateTime pauseTime = DateTime.Now; - bool isTimerRunning = false; - bool isPaused = false; + bool isTimerRunning; + bool isPaused; + bool useLegacyUI; Timer timer = new Timer(); @@ -334,6 +338,97 @@ namespace Ink_Canvas } } + private void InitializeUI() + { + // 从设置中读取配置 + if (MainWindow.Settings.RandSettings != null) + { + useLegacyUI = MainWindow.Settings.RandSettings.UseLegacyTimerUI; + UpdateButtonTexts(); + } + } + + public void RefreshUI() + { + InitializeUI(); + } + + private void UpdateButtonTexts() + { + if (useLegacyUI) + { + // 老版UI:使用+5, +1, -1, -5 + HourPlus5Text.Text = "+5"; + 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"; + SecondMinus5Text.Text = "-5"; + } + else + { + // 新版UI:使用箭头符号 + HourPlus5Text.Text = "∧∧"; + HourPlus1Text.Text = "∧"; + HourMinus1Text.Text = "∨"; + HourMinus5Text.Text = "∨∨"; + + MinutePlus5Text.Text = "∧∧"; + MinutePlus1Text.Text = "∧"; + MinuteMinus1Text.Text = "∨"; + MinuteMinus5Text.Text = "∨∨"; + + SecondPlus5Text.Text = "∧∧"; + SecondPlus1Text.Text = "∧"; + SecondMinus1Text.Text = "∨"; + SecondMinus5Text.Text = "∨∨"; + } + } + + private void PlayTimerSound() + { + try + { + double volume = MainWindow.Settings.RandSettings?.TimerVolume ?? 1.0; + mediaPlayer.Volume = volume; + + if (!string.IsNullOrEmpty(MainWindow.Settings.RandSettings?.CustomTimerSoundPath) && + System.IO.File.Exists(MainWindow.Settings.RandSettings.CustomTimerSoundPath)) + { + // 播放自定义铃声 + mediaPlayer.Open(new Uri(MainWindow.Settings.RandSettings.CustomTimerSoundPath)); + } + else + { + // 播放默认铃声 + string tempPath = System.IO.Path.GetTempFileName() + ".wav"; + using (var stream = Properties.Resources.TimerDownNotice) + { + using (var fileStream = new System.IO.FileStream(tempPath, System.IO.FileMode.Create)) + { + stream.CopyTo(fileStream); + } + } + mediaPlayer.Open(new Uri(tempPath)); + } + + mediaPlayer.Play(); + } + catch (Exception ex) + { + // 如果播放失败,静默处理 + System.Diagnostics.Debug.WriteLine($"播放计时器铃声失败: {ex.Message}"); + } + } + private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { isTimerRunning = false; @@ -344,7 +439,7 @@ namespace Ink_Canvas Close(); } - private bool _isInCompact = false; + private bool _isInCompact; private void BtnMinimal_OnMouseUp(object sender, MouseButtonEventArgs e) { diff --git a/Ink Canvas/Windows/SettingsViews/SettingsWindow.xaml.cs b/Ink Canvas/Windows/SettingsViews/SettingsWindow.xaml.cs index 583f1021..2b9f621b 100644 --- a/Ink Canvas/Windows/SettingsViews/SettingsWindow.xaml.cs +++ b/Ink Canvas/Windows/SettingsViews/SettingsWindow.xaml.cs @@ -398,7 +398,7 @@ namespace Ink_Canvas.Windows ((Border)border).Background = new SolidColorBrush(Color.FromRgb(138, 138, 138)); } - private Border _sidebarItemMouseDownBorder = null; + private Border _sidebarItemMouseDownBorder; private void SidebarItem_MouseDown(object sender, MouseButtonEventArgs e) { @@ -999,7 +999,7 @@ namespace Ink_Canvas.Windows public Image ThumbImage { get; set; } public Border TrackBorder { get; set; } public Border ValueBorder { get; set; } - public bool IsTouchCaptured { get; set; } = false; + public bool IsTouchCaptured { get; set; } } #endregion