@@ -16,6 +16,7 @@ using MessageBox = System.Windows.MessageBox;
|
||||
using Window = System.Windows.Window;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Net;
|
||||
|
||||
namespace Ink_Canvas
|
||||
{
|
||||
@@ -48,6 +49,9 @@ namespace Ink_Canvas
|
||||
|
||||
public App()
|
||||
{
|
||||
// 配置TLS协议以支持Windows 7
|
||||
ConfigureTlsForWindows7();
|
||||
|
||||
// 如果是看门狗子进程,直接进入看门狗主循环并终止主流程
|
||||
var args = Environment.GetCommandLineArgs();
|
||||
if (args.Length >= 2 && args[1] == "--watchdog")
|
||||
@@ -75,6 +79,41 @@ namespace Ink_Canvas
|
||||
this.Exit += App_Exit; // 注册退出事件
|
||||
}
|
||||
|
||||
// 新增:配置TLS协议以支持Windows 7
|
||||
private void ConfigureTlsForWindows7()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 检测操作系统版本
|
||||
var osVersion = Environment.OSVersion;
|
||||
bool isWindows7 = osVersion.Version.Major == 6 && osVersion.Version.Minor == 1;
|
||||
|
||||
if (isWindows7)
|
||||
{
|
||||
LogHelper.WriteLogToFile("检测到Windows 7系统,配置TLS协议支持", LogHelper.LogType.Info);
|
||||
|
||||
// 启用所有TLS版本以支持Windows 7
|
||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
|
||||
|
||||
// 配置ServicePointManager以支持Windows 7
|
||||
ServicePointManager.DefaultConnectionLimit = 10;
|
||||
ServicePointManager.Expect100Continue = false;
|
||||
ServicePointManager.UseNagleAlgorithm = false;
|
||||
|
||||
LogHelper.WriteLogToFile("TLS协议配置完成,已启用TLS 1.2/1.1/1.0支持", LogHelper.LogType.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 对于更新的Windows版本,不进行任何TLS配置,使用系统默认设置
|
||||
LogHelper.WriteLogToFile($"检测到Windows版本: {osVersion.VersionString},使用系统默认TLS配置", LogHelper.LogType.Info);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"配置TLS协议时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
// 新增:初始化崩溃监听器
|
||||
private void InitializeCrashListeners()
|
||||
{
|
||||
|
||||
@@ -49,5 +49,5 @@ using System.Windows;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.7.1.0")]
|
||||
[assembly: AssemblyFileVersion("1.7.1.0")]
|
||||
[assembly: AssemblyVersion("1.7.1.3")]
|
||||
[assembly: AssemblyFileVersion("1.7.1.3")]
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -71,7 +71,7 @@
|
||||
|
||||
<!-- 操作按钮 -->
|
||||
<StackPanel Grid.Row="1" Orientation="Horizontal" Margin="5">
|
||||
<Button x:Name="BtnAdd" Content="添加应用" Padding="10,5" Margin="0,5,5,5" Click="BtnAdd_Click"/>
|
||||
<Button x:Name="BtnAdd" Content="添加" Padding="10,5" Margin="0,5,5,5" Click="BtnAdd_Click"/>
|
||||
<Button x:Name="BtnEdit" Content="编辑" Padding="10,5" Margin="5" Click="BtnEdit_Click"/>
|
||||
<Button x:Name="BtnDelete" Content="删除" Padding="10,5" Margin="5" Click="BtnDelete_Click"/>
|
||||
</StackPanel>
|
||||
|
||||
@@ -88,34 +88,23 @@ namespace Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加应用按钮点击事件
|
||||
/// 添加按钮点击事件
|
||||
/// </summary>
|
||||
private void BtnAdd_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 弹出文件选择对话框
|
||||
OpenFileDialog dialog = new OpenFileDialog
|
||||
// 创建新的启动项
|
||||
LauncherItem item = new LauncherItem
|
||||
{
|
||||
Title = "选择应用程序",
|
||||
Filter = "应用程序 (*.exe)|*.exe|所有文件 (*.*)|*.*",
|
||||
Multiselect = false
|
||||
Name = "",
|
||||
Path = "",
|
||||
IsVisible = true,
|
||||
Position = -1 // 让插件管理器分配位置
|
||||
};
|
||||
|
||||
if (dialog.ShowDialog() == true)
|
||||
{
|
||||
// 创建新的启动项
|
||||
LauncherItem item = new LauncherItem
|
||||
{
|
||||
Name = System.IO.Path.GetFileNameWithoutExtension(dialog.FileName),
|
||||
Path = dialog.FileName,
|
||||
IsVisible = true,
|
||||
Position = -1 // 让插件管理器分配位置
|
||||
};
|
||||
|
||||
// 显示编辑对话框
|
||||
EditLauncherItem(item, true);
|
||||
}
|
||||
// 直接显示编辑对话框
|
||||
EditLauncherItem(item, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -217,7 +206,7 @@ namespace Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher
|
||||
// 创建简单的编辑窗口
|
||||
Window editWindow = new Window
|
||||
{
|
||||
Title = isNew ? "添加应用" : "编辑应用",
|
||||
Title = isNew ? "添加" : "编辑应用",
|
||||
Width = 400,
|
||||
Height = 200,
|
||||
WindowStartupLocation = WindowStartupLocation.CenterScreen,
|
||||
@@ -292,6 +281,17 @@ namespace Ink_Canvas.Helpers.Plugins.BuiltIn.SuperLauncher
|
||||
if (dialog.ShowDialog() == true)
|
||||
{
|
||||
pathTextBox.Text = dialog.FileName;
|
||||
|
||||
// 如果选择的是.exe文件,自动获取文件名填入名称字段
|
||||
if (System.IO.Path.GetExtension(dialog.FileName).ToLower() == ".exe")
|
||||
{
|
||||
string fileName = System.IO.Path.GetFileNameWithoutExtension(dialog.FileName);
|
||||
// 只有在名称字段为空或者是新建项目时才自动填入
|
||||
if (string.IsNullOrWhiteSpace(nameTextBox.Text) || isNew)
|
||||
{
|
||||
nameTextBox.Text = fileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Ink_Canvas.Helpers.Plugins.BuiltIn
|
||||
|
||||
public override string Description => "在浮动栏添加一个启动台按钮,可快速启动常用应用程序。";
|
||||
|
||||
public override Version Version => new Version(1, 0, 0);
|
||||
public override Version Version => new Version(1, 0, 1);
|
||||
|
||||
public override string Author => "ICC CE 团队";
|
||||
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ink_Canvas.Helpers.Plugins
|
||||
{
|
||||
/// <summary>
|
||||
/// ICCPP 插件适配器,用于加载和管理 .iccpp 格式的插件
|
||||
/// </summary>
|
||||
public class ICCPPPluginAdapter : PluginBase
|
||||
{
|
||||
private readonly byte[] _pluginData;
|
||||
private readonly string _pluginPath;
|
||||
private readonly string _pluginName;
|
||||
private readonly Version _pluginVersion;
|
||||
private bool _isInitialized = false;
|
||||
|
||||
/// <summary>
|
||||
/// 创建 ICCPP 插件适配器
|
||||
/// </summary>
|
||||
/// <param name="pluginPath">插件文件路径</param>
|
||||
/// <param name="pluginData">插件文件数据</param>
|
||||
public ICCPPPluginAdapter(string pluginPath, byte[] pluginData)
|
||||
{
|
||||
_pluginPath = pluginPath;
|
||||
_pluginData = pluginData;
|
||||
PluginPath = pluginPath;
|
||||
|
||||
// 从文件名获取插件名称
|
||||
_pluginName = Path.GetFileNameWithoutExtension(pluginPath);
|
||||
_pluginVersion = new Version(1, 0, 0); // 默认版本
|
||||
|
||||
// 尝试从插件数据中读取更多信息
|
||||
TryReadPluginMetadata();
|
||||
}
|
||||
|
||||
public ICCPPPluginAdapter()
|
||||
{
|
||||
_pluginPath = string.Empty;
|
||||
_pluginData = new byte[0];
|
||||
PluginPath = string.Empty;
|
||||
_pluginName = "ICCPPPlugin";
|
||||
_pluginVersion = new Version(1, 0, 0);
|
||||
// 可选:初始化其他字段
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试从插件数据中读取元数据
|
||||
/// </summary>
|
||||
private void TryReadPluginMetadata()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 这里可以根据 .iccpp 文件的实际格式解析元数据
|
||||
// 例如,如果文件有特定的头部结构,可以在这里解析
|
||||
|
||||
// 示例:如果前100字节包含元数据
|
||||
if (_pluginData.Length > 100)
|
||||
{
|
||||
// 解析元数据的代码...
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"解析插件 {_pluginName} 元数据时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
#region IPlugin 接口实现
|
||||
|
||||
/// <summary>
|
||||
/// 插件名称
|
||||
/// </summary>
|
||||
public override string Name => _pluginName;
|
||||
|
||||
/// <summary>
|
||||
/// 插件描述
|
||||
/// </summary>
|
||||
public override string Description => $"{_pluginName} (ICCPP 格式插件)";
|
||||
|
||||
/// <summary>
|
||||
/// 插件版本
|
||||
/// </summary>
|
||||
public override Version Version => _pluginVersion;
|
||||
|
||||
/// <summary>
|
||||
/// 插件作者
|
||||
/// </summary>
|
||||
public override string Author => "未知";
|
||||
|
||||
/// <summary>
|
||||
/// 是否为内置插件
|
||||
/// </summary>
|
||||
public override bool IsBuiltIn => false;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化插件
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
if (_isInitialized) return;
|
||||
|
||||
try
|
||||
{
|
||||
// 这里可以添加 .iccpp 插件的初始化逻辑
|
||||
// 例如,根据文件格式加载特定资源
|
||||
|
||||
LogHelper.WriteLogToFile($"ICCPP 插件 {Name} 已初始化", LogHelper.LogType.Info);
|
||||
_isInitialized = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"初始化 ICCPP 插件 {Name} 时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 启用插件
|
||||
/// </summary>
|
||||
public override void Enable()
|
||||
{
|
||||
if (IsEnabled) return;
|
||||
|
||||
try
|
||||
{
|
||||
// 这里可以添加 .iccpp 插件的启用逻辑
|
||||
// 例如,加载动态库、注册事件等
|
||||
|
||||
base.Enable(); // 设置启用状态并触发事件
|
||||
LogHelper.WriteLogToFile($"ICCPP 插件 {Name} 已启用", LogHelper.LogType.Info);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"启用 ICCPP 插件 {Name} 时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 禁用插件
|
||||
/// </summary>
|
||||
public override void Disable()
|
||||
{
|
||||
if (!IsEnabled) return;
|
||||
|
||||
try
|
||||
{
|
||||
// 这里可以添加 .iccpp 插件的禁用逻辑
|
||||
// 例如,卸载动态库、注销事件等
|
||||
|
||||
base.Disable(); // 设置禁用状态并触发事件
|
||||
LogHelper.WriteLogToFile($"ICCPP 插件 {Name} 已禁用", LogHelper.LogType.Info);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"禁用 ICCPP 插件 {Name} 时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理插件资源
|
||||
/// </summary>
|
||||
public override void Cleanup()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 这里可以添加 .iccpp 插件的清理逻辑
|
||||
// 例如,释放资源等
|
||||
|
||||
LogHelper.WriteLogToFile($"ICCPP 插件 {Name} 已清理资源", LogHelper.LogType.Info);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"清理 ICCPP 插件 {Name} 资源时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -195,8 +195,12 @@ namespace Ink_Canvas.Helpers.Plugins
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取所有插件文件
|
||||
var pluginFiles = Directory.GetFiles(PluginsDirectory, "*.iccpp", SearchOption.TopDirectoryOnly);
|
||||
// 获取所有插件文件(支持 .iccpp 和 .dll 格式)
|
||||
var pluginFiles = Directory.GetFiles(PluginsDirectory, "*.iccpp", SearchOption.TopDirectoryOnly)
|
||||
.Concat(Directory.GetFiles(PluginsDirectory, "*.dll", SearchOption.TopDirectoryOnly))
|
||||
.ToArray();
|
||||
|
||||
LogHelper.WriteLogToFile($"发现 {pluginFiles.Length} 个外部插件文件", LogHelper.LogType.Info);
|
||||
|
||||
foreach (var pluginFile in pluginFiles)
|
||||
{
|
||||
@@ -222,6 +226,14 @@ namespace Ink_Canvas.Helpers.Plugins
|
||||
string fileHash = CalculateFileHash(pluginPath);
|
||||
_pluginHashes[pluginPath] = fileHash;
|
||||
|
||||
// 检查文件扩展名
|
||||
string extension = Path.GetExtension(pluginPath).ToLowerInvariant();
|
||||
if (extension == ".iccpp")
|
||||
{
|
||||
// 创建 ICCPP 插件适配器
|
||||
return CreateICCPPPluginAdapter(pluginPath);
|
||||
}
|
||||
|
||||
// 加载插件程序集
|
||||
Assembly pluginAssembly = LoadPluginAssembly(pluginPath);
|
||||
if (pluginAssembly == null) return null;
|
||||
@@ -253,16 +265,48 @@ namespace Ink_Canvas.Helpers.Plugins
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"实例化插件 {pluginType.Name} 时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
LogHelper.WriteLogToFile($"实例化插件类型 {pluginType.Name} 时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
LogHelper.WriteLogToFile($"在程序集 {Path.GetFileName(pluginPath)} 中未找到有效的插件类型", LogHelper.LogType.Warning);
|
||||
return null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"加载插件 {Path.GetFileName(pluginPath)} 时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
LogHelper.WriteLogToFile($"加载外部插件 {Path.GetFileName(pluginPath)} 时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建 ICCPP 插件适配器
|
||||
/// </summary>
|
||||
/// <param name="pluginPath">插件文件路径</param>
|
||||
/// <returns>适配的插件实例</returns>
|
||||
private IPlugin CreateICCPPPluginAdapter(string pluginPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 读取插件文件内容
|
||||
byte[] pluginData = File.ReadAllBytes(pluginPath);
|
||||
|
||||
// 创建适配器插件实例
|
||||
var pluginAdapter = new ICCPPPluginAdapter(pluginPath, pluginData);
|
||||
|
||||
// 添加到插件列表
|
||||
Plugins.Add(pluginAdapter);
|
||||
|
||||
LogHelper.WriteLogToFile($"已创建 ICCPP 插件适配器: {pluginAdapter.Name} 来自 {Path.GetFileName(pluginPath)}",
|
||||
LogHelper.LogType.Info);
|
||||
|
||||
return pluginAdapter;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"创建 ICCPP 插件适配器时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -280,7 +324,7 @@ namespace Ink_Canvas.Helpers.Plugins
|
||||
return loadedAssembly;
|
||||
}
|
||||
|
||||
// 加载程序集
|
||||
// 直接加载程序集
|
||||
Assembly pluginAssembly = Assembly.LoadFrom(pluginPath);
|
||||
_loadedAssemblies[pluginPath] = pluginAssembly;
|
||||
|
||||
@@ -483,117 +527,63 @@ namespace Ink_Canvas.Helpers.Plugins
|
||||
{
|
||||
try
|
||||
{
|
||||
LogHelper.WriteLogToFile($"开始重载插件: {plugin.Name}", LogHelper.LogType.Info);
|
||||
|
||||
// 记录插件状态和信息
|
||||
bool wasEnabled = plugin.IsEnabled;
|
||||
string pluginPath = plugin.PluginPath;
|
||||
string pluginTypeName = plugin.GetType().FullName;
|
||||
|
||||
// 记录日志,方便排查问题
|
||||
LogHelper.WriteLogToFile($"重载前插件状态 - 类型: {pluginTypeName}, 状态: {(wasEnabled ? "启用" : "禁用")}", LogHelper.LogType.Info);
|
||||
|
||||
// 如果配置中有该插件的状态,记录配置中的状态
|
||||
if (PluginStates.TryGetValue(pluginTypeName, out bool currentConfigState))
|
||||
if (string.IsNullOrEmpty(pluginPath) || !File.Exists(pluginPath))
|
||||
{
|
||||
LogHelper.WriteLogToFile($"配置中插件状态: {(currentConfigState ? "启用" : "禁用")}", LogHelper.LogType.Info);
|
||||
LogHelper.WriteLogToFile($"无法重新加载插件 {plugin.Name}: 插件文件不存在", LogHelper.LogType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
// 卸载插件,但不从PluginStates中移除状态信息
|
||||
UnloadPlugin(plugin);
|
||||
LogHelper.WriteLogToFile($"开始热重载插件: {plugin.Name} ({Path.GetFileName(pluginPath)})", LogHelper.LogType.Info);
|
||||
|
||||
// 清除程序集缓存,确保加载最新版本
|
||||
_loadedAssemblies.Remove(pluginPath);
|
||||
// 保存插件的当前状态
|
||||
bool wasEnabled = plugin.IsEnabled;
|
||||
string pluginTypeName = plugin.GetType().FullName;
|
||||
|
||||
// 卸载插件
|
||||
UnloadPlugin(plugin, false);
|
||||
|
||||
// 从加载缓存中移除
|
||||
if (_loadedAssemblies.ContainsKey(pluginPath))
|
||||
{
|
||||
_loadedAssemblies.Remove(pluginPath);
|
||||
}
|
||||
|
||||
// 计算新的文件哈希
|
||||
string newHash = CalculateFileHash(pluginPath);
|
||||
_pluginHashes[pluginPath] = newHash;
|
||||
|
||||
// 重新加载插件
|
||||
IPlugin newPlugin = LoadExternalPlugin(pluginPath);
|
||||
|
||||
if (newPlugin != null)
|
||||
{
|
||||
// 更新配置中的插件状态
|
||||
string newPluginTypeName = newPlugin.GetType().FullName;
|
||||
// 恢复插件状态
|
||||
if (wasEnabled)
|
||||
{
|
||||
newPlugin.Enable();
|
||||
}
|
||||
|
||||
// 如果插件类型名称变化,需要更新配置
|
||||
if (newPluginTypeName != pluginTypeName && PluginStates.ContainsKey(pluginTypeName))
|
||||
// 更新配置(如果类型名称变化)
|
||||
string newPluginTypeName = newPlugin.GetType().FullName;
|
||||
if (pluginTypeName != newPluginTypeName && PluginStates.ContainsKey(pluginTypeName))
|
||||
{
|
||||
bool state = PluginStates[pluginTypeName];
|
||||
PluginStates.Remove(pluginTypeName);
|
||||
PluginStates[newPluginTypeName] = state;
|
||||
LogHelper.WriteLogToFile($"插件类型名称已变更: {pluginTypeName} -> {newPluginTypeName}, 已更新配置", LogHelper.LogType.Info);
|
||||
_configDirty = true;
|
||||
SaveConfig();
|
||||
}
|
||||
|
||||
// 应用正确的状态
|
||||
bool shouldBeEnabled = false;
|
||||
if (PluginStates.TryGetValue(newPluginTypeName, out bool storedConfigState))
|
||||
{
|
||||
shouldBeEnabled = storedConfigState;
|
||||
LogHelper.WriteLogToFile($"从配置获取插件状态: {(shouldBeEnabled ? "启用" : "禁用")}", LogHelper.LogType.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
shouldBeEnabled = wasEnabled;
|
||||
PluginStates[newPluginTypeName] = shouldBeEnabled;
|
||||
LogHelper.WriteLogToFile($"使用之前的状态: {(shouldBeEnabled ? "启用" : "禁用")}", LogHelper.LogType.Info);
|
||||
}
|
||||
LogHelper.WriteLogToFile($"插件 {newPlugin.Name} v{newPlugin.Version} 热重载成功", LogHelper.LogType.Info);
|
||||
|
||||
// 获取重载后的实际状态
|
||||
bool currentState = newPlugin is PluginBase pluginBaseState && pluginBaseState.IsEnabled;
|
||||
LogHelper.WriteLogToFile($"重载后实际状态: {(currentState ? "启用" : "禁用")}", LogHelper.LogType.Info);
|
||||
|
||||
// 根据应该启用的状态启用或禁用插件
|
||||
if (shouldBeEnabled != currentState)
|
||||
{
|
||||
if (shouldBeEnabled)
|
||||
{
|
||||
newPlugin.Enable();
|
||||
LogHelper.WriteLogToFile($"插件 {newPlugin.Name} 已重载并启用", LogHelper.LogType.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
newPlugin.Disable();
|
||||
LogHelper.WriteLogToFile($"插件 {newPlugin.Name} 已重载并禁用", LogHelper.LogType.Info);
|
||||
}
|
||||
|
||||
// 检查状态是否正确应用
|
||||
currentState = newPlugin is PluginBase reloadedBase && reloadedBase.IsEnabled;
|
||||
LogHelper.WriteLogToFile($"应用状态后实际状态: {(currentState ? "启用" : "禁用")}", LogHelper.LogType.Info);
|
||||
|
||||
if (currentState != shouldBeEnabled)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"警告: 插件状态应用失败,目标状态: {(shouldBeEnabled ? "启用" : "禁用")}, 实际状态: {(currentState ? "启用" : "禁用")}", LogHelper.LogType.Warning);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogHelper.WriteLogToFile($"插件 {newPlugin.Name} 已重载并保持{(shouldBeEnabled ? "启用" : "禁用")}状态", LogHelper.LogType.Info);
|
||||
}
|
||||
|
||||
// 保存插件设置
|
||||
if (newPlugin is PluginBase pluginBaseInstance)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 保存插件设置(与启用状态无关)
|
||||
pluginBaseInstance.SavePluginSettings();
|
||||
LogHelper.WriteLogToFile($"已保存插件 {newPlugin.Name} 设置", LogHelper.LogType.Info);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"保存插件 {newPlugin.Name} 设置时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
// 立即保存配置
|
||||
LogHelper.WriteLogToFile($"重载后保存插件配置...", LogHelper.LogType.Info);
|
||||
SaveConfig();
|
||||
// 通知UI刷新
|
||||
NotifyUIRefresh();
|
||||
}
|
||||
else
|
||||
{
|
||||
LogHelper.WriteLogToFile($"插件 {plugin.Name} 重载失败: 无法加载新插件", LogHelper.LogType.Error);
|
||||
LogHelper.WriteLogToFile($"插件 {plugin.Name} 热重载失败", LogHelper.LogType.Error);
|
||||
}
|
||||
|
||||
// 更新UI
|
||||
NotifyUIRefresh();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -605,11 +595,14 @@ namespace Ink_Canvas.Helpers.Plugins
|
||||
/// 卸载插件
|
||||
/// </summary>
|
||||
/// <param name="plugin">要卸载的插件</param>
|
||||
/// <param name="removeFromConfig">是否从配置中移除插件状态(默认为false)</param>
|
||||
/// <param name="removeFromConfig">是否从配置中移除</param>
|
||||
public void UnloadPlugin(IPlugin plugin, bool removeFromConfig = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 保存插件名称,以便在卸载后使用
|
||||
string pluginName = plugin.Name;
|
||||
|
||||
// 如果插件已启用,先禁用它
|
||||
if (plugin is PluginBase pluginBase && pluginBase.IsEnabled)
|
||||
{
|
||||
@@ -633,11 +626,11 @@ namespace Ink_Canvas.Helpers.Plugins
|
||||
}
|
||||
}
|
||||
|
||||
LogHelper.WriteLogToFile($"已卸载插件: {plugin.Name}", LogHelper.LogType.Info);
|
||||
LogHelper.WriteLogToFile($"已卸载插件: {pluginName}", LogHelper.LogType.Info);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"卸载插件 {plugin.Name} 时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
LogHelper.WriteLogToFile($"卸载插件时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -656,6 +649,9 @@ namespace Ink_Canvas.Helpers.Plugins
|
||||
return false;
|
||||
}
|
||||
|
||||
// 保存插件名称,以便在删除后使用
|
||||
string pluginName = plugin.Name;
|
||||
|
||||
// 获取插件路径
|
||||
string pluginPath = null;
|
||||
if (plugin is PluginBase pluginBase)
|
||||
@@ -681,12 +677,12 @@ namespace Ink_Canvas.Helpers.Plugins
|
||||
// 保存配置
|
||||
SaveConfig();
|
||||
|
||||
LogHelper.WriteLogToFile($"已删除插件: {plugin.Name}", LogHelper.LogType.Info);
|
||||
LogHelper.WriteLogToFile($"已删除插件: {pluginName}", LogHelper.LogType.Info);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"删除插件 {plugin.Name} 时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
LogHelper.WriteLogToFile($"删除插件时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,6 +132,8 @@
|
||||
<Reference Include="WindowsBase" />
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.IO.Compression.FileSystem" />
|
||||
<Reference Include="WindowsFormsIntegration" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -134,6 +134,7 @@
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="NHotkey.Wpf" Version="3.0.0" />
|
||||
<PackageReference Include="OSVersionExt" Version="3.0.0" />
|
||||
<PackageReference Include="System.IO.Compression" Version="4.3.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<COMReference Include="IWshRuntimeLibrary">
|
||||
@@ -405,6 +406,7 @@
|
||||
<ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Data.dll" />
|
||||
<ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.dll" />
|
||||
<ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Drawing.dll" />
|
||||
<ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.IO.Compression.dll" />
|
||||
<ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.IO.Compression.FileSystem.dll" />
|
||||
<ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Net.Http.dll" />
|
||||
<ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Numerics.dll" />
|
||||
|
||||
@@ -33,7 +33,13 @@
|
||||
Stylus.IsTouchFeedbackEnabled="False">
|
||||
<!--资源中添加命令-->
|
||||
<Window.Resources>
|
||||
<c:IsEnabledToOpacityConverter x:Key="IsEnabledToOpacityConverter" />
|
||||
<ResourceDictionary>
|
||||
<!-- 合并新橡皮擦资源 -->
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="MainWindow_cs/MW_Eraser.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<c:IsEnabledToOpacityConverter x:Key="IsEnabledToOpacityConverter" />
|
||||
<c:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
|
||||
<c:IntNumberToString x:Key="IntNumberToString" />
|
||||
<c:IntNumberToString2 x:Key="IntNumberToString2" />
|
||||
@@ -121,6 +127,7 @@
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
<!--输入命令绑定-->
|
||||
<Window.InputBindings>
|
||||
@@ -1877,6 +1884,29 @@
|
||||
</ui:SimpleStackPanel>
|
||||
<TextBlock TextWrapping="Wrap" Foreground="#a1a1aa"
|
||||
Text="# 当检测到系统分辨率变化时,会尝试检测FloatingBar是否在屏幕内显示,如果不在屏幕内显示将会尝试移动到屏幕内可见区域(分辨率调小可能会触发,如果在屏幕内不会自动调整位置,请手动挡)。" />
|
||||
|
||||
<!-- 添加备份相关按钮 -->
|
||||
<Line HorizontalAlignment="Center" X1="0" Y1="0" X2="400" Y2="0" Stroke="#3f3f46"
|
||||
StrokeThickness="1" Margin="0,4,0,4" />
|
||||
<TextBlock Text="设置备份与还原" FontWeight="Bold" Foreground="#fafafa"
|
||||
FontSize="16" Margin="0,5,0,5" />
|
||||
<TextBlock TextWrapping="Wrap" Foreground="#a1a1aa"
|
||||
Text="# 可手动备份当前设置或还原之前的备份,自动更新前也会自动备份" />
|
||||
|
||||
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left">
|
||||
<TextBlock Foreground="#fafafa" Text="自动更新前备份" VerticalAlignment="Center"
|
||||
FontSize="14" Margin="0,0,16,0" />
|
||||
<ui:ToggleSwitch OnContent="" OffContent="" Name="ToggleSwitchIsAutoBackupBeforeUpdate"
|
||||
IsOn="True" FontFamily="Microsoft YaHei UI" FontWeight="Bold"
|
||||
Toggled="ToggleSwitchIsAutoBackupBeforeUpdate_Toggled" />
|
||||
</ui:SimpleStackPanel>
|
||||
|
||||
<ui:SimpleStackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,5,0,0">
|
||||
<Button x:Name="BtnManualBackup" Content="手动备份" Click="BtnManualBackup_Click"
|
||||
Background="#2563eb" Foreground="White" Padding="12,6" Margin="0,0,12,0" />
|
||||
<Button x:Name="BtnRestoreBackup" Content="还原备份" Click="BtnRestoreBackup_Click"
|
||||
Background="#2563eb" Foreground="White" Padding="12,6" />
|
||||
</ui:SimpleStackPanel>
|
||||
</ui:SimpleStackPanel>
|
||||
</GroupBox>
|
||||
<GroupBox>
|
||||
@@ -2293,7 +2323,7 @@
|
||||
FontFamily="Microsoft YaHei UI" FontWeight="Bold"
|
||||
Toggled="ToggleSwitchSaveFullPageStrokes_Toggled" />
|
||||
</ui:SimpleStackPanel>
|
||||
<TextBlock Text="# 开启后自动保存和手动保存墨迹时将以全屏模式保存而非单独保存每条墨迹" TextWrapping="Wrap" Foreground="#a1a1aa" />
|
||||
<TextBlock Text="# 开启后自动保存和手动保存墨迹时将以全屏模式保存。如果存在多个画布和墨迹,将把所有页面的墨迹按照每页为单位保存进一个压缩包中(注意,白板的墨迹只能在白板模式下打开,PPT的墨迹只能在PPT放映模式下打开)" TextWrapping="Wrap" Foreground="#a1a1aa" />
|
||||
|
||||
<Line HorizontalAlignment="Center" X1="0" Y1="0" X2="400" Y2="0" Stroke="#3f3f46"
|
||||
StrokeThickness="1" Margin="0,4,0,4" />
|
||||
@@ -2846,7 +2876,7 @@
|
||||
<Label Name="Label" Visibility="Collapsed" Foreground="Gray" Content="0" />
|
||||
<Grid Name="InkCanvasGridForInkReplay">
|
||||
<InkCanvas x:Name="inkCanvas" ForceCursor="True" UseCustomCursor="True"
|
||||
TouchUp="Main_Grid_TouchUp" TouchDown="Main_Grid_TouchDown"
|
||||
TouchDown="Main_Grid_TouchDown"
|
||||
TouchMove="inkCanvas_TouchMove"
|
||||
ManipulationDelta="Main_Grid_ManipulationDelta"
|
||||
ManipulationCompleted="Main_Grid_ManipulationCompleted"
|
||||
@@ -2861,6 +2891,13 @@
|
||||
ManipulationStarting="inkCanvas_ManipulationStarting"
|
||||
SelectionChanged="inkCanvas_SelectionChanged"
|
||||
StrokeCollected="inkCanvas_StrokeCollected" ClipToBounds="False" Background="Transparent" />
|
||||
|
||||
<!-- 新橡皮擦覆盖层 - 用于高级橡皮擦系统 -->
|
||||
<Border x:Name="AdvancedEraserOverlay"
|
||||
Background="Transparent"
|
||||
IsHitTestVisible="False"
|
||||
Loaded="EraserOverlay_Loaded"
|
||||
Panel.ZIndex="1000" />
|
||||
</Grid>
|
||||
|
||||
<Canvas IsHitTestVisible="False">
|
||||
@@ -5707,7 +5744,7 @@
|
||||
</Viewbox>
|
||||
|
||||
<Grid Name="FloatingbarUIForInkReplay">
|
||||
<Viewbox Name="ViewboxFloatingBar" Margin="100,5,0,0"
|
||||
<Viewbox Name="ViewboxFloatingBar" Margin="100,5,0,0" Cursor="Arrow"
|
||||
HorizontalAlignment="Left" Height="58" VerticalAlignment="Top" Width="733"
|
||||
RenderTransformOrigin="0.5,0.5">
|
||||
<Viewbox.LayoutTransform>
|
||||
@@ -5736,7 +5773,7 @@
|
||||
</Canvas>
|
||||
</Border>
|
||||
</Canvas>
|
||||
<ui:SimpleStackPanel Margin="2,0" Name="StackPanelFloatingBar" Orientation="Horizontal">
|
||||
<ui:SimpleStackPanel Margin="2,0" Name="StackPanelFloatingBar" Orientation="Horizontal" Cursor="Arrow">
|
||||
<!--<ui:SimpleStackPanel Name="Cursor_Icon" MouseDown="Border_MouseDown" MouseUp="CursorIcon_Click"-->
|
||||
<ui:SimpleStackPanel Name="Cursor_Icon"
|
||||
MouseDown="FloatingBarToolBtnMouseDownFeedback_Panel"
|
||||
|
||||
+167
-40
@@ -24,9 +24,16 @@ using System.Windows.Media.Animation;
|
||||
using System.Reflection;
|
||||
using Brushes = System.Windows.Media.Brushes;
|
||||
using Point = System.Windows.Point;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ink_Canvas {
|
||||
public partial class MainWindow : Window {
|
||||
// 新增:每一页一个Canvas对象
|
||||
private List<System.Windows.Controls.Canvas> whiteboardPages = new List<System.Windows.Controls.Canvas>();
|
||||
private int currentPageIndex = 0;
|
||||
private System.Windows.Controls.Canvas currentCanvas = null;
|
||||
private AutoUpdateHelper.UpdateLineGroup AvailableLatestLineGroup = null;
|
||||
|
||||
#region Window Initialization
|
||||
|
||||
public MainWindow() {
|
||||
@@ -109,8 +116,13 @@ namespace Ink_Canvas {
|
||||
// 注册输入事件
|
||||
inkCanvas.PreviewMouseDown += inkCanvas_PreviewMouseDown;
|
||||
inkCanvas.StylusDown += inkCanvas_StylusDown;
|
||||
inkCanvas.TouchDown += inkCanvas_TouchDown;
|
||||
inkCanvas.TouchUp += inkCanvas_TouchUp;
|
||||
|
||||
// 初始化第一页Canvas
|
||||
var firstCanvas = new System.Windows.Controls.Canvas();
|
||||
whiteboardPages.Add(firstCanvas);
|
||||
InkCanvasGridForInkReplay.Children.Add(firstCanvas);
|
||||
currentPageIndex = 0;
|
||||
ShowPage(currentPageIndex);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -160,11 +172,42 @@ namespace Ink_Canvas {
|
||||
private void inkCanvas_EditingModeChanged(object sender, RoutedEventArgs e) {
|
||||
var inkCanvas1 = sender as InkCanvas;
|
||||
if (inkCanvas1 == null) return;
|
||||
|
||||
|
||||
// 使用辅助方法设置光标
|
||||
SetCursorBasedOnEditingMode(inkCanvas1);
|
||||
if (Settings.Canvas.IsShowCursor) {
|
||||
if (inkCanvas1.EditingMode == InkCanvasEditingMode.Ink ||
|
||||
inkCanvas1.EditingMode == InkCanvasEditingMode.Select ||
|
||||
drawingShapeMode != 0)
|
||||
inkCanvas1.ForceCursor = true;
|
||||
else
|
||||
inkCanvas1.ForceCursor = false;
|
||||
} else {
|
||||
// 套索选择模式下始终强制显示光标,即使用户设置不显示光标
|
||||
if (inkCanvas1.EditingMode == InkCanvasEditingMode.Select) {
|
||||
inkCanvas1.ForceCursor = true;
|
||||
} else {
|
||||
inkCanvas1.ForceCursor = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (inkCanvas1.EditingMode == InkCanvasEditingMode.Ink) forcePointEraser = !forcePointEraser;
|
||||
|
||||
// 处理高级橡皮擦覆盖层的启用/禁用
|
||||
var eraserOverlay = this.FindName("AdvancedEraserOverlay") as Border;
|
||||
if (eraserOverlay != null) {
|
||||
if (inkCanvas1.EditingMode == InkCanvasEditingMode.EraseByPoint) {
|
||||
// 橡皮擦模式下启用覆盖层
|
||||
eraserOverlay.IsHitTestVisible = true;
|
||||
Trace.WriteLine("Advanced Eraser: Overlay enabled in eraser mode");
|
||||
} else {
|
||||
// 其他模式下禁用覆盖层
|
||||
eraserOverlay.IsHitTestVisible = false;
|
||||
// 同时禁用高级橡皮擦系统
|
||||
DisableAdvancedEraserSystem();
|
||||
Trace.WriteLine("Advanced Eraser: Overlay disabled in non-eraser mode");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Ink Canvas
|
||||
@@ -174,6 +217,7 @@ namespace Ink_Canvas {
|
||||
public static Settings Settings = new Settings();
|
||||
public static string settingsFileName = "Settings.json";
|
||||
private bool isLoaded = false;
|
||||
private bool forcePointEraser = false;
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e) {
|
||||
loadPenCanvas();
|
||||
@@ -381,9 +425,46 @@ namespace Ink_Canvas {
|
||||
}
|
||||
}
|
||||
|
||||
// 辅助方法:使用多线路组下载更新
|
||||
private async Task<bool> DownloadUpdateWithFallback(string version, AutoUpdateHelper.UpdateLineGroup primaryGroup, UpdateChannel channel)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 如果主要线路组可用,直接使用
|
||||
if (primaryGroup != null)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"AutoUpdate | 使用主要线路组下载: {primaryGroup.GroupName}");
|
||||
return await AutoUpdateHelper.DownloadSetupFile(version, primaryGroup);
|
||||
}
|
||||
|
||||
// 如果主要线路组不可用,获取所有可用线路组
|
||||
LogHelper.WriteLogToFile("AutoUpdate | 主要线路组不可用,获取所有可用线路组");
|
||||
var availableGroups = await AutoUpdateHelper.GetAvailableLineGroupsOrdered(channel);
|
||||
if (availableGroups.Count == 0)
|
||||
{
|
||||
LogHelper.WriteLogToFile("AutoUpdate | 没有可用的线路组", LogHelper.LogType.Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
LogHelper.WriteLogToFile($"AutoUpdate | 使用 {availableGroups.Count} 个可用线路组进行下载");
|
||||
return await AutoUpdateHelper.DownloadSetupFileWithFallback(version, availableGroups);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"AutoUpdate | 下载更新时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private async void AutoUpdate() {
|
||||
// 清除之前的更新状态,确保使用新通道重新检查
|
||||
AvailableLatestVersion = null;
|
||||
AvailableLatestLineGroup = null;
|
||||
|
||||
// 使用当前选择的更新通道检查更新
|
||||
AvailableLatestVersion = await AutoUpdateHelper.CheckForUpdates(null, Settings.Startup.UpdateChannel);
|
||||
var (remoteVersion, lineGroup) = await AutoUpdateHelper.CheckForUpdates(Settings.Startup.UpdateChannel);
|
||||
AvailableLatestVersion = remoteVersion;
|
||||
AvailableLatestLineGroup = lineGroup;
|
||||
|
||||
// 声明下载状态变量,用于整个方法
|
||||
bool isDownloadSuccessful = false;
|
||||
@@ -415,8 +496,8 @@ namespace Ink_Canvas {
|
||||
if (Settings.Startup.IsAutoUpdateWithSilence) {
|
||||
LogHelper.WriteLogToFile("AutoUpdate | Silent update enabled, downloading update automatically without notification");
|
||||
|
||||
// 静默下载更新,传递当前选择的更新通道
|
||||
isDownloadSuccessful = await AutoUpdateHelper.DownloadSetupFileAndSaveStatus(AvailableLatestVersion, "", Settings.Startup.UpdateChannel);
|
||||
// 静默下载更新,使用多线路组下载功能
|
||||
isDownloadSuccessful = await DownloadUpdateWithFallback(AvailableLatestVersion, AvailableLatestLineGroup, Settings.Startup.UpdateChannel);
|
||||
|
||||
if (isDownloadSuccessful) {
|
||||
LogHelper.WriteLogToFile("AutoUpdate | Update downloaded successfully, will install when conditions are met");
|
||||
@@ -465,8 +546,8 @@ namespace Ink_Canvas {
|
||||
// 显示下载进度提示
|
||||
MessageBox.Show("开始下载更新,请稍候...", "正在更新", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
|
||||
// 下载更新文件,传递当前选择的更新通道
|
||||
isDownloadSuccessful = await AutoUpdateHelper.DownloadSetupFileAndSaveStatus(AvailableLatestVersion, "", Settings.Startup.UpdateChannel);
|
||||
// 下载更新文件,使用多线路组下载功能
|
||||
isDownloadSuccessful = await DownloadUpdateWithFallback(AvailableLatestVersion, AvailableLatestLineGroup, Settings.Startup.UpdateChannel);
|
||||
|
||||
if (isDownloadSuccessful) {
|
||||
// 下载成功,提示用户准备安装
|
||||
@@ -495,8 +576,8 @@ namespace Ink_Canvas {
|
||||
// 稍后更新:静默下载,在软件关闭时自动安装
|
||||
LogHelper.WriteLogToFile("AutoUpdate | User chose to update later");
|
||||
|
||||
// 不管设置如何,都进行下载
|
||||
isDownloadSuccessful = await AutoUpdateHelper.DownloadSetupFileAndSaveStatus(AvailableLatestVersion, "", Settings.Startup.UpdateChannel);
|
||||
// 不管设置如何,都进行下载,使用多线路组下载功能
|
||||
isDownloadSuccessful = await DownloadUpdateWithFallback(AvailableLatestVersion, AvailableLatestLineGroup, Settings.Startup.UpdateChannel);
|
||||
|
||||
if (isDownloadSuccessful) {
|
||||
LogHelper.WriteLogToFile("AutoUpdate | Update downloaded successfully, will install when application closes");
|
||||
@@ -557,12 +638,22 @@ namespace Ink_Canvas {
|
||||
}
|
||||
|
||||
// 添加一个辅助方法,根据当前编辑模式设置光标
|
||||
private void SetCursorBasedOnEditingMode(InkCanvas canvas)
|
||||
public void SetCursorBasedOnEditingMode(InkCanvas canvas)
|
||||
{
|
||||
// 套索选择模式下光标始终显示,无论用户设置如何
|
||||
if (canvas.EditingMode == InkCanvasEditingMode.Select) {
|
||||
canvas.UseCustomCursor = true;
|
||||
canvas.ForceCursor = true;
|
||||
canvas.Cursor = Cursors.Cross;
|
||||
System.Windows.Forms.Cursor.Show();
|
||||
return;
|
||||
}
|
||||
|
||||
// 其他模式按照用户设置处理
|
||||
if (Settings.Canvas.IsShowCursor) {
|
||||
canvas.UseCustomCursor = true;
|
||||
canvas.ForceCursor = true;
|
||||
|
||||
|
||||
// 根据编辑模式设置不同的光标
|
||||
if (canvas.EditingMode == InkCanvasEditingMode.EraseByPoint) {
|
||||
canvas.Cursor = Cursors.Cross;
|
||||
@@ -570,16 +661,11 @@ namespace Ink_Canvas {
|
||||
var sri = Application.GetResourceStream(new Uri("Resources/Cursors/Pen.cur", UriKind.Relative));
|
||||
if (sri != null)
|
||||
canvas.Cursor = new Cursor(sri.Stream);
|
||||
} else if (canvas.EditingMode == InkCanvasEditingMode.Select) {
|
||||
canvas.Cursor = Cursors.Cross;
|
||||
}
|
||||
|
||||
|
||||
// 确保光标可见,无论是鼠标、触控还是手写笔
|
||||
System.Windows.Forms.Cursor.Show();
|
||||
|
||||
// 强制应用光标设置
|
||||
canvas.ForceCursor = true;
|
||||
|
||||
|
||||
// 确保手写笔模式下也能显示光标
|
||||
if (Tablet.TabletDevices.Count > 0) {
|
||||
foreach (TabletDevice device in Tablet.TabletDevices) {
|
||||
@@ -601,36 +687,17 @@ namespace Ink_Canvas {
|
||||
private void inkCanvas_PreviewMouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
// 使用辅助方法设置光标
|
||||
SetCursorBasedOnEditingMode(inkCanvas);
|
||||
SetCursorBasedOnEditingMode(sender as InkCanvas);
|
||||
}
|
||||
|
||||
// 手写笔输入
|
||||
private void inkCanvas_StylusDown(object sender, StylusDownEventArgs e)
|
||||
{
|
||||
// 使用辅助方法设置光标
|
||||
SetCursorBasedOnEditingMode(inkCanvas);
|
||||
}
|
||||
|
||||
// 触摸输入,不隐藏光标
|
||||
private void inkCanvas_TouchDown(object sender, TouchEventArgs e)
|
||||
{
|
||||
// 使用辅助方法设置光标
|
||||
SetCursorBasedOnEditingMode(inkCanvas);
|
||||
SetCursorBasedOnEditingMode(sender as InkCanvas);
|
||||
}
|
||||
|
||||
// 触摸结束,恢复光标
|
||||
private void inkCanvas_TouchUp(object sender, TouchEventArgs e)
|
||||
{
|
||||
// 使用辅助方法设置光标
|
||||
SetCursorBasedOnEditingMode(inkCanvas);
|
||||
|
||||
// 确保光标可见
|
||||
if (Settings.Canvas.IsShowCursor) {
|
||||
inkCanvas.ForceCursor = true;
|
||||
inkCanvas.UseCustomCursor = true;
|
||||
System.Windows.Forms.Cursor.Show();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Definations and Loading
|
||||
|
||||
@@ -1106,5 +1173,65 @@ namespace Ink_Canvas {
|
||||
MessageBox.Show($"打开插件管理器时出错: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
// 在MainWindow类中添加:
|
||||
private void ApplyCurrentEraserShape()
|
||||
{
|
||||
double k = 1;
|
||||
switch (Settings.Canvas.EraserSize)
|
||||
{
|
||||
case 0:
|
||||
k = Settings.Canvas.EraserShapeType == 0 ? 0.5 : 0.7;
|
||||
break;
|
||||
case 1:
|
||||
k = Settings.Canvas.EraserShapeType == 0 ? 0.8 : 0.9;
|
||||
break;
|
||||
case 3:
|
||||
k = Settings.Canvas.EraserShapeType == 0 ? 1.25 : 1.2;
|
||||
break;
|
||||
case 4:
|
||||
k = Settings.Canvas.EraserShapeType == 0 ? 1.5 : 1.3;
|
||||
break;
|
||||
}
|
||||
if (Settings.Canvas.EraserShapeType == 0)
|
||||
{
|
||||
inkCanvas.EraserShape = new EllipseStylusShape(k * 90, k * 90);
|
||||
}
|
||||
else if (Settings.Canvas.EraserShapeType == 1)
|
||||
{
|
||||
inkCanvas.EraserShape = new RectangleStylusShape(k * 90 * 0.6, k * 90);
|
||||
}
|
||||
}
|
||||
|
||||
// 显示指定页
|
||||
private void ShowPage(int index)
|
||||
{
|
||||
if (index < 0 || index >= whiteboardPages.Count) return;
|
||||
// 只切换可见性
|
||||
for (int i = 0; i < whiteboardPages.Count; i++)
|
||||
{
|
||||
whiteboardPages[i].Visibility = (i == index) ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;
|
||||
}
|
||||
currentCanvas = whiteboardPages[index];
|
||||
currentPageIndex = index;
|
||||
}
|
||||
// 新建页面
|
||||
private void AddNewPage()
|
||||
{
|
||||
var newCanvas = new System.Windows.Controls.Canvas();
|
||||
whiteboardPages.Add(newCanvas);
|
||||
InkCanvasGridForInkReplay.Children.Add(newCanvas);
|
||||
ShowPage(whiteboardPages.Count - 1);
|
||||
}
|
||||
// 删除当前页面
|
||||
private void DeleteCurrentPage()
|
||||
{
|
||||
if (whiteboardPages.Count <= 1) return;
|
||||
InkCanvasGridForInkReplay.Children.Remove(currentCanvas);
|
||||
whiteboardPages.RemoveAt(currentPageIndex);
|
||||
if (currentPageIndex >= whiteboardPages.Count)
|
||||
currentPageIndex = whiteboardPages.Count - 1;
|
||||
ShowPage(currentPageIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -688,29 +688,13 @@ namespace Ink_Canvas {
|
||||
}
|
||||
}
|
||||
|
||||
private void BoardEraserIcon_Click(object sender, RoutedEventArgs e) {
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint ||
|
||||
inkCanvas.EditingMode == InkCanvasEditingMode.EraseByStroke) {
|
||||
if (BoardEraserSizePanel.Visibility == Visibility.Collapsed) {
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(BoardEraserSizePanel);
|
||||
} else {
|
||||
AnimationsHelper.HideWithSlideAndFade(BoardEraserSizePanel);
|
||||
}
|
||||
} else {
|
||||
forceEraser = true;
|
||||
forcePointEraser = true;
|
||||
|
||||
// 使用统一的方法应用橡皮擦形状,确保一致性
|
||||
ApplyCurrentEraserShape();
|
||||
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
|
||||
drawingShapeMode = 0;
|
||||
|
||||
inkCanvas_EditingModeChanged(inkCanvas, null);
|
||||
CancelSingleFingerDragMode();
|
||||
|
||||
HideSubPanels("eraser");
|
||||
}
|
||||
private void BoardLassoIcon_Click(object sender, RoutedEventArgs e) {
|
||||
forceEraser = false;
|
||||
forcePointEraser = false;
|
||||
isLastTouchEraser = false;
|
||||
drawingShapeMode = 0;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.Select;
|
||||
SetCursorBasedOnEditingMode(inkCanvas);
|
||||
}
|
||||
|
||||
private void BoardEraserIconByStrokes_Click(object sender, RoutedEventArgs e) {
|
||||
|
||||
@@ -54,7 +54,6 @@ namespace Ink_Canvas {
|
||||
drawingShapeMode = 0;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
|
||||
CancelSingleFingerDragMode();
|
||||
forceEraser = false;
|
||||
CheckColorTheme();
|
||||
}
|
||||
|
||||
@@ -553,62 +552,52 @@ namespace Ink_Canvas {
|
||||
|
||||
private void BtnColorBlack_Click(object sender, RoutedEventArgs e) {
|
||||
CheckLastColor(0);
|
||||
forceEraser = false;
|
||||
ColorSwitchCheck();
|
||||
}
|
||||
|
||||
private void BtnColorRed_Click(object sender, RoutedEventArgs e) {
|
||||
CheckLastColor(1);
|
||||
forceEraser = false;
|
||||
ColorSwitchCheck();
|
||||
}
|
||||
|
||||
private void BtnColorGreen_Click(object sender, RoutedEventArgs e) {
|
||||
CheckLastColor(2);
|
||||
forceEraser = false;
|
||||
ColorSwitchCheck();
|
||||
}
|
||||
|
||||
private void BtnColorBlue_Click(object sender, RoutedEventArgs e) {
|
||||
CheckLastColor(3);
|
||||
forceEraser = false;
|
||||
ColorSwitchCheck();
|
||||
}
|
||||
|
||||
private void BtnColorYellow_Click(object sender, RoutedEventArgs e) {
|
||||
CheckLastColor(4);
|
||||
forceEraser = false;
|
||||
ColorSwitchCheck();
|
||||
}
|
||||
|
||||
private void BtnColorWhite_Click(object sender, RoutedEventArgs e) {
|
||||
CheckLastColor(5);
|
||||
forceEraser = false;
|
||||
ColorSwitchCheck();
|
||||
}
|
||||
|
||||
private void BtnColorPink_Click(object sender, RoutedEventArgs e) {
|
||||
CheckLastColor(6);
|
||||
forceEraser = false;
|
||||
ColorSwitchCheck();
|
||||
}
|
||||
|
||||
private void BtnColorOrange_Click(object sender, RoutedEventArgs e) {
|
||||
CheckLastColor(8);
|
||||
forceEraser = false;
|
||||
ColorSwitchCheck();
|
||||
}
|
||||
|
||||
private void BtnColorTeal_Click(object sender, RoutedEventArgs e) {
|
||||
CheckLastColor(7);
|
||||
forceEraser = false;
|
||||
ColorSwitchCheck();
|
||||
}
|
||||
|
||||
private void BtnHighlighterColorBlack_Click(object sender, RoutedEventArgs e) {
|
||||
CheckLastColor(100, true);
|
||||
penType = 1;
|
||||
forceEraser = false;
|
||||
CheckPenTypeUIState();
|
||||
ColorSwitchCheck();
|
||||
}
|
||||
@@ -616,7 +605,6 @@ namespace Ink_Canvas {
|
||||
private void BtnHighlighterColorWhite_Click(object sender, RoutedEventArgs e) {
|
||||
CheckLastColor(101, true);
|
||||
penType = 1;
|
||||
forceEraser = false;
|
||||
CheckPenTypeUIState();
|
||||
ColorSwitchCheck();
|
||||
}
|
||||
@@ -624,7 +612,6 @@ namespace Ink_Canvas {
|
||||
private void BtnHighlighterColorRed_Click(object sender, RoutedEventArgs e) {
|
||||
CheckLastColor(102, true);
|
||||
penType = 1;
|
||||
forceEraser = false;
|
||||
CheckPenTypeUIState();
|
||||
ColorSwitchCheck();
|
||||
}
|
||||
@@ -632,7 +619,6 @@ namespace Ink_Canvas {
|
||||
private void BtnHighlighterColorYellow_Click(object sender, RoutedEventArgs e) {
|
||||
CheckLastColor(103, true);
|
||||
penType = 1;
|
||||
forceEraser = false;
|
||||
CheckPenTypeUIState();
|
||||
ColorSwitchCheck();
|
||||
}
|
||||
@@ -640,7 +626,6 @@ namespace Ink_Canvas {
|
||||
private void BtnHighlighterColorGreen_Click(object sender, RoutedEventArgs e) {
|
||||
CheckLastColor(104, true);
|
||||
penType = 1;
|
||||
forceEraser = false;
|
||||
CheckPenTypeUIState();
|
||||
ColorSwitchCheck();
|
||||
}
|
||||
@@ -648,7 +633,6 @@ namespace Ink_Canvas {
|
||||
private void BtnHighlighterColorZinc_Click(object sender, RoutedEventArgs e) {
|
||||
CheckLastColor(105, true);
|
||||
penType = 1;
|
||||
forceEraser = false;
|
||||
CheckPenTypeUIState();
|
||||
ColorSwitchCheck();
|
||||
}
|
||||
@@ -656,7 +640,6 @@ namespace Ink_Canvas {
|
||||
private void BtnHighlighterColorBlue_Click(object sender, RoutedEventArgs e) {
|
||||
CheckLastColor(106, true);
|
||||
penType = 1;
|
||||
forceEraser = false;
|
||||
CheckPenTypeUIState();
|
||||
ColorSwitchCheck();
|
||||
}
|
||||
@@ -664,7 +647,6 @@ namespace Ink_Canvas {
|
||||
private void BtnHighlighterColorPurple_Click(object sender, RoutedEventArgs e) {
|
||||
CheckLastColor(107, true);
|
||||
penType = 1;
|
||||
forceEraser = false;
|
||||
CheckPenTypeUIState();
|
||||
ColorSwitchCheck();
|
||||
}
|
||||
@@ -672,7 +654,6 @@ namespace Ink_Canvas {
|
||||
private void BtnHighlighterColorTeal_Click(object sender, RoutedEventArgs e) {
|
||||
CheckLastColor(108, true);
|
||||
penType = 1;
|
||||
forceEraser = false;
|
||||
CheckPenTypeUIState();
|
||||
ColorSwitchCheck();
|
||||
}
|
||||
@@ -680,7 +661,6 @@ namespace Ink_Canvas {
|
||||
private void BtnHighlighterColorOrange_Click(object sender, RoutedEventArgs e) {
|
||||
CheckLastColor(109, true);
|
||||
penType = 1;
|
||||
forceEraser = false;
|
||||
CheckPenTypeUIState();
|
||||
ColorSwitchCheck();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,736 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Ink;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using Ink_Canvas.Helpers;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace Ink_Canvas {
|
||||
public partial class MainWindow : Window {
|
||||
|
||||
// 新橡皮擦系统的核心变量
|
||||
public bool isUsingAdvancedEraser = false;
|
||||
private IncrementalStrokeHitTester advancedHitTester = null;
|
||||
|
||||
// 橡皮擦配置
|
||||
public double currentEraserSize = 64;
|
||||
public bool isCurrentEraserCircle = false;
|
||||
public bool isUsingStrokeEraser = false;
|
||||
|
||||
// 视觉反馈相关
|
||||
private Matrix eraserTransformMatrix = new Matrix();
|
||||
private Point lastEraserPosition = new Point();
|
||||
private bool isEraserVisible = false;
|
||||
|
||||
// 性能优化相关
|
||||
private DateTime lastEraserUpdate = DateTime.Now;
|
||||
private const double ERASER_UPDATE_INTERVAL = 16.67; // 约60FPS
|
||||
|
||||
// 锁定笔画的GUID(如果不存在则创建一个默认值)
|
||||
private static readonly Guid IsLockGuid = new Guid("12345678-1234-1234-1234-123456789ABC");
|
||||
|
||||
// 橡皮擦视觉反馈控件
|
||||
private DrawingVisual eraserVisual = new DrawingVisual();
|
||||
private VisualCanvas eraserOverlayCanvas = null;
|
||||
private Border eraserVisualBorder = null; // 用于显示橡皮擦视觉反馈的Border
|
||||
|
||||
// 兼容性属性:模拟原有的EraserOverlay_DrawingVisual
|
||||
private VisualCanvas EraserOverlay_DrawingVisual => eraserOverlayCanvas;
|
||||
|
||||
// 兼容性保持
|
||||
[Obsolete("使用 isUsingAdvancedEraser 替代")]
|
||||
public bool isUsingGeometryEraser
|
||||
{
|
||||
get => isUsingAdvancedEraser;
|
||||
set => isUsingAdvancedEraser = value;
|
||||
}
|
||||
|
||||
[Obsolete("使用 currentEraserSize 替代")]
|
||||
public double eraserWidth
|
||||
{
|
||||
get => currentEraserSize;
|
||||
set => currentEraserSize = value;
|
||||
}
|
||||
|
||||
[Obsolete("使用 isCurrentEraserCircle 替代")]
|
||||
public bool isEraserCircleShape
|
||||
{
|
||||
get => isCurrentEraserCircle;
|
||||
set => isCurrentEraserCircle = value;
|
||||
}
|
||||
|
||||
[Obsolete("使用 isUsingStrokeEraser 替代")]
|
||||
public bool isUsingStrokesEraser
|
||||
{
|
||||
get => isUsingStrokeEraser;
|
||||
set => isUsingStrokeEraser = value;
|
||||
}
|
||||
|
||||
[Obsolete("使用 eraserTransformMatrix 替代")]
|
||||
private Matrix scaleMatrix
|
||||
{
|
||||
get => eraserTransformMatrix;
|
||||
set => eraserTransformMatrix = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新橡皮擦覆盖层加载事件处理
|
||||
/// </summary>
|
||||
private void EraserOverlay_Loaded(object sender, RoutedEventArgs e) {
|
||||
var border = (Border)sender;
|
||||
|
||||
// 初始化覆盖层
|
||||
InitializeEraserOverlay(border);
|
||||
|
||||
Trace.WriteLine("Advanced Eraser: Overlay loaded and initialized");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始高级橡皮擦操作
|
||||
/// </summary>
|
||||
private void StartAdvancedEraserOperation(object sender) {
|
||||
if (isUsingAdvancedEraser) return;
|
||||
|
||||
// 设置操作状态
|
||||
isUsingAdvancedEraser = true;
|
||||
isEraserVisible = true;
|
||||
|
||||
// 更新橡皮擦尺寸
|
||||
UpdateEraserSize();
|
||||
|
||||
// 获取inkCanvas引用
|
||||
var inkCanvas = this.FindName("inkCanvas") as InkCanvas;
|
||||
if (inkCanvas == null) return;
|
||||
|
||||
// 根据橡皮擦形状创建碰撞检测器
|
||||
StylusShape eraserShape = CreateEraserShape();
|
||||
advancedHitTester = inkCanvas.Strokes.GetIncrementalStrokeHitTester(eraserShape);
|
||||
advancedHitTester.StrokeHit += OnAdvancedEraserStrokeHit;
|
||||
|
||||
// 初始化变换矩阵
|
||||
InitializeEraserTransform();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建橡皮擦形状
|
||||
/// </summary>
|
||||
private StylusShape CreateEraserShape() {
|
||||
if (isCurrentEraserCircle) {
|
||||
return new EllipseStylusShape(currentEraserSize, currentEraserSize);
|
||||
} else {
|
||||
// 矩形橡皮擦,使用与原来相同的逻辑
|
||||
return new RectangleStylusShape(currentEraserSize, currentEraserSize / 0.6);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化橡皮擦变换矩阵
|
||||
/// </summary>
|
||||
private void InitializeEraserTransform() {
|
||||
eraserTransformMatrix = new Matrix();
|
||||
|
||||
if (isCurrentEraserCircle) {
|
||||
// 圆形橡皮擦:等比例缩放
|
||||
var scale = currentEraserSize / 56.0; // 基于56x56的基准尺寸
|
||||
eraserTransformMatrix.ScaleAt(scale, scale, 0, 0);
|
||||
} else {
|
||||
// 矩形橡皮擦:保持传统比例
|
||||
var scaleX = currentEraserSize / 38.0;
|
||||
var scaleY = (currentEraserSize * 56 / 38) / 56.0;
|
||||
eraserTransformMatrix.ScaleAt(scaleX, scaleY, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新橡皮擦尺寸
|
||||
/// </summary>
|
||||
private void UpdateEraserSize() {
|
||||
// 使用与原来相同的逻辑计算橡皮擦尺寸
|
||||
double k = 1.0;
|
||||
|
||||
switch (Settings.Canvas.EraserSize) {
|
||||
case 0: k = Settings.Canvas.EraserShapeType == 0 ? 0.5 : 0.7; break;
|
||||
case 1: k = Settings.Canvas.EraserShapeType == 0 ? 0.8 : 0.9; break;
|
||||
case 2: k = 1.0; break;
|
||||
case 3: k = Settings.Canvas.EraserShapeType == 0 ? 1.25 : 1.2; break;
|
||||
case 4: k = Settings.Canvas.EraserShapeType == 0 ? 1.5 : 1.3; break;
|
||||
}
|
||||
|
||||
// 更新形状类型
|
||||
isCurrentEraserCircle = (Settings.Canvas.EraserShapeType == 0);
|
||||
|
||||
// 根据形状类型设置尺寸
|
||||
if (isCurrentEraserCircle) {
|
||||
currentEraserSize = k * 90; // 圆形橡皮擦
|
||||
} else {
|
||||
currentEraserSize = k * 90 * 0.6; // 矩形橡皮擦宽度
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 结束高级橡皮擦操作
|
||||
/// </summary>
|
||||
private void EndAdvancedEraserOperation(object sender) {
|
||||
if (!isUsingAdvancedEraser) return;
|
||||
|
||||
// 重置操作状态
|
||||
isUsingAdvancedEraser = false;
|
||||
isEraserVisible = false;
|
||||
|
||||
// 释放鼠标捕获
|
||||
if (sender is Border border) {
|
||||
border.ReleaseMouseCapture();
|
||||
}
|
||||
|
||||
// 隐藏橡皮擦视觉反馈
|
||||
HideEraserFeedback();
|
||||
|
||||
// 结束碰撞检测
|
||||
if (advancedHitTester != null) {
|
||||
advancedHitTester.EndHitTesting();
|
||||
advancedHitTester = null;
|
||||
}
|
||||
|
||||
// 提交橡皮擦历史记录
|
||||
CommitEraserHistory();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 隐藏橡皮擦视觉反馈
|
||||
/// </summary>
|
||||
private void HideEraserFeedback() {
|
||||
try {
|
||||
if (eraserVisualBorder != null) {
|
||||
eraserVisualBorder.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Trace.WriteLine($"Advanced Eraser: Error hiding feedback - {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 提交橡皮擦历史记录
|
||||
/// </summary>
|
||||
private void CommitEraserHistory() {
|
||||
try {
|
||||
if (ReplacedStroke != null || AddedStroke != null) {
|
||||
timeMachine.CommitStrokeEraseHistory(ReplacedStroke, AddedStroke);
|
||||
AddedStroke = null;
|
||||
ReplacedStroke = null;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Trace.WriteLine($"Advanced Eraser: Error committing history - {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 高级橡皮擦笔画碰撞事件处理
|
||||
/// </summary>
|
||||
private void OnAdvancedEraserStrokeHit(object sender, StrokeHitEventArgs args) {
|
||||
try {
|
||||
var inkCanvas = this.FindName("inkCanvas") as InkCanvas;
|
||||
if (inkCanvas == null) return;
|
||||
|
||||
var eraseResult = args.GetPointEraseResults();
|
||||
var strokeToReplace = new StrokeCollection { args.HitStroke };
|
||||
|
||||
// 过滤锁定的笔画
|
||||
var filteredToReplace = strokeToReplace.Where(stroke => !stroke.ContainsPropertyData(IsLockGuid));
|
||||
var filteredToReplaceArray = filteredToReplace as Stroke[] ?? filteredToReplace.ToArray();
|
||||
|
||||
if (!filteredToReplaceArray.Any()) return;
|
||||
|
||||
var filteredResult = eraseResult.Where(stroke => !stroke.ContainsPropertyData(IsLockGuid));
|
||||
var filteredResultArray = filteredResult as Stroke[] ?? filteredResult.ToArray();
|
||||
|
||||
// 执行笔画替换或删除
|
||||
if (filteredResultArray.Any()) {
|
||||
inkCanvas.Strokes.Replace(
|
||||
new StrokeCollection(filteredToReplaceArray),
|
||||
new StrokeCollection(filteredResultArray)
|
||||
);
|
||||
} else {
|
||||
inkCanvas.Strokes.Remove(new StrokeCollection(filteredToReplaceArray));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Trace.WriteLine($"Advanced Eraser: Error in stroke hit - {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新高级橡皮擦位置
|
||||
/// </summary>
|
||||
private void UpdateAdvancedEraserPosition(object sender, Point position) {
|
||||
// 移除isUsingAdvancedEraser检查,让视觉反馈始终更新
|
||||
// if (!isUsingAdvancedEraser) return;
|
||||
|
||||
// 性能优化:限制更新频率
|
||||
var now = DateTime.Now;
|
||||
if ((now - lastEraserUpdate).TotalMilliseconds < ERASER_UPDATE_INTERVAL) {
|
||||
return;
|
||||
}
|
||||
lastEraserUpdate = now;
|
||||
|
||||
// 更新位置
|
||||
lastEraserPosition = position;
|
||||
|
||||
// 更新视觉反馈(始终执行)
|
||||
UpdateEraserVisualFeedback(position);
|
||||
|
||||
// 只有在实际使用橡皮擦时才处理擦除
|
||||
if (isUsingAdvancedEraser) {
|
||||
// 处理不同的橡皮擦模式
|
||||
if (isUsingStrokeEraser) {
|
||||
ProcessStrokeEraserAtPosition(position);
|
||||
} else {
|
||||
ProcessGeometryEraserAtPosition(position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在指定位置处理笔画橡皮擦
|
||||
/// </summary>
|
||||
private void ProcessStrokeEraserAtPosition(Point position) {
|
||||
try {
|
||||
var inkCanvas = this.FindName("inkCanvas") as InkCanvas;
|
||||
if (inkCanvas == null) return;
|
||||
|
||||
var hitStrokes = inkCanvas.Strokes.HitTest(position)
|
||||
.Where(stroke => !stroke.ContainsPropertyData(IsLockGuid));
|
||||
var strokesArray = hitStrokes as Stroke[] ?? hitStrokes.ToArray();
|
||||
|
||||
if (strokesArray.Any()) {
|
||||
inkCanvas.Strokes.Remove(new StrokeCollection(strokesArray));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Trace.WriteLine($"Advanced Eraser: Error in stroke eraser - {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在指定位置处理几何橡皮擦
|
||||
/// </summary>
|
||||
private void ProcessGeometryEraserAtPosition(Point position) {
|
||||
try {
|
||||
if (advancedHitTester != null) {
|
||||
advancedHitTester.AddPoint(position);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Trace.WriteLine($"Advanced Eraser: Error in geometry eraser - {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新橡皮擦视觉反馈
|
||||
/// </summary>
|
||||
private void UpdateEraserVisualFeedback(Point position) {
|
||||
try {
|
||||
// 获取或创建橡皮擦视觉反馈Border
|
||||
if (eraserVisualBorder == null) {
|
||||
eraserVisualBorder = new Border {
|
||||
Background = new SolidColorBrush(Colors.Transparent),
|
||||
BorderBrush = new SolidColorBrush(Colors.Transparent),
|
||||
BorderThickness = new Thickness(0),
|
||||
IsHitTestVisible = false,
|
||||
HorizontalAlignment = HorizontalAlignment.Left,
|
||||
VerticalAlignment = VerticalAlignment.Top,
|
||||
Opacity = 1
|
||||
};
|
||||
Panel.SetZIndex(eraserVisualBorder, 1001);
|
||||
|
||||
// 将Border添加到InkCanvasGridForInkReplay中
|
||||
var inkCanvasGrid = this.FindName("InkCanvasGridForInkReplay") as Grid;
|
||||
if (inkCanvasGrid != null) {
|
||||
inkCanvasGrid.Children.Add(eraserVisualBorder);
|
||||
Trace.WriteLine("Advanced Eraser: Visual feedback border added to grid");
|
||||
} else {
|
||||
Trace.WriteLine("Advanced Eraser: Failed to find InkCanvasGridForInkReplay");
|
||||
return; // 如果找不到Grid,直接返回
|
||||
}
|
||||
}
|
||||
|
||||
if (eraserVisualBorder != null) {
|
||||
// 创建橡皮擦视觉反馈
|
||||
var eraserImage = CreateEraserVisualImage();
|
||||
|
||||
// 清除Border的内容并添加新的图像
|
||||
eraserVisualBorder.Child = eraserImage;
|
||||
|
||||
// 更新橡皮擦位置和大小
|
||||
if (isCurrentEraserCircle) {
|
||||
var radius = currentEraserSize / 2;
|
||||
eraserVisualBorder.Width = currentEraserSize;
|
||||
eraserVisualBorder.Height = currentEraserSize;
|
||||
|
||||
// 使用Margin来定位,因为Border在Grid中
|
||||
eraserVisualBorder.Margin = new Thickness(
|
||||
position.X - radius,
|
||||
position.Y - radius,
|
||||
0, 0);
|
||||
} else {
|
||||
// 矩形橡皮擦,使用与原来相同的逻辑
|
||||
var height = currentEraserSize / 0.6;
|
||||
eraserVisualBorder.Width = currentEraserSize;
|
||||
eraserVisualBorder.Height = height;
|
||||
|
||||
// 使用Margin来定位,因为Border在Grid中
|
||||
eraserVisualBorder.Margin = new Thickness(
|
||||
position.X - currentEraserSize / 2,
|
||||
position.Y - height / 2,
|
||||
0, 0);
|
||||
}
|
||||
|
||||
eraserVisualBorder.Visibility = Visibility.Visible;
|
||||
Trace.WriteLine($"Advanced Eraser: Visual feedback updated to ({position.X:F1}, {position.Y:F1})");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Trace.WriteLine($"Advanced Eraser: Error updating visual feedback - {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建橡皮擦视觉图像
|
||||
/// </summary>
|
||||
private Image CreateEraserVisualImage() {
|
||||
try {
|
||||
// 根据橡皮擦形状选择对应的DrawingGroup资源
|
||||
string resourceKey = isCurrentEraserCircle ? "EraserCircleDrawingGroup" : "EraserDrawingGroup";
|
||||
|
||||
// 尝试从资源字典中获取DrawingGroup
|
||||
var drawingGroup = this.TryFindResource(resourceKey) as DrawingGroup;
|
||||
if (drawingGroup == null) {
|
||||
// 如果找不到资源,创建默认的橡皮擦图像
|
||||
return CreateDefaultEraserImage();
|
||||
}
|
||||
|
||||
// 创建变换后的DrawingGroup
|
||||
var transformedGroup = new DrawingGroup();
|
||||
transformedGroup.Children.Add(drawingGroup);
|
||||
|
||||
// 应用缩放变换
|
||||
var transform = new ScaleTransform();
|
||||
if (isCurrentEraserCircle) {
|
||||
var scale = currentEraserSize / 56.0; // 基于56x56的基准尺寸
|
||||
transform.ScaleX = scale;
|
||||
transform.ScaleY = scale;
|
||||
} else {
|
||||
var scaleX = currentEraserSize / 38.0;
|
||||
var scaleY = (currentEraserSize / 0.6) / 56.0;
|
||||
transform.ScaleX = scaleX;
|
||||
transform.ScaleY = scaleY;
|
||||
}
|
||||
transformedGroup.Transform = transform;
|
||||
|
||||
// 创建DrawingImage
|
||||
var drawingImage = new DrawingImage(transformedGroup);
|
||||
|
||||
// 创建Image控件
|
||||
var image = new Image {
|
||||
Source = drawingImage,
|
||||
Stretch = Stretch.None
|
||||
};
|
||||
RenderOptions.SetBitmapScalingMode(image, BitmapScalingMode.HighQuality);
|
||||
|
||||
return image;
|
||||
} catch (Exception ex) {
|
||||
Trace.WriteLine($"Advanced Eraser: Error creating eraser visual image - {ex.Message}");
|
||||
return CreateDefaultEraserImage();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建默认的橡皮擦图像(当资源不可用时)
|
||||
/// </summary>
|
||||
private Image CreateDefaultEraserImage() {
|
||||
try {
|
||||
// 创建一个简单的几何图形作为默认橡皮擦
|
||||
Geometry geometry;
|
||||
if (isCurrentEraserCircle) {
|
||||
geometry = new EllipseGeometry(new Point(28, 28), 28, 28);
|
||||
} else {
|
||||
geometry = new RectangleGeometry(new Rect(0, 0, 38, 56));
|
||||
}
|
||||
|
||||
var brush = new SolidColorBrush(Colors.LightGray);
|
||||
var pen = new Pen(new SolidColorBrush(Colors.DarkGray), 1);
|
||||
|
||||
var geometryDrawing = new GeometryDrawing(brush, pen, geometry);
|
||||
var drawingGroup = new DrawingGroup();
|
||||
drawingGroup.Children.Add(geometryDrawing);
|
||||
|
||||
// 应用缩放变换
|
||||
var transform = new ScaleTransform();
|
||||
if (isCurrentEraserCircle) {
|
||||
var scale = currentEraserSize / 56.0;
|
||||
transform.ScaleX = scale;
|
||||
transform.ScaleY = scale;
|
||||
} else {
|
||||
var scaleX = currentEraserSize / 38.0;
|
||||
var scaleY = (currentEraserSize / 0.6) / 56.0;
|
||||
transform.ScaleX = scaleX;
|
||||
transform.ScaleY = scaleY;
|
||||
}
|
||||
drawingGroup.Transform = transform;
|
||||
|
||||
var drawingImage = new DrawingImage(drawingGroup);
|
||||
var image = new Image {
|
||||
Source = drawingImage,
|
||||
Stretch = Stretch.None
|
||||
};
|
||||
|
||||
return image;
|
||||
} catch (Exception ex) {
|
||||
Trace.WriteLine($"Advanced Eraser: Error creating default eraser image - {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 兼容性方法:旧版橡皮擦几何碰撞处理
|
||||
/// </summary>
|
||||
[Obsolete("使用 OnAdvancedEraserStrokeHit 替代")]
|
||||
private void EraserGeometry_StrokeHit(object sender, StrokeHitEventArgs args) {
|
||||
OnAdvancedEraserStrokeHit(sender, args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 兼容性方法:旧版橡皮擦移动处理
|
||||
/// </summary>
|
||||
[Obsolete("使用 UpdateAdvancedEraserPosition 替代")]
|
||||
private void EraserOverlay_PointerMove(object sender, Point pt) {
|
||||
UpdateAdvancedEraserPosition(sender, pt);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 兼容性方法:旧版橡皮擦按下处理
|
||||
/// </summary>
|
||||
[Obsolete("使用 StartAdvancedEraserOperation 替代")]
|
||||
private void EraserOverlay_PointerDown(object sender) {
|
||||
StartAdvancedEraserOperation(sender);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 兼容性方法:旧版橡皮擦抬起处理
|
||||
/// </summary>
|
||||
[Obsolete("使用 EndAdvancedEraserOperation 替代")]
|
||||
private void EraserOverlay_PointerUp(object sender) {
|
||||
EndAdvancedEraserOperation(sender);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前橡皮擦状态信息(用于调试)
|
||||
/// </summary>
|
||||
public string GetEraserStatusInfo() {
|
||||
return $"Advanced Eraser Status:\n" +
|
||||
$"- Active: {isUsingAdvancedEraser}\n" +
|
||||
$"- Size: {currentEraserSize:F1}\n" +
|
||||
$"- Shape: {(isCurrentEraserCircle ? "Circle" : "Rectangle")}\n" +
|
||||
$"- Mode: {(isUsingStrokeEraser ? "Stroke" : "Geometry")}\n" +
|
||||
$"- Visible: {isEraserVisible}\n" +
|
||||
$"- Last Position: ({lastEraserPosition.X:F1}, {lastEraserPosition.Y:F1})";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置橡皮擦状态
|
||||
/// </summary>
|
||||
public void ResetEraserState() {
|
||||
isUsingAdvancedEraser = false;
|
||||
isEraserVisible = false;
|
||||
lastEraserPosition = new Point();
|
||||
|
||||
if (advancedHitTester != null) {
|
||||
advancedHitTester.EndHitTesting();
|
||||
advancedHitTester = null;
|
||||
}
|
||||
|
||||
HideEraserFeedback();
|
||||
|
||||
// 清理视觉反馈Border
|
||||
if (eraserVisualBorder != null) {
|
||||
var inkCanvasGrid = this.FindName("InkCanvasGridForInkReplay") as Grid;
|
||||
if (inkCanvasGrid != null) {
|
||||
inkCanvasGrid.Children.Remove(eraserVisualBorder);
|
||||
}
|
||||
eraserVisualBorder = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 应用高级橡皮擦形状到InkCanvas
|
||||
/// </summary>
|
||||
public void ApplyAdvancedEraserShape() {
|
||||
try {
|
||||
var inkCanvas = this.FindName("inkCanvas") as InkCanvas;
|
||||
if (inkCanvas == null) return;
|
||||
|
||||
// 更新橡皮擦尺寸和形状
|
||||
UpdateEraserSize();
|
||||
|
||||
// 创建橡皮擦形状
|
||||
StylusShape eraserShape = CreateEraserShape();
|
||||
|
||||
// 应用到InkCanvas
|
||||
inkCanvas.EraserShape = eraserShape;
|
||||
|
||||
Trace.WriteLine($"Advanced Eraser: Applied shape - Size: {currentEraserSize}, Circle: {isCurrentEraserCircle}");
|
||||
} catch (Exception ex) {
|
||||
Trace.WriteLine($"Advanced Eraser: Error applying shape - {ex.Message}");
|
||||
|
||||
// 回退到传统方法
|
||||
try {
|
||||
ApplyCurrentEraserShape();
|
||||
} catch (Exception fallbackEx) {
|
||||
Trace.WriteLine($"Advanced Eraser: Fallback also failed - {fallbackEx.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 启用高级橡皮擦系统
|
||||
/// </summary>
|
||||
public void EnableAdvancedEraserSystem() {
|
||||
try {
|
||||
// 获取橡皮擦覆盖层
|
||||
var eraserOverlay = this.FindName("AdvancedEraserOverlay") as Border;
|
||||
if (eraserOverlay != null) {
|
||||
// 启用覆盖层的交互
|
||||
eraserOverlay.IsHitTestVisible = true;
|
||||
|
||||
// 确保覆盖层在橡皮擦模式下启用
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint) {
|
||||
eraserOverlay.IsHitTestVisible = true;
|
||||
Trace.WriteLine("Advanced Eraser: Overlay enabled for eraser mode");
|
||||
}
|
||||
|
||||
// 设置覆盖层的大小以覆盖整个InkCanvas
|
||||
var inkCanvasControl = this.FindName("inkCanvas") as InkCanvas;
|
||||
if (inkCanvasControl != null) {
|
||||
eraserOverlay.Width = inkCanvasControl.ActualWidth;
|
||||
eraserOverlay.Height = inkCanvasControl.ActualHeight;
|
||||
Trace.WriteLine($"Advanced Eraser: Overlay size set to {eraserOverlay.Width}x{eraserOverlay.Height}");
|
||||
}
|
||||
|
||||
Trace.WriteLine("Advanced Eraser: System enabled successfully");
|
||||
} else {
|
||||
Trace.WriteLine("Advanced Eraser: Failed to find eraser overlay");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Trace.WriteLine($"Advanced Eraser: Error enabling system - {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化橡皮擦覆盖层
|
||||
/// </summary>
|
||||
private void InitializeEraserOverlay(Border overlay) {
|
||||
try {
|
||||
// 设置覆盖层的基本属性
|
||||
overlay.Background = new SolidColorBrush(Colors.Transparent);
|
||||
overlay.IsHitTestVisible = false; // 默认禁用,只在橡皮擦模式下启用
|
||||
|
||||
// 绑定事件处理
|
||||
overlay.MouseDown += (sender, e) => {
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint) {
|
||||
overlay.CaptureMouse();
|
||||
StartAdvancedEraserOperation(sender);
|
||||
}
|
||||
};
|
||||
|
||||
overlay.MouseUp += (sender, e) => {
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint) {
|
||||
overlay.ReleaseMouseCapture();
|
||||
EndAdvancedEraserOperation(sender);
|
||||
}
|
||||
};
|
||||
|
||||
overlay.MouseMove += (sender, e) => {
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint) {
|
||||
var position = e.GetPosition((UIElement)this.FindName("inkCanvas"));
|
||||
Trace.WriteLine($"Advanced Eraser: Mouse move event triggered at ({position.X:F1}, {position.Y:F1})");
|
||||
UpdateAdvancedEraserPosition(sender, position);
|
||||
} else {
|
||||
Trace.WriteLine($"Advanced Eraser: Mouse move ignored - not in eraser mode, current mode: {inkCanvas.EditingMode}");
|
||||
}
|
||||
};
|
||||
|
||||
// 触控笔事件
|
||||
overlay.StylusDown += (sender, e) => {
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint) {
|
||||
e.Handled = true;
|
||||
if (e.StylusDevice.TabletDevice.Type == TabletDeviceType.Stylus) {
|
||||
overlay.CaptureStylus();
|
||||
}
|
||||
StartAdvancedEraserOperation(sender);
|
||||
}
|
||||
};
|
||||
|
||||
overlay.StylusUp += (sender, e) => {
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint) {
|
||||
e.Handled = true;
|
||||
if (e.StylusDevice.TabletDevice.Type == TabletDeviceType.Stylus) {
|
||||
overlay.ReleaseStylusCapture();
|
||||
}
|
||||
EndAdvancedEraserOperation(sender);
|
||||
}
|
||||
};
|
||||
|
||||
overlay.StylusMove += (sender, e) => {
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint) {
|
||||
e.Handled = true;
|
||||
var position = e.GetPosition((UIElement)this.FindName("inkCanvas"));
|
||||
UpdateAdvancedEraserPosition(sender, position);
|
||||
Trace.WriteLine($"Advanced Eraser: Stylus move at ({position.X:F1}, {position.Y:F1})");
|
||||
}
|
||||
};
|
||||
|
||||
Trace.WriteLine("Advanced Eraser: Overlay initialized successfully");
|
||||
} catch (Exception ex) {
|
||||
Trace.WriteLine($"Advanced Eraser: Error initializing overlay - {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 禁用高级橡皮擦系统
|
||||
/// </summary>
|
||||
public void DisableAdvancedEraserSystem() {
|
||||
try {
|
||||
// 重置橡皮擦状态
|
||||
ResetEraserState();
|
||||
|
||||
// 获取橡皮擦覆盖层并禁用
|
||||
var eraserOverlay = this.FindName("AdvancedEraserOverlay") as Border;
|
||||
if (eraserOverlay != null) {
|
||||
eraserOverlay.IsHitTestVisible = false;
|
||||
}
|
||||
|
||||
// 确保视觉反馈被隐藏
|
||||
HideEraserFeedback();
|
||||
|
||||
Trace.WriteLine("Advanced Eraser: System disabled successfully");
|
||||
} catch (Exception ex) {
|
||||
Trace.WriteLine($"Advanced Eraser: Error disabling system - {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换橡皮擦形状(圆形/矩形)
|
||||
/// </summary>
|
||||
public void ToggleEraserShape() {
|
||||
isCurrentEraserCircle = !isCurrentEraserCircle;
|
||||
|
||||
// 更新设置
|
||||
Settings.Canvas.EraserShapeType = isCurrentEraserCircle ? 0 : 1;
|
||||
|
||||
// 应用新形状
|
||||
ApplyAdvancedEraserShape();
|
||||
|
||||
Trace.WriteLine($"Advanced Eraser: Toggled to {(isCurrentEraserCircle ? "Circle" : "Rectangle")}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<DrawingGroup x:Key="EraserDrawingGroup" ClipGeometry="M0,0 V56 H38 V0 H0 Z">
|
||||
<GeometryDrawing Brush="#FFF2EEEB" Geometry="F1 M38,56z M0,0z M0,4C0,1.79086,1.79086,0,4,0L34,0C36.2091,0,38,1.79086,38,4L38,52C38,54.2091,36.2091,56,34,56L4,56C1.79086,56,0,54.2091,0,52L0,4z" />
|
||||
<GeometryDrawing Brush="#FFCDCDCD" Geometry="F0 M38,56z M0,0z M34,1L4,1C2.34315,1,1,2.34315,1,4L1,52C1,53.6569,2.34315,55,4,55L34,55C35.6569,55,37,53.6569,37,52L37,4C37,2.34315,35.6569,1,34,1z M4,0C1.79086,0,0,1.79086,0,4L0,52C0,54.2091,1.79086,56,4,56L34,56C36.2091,56,38,54.2091,38,52L38,4C38,1.79086,36.2091,0,34,0L4,0z" />
|
||||
<GeometryDrawing Brush="#FFD1CFCD" Geometry="F1 M38,56z M0,0z M12,19.5C12,18.1193,13.1193,17,14.5,17L14.5,17C15.8807,17,17,18.1193,17,19.5L17,36.5C17,37.8807,15.8807,39,14.5,39L14.5,39C13.1193,39,12,37.8807,12,36.5L12,19.5z" />
|
||||
<GeometryDrawing Geometry="F0 M38,56z M0,0z M11.5,19.5C11.5,17.8431 12.8431,16.5 14.5,16.5 16.1569,16.5 17.5,17.8431 17.5,19.5L17.5,36.5C17.5,38.1569 16.1569,39.5 14.5,39.5 12.8431,39.5 11.5,38.1569 11.5,36.5L11.5,19.5z M14.5,17.5C13.3954,17.5,12.5,18.3954,12.5,19.5L12.5,36.5C12.5,37.6046 13.3954,38.5 14.5,38.5 15.6046,38.5 16.5,37.6046 16.5,36.5L16.5,19.5C16.5,18.3954,15.6046,17.5,14.5,17.5z">
|
||||
<GeometryDrawing.Brush>
|
||||
<SolidColorBrush Color="#FF6F6F6F" Opacity="0.25" />
|
||||
</GeometryDrawing.Brush>
|
||||
</GeometryDrawing>
|
||||
<GeometryDrawing Brush="#FFD1CFCD" Geometry="F1 M38,56z M0,0z M21,19.5C21,18.1193,22.1193,17,23.5,17L23.5,17C24.8807,17,26,18.1193,26,19.5L26,36.5C26,37.8807,24.8807,39,23.5,39L23.5,39C22.1193,39,21,37.8807,21,36.5L21,19.5z" />
|
||||
<GeometryDrawing Geometry="F0 M38,56z M0,0z M20.5,19.5C20.5,17.8431 21.8431,16.5 23.5,16.5 25.1569,16.5 26.5,17.8431 26.5,19.5L26.5,36.5C26.5,38.1569 25.1569,39.5 23.5,39.5 21.8431,39.5 20.5,38.1569 20.5,36.5L20.5,19.5z M23.5,17.5C22.3954,17.5,21.5,18.3954,21.5,19.5L21.5,36.5C21.5,37.6046 22.3954,38.5 23.5,38.5 24.6046,38.5 25.5,37.6046 25.5,36.5L25.5,19.5C25.5,18.3954,24.6046,17.5,23.5,17.5z">
|
||||
<GeometryDrawing.Brush>
|
||||
<SolidColorBrush Color="#FF6F6F6F" Opacity="0.25" />
|
||||
</GeometryDrawing.Brush>
|
||||
</GeometryDrawing>
|
||||
</DrawingGroup>
|
||||
|
||||
<DrawingGroup x:Key="EraserCircleDrawingGroup" ClipGeometry="M0,0 V56 H56 V0 H0 Z">
|
||||
<GeometryDrawing Brush="#FFF2EEEB" Geometry="F1 M56,56z M0,0z M0,28C0,12.536,12.536,0,28,0L28,0C43.464,0,56,12.536,56,28L56,28C56,43.464,43.464,56,28,56L28,56C12.536,56,0,43.464,0,28L0,28z" />
|
||||
<GeometryDrawing Brush="#FFCDCDCD" Geometry="F0 M56,56z M0,0z M1,28C1,42.9117 13.0883,55 28,55 42.9117,55 55,42.9117 55,28 55,13.0883 42.9117,1 28,1 13.0883,1 1,13.0883 1,28z M28,0C12.536,0 0,12.536 0,28 0,43.464 12.536,56 28,56 43.464,56 56,43.464 56,28 56,12.536 43.464,0 28,0z" />
|
||||
<GeometryDrawing Brush="#FFD1CFCD" Geometry="F1 M56,56z M0,0z M21,19.5C21,18.1193,22.1193,17,23.5,17L23.5,17C24.8807,17,26,18.1193,26,19.5L26,36.5C26,37.8807,24.8807,39,23.5,39L23.5,39C22.1193,39,21,37.8807,21,36.5L21,19.5z" />
|
||||
<GeometryDrawing Geometry="F0 M56,56z M0,0z M20.5,19.5C20.5,17.8431 21.8431,16.5 23.5,16.5 25.1569,16.5 26.5,17.8431 26.5,19.5L26.5,36.5C26.5,38.1569 25.1569,39.5 23.5,39.5 21.8431,39.5 20.5,38.1569 20.5,36.5L20.5,19.5z M23.5,17.5C22.3954,17.5,21.5,18.3954,21.5,19.5L21.5,36.5C21.5,37.6046 22.3954,38.5 23.5,38.5 24.6046,38.5 25.5,37.6046 25.5,36.5L25.5,19.5C25.5,18.3954,24.6046,17.5,23.5,17.5z">
|
||||
<GeometryDrawing.Brush>
|
||||
<SolidColorBrush Color="#FF6F6F6F" Opacity="0.25" />
|
||||
</GeometryDrawing.Brush>
|
||||
</GeometryDrawing>
|
||||
<GeometryDrawing Brush="#FFD1CFCD" Geometry="F1 M56,56z M0,0z M30,19.5C30,18.1193,31.1193,17,32.5,17L32.5,17C33.8807,17,35,18.1193,35,19.5L35,36.5C35,37.8807,33.8807,39,32.5,39L32.5,39C31.1193,39,30,37.8807,30,36.5L30,19.5z" />
|
||||
<GeometryDrawing Geometry="F0 M56,56z M0,0z M29.5,19.5C29.5,17.8431 30.8431,16.5 32.5,16.5 34.1569,16.5 35.5,17.8431 35.5,19.5L35.5,36.5C35.5,38.1569 34.1569,39.5 32.5,39.5 30.8431,39.5 29.5,38.1569 29.5,36.5L29.5,19.5z M32.5,17.5C31.3954,17.5,30.5,18.3954,30.5,19.5L30.5,36.5C30.5,37.6046 31.3954,38.5 32.5,38.5 33.6046,38.5 34.5,37.6046 34.5,36.5L34.5,19.5C34.5,18.3954,33.6046,17.5,32.5,17.5z">
|
||||
<GeometryDrawing.Brush>
|
||||
<SolidColorBrush Color="#FF6F6F6F" Opacity="0.25" />
|
||||
</GeometryDrawing.Brush>
|
||||
</GeometryDrawing>
|
||||
</DrawingGroup>
|
||||
</ResourceDictionary>
|
||||
@@ -514,6 +514,8 @@ namespace Ink_Canvas {
|
||||
Thread.Sleep(100);
|
||||
Application.Current.Dispatcher.Invoke(() => { ViewboxFloatingBarMarginAnimation(60); });
|
||||
})).Start();
|
||||
|
||||
HideSubPanels();
|
||||
|
||||
if (GridTransparencyFakeBackground.Background == Brushes.Transparent)
|
||||
{
|
||||
@@ -527,11 +529,6 @@ namespace Ink_Canvas {
|
||||
}
|
||||
|
||||
BtnHideInkCanvas_Click(BtnHideInkCanvas, null);
|
||||
HideSubPanels();
|
||||
}
|
||||
else
|
||||
{
|
||||
HideSubPanels();
|
||||
}
|
||||
|
||||
if (Settings.Gesture.AutoSwitchTwoFingerGesture) // 自动关闭多指书写、开启双指移动
|
||||
@@ -1280,6 +1277,10 @@ namespace Ink_Canvas {
|
||||
if (lastBorderMouseDownObject != null && lastBorderMouseDownObject is Panel)
|
||||
((Panel)lastBorderMouseDownObject).Background = new SolidColorBrush(Colors.Transparent);
|
||||
if (sender==Cursor_Icon && lastBorderMouseDownObject != Cursor_Icon) return;
|
||||
|
||||
// 禁用高级橡皮擦系统
|
||||
DisableAdvancedEraserSystem();
|
||||
|
||||
// 隱藏高亮
|
||||
FloatingbarSelectionBG.Visibility = Visibility.Hidden;
|
||||
System.Windows.Controls.Canvas.SetLeft(FloatingbarSelectionBG, 0);
|
||||
@@ -1358,6 +1359,9 @@ namespace Ink_Canvas {
|
||||
((Panel)lastBorderMouseDownObject).Background = new SolidColorBrush(Colors.Transparent);
|
||||
if (sender == Pen_Icon && lastBorderMouseDownObject != Pen_Icon) return;
|
||||
|
||||
// 禁用高级橡皮擦系统
|
||||
DisableAdvancedEraserSystem();
|
||||
|
||||
FloatingbarSelectionBG.Visibility = Visibility.Visible;
|
||||
System.Windows.Controls.Canvas.SetLeft(FloatingbarSelectionBG, 28);
|
||||
|
||||
@@ -1443,86 +1447,72 @@ namespace Ink_Canvas {
|
||||
}
|
||||
|
||||
private void EraserIcon_Click(object sender, RoutedEventArgs e) {
|
||||
|
||||
if (lastBorderMouseDownObject != null && lastBorderMouseDownObject is Panel)
|
||||
((Panel)lastBorderMouseDownObject).Background = new SolidColorBrush(Colors.Transparent);
|
||||
if (sender == Eraser_Icon && lastBorderMouseDownObject != Eraser_Icon) return;
|
||||
|
||||
FloatingbarSelectionBG.Visibility = Visibility.Visible;
|
||||
System.Windows.Controls.Canvas.SetLeft(FloatingbarSelectionBG, 84);
|
||||
|
||||
forceEraser = true;
|
||||
EnterMultiTouchModeIfNeeded();
|
||||
bool isAlreadyEraser = inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint;
|
||||
forceEraser = false;
|
||||
forcePointEraser = true;
|
||||
|
||||
// 即使手掌触发过面积擦,也强制应用当前的EraserShapeType设置
|
||||
ApplyCurrentEraserShape();
|
||||
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint) {
|
||||
if (EraserSizePanel.Visibility == Visibility.Collapsed) {
|
||||
AnimationsHelper.HideWithSlideAndFade(BorderTools);
|
||||
AnimationsHelper.HideWithSlideAndFade(BoardBorderTools);
|
||||
AnimationsHelper.HideWithSlideAndFade(PenPalette);
|
||||
AnimationsHelper.HideWithSlideAndFade(BoardPenPalette);
|
||||
AnimationsHelper.HideWithSlideAndFade(BorderDrawShape);
|
||||
AnimationsHelper.HideWithSlideAndFade(BoardBorderDrawShape);
|
||||
AnimationsHelper.HideWithSlideAndFade(BorderTools);
|
||||
AnimationsHelper.HideWithSlideAndFade(BoardBorderTools);
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(EraserSizePanel);
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(BoardEraserSizePanel);
|
||||
} else {
|
||||
AnimationsHelper.HideWithSlideAndFade(EraserSizePanel);
|
||||
AnimationsHelper.HideWithSlideAndFade(BorderTools);
|
||||
AnimationsHelper.HideWithSlideAndFade(BoardBorderTools);
|
||||
AnimationsHelper.HideWithSlideAndFade(PenPalette);
|
||||
AnimationsHelper.HideWithSlideAndFade(BoardPenPalette);
|
||||
AnimationsHelper.HideWithSlideAndFade(BorderDrawShape);
|
||||
AnimationsHelper.HideWithSlideAndFade(BoardBorderDrawShape);
|
||||
AnimationsHelper.HideWithSlideAndFade(BoardEraserSizePanel);
|
||||
AnimationsHelper.HideWithSlideAndFade(BorderTools);
|
||||
AnimationsHelper.HideWithSlideAndFade(BoardBorderTools);
|
||||
AnimationsHelper.HideWithSlideAndFade(TwoFingerGestureBorder);
|
||||
AnimationsHelper.HideWithSlideAndFade(BoardTwoFingerGestureBorder);
|
||||
}
|
||||
}
|
||||
else {
|
||||
HideSubPanels("eraser");
|
||||
}
|
||||
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
|
||||
isLastTouchEraser = false;
|
||||
drawingShapeMode = 0;
|
||||
|
||||
inkCanvas_EditingModeChanged(inkCanvas, null);
|
||||
CancelSingleFingerDragMode();
|
||||
}
|
||||
|
||||
// 新增方法,根据当前设置应用橡皮擦形状
|
||||
public void ApplyCurrentEraserShape() {
|
||||
double k = 1;
|
||||
switch (Settings.Canvas.EraserSize) {
|
||||
case 0:
|
||||
k = Settings.Canvas.EraserShapeType == 0 ? 0.5 : 0.7;
|
||||
break;
|
||||
case 1:
|
||||
k = Settings.Canvas.EraserShapeType == 0 ? 0.8 : 0.9;
|
||||
break;
|
||||
case 3:
|
||||
k = Settings.Canvas.EraserShapeType == 0 ? 1.25 : 1.2;
|
||||
break;
|
||||
case 4:
|
||||
k = Settings.Canvas.EraserShapeType == 0 ? 1.5 : 1.3;
|
||||
break;
|
||||
}
|
||||
// 启用新的高级橡皮擦系统
|
||||
EnableAdvancedEraserSystem();
|
||||
|
||||
// 使用新的高级橡皮擦系统
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
|
||||
ApplyAdvancedEraserShape(); // 使用新的橡皮擦形状应用方法
|
||||
SetCursorBasedOnEditingMode(inkCanvas);
|
||||
HideSubPanels("eraser"); // 高亮橡皮按钮
|
||||
|
||||
if (Settings.Canvas.EraserShapeType == 0) {
|
||||
// 圆形擦
|
||||
inkCanvas.EraserShape = new EllipseStylusShape(k * 90, k * 90);
|
||||
} else if (Settings.Canvas.EraserShapeType == 1) {
|
||||
// 矩形黑板擦
|
||||
inkCanvas.EraserShape = new RectangleStylusShape(k * 90 * 0.6, k * 90);
|
||||
// 显示橡皮擦视觉反馈(用于测试)
|
||||
// 注意:eraserVisualBorder在MW_Eraser.cs中定义,这里无法直接访问
|
||||
Trace.WriteLine($"Advanced Eraser: Eraser button clicked, current size: {currentEraserSize}, circle: {isCurrentEraserCircle}");
|
||||
|
||||
if (isAlreadyEraser) {
|
||||
// 已是橡皮状态,再次点击才弹出/收起面板
|
||||
if (EraserSizePanel.Visibility == Visibility.Collapsed) {
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(EraserSizePanel);
|
||||
if (BoardEraserSizePanel != null)
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(BoardEraserSizePanel);
|
||||
} else {
|
||||
AnimationsHelper.HideWithSlideAndFade(EraserSizePanel);
|
||||
if (BoardEraserSizePanel != null)
|
||||
AnimationsHelper.HideWithSlideAndFade(BoardEraserSizePanel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void BoardEraserIcon_Click(object sender, RoutedEventArgs e) {
|
||||
EnterMultiTouchModeIfNeeded();
|
||||
bool isAlreadyEraser = inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint;
|
||||
forceEraser = false;
|
||||
forcePointEraser = true;
|
||||
isLastTouchEraser = false;
|
||||
drawingShapeMode = 0;
|
||||
|
||||
// 启用新的高级橡皮擦系统
|
||||
EnableAdvancedEraserSystem();
|
||||
|
||||
// 使用新的高级橡皮擦系统
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
|
||||
ApplyAdvancedEraserShape(); // 使用新的橡皮擦形状应用方法
|
||||
SetCursorBasedOnEditingMode(inkCanvas);
|
||||
HideSubPanels("eraser"); // 高亮橡皮按钮
|
||||
|
||||
if (isAlreadyEraser) {
|
||||
// 已是橡皮状态,再次点击才弹出/收起面板
|
||||
if (BoardEraserSizePanel != null && BoardEraserSizePanel.Visibility == Visibility.Collapsed) {
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(BoardEraserSizePanel);
|
||||
AnimationsHelper.ShowWithSlideFromBottomAndFade(EraserSizePanel);
|
||||
} else {
|
||||
if (BoardEraserSizePanel != null)
|
||||
AnimationsHelper.HideWithSlideAndFade(BoardEraserSizePanel);
|
||||
AnimationsHelper.HideWithSlideAndFade(EraserSizePanel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void EraserIconByStrokes_Click(object sender, RoutedEventArgs e) {
|
||||
EnterMultiTouchModeIfNeeded();
|
||||
|
||||
if (lastBorderMouseDownObject != null && lastBorderMouseDownObject is Panel)
|
||||
((Panel)lastBorderMouseDownObject).Background = new SolidColorBrush(Colors.Transparent);
|
||||
@@ -1555,6 +1545,9 @@ namespace Ink_Canvas {
|
||||
}
|
||||
|
||||
private void SelectIcon_MouseUp(object sender, RoutedEvent e) {
|
||||
// 禁用高级橡皮擦系统
|
||||
DisableAdvancedEraserSystem();
|
||||
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 0;
|
||||
inkCanvas.IsManipulationEnabled = false;
|
||||
|
||||
@@ -194,7 +194,7 @@ namespace Ink_Canvas {
|
||||
var pptProcesses = Process.GetProcessesByName("POWERPNT");
|
||||
|
||||
// 根据设置和进程状态决定模式
|
||||
isWPSMode = isWPSSupportOn && wpsRunning;
|
||||
isWPSMode = isWPSSupportOn;
|
||||
|
||||
LogHelper.WriteLogToFile($"初始化模式: {(isWPSMode ? "WPS" : "PowerPoint")}", LogHelper.LogType.Info);
|
||||
|
||||
@@ -490,6 +490,18 @@ namespace Ink_Canvas {
|
||||
catch (Exception ex) {
|
||||
LogHelper.WriteLogToFile(ex.ToString(), LogHelper.LogType.Error);
|
||||
}
|
||||
// ========== 新增:WPS进程清理调用 ==========
|
||||
if (isWPSMode && pptApplication != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (pptApplication.Presentations.Count == 0)
|
||||
{
|
||||
TryCloseExtraWpsProcesses();
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
|
||||
private bool isPresentationHaveBlackSpace = false;
|
||||
@@ -872,6 +884,18 @@ namespace Ink_Canvas {
|
||||
await Application.Current.Dispatcher.InvokeAsync(() => {
|
||||
ViewboxFloatingBarMarginAnimation(100, true);
|
||||
});
|
||||
// ========== 新增:WPS进程清理调用 ==========
|
||||
if (isWPSMode && pptApplication != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (pptApplication.Presentations.Count == 0)
|
||||
{
|
||||
TryCloseExtraWpsProcesses();
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
LogHelper.WriteLogToFile(ex.ToString(), LogHelper.LogType.Error);
|
||||
@@ -1311,5 +1335,67 @@ namespace Ink_Canvas {
|
||||
|
||||
base.OnClosed(e);
|
||||
}
|
||||
|
||||
// ========== 新增:安全关闭多余WPS进程的方法 ==========
|
||||
/// <summary>
|
||||
/// 检查并安全关闭多余的WPS进程(仅当所有WPS都未打开PPT时)
|
||||
/// </summary>
|
||||
private void TryCloseExtraWpsProcesses()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 检查所有WPS进程是否都没有打开PPT
|
||||
bool allWpsNoPpt = true;
|
||||
foreach (var processName in GetPossibleWPSProcessNames())
|
||||
{
|
||||
foreach (var process in Process.GetProcessesByName(processName))
|
||||
{
|
||||
try
|
||||
{
|
||||
dynamic wpsApp = null;
|
||||
try
|
||||
{
|
||||
wpsApp = Marshal.GetActiveObject(processName + ".Application");
|
||||
}
|
||||
catch { }
|
||||
if (wpsApp != null)
|
||||
{
|
||||
if (wpsApp.Presentations.Count > 0)
|
||||
{
|
||||
allWpsNoPpt = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
if (!allWpsNoPpt) break;
|
||||
}
|
||||
|
||||
if (allWpsNoPpt)
|
||||
{
|
||||
// 所有WPS都没有打开PPT,可以安全关闭
|
||||
foreach (var processName in GetPossibleWPSProcessNames())
|
||||
{
|
||||
foreach (var process in Process.GetProcessesByName(processName))
|
||||
{
|
||||
try
|
||||
{
|
||||
process.Kill();
|
||||
LogHelper.WriteLogToFile($"已终止WPS进程: {process.ProcessName}({process.Id})", LogHelper.LogType.Info);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"终止WPS进程失败: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"WPS进程清理异常: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using Ink_Canvas.Helpers;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Windows;
|
||||
using System.Windows.Ink;
|
||||
using System.Windows.Input;
|
||||
@@ -10,6 +11,8 @@ using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Forms;
|
||||
using OpenFileDialog = Microsoft.Win32.OpenFileDialog;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Ink_Canvas {
|
||||
public partial class MainWindow : Window {
|
||||
@@ -38,76 +41,75 @@ namespace Ink_Canvas {
|
||||
//savePathWithName = savePath + @"\" + DateTime.Now.ToString("u").Replace(':', '-') + ".icstk";
|
||||
savePathWithName = savePath + @"\" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss-fff") + ".icstk";
|
||||
|
||||
var fs = new FileStream(savePathWithName, FileMode.Create);
|
||||
|
||||
if (Settings.Automation.IsSaveFullPageStrokes)
|
||||
{
|
||||
// 全页面保存模式 - 保存整个墨迹页面的图像
|
||||
var bitmap = new System.Drawing.Bitmap(
|
||||
(int)System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width,
|
||||
(int)System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
|
||||
// 全页面保存模式 - 检查是否存在多页面墨迹
|
||||
bool hasMultiplePages = false;
|
||||
List<StrokeCollection> allPageStrokes = new List<StrokeCollection>();
|
||||
|
||||
using (var g = System.Drawing.Graphics.FromImage(bitmap))
|
||||
// 检查PPT放映模式下的多页面墨迹
|
||||
if (BtnPPTSlideShowEnd.Visibility == Visibility.Visible && pptApplication != null)
|
||||
{
|
||||
// 创建黑色或透明背景
|
||||
System.Drawing.Color bgColor = Settings.Canvas.UsingWhiteboard
|
||||
? System.Drawing.Color.White
|
||||
: System.Drawing.Color.FromArgb(22, 41, 36); // 黑板背景色
|
||||
g.Clear(bgColor);
|
||||
|
||||
// 将InkCanvas墨迹渲染到Visual
|
||||
var visual = new DrawingVisual();
|
||||
using (var dc = visual.RenderOpen())
|
||||
hasMultiplePages = true;
|
||||
// 收集PPT放映模式下的所有页面墨迹
|
||||
for (int i = 1; i <= pptApplication.SlideShowWindows[1].Presentation.Slides.Count; i++)
|
||||
{
|
||||
// 创建一个VisualBrush,使用inkCanvas作为源
|
||||
var visualBrush = new VisualBrush(inkCanvas);
|
||||
// 绘制矩形并填充为inkCanvas的内容
|
||||
dc.DrawRectangle(visualBrush, null, new Rect(0, 0, inkCanvas.ActualWidth, inkCanvas.ActualHeight));
|
||||
if (memoryStreams[i] != null && memoryStreams[i].Length > 8)
|
||||
{
|
||||
memoryStreams[i].Position = 0;
|
||||
allPageStrokes.Add(new StrokeCollection(memoryStreams[i]));
|
||||
}
|
||||
else if (i == previousSlideID && inkCanvas.Strokes.Count > 0)
|
||||
{
|
||||
// 当前页面的墨迹
|
||||
allPageStrokes.Add(inkCanvas.Strokes.Clone());
|
||||
}
|
||||
else
|
||||
{
|
||||
allPageStrokes.Add(new StrokeCollection()); // 空页面
|
||||
}
|
||||
}
|
||||
|
||||
// 创建适合墨迹画布尺寸的渲染位图
|
||||
var rtb = new RenderTargetBitmap(
|
||||
(int)inkCanvas.ActualWidth, (int)inkCanvas.ActualHeight,
|
||||
96, 96,
|
||||
PixelFormats.Pbgra32);
|
||||
rtb.Render(visual);
|
||||
|
||||
// 转换为GDI+ Bitmap并保存
|
||||
var encoder = new PngBitmapEncoder();
|
||||
encoder.Frames.Add(BitmapFrame.Create(rtb));
|
||||
|
||||
using (var ms = new MemoryStream())
|
||||
}
|
||||
// 检查白板模式下的多页面墨迹
|
||||
else if (currentMode != 0 && WhiteboardTotalCount > 1)
|
||||
{
|
||||
hasMultiplePages = true;
|
||||
// 收集白板模式下的所有页面墨迹
|
||||
for (int i = 1; i <= WhiteboardTotalCount; i++)
|
||||
{
|
||||
encoder.Save(ms);
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
var imgBitmap = new System.Drawing.Bitmap(ms);
|
||||
|
||||
// 将生成的墨迹图像绘制到屏幕截图上
|
||||
// 居中绘制,确保墨迹位于屏幕中央
|
||||
int x = (bitmap.Width - imgBitmap.Width) / 2;
|
||||
int y = (bitmap.Height - imgBitmap.Height) / 2;
|
||||
g.DrawImage(imgBitmap, x, y);
|
||||
|
||||
// 保存为PNG
|
||||
string imagePathWithName = Path.ChangeExtension(savePathWithName, "png");
|
||||
bitmap.Save(imagePathWithName, System.Drawing.Imaging.ImageFormat.Png);
|
||||
|
||||
// 仍然保存墨迹文件以兼容旧版本
|
||||
inkCanvas.Strokes.Save(fs);
|
||||
if (TimeMachineHistories[i] != null)
|
||||
{
|
||||
// 从历史记录中恢复墨迹
|
||||
var strokes = ApplyHistoriesToNewStrokeCollection(TimeMachineHistories[i]);
|
||||
allPageStrokes.Add(strokes);
|
||||
}
|
||||
else
|
||||
{
|
||||
allPageStrokes.Add(new StrokeCollection()); // 空页面
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 显示提示
|
||||
if (newNotice) ShowNotification("墨迹成功全页面保存至 " + Path.ChangeExtension(savePathWithName, "png"));
|
||||
if (hasMultiplePages && allPageStrokes.Count > 0)
|
||||
{
|
||||
// 多页面墨迹保存为压缩包
|
||||
string zipFileName = Path.ChangeExtension(savePathWithName, "zip");
|
||||
SaveMultiPageStrokesAsZip(allPageStrokes, zipFileName, newNotice);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 单页面墨迹保存为图像
|
||||
SaveSinglePageStrokesAsImage(savePathWithName, newNotice);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 常规保存模式 - 仅保存墨迹对象
|
||||
var fs = new FileStream(savePathWithName, FileMode.Create);
|
||||
inkCanvas.Strokes.Save(fs);
|
||||
fs.Close();
|
||||
if (newNotice) ShowNotification("墨迹成功保存至 " + savePathWithName);
|
||||
}
|
||||
|
||||
fs.Close();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ShowNotification("墨迹保存失败");
|
||||
@@ -115,6 +117,193 @@ namespace Ink_Canvas {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将多页面墨迹保存为压缩包
|
||||
/// </summary>
|
||||
private void SaveMultiPageStrokesAsZip(List<StrokeCollection> allPageStrokes, string zipFileName, bool newNotice)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 创建临时目录来存放文件
|
||||
string tempDir = Path.Combine(Path.GetTempPath(), $"InkCanvas_MultiPage_{DateTime.Now:yyyyMMdd_HHmmss}");
|
||||
Directory.CreateDirectory(tempDir);
|
||||
|
||||
try
|
||||
{
|
||||
// 保存所有页面的文件到临时目录
|
||||
for (int i = 0; i < allPageStrokes.Count; i++)
|
||||
{
|
||||
var strokes = allPageStrokes[i];
|
||||
if (strokes.Count > 0)
|
||||
{
|
||||
// 保存墨迹文件
|
||||
string strokeFileName = Path.Combine(tempDir, $"page_{i + 1:D4}.icstk");
|
||||
using (var fs = new FileStream(strokeFileName, FileMode.Create))
|
||||
{
|
||||
strokes.Save(fs);
|
||||
}
|
||||
|
||||
// 保存页面图像
|
||||
string imageFileName = Path.Combine(tempDir, $"page_{i + 1:D4}.png");
|
||||
using (var fs = new FileStream(imageFileName, FileMode.Create))
|
||||
{
|
||||
SavePageAsImage(strokes, fs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 保存元数据信息
|
||||
string metadataFile = Path.Combine(tempDir, "metadata.txt");
|
||||
using (var writer = new StreamWriter(metadataFile, false, System.Text.Encoding.UTF8))
|
||||
{
|
||||
writer.WriteLine($"保存时间: {DateTime.Now:yyyy-MM-dd HH:mm:ss}");
|
||||
writer.WriteLine($"总页数: {allPageStrokes.Count}");
|
||||
writer.WriteLine($"模式: {(currentMode == 0 ? "PPT放映" : "白板")}");
|
||||
if (currentMode != 0)
|
||||
{
|
||||
writer.WriteLine($"当前页面: {CurrentWhiteboardIndex}");
|
||||
writer.WriteLine($"总页面数: {WhiteboardTotalCount}");
|
||||
}
|
||||
else if (pptApplication != null)
|
||||
{
|
||||
writer.WriteLine($"PPT名称: {pptApplication.SlideShowWindows[1].Presentation.Name}");
|
||||
writer.WriteLine($"PPT总页数: {pptApplication.SlideShowWindows[1].Presentation.Slides.Count}");
|
||||
}
|
||||
|
||||
for (int i = 0; i < allPageStrokes.Count; i++)
|
||||
{
|
||||
writer.WriteLine($"页面 {i + 1}: {allPageStrokes[i].Count} 条墨迹");
|
||||
}
|
||||
}
|
||||
|
||||
// 使用.NET Framework内置的压缩功能创建ZIP文件
|
||||
if (File.Exists(zipFileName))
|
||||
File.Delete(zipFileName);
|
||||
|
||||
// 使用System.IO.Compression.FileSystem来创建ZIP
|
||||
System.IO.Compression.ZipFile.CreateFromDirectory(tempDir, zipFileName);
|
||||
|
||||
if (newNotice) ShowNotification($"多页面墨迹成功保存至压缩包 {zipFileName}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
// 清理临时目录
|
||||
try
|
||||
{
|
||||
if (Directory.Exists(tempDir))
|
||||
Directory.Delete(tempDir, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"清理临时目录失败: {ex.ToString()}", LogHelper.LogType.Warning);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"保存多页面墨迹压缩包失败: {ex.ToString()}", LogHelper.LogType.Error);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将单页面墨迹保存为图像
|
||||
/// </summary>
|
||||
private void SaveSinglePageStrokesAsImage(string savePathWithName, bool newNotice)
|
||||
{
|
||||
// 全页面保存模式 - 保存整个墨迹页面的图像
|
||||
var bitmap = new System.Drawing.Bitmap(
|
||||
(int)System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width,
|
||||
(int)System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
|
||||
|
||||
using (var g = System.Drawing.Graphics.FromImage(bitmap))
|
||||
{
|
||||
// 创建黑色或透明背景
|
||||
System.Drawing.Color bgColor = Settings.Canvas.UsingWhiteboard
|
||||
? System.Drawing.Color.White
|
||||
: System.Drawing.Color.FromArgb(22, 41, 36); // 黑板背景色
|
||||
g.Clear(bgColor);
|
||||
|
||||
// 将InkCanvas墨迹渲染到Visual
|
||||
var visual = new DrawingVisual();
|
||||
using (var dc = visual.RenderOpen())
|
||||
{
|
||||
// 创建一个VisualBrush,使用inkCanvas作为源
|
||||
var visualBrush = new VisualBrush(inkCanvas);
|
||||
// 绘制矩形并填充为inkCanvas的内容
|
||||
dc.DrawRectangle(visualBrush, null, new Rect(0, 0, inkCanvas.ActualWidth, inkCanvas.ActualHeight));
|
||||
}
|
||||
|
||||
// 创建适合墨迹画布尺寸的渲染位图
|
||||
var rtb = new RenderTargetBitmap(
|
||||
(int)inkCanvas.ActualWidth, (int)inkCanvas.ActualHeight,
|
||||
96, 96,
|
||||
PixelFormats.Pbgra32);
|
||||
rtb.Render(visual);
|
||||
|
||||
// 转换为GDI+ Bitmap并保存
|
||||
var encoder = new PngBitmapEncoder();
|
||||
encoder.Frames.Add(BitmapFrame.Create(rtb));
|
||||
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
encoder.Save(ms);
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
var imgBitmap = new System.Drawing.Bitmap(ms);
|
||||
|
||||
// 将生成的墨迹图像绘制到屏幕截图上
|
||||
// 居中绘制,确保墨迹位于屏幕中央
|
||||
int x = (bitmap.Width - imgBitmap.Width) / 2;
|
||||
int y = (bitmap.Height - imgBitmap.Height) / 2;
|
||||
g.DrawImage(imgBitmap, x, y);
|
||||
|
||||
// 保存为PNG
|
||||
string imagePathWithName = Path.ChangeExtension(savePathWithName, "png");
|
||||
bitmap.Save(imagePathWithName, System.Drawing.Imaging.ImageFormat.Png);
|
||||
|
||||
// 仍然保存墨迹文件以兼容旧版本
|
||||
var fs = new FileStream(savePathWithName, FileMode.Create);
|
||||
inkCanvas.Strokes.Save(fs);
|
||||
fs.Close();
|
||||
}
|
||||
}
|
||||
|
||||
// 显示提示
|
||||
if (newNotice) ShowNotification("墨迹成功全页面保存至 " + Path.ChangeExtension(savePathWithName, "png"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将指定墨迹集合保存为图像到指定流
|
||||
/// </summary>
|
||||
private void SavePageAsImage(StrokeCollection strokes, Stream outputStream)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 创建临时InkCanvas来渲染墨迹
|
||||
var tempCanvas = new InkCanvas();
|
||||
tempCanvas.Strokes = strokes;
|
||||
tempCanvas.Width = inkCanvas.ActualWidth;
|
||||
tempCanvas.Height = inkCanvas.ActualHeight;
|
||||
|
||||
// 创建渲染位图
|
||||
var rtb = new RenderTargetBitmap(
|
||||
(int)tempCanvas.Width, (int)tempCanvas.Height,
|
||||
96, 96,
|
||||
PixelFormats.Pbgra32);
|
||||
rtb.Render(tempCanvas);
|
||||
|
||||
// 保存为PNG
|
||||
var encoder = new PngBitmapEncoder();
|
||||
encoder.Frames.Add(BitmapFrame.Create(rtb));
|
||||
encoder.Save(outputStream);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"保存页面图像失败: {ex.ToString()}", LogHelper.LogType.Error);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void SymbolIconOpenStrokes_MouseUp(object sender, MouseButtonEventArgs e) {
|
||||
if (lastBorderMouseDownObject != sender) return;
|
||||
AnimationsHelper.HideWithSlideAndFade(BorderTools);
|
||||
@@ -123,13 +312,237 @@ namespace Ink_Canvas {
|
||||
var openFileDialog = new OpenFileDialog();
|
||||
openFileDialog.InitialDirectory = Settings.Automation.AutoSavedStrokesLocation;
|
||||
openFileDialog.Title = "打开墨迹文件";
|
||||
openFileDialog.Filter = "Ink Canvas Strokes File (*.icstk)|*.icstk";
|
||||
openFileDialog.Filter = "Ink Canvas Strokes File (*.icstk)|*.icstk|ICC压缩包 (*.zip)|*.zip";
|
||||
if (openFileDialog.ShowDialog() != true) return;
|
||||
LogHelper.WriteLogToFile($"Strokes Insert: Name: {openFileDialog.FileName}",
|
||||
LogHelper.LogType.Event);
|
||||
|
||||
try {
|
||||
string fileExtension = Path.GetExtension(openFileDialog.FileName).ToLower();
|
||||
|
||||
if (fileExtension == ".zip") {
|
||||
// 处理ICC压缩包
|
||||
OpenICCZipFile(openFileDialog.FileName);
|
||||
} else {
|
||||
// 处理单个墨迹文件
|
||||
OpenSingleStrokeFile(openFileDialog.FileName);
|
||||
}
|
||||
|
||||
if (inkCanvas.Visibility != Visibility.Visible) SymbolIconCursor_Click(sender, null);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ShowNotification("墨迹打开失败");
|
||||
LogHelper.WriteLogToFile($"墨迹打开失败: {ex.ToString()}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开ICC创建的.zip压缩包
|
||||
/// </summary>
|
||||
private void OpenICCZipFile(string zipFilePath) {
|
||||
try {
|
||||
// 创建临时目录来解压文件
|
||||
string tempDir = Path.Combine(Path.GetTempPath(), $"InkCanvas_Open_{DateTime.Now:yyyyMMdd_HHmmss}");
|
||||
Directory.CreateDirectory(tempDir);
|
||||
|
||||
try {
|
||||
// 解压ZIP文件
|
||||
System.IO.Compression.ZipFile.ExtractToDirectory(zipFilePath, tempDir);
|
||||
|
||||
// 读取元数据文件
|
||||
string metadataFile = Path.Combine(tempDir, "metadata.txt");
|
||||
if (!File.Exists(metadataFile)) {
|
||||
throw new Exception("压缩包中未找到元数据文件");
|
||||
}
|
||||
|
||||
var metadata = ReadMetadataFile(metadataFile);
|
||||
|
||||
// 根据元数据信息决定恢复模式
|
||||
bool isPPTMode = metadata.ContainsKey("模式") && metadata["模式"].Contains("PPT放映");
|
||||
bool isWhiteboardMode = metadata.ContainsKey("模式") && metadata["模式"].Contains("白板");
|
||||
|
||||
// 检查当前是否处于PPT模式
|
||||
bool isCurrentlyInPPTMode = BtnPPTSlideShowEnd.Visibility == Visibility.Visible && pptApplication != null;
|
||||
|
||||
// 检查当前是否处于白板模式
|
||||
bool isCurrentlyInWhiteboardMode = currentMode != 0;
|
||||
|
||||
// 严格模式隔离:只在对应模式下恢复对应墨迹
|
||||
if (isPPTMode && isCurrentlyInPPTMode) {
|
||||
// 只在PPT放映模式下恢复PPT墨迹
|
||||
RestorePPTStrokesFromZip(tempDir, metadata);
|
||||
} else if (isWhiteboardMode && isCurrentlyInWhiteboardMode) {
|
||||
// 只在白板模式下恢复白板墨迹
|
||||
RestoreWhiteboardStrokesFromZip(tempDir, metadata);
|
||||
} else {
|
||||
// 模式不匹配时,显示提示信息
|
||||
string savedMode = isPPTMode ? "PPT放映" : (isWhiteboardMode ? "白板" : "未知");
|
||||
string currentMode = isCurrentlyInPPTMode ? "PPT放映" : (isCurrentlyInWhiteboardMode ? "白板" : "桌面");
|
||||
ShowNotification($"墨迹保存模式({savedMode})与当前模式({currentMode})不匹配,无法恢复墨迹");
|
||||
LogHelper.WriteLogToFile($"模式不匹配:保存模式={savedMode},当前模式={currentMode}", LogHelper.LogType.Warning);
|
||||
}
|
||||
|
||||
ShowNotification($"成功打开ICC压缩包,共{(metadata.ContainsKey("总页数") ? metadata["总页数"] : "0")}页");
|
||||
}
|
||||
finally {
|
||||
// 清理临时目录
|
||||
try {
|
||||
if (Directory.Exists(tempDir))
|
||||
Directory.Delete(tempDir, true);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
LogHelper.WriteLogToFile($"清理临时目录失败: {ex.ToString()}", LogHelper.LogType.Warning);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
LogHelper.WriteLogToFile($"打开ICC压缩包失败: {ex.ToString()}", LogHelper.LogType.Error);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取元数据文件
|
||||
/// </summary>
|
||||
private Dictionary<string, string> ReadMetadataFile(string metadataPath) {
|
||||
var metadata = new Dictionary<string, string>();
|
||||
|
||||
using (var reader = new StreamReader(metadataPath, System.Text.Encoding.UTF8)) {
|
||||
string line;
|
||||
while ((line = reader.ReadLine()) != null) {
|
||||
if (line.Contains(":")) {
|
||||
var parts = line.Split(new[] { ':' }, 2);
|
||||
if (parts.Length == 2) {
|
||||
metadata[parts[0].Trim()] = parts[1].Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return metadata;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从ZIP文件恢复PPT墨迹
|
||||
/// </summary>
|
||||
private void RestorePPTStrokesFromZip(string tempDir, Dictionary<string, string> metadata) {
|
||||
try {
|
||||
// 确保当前处于PPT放映模式
|
||||
if (BtnPPTSlideShowEnd.Visibility != Visibility.Visible || pptApplication == null) {
|
||||
throw new InvalidOperationException("当前不在PPT放映模式,无法恢复PPT墨迹");
|
||||
}
|
||||
|
||||
// 清空当前墨迹
|
||||
ClearStrokes(true);
|
||||
timeMachine.ClearStrokeHistory();
|
||||
|
||||
// 重置PPT墨迹存储
|
||||
if (memoryStreams == null) {
|
||||
memoryStreams = new MemoryStream[50];
|
||||
}
|
||||
|
||||
// 读取所有页面的墨迹文件
|
||||
var files = Directory.GetFiles(tempDir, "page_*.icstk");
|
||||
foreach (var file in files) {
|
||||
var fileName = Path.GetFileNameWithoutExtension(file);
|
||||
if (fileName.StartsWith("page_") && int.TryParse(fileName.Substring(5), out int pageNumber)) {
|
||||
using (var fs = new FileStream(file, FileMode.Open, FileAccess.Read)) {
|
||||
var strokes = new StrokeCollection(fs);
|
||||
if (strokes.Count > 0) {
|
||||
var ms = new MemoryStream();
|
||||
strokes.Save(ms);
|
||||
ms.Position = 0;
|
||||
memoryStreams[pageNumber] = ms;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 恢复当前页面的墨迹
|
||||
if (pptApplication.SlideShowWindows.Count > 0) {
|
||||
int currentSlide = pptApplication.SlideShowWindows[1].View.CurrentShowPosition;
|
||||
if (memoryStreams[currentSlide] != null && memoryStreams[currentSlide].Length > 0) {
|
||||
memoryStreams[currentSlide].Position = 0;
|
||||
inkCanvas.Strokes.Add(new StrokeCollection(memoryStreams[currentSlide]));
|
||||
}
|
||||
previousSlideID = currentSlide;
|
||||
}
|
||||
|
||||
LogHelper.WriteLogToFile($"成功恢复PPT墨迹,共{files.Length}页");
|
||||
}
|
||||
catch (Exception ex) {
|
||||
LogHelper.WriteLogToFile($"恢复PPT墨迹失败: {ex.ToString()}", LogHelper.LogType.Error);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从ZIP文件恢复白板墨迹
|
||||
/// </summary>
|
||||
private void RestoreWhiteboardStrokesFromZip(string tempDir, Dictionary<string, string> metadata) {
|
||||
try {
|
||||
// 确保当前处于白板模式
|
||||
if (currentMode == 0) {
|
||||
throw new InvalidOperationException("当前不在白板模式,无法恢复白板墨迹");
|
||||
}
|
||||
|
||||
// 清空当前墨迹
|
||||
ClearStrokes(true);
|
||||
timeMachine.ClearStrokeHistory();
|
||||
|
||||
// 读取总页数
|
||||
int totalPages = 1;
|
||||
if (metadata.ContainsKey("总页数") && int.TryParse(metadata["总页数"], out int parsedPages)) {
|
||||
totalPages = parsedPages;
|
||||
}
|
||||
|
||||
// 重置白板状态
|
||||
WhiteboardTotalCount = totalPages;
|
||||
CurrentWhiteboardIndex = 1;
|
||||
|
||||
// 清空历史记录
|
||||
for (int i = 0; i < TimeMachineHistories.Length; i++) {
|
||||
TimeMachineHistories[i] = null;
|
||||
}
|
||||
|
||||
// 读取所有页面的墨迹文件
|
||||
var files = Directory.GetFiles(tempDir, "page_*.icstk");
|
||||
foreach (var file in files) {
|
||||
var fileName = Path.GetFileNameWithoutExtension(file);
|
||||
if (fileName.StartsWith("page_") && int.TryParse(fileName.Substring(5), out int pageNumber)) {
|
||||
using (var fs = new FileStream(file, FileMode.Open, FileAccess.Read)) {
|
||||
var strokes = new StrokeCollection(fs);
|
||||
if (strokes.Count > 0) {
|
||||
// 创建历史记录
|
||||
var history = new TimeMachineHistory(strokes, TimeMachineHistoryType.UserInput, false);
|
||||
TimeMachineHistories[pageNumber] = new TimeMachineHistory[] { history };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 恢复第一页的墨迹
|
||||
if (TimeMachineHistories[1] != null) {
|
||||
RestoreStrokes();
|
||||
}
|
||||
|
||||
// 更新UI显示
|
||||
UpdateIndexInfoDisplay();
|
||||
|
||||
LogHelper.WriteLogToFile($"成功恢复白板墨迹,共{totalPages}页");
|
||||
}
|
||||
catch (Exception ex) {
|
||||
LogHelper.WriteLogToFile($"恢复白板墨迹失败: {ex.ToString()}", LogHelper.LogType.Error);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开单个墨迹文件
|
||||
/// </summary>
|
||||
private void OpenSingleStrokeFile(string filePath) {
|
||||
var fileStreamHasNoStroke = false;
|
||||
using (var fs = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read)) {
|
||||
using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)) {
|
||||
var strokes = new StrokeCollection(fs);
|
||||
fileStreamHasNoStroke = strokes.Count == 0;
|
||||
if (!fileStreamHasNoStroke) {
|
||||
@@ -141,19 +554,13 @@ namespace Ink_Canvas {
|
||||
}
|
||||
|
||||
if (fileStreamHasNoStroke)
|
||||
using (var ms = new MemoryStream(File.ReadAllBytes(openFileDialog.FileName))) {
|
||||
using (var ms = new MemoryStream(File.ReadAllBytes(filePath))) {
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
var strokes = new StrokeCollection(ms);
|
||||
ClearStrokes(true);
|
||||
timeMachine.ClearStrokeHistory();
|
||||
inkCanvas.Strokes.Add(strokes);
|
||||
LogHelper.NewLog($"Strokes Insert (2): Strokes Count: {strokes.Count.ToString()}");
|
||||
}
|
||||
|
||||
if (inkCanvas.Visibility != Visibility.Visible) SymbolIconCursor_Click(sender, null);
|
||||
}
|
||||
catch {
|
||||
ShowNotification("墨迹打开失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,6 +244,7 @@ namespace Ink_Canvas {
|
||||
}
|
||||
|
||||
private void BtnSelect_Click(object sender, RoutedEventArgs e) {
|
||||
ExitMultiTouchModeIfNeeded();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 0;
|
||||
inkCanvas.IsManipulationEnabled = false;
|
||||
@@ -422,5 +423,26 @@ namespace Ink_Canvas {
|
||||
StrokesSelectionClone = new StrokeCollection();
|
||||
}
|
||||
}
|
||||
|
||||
private void LassoSelect_Click(object sender, RoutedEventArgs e) {
|
||||
ExitMultiTouchModeIfNeeded();
|
||||
forceEraser = false;
|
||||
forcePointEraser = false;
|
||||
isLastTouchEraser = false;
|
||||
drawingShapeMode = 0;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.Select;
|
||||
SetCursorBasedOnEditingMode(inkCanvas);
|
||||
}
|
||||
|
||||
private void BtnLassoSelect_Click(object sender, RoutedEventArgs e) {
|
||||
ExitMultiTouchModeIfNeeded();
|
||||
forceEraser = false;
|
||||
forcePointEraser = false;
|
||||
isLastTouchEraser = false;
|
||||
drawingShapeMode = 0;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.Select;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
SetCursorBasedOnEditingMode(inkCanvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,8 @@ using System.Windows.Media.Imaging;
|
||||
using System.Windows.Interop;
|
||||
using Hardcodet.Wpf.TaskbarNotification;
|
||||
using OSVersionExtension;
|
||||
using Microsoft.Win32;
|
||||
using System.IO;
|
||||
|
||||
namespace Ink_Canvas {
|
||||
public partial class MainWindow : Window {
|
||||
@@ -867,12 +869,19 @@ namespace Ink_Canvas {
|
||||
private void ComboBoxEraserSize_SelectionChanged(object sender, SelectionChangedEventArgs e) {
|
||||
if (!isLoaded) return;
|
||||
Settings.Canvas.EraserSize = ComboBoxEraserSize.SelectedIndex;
|
||||
|
||||
// 使用新的高级橡皮擦形状应用方法
|
||||
ApplyAdvancedEraserShape();
|
||||
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint) {
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
|
||||
}
|
||||
SaveSettingsToFile();
|
||||
}
|
||||
|
||||
private void ComboBoxEraserSizeFloatingBar_SelectionChanged(object sender, SelectionChangedEventArgs e) {
|
||||
if (!isLoaded) return;
|
||||
|
||||
ComboBox s = (ComboBox)sender;
|
||||
Settings.Canvas.EraserSize = s.SelectedIndex;
|
||||
if (s == ComboBoxEraserSizeFloatingBar) {
|
||||
@@ -882,17 +891,14 @@ namespace Ink_Canvas {
|
||||
ComboBoxEraserSizeFloatingBar.SelectedIndex = s.SelectedIndex;
|
||||
ComboBoxEraserSize.SelectedIndex = s.SelectedIndex;
|
||||
}
|
||||
|
||||
// 使用统一的方法应用橡皮擦形状
|
||||
ApplyCurrentEraserShape();
|
||||
|
||||
// 确保当前处于橡皮擦模式时能立即看到效果
|
||||
|
||||
// 使用新的高级橡皮擦形状应用方法
|
||||
ApplyAdvancedEraserShape();
|
||||
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint) {
|
||||
// 先切换一下模式,再切回来,确保橡皮擦形状得到刷新
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
|
||||
}
|
||||
|
||||
SaveSettingsToFile();
|
||||
}
|
||||
|
||||
@@ -901,10 +907,10 @@ namespace Ink_Canvas {
|
||||
Settings.Canvas.EraserShapeType = 0;
|
||||
SaveSettingsToFile();
|
||||
CheckEraserTypeTab();
|
||||
|
||||
// 使用统一的方法应用橡皮擦形状
|
||||
ApplyCurrentEraserShape();
|
||||
|
||||
|
||||
// 使用新的高级橡皮擦形状应用方法
|
||||
ApplyAdvancedEraserShape();
|
||||
|
||||
// 确保当前处于橡皮擦模式时能立即看到效果
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
|
||||
@@ -915,10 +921,10 @@ namespace Ink_Canvas {
|
||||
Settings.Canvas.EraserShapeType = 1;
|
||||
SaveSettingsToFile();
|
||||
CheckEraserTypeTab();
|
||||
|
||||
// 使用统一的方法应用橡皮擦形状
|
||||
ApplyCurrentEraserShape();
|
||||
|
||||
|
||||
// 使用新的高级橡皮擦形状应用方法
|
||||
ApplyAdvancedEraserShape();
|
||||
|
||||
// 确保当前处于橡皮擦模式时能立即看到效果
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
|
||||
@@ -1813,6 +1819,100 @@ namespace Ink_Canvas {
|
||||
Settings.Advanced.IsSecondConfirmWhenShutdownApp = ToggleSwitchIsSecondConfimeWhenShutdownApp.IsOn;
|
||||
SaveSettingsToFile();
|
||||
}
|
||||
|
||||
private void ToggleSwitchIsAutoBackupBeforeUpdate_Toggled(object sender, RoutedEventArgs e) {
|
||||
if (!isLoaded) return;
|
||||
Settings.Advanced.IsAutoBackupBeforeUpdate = ToggleSwitchIsAutoBackupBeforeUpdate.IsOn;
|
||||
SaveSettingsToFile();
|
||||
}
|
||||
|
||||
private void BtnManualBackup_Click(object sender, RoutedEventArgs e) {
|
||||
if (!isLoaded) return;
|
||||
|
||||
try {
|
||||
// 确保Backups目录存在
|
||||
string backupDir = Path.Combine(App.RootPath, "Backups");
|
||||
if (!Directory.Exists(backupDir)) {
|
||||
Directory.CreateDirectory(backupDir);
|
||||
LogHelper.WriteLogToFile($"创建备份目录: {backupDir}", LogHelper.LogType.Info);
|
||||
}
|
||||
|
||||
// 创建备份文件名(使用当前日期时间)
|
||||
string backupFileName = $"Settings_Backup_{DateTime.Now:yyyyMMdd_HHmmss}.json";
|
||||
string backupPath = Path.Combine(backupDir, backupFileName);
|
||||
|
||||
// 序列化当前设置并保存到备份文件
|
||||
string settingsJson = JsonConvert.SerializeObject(Settings, Formatting.Indented);
|
||||
File.WriteAllText(backupPath, settingsJson);
|
||||
|
||||
LogHelper.WriteLogToFile($"成功创建设置备份: {backupPath}", LogHelper.LogType.Info);
|
||||
MessageBox.Show($"设置已成功备份到:\n{backupPath}", "备份成功", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
LogHelper.WriteLogToFile($"创建设置备份时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
MessageBox.Show($"创建备份失败: {ex.Message}", "备份失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnRestoreBackup_Click(object sender, RoutedEventArgs e) {
|
||||
if (!isLoaded) return;
|
||||
|
||||
try {
|
||||
// 确保Backups目录存在
|
||||
string backupDir = Path.Combine(App.RootPath, "Backups");
|
||||
if (!Directory.Exists(backupDir)) {
|
||||
Directory.CreateDirectory(backupDir);
|
||||
LogHelper.WriteLogToFile($"创建备份目录: {backupDir}", LogHelper.LogType.Info);
|
||||
MessageBox.Show("没有找到备份文件,请先创建备份", "还原失败", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
// 打开文件选择对话框
|
||||
OpenFileDialog dlg = new OpenFileDialog();
|
||||
dlg.InitialDirectory = backupDir;
|
||||
dlg.Filter = "设置备份文件|Settings_Backup_*.json|所有JSON文件|*.json";
|
||||
dlg.Title = "选择要还原的备份文件";
|
||||
|
||||
if (dlg.ShowDialog() == true) {
|
||||
// 读取备份文件
|
||||
string backupJson = File.ReadAllText(dlg.FileName);
|
||||
|
||||
// 反序列化备份数据
|
||||
Settings backupSettings = JsonConvert.DeserializeObject<Settings>(backupJson);
|
||||
|
||||
if (backupSettings != null) {
|
||||
// 确认是否要还原
|
||||
if (MessageBox.Show("确定要还原选择的备份文件吗?当前设置将被覆盖。", "确认还原",
|
||||
MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) {
|
||||
|
||||
// 备份当前设置,以防出错
|
||||
string currentSettingsJson = JsonConvert.SerializeObject(Settings, Formatting.Indented);
|
||||
string tempBackupPath = Path.Combine(backupDir, $"Settings_Before_Restore_{DateTime.Now:yyyyMMdd_HHmmss}.json");
|
||||
File.WriteAllText(tempBackupPath, currentSettingsJson);
|
||||
|
||||
// 还原设置
|
||||
Settings = backupSettings;
|
||||
|
||||
// 保存还原后的设置到文件
|
||||
SaveSettingsToFile();
|
||||
|
||||
// 重新加载设置到UI
|
||||
LoadSettings();
|
||||
|
||||
LogHelper.WriteLogToFile($"成功从备份还原设置: {dlg.FileName}", LogHelper.LogType.Info);
|
||||
MessageBox.Show("设置已成功还原,部分设置可能需要重启软件后生效。", "还原成功", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
else {
|
||||
MessageBox.Show("无法解析备份文件,文件可能已损坏", "还原失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
LogHelper.WriteLogToFile($"还原设置备份时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
MessageBox.Show($"还原备份失败: {ex.Message}", "还原失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1892,14 +1992,42 @@ namespace Ink_Canvas {
|
||||
HideSubPanels();
|
||||
}
|
||||
|
||||
private void UpdateChannelSelector_Checked(object sender, RoutedEventArgs e) {
|
||||
private async void UpdateChannelSelector_Checked(object sender, RoutedEventArgs e) {
|
||||
if (!isLoaded) return;
|
||||
var radioButton = sender as System.Windows.Controls.RadioButton;
|
||||
if (radioButton != null) {
|
||||
string channel = radioButton.Tag.ToString();
|
||||
Settings.Startup.UpdateChannel = channel == "Beta" ? UpdateChannel.Beta : UpdateChannel.Release;
|
||||
UpdateChannel newChannel = channel == "Beta" ? UpdateChannel.Beta : UpdateChannel.Release;
|
||||
|
||||
// 如果通道没有变化,不需要执行更新检查
|
||||
if (Settings.Startup.UpdateChannel == newChannel) {
|
||||
return;
|
||||
}
|
||||
|
||||
Settings.Startup.UpdateChannel = newChannel;
|
||||
LogHelper.WriteLogToFile($"Settings | Update channel changed to {Settings.Startup.UpdateChannel}");
|
||||
SaveSettingsToFile();
|
||||
|
||||
// 如果启用了自动更新,立即执行完整的检查更新操作
|
||||
if (Settings.Startup.IsAutoUpdate) {
|
||||
LogHelper.WriteLogToFile($"AutoUpdate | Channel changed to {newChannel}, performing immediate update check");
|
||||
|
||||
// 执行完整的更新检查
|
||||
await Task.Run(async () => {
|
||||
try {
|
||||
// 调用主窗口的AutoUpdate方法,它会自动清除之前的更新状态并使用新通道重新检查
|
||||
Dispatcher.Invoke(() => {
|
||||
AutoUpdate();
|
||||
});
|
||||
}
|
||||
catch (Exception ex) {
|
||||
LogHelper.WriteLogToFile($"AutoUpdate | Error during channel switch update check: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
LogHelper.WriteLogToFile($"AutoUpdate | Channel changed to {newChannel}, but auto-update is disabled");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -555,6 +555,7 @@ namespace Ink_Canvas {
|
||||
ToggleSwitchIsEnableResolutionChangeDetection.IsOn = Settings.Advanced.IsEnableResolutionChangeDetection;
|
||||
ToggleSwitchIsEnableDPIChangeDetection.IsOn = Settings.Advanced.IsEnableDPIChangeDetection;
|
||||
ToggleSwitchIsEnableAvoidFullScreenHelper.IsOn = Settings.Advanced.IsEnableAvoidFullScreenHelper;
|
||||
ToggleSwitchIsAutoBackupBeforeUpdate.IsOn = Settings.Advanced.IsAutoBackupBeforeUpdate;
|
||||
if (Settings.Advanced.IsEnableFullScreenHelper) {
|
||||
FullScreenHelper.MarkFullscreenWindowTaskbarList(new WindowInteropHelper(this).Handle, true);
|
||||
}
|
||||
|
||||
@@ -103,12 +103,23 @@ namespace Ink_Canvas {
|
||||
}
|
||||
|
||||
private void BtnPen_Click(object sender, RoutedEventArgs e) {
|
||||
// 禁用高级橡皮擦系统
|
||||
DisableAdvancedEraserSystem();
|
||||
|
||||
// 如果当前已是批注模式,再次点击弹出批注子面板
|
||||
if (penType == 0 && inkCanvas.EditingMode == InkCanvasEditingMode.Ink && !drawingAttributes.IsHighlighter) {
|
||||
return;
|
||||
}
|
||||
// 否则只切换到批注模式,不弹出子面板
|
||||
forceEraser = false;
|
||||
forcePointEraser = false;
|
||||
isLastTouchEraser = false;
|
||||
drawingShapeMode = 0;
|
||||
penType = 0;
|
||||
drawingAttributes.IsHighlighter = false;
|
||||
drawingAttributes.StylusTip = StylusTip.Ellipse;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
CancelSingleFingerDragMode();
|
||||
isLongPressSelected = false;
|
||||
SetCursorBasedOnEditingMode(inkCanvas);
|
||||
}
|
||||
|
||||
private Task<bool> CheckIsDrawingShapesInMultiTouchMode() {
|
||||
@@ -131,349 +142,260 @@ namespace Ink_Canvas {
|
||||
|
||||
private async void BtnDrawLine_Click(object sender, MouseButtonEventArgs e) {
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
if (lastMouseDownSender == sender) {
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 1;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
CancelSingleFingerDragMode();
|
||||
}
|
||||
else {
|
||||
// 即使不是长按,也设置必要的绘图状态
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 1;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
isLongPressSelected = true; // 设置为选中状态,避免抬笔后切换回笔模式
|
||||
}
|
||||
|
||||
EnterShapeDrawingMode(1);
|
||||
CancelSingleFingerDragMode();
|
||||
lastMouseDownSender = null;
|
||||
if (isLongPressSelected) {
|
||||
if (ToggleSwitchDrawShapeBorderAutoHide.IsOn) CollapseBorderDrawShape();
|
||||
var dA = new DoubleAnimation(1, 1, new Duration(TimeSpan.FromMilliseconds(0)));
|
||||
ImageDrawLine.BeginAnimation(OpacityProperty, dA);
|
||||
}
|
||||
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawDashedLine_Click(object sender, MouseButtonEventArgs e) {
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
if (lastMouseDownSender == sender) {
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 8;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
CancelSingleFingerDragMode();
|
||||
}
|
||||
|
||||
EnterShapeDrawingMode(8);
|
||||
CancelSingleFingerDragMode();
|
||||
lastMouseDownSender = null;
|
||||
if (isLongPressSelected) {
|
||||
if (ToggleSwitchDrawShapeBorderAutoHide.IsOn) CollapseBorderDrawShape();
|
||||
var dA = new DoubleAnimation(1, 1, new Duration(TimeSpan.FromMilliseconds(0)));
|
||||
ImageDrawDashedLine.BeginAnimation(OpacityProperty, dA);
|
||||
}
|
||||
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawDotLine_Click(object sender, MouseButtonEventArgs e) {
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
if (lastMouseDownSender == sender) {
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 18;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
CancelSingleFingerDragMode();
|
||||
}
|
||||
|
||||
EnterShapeDrawingMode(18);
|
||||
CancelSingleFingerDragMode();
|
||||
lastMouseDownSender = null;
|
||||
if (isLongPressSelected) {
|
||||
if (ToggleSwitchDrawShapeBorderAutoHide.IsOn) CollapseBorderDrawShape();
|
||||
var dA = new DoubleAnimation(1, 1, new Duration(TimeSpan.FromMilliseconds(0)));
|
||||
ImageDrawDotLine.BeginAnimation(OpacityProperty, dA);
|
||||
}
|
||||
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawArrow_Click(object sender, MouseButtonEventArgs e) {
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
if (lastMouseDownSender == sender) {
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 2;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
CancelSingleFingerDragMode();
|
||||
}
|
||||
else {
|
||||
// 即使不是长按,也设置必要的绘图状态
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 2;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
isLongPressSelected = true; // 设置为选中状态,避免抬笔后切换回笔模式
|
||||
}
|
||||
|
||||
EnterShapeDrawingMode(2);
|
||||
CancelSingleFingerDragMode();
|
||||
lastMouseDownSender = null;
|
||||
if (isLongPressSelected) {
|
||||
if (ToggleSwitchDrawShapeBorderAutoHide.IsOn) CollapseBorderDrawShape();
|
||||
var dA = new DoubleAnimation(1, 1, new Duration(TimeSpan.FromMilliseconds(0)));
|
||||
ImageDrawArrow.BeginAnimation(OpacityProperty, dA);
|
||||
}
|
||||
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawParallelLine_Click(object sender, MouseButtonEventArgs e) {
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
if (lastMouseDownSender == sender) {
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 15;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
CancelSingleFingerDragMode();
|
||||
}
|
||||
|
||||
EnterShapeDrawingMode(15);
|
||||
CancelSingleFingerDragMode();
|
||||
lastMouseDownSender = null;
|
||||
if (isLongPressSelected) {
|
||||
if (ToggleSwitchDrawShapeBorderAutoHide.IsOn) CollapseBorderDrawShape();
|
||||
var dA = new DoubleAnimation(1, 1, new Duration(TimeSpan.FromMilliseconds(0)));
|
||||
ImageDrawParallelLine.BeginAnimation(OpacityProperty, dA);
|
||||
}
|
||||
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawCoordinate1_Click(object sender, MouseButtonEventArgs e) {
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 11;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
EnterShapeDrawingMode(11);
|
||||
CancelSingleFingerDragMode();
|
||||
lastMouseDownSender = null;
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawCoordinate2_Click(object sender, MouseButtonEventArgs e) {
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 12;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
EnterShapeDrawingMode(12);
|
||||
CancelSingleFingerDragMode();
|
||||
lastMouseDownSender = null;
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawCoordinate3_Click(object sender, MouseButtonEventArgs e) {
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 13;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
EnterShapeDrawingMode(13);
|
||||
CancelSingleFingerDragMode();
|
||||
lastMouseDownSender = null;
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawCoordinate4_Click(object sender, MouseButtonEventArgs e) {
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 14;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
EnterShapeDrawingMode(14);
|
||||
CancelSingleFingerDragMode();
|
||||
lastMouseDownSender = null;
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawCoordinate5_Click(object sender, MouseButtonEventArgs e) {
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 17;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
EnterShapeDrawingMode(17);
|
||||
CancelSingleFingerDragMode();
|
||||
lastMouseDownSender = null;
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawRectangle_Click(object sender, MouseButtonEventArgs e) {
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 3;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
isLongPressSelected = true; // 设置为选中状态,避免抬笔后切换回笔模式
|
||||
EnterShapeDrawingMode(3);
|
||||
CancelSingleFingerDragMode();
|
||||
isLongPressSelected = true; // 设置为选中状态,避免抬笔后切换回笔模式
|
||||
lastMouseDownSender = null;
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawRectangleCenter_Click(object sender, MouseButtonEventArgs e) {
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 19;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
EnterShapeDrawingMode(19);
|
||||
CancelSingleFingerDragMode();
|
||||
lastMouseDownSender = null;
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawEllipse_Click(object sender, MouseButtonEventArgs e) {
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 4;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
EnterShapeDrawingMode(4);
|
||||
CancelSingleFingerDragMode();
|
||||
lastMouseDownSender = null;
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawCircle_Click(object sender, MouseButtonEventArgs e) {
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 5;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
EnterShapeDrawingMode(5);
|
||||
CancelSingleFingerDragMode();
|
||||
lastMouseDownSender = null;
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawCenterEllipse_Click(object sender, MouseButtonEventArgs e) {
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 16;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
EnterShapeDrawingMode(16);
|
||||
CancelSingleFingerDragMode();
|
||||
lastMouseDownSender = null;
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawCenterEllipseWithFocalPoint_Click(object sender, MouseButtonEventArgs e) {
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 23;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
EnterShapeDrawingMode(23);
|
||||
CancelSingleFingerDragMode();
|
||||
lastMouseDownSender = null;
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawDashedCircle_Click(object sender, MouseButtonEventArgs e) {
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 10;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
EnterShapeDrawingMode(10);
|
||||
CancelSingleFingerDragMode();
|
||||
lastMouseDownSender = null;
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawHyperbola_Click(object sender, MouseButtonEventArgs e) {
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 24;
|
||||
EnterShapeDrawingMode(24);
|
||||
drawMultiStepShapeCurrentStep = 0;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
CancelSingleFingerDragMode();
|
||||
lastMouseDownSender = null;
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawHyperbolaWithFocalPoint_Click(object sender, MouseButtonEventArgs e) {
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 25;
|
||||
EnterShapeDrawingMode(25);
|
||||
drawMultiStepShapeCurrentStep = 0;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
CancelSingleFingerDragMode();
|
||||
lastMouseDownSender = null;
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawParabola1_Click(object sender, MouseButtonEventArgs e) {
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 20;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
EnterShapeDrawingMode(20);
|
||||
CancelSingleFingerDragMode();
|
||||
lastMouseDownSender = null;
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawParabolaWithFocalPoint_Click(object sender, MouseButtonEventArgs e) {
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 22;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
EnterShapeDrawingMode(22);
|
||||
CancelSingleFingerDragMode();
|
||||
lastMouseDownSender = null;
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawParabola2_Click(object sender, MouseButtonEventArgs e) {
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 21;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
EnterShapeDrawingMode(21);
|
||||
CancelSingleFingerDragMode();
|
||||
lastMouseDownSender = null;
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawCylinder_Click(object sender, MouseButtonEventArgs e) {
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 6;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
EnterShapeDrawingMode(6);
|
||||
CancelSingleFingerDragMode();
|
||||
lastMouseDownSender = null;
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawCone_Click(object sender, MouseButtonEventArgs e) {
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 7;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
EnterShapeDrawingMode(7);
|
||||
CancelSingleFingerDragMode();
|
||||
lastMouseDownSender = null;
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawCuboid_Click(object sender, MouseButtonEventArgs e) {
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 9;
|
||||
EnterShapeDrawingMode(9);
|
||||
isFirstTouchCuboid = true;
|
||||
CuboidFrontRectIniP = new Point();
|
||||
CuboidFrontRectEndP = new Point();
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
CancelSingleFingerDragMode();
|
||||
lastMouseDownSender = null;
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void inkCanvas_TouchMove(object sender, TouchEventArgs e) {
|
||||
// 确保套索选择模式下触摸移动时光标保持可见
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.Select) {
|
||||
SetCursorBasedOnEditingMode(inkCanvas);
|
||||
}
|
||||
|
||||
// 如果处于手掌擦状态,继续使用相同的橡皮形状
|
||||
if (isLastTouchEraser && currentPalmEraserShape != null) {
|
||||
inkCanvas.EraserShape = currentPalmEraserShape;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
|
||||
return;
|
||||
}
|
||||
|
||||
if (isSingleFingerDragMode) return;
|
||||
|
||||
// 处理形状绘制模式
|
||||
// 处理几何绘制模式
|
||||
if (drawingShapeMode != 0) {
|
||||
if (isLastTouchEraser) return;
|
||||
//EraserContainer.Background = null;
|
||||
//ImageEraser.Visibility = Visibility.Visible;
|
||||
|
||||
// 修复触屏状态下几何绘制功能不可用的问题
|
||||
// 在几何绘制模式下,即使isWaitUntilNextTouchDown为true,也应该处理触摸移动事件
|
||||
// 只有当多点触控时才需要等待下一次触摸
|
||||
if (isWaitUntilNextTouchDown && dec.Count > 1) return;
|
||||
|
||||
if (dec.Count > 1) {
|
||||
isWaitUntilNextTouchDown = true;
|
||||
try {
|
||||
@@ -485,19 +407,19 @@ namespace Ink_Canvas {
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 在几何绘制模式下,确保处理单点触控的移动事件
|
||||
Point touchPoint = e.GetTouchPoint(inkCanvas).Position;
|
||||
MouseTouchMove(touchPoint);
|
||||
return; // 处理完几何绘制后直接返回,不执行后面的代码
|
||||
}
|
||||
|
||||
// 触摸移动时保持自定义光标显示
|
||||
if (inkCanvas.EditingMode != InkCanvasEditingMode.None)
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
|
||||
|
||||
MouseTouchMove(e.GetTouchPoint(inkCanvas).Position);
|
||||
// 其它模式下,允许橡皮、套索、批注等正常工作,不覆盖EditingMode
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint ||
|
||||
inkCanvas.EditingMode == InkCanvasEditingMode.Select ||
|
||||
inkCanvas.EditingMode == InkCanvasEditingMode.Ink) {
|
||||
// 允许正常橡皮、套索、批注
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private int drawMultiStepShapeCurrentStep = 0; //多笔完成的图形 当前所处在的笔画
|
||||
@@ -1317,42 +1239,6 @@ namespace Ink_Canvas {
|
||||
private Point CuboidFrontRectIniP = new Point();
|
||||
private Point CuboidFrontRectEndP = new Point();
|
||||
|
||||
private void Main_Grid_TouchUp(object sender, TouchEventArgs e) {
|
||||
|
||||
inkCanvas.ReleaseAllTouchCaptures();
|
||||
ViewboxFloatingBar.IsHitTestVisible = true;
|
||||
BlackboardUIGridForInkReplay.IsHitTestVisible = true;
|
||||
|
||||
// 在几何绘制模式下,确保正确处理触摸抬起事件
|
||||
if (drawingShapeMode != 0) {
|
||||
// 如果是几何绘制模式,确保将临时绘制的图形添加到永久图形中
|
||||
if (lastTempStroke != null) {
|
||||
// 将临时笔画添加到历史记录中
|
||||
var strokes = new StrokeCollection();
|
||||
strokes.Add(lastTempStroke);
|
||||
timeMachine.CommitStrokeUserInputHistory(strokes);
|
||||
// 清除临时笔画引用,以便下次绘制
|
||||
lastTempStroke = null;
|
||||
}
|
||||
|
||||
if (lastTempStrokeCollection != null && lastTempStrokeCollection.Count > 0) {
|
||||
// 将临时笔画集合添加到历史记录中
|
||||
timeMachine.CommitStrokeUserInputHistory(lastTempStrokeCollection);
|
||||
// 清除临时笔画集合引用,以便下次绘制
|
||||
lastTempStrokeCollection = new StrokeCollection();
|
||||
}
|
||||
|
||||
// 如果不是长按选中的状态,则需要在抬起手指后重置isWaitUntilNextTouchDown
|
||||
if (!isLongPressSelected && dec.Count == 0) {
|
||||
isWaitUntilNextTouchDown = false;
|
||||
}
|
||||
}
|
||||
|
||||
inkCanvas_MouseUp(sender, null);
|
||||
// 修改此处逻辑,在长按选择图形模式下保持isWaitUntilNextTouchDown
|
||||
if (dec.Count == 0 && !isLongPressSelected) isWaitUntilNextTouchDown = false;
|
||||
}
|
||||
|
||||
private Stroke lastTempStroke = null;
|
||||
private StrokeCollection lastTempStrokeCollection = new StrokeCollection();
|
||||
|
||||
@@ -1735,5 +1621,15 @@ namespace Ink_Canvas {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 在MainWindow类中添加:
|
||||
private void EnterShapeDrawingMode(int mode) {
|
||||
forceEraser = true;
|
||||
forcePointEraser = false;
|
||||
isLastTouchEraser = false;
|
||||
drawingShapeMode = mode;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
SetCursorBasedOnEditingMode(inkCanvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -329,9 +329,36 @@ namespace Ink_Canvas {
|
||||
if (!File.Exists(statusFilePath) || File.ReadAllText(statusFilePath).Trim().ToLower() != "true") {
|
||||
LogHelper.WriteLogToFile("AutoUpdate | Update file not downloaded yet");
|
||||
|
||||
// 尝试下载更新文件
|
||||
// 尝试下载更新文件,使用多线路组下载功能
|
||||
Task.Run(async () => {
|
||||
bool isDownloadSuccessful = await AutoUpdateHelper.DownloadSetupFileAndSaveStatus(AvailableLatestVersion);
|
||||
bool isDownloadSuccessful = false;
|
||||
|
||||
try
|
||||
{
|
||||
// 如果主要线路组可用,直接使用
|
||||
if (AvailableLatestLineGroup != null)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"AutoUpdate | 使用主要线路组下载: {AvailableLatestLineGroup.GroupName}");
|
||||
isDownloadSuccessful = await AutoUpdateHelper.DownloadSetupFile(AvailableLatestVersion, AvailableLatestLineGroup);
|
||||
}
|
||||
|
||||
// 如果主要线路组不可用或下载失败,获取所有可用线路组
|
||||
if (!isDownloadSuccessful)
|
||||
{
|
||||
LogHelper.WriteLogToFile("AutoUpdate | 主要线路组不可用或下载失败,获取所有可用线路组");
|
||||
var availableGroups = await AutoUpdateHelper.GetAvailableLineGroupsOrdered(Settings.Startup.UpdateChannel);
|
||||
if (availableGroups.Count > 0)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"AutoUpdate | 使用 {availableGroups.Count} 个可用线路组进行下载");
|
||||
isDownloadSuccessful = await AutoUpdateHelper.DownloadSetupFileWithFallback(AvailableLatestVersion, availableGroups);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"AutoUpdate | 下载更新时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
|
||||
if (isDownloadSuccessful) {
|
||||
LogHelper.WriteLogToFile("AutoUpdate | Update downloaded successfully, will check again for installation");
|
||||
// 重新启动计时器,下次检查时安装
|
||||
|
||||
@@ -15,6 +15,11 @@ namespace Ink_Canvas {
|
||||
#region Multi-Touch
|
||||
|
||||
private bool isInMultiTouchMode = false;
|
||||
private InkCanvasEditingMode prePalmEraserEditingMode = InkCanvasEditingMode.Ink;
|
||||
private List<int> dec = new List<int>();
|
||||
private bool isSingleFingerDragMode = false;
|
||||
private Point centerPoint = new Point(0, 0);
|
||||
private InkCanvasEditingMode lastInkCanvasEditingMode = InkCanvasEditingMode.Ink;
|
||||
|
||||
private void BorderMultiTouchMode_MouseUp(object sender, MouseButtonEventArgs e) {
|
||||
if (isInMultiTouchMode) {
|
||||
@@ -23,7 +28,9 @@ namespace Ink_Canvas {
|
||||
inkCanvas.StylusUp -= MainWindow_StylusUp;
|
||||
inkCanvas.TouchDown -= MainWindow_TouchDown;
|
||||
inkCanvas.TouchDown += Main_Grid_TouchDown;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
|
||||
if (inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint) {
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
|
||||
}
|
||||
inkCanvas.Children.Clear();
|
||||
isInMultiTouchMode = false;
|
||||
|
||||
@@ -43,7 +50,9 @@ namespace Ink_Canvas {
|
||||
inkCanvas.StylusUp += MainWindow_StylusUp;
|
||||
inkCanvas.TouchDown += MainWindow_TouchDown;
|
||||
inkCanvas.TouchDown -= Main_Grid_TouchDown;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
if (inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint) {
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
}
|
||||
inkCanvas.Children.Clear();
|
||||
isInMultiTouchMode = true;
|
||||
}
|
||||
@@ -70,17 +79,22 @@ namespace Ink_Canvas {
|
||||
inkCanvas.EraserShape = currentPalmEraserShape;
|
||||
TouchDownPointsList[e.TouchDevice.Id] = InkCanvasEditingMode.EraseByPoint;
|
||||
isLastTouchEraser = true;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
|
||||
if (inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint) {
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
|
||||
}
|
||||
}
|
||||
else {
|
||||
TouchDownPointsList[e.TouchDevice.Id] = InkCanvasEditingMode.None;
|
||||
// 修复面积擦时不显示橡皮形状:无论 forcePointEraser 状态,均显示 50x50 橡皮
|
||||
inkCanvas.EraserShape = new EllipseStylusShape(50, 50);
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
if (inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint) {
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void MainWindow_StylusDown(object sender, StylusDownEventArgs e) {
|
||||
SetCursorBasedOnEditingMode(inkCanvas);
|
||||
|
||||
inkCanvas.CaptureStylus();
|
||||
ViewboxFloatingBar.IsHitTestVisible = false;
|
||||
@@ -200,7 +214,6 @@ namespace Ink_Canvas {
|
||||
|
||||
private Point iniP = new Point(0, 0);
|
||||
private bool isLastTouchEraser = false;
|
||||
private bool forcePointEraser = true;
|
||||
// 用于记录手掌擦的尺寸和形状
|
||||
private StylusShape currentPalmEraserShape = null;
|
||||
|
||||
@@ -233,108 +246,41 @@ namespace Ink_Canvas {
|
||||
}
|
||||
|
||||
private void Main_Grid_TouchDown(object sender, TouchEventArgs e) {
|
||||
// 确保触摸时显示自定义光标
|
||||
if (Settings.Canvas.IsShowCursor) {
|
||||
inkCanvas.ForceCursor = true;
|
||||
System.Windows.Forms.Cursor.Show();
|
||||
}
|
||||
|
||||
SetCursorBasedOnEditingMode(inkCanvas);
|
||||
inkCanvas.CaptureTouch(e.TouchDevice);
|
||||
ViewboxFloatingBar.IsHitTestVisible = false;
|
||||
BlackboardUIGridForInkReplay.IsHitTestVisible = false;
|
||||
|
||||
if (!isHidingSubPanelsWhenInking) {
|
||||
isHidingSubPanelsWhenInking = true;
|
||||
HideSubPanels(); // 书写时自动隐藏二级菜单
|
||||
}
|
||||
|
||||
if (NeedUpdateIniP()) iniP = e.GetTouchPoint(inkCanvas).Position;
|
||||
if (drawingShapeMode == 9 && isFirstTouchCuboid == false) MouseTouchMove(iniP);
|
||||
inkCanvas.Opacity = 1;
|
||||
|
||||
// 如果已处于多指书写模式,禁用手掌擦功能
|
||||
if (isInMultiTouchMode) {
|
||||
isLastTouchEraser = false;
|
||||
currentPalmEraserShape = null;
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint) {
|
||||
// 橡皮状态下只return,保证橡皮状态可保持
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果已经处于手掌擦状态,保持状态不变
|
||||
if (isLastTouchEraser && currentPalmEraserShape != null) {
|
||||
inkCanvas.EraserShape = currentPalmEraserShape;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.Select) {
|
||||
// 套索选状态下只return,保证套索选可用
|
||||
return;
|
||||
}
|
||||
|
||||
double boundsWidth = GetTouchBoundWidth(e), eraserMultiplier = 1.0;
|
||||
if (!Settings.Advanced.EraserBindTouchMultiplier && Settings.Advanced.IsSpecialScreen)
|
||||
eraserMultiplier = 1 / Settings.Advanced.TouchMultiplier;
|
||||
|
||||
// 检查触控点数量,只有大于等于三个触控点时才激活手掌擦功能
|
||||
if (dec.Count >= 3 && boundsWidth > BoundsWidth) {
|
||||
// 保存当前的编辑模式,以便恢复
|
||||
if (!isLastTouchEraser) {
|
||||
prePalmEraserEditingMode = inkCanvas.EditingMode;
|
||||
// 模拟点击橡皮选项卡
|
||||
EraserIcon_Click(null, null);
|
||||
}
|
||||
|
||||
isLastTouchEraser = true;
|
||||
if (drawingShapeMode == 0 && forceEraser) return;
|
||||
if (boundsWidth > BoundsWidth * 2.5) {
|
||||
// 直接使用固定尺寸的矩形黑板擦形状,不随触控面积动态变化
|
||||
currentPalmEraserShape = GetPalmRectangleEraserShape(eraserMultiplier);
|
||||
inkCanvas.EraserShape = currentPalmEraserShape;
|
||||
TouchDownPointsList[e.TouchDevice.Id] = InkCanvasEditingMode.EraseByPoint;
|
||||
}
|
||||
else {
|
||||
if (StackPanelPPTControls.Visibility == Visibility.Visible && inkCanvas.Strokes.Count == 0 &&
|
||||
Settings.PowerPointSettings.IsEnableFingerGestureSlideShowControl) {
|
||||
isLastTouchEraser = false;
|
||||
currentPalmEraserShape = null;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.GestureOnly;
|
||||
inkCanvas.Opacity = 0.1;
|
||||
}
|
||||
else {
|
||||
// 手掌橡皮固定为矩形黑板擦,大小由设置决定
|
||||
currentPalmEraserShape = GetPalmRectangleEraserShape(eraserMultiplier);
|
||||
inkCanvas.EraserShape = currentPalmEraserShape;
|
||||
TouchDownPointsList[e.TouchDevice.Id] = InkCanvasEditingMode.EraseByPoint;
|
||||
}
|
||||
if (drawingShapeMode == 9) {
|
||||
if (isFirstTouchCuboid) {
|
||||
CuboidFrontRectIniP = e.GetTouchPoint(inkCanvas).Position;
|
||||
}
|
||||
// 允许MouseTouchMove在TouchMove时处理
|
||||
return;
|
||||
}
|
||||
else {
|
||||
isLastTouchEraser = false;
|
||||
currentPalmEraserShape = null;
|
||||
// 修复面积擦时不显示橡皮形状:无论 forcePointEraser 状态,均显示 50x50 橡皮
|
||||
inkCanvas.EraserShape = new EllipseStylusShape(50, 50);
|
||||
// 修复触屏状态下几何绘制功能不可用的问题:在几何绘制模式下不应该因为forceEraser而直接返回
|
||||
if (forceEraser && drawingShapeMode == 0) return;
|
||||
if (drawingShapeMode != 0) {
|
||||
return;
|
||||
}
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.Ink) {
|
||||
return;
|
||||
}
|
||||
if (inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint) {
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
|
||||
}
|
||||
}
|
||||
|
||||
private double GetTouchBoundWidth(TouchEventArgs e) {
|
||||
var args = e.GetTouchPoint(null).Bounds;
|
||||
double value;
|
||||
if (!Settings.Advanced.IsQuadIR) value = args.Width;
|
||||
else value = Math.Sqrt(args.Width * args.Height); //四边红外
|
||||
if (Settings.Advanced.IsSpecialScreen) value *= Settings.Advanced.TouchMultiplier;
|
||||
return value;
|
||||
}
|
||||
|
||||
//记录触摸设备ID
|
||||
private List<int> dec = new List<int>();
|
||||
|
||||
//中心点
|
||||
private Point centerPoint;
|
||||
private InkCanvasEditingMode lastInkCanvasEditingMode = InkCanvasEditingMode.Ink;
|
||||
private bool isSingleFingerDragMode = false;
|
||||
|
||||
// 保存触发手掌擦前的编辑模式,用于手掌擦结束后恢复
|
||||
private InkCanvasEditingMode prePalmEraserEditingMode = InkCanvasEditingMode.Ink;
|
||||
|
||||
private void inkCanvas_PreviewTouchDown(object sender, TouchEventArgs e) {
|
||||
// 橡皮状态下不做任何切换,直接return,保证橡皮可持续
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint) {
|
||||
return;
|
||||
}
|
||||
SetCursorBasedOnEditingMode(inkCanvas);
|
||||
|
||||
inkCanvas.CaptureTouch(e.TouchDevice);
|
||||
ViewboxFloatingBar.IsHitTestVisible = false;
|
||||
@@ -346,6 +292,11 @@ namespace Ink_Canvas {
|
||||
var touchPoint = e.GetTouchPoint(inkCanvas);
|
||||
centerPoint = touchPoint.Position;
|
||||
|
||||
// 新增:几何绘制模式下,记录初始点
|
||||
if (drawingShapeMode != 0) {
|
||||
iniP = touchPoint.Position;
|
||||
}
|
||||
|
||||
//记录第一根手指点击时的 StrokeCollection
|
||||
lastTouchDownStrokeCollection = inkCanvas.Strokes.Clone();
|
||||
}
|
||||
@@ -355,19 +306,37 @@ namespace Ink_Canvas {
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.None ||
|
||||
inkCanvas.EditingMode == InkCanvasEditingMode.Select) return;
|
||||
lastInkCanvasEditingMode = inkCanvas.EditingMode;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
if (inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint) {
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void inkCanvas_PreviewTouchUp(object sender, TouchEventArgs e) {
|
||||
// 橡皮状态下不做任何切换,直接return,保证橡皮可持续
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.EraseByPoint) {
|
||||
return;
|
||||
}
|
||||
inkCanvas.ReleaseAllTouchCaptures();
|
||||
ViewboxFloatingBar.IsHitTestVisible = true;
|
||||
BlackboardUIGridForInkReplay.IsHitTestVisible = true;
|
||||
|
||||
// 新增:几何绘制模式下,触摸抬手时自动落笔
|
||||
if (drawingShapeMode != 0) {
|
||||
var mouseArgs = new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Left)
|
||||
{
|
||||
RoutedEvent = UIElement.MouseLeftButtonUpEvent,
|
||||
Source = inkCanvas
|
||||
};
|
||||
inkCanvas_MouseUp(inkCanvas, mouseArgs);
|
||||
}
|
||||
|
||||
//手势完成后切回之前的状态
|
||||
if (dec.Count > 1)
|
||||
if (inkCanvas.EditingMode == InkCanvasEditingMode.None)
|
||||
inkCanvas.EditingMode = lastInkCanvasEditingMode;
|
||||
if (lastInkCanvasEditingMode != InkCanvasEditingMode.EraseByPoint) {
|
||||
inkCanvas.EditingMode = lastInkCanvasEditingMode;
|
||||
}
|
||||
dec.Remove(e.TouchDevice.Id);
|
||||
inkCanvas.Opacity = 1;
|
||||
|
||||
@@ -415,7 +384,9 @@ namespace Ink_Canvas {
|
||||
private void Main_Grid_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e) {
|
||||
if (e.Manipulators.Count() != 0) return;
|
||||
if (forceEraser) return;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
|
||||
if (inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint) {
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
|
||||
}
|
||||
}
|
||||
|
||||
private void Main_Grid_ManipulationDelta(object sender, ManipulationDeltaEventArgs e) {
|
||||
@@ -508,5 +479,43 @@ namespace Ink_Canvas {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 退出多指书写模式,恢复InkCanvas的TouchDown事件绑定
|
||||
private void ExitMultiTouchModeIfNeeded()
|
||||
{
|
||||
if (isInMultiTouchMode)
|
||||
{
|
||||
inkCanvas.StylusDown -= MainWindow_StylusDown;
|
||||
inkCanvas.StylusMove -= MainWindow_StylusMove;
|
||||
inkCanvas.StylusUp -= MainWindow_StylusUp;
|
||||
inkCanvas.TouchDown -= MainWindow_TouchDown;
|
||||
inkCanvas.TouchDown += Main_Grid_TouchDown;
|
||||
if (inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint)
|
||||
{
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
|
||||
}
|
||||
inkCanvas.Children.Clear();
|
||||
isInMultiTouchMode = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 进入多指书写模式,绑定Main_Grid_TouchDown
|
||||
private void EnterMultiTouchModeIfNeeded()
|
||||
{
|
||||
if (!isInMultiTouchMode)
|
||||
{
|
||||
inkCanvas.StylusDown += MainWindow_StylusDown;
|
||||
inkCanvas.StylusMove += MainWindow_StylusMove;
|
||||
inkCanvas.StylusUp += MainWindow_StylusUp;
|
||||
inkCanvas.TouchDown += MainWindow_TouchDown;
|
||||
inkCanvas.TouchDown -= Main_Grid_TouchDown;
|
||||
if (inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint)
|
||||
{
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
}
|
||||
inkCanvas.Children.Clear();
|
||||
isInMultiTouchMode = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,5 +49,5 @@ using System.Windows;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.7.1.0")]
|
||||
[assembly: AssemblyFileVersion("1.7.1.0")]
|
||||
[assembly: AssemblyVersion("1.7.1.3")]
|
||||
[assembly: AssemblyFileVersion("1.7.1.3")]
|
||||
|
||||
@@ -418,6 +418,9 @@ namespace Ink_Canvas
|
||||
|
||||
[JsonProperty("isEnableAvoidFullScreenHelper")]
|
||||
public bool IsEnableAvoidFullScreenHelper { get; set; } = false;
|
||||
|
||||
[JsonProperty("isAutoBackupBeforeUpdate")]
|
||||
public bool IsAutoBackupBeforeUpdate { get; set; } = true;
|
||||
}
|
||||
|
||||
public class InkToShape
|
||||
|
||||
@@ -292,9 +292,12 @@ namespace Ink_Canvas.Windows
|
||||
return;
|
||||
}
|
||||
|
||||
// 保存插件名称,以便在删除后使用
|
||||
string pluginName = SelectedPlugin.Name;
|
||||
|
||||
// 确认删除
|
||||
MessageBoxResult result = MessageBox.Show(
|
||||
$"确定要删除插件 {SelectedPlugin.Name} 吗?\n此操作将永久删除插件文件,无法恢复。",
|
||||
$"确定要删除插件 {pluginName} 吗?\n此操作将永久删除插件文件,无法恢复。",
|
||||
"删除确认",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Warning);
|
||||
@@ -315,11 +318,11 @@ namespace Ink_Canvas.Windows
|
||||
PluginListView.SelectedIndex = 0;
|
||||
}
|
||||
|
||||
MessageBox.Show($"插件 {SelectedPlugin.Name} 已成功删除。", "成功", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
MessageBox.Show($"插件 {pluginName} 已成功删除。", "成功", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("删除插件失败,请稍后重试。", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
MessageBox.Show($"删除插件 {pluginName} 失败,请稍后重试。", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,20 @@
|
||||
InkCanvasForClass
|
||||
|
||||
|
||||
winexe
|
||||
C#
|
||||
.cs
|
||||
E:\ICC CE\ICC CE main\community\Ink Canvas\obj\Debug\net472\
|
||||
Ink_Canvas
|
||||
none
|
||||
false
|
||||
TRACE;DEBUG;NETFRAMEWORK;NET472;;NET30_OR_GREATER;NET35_OR_GREATER;NET40_OR_GREATER;NET45_OR_GREATER;NET451_OR_GREATER;NET452_OR_GREATER;NET46_OR_GREATER;NET461_OR_GREATER;NET462_OR_GREATER;NET47_OR_GREATER;NET471_OR_GREATER;NET472_OR_GREATER
|
||||
E:\ICC CE\ICC CE main\community\Ink Canvas\App.xaml
|
||||
21348134359
|
||||
|
||||
731095817143
|
||||
471037513499
|
||||
Helpers\Plugins\BuiltIn\SuperLauncher\LauncherSettingsControl.xaml;Helpers\Plugins\BuiltIn\SuperLauncher\LauncherWindow.xaml;MainWindow.xaml;MainWindow_cs\MW_Eraser.xaml;Resources\DrawShapeImageDictionary.xaml;Resources\IconImageDictionary.xaml;Resources\SeewoImageDictionary.xaml;Resources\Styles\Dark.xaml;Resources\Styles\Light.xaml;Windows\AddCustomIconWindow.xaml;Windows\AddPickNameBackgroundWindow.xaml;Windows\CountdownTimerWindow.xaml;Windows\CustomIconWindow.xaml;Windows\CycleProcessBar.xaml;Windows\HasNewUpdateWindow.xaml;Windows\ManagePickNameBackgroundsWindow.xaml;Windows\NamesInputWindow.xaml;Windows\OperatingGuideWindow.xaml;Windows\PluginSettingsWindow.xaml;Windows\RandWindow.xaml;Windows\YesOrNoNotificationWindow.xaml;
|
||||
|
||||
False
|
||||
|
||||
Reference in New Issue
Block a user