代码清理
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace Ink_Canvas
|
||||
{
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace Ink_Canvas
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Ink_Canvas.Helpers;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Media;
|
||||
using System.Timers;
|
||||
@@ -7,7 +8,6 @@ using System.Windows.Forms;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
using Ink_Canvas.Helpers;
|
||||
using Application = System.Windows.Application;
|
||||
using MouseEventArgs = System.Windows.Input.MouseEventArgs;
|
||||
using Timer = System.Timers.Timer;
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using System;
|
||||
using Ink_Canvas.Helpers;
|
||||
using iNKORE.UI.WPF.Modern.Controls;
|
||||
using MdXaml;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -10,9 +13,6 @@ using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
using Ink_Canvas.Helpers;
|
||||
using iNKORE.UI.WPF.Modern.Controls;
|
||||
using MdXaml;
|
||||
|
||||
namespace Ink_Canvas
|
||||
{
|
||||
@@ -340,7 +340,7 @@ namespace Ink_Canvas
|
||||
downloadUrl = Path.Combine(updatesFolderPath, $"InkCanvasForClass.CE.{version}.zip");
|
||||
}
|
||||
LogHelper.WriteLogToFile($"AutoUpdate | 开始安装版本: {version}");
|
||||
AutoUpdateHelper.InstallNewVersionApp(version, true);
|
||||
AutoUpdateHelper.InstallNewVersionApp(version, true);
|
||||
App.IsAppExitByUser = true;
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Ink_Canvas.Helpers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@@ -7,7 +8,6 @@ using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using Ink_Canvas.Helpers;
|
||||
|
||||
// Added for OrderByDescending
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Ink_Canvas.Windows
|
||||
|
||||
public string DefaultKey { get; set; }
|
||||
public string DefaultModifiers { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 快捷键名称(用于标识,如"Undo")
|
||||
/// </summary>
|
||||
@@ -94,10 +94,10 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
BtnSetHotkey.Content = "请按键...";
|
||||
BtnSetHotkey.Background = Brushes.Orange;
|
||||
|
||||
|
||||
// 设置焦点以捕获键盘事件
|
||||
Focus();
|
||||
|
||||
|
||||
// 添加键盘事件处理器
|
||||
KeyDown += HotkeyItem_KeyDown;
|
||||
KeyUp += HotkeyItem_KeyUp;
|
||||
@@ -107,7 +107,7 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
BtnSetHotkey.Content = "设置";
|
||||
BtnSetHotkey.Background = Brushes.DodgerBlue;
|
||||
|
||||
|
||||
// 移除键盘事件处理器
|
||||
KeyDown -= HotkeyItem_KeyDown;
|
||||
KeyUp -= HotkeyItem_KeyUp;
|
||||
@@ -116,7 +116,7 @@ namespace Ink_Canvas.Windows
|
||||
private void HotkeyItem_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
e.Handled = true;
|
||||
|
||||
|
||||
// 忽略某些特殊键
|
||||
if (e.Key == Key.LeftShift || e.Key == Key.RightShift ||
|
||||
e.Key == Key.LeftCtrl || e.Key == Key.RightCtrl ||
|
||||
@@ -140,10 +140,10 @@ namespace Ink_Canvas.Windows
|
||||
// 设置新的快捷键
|
||||
var oldKey = _currentKey;
|
||||
var oldModifiers = _currentModifiers;
|
||||
|
||||
|
||||
_currentKey = e.Key;
|
||||
_currentModifiers = modifiers;
|
||||
|
||||
|
||||
UpdateHotkeyDisplay();
|
||||
StopHotkeyCapture();
|
||||
|
||||
@@ -169,4 +169,4 @@ namespace Ink_Canvas.Windows
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
using Ink_Canvas.Helpers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using Ink_Canvas.Helpers;
|
||||
|
||||
namespace Ink_Canvas.Windows
|
||||
{
|
||||
@@ -30,15 +30,15 @@ namespace Ink_Canvas.Windows
|
||||
// 隐藏主窗口的设置页面
|
||||
HideMainWindowSettings();
|
||||
InitializeHotkeyItems();
|
||||
|
||||
|
||||
// 延迟加载快捷键,确保快捷键管理器已完全初始化
|
||||
Loaded += (s, e) =>
|
||||
Loaded += (s, e) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
// 不启用快捷键注册功能,只读取配置文件中的快捷键信息用于显示
|
||||
// 这样用户可以看到配置文件中保存的快捷键,但不会自动注册
|
||||
|
||||
|
||||
// 加载当前快捷键(包括配置文件中的)
|
||||
LoadCurrentHotkeys();
|
||||
SetupEventHandlers();
|
||||
@@ -60,62 +60,62 @@ namespace Ink_Canvas.Windows
|
||||
try
|
||||
{
|
||||
LogHelper.WriteLogToFile("开始初始化快捷键项");
|
||||
|
||||
|
||||
// 初始化快捷键项并设置HotkeyName
|
||||
_hotkeyItems["Undo"] = UndoHotkey;
|
||||
UndoHotkey.HotkeyName = "Undo";
|
||||
|
||||
|
||||
_hotkeyItems["Redo"] = RedoHotkey;
|
||||
RedoHotkey.HotkeyName = "Redo";
|
||||
|
||||
|
||||
_hotkeyItems["Clear"] = ClearHotkey;
|
||||
ClearHotkey.HotkeyName = "Clear";
|
||||
|
||||
|
||||
_hotkeyItems["Paste"] = PasteHotkey;
|
||||
PasteHotkey.HotkeyName = "Paste";
|
||||
|
||||
|
||||
_hotkeyItems["SelectTool"] = SelectToolHotkey;
|
||||
SelectToolHotkey.HotkeyName = "SelectTool";
|
||||
|
||||
|
||||
_hotkeyItems["DrawTool"] = DrawToolHotkey;
|
||||
DrawToolHotkey.HotkeyName = "DrawTool";
|
||||
|
||||
|
||||
_hotkeyItems["EraserTool"] = EraserToolHotkey;
|
||||
EraserToolHotkey.HotkeyName = "EraserTool";
|
||||
|
||||
|
||||
_hotkeyItems["BlackboardTool"] = BlackboardToolHotkey;
|
||||
BlackboardToolHotkey.HotkeyName = "BlackboardTool";
|
||||
|
||||
|
||||
_hotkeyItems["QuitDrawTool"] = QuitDrawToolHotkey;
|
||||
QuitDrawToolHotkey.HotkeyName = "QuitDrawTool";
|
||||
|
||||
|
||||
_hotkeyItems["Pen1"] = Pen1Hotkey;
|
||||
Pen1Hotkey.HotkeyName = "Pen1";
|
||||
|
||||
|
||||
_hotkeyItems["Pen2"] = Pen2Hotkey;
|
||||
Pen2Hotkey.HotkeyName = "Pen2";
|
||||
|
||||
|
||||
_hotkeyItems["Pen3"] = Pen3Hotkey;
|
||||
Pen3Hotkey.HotkeyName = "Pen3";
|
||||
|
||||
|
||||
_hotkeyItems["Pen4"] = Pen4Hotkey;
|
||||
Pen4Hotkey.HotkeyName = "Pen4";
|
||||
|
||||
|
||||
_hotkeyItems["Pen5"] = Pen5Hotkey;
|
||||
Pen5Hotkey.HotkeyName = "Pen5";
|
||||
|
||||
|
||||
_hotkeyItems["DrawLine"] = DrawLineHotkey;
|
||||
DrawLineHotkey.HotkeyName = "DrawLine";
|
||||
|
||||
|
||||
_hotkeyItems["Screenshot"] = ScreenshotHotkey;
|
||||
ScreenshotHotkey.HotkeyName = "Screenshot";
|
||||
|
||||
|
||||
_hotkeyItems["Hide"] = HideHotkey;
|
||||
HideHotkey.HotkeyName = "Hide";
|
||||
|
||||
|
||||
_hotkeyItems["Exit"] = ExitHotkey;
|
||||
ExitHotkey.HotkeyName = "Exit";
|
||||
|
||||
|
||||
LogHelper.WriteLogToFile($"成功初始化 {_hotkeyItems.Count} 个快捷键项");
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -131,7 +131,7 @@ namespace Ink_Canvas.Windows
|
||||
// 首先尝试从配置文件获取快捷键信息
|
||||
var configHotkeys = _hotkeyManager.GetHotkeysFromConfigFile();
|
||||
LogHelper.WriteLogToFile($"配置文件中的快捷键数量: {configHotkeys.Count}");
|
||||
|
||||
|
||||
// 显示配置文件中的快捷键
|
||||
foreach (var hotkey in configHotkeys)
|
||||
{
|
||||
@@ -141,7 +141,7 @@ namespace Ink_Canvas.Windows
|
||||
LogHelper.WriteLogToFile($"从配置文件设置快捷键项: {hotkey.Name} -> {hotkey.Modifiers}+{hotkey.Key}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 为没有快捷键的项目设置默认显示值(仅用于UI显示,不实际注册)
|
||||
foreach (var kvp in _hotkeyItems)
|
||||
{
|
||||
@@ -246,11 +246,11 @@ namespace Ink_Canvas.Windows
|
||||
try
|
||||
{
|
||||
LogHelper.WriteLogToFile($"收到快捷键变更事件: {e.HotkeyName} -> {e.Modifiers}+{e.Key}");
|
||||
|
||||
|
||||
// 检查快捷键冲突
|
||||
if (IsHotkeyConflict(e.Key, e.Modifiers, e.HotkeyName))
|
||||
{
|
||||
MessageBox.Show($"快捷键 {e.Modifiers}+{e.Key} 已被其他功能使用,请选择其他组合。",
|
||||
MessageBox.Show($"快捷键 {e.Modifiers}+{e.Key} 已被其他功能使用,请选择其他组合。",
|
||||
"快捷键冲突", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
@@ -270,14 +270,14 @@ namespace Ink_Canvas.Windows
|
||||
var registeredHotkeys = _hotkeyManager.GetRegisteredHotkeys();
|
||||
foreach (var hotkey in registeredHotkeys)
|
||||
{
|
||||
if (hotkey.Name != excludeHotkeyName &&
|
||||
hotkey.Key == key &&
|
||||
if (hotkey.Name != excludeHotkeyName &&
|
||||
hotkey.Key == key &&
|
||||
hotkey.Modifiers == modifiers)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 检查是否与默认快捷键冲突(如果当前快捷键项还没有注册)
|
||||
if (excludeHotkeyName != null && _hotkeyItems.TryGetValue(excludeHotkeyName, out var currentItem))
|
||||
{
|
||||
@@ -299,7 +299,7 @@ namespace Ink_Canvas.Windows
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -308,30 +308,30 @@ namespace Ink_Canvas.Windows
|
||||
try
|
||||
{
|
||||
LogHelper.WriteLogToFile($"开始更新快捷键: {hotkeyName} -> {modifiers}+{key}");
|
||||
|
||||
|
||||
// 先注销原有的快捷键(如果存在)
|
||||
_hotkeyManager.UnregisterHotkey(hotkeyName);
|
||||
LogHelper.WriteLogToFile($"已注销原有快捷键: {hotkeyName}");
|
||||
|
||||
|
||||
// 根据快捷键名称获取对应的动作
|
||||
var action = GetActionForHotkey(hotkeyName);
|
||||
if (action != null)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"找到快捷键动作: {hotkeyName}");
|
||||
|
||||
|
||||
// 直接注册新的快捷键
|
||||
if (_hotkeyManager.RegisterHotkey(hotkeyName, key, modifiers, action))
|
||||
{
|
||||
LogHelper.WriteLogToFile($"成功注册新快捷键: {hotkeyName} -> {modifiers}+{key}");
|
||||
|
||||
|
||||
// 立即保存到配置文件
|
||||
_hotkeyManager.SaveHotkeysToSettings();
|
||||
LogHelper.WriteLogToFile("已保存快捷键配置");
|
||||
|
||||
|
||||
// 更新UI显示
|
||||
LoadCurrentHotkeys();
|
||||
LogHelper.WriteLogToFile("已更新UI显示");
|
||||
|
||||
|
||||
LogHelper.WriteLogToFile($"快捷键 {hotkeyName} 已更新为 {modifiers}+{key} 并保存", LogHelper.LogType.Event);
|
||||
}
|
||||
else
|
||||
@@ -404,17 +404,17 @@ namespace Ink_Canvas.Windows
|
||||
try
|
||||
{
|
||||
// 通过反射访问主窗口的penType字段
|
||||
var penTypeField = _mainWindow.GetType().GetField("penType",
|
||||
var penTypeField = _mainWindow.GetType().GetField("penType",
|
||||
BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
|
||||
|
||||
if (penTypeField != null)
|
||||
{
|
||||
penTypeField.SetValue(_mainWindow, penTypeIndex);
|
||||
|
||||
|
||||
// 调用CheckPenTypeUIState方法更新UI状态
|
||||
var checkPenTypeMethod = _mainWindow.GetType().GetMethod("CheckPenTypeUIState",
|
||||
var checkPenTypeMethod = _mainWindow.GetType().GetMethod("CheckPenTypeUIState",
|
||||
BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
|
||||
|
||||
if (checkPenTypeMethod != null)
|
||||
{
|
||||
checkPenTypeMethod.Invoke(_mainWindow, null);
|
||||
@@ -437,18 +437,18 @@ namespace Ink_Canvas.Windows
|
||||
try
|
||||
{
|
||||
// 通过反射访问主窗口的设置面板
|
||||
var settingsBorder = _mainWindow.GetType().GetField("BorderSettings",
|
||||
var settingsBorder = _mainWindow.GetType().GetField("BorderSettings",
|
||||
BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(_mainWindow) as Border;
|
||||
|
||||
|
||||
if (settingsBorder != null)
|
||||
{
|
||||
settingsBorder.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
// 隐藏设置蒙版
|
||||
var settingsMask = _mainWindow.GetType().GetField("BorderSettingsMask",
|
||||
var settingsMask = _mainWindow.GetType().GetField("BorderSettingsMask",
|
||||
BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(_mainWindow) as Border;
|
||||
|
||||
|
||||
if (settingsMask != null)
|
||||
{
|
||||
settingsMask.Visibility = Visibility.Collapsed;
|
||||
@@ -468,18 +468,18 @@ namespace Ink_Canvas.Windows
|
||||
try
|
||||
{
|
||||
// 通过反射访问主窗口的设置面板
|
||||
var settingsBorder = _mainWindow.GetType().GetField("BorderSettings",
|
||||
var settingsBorder = _mainWindow.GetType().GetField("BorderSettings",
|
||||
BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(_mainWindow) as Border;
|
||||
|
||||
|
||||
if (settingsBorder != null)
|
||||
{
|
||||
settingsBorder.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
// 显示设置蒙版
|
||||
var settingsMask = _mainWindow.GetType().GetField("BorderSettingsMask",
|
||||
var settingsMask = _mainWindow.GetType().GetField("BorderSettingsMask",
|
||||
BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(_mainWindow) as Border;
|
||||
|
||||
|
||||
if (settingsMask != null)
|
||||
{
|
||||
settingsMask.Visibility = Visibility.Visible;
|
||||
@@ -513,22 +513,22 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = MessageBox.Show("确定要重置所有快捷键为默认设置吗?",
|
||||
var result = MessageBox.Show("确定要重置所有快捷键为默认设置吗?",
|
||||
"确认重置", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
if (result == MessageBoxResult.Yes)
|
||||
{
|
||||
// 先注销所有现有快捷键
|
||||
_hotkeyManager.UnregisterAllHotkeys();
|
||||
|
||||
|
||||
// 重置为默认快捷键
|
||||
_hotkeyManager.RegisterDefaultHotkeys();
|
||||
|
||||
|
||||
// 立即保存到配置文件
|
||||
_hotkeyManager.SaveHotkeysToSettings();
|
||||
|
||||
|
||||
// 更新UI显示
|
||||
LoadCurrentHotkeys();
|
||||
|
||||
|
||||
MessageBox.Show("快捷键已重置为默认设置。", "重置完成", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
@@ -545,7 +545,7 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
// 保存快捷键配置
|
||||
_hotkeyManager.SaveHotkeysToSettings();
|
||||
|
||||
|
||||
MessageBox.Show("快捷键设置已保存。", "保存成功", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
Close();
|
||||
}
|
||||
@@ -569,4 +569,4 @@ namespace Ink_Canvas.Windows
|
||||
public ModifierKeys Modifiers { get; set; }
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.ComponentModel;
|
||||
using Ink_Canvas.Helpers;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using Ink_Canvas.Helpers;
|
||||
|
||||
namespace Ink_Canvas
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Windows;
|
||||
using Ink_Canvas.Helpers;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using Ink_Canvas.Helpers;
|
||||
|
||||
namespace Ink_Canvas
|
||||
{
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
using Ink_Canvas.Helpers;
|
||||
using Ink_Canvas.Helpers.Plugins;
|
||||
using Ink_Canvas.Helpers.Plugins.BuiltIn;
|
||||
using Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher;
|
||||
using iNKORE.UI.WPF.Modern.Controls;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
@@ -6,12 +12,6 @@ using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Threading;
|
||||
using Ink_Canvas.Helpers;
|
||||
using Ink_Canvas.Helpers.Plugins;
|
||||
using Ink_Canvas.Helpers.Plugins.BuiltIn;
|
||||
using Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher;
|
||||
using iNKORE.UI.WPF.Modern.Controls;
|
||||
using Microsoft.Win32;
|
||||
using MessageBox = System.Windows.MessageBox;
|
||||
|
||||
namespace Ink_Canvas.Windows
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using Ink_Canvas.Helpers;
|
||||
using Microsoft.VisualBasic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
@@ -8,8 +10,6 @@ using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Ink_Canvas.Helpers;
|
||||
using Microsoft.VisualBasic;
|
||||
using MessageBox = iNKORE.UI.WPF.Modern.Controls.MessageBox;
|
||||
|
||||
namespace Ink_Canvas
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace Ink_Canvas
|
||||
private void BindControlPointEvents()
|
||||
{
|
||||
// 绑定所有控制点的鼠标事件
|
||||
var controlPoints = new[]
|
||||
var controlPoints = new[]
|
||||
{
|
||||
TopLeftControl, TopRightControl, BottomLeftControl, BottomRightControl,
|
||||
TopControl, BottomControl, LeftControl, RightControl
|
||||
@@ -92,11 +92,11 @@ namespace Ink_Canvas
|
||||
control.MouseLeftButtonDown += ControlPoint_MouseLeftButtonDown;
|
||||
control.MouseLeftButtonUp += ControlPoint_MouseLeftButtonUp;
|
||||
control.MouseMove += ControlPoint_MouseMove;
|
||||
|
||||
|
||||
// 确保控制点能够接收鼠标事件
|
||||
control.IsHitTestVisible = true;
|
||||
control.Focusable = false;
|
||||
|
||||
|
||||
// 设置控制点的Z-index,确保它们在最上层
|
||||
WpfCanvas.SetZIndex(control, 1003);
|
||||
}
|
||||
@@ -142,7 +142,7 @@ namespace Ink_Canvas
|
||||
{
|
||||
// 重置所有选择状态
|
||||
ResetSelectionState();
|
||||
|
||||
|
||||
_isFreehandMode = false;
|
||||
RectangleModeButton.Background = new SolidColorBrush(Color.FromRgb(37, 99, 235)); // 蓝色
|
||||
FreehandModeButton.Background = new SolidColorBrush(Color.FromRgb(107, 114, 128)); // 灰色
|
||||
@@ -154,7 +154,7 @@ namespace Ink_Canvas
|
||||
{
|
||||
// 重置所有选择状态
|
||||
ResetSelectionState();
|
||||
|
||||
|
||||
_isFreehandMode = true;
|
||||
FreehandModeButton.Background = new SolidColorBrush(Color.FromRgb(37, 99, 235)); // 蓝色
|
||||
RectangleModeButton.Background = new SolidColorBrush(Color.FromRgb(107, 114, 128)); // 灰色
|
||||
@@ -169,7 +169,7 @@ namespace Ink_Canvas
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ConfirmSelection();
|
||||
}
|
||||
|
||||
@@ -183,10 +183,10 @@ namespace Ink_Canvas
|
||||
// 检查是否点击了UI元素,如果是则不处理选择
|
||||
var hitElement = e.Source as FrameworkElement;
|
||||
if (hitElement != null && (
|
||||
hitElement is Ellipse ||
|
||||
hitElement is System.Windows.Controls.Button ||
|
||||
hitElement is Border ||
|
||||
hitElement is TextBlock ||
|
||||
hitElement is Ellipse ||
|
||||
hitElement is System.Windows.Controls.Button ||
|
||||
hitElement is Border ||
|
||||
hitElement is TextBlock ||
|
||||
hitElement is StackPanel ||
|
||||
hitElement is Separator ||
|
||||
hitElement.Name == "SizeInfoBorder" ||
|
||||
@@ -221,7 +221,7 @@ namespace Ink_Canvas
|
||||
_freehandPolyline.Points.Clear();
|
||||
_freehandPoints.Add(_startPoint);
|
||||
_freehandPolyline.Points.Add(_startPoint);
|
||||
|
||||
|
||||
// 确保自由绘制路径可见
|
||||
_freehandPolyline.Visibility = Visibility.Visible;
|
||||
}
|
||||
@@ -252,7 +252,7 @@ namespace Ink_Canvas
|
||||
// 自由绘制模式:添加点到路径
|
||||
_freehandPoints.Add(_currentPoint);
|
||||
_freehandPolyline.Points.Add(_currentPoint);
|
||||
|
||||
|
||||
// 确保自由绘制路径可见
|
||||
_freehandPolyline.Visibility = Visibility.Visible;
|
||||
}
|
||||
@@ -278,7 +278,7 @@ namespace Ink_Canvas
|
||||
{
|
||||
// 创建路径的副本,避免修改原始列表
|
||||
var pathPoints = new List<Point>(_freehandPoints);
|
||||
|
||||
|
||||
// 简化路径处理,不强制闭合
|
||||
// 如果路径没有闭合,自动添加起始点
|
||||
if (pathPoints.Count > 0)
|
||||
@@ -288,13 +288,13 @@ namespace Ink_Canvas
|
||||
|
||||
// 优化路径:移除重复点和过于接近的点,提高路径质量
|
||||
var optimizedPath = OptimizePath(pathPoints);
|
||||
|
||||
|
||||
// 保存选择的路径
|
||||
SelectedPath = optimizedPath;
|
||||
|
||||
// 计算边界矩形用于截图
|
||||
var bounds = CalculatePathBounds(optimizedPath);
|
||||
|
||||
|
||||
// 确保边界矩形有效
|
||||
if (bounds.Width >= 0 && bounds.Height >= 0)
|
||||
{
|
||||
@@ -312,7 +312,7 @@ namespace Ink_Canvas
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 如果自由绘制失败,清除路径并继续
|
||||
_freehandPoints.Clear();
|
||||
_freehandPolyline.Points.Clear();
|
||||
@@ -350,7 +350,7 @@ namespace Ink_Canvas
|
||||
|
||||
_isMoving = true;
|
||||
_lastMousePosition = e.GetPosition(this);
|
||||
|
||||
|
||||
// 确定当前控制点类型
|
||||
var ellipse = sender as Ellipse;
|
||||
if (ellipse == TopLeftControl) _activeControlPoint = ControlPointType.TopLeft;
|
||||
@@ -467,26 +467,26 @@ namespace Ink_Canvas
|
||||
// 更新角控制点位置
|
||||
WpfCanvas.SetLeft(TopLeftControl, rect.Left - 4);
|
||||
WpfCanvas.SetTop(TopLeftControl, rect.Top - 4);
|
||||
|
||||
|
||||
WpfCanvas.SetLeft(TopRightControl, rect.Right - 4);
|
||||
WpfCanvas.SetTop(TopRightControl, rect.Top - 4);
|
||||
|
||||
|
||||
WpfCanvas.SetLeft(BottomLeftControl, rect.Left - 4);
|
||||
WpfCanvas.SetTop(BottomLeftControl, rect.Bottom - 4);
|
||||
|
||||
|
||||
WpfCanvas.SetLeft(BottomRightControl, rect.Right - 4);
|
||||
WpfCanvas.SetTop(BottomRightControl, rect.Bottom - 4);
|
||||
|
||||
// 更新边控制点位置
|
||||
WpfCanvas.SetLeft(TopControl, rect.Left + rect.Width / 2 - 4);
|
||||
WpfCanvas.SetTop(TopControl, rect.Top - 4);
|
||||
|
||||
|
||||
WpfCanvas.SetLeft(BottomControl, rect.Left + rect.Width / 2 - 4);
|
||||
WpfCanvas.SetTop(BottomControl, rect.Bottom - 4);
|
||||
|
||||
|
||||
WpfCanvas.SetLeft(LeftControl, rect.Left - 4);
|
||||
WpfCanvas.SetTop(LeftControl, rect.Top + rect.Height / 2 - 4);
|
||||
|
||||
|
||||
WpfCanvas.SetLeft(RightControl, rect.Right - 4);
|
||||
WpfCanvas.SetTop(RightControl, rect.Top + rect.Height / 2 - 4);
|
||||
}
|
||||
@@ -522,7 +522,7 @@ namespace Ink_Canvas
|
||||
{
|
||||
// 更新选择区域的几何体
|
||||
SelectionClipGeometry.Rect = selectionRect;
|
||||
|
||||
|
||||
// 显示透明遮罩,隐藏原始遮罩
|
||||
TransparentSelectionMask.Visibility = Visibility.Visible;
|
||||
OverlayRectangle.Visibility = Visibility.Collapsed;
|
||||
@@ -580,7 +580,7 @@ namespace Ink_Canvas
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (_isAdjusting)
|
||||
{
|
||||
// 转换为屏幕坐标,考虑DPI缩放
|
||||
@@ -701,29 +701,29 @@ namespace Ink_Canvas
|
||||
_isAdjusting = false;
|
||||
_isMoving = false;
|
||||
_activeControlPoint = ControlPointType.None;
|
||||
|
||||
|
||||
// 清除自由绘制的内容
|
||||
_freehandPoints.Clear();
|
||||
_freehandPolyline.Points.Clear();
|
||||
_freehandPolyline.Visibility = Visibility.Collapsed;
|
||||
|
||||
|
||||
// 清除矩形选择的内容
|
||||
SelectionRectangle.Visibility = Visibility.Collapsed;
|
||||
ControlPointsCanvas.Visibility = Visibility.Collapsed;
|
||||
SizeInfoBorder.Visibility = Visibility.Collapsed;
|
||||
SelectionPath.Visibility = Visibility.Collapsed;
|
||||
AdjustModeHint.Visibility = Visibility.Collapsed;
|
||||
|
||||
|
||||
// 重置遮罩
|
||||
TransparentSelectionMask.Visibility = Visibility.Collapsed;
|
||||
OverlayRectangle.Visibility = Visibility.Visible;
|
||||
|
||||
|
||||
// 释放鼠标捕获
|
||||
if (IsMouseCaptured)
|
||||
{
|
||||
ReleaseMouseCapture();
|
||||
}
|
||||
|
||||
|
||||
// 重置选择区域
|
||||
_currentSelection = new Rect();
|
||||
SelectedArea = null;
|
||||
|
||||
Reference in New Issue
Block a user