Skip to content

Commit

Permalink
完成深浅色切换、根据配置文件自定义颜色功能
Browse files Browse the repository at this point in the history
- 修复了加载颜色的所有问题
- 新增对更改颜色请求是否从浮动工具栏发出的判断
  • Loading branch information
STBBRD committed Oct 29, 2023
1 parent 02fa775 commit acc3a0c
Showing 1 changed file with 57 additions and 15 deletions.
72 changes: 57 additions & 15 deletions Ink Canvas/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public MainWindow()
{
InitializeComponent();


BorderSettings.Visibility = Visibility.Collapsed;
StackPanelToolButtons.Visibility = Visibility.Collapsed;
BorderDrawShape.Visibility = Visibility.Collapsed;
Expand Down Expand Up @@ -148,22 +147,21 @@ private void TimerKillProcess_Elapsed(object sender, ElapsedEventArgs e)
}
}
catch { }
}
}

#endregion Timer

#region Ink Canvas Functions

Color Ink_DefaultColor = Colors.Red;


DrawingAttributes drawingAttributes;
private void loadPenCanvas()
{
SetDarkColors();
try
{
//drawingAttributes = new DrawingAttributes();
drawingAttributes = inkCanvas.DefaultDrawingAttributes;
drawingAttributes.Color = Ink_DefaultColor;
drawingAttributes.Color = ((SolidColorBrush)BtnColorRed.Background).Color;

drawingAttributes.Height = 2.5;
drawingAttributes.Width = 2.5;
Expand Down Expand Up @@ -1557,13 +1555,20 @@ private void BtnColorRed_Click(object sender, RoutedEventArgs e)
{
inkColor = 1;
forceEraser = false;
if (BtnSwitchTheme.Content.ToString() == "浅色")
if (!isLastSwitchColorByFloatBar)
{
SetDarkColors(); //在浅色背景上使用深色墨迹
if (BtnSwitchTheme.Content.ToString() == "浅色")
{
SetDarkColors(); //在浅色背景上使用深色墨迹
}
else
{
SetLightColors(); //在深色背景上使用浅色墨迹
}
}
else
{
SetLightColors(); //在深色背景上使用浅色墨迹
isLastSwitchColorByFloatBar = false;
}
inkCanvas.DefaultDrawingAttributes.Color = ((SolidColorBrush)BtnColorRed.Background).Color;

Expand All @@ -1574,13 +1579,20 @@ private void BtnColorGreen_Click(object sender, RoutedEventArgs e)
{
inkColor = 2;
forceEraser = false;
if (BtnSwitchTheme.Content.ToString() == "浅色")
if (!isLastSwitchColorByFloatBar)
{
SetDarkColors(); //在浅色背景上使用深色墨迹
if (BtnSwitchTheme.Content.ToString() == "浅色")
{
SetDarkColors(); //在浅色背景上使用深色墨迹
}
else
{
SetLightColors(); //在深色背景上使用浅色墨迹
}
}
else
{
SetLightColors(); //在深色背景上使用浅色墨迹
isLastSwitchColorByFloatBar = false;
}
inkCanvas.DefaultDrawingAttributes.Color = ((SolidColorBrush)BtnColorGreen.Background).Color;

Expand All @@ -1591,6 +1603,21 @@ private void BtnColorBlue_Click(object sender, RoutedEventArgs e)
{
inkColor = 3;
forceEraser = false;
if (!isLastSwitchColorByFloatBar)
{
if (BtnSwitchTheme.Content.ToString() == "浅色")
{
SetDarkColors(); //在浅色背景上使用深色墨迹
}
else
{
SetLightColors(); //在深色背景上使用浅色墨迹
}
}
else
{
isLastSwitchColorByFloatBar = false;
}
inkCanvas.DefaultDrawingAttributes.Color = ((SolidColorBrush)BtnColorBlue.Background).Color;

ColorSwitchCheck();
Expand All @@ -1600,13 +1627,20 @@ private void BtnColorYellow_Click(object sender, RoutedEventArgs e)
{
inkColor = 4;
forceEraser = false;
if (BtnSwitchTheme.Content.ToString() == "浅色")
if (!isLastSwitchColorByFloatBar)
{
SetDarkColors(); //在浅色背景上使用深色墨迹
if (BtnSwitchTheme.Content.ToString() == "浅色")
{
SetDarkColors(); //在浅色背景上使用深色墨迹
}
else
{
SetLightColors(); //在深色背景上使用浅色墨迹
}
}
else
{
SetLightColors(); //在深色背景上使用浅色墨迹
isLastSwitchColorByFloatBar = false;
}
inkCanvas.DefaultDrawingAttributes.Color = ((SolidColorBrush)BtnColorYellow.Background).Color;

Expand Down Expand Up @@ -5864,6 +5898,7 @@ private void SetLightColors()
{
BtnColorRed.Background = new SolidColorBrush(StringToColor("#FFFF3333"));
BtnColorGreen.Background = new SolidColorBrush(StringToColor("#FF1ED760"));
BtnColorBlue.Background = new SolidColorBrush(StringToColor("#FF239AD6"));
BtnColorYellow.Background = new SolidColorBrush(StringToColor("#FFFFC000"));
}
}
Expand All @@ -5882,6 +5917,7 @@ private void SetDarkColors()
{
BtnColorRed.Background = new SolidColorBrush(Colors.Red);
BtnColorGreen.Background = new SolidColorBrush(StringToColor("#FF169141"));
BtnColorBlue.Background = new SolidColorBrush(StringToColor("#FF239AD6"));
BtnColorYellow.Background = new SolidColorBrush(StringToColor("#FFF38B00"));
}
}
Expand Down Expand Up @@ -6853,6 +6889,8 @@ private void HideSubPanels()
BorderTools.Visibility = Visibility.Collapsed;
}

bool isLastSwitchColorByFloatBar = false;

private void BorderPenColorBlack_MouseUp(object sender, MouseButtonEventArgs e)
{
BtnColorBlack_Click(BtnColorBlack, null);
Expand All @@ -6861,24 +6899,28 @@ private void BorderPenColorBlack_MouseUp(object sender, MouseButtonEventArgs e)

private void BorderPenColorRed_MouseUp(object sender, MouseButtonEventArgs e)
{
isLastSwitchColorByFloatBar = true;
BtnColorRed_Click(BtnColorRed, null);
HideSubPanels();
}

private void BorderPenColorGreen_MouseUp(object sender, MouseButtonEventArgs e)
{
isLastSwitchColorByFloatBar = true;
BtnColorGreen_Click(BtnColorGreen, null);
HideSubPanels();
}

private void BorderPenColorBlue_MouseUp(object sender, MouseButtonEventArgs e)
{
isLastSwitchColorByFloatBar = true;
BtnColorBlue_Click(BtnColorBlue, null);
HideSubPanels();
}

private void BorderPenColorYellow_MouseUp(object sender, MouseButtonEventArgs e)
{
isLastSwitchColorByFloatBar = true;
BtnColorYellow_Click(BtnColorYellow, null);
HideSubPanels();
}
Expand Down

0 comments on commit acc3a0c

Please sign in to comment.