优化代码

This commit is contained in:
2025-08-31 08:51:50 +08:00
parent a2aa6b48a8
commit 1bc23af61a
15 changed files with 81 additions and 46 deletions
-2
View File
@@ -1340,8 +1340,6 @@ namespace Ink_Canvas.Helpers
return descriptions.Count > 0 ? string.Join(", ", descriptions) : "普通用户";
}
/// <summary>
/// 关机时保存使用时间数据
/// </summary>
+1 -5
View File
@@ -721,8 +721,7 @@ namespace Ink_Canvas.Helpers
// 根据高光位置判断当前选中的工具
// 位置计算基于SetFloatingBarHighlightPosition方法中的逻辑
bool isMouseMode = false;
string currentTool = "unknown";
bool isMouseMode;
// 简化判断:如果位置接近0,说明是鼠标模式
// 如果位置接近28,说明是批注模式
@@ -730,17 +729,14 @@ namespace Ink_Canvas.Helpers
if (position < 5) // 鼠标模式:marginOffset + (cursorWidth - actualHighlightWidth) / 2 ≈ 0
{
isMouseMode = true;
currentTool = "鼠标";
}
else if (position < 35) // 批注模式:marginOffset + cursorWidth + (penWidth - actualHighlightWidth) / 2 ≈ 28
{
isMouseMode = false;
currentTool = "批注";
}
else // 其他工具(橡皮擦、选择等)
{
isMouseMode = false;
currentTool = "其他工具";
}
return isMouseMode;
@@ -16,7 +16,6 @@ namespace Ink_Canvas.Helpers
{
private readonly RenderTargetBitmap _renderTarget;
private readonly DrawingVisual _drawingVisual;
private readonly DrawingContext _drawingContext;
private bool _isInitialized;
public HardwareAcceleratedInkProcessor(int width = 1920, int height = 1080)
@@ -191,7 +190,6 @@ namespace Ink_Canvas.Helpers
/// </summary>
public void Dispose()
{
_drawingContext?.Close();
_renderTarget?.Clear();
_isInitialized = false;
}
+1 -1
View File
@@ -5159,7 +5159,7 @@
<Run Text="图形" />
<Run Text="(第一行支持长按保持选中)" FontSize="10" />
</TextBlock>
<ui:SymbolIcon Margin="0,-20,8,15" Symbol="Pin"
<ui:FontIcon Margin="0,-20,8,15" Glyph="&#xE840;"
MouseDown="Border_MouseDown"
MouseUp="SymbolIconPinBorderDrawShape_MouseUp"
Foreground="{DynamicResource FloatBarForeground}"
+34 -2
View File
@@ -130,6 +130,13 @@ namespace Ink_Canvas
{
try
{
// 隐藏图片选择工具栏
if (currentSelectedElement != null)
{
UnselectElement(currentSelectedElement);
currentSelectedElement = null;
}
var targetIndex = isBackupMain ? 0 : CurrentWhiteboardIndex;
// 先清空当前画布的墨迹
@@ -209,7 +216,12 @@ namespace Ink_Canvas
{
if (CurrentWhiteboardIndex <= 1) return;
// 隐藏图片选择工具栏
if (currentSelectedElement != null)
{
UnselectElement(currentSelectedElement);
currentSelectedElement = null;
}
SaveStrokes();
@@ -229,11 +241,17 @@ namespace Ink_Canvas
inkCanvas.Strokes.Count > Settings.Automation.MinimumAutomationStrokeNumber) SaveScreenShot(true);
if (CurrentWhiteboardIndex >= WhiteboardTotalCount)
{
// 在最后一页时,点击新页面按钮直接新增一页
// 在最后一页时,点击"新页面"按钮直接新增一页
BtnWhiteBoardAdd_Click(sender, e);
return;
}
// 隐藏图片选择工具栏
if (currentSelectedElement != null)
{
UnselectElement(currentSelectedElement);
currentSelectedElement = null;
}
SaveStrokes();
@@ -251,6 +269,13 @@ namespace Ink_Canvas
if (Settings.Automation.IsAutoSaveStrokesAtClear &&
inkCanvas.Strokes.Count > Settings.Automation.MinimumAutomationStrokeNumber) SaveScreenShot(true);
// 隐藏图片选择工具栏
if (currentSelectedElement != null)
{
UnselectElement(currentSelectedElement);
currentSelectedElement = null;
}
SaveStrokes();
ClearStrokes(true);
@@ -279,6 +304,13 @@ namespace Ink_Canvas
private void BtnWhiteBoardDelete_Click(object sender, RoutedEventArgs e)
{
// 隐藏图片选择工具栏
if (currentSelectedElement != null)
{
UnselectElement(currentSelectedElement);
currentSelectedElement = null;
}
ClearStrokes(true);
if (CurrentWhiteboardIndex != WhiteboardTotalCount)
@@ -3096,19 +3096,16 @@ namespace Ink_Canvas
// 检查快捷调色盘是否显示及其实际宽度
bool isQuickColorPaletteVisible = false;
double quickColorPaletteWidth = 0;
string quickColorPaletteMode = "none";
if (QuickColorPalettePanel != null && QuickColorPalettePanel.Visibility == Visibility.Visible)
{
isQuickColorPaletteVisible = true;
quickColorPaletteWidth = QuickColorPalettePanel.ActualWidth > 0 ? QuickColorPalettePanel.ActualWidth : 60;
quickColorPaletteMode = "double";
}
else if (QuickColorPaletteSingleRowPanel != null && QuickColorPaletteSingleRowPanel.Visibility == Visibility.Visible)
{
isQuickColorPaletteVisible = true;
quickColorPaletteWidth = QuickColorPaletteSingleRowPanel.ActualWidth > 0 ? QuickColorPaletteSingleRowPanel.ActualWidth : 120;
quickColorPaletteMode = "single";
}
// 获取实际按钮宽度,如果获取不到则使用默认值,同时考虑按钮的可见性
@@ -86,6 +86,13 @@ namespace Ink_Canvas
// 只有当选择的页面与当前页面不同时才进行切换
if (index + 1 != CurrentWhiteboardIndex)
{
// 隐藏图片选择工具栏
if (currentSelectedElement != null)
{
UnselectElement(currentSelectedElement);
currentSelectedElement = null;
}
SaveStrokes();
ClearStrokes(true);
CurrentWhiteboardIndex = index + 1;
@@ -108,6 +115,13 @@ namespace Ink_Canvas
// 只有当选择的页面与当前页面不同时才进行切换
if (index + 1 != CurrentWhiteboardIndex)
{
// 隐藏图片选择工具栏
if (currentSelectedElement != null)
{
UnselectElement(currentSelectedElement);
currentSelectedElement = null;
}
SaveStrokes();
ClearStrokes(true);
CurrentWhiteboardIndex = index + 1;
+2 -2
View File
@@ -74,9 +74,9 @@ namespace Ink_Canvas
ToggleSwitchDrawShapeBorderAutoHide.IsOn = !ToggleSwitchDrawShapeBorderAutoHide.IsOn;
if (ToggleSwitchDrawShapeBorderAutoHide.IsOn)
((SymbolIcon)sender).Symbol = Symbol.Pin;
((FontIcon)sender).Glyph = "&#xE840;";
else
((SymbolIcon)sender).Symbol = Symbol.UnPin;
((FontIcon)sender).Glyph = "&#xE77A;";
}
private object lastMouseDownSender;
+7 -7
View File
@@ -179,12 +179,12 @@
<Grid>
<Border x:Name="BtnStart" MouseUp="BtnStart_MouseUp" Background="#0066BF" Height="20" Width="20" CornerRadius="100">
<Viewbox Margin="5">
<ui:SymbolIcon Name="SymbolIconStart" Symbol="Play" Foreground="White"/>
<ui:FontIcon Name="FontIconStart" Glyph="&#xE768;" Foreground="White"/>
</Viewbox>
</Border>
<Border x:Name="BtnStartCover" Visibility="Collapsed" Background="#BFBFBF" Height="20" Width="20" CornerRadius="100">
<Viewbox Margin="5">
<ui:SymbolIcon Symbol="{Binding ElementName=SymbolIconStart, Path=Symbol}" Foreground="White"/>
<ui:FontIcon Glyph="{Binding ElementName=FontIconStart, Path=Glyph}" Foreground="White"/>
</Viewbox>
</Border>
</Grid>
@@ -194,12 +194,12 @@
<DropShadowEffect Direction="0" ShadowDepth="0" Opacity="0.15" BlurRadius="3"/>
</Border.Effect>
<Viewbox Margin="5.5">
<ui:SymbolIcon Symbol="Refresh" Foreground="Black"/>
<ui:FontIcon Glyph="&#xE72C;" Foreground="Black"/>
</Viewbox>
</Border>
<Border x:Name="BtnResetCover" Background="#F3F5F9" Height="20" Width="20" CornerRadius="100">
<Viewbox Margin="5.5">
<ui:SymbolIcon Symbol="Refresh" Foreground="#9D9D9E"/>
<ui:FontIcon Glyph="&#xE72C;" Foreground="#9D9D9E"/>
</Viewbox>
</Border>
</Grid>
@@ -215,7 +215,7 @@
<DropShadowEffect Direction="0" ShadowDepth="0" Opacity="0.1" BlurRadius="3"/>
</Border.Effect>
<Viewbox Margin="5.5">
<ui:SymbolIcon Name="SymbolIconMinimal" Symbol="HideBcc" Foreground="Black"/>
<ui:FontIcon Name="FontIconMinimal" Glyph="&#xE7B3;" Foreground="Black"/>
</Viewbox>
</Border>
<Border x:Name="BtnFullscreen" MouseUp="BtnFullscreen_MouseUp" HorizontalAlignment="Right" VerticalAlignment="Bottom"
@@ -225,7 +225,7 @@
<DropShadowEffect Direction="0" ShadowDepth="0" Opacity="0.1" BlurRadius="3"/>
</Border.Effect>
<Viewbox Margin="5.5">
<ui:SymbolIcon Name="SymbolIconFullscreen" Symbol="FullScreen" Foreground="Black"/>
<ui:FontIcon Name="FontIconFullscreen" Glyph="&#xE740;" Foreground="Black"/>
</Viewbox>
</Border>
<Border x:Name="BtnClose" MouseUp="BtnClose_MouseUp" HorizontalAlignment="Right" VerticalAlignment="Bottom"
@@ -235,7 +235,7 @@
<DropShadowEffect Direction="0" ShadowDepth="0" Opacity="0.1" BlurRadius="3"/>
</Border.Effect>
<Viewbox Margin="5.5">
<ui:SymbolIcon Symbol="Clear" Foreground="White"/>
<ui:FontIcon Glyph="&#xE8BB;" Foreground="White"/>
</Viewbox>
</Border>
</ui:SimpleStackPanel>
@@ -57,7 +57,7 @@ namespace Ink_Canvas
TextBlockSecond.Text = "00";
timer.Stop();
isTimerRunning = false;
SymbolIconStart.Symbol = Symbol.Play;
FontIconStart.Glyph = "&#xE768;";
BtnStartCover.Visibility = Visibility.Visible;
TextBlockHour.Foreground = new SolidColorBrush(StringToColor("#FF5B5D5F"));
BorderStopTime.Visibility = Visibility.Collapsed;
@@ -208,12 +208,12 @@ namespace Ink_Canvas
if (WindowState == WindowState.Normal)
{
WindowState = WindowState.Maximized;
SymbolIconFullscreen.Symbol = Symbol.BackToWindow;
FontIconFullscreen.Glyph = "&#xE73F;";
}
else
{
WindowState = WindowState.Normal;
SymbolIconFullscreen.Symbol = Symbol.FullScreen;
FontIconFullscreen.Glyph = "&#xE740;";
}
}
@@ -238,7 +238,7 @@ namespace Ink_Canvas
BtnStartCover.Visibility = Visibility.Collapsed;
BorderStopTime.Visibility = Visibility.Collapsed;
TextBlockHour.Foreground = new SolidColorBrush(StringToColor("#FF5B5D5F"));
SymbolIconStart.Symbol = Symbol.Play;
FontIconStart.Glyph = "&#xE768;";
isTimerRunning = false;
timer.Stop();
isPaused = false;
@@ -288,7 +288,7 @@ namespace Ink_Canvas
startTime += DateTime.Now - pauseTime;
ProcessBarTime.IsPaused = false;
TextBlockHour.Foreground = Brushes.Black;
SymbolIconStart.Symbol = Symbol.Pause;
FontIconStart.Glyph = "&#xE769;";
isPaused = false;
timer.Start();
UpdateStopTime();
@@ -300,7 +300,7 @@ namespace Ink_Canvas
pauseTime = DateTime.Now;
ProcessBarTime.IsPaused = true;
TextBlockHour.Foreground = new SolidColorBrush(StringToColor("#FF5B5D5F"));
SymbolIconStart.Symbol = Symbol.Play;
FontIconStart.Glyph = "&#xE768;";
BorderStopTime.Visibility = Visibility.Collapsed;
isPaused = true;
timer.Stop();
@@ -312,7 +312,7 @@ namespace Ink_Canvas
totalSeconds = ((hour * 60) + minute) * 60 + second;
ProcessBarTime.IsPaused = false;
TextBlockHour.Foreground = Brushes.Black;
SymbolIconStart.Symbol = Symbol.Pause;
FontIconStart.Glyph = "&#xE769;";
BtnResetCover.Visibility = Visibility.Collapsed;
if (totalSeconds <= 10)
+2 -2
View File
@@ -80,7 +80,7 @@
<DropShadowEffect Direction="0" ShadowDepth="0" Opacity="0.1" BlurRadius="3"/>
</Border.Effect>
<Viewbox Margin="5.5">
<ui:SymbolIcon Name="SymbolIconFullscreen" Symbol="FullScreen" Foreground="Black"/>
<ui:FontIcon Name="FontIconFullscreen" Glyph="&#xE740;" Foreground="Black"/>
</Viewbox>
</Border>
<Border x:Name="BtnClose" MouseUp="BtnClose_MouseUp" HorizontalAlignment="Right" VerticalAlignment="Bottom"
@@ -90,7 +90,7 @@
<DropShadowEffect Direction="0" ShadowDepth="0" Opacity="0.1" BlurRadius="3"/>
</Border.Effect>
<Viewbox Margin="5.5">
<ui:SymbolIcon Symbol="Clear" Foreground="White"/>
<ui:FontIcon Glyph="&#xE8BB;" Foreground="White"/>
</Viewbox>
</Border>
</ui:SimpleStackPanel>
@@ -31,12 +31,12 @@ namespace Ink_Canvas
if (WindowState == WindowState.Normal)
{
WindowState = WindowState.Maximized;
SymbolIconFullscreen.Symbol = Symbol.BackToWindow;
FontIconFullscreen.Glyph = "&#xE73F;";
}
else
{
WindowState = WindowState.Normal;
SymbolIconFullscreen.Symbol = Symbol.FullScreen;
FontIconFullscreen.Glyph = "&#xE740;";
}
}
@@ -68,11 +68,11 @@ namespace Ink_Canvas.Windows
}
}
public string Name => SelectedPlugin?.Name ?? string.Empty;
public new string Name => SelectedPlugin?.Name ?? string.Empty;
public string Version => SelectedPlugin?.Version?.ToString() ?? string.Empty;
public string Author => SelectedPlugin?.Author ?? string.Empty;
public string Description => SelectedPlugin?.Description ?? string.Empty;
public bool IsEnabled => SelectedPlugin is PluginBase plugin && plugin.IsEnabled;
public new bool IsEnabled => SelectedPlugin is PluginBase plugin && plugin.IsEnabled;
public bool IsBuiltIn => SelectedPlugin?.IsBuiltIn ?? false;
/// <summary>
+4 -4
View File
@@ -98,7 +98,7 @@
<Border x:Name="BorderBtnRand" MouseUp="BorderBtnRand_MouseUp" Background="#0066BF" Height="70" Width="200" CornerRadius="35">
<ui:SimpleStackPanel Margin="3,0" Spacing="20" Orientation="Horizontal" HorizontalAlignment="Center">
<Viewbox Margin="0,20">
<ui:SymbolIcon Name="SymbolIconStart" Symbol="Contact" Foreground="White"/>
<ui:FontIcon Name="FontIconStart" Glyph="&#xE779;" Foreground="White"/>
</Viewbox>
<TextBlock Text="开抽" Foreground="White" FontSize="32" Margin="-1,-1,4,0" VerticalAlignment="Center"/>
</ui:SimpleStackPanel>
@@ -113,7 +113,7 @@
<Border x:Name="BorderBtnExternalCaller" MouseUp="BorderBtnExternalCaller_MouseUp" Background="#00B894" Height="50" Width="120" CornerRadius="25">
<ui:SimpleStackPanel Margin="3,0" Spacing="8" Orientation="Horizontal" HorizontalAlignment="Center">
<Viewbox Margin="0,10">
<ui:SymbolIcon Symbol="Globe" Foreground="White"/>
<ui:FontIcon Glyph="&#xE909;" Foreground="White"/>
</Viewbox>
<TextBlock Text="外部点名" Foreground="White" FontSize="16" Margin="-1,-1,4,0" VerticalAlignment="Center"/>
</ui:SimpleStackPanel>
@@ -127,7 +127,7 @@
</Border.Effect>
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Viewbox Margin="15,12">
<ui:SymbolIcon Symbol="People" Foreground="Black"/>
<ui:FontIcon Glyph="&#xE716;" Foreground="Black"/>
</Viewbox>
<TextBlock Margin="-5,12,15,12" Name="TextBlockPeopleCount" Text="点击此处以导入名单" FontSize="16" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</ui:SimpleStackPanel>
@@ -137,7 +137,7 @@
<DropShadowEffect Direction="0" ShadowDepth="0" Opacity="0.1" BlurRadius="3"/>
</Border.Effect>
<Viewbox Margin="14">
<ui:SymbolIcon Symbol="Clear" Foreground="White"/>
<ui:FontIcon Glyph="&#xE8BB;" Foreground="White"/>
</Viewbox>
</Border>
</Canvas>
+2 -2
View File
@@ -100,7 +100,7 @@ namespace Ink_Canvas
if (RandMaxPeopleOneTime != -1 && TotalCount >= RandMaxPeopleOneTime) return;
TotalCount++;
LabelNumberCount.Text = TotalCount.ToString();
SymbolIconStart.Symbol = Symbol.People;
FontIconStart.Glyph = "&#xE779;";
BorderBtnAdd.Opacity = 1;
BorderBtnMinus.Opacity = 1;
}
@@ -112,7 +112,7 @@ namespace Ink_Canvas
LabelNumberCount.Text = TotalCount.ToString();
if (TotalCount == 1)
{
SymbolIconStart.Symbol = Symbol.Contact;
FontIconStart.Glyph = "&#xE779;";
}
}