1145141919810

代码清理
This commit is contained in:
PrefacedCorg
2025-10-03 17:08:46 +08:00
parent 8ad6ca8d41
commit d9e8f64699
37 changed files with 563 additions and 566 deletions
@@ -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)
@@ -92,7 +92,7 @@ namespace Ink_Canvas
LogHelper.WriteLogToFile($"应用主题时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 更新为浅色主题颜色
/// </summary>
@@ -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);
}
}
/// <summary>
/// 更新为深色主题颜色
/// </summary>
@@ -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);
}
}
/// <summary>
/// 检查系统是否为浅色主题
/// </summary>
@@ -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)
@@ -33,12 +33,12 @@ namespace Ink_Canvas
{
InitializeComponent();
this.channel = channel;
// 应用当前主题
ApplyCurrentTheme();
LoadVersions();
// 添加窗口拖动功能
MouseDown += (sender, e) =>
{
@@ -48,7 +48,7 @@ namespace Ink_Canvas
}
};
}
/// <summary>
/// 应用当前主题设置
/// </summary>
@@ -86,7 +86,7 @@ namespace Ink_Canvas
LogHelper.WriteLogToFile($"应用主题时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 更新为浅色主题颜色
/// </summary>
@@ -104,7 +104,7 @@ namespace Ink_Canvas
LogHelper.WriteLogToFile($"更新浅色主题颜色时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 更新为深色主题颜色
/// </summary>
@@ -122,7 +122,7 @@ namespace Ink_Canvas
LogHelper.WriteLogToFile($"更新深色主题颜色时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
/// <summary>
/// 检查系统是否为浅色主题
/// </summary>
@@ -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;
+37 -38
View File
@@ -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;
}