代码清理

This commit is contained in:
PrefacedCorg
2025-09-07 13:30:46 +08:00
parent ad8369cfe9
commit 084cbcd362
33 changed files with 669 additions and 489 deletions
+3 -3
View File
@@ -633,13 +633,13 @@ namespace Ink_Canvas
if (!ret && !e.Args.Contains("-m")) //-m multiple if (!ret && !e.Args.Contains("-m")) //-m multiple
{ {
LogHelper.NewLog("Detected existing instance"); LogHelper.NewLog("Detected existing instance");
// 检查是否有.icstk文件参数 // 检查是否有.icstk文件参数
string icstkFile = FileAssociationManager.GetIcstkFileFromArgs(e.Args); string icstkFile = FileAssociationManager.GetIcstkFileFromArgs(e.Args);
if (!string.IsNullOrEmpty(icstkFile)) if (!string.IsNullOrEmpty(icstkFile))
{ {
LogHelper.WriteLogToFile($"检测到已运行实例,尝试通过IPC发送文件: {icstkFile}", LogHelper.LogType.Event); LogHelper.WriteLogToFile($"检测到已运行实例,尝试通过IPC发送文件: {icstkFile}", LogHelper.LogType.Event);
// 尝试通过IPC发送文件路径给已运行实例 // 尝试通过IPC发送文件路径给已运行实例
if (FileAssociationManager.TrySendFileToExistingInstance(icstkFile)) if (FileAssociationManager.TrySendFileToExistingInstance(icstkFile))
{ {
@@ -654,7 +654,7 @@ namespace Ink_Canvas
{ {
LogHelper.WriteLogToFile("检测到已运行实例,但无文件参数", LogHelper.LogType.Event); LogHelper.WriteLogToFile("检测到已运行实例,但无文件参数", LogHelper.LogType.Event);
} }
LogHelper.NewLog("Ink Canvas automatically closed"); LogHelper.NewLog("Ink Canvas automatically closed");
IsAppExitByUser = true; // 多开时标记为用户主动退出 IsAppExitByUser = true; // 多开时标记为用户主动退出
// 写入退出信号,确保看门狗不会重启 // 写入退出信号,确保看门狗不会重启
+1 -1
View File
@@ -1092,7 +1092,7 @@ namespace Ink_Canvas.Helpers
{ {
int versionDiff = CalculateVersionGenerationDifference(localVersion, updateVersion); int versionDiff = CalculateVersionGenerationDifference(localVersion, updateVersion);
LogHelper.WriteLogToFile($"DeviceIdentifier | 无法获取版本发布时间,使用版本号差异判断 - 本地版本: {localVersion}, 远程版本: {updateVersion}, 代数差异: {versionDiff}"); LogHelper.WriteLogToFile($"DeviceIdentifier | 无法获取版本发布时间,使用版本号差异判断 - 本地版本: {localVersion}, 远程版本: {updateVersion}, 代数差异: {versionDiff}");
// 当版本号代数差异大于3时自动更新 // 当版本号代数差异大于3时自动更新
if (versionDiff > 3) if (versionDiff > 3)
{ {
+38 -38
View File
@@ -1,12 +1,12 @@
using Microsoft.Win32;
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security; using System.Security;
using System.Windows;
using Microsoft.Win32;
using System.Threading;
using System.Text; using System.Text;
using System.Threading;
using System.Windows;
namespace Ink_Canvas.Helpers namespace Ink_Canvas.Helpers
{ {
@@ -19,7 +19,7 @@ namespace Ink_Canvas.Helpers
private const string FileTypeName = "InkCanvasStrokesFile"; private const string FileTypeName = "InkCanvasStrokesFile";
private const string AppName = "Ink Canvas"; private const string AppName = "Ink Canvas";
private const string AppDescription = "Ink Canvas Strokes File"; private const string AppDescription = "Ink Canvas Strokes File";
// IPC相关常量 // IPC相关常量
private const string IpcMutexName = "InkCanvasFileAssociationIpc"; private const string IpcMutexName = "InkCanvasFileAssociationIpc";
private const string IpcEventName = "InkCanvasFileAssociationEvent"; private const string IpcEventName = "InkCanvasFileAssociationEvent";
@@ -34,19 +34,19 @@ namespace Ink_Canvas.Helpers
try try
{ {
string exePath = Process.GetCurrentProcess().MainModule.FileName; string exePath = Process.GetCurrentProcess().MainModule.FileName;
// 注册文件类型 // 注册文件类型
using (RegistryKey fileTypeKey = Registry.ClassesRoot.CreateSubKey(FileTypeName)) using (RegistryKey fileTypeKey = Registry.ClassesRoot.CreateSubKey(FileTypeName))
{ {
fileTypeKey.SetValue("", AppDescription); fileTypeKey.SetValue("", AppDescription);
fileTypeKey.SetValue("FriendlyTypeName", AppDescription); fileTypeKey.SetValue("FriendlyTypeName", AppDescription);
// 设置默认图标 // 设置默认图标
using (RegistryKey defaultIconKey = fileTypeKey.CreateSubKey("DefaultIcon")) using (RegistryKey defaultIconKey = fileTypeKey.CreateSubKey("DefaultIcon"))
{ {
defaultIconKey.SetValue("", $"\"{exePath}\",0"); defaultIconKey.SetValue("", $"\"{exePath}\",0");
} }
// 设置打开命令 // 设置打开命令
using (RegistryKey shellKey = fileTypeKey.CreateSubKey("shell")) using (RegistryKey shellKey = fileTypeKey.CreateSubKey("shell"))
using (RegistryKey openKey = shellKey.CreateSubKey("open")) using (RegistryKey openKey = shellKey.CreateSubKey("open"))
@@ -55,16 +55,16 @@ namespace Ink_Canvas.Helpers
commandKey.SetValue("", $"\"{exePath}\" \"%1\""); commandKey.SetValue("", $"\"{exePath}\" \"%1\"");
} }
} }
// 注册文件扩展名 // 注册文件扩展名
using (RegistryKey extensionKey = Registry.ClassesRoot.CreateSubKey(FileExtension)) using (RegistryKey extensionKey = Registry.ClassesRoot.CreateSubKey(FileExtension))
{ {
extensionKey.SetValue("", FileTypeName); extensionKey.SetValue("", FileTypeName);
} }
// 刷新系统文件关联缓存 // 刷新系统文件关联缓存
RefreshSystemFileAssociations(); RefreshSystemFileAssociations();
LogHelper.WriteLogToFile($"成功注册{FileExtension}文件关联", LogHelper.LogType.Event); LogHelper.WriteLogToFile($"成功注册{FileExtension}文件关联", LogHelper.LogType.Event);
return true; return true;
} }
@@ -94,13 +94,13 @@ namespace Ink_Canvas.Helpers
{ {
// 删除文件扩展名关联 // 删除文件扩展名关联
Registry.ClassesRoot.DeleteSubKeyTree(FileExtension, false); Registry.ClassesRoot.DeleteSubKeyTree(FileExtension, false);
// 删除文件类型定义 // 删除文件类型定义
Registry.ClassesRoot.DeleteSubKeyTree(FileTypeName, false); Registry.ClassesRoot.DeleteSubKeyTree(FileTypeName, false);
// 刷新系统文件关联缓存 // 刷新系统文件关联缓存
RefreshSystemFileAssociations(); RefreshSystemFileAssociations();
LogHelper.WriteLogToFile($"成功注销{FileExtension}文件关联", LogHelper.LogType.Event); LogHelper.WriteLogToFile($"成功注销{FileExtension}文件关联", LogHelper.LogType.Event);
return true; return true;
} }
@@ -121,21 +121,21 @@ namespace Ink_Canvas.Helpers
using (RegistryKey extensionKey = Registry.ClassesRoot.OpenSubKey(FileExtension)) using (RegistryKey extensionKey = Registry.ClassesRoot.OpenSubKey(FileExtension))
{ {
if (extensionKey == null) return false; if (extensionKey == null) return false;
string fileType = extensionKey.GetValue("") as string; string fileType = extensionKey.GetValue("") as string;
if (string.IsNullOrEmpty(fileType)) return false; if (string.IsNullOrEmpty(fileType)) return false;
using (RegistryKey fileTypeKey = Registry.ClassesRoot.OpenSubKey(fileType)) using (RegistryKey fileTypeKey = Registry.ClassesRoot.OpenSubKey(fileType))
{ {
if (fileTypeKey == null) return false; if (fileTypeKey == null) return false;
using (RegistryKey shellKey = fileTypeKey.OpenSubKey("shell\\open\\command")) using (RegistryKey shellKey = fileTypeKey.OpenSubKey("shell\\open\\command"))
{ {
if (shellKey == null) return false; if (shellKey == null) return false;
string command = shellKey.GetValue("") as string; string command = shellKey.GetValue("") as string;
if (string.IsNullOrEmpty(command)) return false; if (string.IsNullOrEmpty(command)) return false;
// 检查命令是否指向当前应用程序 // 检查命令是否指向当前应用程序
string currentExePath = Process.GetCurrentProcess().MainModule.FileName; string currentExePath = Process.GetCurrentProcess().MainModule.FileName;
return command.Contains(currentExePath); return command.Contains(currentExePath);
@@ -147,7 +147,7 @@ namespace Ink_Canvas.Helpers
{ {
LogHelper.WriteLogToFile($"检查文件关联状态时出错: {ex.Message}", LogHelper.LogType.Error); LogHelper.WriteLogToFile($"检查文件关联状态时出错: {ex.Message}", LogHelper.LogType.Error);
} }
return false; return false;
} }
@@ -184,11 +184,11 @@ namespace Ink_Canvas.Helpers
public static string GetIcstkFileFromArgs(string[] args) public static string GetIcstkFileFromArgs(string[] args)
{ {
if (args == null || args.Length == 0) return null; if (args == null || args.Length == 0) return null;
foreach (string arg in args) foreach (string arg in args)
{ {
if (string.IsNullOrEmpty(arg)) continue; if (string.IsNullOrEmpty(arg)) continue;
// 检查是否为.icstk文件 // 检查是否为.icstk文件
if (Path.GetExtension(arg).Equals(FileExtension, StringComparison.OrdinalIgnoreCase)) if (Path.GetExtension(arg).Equals(FileExtension, StringComparison.OrdinalIgnoreCase))
{ {
@@ -204,7 +204,7 @@ namespace Ink_Canvas.Helpers
} }
} }
} }
return null; return null;
} }
@@ -218,24 +218,24 @@ namespace Ink_Canvas.Helpers
try try
{ {
LogHelper.WriteLogToFile($"尝试通过IPC发送文件路径给已运行实例: {filePath}", LogHelper.LogType.Event); LogHelper.WriteLogToFile($"尝试通过IPC发送文件路径给已运行实例: {filePath}", LogHelper.LogType.Event);
// 创建IPC文件 // 创建IPC文件
string tempDir = Path.GetTempPath(); string tempDir = Path.GetTempPath();
string ipcFileName = IpcFilePrefix + Guid.NewGuid().ToString("N") + ".tmp"; string ipcFileName = IpcFilePrefix + Guid.NewGuid().ToString("N") + ".tmp";
string ipcFilePath = Path.Combine(tempDir, ipcFileName); string ipcFilePath = Path.Combine(tempDir, ipcFileName);
// 写入文件路径到IPC文件 // 写入文件路径到IPC文件
File.WriteAllText(ipcFilePath, filePath, Encoding.UTF8); File.WriteAllText(ipcFilePath, filePath, Encoding.UTF8);
// 创建事件通知已运行实例 // 创建事件通知已运行实例
using (EventWaitHandle ipcEvent = new EventWaitHandle(false, EventResetMode.ManualReset, IpcEventName)) using (EventWaitHandle ipcEvent = new EventWaitHandle(false, EventResetMode.ManualReset, IpcEventName))
{ {
ipcEvent.Set(); ipcEvent.Set();
} }
// 等待一段时间让已运行实例处理文件 // 等待一段时间让已运行实例处理文件
Thread.Sleep(1000); Thread.Sleep(1000);
// 清理IPC文件 // 清理IPC文件
try try
{ {
@@ -248,7 +248,7 @@ namespace Ink_Canvas.Helpers
{ {
LogHelper.WriteLogToFile($"清理IPC文件失败: {ex.Message}", LogHelper.LogType.Warning); LogHelper.WriteLogToFile($"清理IPC文件失败: {ex.Message}", LogHelper.LogType.Warning);
} }
LogHelper.WriteLogToFile("IPC文件路径发送完成", LogHelper.LogType.Event); LogHelper.WriteLogToFile("IPC文件路径发送完成", LogHelper.LogType.Event);
return true; return true;
} }
@@ -271,7 +271,7 @@ namespace Ink_Canvas.Helpers
try try
{ {
LogHelper.WriteLogToFile("启动IPC监听器", LogHelper.LogType.Event); LogHelper.WriteLogToFile("启动IPC监听器", LogHelper.LogType.Event);
using (EventWaitHandle ipcEvent = new EventWaitHandle(false, EventResetMode.ManualReset, IpcEventName)) using (EventWaitHandle ipcEvent = new EventWaitHandle(false, EventResetMode.ManualReset, IpcEventName))
{ {
while (true) while (true)
@@ -281,11 +281,11 @@ namespace Ink_Canvas.Helpers
{ {
// 处理IPC文件 // 处理IPC文件
ProcessIpcFiles(); ProcessIpcFiles();
// 重置事件 // 重置事件
ipcEvent.Reset(); ipcEvent.Reset();
} }
// 检查应用是否还在运行 // 检查应用是否还在运行
if (Application.Current == null || Application.Current.Dispatcher == null) if (Application.Current == null || Application.Current.Dispatcher == null)
{ {
@@ -299,7 +299,7 @@ namespace Ink_Canvas.Helpers
LogHelper.WriteLogToFile($"IPC监听器出错: {ex.Message}", LogHelper.LogType.Error); LogHelper.WriteLogToFile($"IPC监听器出错: {ex.Message}", LogHelper.LogType.Error);
} }
}); });
ipcThread.IsBackground = true; ipcThread.IsBackground = true;
ipcThread.Start(); ipcThread.Start();
} }
@@ -318,18 +318,18 @@ namespace Ink_Canvas.Helpers
{ {
string tempDir = Path.GetTempPath(); string tempDir = Path.GetTempPath();
string[] ipcFiles = Directory.GetFiles(tempDir, IpcFilePrefix + "*.tmp"); string[] ipcFiles = Directory.GetFiles(tempDir, IpcFilePrefix + "*.tmp");
foreach (string ipcFile in ipcFiles) foreach (string ipcFile in ipcFiles)
{ {
try try
{ {
// 读取文件路径 // 读取文件路径
string filePath = File.ReadAllText(ipcFile, Encoding.UTF8); string filePath = File.ReadAllText(ipcFile, Encoding.UTF8);
if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath)) if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath))
{ {
LogHelper.WriteLogToFile($"IPC接收到文件路径: {filePath}", LogHelper.LogType.Event); LogHelper.WriteLogToFile($"IPC接收到文件路径: {filePath}", LogHelper.LogType.Event);
// 在UI线程中处理文件打开 // 在UI线程中处理文件打开
Application.Current.Dispatcher.BeginInvoke(new Action(() => Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{ {
@@ -348,14 +348,14 @@ namespace Ink_Canvas.Helpers
} }
})); }));
} }
// 删除IPC文件 // 删除IPC文件
File.Delete(ipcFile); File.Delete(ipcFile);
} }
catch (Exception ex) catch (Exception ex)
{ {
LogHelper.WriteLogToFile($"处理IPC文件失败: {ex.Message}", LogHelper.LogType.Warning); LogHelper.WriteLogToFile($"处理IPC文件失败: {ex.Message}", LogHelper.LogType.Warning);
// 尝试删除损坏的IPC文件 // 尝试删除损坏的IPC文件
try try
{ {
@@ -377,4 +377,4 @@ namespace Ink_Canvas.Helpers
[DllImport("shell32.dll")] [DllImport("shell32.dll")]
private static extern void SHChangeNotify(uint wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2); private static extern void SHChangeNotify(uint wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2);
} }
} }
+4 -4
View File
@@ -70,17 +70,17 @@ namespace Ink_Canvas.Helpers
try try
{ {
if (PPTApplication == null || !Marshal.IsComObject(PPTApplication)) return false; if (PPTApplication == null || !Marshal.IsComObject(PPTApplication)) return false;
// 检查是否有放映窗口 // 检查是否有放映窗口
var slideShowWindows = PPTApplication.SlideShowWindows; var slideShowWindows = PPTApplication.SlideShowWindows;
if (slideShowWindows == null || slideShowWindows.Count == 0) return false; if (slideShowWindows == null || slideShowWindows.Count == 0) return false;
// 验证放映窗口是否真正有效 // 验证放映窗口是否真正有效
try try
{ {
var slideShowWindow = slideShowWindows[1]; var slideShowWindow = slideShowWindows[1];
if (slideShowWindow == null) return false; if (slideShowWindow == null) return false;
// 尝试访问放映窗口的属性来验证其有效性 // 尝试访问放映窗口的属性来验证其有效性
var _ = slideShowWindow.View; var _ = slideShowWindow.View;
return true; return true;
@@ -479,7 +479,7 @@ namespace Ink_Canvas.Helpers
{ {
CurrentPresentation = activePresentation; CurrentPresentation = activePresentation;
CurrentSlides = CurrentPresentation.Slides; CurrentSlides = CurrentPresentation.Slides;
// 验证页数读取是否成功 // 验证页数读取是否成功
try try
{ {
+1 -1
View File
@@ -181,7 +181,7 @@ namespace Ink_Canvas.Helpers
bool isInSlideShow = _mainWindow.PPTManager?.IsInSlideShow == true; bool isInSlideShow = _mainWindow.PPTManager?.IsInSlideShow == true;
int slidesCount = _mainWindow.PPTManager?.SlidesCount ?? 0; int slidesCount = _mainWindow.PPTManager?.SlidesCount ?? 0;
bool hasValidPageCount = slidesCount > 0; bool hasValidPageCount = slidesCount > 0;
bool shouldShowButtons = ShowPPTButton && bool shouldShowButtons = ShowPPTButton &&
_mainWindow.BtnPPTSlideShowEnd.Visibility == Visibility.Visible && _mainWindow.BtnPPTSlideShowEnd.Visibility == Visibility.Visible &&
isInSlideShow && isInSlideShow &&
@@ -238,4 +238,4 @@ namespace Ink_Canvas.Helpers.Plugins
#endregion #endregion
} }
} }
+1 -1
View File
@@ -293,4 +293,4 @@ namespace Ink_Canvas.Helpers.Plugins
#endregion #endregion
} }
} }
+1 -1
View File
@@ -211,4 +211,4 @@ namespace Ink_Canvas.Helpers.Plugins
#endregion #endregion
} }
} }
+1 -1
View File
@@ -149,4 +149,4 @@ namespace Ink_Canvas.Helpers.Plugins
#endregion #endregion
} }
} }
+1 -1
View File
@@ -156,7 +156,7 @@ namespace Ink_Canvas.Helpers
// 使用更直接的方法:先激活窗口,再置顶 // 使用更直接的方法:先激活窗口,再置顶
window.Activate(); window.Activate();
window.Focus(); window.Focus();
// 设置窗口为置顶 // 设置窗口为置顶
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOOWNERZORDER); SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOOWNERZORDER);
+23 -23
View File
@@ -247,7 +247,7 @@ namespace Ink_Canvas
// 为浮动栏按钮添加触摸事件支持 // 为浮动栏按钮添加触摸事件支持
AddTouchSupportToFloatingBarButtons(); AddTouchSupportToFloatingBarButtons();
// 为滑块控件添加触摸事件支持 // 为滑块控件添加触摸事件支持
AddTouchSupportToSliders(); AddTouchSupportToSliders();
} }
@@ -301,7 +301,7 @@ namespace Ink_Canvas
foreach (var gest in gestures) foreach (var gest in gestures)
//Trace.WriteLine(string.Format("Gesture: {0}, Confidence: {1}", gest.ApplicationGesture, gest.RecognitionConfidence)); //Trace.WriteLine(string.Format("Gesture: {0}, Confidence: {1}", gest.ApplicationGesture, gest.RecognitionConfidence));
// 只有在PPT放映模式下才响应翻页手势 // 只有在PPT放映模式下才响应翻页手势
if (StackPanelPPTControls.Visibility == Visibility.Visible && if (StackPanelPPTControls.Visibility == Visibility.Visible &&
BtnPPTSlideShowEnd.Visibility == Visibility.Visible && BtnPPTSlideShowEnd.Visibility == Visibility.Visible &&
PPTManager?.IsInSlideShow == true) PPTManager?.IsInSlideShow == true)
{ {
@@ -1035,7 +1035,7 @@ namespace Ink_Canvas
// 取消选中元素 // 取消选中元素
UnselectElement(currentSelectedElement); UnselectElement(currentSelectedElement);
currentSelectedElement = null; currentSelectedElement = null;
// 重置为选择模式,确保用户可以继续选择其他元素 // 重置为选择模式,确保用户可以继续选择其他元素
SetCurrentToolMode(InkCanvasEditingMode.Select); SetCurrentToolMode(InkCanvasEditingMode.Select);
// 更新模式缓存 // 更新模式缓存
@@ -2033,14 +2033,14 @@ namespace Ink_Canvas
MessageBox.Show("快捷键管理器尚未初始化,请稍后重试。", "错误", MessageBoxButton.OK, MessageBoxImage.Error); MessageBox.Show("快捷键管理器尚未初始化,请稍后重试。", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
return; return;
} }
// 暂时隐藏设置面板 // 暂时隐藏设置面板
BorderSettings.Visibility = Visibility.Hidden; BorderSettings.Visibility = Visibility.Hidden;
BorderSettingsMask.Visibility = Visibility.Hidden; BorderSettingsMask.Visibility = Visibility.Hidden;
// 创建快捷键设置窗口 // 创建快捷键设置窗口
var hotkeySettingsWindow = new HotkeySettingsWindow(this, _globalHotkeyManager); var hotkeySettingsWindow = new HotkeySettingsWindow(this, _globalHotkeyManager);
// 设置窗口关闭事件,用于在快捷键设置窗口关闭后恢复设置面板 // 设置窗口关闭事件,用于在快捷键设置窗口关闭后恢复设置面板
hotkeySettingsWindow.Closed += (s, e) => hotkeySettingsWindow.Closed += (s, e) =>
{ {
@@ -2048,7 +2048,7 @@ namespace Ink_Canvas
BorderSettings.Visibility = Visibility.Visible; BorderSettings.Visibility = Visibility.Visible;
BorderSettingsMask.Visibility = Visibility.Visible; BorderSettingsMask.Visibility = Visibility.Visible;
}; };
// 显示快捷键设置窗口 // 显示快捷键设置窗口
hotkeySettingsWindow.ShowDialog(); hotkeySettingsWindow.ShowDialog();
} }
@@ -2057,7 +2057,7 @@ namespace Ink_Canvas
// 确保在发生错误时也恢复设置面板显示 // 确保在发生错误时也恢复设置面板显示
BorderSettings.Visibility = Visibility.Visible; BorderSettings.Visibility = Visibility.Visible;
BorderSettingsMask.Visibility = Visibility.Visible; BorderSettingsMask.Visibility = Visibility.Visible;
LogHelper.WriteLogToFile($"打开快捷键设置窗口时出错: {ex.Message}", LogHelper.LogType.Error); LogHelper.WriteLogToFile($"打开快捷键设置窗口时出错: {ex.Message}", LogHelper.LogType.Error);
MessageBox.Show($"打开快捷键设置窗口时出错: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error); MessageBox.Show($"打开快捷键设置窗口时出错: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
} }
@@ -2158,13 +2158,13 @@ namespace Ink_Canvas
var toggle = sender as ToggleSwitch; var toggle = sender as ToggleSwitch;
Settings.PowerPointSettings.ShowGestureButtonInSlideShow = toggle != null && toggle.IsOn; Settings.PowerPointSettings.ShowGestureButtonInSlideShow = toggle != null && toggle.IsOn;
SaveSettingsToFile(); SaveSettingsToFile();
// 如果当前在PPT放映模式,需要立即更新手势按钮的显示状态 // 如果当前在PPT放映模式,需要立即更新手势按钮的显示状态
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible)
{ {
UpdateGestureButtonVisibilityInPPTMode(); UpdateGestureButtonVisibilityInPPTMode();
} }
LogHelper.WriteLogToFile($"PPT放映模式显示手势按钮已{(Settings.PowerPointSettings.ShowGestureButtonInSlideShow ? "" : "")}", LogHelper.LogType.Event); LogHelper.WriteLogToFile($"PPT放映模式显示手势按钮已{(Settings.PowerPointSettings.ShowGestureButtonInSlideShow ? "" : "")}", LogHelper.LogType.Event);
} }
catch (Exception ex) catch (Exception ex)
@@ -2276,11 +2276,11 @@ namespace Ink_Canvas
{ {
// 检查启动参数中是否有.icstk文件 // 检查启动参数中是否有.icstk文件
string icstkFile = FileAssociationManager.GetIcstkFileFromArgs(App.StartArgs); string icstkFile = FileAssociationManager.GetIcstkFileFromArgs(App.StartArgs);
if (!string.IsNullOrEmpty(icstkFile)) if (!string.IsNullOrEmpty(icstkFile))
{ {
LogHelper.WriteLogToFile($"检测到命令行参数中的.icstk文件: {icstkFile}", LogHelper.LogType.Event); LogHelper.WriteLogToFile($"检测到命令行参数中的.icstk文件: {icstkFile}", LogHelper.LogType.Event);
// 延迟执行,确保UI已完全加载 // 延迟执行,确保UI已完全加载
Dispatcher.BeginInvoke(new Action(() => Dispatcher.BeginInvoke(new Action(() =>
{ {
@@ -2433,10 +2433,10 @@ namespace Ink_Canvas
// 计算触摸位置对应的滑块值 // 计算触摸位置对应的滑块值
var touchPoint = e.GetTouchPoint(slider); var touchPoint = e.GetTouchPoint(slider);
// 使用更精确的位置计算方法 // 使用更精确的位置计算方法
UpdateSliderValueFromPositionImproved(slider, touchPoint.Position); UpdateSliderValueFromPositionImproved(slider, touchPoint.Position);
e.Handled = true; e.Handled = true;
} }
@@ -2449,7 +2449,7 @@ namespace Ink_Canvas
// 释放触摸捕获 // 释放触摸捕获
slider.ReleaseTouchCapture(e.TouchDevice); slider.ReleaseTouchCapture(e.TouchDevice);
e.Handled = true; e.Handled = true;
} }
@@ -2472,7 +2472,7 @@ namespace Ink_Canvas
{ {
UpdateSliderValueFromPositionImproved(slider, stylusPoint[0].ToPoint()); UpdateSliderValueFromPositionImproved(slider, stylusPoint[0].ToPoint());
} }
e.Handled = true; e.Handled = true;
} }
@@ -2485,7 +2485,7 @@ namespace Ink_Canvas
// 释放手写笔捕获 // 释放手写笔捕获
slider.ReleaseStylusCapture(); slider.ReleaseStylusCapture();
e.Handled = true; e.Handled = true;
} }
@@ -2511,9 +2511,9 @@ namespace Ink_Canvas
// 获取轨道的实际边界 // 获取轨道的实际边界
var trackBounds = track.TransformToAncestor(slider).TransformBounds(new Rect(0, 0, track.ActualWidth, track.ActualHeight)); var trackBounds = track.TransformToAncestor(slider).TransformBounds(new Rect(0, 0, track.ActualWidth, track.ActualHeight));
double relativePosition = 0; double relativePosition = 0;
if (slider.Orientation == System.Windows.Controls.Orientation.Horizontal) if (slider.Orientation == System.Windows.Controls.Orientation.Horizontal)
{ {
// 水平滑块 // 水平滑块
@@ -2537,7 +2537,7 @@ namespace Ink_Canvas
// 计算新的滑块值 // 计算新的滑块值
var newValue = slider.Minimum + relativePosition * (slider.Maximum - slider.Minimum); var newValue = slider.Minimum + relativePosition * (slider.Maximum - slider.Minimum);
// 如果启用了吸附到刻度,则调整到最近的刻度 // 如果启用了吸附到刻度,则调整到最近的刻度
if (slider.IsSnapToTickEnabled && slider.TickFrequency > 0) if (slider.IsSnapToTickEnabled && slider.TickFrequency > 0)
{ {
@@ -2570,7 +2570,7 @@ namespace Ink_Canvas
{ {
// 使用更简单直接的方法计算滑块值 // 使用更简单直接的方法计算滑块值
double relativePosition = 0; double relativePosition = 0;
if (slider.Orientation == System.Windows.Controls.Orientation.Horizontal) if (slider.Orientation == System.Windows.Controls.Orientation.Horizontal)
{ {
// 水平滑块 - 使用滑块的实际宽度 // 水平滑块 - 使用滑块的实际宽度
@@ -2600,7 +2600,7 @@ namespace Ink_Canvas
// 计算新的滑块值 // 计算新的滑块值
var newValue = slider.Minimum + relativePosition * (slider.Maximum - slider.Minimum); var newValue = slider.Minimum + relativePosition * (slider.Maximum - slider.Minimum);
// 如果启用了吸附到刻度,则调整到最近的刻度 // 如果启用了吸附到刻度,则调整到最近的刻度
if (slider.IsSnapToTickEnabled && slider.TickFrequency > 0) if (slider.IsSnapToTickEnabled && slider.TickFrequency > 0)
{ {
@@ -2633,7 +2633,7 @@ namespace Ink_Canvas
if (toggle != null) if (toggle != null)
{ {
Settings.ModeSettings.IsPPTOnlyMode = toggle.IsOn; Settings.ModeSettings.IsPPTOnlyMode = toggle.IsOn;
// 如果切换到仅PPT模式,立即隐藏主窗口 // 如果切换到仅PPT模式,立即隐藏主窗口
if (Settings.ModeSettings.IsPPTOnlyMode) if (Settings.ModeSettings.IsPPTOnlyMode)
{ {
+6 -6
View File
@@ -260,7 +260,7 @@ namespace Ink_Canvas
} }
// 只有在PPT放映模式下且页数有效时才显示翻页按钮 // 只有在PPT放映模式下且页数有效时才显示翻页按钮
if (StackPanelPPTControls.Visibility == Visibility.Visible && if (StackPanelPPTControls.Visibility == Visibility.Visible &&
BtnPPTSlideShowEnd.Visibility == Visibility.Visible && BtnPPTSlideShowEnd.Visibility == Visibility.Visible &&
PPTManager?.IsInSlideShow == true && PPTManager?.IsInSlideShow == true &&
PPTManager?.SlidesCount > 0) PPTManager?.SlidesCount > 0)
@@ -288,17 +288,17 @@ namespace Ink_Canvas
{ {
// 强制更新布局以确保ActualWidth正确 // 强制更新布局以确保ActualWidth正确
ViewboxFloatingBar.UpdateLayout(); ViewboxFloatingBar.UpdateLayout();
// 等待一小段时间让布局完全更新 // 等待一小段时间让布局完全更新
Task.Delay(50); Task.Delay(50);
// 再次强制更新布局 // 再次强制更新布局
ViewboxFloatingBar.UpdateLayout(); ViewboxFloatingBar.UpdateLayout();
// 强制重新测量和排列 // 强制重新测量和排列
ViewboxFloatingBar.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); ViewboxFloatingBar.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
ViewboxFloatingBar.Arrange(new Rect(ViewboxFloatingBar.DesiredSize)); ViewboxFloatingBar.Arrange(new Rect(ViewboxFloatingBar.DesiredSize));
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible) if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible)
ViewboxFloatingBarMarginAnimation(60); ViewboxFloatingBarMarginAnimation(60);
else else
@@ -314,7 +314,7 @@ namespace Ink_Canvas
{ {
// 等待UI完全更新 // 等待UI完全更新
await Task.Delay(100); await Task.Delay(100);
// 获取当前选中的模式并重新设置高光位置 // 获取当前选中的模式并重新设置高光位置
string selectedToolMode = GetCurrentSelectedMode(); string selectedToolMode = GetCurrentSelectedMode();
if (!string.IsNullOrEmpty(selectedToolMode)) if (!string.IsNullOrEmpty(selectedToolMode))
+2 -2
View File
@@ -750,7 +750,7 @@ namespace Ink_Canvas
{ {
overlay.CaptureMouse(); overlay.CaptureMouse();
StartAdvancedEraserOperation(sender); StartAdvancedEraserOperation(sender);
// 处理单点擦除 // 处理单点擦除
var position = e.GetPosition((UIElement)FindName("inkCanvas")); var position = e.GetPosition((UIElement)FindName("inkCanvas"));
UpdateAdvancedEraserPosition(sender, position); UpdateAdvancedEraserPosition(sender, position);
@@ -791,7 +791,7 @@ namespace Ink_Canvas
overlay.CaptureStylus(); overlay.CaptureStylus();
} }
StartAdvancedEraserOperation(sender); StartAdvancedEraserOperation(sender);
// 处理单点擦除 // 处理单点擦除
var position = e.GetPosition((UIElement)FindName("inkCanvas")); var position = e.GetPosition((UIElement)FindName("inkCanvas"));
UpdateAdvancedEraserPosition(sender, position); UpdateAdvancedEraserPosition(sender, position);
+32 -32
View File
@@ -674,7 +674,7 @@ namespace Ink_Canvas
HideSubPanelsImmediately(); HideSubPanelsImmediately();
// 只有在PPT放映模式下且页数有效时才显示翻页按钮 // 只有在PPT放映模式下且页数有效时才显示翻页按钮
if (StackPanelPPTControls.Visibility == Visibility.Visible && if (StackPanelPPTControls.Visibility == Visibility.Visible &&
BtnPPTSlideShowEnd.Visibility == Visibility.Visible && BtnPPTSlideShowEnd.Visibility == Visibility.Visible &&
PPTManager?.IsInSlideShow == true && PPTManager?.IsInSlideShow == true &&
PPTManager?.SlidesCount > 0) PPTManager?.SlidesCount > 0)
@@ -696,7 +696,7 @@ namespace Ink_Canvas
RightSidePanelForPPTNavigation.Visibility = Visibility.Collapsed; RightSidePanelForPPTNavigation.Visibility = Visibility.Collapsed;
LogHelper.WriteLogToFile($"隐藏PPT翻页按钮 - 放映状态: {PPTManager?.IsInSlideShow}, 页数: {PPTManager?.SlidesCount}", LogHelper.LogType.Trace); LogHelper.WriteLogToFile($"隐藏PPT翻页按钮 - 放映状态: {PPTManager?.IsInSlideShow}, 页数: {PPTManager?.SlidesCount}", LogHelper.LogType.Trace);
} }
// 使用PPT UI管理器来正确更新翻页按钮显示状态,确保遵循用户设置 // 使用PPT UI管理器来正确更新翻页按钮显示状态,确保遵循用户设置
if (_pptUIManager != null) if (_pptUIManager != null)
{ {
@@ -833,10 +833,10 @@ namespace Ink_Canvas
if (sender == SymbolIconSelect && lastBorderMouseDownObject != SymbolIconSelect) return; if (sender == SymbolIconSelect && lastBorderMouseDownObject != SymbolIconSelect) return;
BtnSelect_Click(null, null); BtnSelect_Click(null, null);
// 更新模式缓存 // 更新模式缓存
UpdateCurrentToolMode("select"); UpdateCurrentToolMode("select");
HideSubPanels("select"); HideSubPanels("select");
} }
@@ -973,7 +973,7 @@ namespace Ink_Canvas
var randWindow = new RandWindow(Settings); var randWindow = new RandWindow(Settings);
randWindow.Show(); randWindow.Show();
// 使用延迟确保窗口完全显示后再强制置顶 // 使用延迟确保窗口完全显示后再强制置顶
randWindow.Dispatcher.BeginInvoke(new Action(() => randWindow.Dispatcher.BeginInvoke(new Action(() =>
{ {
@@ -982,10 +982,10 @@ namespace Ink_Canvas
// 强制激活窗口 // 强制激活窗口
randWindow.Activate(); randWindow.Activate();
randWindow.Focus(); randWindow.Focus();
// 设置置顶 // 设置置顶
randWindow.Topmost = true; randWindow.Topmost = true;
// 使用Win32 API强制置顶 // 使用Win32 API强制置顶
var hwnd = new WindowInteropHelper(randWindow).Handle; var hwnd = new WindowInteropHelper(randWindow).Handle;
if (hwnd != IntPtr.Zero) if (hwnd != IntPtr.Zero)
@@ -1410,19 +1410,19 @@ namespace Ink_Canvas
// 计算浮动栏位置,考虑快捷调色盘的显示状态 // 计算浮动栏位置,考虑快捷调色盘的显示状态
// 使用更可靠的方法获取浮动栏宽度 // 使用更可靠的方法获取浮动栏宽度
double baseWidth = ViewboxFloatingBar.ActualWidth; double baseWidth = ViewboxFloatingBar.ActualWidth;
// 如果ActualWidth为0,尝试使用DesiredSize // 如果ActualWidth为0,尝试使用DesiredSize
if (baseWidth <= 0) if (baseWidth <= 0)
{ {
baseWidth = ViewboxFloatingBar.DesiredSize.Width; baseWidth = ViewboxFloatingBar.DesiredSize.Width;
} }
// 如果仍然为0,使用RenderSize // 如果仍然为0,使用RenderSize
if (baseWidth <= 0) if (baseWidth <= 0)
{ {
baseWidth = ViewboxFloatingBar.RenderSize.Width; baseWidth = ViewboxFloatingBar.RenderSize.Width;
} }
// 如果所有方法都失败,使用一个基于内容的估算值 // 如果所有方法都失败,使用一个基于内容的估算值
if (baseWidth <= 0) if (baseWidth <= 0)
{ {
@@ -1430,9 +1430,9 @@ namespace Ink_Canvas
baseWidth = 200; // 最小宽度 baseWidth = 200; // 最小宽度
LogHelper.WriteLogToFile($"浮动栏宽度无法获取,使用估算值: {baseWidth}"); LogHelper.WriteLogToFile($"浮动栏宽度无法获取,使用估算值: {baseWidth}");
} }
double floatingBarWidth = baseWidth * ViewboxFloatingBarScaleTransform.ScaleX; double floatingBarWidth = baseWidth * ViewboxFloatingBarScaleTransform.ScaleX;
// 如果快捷调色盘显示,确保有足够空间 // 如果快捷调色盘显示,确保有足够空间
if ((QuickColorPalettePanel != null && QuickColorPalettePanel.Visibility == Visibility.Visible) || if ((QuickColorPalettePanel != null && QuickColorPalettePanel.Visibility == Visibility.Visible) ||
@@ -1555,19 +1555,19 @@ namespace Ink_Canvas
// 计算浮动栏位置,考虑快捷调色盘的显示状态 // 计算浮动栏位置,考虑快捷调色盘的显示状态
// 使用更可靠的方法获取浮动栏宽度 // 使用更可靠的方法获取浮动栏宽度
double baseWidth = ViewboxFloatingBar.ActualWidth; double baseWidth = ViewboxFloatingBar.ActualWidth;
// 如果ActualWidth为0,尝试使用DesiredSize // 如果ActualWidth为0,尝试使用DesiredSize
if (baseWidth <= 0) if (baseWidth <= 0)
{ {
baseWidth = ViewboxFloatingBar.DesiredSize.Width; baseWidth = ViewboxFloatingBar.DesiredSize.Width;
} }
// 如果仍然为0,使用RenderSize // 如果仍然为0,使用RenderSize
if (baseWidth <= 0) if (baseWidth <= 0)
{ {
baseWidth = ViewboxFloatingBar.RenderSize.Width; baseWidth = ViewboxFloatingBar.RenderSize.Width;
} }
// 如果所有方法都失败,使用一个基于内容的估算值 // 如果所有方法都失败,使用一个基于内容的估算值
if (baseWidth <= 0) if (baseWidth <= 0)
{ {
@@ -1575,9 +1575,9 @@ namespace Ink_Canvas
baseWidth = 200; // 最小宽度 baseWidth = 200; // 最小宽度
LogHelper.WriteLogToFile($"浮动栏宽度无法获取,使用估算值: {baseWidth}"); LogHelper.WriteLogToFile($"浮动栏宽度无法获取,使用估算值: {baseWidth}");
} }
double floatingBarWidth = baseWidth * ViewboxFloatingBarScaleTransform.ScaleX; double floatingBarWidth = baseWidth * ViewboxFloatingBarScaleTransform.ScaleX;
// 如果快捷调色盘显示,确保有足够空间 // 如果快捷调色盘显示,确保有足够空间
if ((QuickColorPalettePanel != null && QuickColorPalettePanel.Visibility == Visibility.Visible) || if ((QuickColorPalettePanel != null && QuickColorPalettePanel.Visibility == Visibility.Visible) ||
@@ -1661,19 +1661,19 @@ namespace Ink_Canvas
// 计算浮动栏位置,考虑快捷调色盘的显示状态 // 计算浮动栏位置,考虑快捷调色盘的显示状态
// 使用更可靠的方法获取浮动栏宽度 // 使用更可靠的方法获取浮动栏宽度
double baseWidth = ViewboxFloatingBar.ActualWidth; double baseWidth = ViewboxFloatingBar.ActualWidth;
// 如果ActualWidth为0,尝试使用DesiredSize // 如果ActualWidth为0,尝试使用DesiredSize
if (baseWidth <= 0) if (baseWidth <= 0)
{ {
baseWidth = ViewboxFloatingBar.DesiredSize.Width; baseWidth = ViewboxFloatingBar.DesiredSize.Width;
} }
// 如果仍然为0,使用RenderSize // 如果仍然为0,使用RenderSize
if (baseWidth <= 0) if (baseWidth <= 0)
{ {
baseWidth = ViewboxFloatingBar.RenderSize.Width; baseWidth = ViewboxFloatingBar.RenderSize.Width;
} }
// 如果所有方法都失败,使用一个基于内容的估算值 // 如果所有方法都失败,使用一个基于内容的估算值
if (baseWidth <= 0) if (baseWidth <= 0)
{ {
@@ -1681,9 +1681,9 @@ namespace Ink_Canvas
baseWidth = 200; // 最小宽度 baseWidth = 200; // 最小宽度
LogHelper.WriteLogToFile($"浮动栏宽度无法获取,使用估算值: {baseWidth}"); LogHelper.WriteLogToFile($"浮动栏宽度无法获取,使用估算值: {baseWidth}");
} }
double floatingBarWidth = baseWidth * ViewboxFloatingBarScaleTransform.ScaleX; double floatingBarWidth = baseWidth * ViewboxFloatingBarScaleTransform.ScaleX;
// 如果快捷调色盘显示,确保有足够空间 // 如果快捷调色盘显示,确保有足够空间
if ((QuickColorPalettePanel != null && QuickColorPalettePanel.Visibility == Visibility.Visible) || if ((QuickColorPalettePanel != null && QuickColorPalettePanel.Visibility == Visibility.Visible) ||
@@ -1741,7 +1741,7 @@ namespace Ink_Canvas
// 使用集中化的工具模式切换方法,确保快捷键状态正确更新 // 使用集中化的工具模式切换方法,确保快捷键状态正确更新
// 鼠标模式下应该禁用快捷键以放行键盘操作 // 鼠标模式下应该禁用快捷键以放行键盘操作
SetCurrentToolMode(InkCanvasEditingMode.None); SetCurrentToolMode(InkCanvasEditingMode.None);
// 更新模式缓存,确保后续的模式检测正确 // 更新模式缓存,确保后续的模式检测正确
UpdateCurrentToolMode("cursor"); UpdateCurrentToolMode("cursor");
@@ -1880,7 +1880,7 @@ namespace Ink_Canvas
{ {
// 使用集中化的工具模式切换方法 // 使用集中化的工具模式切换方法
SetCurrentToolMode(InkCanvasEditingMode.Ink); SetCurrentToolMode(InkCanvasEditingMode.Ink);
// 更新模式缓存 // 更新模式缓存
UpdateCurrentToolMode("pen"); UpdateCurrentToolMode("pen");
@@ -1917,7 +1917,7 @@ namespace Ink_Canvas
CheckEnableTwoFingerGestureBtnVisibility(true); CheckEnableTwoFingerGestureBtnVisibility(true);
// 使用集中化的工具模式切换方法 // 使用集中化的工具模式切换方法
SetCurrentToolMode(InkCanvasEditingMode.Ink); SetCurrentToolMode(InkCanvasEditingMode.Ink);
// 更新模式缓存 // 更新模式缓存
UpdateCurrentToolMode("pen"); UpdateCurrentToolMode("pen");
@@ -2042,7 +2042,7 @@ namespace Ink_Canvas
} }
// 使用集中化的工具模式切换方法 // 使用集中化的工具模式切换方法
SetCurrentToolMode(InkCanvasEditingMode.Ink); SetCurrentToolMode(InkCanvasEditingMode.Ink);
// 更新模式缓存 // 更新模式缓存
UpdateCurrentToolMode("pen"); UpdateCurrentToolMode("pen");
@@ -2106,10 +2106,10 @@ namespace Ink_Canvas
// 使用新的高级橡皮擦系统 // 使用新的高级橡皮擦系统
// 使用集中化的工具模式切换方法 // 使用集中化的工具模式切换方法
SetCurrentToolMode(InkCanvasEditingMode.EraseByPoint); SetCurrentToolMode(InkCanvasEditingMode.EraseByPoint);
// 更新模式缓存 // 更新模式缓存
UpdateCurrentToolMode("eraser"); UpdateCurrentToolMode("eraser");
ApplyAdvancedEraserShape(); // 使用新的橡皮擦形状应用方法 ApplyAdvancedEraserShape(); // 使用新的橡皮擦形状应用方法
SetCursorBasedOnEditingMode(inkCanvas); SetCursorBasedOnEditingMode(inkCanvas);
HideSubPanels("eraser"); // 高亮橡皮按钮 HideSubPanels("eraser"); // 高亮橡皮按钮
@@ -2150,10 +2150,10 @@ namespace Ink_Canvas
// 使用新的高级橡皮擦系统 // 使用新的高级橡皮擦系统
// 使用集中化的工具模式切换方法 // 使用集中化的工具模式切换方法
SetCurrentToolMode(InkCanvasEditingMode.EraseByPoint); SetCurrentToolMode(InkCanvasEditingMode.EraseByPoint);
// 更新模式缓存 // 更新模式缓存
UpdateCurrentToolMode("eraser"); UpdateCurrentToolMode("eraser");
ApplyAdvancedEraserShape(); // 使用新的橡皮擦形状应用方法 ApplyAdvancedEraserShape(); // 使用新的橡皮擦形状应用方法
SetCursorBasedOnEditingMode(inkCanvas); SetCursorBasedOnEditingMode(inkCanvas);
HideSubPanels("eraser"); // 高亮橡皮按钮 HideSubPanels("eraser"); // 高亮橡皮按钮
@@ -2192,10 +2192,10 @@ namespace Ink_Canvas
inkCanvas.EraserShape = new EllipseStylusShape(5, 5); inkCanvas.EraserShape = new EllipseStylusShape(5, 5);
// 使用集中化的工具模式切换方法 // 使用集中化的工具模式切换方法
SetCurrentToolMode(InkCanvasEditingMode.EraseByStroke); SetCurrentToolMode(InkCanvasEditingMode.EraseByStroke);
// 更新模式缓存 // 更新模式缓存
UpdateCurrentToolMode("eraserByStrokes"); UpdateCurrentToolMode("eraserByStrokes");
drawingShapeMode = 0; drawingShapeMode = 0;
// 修复:切换到线擦时,保存当前的笔类型状态,而不是强制重置 // 修复:切换到线擦时,保存当前的笔类型状态,而不是强制重置
+4 -4
View File
@@ -8,8 +8,8 @@ namespace Ink_Canvas
private void Window_MouseWheel(object sender, MouseWheelEventArgs e) private void Window_MouseWheel(object sender, MouseWheelEventArgs e)
{ {
// 只有在PPT放映模式下才响应鼠标滚轮翻页 // 只有在PPT放映模式下才响应鼠标滚轮翻页
if (StackPanelPPTControls.Visibility != Visibility.Visible || if (StackPanelPPTControls.Visibility != Visibility.Visible ||
currentMode != 0 || currentMode != 0 ||
BtnPPTSlideShowEnd.Visibility != Visibility.Visible || BtnPPTSlideShowEnd.Visibility != Visibility.Visible ||
PPTManager?.IsInSlideShow != true) return; PPTManager?.IsInSlideShow != true) return;
@@ -29,8 +29,8 @@ namespace Ink_Canvas
private void Main_Grid_PreviewKeyDown(object sender, KeyEventArgs e) private void Main_Grid_PreviewKeyDown(object sender, KeyEventArgs e)
{ {
// 只有在PPT放映模式下才响应键盘翻页快捷键 // 只有在PPT放映模式下才响应键盘翻页快捷键
if (StackPanelPPTControls.Visibility != Visibility.Visible || if (StackPanelPPTControls.Visibility != Visibility.Visible ||
currentMode != 0 || currentMode != 0 ||
BtnPPTSlideShowEnd.Visibility != Visibility.Visible || BtnPPTSlideShowEnd.Visibility != Visibility.Visible ||
PPTManager?.IsInSlideShow != true) return; PPTManager?.IsInSlideShow != true) return;
+16 -16
View File
@@ -229,10 +229,10 @@ namespace Ink_Canvas
// 创建新的PowerPoint应用程序实例 // 创建新的PowerPoint应用程序实例
pptApplication = new Microsoft.Office.Interop.PowerPoint.Application(); pptApplication = new Microsoft.Office.Interop.PowerPoint.Application();
// 设置为不可见,作为后台进程 // 设置为不可见,作为后台进程
pptApplication.Visible = MsoTriState.msoFalse; pptApplication.Visible = MsoTriState.msoFalse;
// 设置应用程序属性 // 设置应用程序属性
pptApplication.WindowState = PpWindowState.ppWindowMinimized; pptApplication.WindowState = PpWindowState.ppWindowMinimized;
@@ -277,9 +277,9 @@ namespace Ink_Canvas
// 使用反射调用PPTManager的ConnectToPPT方法 // 使用反射调用PPTManager的ConnectToPPT方法
var pptManagerType = _pptManager.GetType(); var pptManagerType = _pptManager.GetType();
var connectMethod = pptManagerType.GetMethod("ConnectToPPT", var connectMethod = pptManagerType.GetMethod("ConnectToPPT",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (connectMethod != null) if (connectMethod != null)
{ {
connectMethod.Invoke(_pptManager, new object[] { app }); connectMethod.Invoke(_pptManager, new object[] { app });
@@ -288,9 +288,9 @@ namespace Ink_Canvas
else else
{ {
// 如果无法通过反射调用,尝试直接设置属性 // 如果无法通过反射调用,尝试直接设置属性
var pptApplicationProperty = pptManagerType.GetProperty("PPTApplication", var pptApplicationProperty = pptManagerType.GetProperty("PPTApplication",
System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
if (pptApplicationProperty != null && pptApplicationProperty.CanWrite) if (pptApplicationProperty != null && pptApplicationProperty.CanWrite)
{ {
pptApplicationProperty.SetValue(_pptManager, app); pptApplicationProperty.SetValue(_pptManager, app);
@@ -317,7 +317,7 @@ namespace Ink_Canvas
{ {
if (pptApplication == null) return false; if (pptApplication == null) return false;
if (!Marshal.IsComObject(pptApplication)) return false; if (!Marshal.IsComObject(pptApplication)) return false;
// 尝试访问一个简单的属性来验证连接是否有效 // 尝试访问一个简单的属性来验证连接是否有效
var _ = pptApplication.Name; var _ = pptApplication.Name;
return true; return true;
@@ -362,12 +362,12 @@ namespace Ink_Canvas
// 退出PowerPoint应用程序 // 退出PowerPoint应用程序
pptApplication.Quit(); pptApplication.Quit();
// 释放COM对象 // 释放COM对象
Marshal.ReleaseComObject(pptApplication); Marshal.ReleaseComObject(pptApplication);
pptApplication = null; pptApplication = null;
} }
LogHelper.WriteLogToFile("PowerPoint应用程序已关闭", LogHelper.LogType.Event); LogHelper.WriteLogToFile("PowerPoint应用程序已关闭", LogHelper.LogType.Event);
} }
catch (Exception ex) catch (Exception ex)
@@ -650,7 +650,7 @@ namespace Ink_Canvas
// 在PPT模式下根据设置决定是否隐藏手势面板和手势按钮 // 在PPT模式下根据设置决定是否隐藏手势面板和手势按钮
AnimationsHelper.HideWithSlideAndFade(TwoFingerGestureBorder); AnimationsHelper.HideWithSlideAndFade(TwoFingerGestureBorder);
AnimationsHelper.HideWithSlideAndFade(BoardTwoFingerGestureBorder); AnimationsHelper.HideWithSlideAndFade(BoardTwoFingerGestureBorder);
// 根据设置决定是否在PPT放映模式下显示手势按钮 // 根据设置决定是否在PPT放映模式下显示手势按钮
if (Settings.PowerPointSettings.ShowGestureButtonInSlideShow) if (Settings.PowerPointSettings.ShowGestureButtonInSlideShow)
{ {
@@ -1066,24 +1066,24 @@ namespace Ink_Canvas
private void ToggleSwitchPowerPointEnhancement_Toggled(object sender, RoutedEventArgs e) private void ToggleSwitchPowerPointEnhancement_Toggled(object sender, RoutedEventArgs e)
{ {
if (!isLoaded) return; if (!isLoaded) return;
Settings.PowerPointSettings.EnablePowerPointEnhancement = ToggleSwitchPowerPointEnhancement.IsOn; Settings.PowerPointSettings.EnablePowerPointEnhancement = ToggleSwitchPowerPointEnhancement.IsOn;
// 与WPS支持互斥 // 与WPS支持互斥
if (Settings.PowerPointSettings.EnablePowerPointEnhancement) if (Settings.PowerPointSettings.EnablePowerPointEnhancement)
{ {
Settings.PowerPointSettings.IsSupportWPS = false; Settings.PowerPointSettings.IsSupportWPS = false;
ToggleSwitchSupportWPS.IsOn = false; ToggleSwitchSupportWPS.IsOn = false;
// 更新PPT管理器的WPS支持设置 // 更新PPT管理器的WPS支持设置
if (_pptManager != null) if (_pptManager != null)
{ {
_pptManager.IsSupportWPS = false; _pptManager.IsSupportWPS = false;
} }
} }
SaveSettingsToFile(); SaveSettingsToFile();
// 启动或停止PowerPoint进程守护 // 启动或停止PowerPoint进程守护
if (Settings.PowerPointSettings.EnablePowerPointEnhancement) if (Settings.PowerPointSettings.EnablePowerPointEnhancement)
{ {
@@ -1100,7 +1100,7 @@ namespace Ink_Canvas
if (!isLoaded) return; if (!isLoaded) return;
Settings.PowerPointSettings.IsSupportWPS = ToggleSwitchSupportWPS.IsOn; Settings.PowerPointSettings.IsSupportWPS = ToggleSwitchSupportWPS.IsOn;
// 与PowerPoint联动增强互斥 // 与PowerPoint联动增强互斥
if (Settings.PowerPointSettings.IsSupportWPS) if (Settings.PowerPointSettings.IsSupportWPS)
{ {
@@ -1,3 +1,4 @@
using Ink_Canvas.Helpers;
using iNKORE.UI.WPF.Modern.Controls; using iNKORE.UI.WPF.Modern.Controls;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -8,7 +9,6 @@ using System.Windows.Ink;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Shapes; using System.Windows.Shapes;
using Ink_Canvas.Helpers;
using Point = System.Windows.Point; using Point = System.Windows.Point;
namespace Ink_Canvas namespace Ink_Canvas
@@ -259,7 +259,7 @@ namespace Ink_Canvas
private bool isStrokeDragging = false; private bool isStrokeDragging = false;
private Point strokeDragStartPoint; private Point strokeDragStartPoint;
private StrokeCollection StrokesSelectionClone = new StrokeCollection(); private StrokeCollection StrokesSelectionClone = new StrokeCollection();
// 选择框和选择点相关变量 // 选择框和选择点相关变量
private bool isResizing = false; private bool isResizing = false;
private string currentResizeHandle = ""; private string currentResizeHandle = "";
@@ -269,18 +269,18 @@ namespace Ink_Canvas
private void GridInkCanvasSelectionCover_MouseDown(object sender, MouseButtonEventArgs e) private void GridInkCanvasSelectionCover_MouseDown(object sender, MouseButtonEventArgs e)
{ {
isGridInkCanvasSelectionCoverMouseDown = true; isGridInkCanvasSelectionCoverMouseDown = true;
// 检查是否有选中的墨迹 // 检查是否有选中的墨迹
if (inkCanvas.GetSelectedStrokes().Count > 0) if (inkCanvas.GetSelectedStrokes().Count > 0)
{ {
// 获取鼠标点击位置 // 获取鼠标点击位置
var clickPoint = e.GetPosition(inkCanvas); var clickPoint = e.GetPosition(inkCanvas);
var selectionBounds = inkCanvas.GetSelectionBounds(); var selectionBounds = inkCanvas.GetSelectionBounds();
// 检查点击位置是否在选择框边界内 // 检查点击位置是否在选择框边界内
if (clickPoint.X >= selectionBounds.Left && if (clickPoint.X >= selectionBounds.Left &&
clickPoint.X <= selectionBounds.Right && clickPoint.X <= selectionBounds.Right &&
clickPoint.Y >= selectionBounds.Top && clickPoint.Y >= selectionBounds.Top &&
clickPoint.Y <= selectionBounds.Bottom) clickPoint.Y <= selectionBounds.Bottom)
{ {
// 只有在选择框边界内才允许拖动 // 只有在选择框边界内才允许拖动
@@ -301,27 +301,27 @@ namespace Ink_Canvas
private void GridInkCanvasSelectionCover_MouseMove(object sender, MouseEventArgs e) private void GridInkCanvasSelectionCover_MouseMove(object sender, MouseEventArgs e)
{ {
if (!isGridInkCanvasSelectionCoverMouseDown) return; if (!isGridInkCanvasSelectionCoverMouseDown) return;
// 如果正在拖动墨迹,执行拖动操作 // 如果正在拖动墨迹,执行拖动操作
if (isStrokeDragging && GridInkCanvasSelectionCover.IsMouseCaptured) if (isStrokeDragging && GridInkCanvasSelectionCover.IsMouseCaptured)
{ {
var currentPoint = e.GetPosition(inkCanvas); var currentPoint = e.GetPosition(inkCanvas);
var delta = currentPoint - strokeDragStartPoint; var delta = currentPoint - strokeDragStartPoint;
// 创建变换矩阵 // 创建变换矩阵
var matrix = new Matrix(); var matrix = new Matrix();
matrix.Translate(delta.X, delta.Y); matrix.Translate(delta.X, delta.Y);
// 对选中的墨迹应用变换 // 对选中的墨迹应用变换
var selectedStrokes = inkCanvas.GetSelectedStrokes(); var selectedStrokes = inkCanvas.GetSelectedStrokes();
foreach (var stroke in selectedStrokes) foreach (var stroke in selectedStrokes)
{ {
stroke.Transform(matrix, false); stroke.Transform(matrix, false);
} }
// 更新选中栏位置 // 更新选中栏位置
updateBorderStrokeSelectionControlLocation(); updateBorderStrokeSelectionControlLocation();
// 更新起始点 // 更新起始点
strokeDragStartPoint = currentPoint; strokeDragStartPoint = currentPoint;
} }
@@ -335,7 +335,7 @@ namespace Ink_Canvas
private void GridInkCanvasSelectionCover_MouseUp(object sender, MouseButtonEventArgs e) private void GridInkCanvasSelectionCover_MouseUp(object sender, MouseButtonEventArgs e)
{ {
if (!isGridInkCanvasSelectionCoverMouseDown) return; if (!isGridInkCanvasSelectionCoverMouseDown) return;
// 结束墨迹拖动 // 结束墨迹拖动
if (isStrokeDragging) if (isStrokeDragging)
{ {
@@ -343,9 +343,9 @@ namespace Ink_Canvas
GridInkCanvasSelectionCover.ReleaseMouseCapture(); GridInkCanvasSelectionCover.ReleaseMouseCapture();
GridInkCanvasSelectionCover.Cursor = Cursors.Arrow; GridInkCanvasSelectionCover.Cursor = Cursors.Arrow;
} }
isGridInkCanvasSelectionCoverMouseDown = false; isGridInkCanvasSelectionCoverMouseDown = false;
// 只有在没有选中墨迹时才隐藏选中栏 // 只有在没有选中墨迹时才隐藏选中栏
if (inkCanvas.GetSelectedStrokes().Count == 0) if (inkCanvas.GetSelectedStrokes().Count == 0)
{ {
@@ -404,7 +404,7 @@ namespace Ink_Canvas
BorderImageSelectionControl.Visibility = Visibility.Collapsed; BorderImageSelectionControl.Visibility = Visibility.Collapsed;
} }
} }
// 显示墨迹选择栏和选择框 // 显示墨迹选择栏和选择框
GridInkCanvasSelectionCover.Visibility = Visibility.Visible; GridInkCanvasSelectionCover.Visibility = Visibility.Visible;
BorderStrokeSelectionClone.Background = Brushes.Transparent; BorderStrokeSelectionClone.Background = Brushes.Transparent;
@@ -524,7 +524,7 @@ namespace Ink_Canvas
strokes = StrokesSelectionClone; strokes = StrokesSelectionClone;
else if (Settings.Gesture.IsEnableTwoFingerRotationOnSelection) else if (Settings.Gesture.IsEnableTwoFingerRotationOnSelection)
m.RotateAt(rotate, center.X, center.Y); // 旋转 m.RotateAt(rotate, center.X, center.Y); // 旋转
// 应用变换到选中的墨迹 // 应用变换到选中的墨迹
foreach (var stroke in strokes) foreach (var stroke in strokes)
{ {
@@ -554,29 +554,29 @@ namespace Ink_Canvas
if (inkCanvas.GetSelectedStrokes().Count > 0 && dec.Count == 1) if (inkCanvas.GetSelectedStrokes().Count > 0 && dec.Count == 1)
{ {
var currentTouchPoint = e.GetTouchPoint(inkCanvas).Position; var currentTouchPoint = e.GetTouchPoint(inkCanvas).Position;
// 检查是否有有效的起始触摸点 // 检查是否有有效的起始触摸点
if (lastTouchPointOnGridInkCanvasCover != new Point(0, 0)) if (lastTouchPointOnGridInkCanvasCover != new Point(0, 0))
{ {
var delta = currentTouchPoint - lastTouchPointOnGridInkCanvasCover; var delta = currentTouchPoint - lastTouchPointOnGridInkCanvasCover;
// 只有当移动距离足够大时才进行拖动(避免微小移动造成的抖动) // 只有当移动距离足够大时才进行拖动(避免微小移动造成的抖动)
if (Math.Abs(delta.X) > 1 || Math.Abs(delta.Y) > 1) if (Math.Abs(delta.X) > 1 || Math.Abs(delta.Y) > 1)
{ {
// 创建变换矩阵 // 创建变换矩阵
var matrix = new Matrix(); var matrix = new Matrix();
matrix.Translate(delta.X, delta.Y); matrix.Translate(delta.X, delta.Y);
// 对选中的墨迹应用变换 // 对选中的墨迹应用变换
var selectedStrokes = inkCanvas.GetSelectedStrokes(); var selectedStrokes = inkCanvas.GetSelectedStrokes();
foreach (var stroke in selectedStrokes) foreach (var stroke in selectedStrokes)
{ {
stroke.Transform(matrix, false); stroke.Transform(matrix, false);
} }
// 更新选中栏位置 // 更新选中栏位置
updateBorderStrokeSelectionControlLocation(); updateBorderStrokeSelectionControlLocation();
// 更新最后触摸点 // 更新最后触摸点
lastTouchPointOnGridInkCanvasCover = currentTouchPoint; lastTouchPointOnGridInkCanvasCover = currentTouchPoint;
} }
@@ -590,29 +590,29 @@ namespace Ink_Canvas
if (inkCanvas.GetSelectedStrokes().Count > 0 && dec.Count == 1) if (inkCanvas.GetSelectedStrokes().Count > 0 && dec.Count == 1)
{ {
var currentTouchPoint = e.GetTouchPoint(inkCanvas).Position; var currentTouchPoint = e.GetTouchPoint(inkCanvas).Position;
// 检查是否有有效的起始触摸点 // 检查是否有有效的起始触摸点
if (lastTouchPointOnGridInkCanvasCover != new Point(0, 0)) if (lastTouchPointOnGridInkCanvasCover != new Point(0, 0))
{ {
var delta = currentTouchPoint - lastTouchPointOnGridInkCanvasCover; var delta = currentTouchPoint - lastTouchPointOnGridInkCanvasCover;
// 只有当移动距离足够大时才进行拖动(避免微小移动造成的抖动) // 只有当移动距离足够大时才进行拖动(避免微小移动造成的抖动)
if (Math.Abs(delta.X) > 1 || Math.Abs(delta.Y) > 1) if (Math.Abs(delta.X) > 1 || Math.Abs(delta.Y) > 1)
{ {
// 创建变换矩阵 // 创建变换矩阵
var matrix = new Matrix(); var matrix = new Matrix();
matrix.Translate(delta.X, delta.Y); matrix.Translate(delta.X, delta.Y);
// 对选中的墨迹应用变换 // 对选中的墨迹应用变换
var selectedStrokes = inkCanvas.GetSelectedStrokes(); var selectedStrokes = inkCanvas.GetSelectedStrokes();
foreach (var stroke in selectedStrokes) foreach (var stroke in selectedStrokes)
{ {
stroke.Transform(matrix, false); stroke.Transform(matrix, false);
} }
// 更新选中栏位置 // 更新选中栏位置
updateBorderStrokeSelectionControlLocation(); updateBorderStrokeSelectionControlLocation();
// 更新最后触摸点 // 更新最后触摸点
lastTouchPointOnGridInkCanvasCover = currentTouchPoint; lastTouchPointOnGridInkCanvasCover = currentTouchPoint;
} }
@@ -638,15 +638,15 @@ namespace Ink_Canvas
// 获取触摸点位置 // 获取触摸点位置
var touchPosition = e.GetTouchPoint(inkCanvas).Position; var touchPosition = e.GetTouchPoint(inkCanvas).Position;
var selectionBounds = inkCanvas.GetSelectionBounds(); var selectionBounds = inkCanvas.GetSelectionBounds();
// 检查触摸位置是否在选择框边界内 // 检查触摸位置是否在选择框边界内
if (touchPosition.X >= selectionBounds.Left && if (touchPosition.X >= selectionBounds.Left &&
touchPosition.X <= selectionBounds.Right && touchPosition.X <= selectionBounds.Right &&
touchPosition.Y >= selectionBounds.Top && touchPosition.Y >= selectionBounds.Top &&
touchPosition.Y <= selectionBounds.Bottom) touchPosition.Y <= selectionBounds.Bottom)
{ {
// 只有在选择框边界内才允许拖动 // 只有在选择框边界内才允许拖动
// 触摸拖动状态已通过TouchMove事件处理 // 触摸拖动状态已通过TouchMove事件处理
} }
else else
{ {
@@ -681,11 +681,11 @@ namespace Ink_Canvas
{ {
dec.Remove(e.TouchDevice.Id); dec.Remove(e.TouchDevice.Id);
if (dec.Count >= 1) return; if (dec.Count >= 1) return;
// 重置触摸状态 // 重置触摸状态
lastTouchPointOnGridInkCanvasCover = new Point(0, 0); lastTouchPointOnGridInkCanvasCover = new Point(0, 0);
isProgramChangeStrokeSelection = false; isProgramChangeStrokeSelection = false;
// 检查是否有点击(没有移动) // 检查是否有点击(没有移动)
var currentTouchPoint = e.GetTouchPoint(null).Position; var currentTouchPoint = e.GetTouchPoint(null).Position;
if (Math.Abs(currentTouchPoint.X - centerPoint.X) < 5 && Math.Abs(currentTouchPoint.Y - centerPoint.Y) < 5) if (Math.Abs(currentTouchPoint.X - centerPoint.X) < 5 && Math.Abs(currentTouchPoint.Y - centerPoint.Y) < 5)
@@ -694,9 +694,9 @@ namespace Ink_Canvas
if (inkCanvas.GetSelectedStrokes().Count > 0) if (inkCanvas.GetSelectedStrokes().Count > 0)
{ {
var selectionBounds = inkCanvas.GetSelectionBounds(); var selectionBounds = inkCanvas.GetSelectionBounds();
if (currentTouchPoint.X >= selectionBounds.Left && if (currentTouchPoint.X >= selectionBounds.Left &&
currentTouchPoint.X <= selectionBounds.Right && currentTouchPoint.X <= selectionBounds.Right &&
currentTouchPoint.Y >= selectionBounds.Top && currentTouchPoint.Y >= selectionBounds.Top &&
currentTouchPoint.Y <= selectionBounds.Bottom) currentTouchPoint.Y <= selectionBounds.Bottom)
{ {
// 点击在选择框内,保持选择 // 点击在选择框内,保持选择
@@ -705,7 +705,7 @@ namespace Ink_Canvas
return; return;
} }
} }
// 点击在选择框外,取消选择 // 点击在选择框外,取消选择
inkCanvas.Select(new StrokeCollection()); inkCanvas.Select(new StrokeCollection());
StrokesSelectionClone = new StrokeCollection(); StrokesSelectionClone = new StrokeCollection();
@@ -720,7 +720,7 @@ namespace Ink_Canvas
GridInkCanvasSelectionCover.Visibility = Visibility.Visible; GridInkCanvasSelectionCover.Visibility = Visibility.Visible;
StrokesSelectionClone = new StrokeCollection(); StrokesSelectionClone = new StrokeCollection();
} }
} }
private void LassoSelect_Click(object sender, RoutedEventArgs e) private void LassoSelect_Click(object sender, RoutedEventArgs e)
@@ -799,7 +799,7 @@ namespace Ink_Canvas
} }
var selectionBounds = inkCanvas.GetSelectionBounds(); var selectionBounds = inkCanvas.GetSelectionBounds();
// 更新选择框 // 更新选择框
SelectionRectangle.Visibility = Visibility.Visible; SelectionRectangle.Visibility = Visibility.Visible;
SelectionRectangle.Margin = new Thickness(selectionBounds.Left, selectionBounds.Top, 0, 0); SelectionRectangle.Margin = new Thickness(selectionBounds.Left, selectionBounds.Top, 0, 0);
@@ -853,10 +853,10 @@ namespace Ink_Canvas
var delta = new Point(currentPoint.X - resizeStartPoint.X, currentPoint.Y - resizeStartPoint.Y); var delta = new Point(currentPoint.X - resizeStartPoint.X, currentPoint.Y - resizeStartPoint.Y);
var newBounds = CalculateNewBounds(originalSelectionBounds, delta, currentResizeHandle); var newBounds = CalculateNewBounds(originalSelectionBounds, delta, currentResizeHandle);
// 应用新的边界到选中的墨迹 // 应用新的边界到选中的墨迹
ApplyBoundsToStrokes(newBounds); ApplyBoundsToStrokes(newBounds);
// 更新选择框显示 // 更新选择框显示
UpdateSelectionDisplay(); UpdateSelectionDisplay();
} }
@@ -934,11 +934,11 @@ namespace Ink_Canvas
if (selectedStrokes.Count == 0) return; if (selectedStrokes.Count == 0) return;
var originalBounds = inkCanvas.GetSelectionBounds(); var originalBounds = inkCanvas.GetSelectionBounds();
// 计算缩放比例 // 计算缩放比例
var scaleX = newBounds.Width / originalBounds.Width; var scaleX = newBounds.Width / originalBounds.Width;
var scaleY = newBounds.Height / originalBounds.Height; var scaleY = newBounds.Height / originalBounds.Height;
// 计算平移量 // 计算平移量
var translateX = newBounds.X - originalBounds.X; var translateX = newBounds.X - originalBounds.X;
var translateY = newBounds.Y - originalBounds.Y; var translateY = newBounds.Y - originalBounds.Y;
+5 -5
View File
@@ -197,23 +197,23 @@ namespace Ink_Canvas
val > 0.5 && val < 1.25 ? val : val <= 0.5 ? 0.5 : val >= 1.25 ? 1.25 : 1; val > 0.5 && val < 1.25 ? val : val <= 0.5 ? 0.5 : val >= 1.25 ? 1.25 : 1;
ViewboxFloatingBarScaleTransform.ScaleY = ViewboxFloatingBarScaleTransform.ScaleY =
val > 0.5 && val < 1.25 ? val : val <= 0.5 ? 0.5 : val >= 1.25 ? 1.25 : 1; val > 0.5 && val < 1.25 ? val : val <= 0.5 ? 0.5 : val >= 1.25 ? 1.25 : 1;
// 等待UI更新后再重新计算浮动栏位置,确保居中计算准确 // 等待UI更新后再重新计算浮动栏位置,确保居中计算准确
Dispatcher.BeginInvoke(new Action(async () => Dispatcher.BeginInvoke(new Action(async () =>
{ {
// 强制更新布局以确保ActualWidth正确 // 强制更新布局以确保ActualWidth正确
ViewboxFloatingBar.UpdateLayout(); ViewboxFloatingBar.UpdateLayout();
// 等待一小段时间让布局完全更新 // 等待一小段时间让布局完全更新
await Task.Delay(100); await Task.Delay(100);
// 再次强制更新布局 // 再次强制更新布局
ViewboxFloatingBar.UpdateLayout(); ViewboxFloatingBar.UpdateLayout();
// 强制重新测量和排列 // 强制重新测量和排列
ViewboxFloatingBar.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); ViewboxFloatingBar.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
ViewboxFloatingBar.Arrange(new Rect(ViewboxFloatingBar.DesiredSize)); ViewboxFloatingBar.Arrange(new Rect(ViewboxFloatingBar.DesiredSize));
// auto align - 新增:只在屏幕模式下重新计算浮动栏位置 // auto align - 新增:只在屏幕模式下重新计算浮动栏位置
if (currentMode == 0) if (currentMode == 0)
{ {
@@ -256,7 +256,7 @@ namespace Ink_Canvas
_taskbar.Visibility = Settings.Appearance.EnableTrayIcon ? Visibility.Visible : Visibility.Collapsed; _taskbar.Visibility = Settings.Appearance.EnableTrayIcon ? Visibility.Visible : Visibility.Collapsed;
ViewboxFloatingBar.Opacity = Settings.Appearance.ViewboxFloatingBarOpacityValue; ViewboxFloatingBar.Opacity = Settings.Appearance.ViewboxFloatingBarOpacityValue;
// 初始化浮动栏透明度滑块值 // 初始化浮动栏透明度滑块值
ViewboxFloatingBarOpacityValueSlider.Value = Settings.Appearance.ViewboxFloatingBarOpacityValue; ViewboxFloatingBarOpacityValueSlider.Value = Settings.Appearance.ViewboxFloatingBarOpacityValue;
ViewboxFloatingBarOpacityInPPTValueSlider.Value = Settings.Appearance.ViewboxFloatingBarOpacityInPPTValue; ViewboxFloatingBarOpacityInPPTValueSlider.Value = Settings.Appearance.ViewboxFloatingBarOpacityInPPTValue;
+2 -2
View File
@@ -107,10 +107,10 @@ namespace Ink_Canvas
else if (sender == ImageDrawArrow || sender == BoardImageDrawArrow) else if (sender == ImageDrawArrow || sender == BoardImageDrawArrow)
drawingShapeMode = 2; drawingShapeMode = 2;
else if (sender == ImageDrawParallelLine || sender == BoardImageDrawParallelLine) drawingShapeMode = 15; else if (sender == ImageDrawParallelLine || sender == BoardImageDrawParallelLine) drawingShapeMode = 15;
// 更新模式缓存 // 更新模式缓存
UpdateCurrentToolMode("shape"); UpdateCurrentToolMode("shape");
isLongPressSelected = true; isLongPressSelected = true;
if (isSingleFingerDragMode) BtnFingerDragMode_Click(BtnFingerDragMode, null); if (isSingleFingerDragMode) BtnFingerDragMode_Click(BtnFingerDragMode, null);
} }
+11 -11
View File
@@ -127,15 +127,15 @@ namespace Ink_Canvas
{ {
DateTime localTime = DateTime.Now; DateTime localTime = DateTime.Now;
DateTime displayTime = localTime; // 默认使用本地时间 DateTime displayTime = localTime; // 默认使用本地时间
try try
{ {
DateTime networkTime = await GetNetworkTimeAsync(); DateTime networkTime = await GetNetworkTimeAsync();
// 计算时间差 // 计算时间差
TimeSpan timeDifference = networkTime - localTime; TimeSpan timeDifference = networkTime - localTime;
double timeDifferenceMinutes = Math.Abs(timeDifference.TotalMinutes); double timeDifferenceMinutes = Math.Abs(timeDifference.TotalMinutes);
// 如果网络时间与本地时间相差不超过1分钟,则使用本地时间 // 如果网络时间与本地时间相差不超过1分钟,则使用本地时间
// 否则使用网络时间 // 否则使用网络时间
displayTime = timeDifferenceMinutes <= 1.0 ? localTime : networkTime; displayTime = timeDifferenceMinutes <= 1.0 ? localTime : networkTime;
@@ -145,7 +145,7 @@ namespace Ink_Canvas
// 网络时间获取失败时,使用本地时间 // 网络时间获取失败时,使用本地时间
displayTime = localTime; displayTime = localTime;
} }
// 只更新时间,日期由原有逻辑定时更新即可 // 只更新时间,日期由原有逻辑定时更新即可
Dispatcher.Invoke(() => Dispatcher.Invoke(() =>
{ {
@@ -313,7 +313,7 @@ namespace Ink_Canvas
var windowTitle = ForegroundWindowInfo.WindowTitle(); var windowTitle = ForegroundWindowInfo.WindowTitle();
var windowRect = ForegroundWindowInfo.WindowRect(); var windowRect = ForegroundWindowInfo.WindowRect();
var windowProcessName = ForegroundWindowInfo.ProcessName(); var windowProcessName = ForegroundWindowInfo.ProcessName();
// 检测希沃白板五的批注面板 // 检测希沃白板五的批注面板
// 希沃白板五的批注面板通常具有以下特征: // 希沃白板五的批注面板通常具有以下特征:
// 1. 窗口标题为空或包含特定关键词 // 1. 窗口标题为空或包含特定关键词
@@ -323,32 +323,32 @@ namespace Ink_Canvas
{ {
// 检测希沃白板五的批注工具栏 // 检测希沃白板五的批注工具栏
// 批注工具栏通常高度在50-200像素之间,宽度在200-800像素之间 // 批注工具栏通常高度在50-200像素之间,宽度在200-800像素之间
if (windowRect.Height >= 50 && windowRect.Height <= 200 && if (windowRect.Height >= 50 && windowRect.Height <= 200 &&
windowRect.Width >= 200 && windowRect.Width <= 800) windowRect.Width >= 200 && windowRect.Width <= 800)
{ {
return true; return true;
} }
// 检测希沃白板五的二级菜单面板 // 检测希沃白板五的二级菜单面板
// 二级菜单面板通常高度在100-400像素之间,宽度在150-400像素之间 // 二级菜单面板通常高度在100-400像素之间,宽度在150-400像素之间
if (windowRect.Height >= 100 && windowRect.Height <= 400 && if (windowRect.Height >= 100 && windowRect.Height <= 400 &&
windowRect.Width >= 150 && windowRect.Width <= 400) windowRect.Width >= 150 && windowRect.Width <= 400)
{ {
return true; return true;
} }
} }
// 检测鸿合软件的批注面板 // 检测鸿合软件的批注面板
if (windowProcessName == "HiteCamera" || windowProcessName == "HiteTouchPro" || windowProcessName == "HiteLightBoard") if (windowProcessName == "HiteCamera" || windowProcessName == "HiteTouchPro" || windowProcessName == "HiteLightBoard")
{ {
// 鸿合软件的批注面板特征 // 鸿合软件的批注面板特征
if (windowRect.Height >= 50 && windowRect.Height <= 300 && if (windowRect.Height >= 50 && windowRect.Height <= 300 &&
windowRect.Width >= 200 && windowRect.Width <= 600) windowRect.Width >= 200 && windowRect.Width <= 600)
{ {
return true; return true;
} }
} }
// 原有的检测逻辑(保持向后兼容) // 原有的检测逻辑(保持向后兼容)
return windowTitle.Length == 0 && windowRect.Height < 500; return windowTitle.Length == 0 && windowRect.Height < 500;
} }
+14 -14
View File
@@ -503,7 +503,7 @@ namespace Ink_Canvas
// 计算触摸面积(使用设备提供的Size) // 计算触摸面积(使用设备提供的Size)
double touchArea = size.Width * size.Height; double touchArea = size.Width * size.Height;
// 计算宽高比(使用Bounds确保准确性) // 计算宽高比(使用Bounds确保准确性)
double aspectRatio = Math.Min(bounds.Width, bounds.Height) / Math.Max(bounds.Width, bounds.Height); double aspectRatio = Math.Min(bounds.Width, bounds.Height) / Math.Max(bounds.Width, bounds.Height);
@@ -511,7 +511,7 @@ namespace Ink_Canvas
bool isLargeTouch = touchArea >= palmAreaThreshold; bool isLargeTouch = touchArea >= palmAreaThreshold;
bool isPalmLikeShape = aspectRatio >= aspectRatioThreshold; bool isPalmLikeShape = aspectRatio >= aspectRatioThreshold;
bool hasMultipleTouchPoints = dec.Count >= minTouchPoints; bool hasMultipleTouchPoints = dec.Count >= minTouchPoints;
// 新增:额外的判定条件提高准确性 // 新增:额外的判定条件提高准确性
bool isReasonableSize = size.Width >= 20 && size.Height >= 20 && size.Width <= 200 && size.Height <= 200; // 合理的触摸尺寸范围 bool isReasonableSize = size.Width >= 20 && size.Height >= 20 && size.Width <= 200 && size.Height <= 200; // 合理的触摸尺寸范围
bool isNotTooElongated = aspectRatio >= 0.2; // 避免过于细长的触摸(可能是手指) bool isNotTooElongated = aspectRatio >= 0.2; // 避免过于细长的触摸(可能是手指)
@@ -614,7 +614,7 @@ namespace Ink_Canvas
if (isPalmEraserActive && palmEraserTouchIds.Count == 0) if (isPalmEraserActive && palmEraserTouchIds.Count == 0)
{ {
LogHelper.WriteLogToFile($"Palm eraser recovery triggered - Touch points remaining: {palmEraserTouchIds.Count}, dec.Count: {dec.Count}"); LogHelper.WriteLogToFile($"Palm eraser recovery triggered - Touch points remaining: {palmEraserTouchIds.Count}, dec.Count: {dec.Count}");
// 恢复高光状态 // 恢复高光状态
drawingAttributes.IsHighlighter = palmEraserLastIsHighlighter; drawingAttributes.IsHighlighter = palmEraserLastIsHighlighter;
@@ -778,10 +778,10 @@ namespace Ink_Canvas
if (isPalmEraserActive) if (isPalmEraserActive)
{ {
LogHelper.WriteLogToFile("Palm eraser force recovery - all touch points cleared"); LogHelper.WriteLogToFile("Palm eraser force recovery - all touch points cleared");
// 恢复高光状态 // 恢复高光状态
drawingAttributes.IsHighlighter = palmEraserLastIsHighlighter; drawingAttributes.IsHighlighter = palmEraserLastIsHighlighter;
// 恢复编辑模式 // 恢复编辑模式
try try
{ {
@@ -807,7 +807,7 @@ namespace Ink_Canvas
LogHelper.WriteLogToFile($"Palm eraser force recovery failed: {ex.Message}, forcing to Ink mode", LogHelper.LogType.Error); LogHelper.WriteLogToFile($"Palm eraser force recovery failed: {ex.Message}, forcing to Ink mode", LogHelper.LogType.Error);
inkCanvas.EditingMode = InkCanvasEditingMode.Ink; inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
} }
// 如果手掌擦还在激活状态但触摸点已清空,强制重置状态 // 如果手掌擦还在激活状态但触摸点已清空,强制重置状态
isPalmEraserActive = false; isPalmEraserActive = false;
palmEraserTouchDownHandled = false; palmEraserTouchDownHandled = false;
@@ -817,10 +817,10 @@ namespace Ink_Canvas
ViewboxFloatingBar.IsHitTestVisible = true; ViewboxFloatingBar.IsHitTestVisible = true;
BlackboardUIGridForInkReplay.IsHitTestVisible = true; BlackboardUIGridForInkReplay.IsHitTestVisible = true;
// 停止恢复定时器 // 停止恢复定时器
StopPalmEraserRecoveryTimer(); StopPalmEraserRecoveryTimer();
LogHelper.WriteLogToFile("Palm eraser force recovery completed"); LogHelper.WriteLogToFile("Palm eraser force recovery completed");
} }
} }
@@ -865,33 +865,33 @@ namespace Ink_Canvas
return; return;
// 三指及以上禁止缩放 // 三指及以上禁止缩放
bool disableScale = dec.Count >= 3; bool disableScale = dec.Count >= 3;
// 修复:允许单指拖动选中的墨迹,即使禁用了多指手势 // 修复:允许单指拖动选中的墨迹,即使禁用了多指手势
if (isInMultiTouchMode) return; if (isInMultiTouchMode) return;
// 如果是单指拖动选中的墨迹,允许处理 // 如果是单指拖动选中的墨迹,允许处理
if (dec.Count == 1 && inkCanvas.GetSelectedStrokes().Count > 0) if (dec.Count == 1 && inkCanvas.GetSelectedStrokes().Count > 0)
{ {
var md = e.DeltaManipulation; var md = e.DeltaManipulation;
var trans = md.Translation; // 获得位移矢量 var trans = md.Translation; // 获得位移矢量
if (trans.X != 0 || trans.Y != 0) if (trans.X != 0 || trans.Y != 0)
{ {
var m = new Matrix(); var m = new Matrix();
m.Translate(trans.X, trans.Y); // 移动 m.Translate(trans.X, trans.Y); // 移动
var strokes = inkCanvas.GetSelectedStrokes(); var strokes = inkCanvas.GetSelectedStrokes();
foreach (var stroke in strokes) foreach (var stroke in strokes)
{ {
stroke.Transform(m, false); stroke.Transform(m, false);
} }
// 更新选择框位置 // 更新选择框位置
updateBorderStrokeSelectionControlLocation(); updateBorderStrokeSelectionControlLocation();
} }
return; return;
} }
if (!Settings.Gesture.IsEnableTwoFingerGesture) return; if (!Settings.Gesture.IsEnableTwoFingerGesture) return;
if ((dec.Count >= 2 && (Settings.PowerPointSettings.IsEnableTwoFingerGestureInPresentationMode || if ((dec.Count >= 2 && (Settings.PowerPointSettings.IsEnableTwoFingerGestureInPresentationMode ||
StackPanelPPTControls.Visibility != Visibility.Visible || StackPanelPPTControls.Visibility != Visibility.Visible ||
+18 -11
View File
@@ -1,22 +1,27 @@
using System.Windows; using System.Windows;
using System.Windows.Media; using System.Windows.Media;
namespace Ink_Canvas.Resources.ICCConfiguration { namespace Ink_Canvas.Resources.ICCConfiguration
public enum InitialPositionTypes { {
public enum InitialPositionTypes
{
TopLeft, TopRight, BottomLeft, BottomRight, TopCenter, BottomCenter, Custom TopLeft, TopRight, BottomLeft, BottomRight, TopCenter, BottomCenter, Custom
} }
public enum ElementCornerRadiusTypes { public enum ElementCornerRadiusTypes
{
SuperEllipse, Circle, Custom, None SuperEllipse, Circle, Custom, None
} }
public class NearSnapAreaSize { public class NearSnapAreaSize
public double[] TopLeft { get; set; } = {24,24}; {
public double[] TopRight { get; set; } = {24,24}; public double[] TopLeft { get; set; } = { 24, 24 };
public double[] BottomLeft { get; set; } = {24,24}; public double[] TopRight { get; set; } = { 24, 24 };
public double[] BottomRight { get; set; } = {24,24}; public double[] BottomLeft { get; set; } = { 24, 24 };
public double[] BottomRight { get; set; } = { 24, 24 };
public double TopCenter { get; set; } = 24; public double TopCenter { get; set; } = 24;
public double BottomCenter { get; set; } = 24; public double BottomCenter { get; set; } = 24;
} }
public class ICCFloatingBarConfiguration { public class ICCFloatingBarConfiguration
{
public bool SemiTransparent { get; set; } = false; public bool SemiTransparent { get; set; } = false;
public bool NearSnap { get; set; } = true; public bool NearSnap { get; set; } = true;
public InitialPositionTypes InitialPosition { get; set; } = InitialPositionTypes.BottomCenter; public InitialPositionTypes InitialPosition { get; set; } = InitialPositionTypes.BottomCenter;
@@ -32,7 +37,8 @@ namespace Ink_Canvas.Resources.ICCConfiguration {
public double MovingLimitationNoSnap { get; set; } = 12; public double MovingLimitationNoSnap { get; set; } = 12;
public double MovingLimitationSnapped { get; set; } = 24; public double MovingLimitationSnapped { get; set; } = 24;
public NearSnapAreaSize NearSnapAreaSize { get; set; } = new NearSnapAreaSize() { public NearSnapAreaSize NearSnapAreaSize { get; set; } = new NearSnapAreaSize()
{
TopLeft = new double[] { 24, 24 }, TopLeft = new double[] { 24, 24 },
TopRight = new double[] { 24, 24 }, TopRight = new double[] { 24, 24 },
BottomLeft = new double[] { 24, 24 }, BottomLeft = new double[] { 24, 24 },
@@ -50,7 +56,8 @@ namespace Ink_Canvas.Resources.ICCConfiguration {
}; };
} }
public class ICCConfiguration { public class ICCConfiguration
{
public ICCFloatingBarConfiguration FloatingBar { get; set; } = new ICCFloatingBarConfiguration(); public ICCFloatingBarConfiguration FloatingBar { get; set; } = new ICCFloatingBarConfiguration();
} }
} }
@@ -359,7 +359,8 @@ namespace Ink_Canvas
// Set to center // Set to center
double dpiScaleX = 1, dpiScaleY = 1; double dpiScaleX = 1, dpiScaleY = 1;
PresentationSource source = PresentationSource.FromVisual(this); PresentationSource source = PresentationSource.FromVisual(this);
if (source != null) { if (source != null)
{
dpiScaleX = source.CompositionTarget.TransformToDevice.M11; dpiScaleX = source.CompositionTarget.TransformToDevice.M11;
dpiScaleY = source.CompositionTarget.TransformToDevice.M22; dpiScaleY = source.CompositionTarget.TransformToDevice.M22;
} }
@@ -42,7 +42,7 @@ namespace Ink_Canvas.Windows
// 加载当前快捷键(包括配置文件中的) // 加载当前快捷键(包括配置文件中的)
LoadCurrentHotkeys(); LoadCurrentHotkeys();
SetupEventHandlers(); SetupEventHandlers();
// 初始化鼠标模式快捷键设置 // 初始化鼠标模式快捷键设置
InitializeMouseModeSettings(); InitializeMouseModeSettings();
} }
@@ -67,10 +67,10 @@ namespace Ink_Canvas.Windows
{ {
// 设置窗口启动位置为屏幕中心 // 设置窗口启动位置为屏幕中心
WindowStartupLocation = WindowStartupLocation.CenterScreen; WindowStartupLocation = WindowStartupLocation.CenterScreen;
// 确保窗口在显示时获得焦点 // 确保窗口在显示时获得焦点
ShowInTaskbar = true; ShowInTaskbar = true;
LogHelper.WriteLogToFile("快捷键设置窗口属性已设置"); LogHelper.WriteLogToFile("快捷键设置窗口属性已设置");
} }
catch (Exception ex) catch (Exception ex)
@@ -274,10 +274,10 @@ namespace Ink_Canvas.Windows
{ {
// 设置开关的初始状态 // 设置开关的初始状态
ToggleSwitchEnableHotkeysInMouseMode.IsOn = MainWindow.Settings.Appearance.EnableHotkeysInMouseMode; ToggleSwitchEnableHotkeysInMouseMode.IsOn = MainWindow.Settings.Appearance.EnableHotkeysInMouseMode;
// 绑定开关变化事件 // 绑定开关变化事件
ToggleSwitchEnableHotkeysInMouseMode.Toggled += OnMouseModeHotkeyToggleChanged; ToggleSwitchEnableHotkeysInMouseMode.Toggled += OnMouseModeHotkeyToggleChanged;
LogHelper.WriteLogToFile($"鼠标模式快捷键设置已初始化: {MainWindow.Settings.Appearance.EnableHotkeysInMouseMode}"); LogHelper.WriteLogToFile($"鼠标模式快捷键设置已初始化: {MainWindow.Settings.Appearance.EnableHotkeysInMouseMode}");
} }
catch (Exception ex) catch (Exception ex)
@@ -295,16 +295,16 @@ namespace Ink_Canvas.Windows
{ {
// 更新设置 // 更新设置
MainWindow.Settings.Appearance.EnableHotkeysInMouseMode = ToggleSwitchEnableHotkeysInMouseMode.IsOn; MainWindow.Settings.Appearance.EnableHotkeysInMouseMode = ToggleSwitchEnableHotkeysInMouseMode.IsOn;
// 立即保存设置 // 立即保存设置
MainWindow.SaveSettingsToFile(); MainWindow.SaveSettingsToFile();
// 如果快捷键管理器存在,立即更新快捷键状态 // 如果快捷键管理器存在,立即更新快捷键状态
if (_hotkeyManager != null) if (_hotkeyManager != null)
{ {
// 检查当前是否处于鼠标模式 // 检查当前是否处于鼠标模式
bool isCurrentlyMouseMode = _mainWindow.inkCanvas.EditingMode == InkCanvasEditingMode.None; bool isCurrentlyMouseMode = _mainWindow.inkCanvas.EditingMode == InkCanvasEditingMode.None;
// 如果当前处于鼠标模式且关闭了开关,立即禁用快捷键 // 如果当前处于鼠标模式且关闭了开关,立即禁用快捷键
if (isCurrentlyMouseMode && !ToggleSwitchEnableHotkeysInMouseMode.IsOn) if (isCurrentlyMouseMode && !ToggleSwitchEnableHotkeysInMouseMode.IsOn)
{ {
@@ -317,7 +317,7 @@ namespace Ink_Canvas.Windows
_hotkeyManager.UpdateHotkeyStateForToolMode(isCurrentlyMouseMode); _hotkeyManager.UpdateHotkeyStateForToolMode(isCurrentlyMouseMode);
} }
} }
LogHelper.WriteLogToFile($"鼠标模式快捷键设置已更新: {MainWindow.Settings.Appearance.EnableHotkeysInMouseMode}", LogHelper.LogType.Event); LogHelper.WriteLogToFile($"鼠标模式快捷键设置已更新: {MainWindow.Settings.Appearance.EnableHotkeysInMouseMode}", LogHelper.LogType.Event);
} }
catch (Exception ex) catch (Exception ex)
@@ -25,17 +25,22 @@ namespace Ink_Canvas
if (e.LeftButton == MouseButtonState.Pressed) DragMove(); if (e.LeftButton == MouseButtonState.Pressed) DragMove();
} }
private void BtnFullscreen_MouseUp(object sender, MouseButtonEventArgs e) { private void BtnFullscreen_MouseUp(object sender, MouseButtonEventArgs e)
if (WindowState == WindowState.Normal) { {
if (WindowState == WindowState.Normal)
{
WindowState = WindowState.Maximized; WindowState = WindowState.Maximized;
SymbolIconFullscreen.Symbol = iNKORE.UI.WPF.Modern.Controls.Symbol.BackToWindow; SymbolIconFullscreen.Symbol = iNKORE.UI.WPF.Modern.Controls.Symbol.BackToWindow;
} else { }
else
{
WindowState = WindowState.Normal; WindowState = WindowState.Normal;
SymbolIconFullscreen.Symbol = iNKORE.UI.WPF.Modern.Controls.Symbol.FullScreen; SymbolIconFullscreen.Symbol = iNKORE.UI.WPF.Modern.Controls.Symbol.FullScreen;
} }
} }
private void SCManipulationBoundaryFeedback(object sender, ManipulationBoundaryFeedbackEventArgs e) { private void SCManipulationBoundaryFeedback(object sender, ManipulationBoundaryFeedbackEventArgs e)
{
e.Handled = true; e.Handled = true;
} }
} }
+6 -6
View File
@@ -36,10 +36,10 @@ namespace Ink_Canvas
// 设置窗口为置顶 // 设置窗口为置顶
Topmost = true; Topmost = true;
// 添加窗口关闭事件处理 // 添加窗口关闭事件处理
Closed += RandWindow_Closed; Closed += RandWindow_Closed;
// 添加窗口显示事件处理,确保置顶 // 添加窗口显示事件处理,确保置顶
Loaded += RandWindow_Loaded; Loaded += RandWindow_Loaded;
} }
@@ -90,10 +90,10 @@ namespace Ink_Canvas
// 设置窗口为置顶 // 设置窗口为置顶
Topmost = true; Topmost = true;
// 添加窗口关闭事件处理 // 添加窗口关闭事件处理
Closed += RandWindow_Closed; Closed += RandWindow_Closed;
// 添加窗口显示事件处理,确保置顶 // 添加窗口显示事件处理,确保置顶
Loaded += RandWindow_Loaded; Loaded += RandWindow_Loaded;
@@ -372,10 +372,10 @@ namespace Ink_Canvas
// 强制激活窗口 // 强制激活窗口
Activate(); Activate();
Focus(); Focus();
// 设置置顶 // 设置置顶
Topmost = true; Topmost = true;
// 使用Win32 API强制置顶 // 使用Win32 API强制置顶
var hwnd = new WindowInteropHelper(this).Handle; var hwnd = new WindowInteropHelper(this).Handle;
if (hwnd != IntPtr.Zero) if (hwnd != IntPtr.Zero)
@@ -81,7 +81,7 @@ namespace Ink_Canvas
private void BindControlPointEvents() private void BindControlPointEvents()
{ {
// 绑定所有控制点的鼠标事件 // 绑定所有控制点的鼠标事件
var controlPoints = new[] var controlPoints = new[]
{ {
TopLeftControl, TopRightControl, BottomLeftControl, BottomRightControl, TopLeftControl, TopRightControl, BottomLeftControl, BottomRightControl,
TopControl, BottomControl, LeftControl, RightControl TopControl, BottomControl, LeftControl, RightControl
@@ -92,11 +92,11 @@ namespace Ink_Canvas
control.MouseLeftButtonDown += ControlPoint_MouseLeftButtonDown; control.MouseLeftButtonDown += ControlPoint_MouseLeftButtonDown;
control.MouseLeftButtonUp += ControlPoint_MouseLeftButtonUp; control.MouseLeftButtonUp += ControlPoint_MouseLeftButtonUp;
control.MouseMove += ControlPoint_MouseMove; control.MouseMove += ControlPoint_MouseMove;
// 确保控制点能够接收鼠标事件 // 确保控制点能够接收鼠标事件
control.IsHitTestVisible = true; control.IsHitTestVisible = true;
control.Focusable = false; control.Focusable = false;
// 设置控制点的Z-index,确保它们在最上层 // 设置控制点的Z-index,确保它们在最上层
WpfCanvas.SetZIndex(control, 1003); WpfCanvas.SetZIndex(control, 1003);
} }
@@ -142,7 +142,7 @@ namespace Ink_Canvas
{ {
// 重置所有选择状态 // 重置所有选择状态
ResetSelectionState(); ResetSelectionState();
_isFreehandMode = false; _isFreehandMode = false;
RectangleModeButton.Background = new SolidColorBrush(Color.FromRgb(37, 99, 235)); // 蓝色 RectangleModeButton.Background = new SolidColorBrush(Color.FromRgb(37, 99, 235)); // 蓝色
FreehandModeButton.Background = new SolidColorBrush(Color.FromRgb(107, 114, 128)); // 灰色 FreehandModeButton.Background = new SolidColorBrush(Color.FromRgb(107, 114, 128)); // 灰色
@@ -154,7 +154,7 @@ namespace Ink_Canvas
{ {
// 重置所有选择状态 // 重置所有选择状态
ResetSelectionState(); ResetSelectionState();
_isFreehandMode = true; _isFreehandMode = true;
FreehandModeButton.Background = new SolidColorBrush(Color.FromRgb(37, 99, 235)); // 蓝色 FreehandModeButton.Background = new SolidColorBrush(Color.FromRgb(37, 99, 235)); // 蓝色
RectangleModeButton.Background = new SolidColorBrush(Color.FromRgb(107, 114, 128)); // 灰色 RectangleModeButton.Background = new SolidColorBrush(Color.FromRgb(107, 114, 128)); // 灰色
@@ -169,7 +169,7 @@ namespace Ink_Canvas
{ {
return; return;
} }
ConfirmSelection(); ConfirmSelection();
} }
@@ -183,10 +183,10 @@ namespace Ink_Canvas
// 检查是否点击了UI元素,如果是则不处理选择 // 检查是否点击了UI元素,如果是则不处理选择
var hitElement = e.Source as FrameworkElement; var hitElement = e.Source as FrameworkElement;
if (hitElement != null && ( if (hitElement != null && (
hitElement is Ellipse || hitElement is Ellipse ||
hitElement is System.Windows.Controls.Button || hitElement is System.Windows.Controls.Button ||
hitElement is Border || hitElement is Border ||
hitElement is TextBlock || hitElement is TextBlock ||
hitElement is StackPanel || hitElement is StackPanel ||
hitElement is Separator || hitElement is Separator ||
hitElement.Name == "SizeInfoBorder" || hitElement.Name == "SizeInfoBorder" ||
@@ -222,7 +222,7 @@ namespace Ink_Canvas
_freehandPolyline.Points.Clear(); _freehandPolyline.Points.Clear();
_freehandPoints.Add(_startPoint); _freehandPoints.Add(_startPoint);
_freehandPolyline.Points.Add(_startPoint); _freehandPolyline.Points.Add(_startPoint);
// 确保自由绘制路径可见 // 确保自由绘制路径可见
_freehandPolyline.Visibility = Visibility.Visible; _freehandPolyline.Visibility = Visibility.Visible;
} }
@@ -259,7 +259,7 @@ namespace Ink_Canvas
// 自由绘制模式:添加点到路径 // 自由绘制模式:添加点到路径
_freehandPoints.Add(_currentPoint); _freehandPoints.Add(_currentPoint);
_freehandPolyline.Points.Add(_currentPoint); _freehandPolyline.Points.Add(_currentPoint);
// 确保自由绘制路径可见 // 确保自由绘制路径可见
_freehandPolyline.Visibility = Visibility.Visible; _freehandPolyline.Visibility = Visibility.Visible;
} }
@@ -291,7 +291,7 @@ namespace Ink_Canvas
{ {
// 创建路径的副本,避免修改原始列表 // 创建路径的副本,避免修改原始列表
var pathPoints = new List<Point>(_freehandPoints); var pathPoints = new List<Point>(_freehandPoints);
// 简化路径处理,不强制闭合 // 简化路径处理,不强制闭合
// 如果路径没有闭合,自动添加起始点 // 如果路径没有闭合,自动添加起始点
if (pathPoints.Count > 0) if (pathPoints.Count > 0)
@@ -301,13 +301,13 @@ namespace Ink_Canvas
// 优化路径:移除重复点和过于接近的点,提高路径质量 // 优化路径:移除重复点和过于接近的点,提高路径质量
var optimizedPath = OptimizePath(pathPoints); var optimizedPath = OptimizePath(pathPoints);
// 保存选择的路径 // 保存选择的路径
SelectedPath = optimizedPath; SelectedPath = optimizedPath;
// 计算边界矩形用于截图 // 计算边界矩形用于截图
var bounds = CalculatePathBounds(optimizedPath); var bounds = CalculatePathBounds(optimizedPath);
// 确保边界矩形有效 // 确保边界矩形有效
if (bounds.Width >= 0 && bounds.Height >= 0) if (bounds.Width >= 0 && bounds.Height >= 0)
{ {
@@ -325,7 +325,7 @@ namespace Ink_Canvas
return; return;
} }
} }
// 如果自由绘制失败,清除路径并继续 // 如果自由绘制失败,清除路径并继续
_freehandPoints.Clear(); _freehandPoints.Clear();
_freehandPolyline.Points.Clear(); _freehandPolyline.Points.Clear();
@@ -363,7 +363,7 @@ namespace Ink_Canvas
_isMoving = true; _isMoving = true;
_lastMousePosition = e.GetPosition(this); _lastMousePosition = e.GetPosition(this);
// 确定当前控制点类型 // 确定当前控制点类型
var ellipse = sender as Ellipse; var ellipse = sender as Ellipse;
if (ellipse == TopLeftControl) _activeControlPoint = ControlPointType.TopLeft; if (ellipse == TopLeftControl) _activeControlPoint = ControlPointType.TopLeft;
@@ -486,26 +486,26 @@ namespace Ink_Canvas
// 更新角控制点位置 // 更新角控制点位置
WpfCanvas.SetLeft(TopLeftControl, rect.Left - 4); WpfCanvas.SetLeft(TopLeftControl, rect.Left - 4);
WpfCanvas.SetTop(TopLeftControl, rect.Top - 4); WpfCanvas.SetTop(TopLeftControl, rect.Top - 4);
WpfCanvas.SetLeft(TopRightControl, rect.Right - 4); WpfCanvas.SetLeft(TopRightControl, rect.Right - 4);
WpfCanvas.SetTop(TopRightControl, rect.Top - 4); WpfCanvas.SetTop(TopRightControl, rect.Top - 4);
WpfCanvas.SetLeft(BottomLeftControl, rect.Left - 4); WpfCanvas.SetLeft(BottomLeftControl, rect.Left - 4);
WpfCanvas.SetTop(BottomLeftControl, rect.Bottom - 4); WpfCanvas.SetTop(BottomLeftControl, rect.Bottom - 4);
WpfCanvas.SetLeft(BottomRightControl, rect.Right - 4); WpfCanvas.SetLeft(BottomRightControl, rect.Right - 4);
WpfCanvas.SetTop(BottomRightControl, rect.Bottom - 4); WpfCanvas.SetTop(BottomRightControl, rect.Bottom - 4);
// 更新边控制点位置 // 更新边控制点位置
WpfCanvas.SetLeft(TopControl, rect.Left + rect.Width / 2 - 4); WpfCanvas.SetLeft(TopControl, rect.Left + rect.Width / 2 - 4);
WpfCanvas.SetTop(TopControl, rect.Top - 4); WpfCanvas.SetTop(TopControl, rect.Top - 4);
WpfCanvas.SetLeft(BottomControl, rect.Left + rect.Width / 2 - 4); WpfCanvas.SetLeft(BottomControl, rect.Left + rect.Width / 2 - 4);
WpfCanvas.SetTop(BottomControl, rect.Bottom - 4); WpfCanvas.SetTop(BottomControl, rect.Bottom - 4);
WpfCanvas.SetLeft(LeftControl, rect.Left - 4); WpfCanvas.SetLeft(LeftControl, rect.Left - 4);
WpfCanvas.SetTop(LeftControl, rect.Top + rect.Height / 2 - 4); WpfCanvas.SetTop(LeftControl, rect.Top + rect.Height / 2 - 4);
WpfCanvas.SetLeft(RightControl, rect.Right - 4); WpfCanvas.SetLeft(RightControl, rect.Right - 4);
WpfCanvas.SetTop(RightControl, rect.Top + rect.Height / 2 - 4); WpfCanvas.SetTop(RightControl, rect.Top + rect.Height / 2 - 4);
} }
@@ -519,7 +519,7 @@ namespace Ink_Canvas
WpfCanvas.SetTop(SelectionRectangle, rect.Y); WpfCanvas.SetTop(SelectionRectangle, rect.Y);
SelectionRectangle.Width = rect.Width; SelectionRectangle.Width = rect.Width;
SelectionRectangle.Height = rect.Height; SelectionRectangle.Height = rect.Height;
// 在选择过程中,禁用选择矩形的鼠标事件,避免干扰选择操作 // 在选择过程中,禁用选择矩形的鼠标事件,避免干扰选择操作
if (_isSelecting) if (_isSelecting)
{ {
@@ -547,7 +547,7 @@ namespace Ink_Canvas
{ {
// 更新选择区域的几何体 // 更新选择区域的几何体
SelectionClipGeometry.Rect = selectionRect; SelectionClipGeometry.Rect = selectionRect;
// 显示透明遮罩,隐藏原始遮罩 // 显示透明遮罩,隐藏原始遮罩
TransparentSelectionMask.Visibility = Visibility.Visible; TransparentSelectionMask.Visibility = Visibility.Visible;
OverlayRectangle.Visibility = Visibility.Collapsed; OverlayRectangle.Visibility = Visibility.Collapsed;
@@ -569,7 +569,7 @@ namespace Ink_Canvas
WpfCanvas.SetTop(SelectionRectangle, rect.Y); WpfCanvas.SetTop(SelectionRectangle, rect.Y);
SelectionRectangle.Width = rect.Width; SelectionRectangle.Width = rect.Width;
SelectionRectangle.Height = rect.Height; SelectionRectangle.Height = rect.Height;
// 确保选择矩形在调整模式下能够接收鼠标事件 // 确保选择矩形在调整模式下能够接收鼠标事件
if (_isAdjusting) if (_isAdjusting)
{ {
@@ -612,7 +612,7 @@ namespace Ink_Canvas
{ {
return; return;
} }
if (_isAdjusting) if (_isAdjusting)
{ {
// 转换为屏幕坐标,考虑DPI缩放 // 转换为屏幕坐标,考虑DPI缩放
@@ -733,7 +733,7 @@ namespace Ink_Canvas
_isMoving = true; _isMoving = true;
_activeControlPoint = ControlPointType.Move; _activeControlPoint = ControlPointType.Move;
_lastMousePosition = e.GetPosition(this); _lastMousePosition = e.GetPosition(this);
// 捕获鼠标到选择矩形 // 捕获鼠标到选择矩形
SelectionRectangle.CaptureMouse(); SelectionRectangle.CaptureMouse();
e.Handled = true; e.Handled = true;
@@ -793,12 +793,12 @@ namespace Ink_Canvas
_isAdjusting = false; _isAdjusting = false;
_isMoving = false; _isMoving = false;
_activeControlPoint = ControlPointType.None; _activeControlPoint = ControlPointType.None;
// 清除自由绘制的内容 // 清除自由绘制的内容
_freehandPoints.Clear(); _freehandPoints.Clear();
_freehandPolyline.Points.Clear(); _freehandPolyline.Points.Clear();
_freehandPolyline.Visibility = Visibility.Collapsed; _freehandPolyline.Visibility = Visibility.Collapsed;
// 清除矩形选择的内容 // 清除矩形选择的内容
SelectionRectangle.Visibility = Visibility.Collapsed; SelectionRectangle.Visibility = Visibility.Collapsed;
SelectionRectangle.IsHitTestVisible = false; SelectionRectangle.IsHitTestVisible = false;
@@ -806,23 +806,23 @@ namespace Ink_Canvas
SizeInfoBorder.Visibility = Visibility.Collapsed; SizeInfoBorder.Visibility = Visibility.Collapsed;
SelectionPath.Visibility = Visibility.Collapsed; SelectionPath.Visibility = Visibility.Collapsed;
AdjustModeHint.Visibility = Visibility.Collapsed; AdjustModeHint.Visibility = Visibility.Collapsed;
// 重置遮罩 // 重置遮罩
TransparentSelectionMask.Visibility = Visibility.Collapsed; TransparentSelectionMask.Visibility = Visibility.Collapsed;
OverlayRectangle.Visibility = Visibility.Visible; OverlayRectangle.Visibility = Visibility.Visible;
// 释放鼠标捕获 // 释放鼠标捕获
if (IsMouseCaptured) if (IsMouseCaptured)
{ {
ReleaseMouseCapture(); ReleaseMouseCapture();
} }
// 释放选择矩形的鼠标捕获 // 释放选择矩形的鼠标捕获
if (SelectionRectangle.IsMouseCaptured) if (SelectionRectangle.IsMouseCaptured)
{ {
SelectionRectangle.ReleaseMouseCapture(); SelectionRectangle.ReleaseMouseCapture();
} }
// 重置选择区域 // 重置选择区域
_currentSelection = new Rect(); _currentSelection = new Rect();
SelectedArea = null; SelectedArea = null;
@@ -1,4 +1,5 @@
using OSVersionExtension; using iNKORE.UI.WPF.Helpers;
using OSVersionExtension;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@@ -13,31 +14,38 @@ using System.Windows.Controls.Primitives;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using iNKORE.UI.WPF.Helpers;
namespace Ink_Canvas.Windows.SettingsViews { namespace Ink_Canvas.Windows.SettingsViews
{
/// <summary> /// <summary>
/// AboutPanel.xaml 的交互逻辑 /// AboutPanel.xaml 的交互逻辑
/// </summary> /// </summary>
public partial class AboutPanel : UserControl { public partial class AboutPanel : UserControl
public AboutPanel() { {
public AboutPanel()
{
InitializeComponent(); InitializeComponent();
// 关于页面图片横幅 // 关于页面图片横幅
if (File.Exists(App.RootPath + "icc-about-illustrations.png")) { if (File.Exists(App.RootPath + "icc-about-illustrations.png"))
try { {
try
{
CopyrightBannerImage.Visibility = Visibility.Visible; CopyrightBannerImage.Visibility = Visibility.Visible;
CopyrightBannerImage.Source = CopyrightBannerImage.Source =
new BitmapImage(new Uri($"file://{App.RootPath + "icc-about-illustrations.png"}")); new BitmapImage(new Uri($"file://{App.RootPath + "icc-about-illustrations.png"}"));
} }
catch { } catch { }
} else { }
else
{
CopyrightBannerImage.Visibility = Visibility.Collapsed; CopyrightBannerImage.Visibility = Visibility.Collapsed;
} }
// 关于页面构建时间 // 关于页面构建时间
var buildTime = FileBuildTimeHelper.GetBuildDateTime(Assembly.GetExecutingAssembly()); var buildTime = FileBuildTimeHelper.GetBuildDateTime(Assembly.GetExecutingAssembly());
if (buildTime != null) { if (buildTime != null)
{
var bt = ((DateTimeOffset)buildTime).LocalDateTime; var bt = ((DateTimeOffset)buildTime).LocalDateTime;
var m = bt.Month.ToString().PadLeft(2, '0'); var m = bt.Month.ToString().PadLeft(2, '0');
var d = bt.Day.ToString().PadLeft(2, '0'); var d = bt.Day.ToString().PadLeft(2, '0');
@@ -52,7 +60,8 @@ namespace Ink_Canvas.Windows.SettingsViews {
AboutSystemVersion.Text = $"{OSVersion.GetOperatingSystem()} {OSVersion.GetOSVersion().Version}"; AboutSystemVersion.Text = $"{OSVersion.GetOperatingSystem()} {OSVersion.GetOSVersion().Version}";
// 关于页面触摸设备 // 关于页面触摸设备
var _t_touch = new Thread(() => { var _t_touch = new Thread(() =>
{
var touchcount = TouchTabletDetectHelper.GetTouchTabletDevices().Count; var touchcount = TouchTabletDetectHelper.GetTouchTabletDevices().Count;
var support = TouchTabletDetectHelper.IsTouchEnabled(); var support = TouchTabletDetectHelper.IsTouchEnabled();
Dispatcher.BeginInvoke(() => Dispatcher.BeginInvoke(() =>
@@ -61,7 +70,8 @@ namespace Ink_Canvas.Windows.SettingsViews {
_t_touch.Start(); _t_touch.Start();
} }
public static class TouchTabletDetectHelper { public static class TouchTabletDetectHelper
{
[DllImport("user32.dll")] [DllImport("user32.dll")]
public static extern int GetSystemMetrics(int nIndex); public static extern int GetSystemMetrics(int nIndex);
@@ -92,9 +102,10 @@ namespace Ink_Canvas.Windows.SettingsViews {
ManagementObjectCollection collection; ManagementObjectCollection collection;
using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_PnPEntity")) using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_PnPEntity"))
collection = searcher.Get(); collection = searcher.Get();
foreach (var device in collection) { foreach (var device in collection)
{
var name = new StringBuilder((string)device.GetPropertyValue("Name")).ToString(); var name = new StringBuilder((string)device.GetPropertyValue("Name")).ToString();
if (!name.Contains("Pentablet")) continue; if (!name.Contains("Pentablet")) continue;
devices.Add(new USBDeviceInfo( devices.Add(new USBDeviceInfo(
@@ -109,7 +120,8 @@ namespace Ink_Canvas.Windows.SettingsViews {
} }
} }
public static class FileBuildTimeHelper { public static class FileBuildTimeHelper
{
public struct _IMAGE_FILE_HEADER public struct _IMAGE_FILE_HEADER
{ {
public ushort Machine; public ushort Machine;
@@ -146,46 +158,55 @@ namespace Ink_Canvas.Windows.SettingsViews {
pinnedBuffer.Free(); pinnedBuffer.Free();
} }
} }
else else
{ {
return null; return null;
} }
} }
} }
public event EventHandler<RoutedEventArgs> IsTopBarNeedShadowEffect; public event EventHandler<RoutedEventArgs> IsTopBarNeedShadowEffect;
public event EventHandler<RoutedEventArgs> IsTopBarNeedNoShadowEffect; public event EventHandler<RoutedEventArgs> IsTopBarNeedNoShadowEffect;
private void ScrollViewerEx_ScrollChanged(object sender, ScrollChangedEventArgs e) { private void ScrollViewerEx_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
var scrollViewer = (ScrollViewer)sender; var scrollViewer = (ScrollViewer)sender;
if (scrollViewer.VerticalOffset >= 10) { if (scrollViewer.VerticalOffset >= 10)
{
IsTopBarNeedShadowEffect?.Invoke(this, new RoutedEventArgs()); IsTopBarNeedShadowEffect?.Invoke(this, new RoutedEventArgs());
} else { }
else
{
IsTopBarNeedNoShadowEffect?.Invoke(this, new RoutedEventArgs()); IsTopBarNeedNoShadowEffect?.Invoke(this, new RoutedEventArgs());
} }
} }
private void ScrollBar_Scroll(object sender, RoutedEventArgs e) { private void ScrollBar_Scroll(object sender, RoutedEventArgs e)
{
var scrollbar = (ScrollBar)sender; var scrollbar = (ScrollBar)sender;
var scrollviewer = scrollbar.FindAscendant<ScrollViewer>(); var scrollviewer = scrollbar.FindAscendant<ScrollViewer>();
if (scrollviewer != null) scrollviewer.ScrollToVerticalOffset(scrollbar.Track.Value); if (scrollviewer != null) scrollviewer.ScrollToVerticalOffset(scrollbar.Track.Value);
} }
private void ScrollBarTrack_MouseEnter(object sender, MouseEventArgs e) { private void ScrollBarTrack_MouseEnter(object sender, MouseEventArgs e)
{
var border = (Border)sender; var border = (Border)sender;
if (border.Child is Track track) { if (border.Child is Track track)
{
track.Width = 16; track.Width = 16;
track.Margin = new Thickness(0, 0, -2, 0); track.Margin = new Thickness(0, 0, -2, 0);
var scrollbar = track.FindAscendant<ScrollBar>(); var scrollbar = track.FindAscendant<ScrollBar>();
if (scrollbar != null) scrollbar.Width = 16; if (scrollbar != null) scrollbar.Width = 16;
var grid = track.FindAscendant<Grid>(); var grid = track.FindAscendant<Grid>();
if (grid.FindDescendantByName("ScrollBarBorderTrackBackground") is Border backgroundBorder) { if (grid.FindDescendantByName("ScrollBarBorderTrackBackground") is Border backgroundBorder)
{
backgroundBorder.Width = 8; backgroundBorder.Width = 8;
backgroundBorder.CornerRadius = new CornerRadius(4); backgroundBorder.CornerRadius = new CornerRadius(4);
backgroundBorder.Opacity = 1; backgroundBorder.Opacity = 1;
} }
var thumb = track.Thumb.Template.FindName("ScrollbarThumbEx", track.Thumb) ; var thumb = track.Thumb.Template.FindName("ScrollbarThumbEx", track.Thumb);
if (thumb != null) { if (thumb != null)
{
var _thumb = thumb as Border; var _thumb = thumb as Border;
_thumb.CornerRadius = new CornerRadius(4); _thumb.CornerRadius = new CornerRadius(4);
_thumb.Width = 8; _thumb.Width = 8;
@@ -195,23 +216,27 @@ namespace Ink_Canvas.Windows.SettingsViews {
} }
} }
private void ScrollBarTrack_MouseLeave(object sender, MouseEventArgs e) { private void ScrollBarTrack_MouseLeave(object sender, MouseEventArgs e)
{
var border = (Border)sender; var border = (Border)sender;
border.Background = new SolidColorBrush(Colors.Transparent); border.Background = new SolidColorBrush(Colors.Transparent);
border.CornerRadius = new CornerRadius(0); border.CornerRadius = new CornerRadius(0);
if (border.Child is Track track) { if (border.Child is Track track)
{
track.Width = 6; track.Width = 6;
track.Margin = new Thickness(0, 0, 0, 0); track.Margin = new Thickness(0, 0, 0, 0);
var scrollbar = track.FindAscendant<ScrollBar>(); var scrollbar = track.FindAscendant<ScrollBar>();
if (scrollbar != null) scrollbar.Width = 6; if (scrollbar != null) scrollbar.Width = 6;
var grid = track.FindAscendant<Grid>(); var grid = track.FindAscendant<Grid>();
if (grid.FindDescendantByName("ScrollBarBorderTrackBackground") is Border backgroundBorder) { if (grid.FindDescendantByName("ScrollBarBorderTrackBackground") is Border backgroundBorder)
{
backgroundBorder.Width = 3; backgroundBorder.Width = 3;
backgroundBorder.CornerRadius = new CornerRadius(1.5); backgroundBorder.CornerRadius = new CornerRadius(1.5);
backgroundBorder.Opacity = 0; backgroundBorder.Opacity = 0;
} }
var thumb = track.Thumb.Template.FindName("ScrollbarThumbEx", track.Thumb) ; var thumb = track.Thumb.Template.FindName("ScrollbarThumbEx", track.Thumb);
if (thumb != null) { if (thumb != null)
{
var _thumb = thumb as Border; var _thumb = thumb as Border;
_thumb.CornerRadius = new CornerRadius(1.5); _thumb.CornerRadius = new CornerRadius(1.5);
_thumb.Width = 3; _thumb.Width = 3;
@@ -221,15 +246,17 @@ namespace Ink_Canvas.Windows.SettingsViews {
} }
} }
private void ScrollbarThumb_MouseDown(object sender, MouseButtonEventArgs e) { private void ScrollbarThumb_MouseDown(object sender, MouseButtonEventArgs e)
{
var thumb = (Thumb)sender; var thumb = (Thumb)sender;
var border = thumb.Template.FindName("ScrollbarThumbEx",thumb); var border = thumb.Template.FindName("ScrollbarThumbEx", thumb);
((Border)border).Background = new SolidColorBrush(Color.FromRgb(95, 95, 95)); ((Border)border).Background = new SolidColorBrush(Color.FromRgb(95, 95, 95));
} }
private void ScrollbarThumb_MouseUp(object sender, MouseButtonEventArgs e) { private void ScrollbarThumb_MouseUp(object sender, MouseButtonEventArgs e)
{
var thumb = (Thumb)sender; var thumb = (Thumb)sender;
var border = thumb.Template.FindName("ScrollbarThumbEx",thumb); var border = thumb.Template.FindName("ScrollbarThumbEx", thumb);
((Border)border).Background = new SolidColorBrush(Color.FromRgb(138, 138, 138)); ((Border)border).Background = new SolidColorBrush(Color.FromRgb(138, 138, 138));
} }
} }
@@ -2,11 +2,15 @@
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
namespace Ink_Canvas.Windows.SettingsViews { namespace Ink_Canvas.Windows.SettingsViews
public partial class AppearancePanel : UserControl { {
public AppearancePanel() { public partial class AppearancePanel : UserControl
{
public AppearancePanel()
{
InitializeComponent(); InitializeComponent();
BaseView.SettingsPanels.Add(new SettingsViewPanel() { BaseView.SettingsPanels.Add(new SettingsViewPanel()
{
Title = "新版设置测试", Title = "新版设置测试",
Items = new ObservableCollection<SettingsItem>(new SettingsItem[] { Items = new ObservableCollection<SettingsItem>(new SettingsItem[] {
new SettingsItem() { new SettingsItem() {
@@ -55,7 +59,8 @@ namespace Ink_Canvas.Windows.SettingsViews {
}, },
}) })
}); });
BaseView.SettingsPanels[0].Items[5].OnToggleSwitchToggled += (sender, args) => { BaseView.SettingsPanels[0].Items[5].OnToggleSwitchToggled += (sender, args) =>
{
var item = (SettingsItem)sender; var item = (SettingsItem)sender;
BaseView.SettingsPanels[0].Items[4].ToggleSwitchEnabled = item.ToggleSwitchToggled; BaseView.SettingsPanels[0].Items[4].ToggleSwitchEnabled = item.ToggleSwitchToggled;
}; };
@@ -1,93 +1,120 @@
using System.Collections.ObjectModel; using iNKORE.UI.WPF.DragDrop;
using System.Collections.ObjectModel;
using System.Diagnostics; using System.Diagnostics;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
using iNKORE.UI.WPF.DragDrop;
namespace Ink_Canvas.Windows.SettingsViews { namespace Ink_Canvas.Windows.SettingsViews
{
public class FloatingBarItem {
public class FloatingBarItem
{
public DrawingImage IconSource { get; set; } public DrawingImage IconSource { get; set; }
} }
public partial class FloatingBarDnDSettingsPanel : UserControl {
public class BarItemsDropTarget : IDropTarget { public partial class FloatingBarDnDSettingsPanel : UserControl
{
public class BarItemsDropTarget : IDropTarget
{
public ObservableCollection<FloatingBarItem> BarItems { get; set; } = public ObservableCollection<FloatingBarItem> BarItems { get; set; } =
new ObservableCollection<FloatingBarItem>(); new ObservableCollection<FloatingBarItem>();
void IDropTarget.DragOver(IDropInfo info) { void IDropTarget.DragOver(IDropInfo info)
{
info.Effects = DragDropEffects.Move; info.Effects = DragDropEffects.Move;
info.DropTargetAdorner = DropTargetAdorners.Insert; info.DropTargetAdorner = DropTargetAdorners.Insert;
} }
void IDropTarget.Drop(IDropInfo info) { void IDropTarget.Drop(IDropInfo info)
if (info.Data is FloatingBarItem draggedItem) { {
if (info.Data is FloatingBarItem draggedItem)
{
var targetCollection = info.TargetCollection as ObservableCollection<FloatingBarItem>; var targetCollection = info.TargetCollection as ObservableCollection<FloatingBarItem>;
var sourceCollection = info.DragInfo.SourceCollection as ObservableCollection<FloatingBarItem>; var sourceCollection = info.DragInfo.SourceCollection as ObservableCollection<FloatingBarItem>;
Trace.WriteLine(info.InsertIndex); Trace.WriteLine(info.InsertIndex);
// 在同一个 ObservableCollection 中移动 // 在同一个 ObservableCollection 中移动
if (targetCollection.Equals(sourceCollection)) { if (targetCollection.Equals(sourceCollection))
if (info.InsertIndex == 0) { {
targetCollection.Move(targetCollection.IndexOf(info.Data as FloatingBarItem),0); if (info.InsertIndex == 0)
} else if (info.InsertIndex == targetCollection.Count) { {
targetCollection.Move(targetCollection.IndexOf(info.Data as FloatingBarItem), 0);
}
else if (info.InsertIndex == targetCollection.Count)
{
targetCollection.Remove(info.Data as FloatingBarItem); targetCollection.Remove(info.Data as FloatingBarItem);
targetCollection.Add(info.Data as FloatingBarItem); targetCollection.Add(info.Data as FloatingBarItem);
} else if ((info.InsertIndex - targetCollection.IndexOf(info.Data as FloatingBarItem) == 1 &&
info.InsertPosition == RelativeInsertPosition.AfterTargetItem) ||
(info.InsertIndex - targetCollection.IndexOf(info.Data as FloatingBarItem) == 0 &&
info.InsertPosition == RelativeInsertPosition.BeforeTargetItem)) { } else {
targetCollection.Move(targetCollection.IndexOf(info.Data as FloatingBarItem),info.InsertIndex - 1);
} }
} else { // 跨 ObservableCollection 移动 else if ((info.InsertIndex - targetCollection.IndexOf(info.Data as FloatingBarItem) == 1 &&
info.InsertPosition == RelativeInsertPosition.AfterTargetItem) ||
(info.InsertIndex - targetCollection.IndexOf(info.Data as FloatingBarItem) == 0 &&
info.InsertPosition == RelativeInsertPosition.BeforeTargetItem)) { }
else
{
targetCollection.Move(targetCollection.IndexOf(info.Data as FloatingBarItem), info.InsertIndex - 1);
}
}
else
{ // 跨 ObservableCollection 移动
sourceCollection.Remove(info.Data as FloatingBarItem); sourceCollection.Remove(info.Data as FloatingBarItem);
targetCollection.Insert(info.InsertIndex, info.Data as FloatingBarItem); targetCollection.Insert(info.InsertIndex, info.Data as FloatingBarItem);
} }
} }
} }
void IDropTarget.DragEnter(IDropInfo info) { void IDropTarget.DragEnter(IDropInfo info)
{
} }
void IDropTarget.DragLeave(IDropInfo info) { void IDropTarget.DragLeave(IDropInfo info)
{
} }
} }
public class BarDrawerItemsDropTarget : IDropTarget { public class BarDrawerItemsDropTarget : IDropTarget
{
public ObservableCollection<FloatingBarItem> BarDrawerItems { get; set; } = public ObservableCollection<FloatingBarItem> BarDrawerItems { get; set; } =
new ObservableCollection<FloatingBarItem>(); new ObservableCollection<FloatingBarItem>();
void IDropTarget.DragOver(IDropInfo info) { void IDropTarget.DragOver(IDropInfo info)
{
info.Effects = DragDropEffects.Move; info.Effects = DragDropEffects.Move;
info.DropTargetAdorner = DropTargetAdorners.Insert; info.DropTargetAdorner = DropTargetAdorners.Insert;
} }
void IDropTarget.Drop(IDropInfo info) { void IDropTarget.Drop(IDropInfo info)
if (info.Data is FloatingBarItem draggedItem) { {
if (info.Data is FloatingBarItem draggedItem)
{
var targetCollection = info.TargetCollection as ObservableCollection<FloatingBarItem>; var targetCollection = info.TargetCollection as ObservableCollection<FloatingBarItem>;
var sourceCollection = info.DragInfo.SourceCollection as ObservableCollection<FloatingBarItem>; var sourceCollection = info.DragInfo.SourceCollection as ObservableCollection<FloatingBarItem>;
// 在同一个 ObservableCollection 中移动 // 在同一个 ObservableCollection 中移动
if (targetCollection.Equals(sourceCollection)) { if (targetCollection.Equals(sourceCollection))
{
targetCollection.Insert(info.InsertIndex, info.Data as FloatingBarItem); targetCollection.Insert(info.InsertIndex, info.Data as FloatingBarItem);
} else { // 跨 ObservableCollection 移动 }
else
{ // 跨 ObservableCollection 移动
sourceCollection.Remove(info.Data as FloatingBarItem); sourceCollection.Remove(info.Data as FloatingBarItem);
targetCollection.Insert(info.InsertIndex, info.Data as FloatingBarItem); targetCollection.Insert(info.InsertIndex, info.Data as FloatingBarItem);
} }
} }
} }
void IDropTarget.DragEnter(IDropInfo info) { void IDropTarget.DragEnter(IDropInfo info)
{
} }
void IDropTarget.DragLeave(IDropInfo info) { void IDropTarget.DragLeave(IDropInfo info)
{
} }
@@ -96,19 +123,23 @@ namespace Ink_Canvas.Windows.SettingsViews {
public BarItemsDropTarget barItems { get; set; } = new BarItemsDropTarget(); public BarItemsDropTarget barItems { get; set; } = new BarItemsDropTarget();
public BarDrawerItemsDropTarget barDrawerItems { get; set; } = new BarDrawerItemsDropTarget(); public BarDrawerItemsDropTarget barDrawerItems { get; set; } = new BarDrawerItemsDropTarget();
public FloatingBarDnDSettingsPanel() { public FloatingBarDnDSettingsPanel()
{
InitializeComponent(); InitializeComponent();
ToolbarItemsControl.DataContext = barItems; ToolbarItemsControl.DataContext = barItems;
ToolbarDrawerItemsControl.DataContext = barDrawerItems; ToolbarDrawerItemsControl.DataContext = barDrawerItems;
barItems.BarItems.Add(new FloatingBarItem() { barItems.BarItems.Add(new FloatingBarItem()
{
IconSource = FindResource("EraserIcon") as DrawingImage, IconSource = FindResource("EraserIcon") as DrawingImage,
}); });
barDrawerItems.BarDrawerItems.Add(new FloatingBarItem() { barDrawerItems.BarDrawerItems.Add(new FloatingBarItem()
{
IconSource = FindResource("CursorIcon") as DrawingImage, IconSource = FindResource("CursorIcon") as DrawingImage,
}); });
barDrawerItems.BarDrawerItems.Add(new FloatingBarItem() { barDrawerItems.BarDrawerItems.Add(new FloatingBarItem()
{
IconSource = FindResource("PenIcon") as DrawingImage, IconSource = FindResource("PenIcon") as DrawingImage,
}); });
} }
@@ -1,4 +1,6 @@
using System; using iNKORE.UI.WPF.Helpers;
using iNKORE.UI.WPF.Modern.Controls;
using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using System.Windows; using System.Windows;
@@ -6,12 +8,12 @@ using System.Windows.Controls;
using System.Windows.Controls.Primitives; using System.Windows.Controls.Primitives;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using iNKORE.UI.WPF.Helpers;
using iNKORE.UI.WPF.Modern.Controls;
namespace Ink_Canvas.Windows.SettingsViews { namespace Ink_Canvas.Windows.SettingsViews
{
public class SettingsViewPanel { public class SettingsViewPanel
{
public string Title { get; set; } public string Title { get; set; }
public Visibility _TitleVisibility => String.IsNullOrWhiteSpace(Title) ? Visibility.Collapsed : Visibility.Visible; public Visibility _TitleVisibility => String.IsNullOrWhiteSpace(Title) ? Visibility.Collapsed : Visibility.Visible;
public Thickness _PanelMargin => public Thickness _PanelMargin =>
@@ -19,14 +21,16 @@ namespace Ink_Canvas.Windows.SettingsViews {
public ObservableCollection<SettingsItem> Items { get; set; } = new ObservableCollection<SettingsItem>() { }; public ObservableCollection<SettingsItem> Items { get; set; } = new ObservableCollection<SettingsItem>() { };
} }
public enum SettingsItemType { public enum SettingsItemType
{
Plain, // 只显示Title和Description Plain, // 只显示Title和Description
SingleToggleSwtich, SingleToggleSwtich,
ToggleSwitchWithArrowButton, ToggleSwitchWithArrowButton,
SelectionButtons, SelectionButtons,
} }
public class SettingsItem : INotifyPropertyChanged { public class SettingsItem : INotifyPropertyChanged
{
public string Title { get; set; } public string Title { get; set; }
public string Description { get; set; } public string Description { get; set; }
public SettingsItemType Type { get; set; } = SettingsItemType.Plain; public SettingsItemType Type { get; set; } = SettingsItemType.Plain;
@@ -36,10 +40,13 @@ namespace Ink_Canvas.Windows.SettingsViews {
public Visibility _ToggleSwitchVisibility => public Visibility _ToggleSwitchVisibility =>
Type == SettingsItemType.SingleToggleSwtich || Type == SettingsItemType.ToggleSwitchWithArrowButton ? Visibility.Visible : Visibility.Collapsed; Type == SettingsItemType.SingleToggleSwtich || Type == SettingsItemType.ToggleSwitchWithArrowButton ? Visibility.Visible : Visibility.Collapsed;
private bool _toggleSwitchToggled; private bool _toggleSwitchToggled;
public bool ToggleSwitchToggled { public bool ToggleSwitchToggled
{
get => _toggleSwitchToggled; get => _toggleSwitchToggled;
set { set
if (_toggleSwitchToggled != value) { {
if (_toggleSwitchToggled != value)
{
_toggleSwitchToggled = value; _toggleSwitchToggled = value;
OnPropertyChanged(nameof(ToggleSwitchToggled)); // 通知绑定控件属性变化 OnPropertyChanged(nameof(ToggleSwitchToggled)); // 通知绑定控件属性变化
OnToggleSwitchToggled?.Invoke(this, EventArgs.Empty); // 触发事件 OnToggleSwitchToggled?.Invoke(this, EventArgs.Empty); // 触发事件
@@ -48,15 +55,19 @@ namespace Ink_Canvas.Windows.SettingsViews {
} }
public event EventHandler OnToggleSwitchToggled; public event EventHandler OnToggleSwitchToggled;
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName) { protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
} }
private SolidColorBrush _toggleSwitchBackground = new SolidColorBrush(Color.FromRgb(53, 132, 228)); private SolidColorBrush _toggleSwitchBackground = new SolidColorBrush(Color.FromRgb(53, 132, 228));
public SolidColorBrush ToggleSwitchBackground { public SolidColorBrush ToggleSwitchBackground
{
get => _toggleSwitchBackground; get => _toggleSwitchBackground;
set { set
if (_toggleSwitchBackground != value) { {
if (_toggleSwitchBackground != value)
{
_toggleSwitchBackground = value; _toggleSwitchBackground = value;
OnPropertyChanged(nameof(ToggleSwitchBackground)); // 通知绑定控件属性变化 OnPropertyChanged(nameof(ToggleSwitchBackground)); // 通知绑定控件属性变化
} }
@@ -64,19 +75,24 @@ namespace Ink_Canvas.Windows.SettingsViews {
} }
private bool _toggleSwitchEnabled = true; private bool _toggleSwitchEnabled = true;
public bool ToggleSwitchEnabled { public bool ToggleSwitchEnabled
{
get => _toggleSwitchEnabled; get => _toggleSwitchEnabled;
set { set
if (_toggleSwitchEnabled != value) { {
if (_toggleSwitchEnabled != value)
{
_toggleSwitchEnabled = value; _toggleSwitchEnabled = value;
OnPropertyChanged(nameof(ToggleSwitchEnabled)); // 通知绑定控件属性变化 OnPropertyChanged(nameof(ToggleSwitchEnabled)); // 通知绑定控件属性变化
} }
} }
} }
} }
public partial class SettingsBaseView : UserControl { public partial class SettingsBaseView : UserControl
public SettingsBaseView() { {
public SettingsBaseView()
{
InitializeComponent(); InitializeComponent();
SettingsViewBaseItemsControl.ItemsSource = SettingsPanels; SettingsViewBaseItemsControl.ItemsSource = SettingsPanels;
} }
@@ -84,39 +100,48 @@ namespace Ink_Canvas.Windows.SettingsViews {
public ObservableCollection<SettingsViewPanel> SettingsPanels { get; set; } = public ObservableCollection<SettingsViewPanel> SettingsPanels { get; set; } =
new ObservableCollection<SettingsViewPanel>() { }; new ObservableCollection<SettingsViewPanel>() { };
public event EventHandler<RoutedEventArgs> IsTopBarNeedShadowEffect; public event EventHandler<RoutedEventArgs> IsTopBarNeedShadowEffect;
public event EventHandler<RoutedEventArgs> IsTopBarNeedNoShadowEffect; public event EventHandler<RoutedEventArgs> IsTopBarNeedNoShadowEffect;
private void ScrollViewerEx_ScrollChanged(object sender, ScrollChangedEventArgs e) { private void ScrollViewerEx_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
var scrollViewer = (ScrollViewer)sender; var scrollViewer = (ScrollViewer)sender;
if (scrollViewer.VerticalOffset >= 10) { if (scrollViewer.VerticalOffset >= 10)
{
IsTopBarNeedShadowEffect?.Invoke(this, new RoutedEventArgs()); IsTopBarNeedShadowEffect?.Invoke(this, new RoutedEventArgs());
} else { }
else
{
IsTopBarNeedNoShadowEffect?.Invoke(this, new RoutedEventArgs()); IsTopBarNeedNoShadowEffect?.Invoke(this, new RoutedEventArgs());
} }
} }
private void ScrollBar_Scroll(object sender, RoutedEventArgs e) { private void ScrollBar_Scroll(object sender, RoutedEventArgs e)
{
var scrollbar = (ScrollBar)sender; var scrollbar = (ScrollBar)sender;
var scrollviewer = scrollbar.FindAscendant<ScrollViewer>(); var scrollviewer = scrollbar.FindAscendant<ScrollViewer>();
if (scrollviewer != null) scrollviewer.ScrollToVerticalOffset(scrollbar.Track.Value); if (scrollviewer != null) scrollviewer.ScrollToVerticalOffset(scrollbar.Track.Value);
} }
private void ScrollBarTrack_MouseEnter(object sender, MouseEventArgs e) { private void ScrollBarTrack_MouseEnter(object sender, MouseEventArgs e)
{
var border = (Border)sender; var border = (Border)sender;
if (border.Child is Track track) { if (border.Child is Track track)
{
track.Width = 16; track.Width = 16;
track.Margin = new Thickness(0, 0, -2, 0); track.Margin = new Thickness(0, 0, -2, 0);
var scrollbar = track.FindAscendant<ScrollBar>(); var scrollbar = track.FindAscendant<ScrollBar>();
if (scrollbar != null) scrollbar.Width = 16; if (scrollbar != null) scrollbar.Width = 16;
var grid = track.FindAscendant<Grid>(); var grid = track.FindAscendant<Grid>();
if (grid.FindDescendantByName("ScrollBarBorderTrackBackground") is Border backgroundBorder) { if (grid.FindDescendantByName("ScrollBarBorderTrackBackground") is Border backgroundBorder)
{
backgroundBorder.Width = 8; backgroundBorder.Width = 8;
backgroundBorder.CornerRadius = new CornerRadius(4); backgroundBorder.CornerRadius = new CornerRadius(4);
backgroundBorder.Opacity = 1; backgroundBorder.Opacity = 1;
} }
var thumb = track.Thumb.Template.FindName("ScrollbarThumbEx", track.Thumb) ; var thumb = track.Thumb.Template.FindName("ScrollbarThumbEx", track.Thumb);
if (thumb != null) { if (thumb != null)
{
var _thumb = thumb as Border; var _thumb = thumb as Border;
_thumb.CornerRadius = new CornerRadius(4); _thumb.CornerRadius = new CornerRadius(4);
_thumb.Width = 8; _thumb.Width = 8;
@@ -126,29 +151,34 @@ namespace Ink_Canvas.Windows.SettingsViews {
} }
} }
private void ToggleSwitch_OnToggled(object sender, RoutedEventArgs e) { private void ToggleSwitch_OnToggled(object sender, RoutedEventArgs e)
{
var toggleswitch = sender as ToggleSwitch; var toggleswitch = sender as ToggleSwitch;
var item = toggleswitch.Tag as SettingsItem; var item = toggleswitch.Tag as SettingsItem;
item.ToggleSwitchToggled = toggleswitch.IsOn; item.ToggleSwitchToggled = toggleswitch.IsOn;
} }
private void ScrollBarTrack_MouseLeave(object sender, MouseEventArgs e) { private void ScrollBarTrack_MouseLeave(object sender, MouseEventArgs e)
{
var border = (Border)sender; var border = (Border)sender;
border.Background = new SolidColorBrush(Colors.Transparent); border.Background = new SolidColorBrush(Colors.Transparent);
border.CornerRadius = new CornerRadius(0); border.CornerRadius = new CornerRadius(0);
if (border.Child is Track track) { if (border.Child is Track track)
{
track.Width = 6; track.Width = 6;
track.Margin = new Thickness(0, 0, 0, 0); track.Margin = new Thickness(0, 0, 0, 0);
var scrollbar = track.FindAscendant<ScrollBar>(); var scrollbar = track.FindAscendant<ScrollBar>();
if (scrollbar != null) scrollbar.Width = 6; if (scrollbar != null) scrollbar.Width = 6;
var grid = track.FindAscendant<Grid>(); var grid = track.FindAscendant<Grid>();
if (grid.FindDescendantByName("ScrollBarBorderTrackBackground") is Border backgroundBorder) { if (grid.FindDescendantByName("ScrollBarBorderTrackBackground") is Border backgroundBorder)
{
backgroundBorder.Width = 3; backgroundBorder.Width = 3;
backgroundBorder.CornerRadius = new CornerRadius(1.5); backgroundBorder.CornerRadius = new CornerRadius(1.5);
backgroundBorder.Opacity = 0; backgroundBorder.Opacity = 0;
} }
var thumb = track.Thumb.Template.FindName("ScrollbarThumbEx", track.Thumb) ; var thumb = track.Thumb.Template.FindName("ScrollbarThumbEx", track.Thumb);
if (thumb != null) { if (thumb != null)
{
var _thumb = thumb as Border; var _thumb = thumb as Border;
_thumb.CornerRadius = new CornerRadius(1.5); _thumb.CornerRadius = new CornerRadius(1.5);
_thumb.Width = 3; _thumb.Width = 3;
@@ -158,15 +188,17 @@ namespace Ink_Canvas.Windows.SettingsViews {
} }
} }
private void ScrollbarThumb_MouseDown(object sender, MouseButtonEventArgs e) { private void ScrollbarThumb_MouseDown(object sender, MouseButtonEventArgs e)
{
var thumb = (Thumb)sender; var thumb = (Thumb)sender;
var border = thumb.Template.FindName("ScrollbarThumbEx",thumb); var border = thumb.Template.FindName("ScrollbarThumbEx", thumb);
((Border)border).Background = new SolidColorBrush(Color.FromRgb(95, 95, 95)); ((Border)border).Background = new SolidColorBrush(Color.FromRgb(95, 95, 95));
} }
private void ScrollbarThumb_MouseUp(object sender, MouseButtonEventArgs e) { private void ScrollbarThumb_MouseUp(object sender, MouseButtonEventArgs e)
{
var thumb = (Thumb)sender; var thumb = (Thumb)sender;
var border = thumb.Template.FindName("ScrollbarThumbEx",thumb); var border = thumb.Template.FindName("ScrollbarThumbEx", thumb);
((Border)border).Background = new SolidColorBrush(Color.FromRgb(138, 138, 138)); ((Border)border).Background = new SolidColorBrush(Color.FromRgb(138, 138, 138));
} }
} }
@@ -1,4 +1,5 @@
using System; using iNKORE.UI.WPF.Helpers;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics; using System.Diagnostics;
@@ -8,72 +9,84 @@ using System.Windows.Controls.Primitives;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using iNKORE.UI.WPF.Helpers;
namespace Ink_Canvas.Windows { namespace Ink_Canvas.Windows
public partial class SettingsWindow : Window { {
public partial class SettingsWindow : Window
{
public SettingsWindow() { public SettingsWindow()
{
InitializeComponent(); InitializeComponent();
// 初始化侧边栏项目 // 初始化侧边栏项目
SidebarItemsControl.ItemsSource = SidebarItems; SidebarItemsControl.ItemsSource = SidebarItems;
SidebarItems.Add(new SidebarItem() { SidebarItems.Add(new SidebarItem()
{
Type = SidebarItemType.Item, Type = SidebarItemType.Item,
Title = "启动时行为", Title = "启动时行为",
Name = "StartupItem", Name = "StartupItem",
IconSource = FindResource("StartupIcon") as DrawingImage, IconSource = FindResource("StartupIcon") as DrawingImage,
Selected = false, Selected = false,
}); });
SidebarItems.Add(new SidebarItem() { SidebarItems.Add(new SidebarItem()
{
Type = SidebarItemType.Item, Type = SidebarItemType.Item,
Title = "画板和墨迹", Title = "画板和墨迹",
Name = "CanvasAndInkItem", Name = "CanvasAndInkItem",
IconSource = FindResource("CanvasAndInkIcon") as DrawingImage, IconSource = FindResource("CanvasAndInkIcon") as DrawingImage,
Selected = false, Selected = false,
}); });
SidebarItems.Add(new SidebarItem() { SidebarItems.Add(new SidebarItem()
{
Type = SidebarItemType.Item, Type = SidebarItemType.Item,
Title = "手势操作", Title = "手势操作",
Name = "GesturesItem", Name = "GesturesItem",
IconSource = FindResource("GesturesIcon") as DrawingImage, IconSource = FindResource("GesturesIcon") as DrawingImage,
Selected = false, Selected = false,
}); });
SidebarItems.Add(new SidebarItem() { SidebarItems.Add(new SidebarItem()
{
Type = SidebarItemType.Item, Type = SidebarItemType.Item,
Title = "墨迹纠正", Title = "墨迹纠正",
Name = "InkRecognitionItem", Name = "InkRecognitionItem",
IconSource = FindResource("InkRecognitionIcon") as DrawingImage, IconSource = FindResource("InkRecognitionIcon") as DrawingImage,
Selected = false, Selected = false,
}); });
SidebarItems.Add(new SidebarItem() { SidebarItems.Add(new SidebarItem()
{
Type = SidebarItemType.Separator Type = SidebarItemType.Separator
}); });
SidebarItems.Add(new SidebarItem() { SidebarItems.Add(new SidebarItem()
{
Type = SidebarItemType.Item, Type = SidebarItemType.Item,
Title = "个性化设置", Title = "个性化设置",
Name = "ThemeItem", Name = "ThemeItem",
IconSource = FindResource("AppearanceIcon") as DrawingImage, IconSource = FindResource("AppearanceIcon") as DrawingImage,
Selected = false, Selected = false,
}); });
SidebarItems.Add(new SidebarItem() { SidebarItems.Add(new SidebarItem()
{
Type = SidebarItemType.Item, Type = SidebarItemType.Item,
Title = "快捷键设置", Title = "快捷键设置",
Name = "ShortcutsItem", Name = "ShortcutsItem",
IconSource = FindResource("AppearanceIcon") as DrawingImage, IconSource = FindResource("AppearanceIcon") as DrawingImage,
Selected = false, Selected = false,
}); });
SidebarItems.Add(new SidebarItem() { SidebarItems.Add(new SidebarItem()
{
Type = SidebarItemType.Item, Type = SidebarItemType.Item,
Title = "崩溃处理", Title = "崩溃处理",
Name = "CrashActionItem", Name = "CrashActionItem",
IconSource = FindResource("AppearanceIcon") as DrawingImage, IconSource = FindResource("AppearanceIcon") as DrawingImage,
Selected = false, Selected = false,
}); });
SidebarItems.Add(new SidebarItem() { SidebarItems.Add(new SidebarItem()
{
Type = SidebarItemType.Separator Type = SidebarItemType.Separator
}); });
SidebarItems.Add(new SidebarItem() { SidebarItems.Add(new SidebarItem()
{
Type = SidebarItemType.Item, Type = SidebarItemType.Item,
Title = "PowerPoint 支持", Title = "PowerPoint 支持",
Name = "PowerPointItem", Name = "PowerPointItem",
@@ -81,48 +94,56 @@ namespace Ink_Canvas.Windows {
Selected = false, Selected = false,
}); });
SidebarItems.Add(new SidebarItem() { SidebarItems.Add(new SidebarItem()
{
Type = SidebarItemType.Item, Type = SidebarItemType.Item,
Title = "自动化行为", Title = "自动化行为",
Name = "AutomationItem", Name = "AutomationItem",
IconSource = FindResource("AutomationIcon") as DrawingImage, IconSource = FindResource("AutomationIcon") as DrawingImage,
Selected = false, Selected = false,
}); });
SidebarItems.Add(new SidebarItem() { SidebarItems.Add(new SidebarItem()
{
Type = SidebarItemType.Item, Type = SidebarItemType.Item,
Title = "随机点名", Title = "随机点名",
Name = "LuckyRandomItem", Name = "LuckyRandomItem",
IconSource = FindResource("LuckyRandomIcon") as DrawingImage, IconSource = FindResource("LuckyRandomIcon") as DrawingImage,
Selected = false, Selected = false,
}); });
SidebarItems.Add(new SidebarItem() { SidebarItems.Add(new SidebarItem()
{
Type = SidebarItemType.Separator Type = SidebarItemType.Separator
}); });
SidebarItems.Add(new SidebarItem() { SidebarItems.Add(new SidebarItem()
{
Type = SidebarItemType.Item, Type = SidebarItemType.Item,
Title = "存储空间", Title = "存储空间",
Name = "StorageItem", Name = "StorageItem",
IconSource = FindResource("StorageIcon") as DrawingImage, IconSource = FindResource("StorageIcon") as DrawingImage,
Selected = false, Selected = false,
}); });
SidebarItems.Add(new SidebarItem() { SidebarItems.Add(new SidebarItem()
{
Type = SidebarItemType.Item, Type = SidebarItemType.Item,
Title = "截图和屏幕捕捉", Title = "截图和屏幕捕捉",
Name = "SnapshotItem", Name = "SnapshotItem",
IconSource = FindResource("SnapshotIcon") as DrawingImage, IconSource = FindResource("SnapshotIcon") as DrawingImage,
Selected = false, Selected = false,
}); });
SidebarItems.Add(new SidebarItem() { SidebarItems.Add(new SidebarItem()
{
Type = SidebarItemType.Separator Type = SidebarItemType.Separator
}); });
SidebarItems.Add(new SidebarItem() { SidebarItems.Add(new SidebarItem()
{
Type = SidebarItemType.Item, Type = SidebarItemType.Item,
Title = "高级选项", Title = "高级选项",
Name = "AdvancedItem", Name = "AdvancedItem",
IconSource = FindResource("AdvancedIcon") as DrawingImage, IconSource = FindResource("AdvancedIcon") as DrawingImage,
Selected = false, Selected = false,
}); });
SidebarItems.Add(new SidebarItem() { SidebarItems.Add(new SidebarItem()
{
Type = SidebarItemType.Item, Type = SidebarItemType.Item,
Title = "关于 InkCanvasForClass", Title = "关于 InkCanvasForClass",
Name = "AboutItem", Name = "AboutItem",
@@ -202,32 +223,37 @@ namespace Ink_Canvas.Windows {
_selectedSidebarItemName = "CanvasAndInkItem"; _selectedSidebarItemName = "CanvasAndInkItem";
UpdateSidebarItemsSelection(); UpdateSidebarItemsSelection();
// 为自定义滑块控件添加触摸支持 // 为自定义滑块控件添加触摸支持
AddTouchSupportToCustomSliders(); AddTouchSupportToCustomSliders();
} }
public enum SidebarItemType { public enum SidebarItemType
{
Item, Item,
Separator Separator
} }
public class SidebarItem { public class SidebarItem
{
public SidebarItemType Type { get; set; } public SidebarItemType Type { get; set; }
public string Title { get; set; } public string Title { get; set; }
public string Name { get; set; } public string Name { get; set; }
public ImageSource IconSource { get; set; } public ImageSource IconSource { get; set; }
public bool Selected { get; set; } public bool Selected { get; set; }
public Visibility _spVisibility { public Visibility _spVisibility
{
get => Type == SidebarItemType.Separator ? Visibility.Visible : Visibility.Collapsed; get => Type == SidebarItemType.Separator ? Visibility.Visible : Visibility.Collapsed;
} }
public Visibility _siVisibility { public Visibility _siVisibility
{
get => Type == SidebarItemType.Item ? Visibility.Visible : Visibility.Collapsed; get => Type == SidebarItemType.Item ? Visibility.Visible : Visibility.Collapsed;
} }
public SolidColorBrush _siBackground { public SolidColorBrush _siBackground
{
get => Selected get => Selected
? new SolidColorBrush(Color.FromRgb(217, 217, 217)) ? new SolidColorBrush(Color.FromRgb(217, 217, 217))
: new SolidColorBrush(Colors.Transparent); : new SolidColorBrush(Colors.Transparent);
@@ -242,10 +268,13 @@ namespace Ink_Canvas.Windows {
public string[] SettingsPaneTitles; public string[] SettingsPaneTitles;
public string[] SettingsPaneNames; public string[] SettingsPaneNames;
public void UpdateSidebarItemsSelection() { public void UpdateSidebarItemsSelection()
foreach (var si in SidebarItems) { {
foreach (var si in SidebarItems)
{
si.Selected = si.Name == _selectedSidebarItemName; si.Selected = si.Name == _selectedSidebarItemName;
if (si.Selected && SettingsWindowTitle != null) { if (si.Selected && SettingsWindowTitle != null)
{
SettingsWindowTitle.Text = si.Title; SettingsWindowTitle.Text = si.Title;
} }
} }
@@ -265,45 +294,57 @@ namespace Ink_Canvas.Windows {
if (StoragePane != null) StoragePane.Visibility = _selectedSidebarItemName == "StorageItem" ? Visibility.Visible : Visibility.Collapsed; if (StoragePane != null) StoragePane.Visibility = _selectedSidebarItemName == "StorageItem" ? Visibility.Visible : Visibility.Collapsed;
if (SnapshotPane != null) SnapshotPane.Visibility = _selectedSidebarItemName == "SnapshotItem" ? Visibility.Visible : Visibility.Collapsed; if (SnapshotPane != null) SnapshotPane.Visibility = _selectedSidebarItemName == "SnapshotItem" ? Visibility.Visible : Visibility.Collapsed;
if (AdvancedPane != null) AdvancedPane.Visibility = _selectedSidebarItemName == "AdvancedItem" ? Visibility.Visible : Visibility.Collapsed; if (AdvancedPane != null) AdvancedPane.Visibility = _selectedSidebarItemName == "AdvancedItem" ? Visibility.Visible : Visibility.Collapsed;
if (SettingsPaneScrollViewers != null) { if (SettingsPaneScrollViewers != null)
foreach (var sv in SettingsPaneScrollViewers) { {
if (sv != null) { foreach (var sv in SettingsPaneScrollViewers)
{
if (sv != null)
{
sv.ScrollToTop(); sv.ScrollToTop();
} }
} }
} }
} }
private void ScrollViewerEx_ScrollChanged(object sender, ScrollChangedEventArgs e) { private void ScrollViewerEx_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
var scrollViewer = (ScrollViewer)sender; var scrollViewer = (ScrollViewer)sender;
if (scrollViewer.VerticalOffset >= 10) { if (scrollViewer.VerticalOffset >= 10)
{
DropShadowEffectTopBar.Opacity = 0.25; DropShadowEffectTopBar.Opacity = 0.25;
} else { }
else
{
DropShadowEffectTopBar.Opacity = 0; DropShadowEffectTopBar.Opacity = 0;
} }
} }
private void ScrollBar_Scroll(object sender, RoutedEventArgs e) { private void ScrollBar_Scroll(object sender, RoutedEventArgs e)
{
var scrollbar = (ScrollBar)sender; var scrollbar = (ScrollBar)sender;
var scrollviewer = scrollbar.FindAscendant<ScrollViewer>(); var scrollviewer = scrollbar.FindAscendant<ScrollViewer>();
if (scrollviewer != null) scrollviewer.ScrollToVerticalOffset(scrollbar.Track.Value); if (scrollviewer != null) scrollviewer.ScrollToVerticalOffset(scrollbar.Track.Value);
} }
private void ScrollBarTrack_MouseEnter(object sender, MouseEventArgs e) { private void ScrollBarTrack_MouseEnter(object sender, MouseEventArgs e)
{
var border = (Border)sender; var border = (Border)sender;
if (border.Child is Track track) { if (border.Child is Track track)
{
track.Width = 16; track.Width = 16;
track.Margin = new Thickness(0, 0, -2, 0); track.Margin = new Thickness(0, 0, -2, 0);
var scrollbar = track.FindAscendant<ScrollBar>(); var scrollbar = track.FindAscendant<ScrollBar>();
if (scrollbar != null) scrollbar.Width = 16; if (scrollbar != null) scrollbar.Width = 16;
var grid = track.FindAscendant<Grid>(); var grid = track.FindAscendant<Grid>();
if (grid.FindDescendantByName("ScrollBarBorderTrackBackground") is Border backgroundBorder) { if (grid.FindDescendantByName("ScrollBarBorderTrackBackground") is Border backgroundBorder)
{
backgroundBorder.Width = 8; backgroundBorder.Width = 8;
backgroundBorder.CornerRadius = new CornerRadius(4); backgroundBorder.CornerRadius = new CornerRadius(4);
backgroundBorder.Opacity = 1; backgroundBorder.Opacity = 1;
} }
var thumb = track.Thumb.Template.FindName("ScrollbarThumbEx", track.Thumb) ; var thumb = track.Thumb.Template.FindName("ScrollbarThumbEx", track.Thumb);
if (thumb != null) { if (thumb != null)
{
var _thumb = thumb as Border; var _thumb = thumb as Border;
_thumb.CornerRadius = new CornerRadius(4); _thumb.CornerRadius = new CornerRadius(4);
_thumb.Width = 8; _thumb.Width = 8;
@@ -313,23 +354,27 @@ namespace Ink_Canvas.Windows {
} }
} }
private void ScrollBarTrack_MouseLeave(object sender, MouseEventArgs e) { private void ScrollBarTrack_MouseLeave(object sender, MouseEventArgs e)
{
var border = (Border)sender; var border = (Border)sender;
border.Background = new SolidColorBrush(Colors.Transparent); border.Background = new SolidColorBrush(Colors.Transparent);
border.CornerRadius = new CornerRadius(0); border.CornerRadius = new CornerRadius(0);
if (border.Child is Track track) { if (border.Child is Track track)
{
track.Width = 6; track.Width = 6;
track.Margin = new Thickness(0, 0, 0, 0); track.Margin = new Thickness(0, 0, 0, 0);
var scrollbar = track.FindAscendant<ScrollBar>(); var scrollbar = track.FindAscendant<ScrollBar>();
if (scrollbar != null) scrollbar.Width = 6; if (scrollbar != null) scrollbar.Width = 6;
var grid = track.FindAscendant<Grid>(); var grid = track.FindAscendant<Grid>();
if (grid.FindDescendantByName("ScrollBarBorderTrackBackground") is Border backgroundBorder) { if (grid.FindDescendantByName("ScrollBarBorderTrackBackground") is Border backgroundBorder)
{
backgroundBorder.Width = 3; backgroundBorder.Width = 3;
backgroundBorder.CornerRadius = new CornerRadius(1.5); backgroundBorder.CornerRadius = new CornerRadius(1.5);
backgroundBorder.Opacity = 0; backgroundBorder.Opacity = 0;
} }
var thumb = track.Thumb.Template.FindName("ScrollbarThumbEx", track.Thumb) ; var thumb = track.Thumb.Template.FindName("ScrollbarThumbEx", track.Thumb);
if (thumb != null) { if (thumb != null)
{
var _thumb = thumb as Border; var _thumb = thumb as Border;
_thumb.CornerRadius = new CornerRadius(1.5); _thumb.CornerRadius = new CornerRadius(1.5);
_thumb.Width = 3; _thumb.Width = 3;
@@ -339,76 +384,90 @@ namespace Ink_Canvas.Windows {
} }
} }
private void ScrollbarThumb_MouseDown(object sender, MouseButtonEventArgs e) { private void ScrollbarThumb_MouseDown(object sender, MouseButtonEventArgs e)
{
var thumb = (Thumb)sender; var thumb = (Thumb)sender;
var border = thumb.Template.FindName("ScrollbarThumbEx",thumb); var border = thumb.Template.FindName("ScrollbarThumbEx", thumb);
((Border)border).Background = new SolidColorBrush(Color.FromRgb(95, 95, 95)); ((Border)border).Background = new SolidColorBrush(Color.FromRgb(95, 95, 95));
} }
private void ScrollbarThumb_MouseUp(object sender, MouseButtonEventArgs e) { private void ScrollbarThumb_MouseUp(object sender, MouseButtonEventArgs e)
{
var thumb = (Thumb)sender; var thumb = (Thumb)sender;
var border = thumb.Template.FindName("ScrollbarThumbEx",thumb); var border = thumb.Template.FindName("ScrollbarThumbEx", thumb);
((Border)border).Background = new SolidColorBrush(Color.FromRgb(138, 138, 138)); ((Border)border).Background = new SolidColorBrush(Color.FromRgb(138, 138, 138));
} }
private Border _sidebarItemMouseDownBorder = null; private Border _sidebarItemMouseDownBorder = null;
private void SidebarItem_MouseDown(object sender, MouseButtonEventArgs e) { private void SidebarItem_MouseDown(object sender, MouseButtonEventArgs e)
{
if (_sidebarItemMouseDownBorder != null || _sidebarItemMouseDownBorder == sender) return; if (_sidebarItemMouseDownBorder != null || _sidebarItemMouseDownBorder == sender) return;
_sidebarItemMouseDownBorder = (Border)sender; _sidebarItemMouseDownBorder = (Border)sender;
var bd = sender as Border; var bd = sender as Border;
if (bd.FindDescendantByName("MouseFeedbackBorder") is Border feedbackBd) feedbackBd.Opacity = 0.12; if (bd.FindDescendantByName("MouseFeedbackBorder") is Border feedbackBd) feedbackBd.Opacity = 0.12;
} }
private void SidebarItem_MouseUp(object sender, MouseButtonEventArgs e) { private void SidebarItem_MouseUp(object sender, MouseButtonEventArgs e)
{
if (_sidebarItemMouseDownBorder == null || _sidebarItemMouseDownBorder != sender) return; if (_sidebarItemMouseDownBorder == null || _sidebarItemMouseDownBorder != sender) return;
if (_sidebarItemMouseDownBorder.Tag is SidebarItem data) _selectedSidebarItemName = data.Name; if (_sidebarItemMouseDownBorder.Tag is SidebarItem data) _selectedSidebarItemName = data.Name;
SidebarItem_MouseLeave(sender, null); SidebarItem_MouseLeave(sender, null);
UpdateSidebarItemsSelection(); UpdateSidebarItemsSelection();
} }
private void SidebarItem_MouseLeave(object sender, MouseEventArgs e) { private void SidebarItem_MouseLeave(object sender, MouseEventArgs e)
{
if (_sidebarItemMouseDownBorder == null || _sidebarItemMouseDownBorder != sender) return; if (_sidebarItemMouseDownBorder == null || _sidebarItemMouseDownBorder != sender) return;
if (_sidebarItemMouseDownBorder.FindDescendantByName("MouseFeedbackBorder") is Border feedbackBd) feedbackBd.Opacity = 0; if (_sidebarItemMouseDownBorder.FindDescendantByName("MouseFeedbackBorder") is Border feedbackBd) feedbackBd.Opacity = 0;
_sidebarItemMouseDownBorder = null; _sidebarItemMouseDownBorder = null;
} }
private void CloseButton_Click(object sender, MouseButtonEventArgs e) { private void CloseButton_Click(object sender, MouseButtonEventArgs e)
{
Close(); Close();
} }
private void SearchButton_Click(object sender, MouseButtonEventArgs e) { private void SearchButton_Click(object sender, MouseButtonEventArgs e)
{
// 搜索功能 - 可以显示搜索框或搜索对话框 // 搜索功能 - 可以显示搜索框或搜索对话框
} }
private void MenuButton_Click(object sender, MouseButtonEventArgs e) { private void MenuButton_Click(object sender, MouseButtonEventArgs e)
{
// 菜单功能 - 可以显示上下文菜单或选项菜单 // 菜单功能 - 可以显示上下文菜单或选项菜单
} }
private void ToggleSwitch_Click(object sender, MouseButtonEventArgs e) { private void ToggleSwitch_Click(object sender, MouseButtonEventArgs e)
{
var border = sender as Border; var border = sender as Border;
if (border != null) { if (border != null)
{
// 切换开关状态 // 切换开关状态
bool isOn = border.Background.ToString() == "#FF3584E4"; bool isOn = border.Background.ToString() == "#FF3584E4";
border.Background = isOn ? new SolidColorBrush(Color.FromRgb(225, 225, 225)) : new SolidColorBrush(Color.FromRgb(53, 132, 228)); border.Background = isOn ? new SolidColorBrush(Color.FromRgb(225, 225, 225)) : new SolidColorBrush(Color.FromRgb(53, 132, 228));
// 切换内部圆点的位置 // 切换内部圆点的位置
var innerBorder = border.Child as Border; var innerBorder = border.Child as Border;
if (innerBorder != null) { if (innerBorder != null)
{
innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Left : HorizontalAlignment.Right; innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Left : HorizontalAlignment.Right;
} }
// 根据Tag处理不同的设置项 // 根据Tag处理不同的设置项
string tag = border.Tag?.ToString(); string tag = border.Tag?.ToString();
if (!string.IsNullOrEmpty(tag)) { if (!string.IsNullOrEmpty(tag))
{
HandleSettingChange(tag, !isOn); HandleSettingChange(tag, !isOn);
} }
} }
} }
private void HandleSettingChange(string settingName, bool value) { private void HandleSettingChange(string settingName, bool value)
{
// 根据设置名称处理不同的设置项 // 根据设置名称处理不同的设置项
switch (settingName) { switch (settingName)
{
case "UseObviousCursor": case "UseObviousCursor":
// 处理使用更加明显的画笔光标设置 // 处理使用更加明显的画笔光标设置
break; break;
@@ -496,18 +555,22 @@ namespace Ink_Canvas.Windows {
} }
} }
private void OptionButton_Click(object sender, MouseButtonEventArgs e) { private void OptionButton_Click(object sender, MouseButtonEventArgs e)
{
var border = sender as Border; var border = sender as Border;
if (border != null) { if (border != null)
{
string tag = border.Tag?.ToString(); string tag = border.Tag?.ToString();
if (!string.IsNullOrEmpty(tag)) { if (!string.IsNullOrEmpty(tag))
{
// 清除同组其他按钮的选中状态 // 清除同组其他按钮的选中状态
ClearOtherOptionsInGroup(border, tag); ClearOtherOptionsInGroup(border, tag);
// 设置当前按钮为选中状态 // 设置当前按钮为选中状态
border.Background = new SolidColorBrush(Color.FromRgb(225, 225, 225)); border.Background = new SolidColorBrush(Color.FromRgb(225, 225, 225));
var textBlock = border.Child as TextBlock; var textBlock = border.Child as TextBlock;
if (textBlock != null) { if (textBlock != null)
{
textBlock.FontWeight = FontWeights.Bold; textBlock.FontWeight = FontWeights.Bold;
} }
@@ -517,21 +580,27 @@ namespace Ink_Canvas.Windows {
} }
} }
private void ClearOtherOptionsInGroup(Border currentBorder, string currentTag) { private void ClearOtherOptionsInGroup(Border currentBorder, string currentTag)
{
// 获取当前按钮所在的父容器 // 获取当前按钮所在的父容器
var parent = currentBorder.Parent as StackPanel; var parent = currentBorder.Parent as StackPanel;
if (parent != null) { if (parent != null)
{
// 获取组名(Tag中下划线前的部分) // 获取组名(Tag中下划线前的部分)
string groupName = currentTag.Split('_')[0]; string groupName = currentTag.Split('_')[0];
// 清除同组其他按钮的选中状态 // 清除同组其他按钮的选中状态
foreach (var child in parent.Children) { foreach (var child in parent.Children)
if (child is Border border && border != currentBorder) { {
if (child is Border border && border != currentBorder)
{
string childTag = border.Tag?.ToString(); string childTag = border.Tag?.ToString();
if (!string.IsNullOrEmpty(childTag) && childTag.StartsWith(groupName + "_")) { if (!string.IsNullOrEmpty(childTag) && childTag.StartsWith(groupName + "_"))
{
border.Background = new SolidColorBrush(Colors.Transparent); border.Background = new SolidColorBrush(Colors.Transparent);
var textBlock = border.Child as TextBlock; var textBlock = border.Child as TextBlock;
if (textBlock != null) { if (textBlock != null)
{
textBlock.FontWeight = FontWeights.Normal; textBlock.FontWeight = FontWeights.Normal;
} }
} }
@@ -540,14 +609,17 @@ namespace Ink_Canvas.Windows {
} }
} }
private void HandleOptionChange(string optionTag) { private void HandleOptionChange(string optionTag)
{
// 根据选项标签处理不同的选项变化 // 根据选项标签处理不同的选项变化
string[] parts = optionTag.Split('_'); string[] parts = optionTag.Split('_');
if (parts.Length >= 2) { if (parts.Length >= 2)
{
string group = parts[0]; string group = parts[0];
string value = parts[1]; string value = parts[1];
switch (group) { switch (group)
{
case "EraserSize": case "EraserSize":
// 处理板擦橡皮大小设置 // 处理板擦橡皮大小设置
break; break;
@@ -620,7 +692,7 @@ namespace Ink_Canvas.Windows {
// 查找面板中的所有自定义滑块控件 // 查找面板中的所有自定义滑块控件
var customSliders = FindCustomSlidersInPanel(pane); var customSliders = FindCustomSlidersInPanel(pane);
foreach (var slider in customSliders) foreach (var slider in customSliders)
{ {
AddTouchSupportToCustomSlider(slider); AddTouchSupportToCustomSlider(slider);
@@ -635,11 +707,11 @@ namespace Ink_Canvas.Windows {
private List<CustomSliderInfo> FindCustomSlidersInPanel(DependencyObject panel) private List<CustomSliderInfo> FindCustomSlidersInPanel(DependencyObject panel)
{ {
var customSliders = new List<CustomSliderInfo>(); var customSliders = new List<CustomSliderInfo>();
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(panel); i++) for (int i = 0; i < VisualTreeHelper.GetChildrenCount(panel); i++)
{ {
var child = VisualTreeHelper.GetChild(panel, i); var child = VisualTreeHelper.GetChild(panel, i);
// 检查是否是自定义滑块控件(包含GnomeSliderThumb图片的Grid // 检查是否是自定义滑块控件(包含GnomeSliderThumb图片的Grid
if (child is Grid grid) if (child is Grid grid)
{ {
@@ -649,11 +721,11 @@ namespace Ink_Canvas.Windows {
customSliders.Add(customSlider); customSliders.Add(customSlider);
} }
} }
// 递归查找子元素 // 递归查找子元素
customSliders.AddRange(FindCustomSlidersInPanel(child)); customSliders.AddRange(FindCustomSlidersInPanel(child));
} }
return customSliders; return customSliders;
} }
@@ -668,7 +740,7 @@ namespace Ink_Canvas.Windows {
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(grid); i++) for (int i = 0; i < VisualTreeHelper.GetChildrenCount(grid); i++)
{ {
var child = VisualTreeHelper.GetChild(grid, i); var child = VisualTreeHelper.GetChild(grid, i);
if (child is Image image && image.Source != null) if (child is Image image && image.Source != null)
{ {
var sourceName = image.Source.ToString(); var sourceName = image.Source.ToString();
@@ -682,12 +754,12 @@ namespace Ink_Canvas.Windows {
TrackBorder = FindTrackBorderInGrid(grid), TrackBorder = FindTrackBorderInGrid(grid),
ValueBorder = FindValueBorderInGrid(grid) ValueBorder = FindValueBorderInGrid(grid)
}; };
return customSlider; return customSlider;
} }
} }
} }
return null; return null;
} }
@@ -701,7 +773,7 @@ namespace Ink_Canvas.Windows {
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(grid); i++) for (int i = 0; i < VisualTreeHelper.GetChildrenCount(grid); i++)
{ {
var child = VisualTreeHelper.GetChild(grid, i); var child = VisualTreeHelper.GetChild(grid, i);
if (child is Border border && border.Background != null) if (child is Border border && border.Background != null)
{ {
var brush = border.Background as SolidColorBrush; var brush = border.Background as SolidColorBrush;
@@ -711,7 +783,7 @@ namespace Ink_Canvas.Windows {
} }
} }
} }
return null; return null;
} }
@@ -725,7 +797,7 @@ namespace Ink_Canvas.Windows {
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(grid); i++) for (int i = 0; i < VisualTreeHelper.GetChildrenCount(grid); i++)
{ {
var child = VisualTreeHelper.GetChild(grid, i); var child = VisualTreeHelper.GetChild(grid, i);
if (child is Border border && border.Background != null) if (child is Border border && border.Background != null)
{ {
var brush = border.Background as SolidColorBrush; var brush = border.Background as SolidColorBrush;
@@ -735,7 +807,7 @@ namespace Ink_Canvas.Windows {
} }
} }
} }
return null; return null;
} }
@@ -881,7 +953,7 @@ namespace Ink_Canvas.Windows {
// 考虑拇指大小,计算有效轨道长度 // 考虑拇指大小,计算有效轨道长度
var thumbSize = 21; // 根据XAML中的Width="21" var thumbSize = 21; // 根据XAML中的Width="21"
var effectiveWidth = trackWidth - thumbSize; var effectiveWidth = trackWidth - thumbSize;
// 计算相对位置(0-1之间),考虑拇指大小 // 计算相对位置(0-1之间),考虑拇指大小
var adjustedX = position.X - thumbSize / 2; var adjustedX = position.X - thumbSize / 2;
var relativePosition = Math.Max(0, Math.Min(1, adjustedX / effectiveWidth)); var relativePosition = Math.Max(0, Math.Min(1, adjustedX / effectiveWidth));
@@ -903,7 +975,7 @@ namespace Ink_Canvas.Windows {
{ {
var valueWidth = relativePosition * trackWidth; var valueWidth = relativePosition * trackWidth;
customSlider.ValueBorder.Width = Math.Max(0, valueWidth); customSlider.ValueBorder.Width = Math.Max(0, valueWidth);
// 调整值显示Border的位置 // 调整值显示Border的位置
var valueMargin = customSlider.ValueBorder.Margin; var valueMargin = customSlider.ValueBorder.Margin;
customSlider.ValueBorder.Margin = new Thickness(0, valueMargin.Top, trackWidth - valueWidth, valueMargin.Bottom); customSlider.ValueBorder.Margin = new Thickness(0, valueMargin.Top, trackWidth - valueWidth, valueMargin.Bottom);