代码清理

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