代码清理

This commit is contained in:
PrefacedCorg
2025-12-27 12:05:34 +08:00
parent d7e8330016
commit 783e5c43a5
9 changed files with 53 additions and 46 deletions
+2 -2
View File
@@ -454,7 +454,7 @@ namespace Ink_Canvas.Helpers
{ {
// 如果设置允许,则在鼠标模式下也启用快捷键 // 如果设置允许,则在鼠标模式下也启用快捷键
EnableHotkeyRegistration(); EnableHotkeyRegistration();
if (_hotkeysShouldBeRegistered && _registeredHotkeys.Count == 0) if (_hotkeysShouldBeRegistered && _registeredHotkeys.Count == 0)
{ {
LoadHotkeysFromSettings(); LoadHotkeysFromSettings();
@@ -470,7 +470,7 @@ namespace Ink_Canvas.Helpers
{ {
// 非鼠标模式下启用快捷键 // 非鼠标模式下启用快捷键
EnableHotkeyRegistration(); EnableHotkeyRegistration();
if (_hotkeysShouldBeRegistered && _registeredHotkeys.Count == 0) if (_hotkeysShouldBeRegistered && _registeredHotkeys.Count == 0)
{ {
LoadHotkeysFromSettings(); LoadHotkeysFromSettings();
+10 -10
View File
@@ -23,10 +23,10 @@ namespace Ink_Canvas.Helpers
public VisualCanvas() public VisualCanvas()
{ {
CacheMode = new BitmapCache(); CacheMode = new BitmapCache();
RenderOptions.SetBitmapScalingMode(this, BitmapScalingMode.HighQuality); RenderOptions.SetBitmapScalingMode(this, BitmapScalingMode.HighQuality);
RenderOptions.SetEdgeMode(this, EdgeMode.Aliased); RenderOptions.SetEdgeMode(this, EdgeMode.Aliased);
RenderOptions.SetCachingHint(this, CachingHint.Cache); RenderOptions.SetCachingHint(this, CachingHint.Cache);
} }
public void AddVisual(DrawingVisual visual) public void AddVisual(DrawingVisual visual)
@@ -52,9 +52,9 @@ namespace Ink_Canvas.Helpers
/// </summary> /// </summary>
public class StrokeVisual public class StrokeVisual
{ {
private int _lastDrawnPointCount = 0; private int _lastDrawnPointCount = 0;
private const int INCREMENTAL_DRAW_THRESHOLD = 2; private const int INCREMENTAL_DRAW_THRESHOLD = 2;
private VisualCanvas _visualCanvas; private VisualCanvas _visualCanvas;
/// <summary> /// <summary>
/// 创建显示笔迹的类 /// 创建显示笔迹的类
@@ -118,10 +118,10 @@ namespace Ink_Canvas.Helpers
var points = Stroke.StylusPoints; var points = Stroke.StylusPoints;
var drawingAttributes = Stroke.DrawingAttributes; var drawingAttributes = Stroke.DrawingAttributes;
// 创建新的DrawingVisual用于绘制这个点段 // 创建新的DrawingVisual用于绘制这个点段
var segmentVisual = new DrawingVisual(); var segmentVisual = new DrawingVisual();
RenderOptions.SetBitmapScalingMode(segmentVisual, BitmapScalingMode.HighQuality); RenderOptions.SetBitmapScalingMode(segmentVisual, BitmapScalingMode.HighQuality);
RenderOptions.SetEdgeMode(segmentVisual, EdgeMode.Aliased); RenderOptions.SetEdgeMode(segmentVisual, EdgeMode.Aliased);
RenderOptions.SetCachingHint(segmentVisual, CachingHint.Cache); RenderOptions.SetCachingHint(segmentVisual, CachingHint.Cache);
@@ -149,7 +149,7 @@ namespace Ink_Canvas.Helpers
// 只有一个点,绘制圆点 // 只有一个点,绘制圆点
var brush = new SolidColorBrush(drawingAttributes.Color); var brush = new SolidColorBrush(drawingAttributes.Color);
var point = points[startIndex]; var point = points[startIndex];
dc.DrawEllipse(brush, null, new Point(point.X, point.Y), dc.DrawEllipse(brush, null, new Point(point.X, point.Y),
drawingAttributes.Width / 2, drawingAttributes.Height / 2); drawingAttributes.Width / 2, drawingAttributes.Height / 2);
} }
} }
+2 -2
View File
@@ -1,5 +1,5 @@
using Microsoft.Office.Interop.PowerPoint; using Microsoft.Office.Core;
using Microsoft.Office.Core; using Microsoft.Office.Interop.PowerPoint;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
+1 -1
View File
@@ -977,7 +977,7 @@ namespace Ink_Canvas
if (DateTime.Now < pauseUntilDate) if (DateTime.Now < pauseUntilDate)
{ {
LogHelper.WriteLogToFile($"AutoUpdate | 自动更新已暂停,直到 {pauseUntilDate:yyyy-MM-dd}"); LogHelper.WriteLogToFile($"AutoUpdate | 自动更新已暂停,直到 {pauseUntilDate:yyyy-MM-dd}");
return; return;
} }
else else
{ {
+21 -13
View File
@@ -73,35 +73,40 @@ namespace Ink_Canvas
/// <summary> /// <summary>
/// 用於更新浮動工具欄的"手勢"按鈕和白板工具欄的"手勢"按鈕的樣式(開啟和關閉狀態) /// 用於更新浮動工具欄的"手勢"按鈕和白板工具欄的"手勢"按鈕的樣式(開啟和關閉狀態)
/// </summary> /// </summary>
private void CheckEnableTwoFingerGestureBtnColorPrompt() { private void CheckEnableTwoFingerGestureBtnColorPrompt()
{
// 根据主题选择手势图标和颜色 // 根据主题选择手势图标和颜色
bool isDarkTheme = Settings.Appearance.Theme == 1 || bool isDarkTheme = Settings.Appearance.Theme == 1 ||
(Settings.Appearance.Theme == 2 && !IsSystemThemeLight()); (Settings.Appearance.Theme == 2 && !IsSystemThemeLight());
bool isLightTheme = !isDarkTheme; bool isLightTheme = !isDarkTheme;
string gestureIconPath = isLightTheme ? "/Resources/new-icons/gesture.png" : "/Resources/new-icons/gesture_white.png"; string gestureIconPath = isLightTheme ? "/Resources/new-icons/gesture.png" : "/Resources/new-icons/gesture_white.png";
// 根据主题设置白板模式下的颜色 // 根据主题设置白板模式下的颜色
Color boardBgColor, boardIconColor, boardTextColor, boardBorderColor; Color boardBgColor, boardIconColor, boardTextColor, boardBorderColor;
if (isLightTheme) { if (isLightTheme)
{
// 浅色主题 // 浅色主题
boardBgColor = Color.FromRgb(244, 244, 245); boardBgColor = Color.FromRgb(244, 244, 245);
boardIconColor = Color.FromRgb(24, 24, 27); boardIconColor = Color.FromRgb(24, 24, 27);
boardTextColor = Color.FromRgb(24, 24, 27); boardTextColor = Color.FromRgb(24, 24, 27);
boardBorderColor = Color.FromRgb(161, 161, 170); boardBorderColor = Color.FromRgb(161, 161, 170);
} else { }
else
{
// 深色主题 // 深色主题
boardBgColor = Color.FromRgb(39, 39, 42); boardBgColor = Color.FromRgb(39, 39, 42);
boardIconColor = Color.FromRgb(244, 244, 245); boardIconColor = Color.FromRgb(244, 244, 245);
boardTextColor = Color.FromRgb(244, 244, 245); boardTextColor = Color.FromRgb(244, 244, 245);
boardBorderColor = Color.FromRgb(113, 113, 122); boardBorderColor = Color.FromRgb(113, 113, 122);
} }
if (ToggleSwitchEnableMultiTouchMode.IsOn) { if (ToggleSwitchEnableMultiTouchMode.IsOn)
{
TwoFingerGestureSimpleStackPanel.Opacity = 0.5; TwoFingerGestureSimpleStackPanel.Opacity = 0.5;
TwoFingerGestureSimpleStackPanel.IsHitTestVisible = false; TwoFingerGestureSimpleStackPanel.IsHitTestVisible = false;
EnableTwoFingerGestureBtn.Source = EnableTwoFingerGestureBtn.Source =
new BitmapImage(new Uri(gestureIconPath, UriKind.Relative)); new BitmapImage(new Uri(gestureIconPath, UriKind.Relative));
BoardGesture.Background = new SolidColorBrush(boardBgColor); BoardGesture.Background = new SolidColorBrush(boardBgColor);
BoardGestureGeometry.Brush = new SolidColorBrush(boardIconColor); BoardGestureGeometry.Brush = new SolidColorBrush(boardIconColor);
BoardGestureGeometry2.Brush = new SolidColorBrush(boardIconColor); BoardGestureGeometry2.Brush = new SolidColorBrush(boardIconColor);
@@ -110,25 +115,28 @@ namespace Ink_Canvas
BoardGestureGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.DisabledGestureIcon); BoardGestureGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.DisabledGestureIcon);
BoardGestureGeometry2.Geometry = Geometry.Parse("F0 M24,24z M0,0z"); BoardGestureGeometry2.Geometry = Geometry.Parse("F0 M24,24z M0,0z");
} }
else { else
{
TwoFingerGestureSimpleStackPanel.Opacity = 1; TwoFingerGestureSimpleStackPanel.Opacity = 1;
TwoFingerGestureSimpleStackPanel.IsHitTestVisible = true; TwoFingerGestureSimpleStackPanel.IsHitTestVisible = true;
if (Settings.Gesture.IsEnableTwoFingerGesture) { if (Settings.Gesture.IsEnableTwoFingerGesture)
{
EnableTwoFingerGestureBtn.Source = EnableTwoFingerGestureBtn.Source =
new BitmapImage(new Uri("/Resources/new-icons/gesture-enabled.png", UriKind.Relative)); new BitmapImage(new Uri("/Resources/new-icons/gesture-enabled.png", UriKind.Relative));
BoardGesture.Background = new SolidColorBrush(Color.FromRgb(37, 99, 235)); BoardGesture.Background = new SolidColorBrush(Color.FromRgb(37, 99, 235));
BoardGestureGeometry.Brush = new SolidColorBrush(Colors.GhostWhite); BoardGestureGeometry.Brush = new SolidColorBrush(Colors.GhostWhite);
BoardGestureGeometry2.Brush = new SolidColorBrush(Colors.GhostWhite); BoardGestureGeometry2.Brush = new SolidColorBrush(Colors.GhostWhite);
BoardGestureLabel.Foreground = new SolidColorBrush(Colors.GhostWhite); BoardGestureLabel.Foreground = new SolidColorBrush(Colors.GhostWhite);
BoardGesture.BorderBrush = new SolidColorBrush(Color.FromRgb(37, 99, 235)); BoardGesture.BorderBrush = new SolidColorBrush(Color.FromRgb(37, 99, 235));
BoardGestureGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.EnabledGestureIcon); BoardGestureGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.EnabledGestureIcon);
BoardGestureGeometry2.Geometry = Geometry.Parse("F0 M24,24z M0,0z "+XamlGraphicsIconGeometries.EnabledGestureIconBadgeCheck); BoardGestureGeometry2.Geometry = Geometry.Parse("F0 M24,24z M0,0z " + XamlGraphicsIconGeometries.EnabledGestureIconBadgeCheck);
} }
else { else
{
EnableTwoFingerGestureBtn.Source = EnableTwoFingerGestureBtn.Source =
new BitmapImage(new Uri(gestureIconPath, UriKind.Relative)); new BitmapImage(new Uri(gestureIconPath, UriKind.Relative));
BoardGesture.Background = new SolidColorBrush(boardBgColor); BoardGesture.Background = new SolidColorBrush(boardBgColor);
BoardGestureGeometry.Brush = new SolidColorBrush(boardIconColor); BoardGestureGeometry.Brush = new SolidColorBrush(boardIconColor);
BoardGestureGeometry2.Brush = new SolidColorBrush(boardIconColor); BoardGestureGeometry2.Brush = new SolidColorBrush(boardIconColor);
+5 -5
View File
@@ -5,8 +5,8 @@ using OSVersionExtension;
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Threading.Tasks;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Forms; using System.Windows.Forms;
@@ -1031,7 +1031,7 @@ namespace Ink_Canvas
bool isHalfOpacity = (bool)((CheckBox)sender).IsChecked; bool isHalfOpacity = (bool)((CheckBox)sender).IsChecked;
c[1] = isHalfOpacity ? '2' : '1'; c[1] = isHalfOpacity ? '2' : '1';
Settings.PowerPointSettings.PPTSButtonsOption = int.Parse(new string(c)); Settings.PowerPointSettings.PPTSButtonsOption = int.Parse(new string(c));
// 如果开启半透明选项,设置默认透明度为0.5;否则为1.0 // 如果开启半透明选项,设置默认透明度为0.5;否则为1.0
if (isHalfOpacity) if (isHalfOpacity)
{ {
@@ -1051,7 +1051,7 @@ namespace Ink_Canvas
PPTLSButtonOpacityValueSlider.Value = Settings.PowerPointSettings.PPTLSButtonOpacity; PPTLSButtonOpacityValueSlider.Value = Settings.PowerPointSettings.PPTLSButtonOpacity;
PPTRSButtonOpacityValueSlider.Value = Settings.PowerPointSettings.PPTRSButtonOpacity; PPTRSButtonOpacityValueSlider.Value = Settings.PowerPointSettings.PPTRSButtonOpacity;
} }
SaveSettingsToFile(); SaveSettingsToFile();
// 更新PPT UI管理器设置 // 更新PPT UI管理器设置
if (_pptUIManager != null && BtnPPTSlideShowEnd.Visibility == Visibility.Visible) if (_pptUIManager != null && BtnPPTSlideShowEnd.Visibility == Visibility.Visible)
@@ -1106,7 +1106,7 @@ namespace Ink_Canvas
bool isHalfOpacity = (bool)((CheckBox)sender).IsChecked; bool isHalfOpacity = (bool)((CheckBox)sender).IsChecked;
c[1] = isHalfOpacity ? '2' : '1'; c[1] = isHalfOpacity ? '2' : '1';
Settings.PowerPointSettings.PPTBButtonsOption = int.Parse(new string(c)); Settings.PowerPointSettings.PPTBButtonsOption = int.Parse(new string(c));
// 如果开启半透明选项,设置默认透明度为0.5;否则为1.0 // 如果开启半透明选项,设置默认透明度为0.5;否则为1.0
if (isHalfOpacity) if (isHalfOpacity)
{ {
@@ -1126,7 +1126,7 @@ namespace Ink_Canvas
PPTLBButtonOpacityValueSlider.Value = Settings.PowerPointSettings.PPTLBButtonOpacity; PPTLBButtonOpacityValueSlider.Value = Settings.PowerPointSettings.PPTLBButtonOpacity;
PPTRBButtonOpacityValueSlider.Value = Settings.PowerPointSettings.PPTRBButtonOpacity; PPTRBButtonOpacityValueSlider.Value = Settings.PowerPointSettings.PPTRBButtonOpacity;
} }
SaveSettingsToFile(); SaveSettingsToFile();
UpdatePPTUIManagerSettings(); UpdatePPTUIManagerSettings();
UpdatePPTBtnPreview(); UpdatePPTBtnPreview();
@@ -557,12 +557,12 @@ namespace Ink_Canvas
// 重用之前定义的sopsc和bopsc变量 // 重用之前定义的sopsc和bopsc变量
bool isSideHalfOpacity = sopsc.Length >= 2 && sopsc[1] == '2'; bool isSideHalfOpacity = sopsc.Length >= 2 && sopsc[1] == '2';
// 如果透明度为0或未设置,根据半透明选项设置默认值 // 如果透明度为0或未设置,根据半透明选项设置默认值
if (Settings.PowerPointSettings.PPTLSButtonOpacity == 0.0 || if (Settings.PowerPointSettings.PPTLSButtonOpacity == 0.0 ||
(Settings.PowerPointSettings.PPTLSButtonOpacity == 1.0 && isSideHalfOpacity)) (Settings.PowerPointSettings.PPTLSButtonOpacity == 1.0 && isSideHalfOpacity))
{ {
Settings.PowerPointSettings.PPTLSButtonOpacity = isSideHalfOpacity ? 0.5 : 1.0; Settings.PowerPointSettings.PPTLSButtonOpacity = isSideHalfOpacity ? 0.5 : 1.0;
} }
if (Settings.PowerPointSettings.PPTRSButtonOpacity == 0.0 || if (Settings.PowerPointSettings.PPTRSButtonOpacity == 0.0 ||
(Settings.PowerPointSettings.PPTRSButtonOpacity == 1.0 && isSideHalfOpacity)) (Settings.PowerPointSettings.PPTRSButtonOpacity == 1.0 && isSideHalfOpacity))
{ {
Settings.PowerPointSettings.PPTRSButtonOpacity = isSideHalfOpacity ? 0.5 : 1.0; Settings.PowerPointSettings.PPTRSButtonOpacity = isSideHalfOpacity ? 0.5 : 1.0;
@@ -572,12 +572,12 @@ namespace Ink_Canvas
bool isBottomHalfOpacity = bopsc.Length >= 2 && bopsc[1] == '2'; bool isBottomHalfOpacity = bopsc.Length >= 2 && bopsc[1] == '2';
// 如果透明度为0或未设置,根据半透明选项设置默认值 // 如果透明度为0或未设置,根据半透明选项设置默认值
if (Settings.PowerPointSettings.PPTLBButtonOpacity == 0.0 || if (Settings.PowerPointSettings.PPTLBButtonOpacity == 0.0 ||
(Settings.PowerPointSettings.PPTLBButtonOpacity == 1.0 && isBottomHalfOpacity)) (Settings.PowerPointSettings.PPTLBButtonOpacity == 1.0 && isBottomHalfOpacity))
{ {
Settings.PowerPointSettings.PPTLBButtonOpacity = isBottomHalfOpacity ? 0.5 : 1.0; Settings.PowerPointSettings.PPTLBButtonOpacity = isBottomHalfOpacity ? 0.5 : 1.0;
} }
if (Settings.PowerPointSettings.PPTRBButtonOpacity == 0.0 || if (Settings.PowerPointSettings.PPTRBButtonOpacity == 0.0 ||
(Settings.PowerPointSettings.PPTRBButtonOpacity == 1.0 && isBottomHalfOpacity)) (Settings.PowerPointSettings.PPTRBButtonOpacity == 1.0 && isBottomHalfOpacity))
{ {
Settings.PowerPointSettings.PPTRBButtonOpacity = isBottomHalfOpacity ? 0.5 : 1.0; Settings.PowerPointSettings.PPTRBButtonOpacity = isBottomHalfOpacity ? 0.5 : 1.0;
+5 -5
View File
@@ -591,9 +591,9 @@ namespace Ink_Canvas
for (int i = 0; i < count && candidatePool.Count > 0; i++) for (int i = 0; i < count && candidatePool.Count > 0; i++)
{ {
int randomIndex = random.Next(0, candidatePool.Count); int randomIndex = random.Next(0, candidatePool.Count);
selectedNames.Add(candidatePool[randomIndex]); selectedNames.Add(candidatePool[randomIndex]);
int lastIndex = candidatePool.Count - 1; int lastIndex = candidatePool.Count - 1;
if (randomIndex != lastIndex) if (randomIndex != lastIndex)
{ {
@@ -1258,17 +1258,17 @@ namespace Ink_Canvas
// 清空名单 // 清空名单
nameList.Clear(); nameList.Clear();
UpdateListCountDisplay(); UpdateListCountDisplay();
// 清空点名历史记录 // 清空点名历史记录
lock (historyLock) lock (historyLock)
{ {
// 重置历史记录数据 // 重置历史记录数据
historyData = new RollCallHistoryData(); historyData = new RollCallHistoryData();
// 保存到文件 // 保存到文件
SaveRollCallHistory(); SaveRollCallHistory();
} }
UpdateStatusDisplay("名单和历史记录已清空"); UpdateStatusDisplay("名单和历史记录已清空");
} }
catch (Exception ex) catch (Exception ex)
+3 -4
View File
@@ -107,8 +107,7 @@ namespace Ink_Canvas
if (settings.RandSettings.SelectedBackgroundIndex <= 0) if (settings.RandSettings.SelectedBackgroundIndex <= 0)
{ {
// 没有自定义背景时,使用主题背景色 // 没有自定义背景时,使用主题背景色
var backgroundBrush = Application.Current.FindResource("RandWindowBackground") as SolidColorBrush; if (Application.Current.FindResource("RandWindowBackground") is SolidColorBrush backgroundBrush)
if (backgroundBrush != null)
{ {
MainBorder.Background = backgroundBrush; MainBorder.Background = backgroundBrush;
} }
@@ -238,7 +237,7 @@ namespace Ink_Canvas
int randomIndex = random.Next(0, animationPool.Count); int randomIndex = random.Next(0, animationPool.Count);
int selectedNumber = animationPool[randomIndex]; int selectedNumber = animationPool[randomIndex];
int lastIndex = animationPool.Count - 1; int lastIndex = animationPool.Count - 1;
if (randomIndex != lastIndex) if (randomIndex != lastIndex)
{ {
@@ -273,7 +272,7 @@ namespace Ink_Canvas
{ {
int randomIndex = random.Next(0, candidatePool.Count); int randomIndex = random.Next(0, candidatePool.Count);
int selectedNumber = candidatePool[randomIndex]; int selectedNumber = candidatePool[randomIndex];
int lastIndex = candidatePool.Count - 1; int lastIndex = candidatePool.Count - 1;
if (randomIndex != lastIndex) if (randomIndex != lastIndex)
{ {