From 86b52b76ed46df5cd8b87c5627c4ca8dabd94989 Mon Sep 17 00:00:00 2001 From: unknown <2564608840@qq.com> Date: Wed, 16 Jul 2025 09:16:36 +0800 Subject: [PATCH] =?UTF-8?q?add:=E8=87=AA=E5=AE=9A=E4=B9=89=E7=99=BD?= =?UTF-8?q?=E6=9D=BF=E8=83=8C=E6=99=AF=E8=89=B2=20#39?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/MainWindow.xaml | 3 + Ink Canvas/MainWindow.xaml.cs | 31 + Ink Canvas/MainWindow_cs/MW_BoardIcons.cs | 717 ++++++++++++++++++ Ink Canvas/MainWindow_cs/MW_Colors.cs | 14 +- .../MainWindow_cs/MW_FloatingBarIcons.cs | 22 +- Ink Canvas/Resources/Settings.cs | 5 +- 6 files changed, 787 insertions(+), 5 deletions(-) diff --git a/Ink Canvas/MainWindow.xaml b/Ink Canvas/MainWindow.xaml index 17ef03bd..197d77a4 100644 --- a/Ink Canvas/MainWindow.xaml +++ b/Ink Canvas/MainWindow.xaml @@ -7035,6 +7035,9 @@ + + + diff --git a/Ink Canvas/MainWindow.xaml.cs b/Ink Canvas/MainWindow.xaml.cs index 1b196557..f941929b 100644 --- a/Ink Canvas/MainWindow.xaml.cs +++ b/Ink Canvas/MainWindow.xaml.cs @@ -22,6 +22,7 @@ using System.Windows.Data; using System.Windows.Documents; using System.Windows.Media.Animation; using System.Reflection; +using Brushes = System.Windows.Media.Brushes; using Point = System.Windows.Point; namespace Ink_Canvas { @@ -179,6 +180,9 @@ namespace Ink_Canvas { //加载设置 LoadSettings(true); + // 加载自定义背景颜色 + LoadCustomBackgroundColor(); + // 注册设置面板滚动事件 if (SettingsPanelScrollViewer != null) { @@ -206,6 +210,9 @@ namespace Ink_Canvas { new SolidColorBrush(System.Windows.Media.Color.FromArgb(127, 24, 24, 27)); BtnRightWhiteBoardSwitchPreviousLabel.Opacity = 0.5; + // 应用颜色主题,这将考虑自定义背景色 + CheckColorTheme(true); + BtnWhiteBoardSwitchPrevious.IsEnabled = CurrentWhiteboardIndex != 1; BorderInkReplayToolBox.Visibility = Visibility.Collapsed; @@ -230,6 +237,30 @@ namespace Ink_Canvas { // 注册系统关机事件处理 RegisterShutdownHandler(); + + // 设置默认为黑板模式 + Settings.Canvas.UsingWhiteboard = false; + Settings.Canvas.CustomBackgroundColor = "#162924"; // 黑板默认颜色 RGB(22, 41, 36) + SaveSettingsToFile(); + + // 如果当前不是黑板模式,则切换到黑板模式 + if (currentMode == 0) + { + // 延迟执行,确保UI已完全加载 + Dispatcher.BeginInvoke(new Action(() => { + // 重新加载自定义背景颜色 + LoadCustomBackgroundColor(); + + // 模拟点击切换按钮进入黑板模式 + if (GridTransparencyFakeBackground.Background != Brushes.Transparent) + { + BtnSwitch_Click(BtnSwitch, null); + } + + // 确保背景颜色正确设置为黑板颜色 + CheckColorTheme(true); + }), System.Windows.Threading.DispatcherPriority.Loaded); + } } private void SystemEventsOnDisplaySettingsChanged(object sender, EventArgs e) { diff --git a/Ink Canvas/MainWindow_cs/MW_BoardIcons.cs b/Ink Canvas/MainWindow_cs/MW_BoardIcons.cs index ea820a31..3a4807fc 100644 --- a/Ink Canvas/MainWindow_cs/MW_BoardIcons.cs +++ b/Ink Canvas/MainWindow_cs/MW_BoardIcons.cs @@ -1,30 +1,693 @@ using Ink_Canvas.Helpers; +using System; using System.Diagnostics; using System.Windows; using System.Windows.Controls; using System.Windows.Ink; using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Controls.Primitives; namespace Ink_Canvas { public partial class MainWindow : Window { private void BoardChangeBackgroundColorBtn_MouseUp(object sender, RoutedEventArgs e) { if (!isLoaded) return; + + // 创建背景选项面板(如果不存在) + if (BackgroundPalette == null) + { + CreateBackgroundPalette(); + } + + // 显示或隐藏背景选项面板 + if (BackgroundPalette != null) + { + if (BackgroundPalette.Visibility == Visibility.Visible) + { + // 如果面板已经显示,则隐藏它 + AnimationsHelper.HideWithSlideAndFade(BackgroundPalette); + } + else + { + // 隐藏其他可能显示的面板 + AnimationsHelper.HideWithSlideAndFade(EraserSizePanel); + AnimationsHelper.HideWithSlideAndFade(BorderTools); + AnimationsHelper.HideWithSlideAndFade(BoardBorderTools); + AnimationsHelper.HideWithSlideAndFade(PenPalette); + AnimationsHelper.HideWithSlideAndFade(BoardPenPalette); + AnimationsHelper.HideWithSlideAndFade(BorderDrawShape); + AnimationsHelper.HideWithSlideAndFade(BoardBorderDrawShape); + AnimationsHelper.HideWithSlideAndFade(BoardEraserSizePanel); + AnimationsHelper.HideWithSlideAndFade(TwoFingerGestureBorder); + AnimationsHelper.HideWithSlideAndFade(BoardTwoFingerGestureBorder); + + // 显示背景选项面板 + AnimationsHelper.ShowWithSlideFromBottomAndFade(BackgroundPalette); + } + return; + } + + // 原有的背景切换代码 Settings.Canvas.UsingWhiteboard = !Settings.Canvas.UsingWhiteboard; SaveSettingsToFile(); if (Settings.Canvas.UsingWhiteboard) { if (inkColor == 5) lastBoardInkColor = 0; ICCWaterMarkDark.Visibility = Visibility.Visible; ICCWaterMarkWhite.Visibility = Visibility.Collapsed; + + // 设置为白板默认背景色 + Color defaultWhiteboardColor = Color.FromRgb(234, 235, 237); + + if (currentMode == 1) // 白板模式 + { + // 设置背景为默认白板背景色 + GridBackgroundCover.Background = new SolidColorBrush(defaultWhiteboardColor); + + // 更新RGB滑块的值为默认白板背景色 + if (BackgroundPalette != null && BackgroundPalette.Visibility == Visibility.Visible) + { + UpdateRGBSliders(defaultWhiteboardColor); + } + + // 更新自定义背景色为默认白板背景色 + CustomBackgroundColor = defaultWhiteboardColor; + + // 保存到设置 + string colorHex = $"#{defaultWhiteboardColor.R:X2}{defaultWhiteboardColor.G:X2}{defaultWhiteboardColor.B:X2}"; + Settings.Canvas.CustomBackgroundColor = colorHex; + SaveSettingsToFile(); + } + + // 设置墨迹颜色为黑色 + CheckLastColor(0); + forceEraser = false; } else { if (inkColor == 0) lastBoardInkColor = 5; ICCWaterMarkWhite.Visibility = Visibility.Visible; ICCWaterMarkDark.Visibility = Visibility.Collapsed; + + // 设置为黑板默认背景色 + Color defaultBlackboardColor = Color.FromRgb(22, 41, 36); + + if (currentMode == 1) // 黑板模式 + { + // 设置背景为默认黑板背景色 + GridBackgroundCover.Background = new SolidColorBrush(defaultBlackboardColor); + + // 更新RGB滑块的值为默认黑板背景色 + if (BackgroundPalette != null && BackgroundPalette.Visibility == Visibility.Visible) + { + UpdateRGBSliders(defaultBlackboardColor); + } + + // 更新自定义背景色为默认黑板背景色 + CustomBackgroundColor = defaultBlackboardColor; + + // 保存到设置 + string colorHex = $"#{defaultBlackboardColor.R:X2}{defaultBlackboardColor.G:X2}{defaultBlackboardColor.B:X2}"; + Settings.Canvas.CustomBackgroundColor = colorHex; + SaveSettingsToFile(); + } + + // 设置墨迹颜色为白色 + CheckLastColor(5); + forceEraser = false; } CheckColorTheme(true); } + // 创建背景选项面板 + private void CreateBackgroundPalette() + { + // 确保加载自定义背景色 + LoadCustomBackgroundColor(); + + // 创建一个类似于PenPalette的面板 + BackgroundPalette = new Border + { + Name = "BackgroundPalette", + Visibility = Visibility.Collapsed, + Background = new SolidColorBrush(Colors.White), + Opacity = 1, + BorderBrush = new SolidColorBrush(Color.FromRgb(0x25, 0x63, 0xeb)), + BorderThickness = new Thickness(1), + CornerRadius = new CornerRadius(8), + Width = 300, + MaxHeight = 400 + }; + + // 确保面板显示在顶层 + System.Windows.Controls.Panel.SetZIndex(BackgroundPalette, 1000); + + // 创建面板内容 + var stackPanel = new StackPanel(); + + // 创建标题栏 + var titleBorder = new Border + { + BorderBrush = new SolidColorBrush(Color.FromRgb(0x1e, 0x3a, 0x8a)), + Height = 32, + BorderThickness = new Thickness(0, 0, 0, 1), + CornerRadius = new CornerRadius(8, 8, 0, 0), + Background = new SolidColorBrush(Color.FromRgb(0x25, 0x63, 0xeb)), + Margin = new Thickness(-1, -1, -1, 0), + Padding = new Thickness(1, 1, 1, 0) + }; + + var titleCanvas = new System.Windows.Controls.Canvas { Height = 24, ClipToBounds = true }; + var titleText = new TextBlock + { + Text = "背景设置", + Foreground = new SolidColorBrush(Colors.White), + Padding = new Thickness(0, 5, 0, 0), + FontSize = 11, + FontWeight = FontWeights.Bold, + TextAlignment = TextAlignment.Center + }; + System.Windows.Controls.Canvas.SetLeft(titleText, 8); + titleCanvas.Children.Add(titleText); + + // 关闭按钮 + var closeImage = new System.Windows.Controls.Image + { + Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("/Resources/new-icons/close-white.png", UriKind.Relative)), + Height = 16, + Width = 16 + }; + RenderOptions.SetBitmapScalingMode(closeImage, BitmapScalingMode.HighQuality); + closeImage.MouseUp += CloseBordertools_MouseUp; + System.Windows.Controls.Canvas.SetRight(closeImage, 8); + System.Windows.Controls.Canvas.SetTop(closeImage, 4); + titleCanvas.Children.Add(closeImage); + + titleBorder.Child = titleCanvas; + stackPanel.Children.Add(titleBorder); + + // 创建背景选项内容区域 + var contentPanel = new StackPanel { Margin = new Thickness(8) }; + + // 黑板/白板选择 + var modeTitle = new TextBlock + { + Text = "白板模式", + Foreground = new SolidColorBrush(Color.FromRgb(0x17, 0x25, 0x54)), + FontSize = 10, + FontWeight = FontWeights.Bold, + HorizontalAlignment = HorizontalAlignment.Center, + Margin = new Thickness(0, 4, 0, 8) + }; + contentPanel.Children.Add(modeTitle); + + var modePanel = new StackPanel { Orientation = Orientation.Horizontal, HorizontalAlignment = HorizontalAlignment.Center }; + + // 白板按钮 + var whiteboardButton = new Border + { + Width = 60, + Height = 30, + Background = Settings.Canvas.UsingWhiteboard ? new SolidColorBrush(Color.FromRgb(0x25, 0x63, 0xeb)) : new SolidColorBrush(Colors.LightGray), + CornerRadius = new CornerRadius(4), + Margin = new Thickness(0, 0, 8, 0) + }; + var whiteboardText = new TextBlock + { + Text = "白板", + Foreground = Settings.Canvas.UsingWhiteboard ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Colors.Black), + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center + }; + whiteboardButton.Child = whiteboardText; + whiteboardButton.MouseUp += (s, args) => { + Settings.Canvas.UsingWhiteboard = true; + SaveSettingsToFile(); + ICCWaterMarkDark.Visibility = Visibility.Visible; + ICCWaterMarkWhite.Visibility = Visibility.Collapsed; + + // 设置为白板默认背景色 + Color defaultWhiteboardColor = Color.FromRgb(234, 235, 237); + + if (currentMode == 1) // 白板模式 + { + // 设置背景为默认白板背景色 + GridBackgroundCover.Background = new SolidColorBrush(defaultWhiteboardColor); + + // 更新RGB滑块的值为默认白板背景色 + UpdateRGBSliders(defaultWhiteboardColor); + + // 更新自定义背景色为默认白板背景色 + CustomBackgroundColor = defaultWhiteboardColor; + + // 保存到设置 + string colorHex = $"#{defaultWhiteboardColor.R:X2}{defaultWhiteboardColor.G:X2}{defaultWhiteboardColor.B:X2}"; + Settings.Canvas.CustomBackgroundColor = colorHex; + SaveSettingsToFile(); + } + + // 设置墨迹颜色为黑色 + CheckLastColor(0); + forceEraser = false; + + CheckColorTheme(true); + UpdateBackgroundButtonsState(); + }; + modePanel.Children.Add(whiteboardButton); + + // 黑板按钮 + var blackboardButton = new Border + { + Width = 60, + Height = 30, + Background = !Settings.Canvas.UsingWhiteboard ? new SolidColorBrush(Color.FromRgb(0x25, 0x63, 0xeb)) : new SolidColorBrush(Colors.LightGray), + CornerRadius = new CornerRadius(4) + }; + var blackboardText = new TextBlock + { + Text = "黑板", + Foreground = !Settings.Canvas.UsingWhiteboard ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Colors.Black), + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center + }; + blackboardButton.Child = blackboardText; + blackboardButton.MouseUp += (s, args) => { + Settings.Canvas.UsingWhiteboard = false; + SaveSettingsToFile(); + ICCWaterMarkWhite.Visibility = Visibility.Visible; + ICCWaterMarkDark.Visibility = Visibility.Collapsed; + + // 设置为黑板默认背景色 + Color defaultBlackboardColor = Color.FromRgb(22, 41, 36); + + if (currentMode == 1) // 黑板模式 + { + // 设置背景为默认黑板背景色 + GridBackgroundCover.Background = new SolidColorBrush(defaultBlackboardColor); + + // 更新RGB滑块的值为默认黑板背景色 + UpdateRGBSliders(defaultBlackboardColor); + + // 更新自定义背景色为默认黑板背景色 + CustomBackgroundColor = defaultBlackboardColor; + + // 保存到设置 + string colorHex = $"#{defaultBlackboardColor.R:X2}{defaultBlackboardColor.G:X2}{defaultBlackboardColor.B:X2}"; + Settings.Canvas.CustomBackgroundColor = colorHex; + SaveSettingsToFile(); + } + + // 设置墨迹颜色为白色 + CheckLastColor(5); + forceEraser = false; + + CheckColorTheme(true); + UpdateBackgroundButtonsState(); + }; + modePanel.Children.Add(blackboardButton); + + contentPanel.Children.Add(modePanel); + + // 添加一条分隔线 + var separator = new Border + { + Height = 1, + Background = new SolidColorBrush(Color.FromRgb(0xd4, 0xd4, 0xd8)), + Margin = new Thickness(0, 12, 0, 12) + }; + contentPanel.Children.Add(separator); + + // 添加RGB颜色选择器部分 + var colorTitle = new TextBlock + { + Text = "背景颜色", + Foreground = new SolidColorBrush(Color.FromRgb(0x17, 0x25, 0x54)), + FontSize = 10, + FontWeight = FontWeights.Bold, + HorizontalAlignment = HorizontalAlignment.Center, + Margin = new Thickness(0, 4, 0, 8) + }; + contentPanel.Children.Add(colorTitle); + + // 创建颜色预览 + Border colorPreview = new Border + { + Width = 100, + Height = 40, + BorderThickness = new Thickness(1), + BorderBrush = new SolidColorBrush(Color.FromRgb(0xd4, 0xd4, 0xd8)), + Background = new SolidColorBrush(Colors.White), + CornerRadius = new CornerRadius(4), + Margin = new Thickness(0, 0, 0, 10), + HorizontalAlignment = HorizontalAlignment.Center + }; + contentPanel.Children.Add(colorPreview); + + // 获取当前背景颜色 + Color currentBackgroundColor; + if (currentMode == 1) // 白板或黑板模式 + { + if (GridBackgroundCover.Background is SolidColorBrush brush) + { + currentBackgroundColor = brush.Color; + } + else + { + // 默认颜色 + currentBackgroundColor = Settings.Canvas.UsingWhiteboard ? + Color.FromRgb(234, 235, 237) : // 白板默认颜色 + Color.FromRgb(22, 41, 36); // 黑板默认颜色 + } + } + else + { + // 默认白色 + currentBackgroundColor = Colors.White; + } + + // 更新颜色预览 + colorPreview.Background = new SolidColorBrush(currentBackgroundColor); + + // 先创建所有滑块控件 + // R滑块和文本框 + var rPanel = new StackPanel { Orientation = Orientation.Horizontal, Margin = new Thickness(10, 0, 10, 5) }; + var rLabel = new TextBlock { Text = "R:", Width = 20, VerticalAlignment = VerticalAlignment.Center }; + var rSlider = new System.Windows.Controls.Slider + { + Minimum = 0, + Maximum = 255, + Value = currentBackgroundColor.R, + Width = 150, + Margin = new Thickness(5, 0, 5, 0), + VerticalAlignment = VerticalAlignment.Center + }; + var rValueText = new TextBlock + { + Text = currentBackgroundColor.R.ToString(), + Width = 30, + VerticalAlignment = VerticalAlignment.Center, + TextAlignment = TextAlignment.Right + }; + + // G滑块和文本框 + var gPanel = new StackPanel { Orientation = Orientation.Horizontal, Margin = new Thickness(10, 0, 10, 5) }; + var gLabel = new TextBlock { Text = "G:", Width = 20, VerticalAlignment = VerticalAlignment.Center }; + var gSlider = new System.Windows.Controls.Slider + { + Minimum = 0, + Maximum = 255, + Value = currentBackgroundColor.G, + Width = 150, + Margin = new Thickness(5, 0, 5, 0), + VerticalAlignment = VerticalAlignment.Center + }; + var gValueText = new TextBlock + { + Text = currentBackgroundColor.G.ToString(), + Width = 30, + VerticalAlignment = VerticalAlignment.Center, + TextAlignment = TextAlignment.Right + }; + + // B滑块和文本框 + var bPanel = new StackPanel { Orientation = Orientation.Horizontal, Margin = new Thickness(10, 0, 10, 5) }; + var bLabel = new TextBlock { Text = "B:", Width = 20, VerticalAlignment = VerticalAlignment.Center }; + var bSlider = new System.Windows.Controls.Slider + { + Minimum = 0, + Maximum = 255, + Value = currentBackgroundColor.B, + Width = 150, + Margin = new Thickness(5, 0, 5, 0), + VerticalAlignment = VerticalAlignment.Center + }; + var bValueText = new TextBlock + { + Text = currentBackgroundColor.B.ToString(), + Width = 30, + VerticalAlignment = VerticalAlignment.Center, + TextAlignment = TextAlignment.Right + }; + + // 现在添加事件处理程序 + rSlider.ValueChanged += (s, e) => { + int value = (int)e.NewValue; + rValueText.Text = value.ToString(); + UpdateColorPreview(colorPreview, rSlider, gSlider, bSlider); + }; + + gSlider.ValueChanged += (s, e) => { + int value = (int)e.NewValue; + gValueText.Text = value.ToString(); + UpdateColorPreview(colorPreview, rSlider, gSlider, bSlider); + }; + + bSlider.ValueChanged += (s, e) => { + int value = (int)e.NewValue; + bValueText.Text = value.ToString(); + UpdateColorPreview(colorPreview, rSlider, gSlider, bSlider); + }; + + // 添加控件到面板 + rPanel.Children.Add(rLabel); + rPanel.Children.Add(rSlider); + rPanel.Children.Add(rValueText); + contentPanel.Children.Add(rPanel); + + gPanel.Children.Add(gLabel); + gPanel.Children.Add(gSlider); + gPanel.Children.Add(gValueText); + contentPanel.Children.Add(gPanel); + + bPanel.Children.Add(bLabel); + bPanel.Children.Add(bSlider); + bPanel.Children.Add(bValueText); + contentPanel.Children.Add(bPanel); + + // 应用按钮 + var applyButton = new Button + { + Content = "应用颜色", + Margin = new Thickness(0, 10, 0, 0), + Padding = new Thickness(10, 5, 10, 5), + Background = new SolidColorBrush(Color.FromRgb(0x25, 0x63, 0xeb)), + Foreground = new SolidColorBrush(Colors.White), + BorderThickness = new Thickness(0), + HorizontalAlignment = HorizontalAlignment.Center + }; + + applyButton.Click += (s, e) => { + Color selectedColor = Color.FromRgb( + (byte)rSlider.Value, + (byte)gSlider.Value, + (byte)bSlider.Value + ); + ApplyCustomBackgroundColor(selectedColor); + }; + + contentPanel.Children.Add(applyButton); + + stackPanel.Children.Add(contentPanel); + + // 将面板添加到父容器 + BackgroundPalette.Child = stackPanel; + + // 获取主窗口中的根网格,确保面板添加到顶层 + Grid mainGrid = FindName("Main_Grid") as Grid; + if (mainGrid != null) + { + // 删除可能已存在的BackgroundPalette + foreach (UIElement element in mainGrid.Children) + { + if (element is Border border && border.Name == "BackgroundPalette") + { + mainGrid.Children.Remove(border); + break; + } + } + + // 重新定位面板 + BackgroundPalette.HorizontalAlignment = HorizontalAlignment.Center; + BackgroundPalette.VerticalAlignment = VerticalAlignment.Center; + BackgroundPalette.Margin = new Thickness(0, 0, 0, 0); + + // 添加到主网格 + mainGrid.Children.Add(BackgroundPalette); + + // 设置面板位置 + var clickElement = FindName("BoardChangeBackgroundColorBtn") as FrameworkElement; + if (clickElement != null) + { + Point position = clickElement.TranslatePoint(new Point(0, 0), mainGrid); + BackgroundPalette.Margin = new Thickness( + position.X - 150, + position.Y + clickElement.ActualHeight + 5, + 0, 0); + BackgroundPalette.HorizontalAlignment = HorizontalAlignment.Left; + BackgroundPalette.VerticalAlignment = VerticalAlignment.Top; + } + } + } + + // 更新背景按钮状态 + private void UpdateBackgroundButtonsState() + { + if (BackgroundPalette != null && BackgroundPalette.Child is StackPanel stackPanel) + { + if (stackPanel.Children.Count > 1 && stackPanel.Children[1] is StackPanel contentPanel) + { + if (contentPanel.Children.Count > 1 && contentPanel.Children[1] is StackPanel modePanel) + { + if (modePanel.Children.Count > 1) + { + var whiteboardButton = modePanel.Children[0] as Border; + var blackboardButton = modePanel.Children[1] as Border; + + if (whiteboardButton != null && whiteboardButton.Child is TextBlock whiteboardText) + { + whiteboardButton.Background = Settings.Canvas.UsingWhiteboard ? + new SolidColorBrush(Color.FromRgb(0x25, 0x63, 0xeb)) : + new SolidColorBrush(Colors.LightGray); + whiteboardText.Foreground = Settings.Canvas.UsingWhiteboard ? + new SolidColorBrush(Colors.White) : + new SolidColorBrush(Colors.Black); + } + + if (blackboardButton != null && blackboardButton.Child is TextBlock blackboardText) + { + blackboardButton.Background = !Settings.Canvas.UsingWhiteboard ? + new SolidColorBrush(Color.FromRgb(0x25, 0x63, 0xeb)) : + new SolidColorBrush(Colors.LightGray); + blackboardText.Foreground = !Settings.Canvas.UsingWhiteboard ? + new SolidColorBrush(Colors.White) : + new SolidColorBrush(Colors.Black); + } + } + } + } + } + } + + // 添加成员变量保存背景面板引用 + private Border BackgroundPalette { get; set; } + + // 添加成员变量保存当前自定义背景色 + private Color? CustomBackgroundColor { get; set; } + + /// + /// 更新颜色预览框的颜色 + /// + private void UpdateColorPreview(Border colorPreview, System.Windows.Controls.Slider rSlider, System.Windows.Controls.Slider gSlider, System.Windows.Controls.Slider bSlider) + { + Color previewColor = Color.FromRgb( + (byte)rSlider.Value, + (byte)gSlider.Value, + (byte)bSlider.Value + ); + colorPreview.Background = new SolidColorBrush(previewColor); + } + + /// + /// 应用自定义背景颜色 + /// + private void ApplyCustomBackgroundColor(Color color) + { + // 保存当前选择的颜色 + CustomBackgroundColor = color; + + // 将颜色转换为十六进制字符串并保存到设置中 + string colorHex = $"#{color.R:X2}{color.G:X2}{color.B:X2}"; + Settings.Canvas.CustomBackgroundColor = colorHex; + + // 只在白板或黑板模式下应用自定义背景色 + if (currentMode == 1) // 白板或黑板模式 + { + // 设置白板/黑板模式下的背景 + GridBackgroundCover.Background = new SolidColorBrush(color); + } + + // 保存设置 + SaveSettingsToFile(); + + // 立即更新界面 + if (BackgroundPalette != null) + { + UpdateBackgroundButtonsState(); + UpdateRGBSliders(color); // 更新RGB滑块的值 + } + + // 显示提示信息 + ShowNotification($"已应用自定义背景色: {colorHex}"); + } + + /// + /// 从设置中加载自定义背景色 + /// + private void LoadCustomBackgroundColor() + { + if (!string.IsNullOrEmpty(Settings.Canvas.CustomBackgroundColor)) + { + try + { + // 解析颜色字符串 + string colorHex = Settings.Canvas.CustomBackgroundColor; + if (colorHex.StartsWith("#") && colorHex.Length == 7) // #RRGGBB 格式 + { + byte r = Convert.ToByte(colorHex.Substring(1, 2), 16); + byte g = Convert.ToByte(colorHex.Substring(3, 2), 16); + byte b = Convert.ToByte(colorHex.Substring(5, 2), 16); + + // 保存到内存中 + CustomBackgroundColor = Color.FromRgb(r, g, b); + } + } + catch (Exception ex) + { + // 解析失败,根据当前模式设置默认颜色 + if (!Settings.Canvas.UsingWhiteboard) + { + // 黑板模式默认颜色 + CustomBackgroundColor = Color.FromRgb(22, 41, 36); + } + else + { + // 白板模式默认颜色 + CustomBackgroundColor = Color.FromRgb(234, 235, 237); + } + + // 可以在这里记录日志 + Console.WriteLine($"解析自定义背景色失败: {ex.Message}"); + } + } + else + { + // 如果没有设置自定义背景色,根据当前模式设置默认颜色 + if (!Settings.Canvas.UsingWhiteboard) + { + // 黑板模式默认颜色 + CustomBackgroundColor = Color.FromRgb(22, 41, 36); + } + else + { + // 白板模式默认颜色 + CustomBackgroundColor = Color.FromRgb(234, 235, 237); + } + } + + // 只在白板或黑板模式下应用自定义背景色 + if (currentMode == 1 && CustomBackgroundColor.HasValue) // 白板或黑板模式 + { + // 设置白板/黑板模式下的背景 + GridBackgroundCover.Background = new SolidColorBrush(CustomBackgroundColor.Value); + + // 更新RGB滑块的值(如果调色板已经创建) + if (BackgroundPalette != null && BackgroundPalette.Visibility == Visibility.Visible) + { + UpdateRGBSliders(CustomBackgroundColor.Value); + } + } + } + private void BoardEraserIcon_Click(object sender, RoutedEventArgs e) { if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint || inkCanvas.EditingMode == InkCanvasEditingMode.EraseByStroke) { @@ -90,5 +753,59 @@ namespace Ink_Canvas { ImageBlackboard_MouseUp(null, null); Process.Start("https://www.desmos.com/calculator?lang=zh-CN"); } + + /// + /// 根据当前背景颜色更新RGB滑块的值 + /// + private void UpdateRGBSliders(Color color) + { + if (BackgroundPalette != null && BackgroundPalette.Child is StackPanel stackPanel) + { + if (stackPanel.Children.Count > 1 && stackPanel.Children[1] is StackPanel contentPanel) + { + // 查找RGB滑块 + System.Windows.Controls.Slider rSlider = null; + System.Windows.Controls.Slider gSlider = null; + System.Windows.Controls.Slider bSlider = null; + + // 遍历面板查找RGB滑块 + foreach (var child in contentPanel.Children) + { + if (child is StackPanel panel && panel.Orientation == Orientation.Horizontal) + { + foreach (var panelChild in panel.Children) + { + if (panelChild is System.Windows.Controls.Slider slider) + { + if (panel.Children.Count > 0 && panel.Children[0] is TextBlock label) + { + if (label.Text == "R:") + { + rSlider = slider; + } + else if (label.Text == "G:") + { + gSlider = slider; + } + else if (label.Text == "B:") + { + bSlider = slider; + } + } + } + } + } + } + + // 更新滑块值 + if (rSlider != null && gSlider != null && bSlider != null) + { + rSlider.Value = color.R; + gSlider.Value = color.G; + bSlider.Value = color.B; + } + } + } + } } } \ No newline at end of file diff --git a/Ink Canvas/MainWindow_cs/MW_Colors.cs b/Ink Canvas/MainWindow_cs/MW_Colors.cs index d1d11883..5c891ae3 100644 --- a/Ink Canvas/MainWindow_cs/MW_Colors.cs +++ b/Ink Canvas/MainWindow_cs/MW_Colors.cs @@ -70,14 +70,24 @@ namespace Ink_Canvas { if (changeColorTheme) if (currentMode != 0) { if (Settings.Canvas.UsingWhiteboard) { - GridBackgroundCover.Background = new SolidColorBrush(Color.FromRgb(234, 235, 237)); + // 检查是否有自定义背景色,如果有则使用自定义背景色 + if (CustomBackgroundColor.HasValue) { + GridBackgroundCover.Background = new SolidColorBrush(CustomBackgroundColor.Value); + } else { + GridBackgroundCover.Background = new SolidColorBrush(Color.FromRgb(234, 235, 237)); + } WaterMarkTime.Foreground = new SolidColorBrush(Color.FromRgb(22, 41, 36)); WaterMarkDate.Foreground = new SolidColorBrush(Color.FromRgb(22, 41, 36)); BlackBoardWaterMark.Foreground = new SolidColorBrush(Color.FromRgb(22, 41, 36)); isUselightThemeColor = false; } else { - GridBackgroundCover.Background = new SolidColorBrush(Color.FromRgb(22, 41, 36)); + // 黑板模式下,检查是否有自定义背景色 + if (CustomBackgroundColor.HasValue) { + GridBackgroundCover.Background = new SolidColorBrush(CustomBackgroundColor.Value); + } else { + GridBackgroundCover.Background = new SolidColorBrush(Color.FromRgb(22, 41, 36)); + } WaterMarkTime.Foreground = new SolidColorBrush(Color.FromRgb(234, 235, 237)); WaterMarkDate.Foreground = new SolidColorBrush(Color.FromRgb(234, 235, 237)); BlackBoardWaterMark.Foreground = new SolidColorBrush(Color.FromRgb(234, 235, 237)); diff --git a/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs b/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs index 12526060..a53aa0f1 100644 --- a/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs +++ b/Ink Canvas/MainWindow_cs/MW_FloatingBarIcons.cs @@ -281,6 +281,13 @@ namespace Ink_Canvas { AnimationsHelper.HideWithSlideAndFade(BorderDrawShape); AnimationsHelper.HideWithSlideAndFade(BoardBorderLeftPageListView); AnimationsHelper.HideWithSlideAndFade(BoardBorderRightPageListView); + + // 隐藏背景设置面板 + var bgPalette = LogicalTreeHelper.FindLogicalNode(this, "BackgroundPalette") as Border; + if (bgPalette != null) + { + AnimationsHelper.HideWithSlideAndFade(bgPalette); + } if (BorderSettings.Visibility == Visibility.Visible) { // 设置蒙版为不可点击,并移除背景 @@ -1850,11 +1857,22 @@ namespace Ink_Canvas { if (Settings.Canvas.UsingWhiteboard) { - BtnColorBlack_Click(null, null); + // 如果有自定义背景色并且是白板模式,应用自定义背景色 + if (CustomBackgroundColor.HasValue) + { + GridBackgroundCover.Background = new SolidColorBrush(CustomBackgroundColor.Value); + } + // 白板模式下设置墨迹颜色为黑色 + CheckLastColor(0); + forceEraser = false; + ColorSwitchCheck(); } else { - BtnColorWhite_Click(null, null); + // 黑板模式下设置墨迹颜色为白色 + CheckLastColor(5); + forceEraser = false; + ColorSwitchCheck(); } StackPanelPPTButtons.Visibility = Visibility.Collapsed; diff --git a/Ink Canvas/Resources/Settings.cs b/Ink Canvas/Resources/Settings.cs index ea7eb78a..33ea477d 100644 --- a/Ink Canvas/Resources/Settings.cs +++ b/Ink Canvas/Resources/Settings.cs @@ -66,7 +66,10 @@ namespace Ink_Canvas public int LineEndpointSnappingThreshold { get; set; } = 15; // 直线端点吸附的距离阈值(像素) [JsonProperty("usingWhiteboard")] - public bool UsingWhiteboard { get; set; } + public bool UsingWhiteboard { get; set; } = false; + + [JsonProperty("customBackgroundColor")] + public string CustomBackgroundColor { get; set; } = "#162924"; [JsonProperty("hyperbolaAsymptoteOption")] public OptionalOperation HyperbolaAsymptoteOption { get; set; } = OptionalOperation.Ask;