代码清理
This commit is contained in:
+14
-14
@@ -342,13 +342,13 @@ namespace Ink_Canvas
|
||||
try
|
||||
{
|
||||
var exception = e.ExceptionObject as Exception;
|
||||
|
||||
|
||||
if (exception is InvalidOperationException invalidOpEx)
|
||||
{
|
||||
string exceptionMessage = invalidOpEx.Message ?? "";
|
||||
string exceptionStackTrace = invalidOpEx.StackTrace ?? "";
|
||||
|
||||
if (exceptionMessage.Contains("调用线程无法访问此对象") ||
|
||||
|
||||
if (exceptionMessage.Contains("调用线程无法访问此对象") ||
|
||||
exceptionMessage.Contains("because another thread owns it") ||
|
||||
exceptionStackTrace.Contains("DynamicRenderer") ||
|
||||
exceptionStackTrace.Contains("CompositionTarget.get_RootVisual"))
|
||||
@@ -360,7 +360,7 @@ namespace Ink_Canvas
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
string errorMessage = exception?.ToString() ?? "未知异常";
|
||||
lastErrorMessage = errorMessage;
|
||||
|
||||
@@ -376,8 +376,8 @@ namespace Ink_Canvas
|
||||
// 尝试在最后时刻记录错误
|
||||
try
|
||||
{
|
||||
string timeStr = (appStartTime != default(DateTime) && appStartTime != DateTime.MinValue)
|
||||
? appStartTime.ToString("yyyy-MM-dd-HH-mm-ss")
|
||||
string timeStr = (appStartTime != default(DateTime) && appStartTime != DateTime.MinValue)
|
||||
? appStartTime.ToString("yyyy-MM-dd-HH-mm-ss")
|
||||
: DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
|
||||
File.AppendAllText(
|
||||
Path.Combine(crashLogFile, $"Crash_{timeStr}.txt"),
|
||||
@@ -518,8 +518,8 @@ namespace Ink_Canvas
|
||||
Directory.CreateDirectory(crashLogFile);
|
||||
}
|
||||
|
||||
string appStartTimeStr = (appStartTime != default(DateTime) && appStartTime != DateTime.MinValue)
|
||||
? appStartTime.ToString("yyyy-MM-dd-HH-mm-ss")
|
||||
string appStartTimeStr = (appStartTime != default(DateTime) && appStartTime != DateTime.MinValue)
|
||||
? appStartTime.ToString("yyyy-MM-dd-HH-mm-ss")
|
||||
: DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
|
||||
string logFileName = Path.Combine(crashLogFile, $"Crash_{appStartTimeStr}.txt");
|
||||
|
||||
@@ -575,9 +575,9 @@ namespace Ink_Canvas
|
||||
{
|
||||
string exceptionMessage = invalidOpEx.Message ?? "";
|
||||
string exceptionStackTrace = invalidOpEx.StackTrace ?? "";
|
||||
|
||||
|
||||
// 检查是否是DynamicRenderer相关的线程访问问题
|
||||
if (exceptionMessage.Contains("调用线程无法访问此对象") ||
|
||||
if (exceptionMessage.Contains("调用线程无法访问此对象") ||
|
||||
exceptionMessage.Contains("because another thread owns it") ||
|
||||
exceptionStackTrace.Contains("DynamicRenderer") ||
|
||||
exceptionStackTrace.Contains("CompositionTarget.get_RootVisual"))
|
||||
@@ -588,13 +588,13 @@ namespace Ink_Canvas
|
||||
$"检测到DynamicRenderer线程访问异常(已安全处理): {invalidOpEx.Message}",
|
||||
LogHelper.LogType.Warning
|
||||
);
|
||||
|
||||
|
||||
// 标记为已处理,不显示错误消息,不触发重启
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ink_Canvas.MainWindow.ShowNewMessage("抱歉,出现未预期的异常,可能导致 InkCanvasForClass 运行不稳定。\n建议保存墨迹后重启应用。");
|
||||
LogHelper.NewLog(e.Exception.ToString());
|
||||
|
||||
@@ -1133,12 +1133,12 @@ namespace Ink_Canvas
|
||||
}
|
||||
// 主进程异常退出,自动重启前判断崩溃后操作
|
||||
SyncCrashActionFromSettings(); // 同步设置
|
||||
|
||||
|
||||
if (IsUIAccessTopMostEnabled)
|
||||
{
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
|
||||
if (CrashAction == CrashActionType.SilentRestart)
|
||||
{
|
||||
StartupCount.Increment();
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using Ink_Canvas.Windows;
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Threading;
|
||||
using MouseEventArgs = System.Windows.Input.MouseEventArgs;
|
||||
using HorizontalAlignment = System.Windows.HorizontalAlignment;
|
||||
using MouseEventArgs = System.Windows.Input.MouseEventArgs;
|
||||
using VerticalAlignment = System.Windows.VerticalAlignment;
|
||||
|
||||
namespace Ink_Canvas.Controls
|
||||
@@ -33,7 +32,7 @@ namespace Ink_Canvas.Controls
|
||||
{
|
||||
// 如果正在拖动,不触发点击事件
|
||||
if (_isDragging) return;
|
||||
|
||||
|
||||
// 打开快抽窗口
|
||||
var quickDrawWindow = new QuickDrawWindow();
|
||||
quickDrawWindow.ShowDialog();
|
||||
@@ -50,10 +49,10 @@ namespace Ink_Canvas.Controls
|
||||
private void DragArea_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
_isDragging = false;
|
||||
|
||||
|
||||
// 记录鼠标在屏幕上的初始位置
|
||||
_dragStartPoint = this.PointToScreen(e.GetPosition(this));
|
||||
|
||||
|
||||
// 记录控件的初始位置
|
||||
var parent = this.Parent as FrameworkElement;
|
||||
if (parent != null)
|
||||
@@ -69,7 +68,7 @@ namespace Ink_Canvas.Controls
|
||||
double.IsNaN(currentMargin.Left) ? 0 : currentMargin.Left,
|
||||
double.IsNaN(currentMargin.Top) ? 0 : currentMargin.Top);
|
||||
}
|
||||
|
||||
|
||||
((UIElement)sender).CaptureMouse();
|
||||
e.Handled = true;
|
||||
}
|
||||
@@ -84,7 +83,7 @@ namespace Ink_Canvas.Controls
|
||||
// 获取鼠标在屏幕上的当前位置
|
||||
Point currentScreenPoint = this.PointToScreen(e.GetPosition(this));
|
||||
Vector diff = currentScreenPoint - _dragStartPoint;
|
||||
|
||||
|
||||
if (!_isDragging && (Math.Abs(diff.X) > 3 || Math.Abs(diff.Y) > 3))
|
||||
{
|
||||
_isDragging = true;
|
||||
@@ -92,7 +91,7 @@ namespace Ink_Canvas.Controls
|
||||
this.HorizontalAlignment = HorizontalAlignment.Left;
|
||||
this.VerticalAlignment = VerticalAlignment.Top;
|
||||
}
|
||||
|
||||
|
||||
if (_isDragging)
|
||||
{
|
||||
// 计算新位置
|
||||
@@ -102,19 +101,19 @@ namespace Ink_Canvas.Controls
|
||||
// 计算屏幕坐标相对于父容器的位置
|
||||
var parentPoint = parent.PointFromScreen(currentScreenPoint);
|
||||
var startParentPoint = parent.PointFromScreen(_dragStartPoint);
|
||||
|
||||
|
||||
// 计算相对于初始位置的偏移
|
||||
double offsetX = parentPoint.X - startParentPoint.X;
|
||||
double offsetY = parentPoint.Y - startParentPoint.Y;
|
||||
|
||||
|
||||
// 新位置 = 初始位置 + 偏移
|
||||
double newLeft = _controlStartPoint.X + offsetX;
|
||||
double newTop = _controlStartPoint.Y + offsetY;
|
||||
|
||||
|
||||
// 限制在父容器范围内
|
||||
newLeft = Math.Max(0, Math.Min(newLeft, parent.ActualWidth - this.ActualWidth));
|
||||
newTop = Math.Max(0, Math.Min(newTop, parent.ActualHeight - this.ActualHeight));
|
||||
|
||||
|
||||
// 更新Margin
|
||||
this.Margin = new Thickness(newLeft, newTop, 0, 0);
|
||||
}
|
||||
@@ -131,17 +130,17 @@ namespace Ink_Canvas.Controls
|
||||
{
|
||||
((UIElement)sender).ReleaseMouseCapture();
|
||||
}
|
||||
|
||||
|
||||
if (_isDragging)
|
||||
{
|
||||
Dispatcher.BeginInvoke(new Action(() => { _isDragging = false; }),
|
||||
Dispatcher.BeginInvoke(new Action(() => { _isDragging = false; }),
|
||||
DispatcherPriority.Background);
|
||||
}
|
||||
else
|
||||
{
|
||||
_isDragging = false;
|
||||
}
|
||||
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,8 +283,8 @@ namespace Ink_Canvas.Helpers
|
||||
|
||||
int targetWidth = _resolutionWidth;
|
||||
int targetHeight = _resolutionHeight;
|
||||
|
||||
if (_rotationAngle == 1 || _rotationAngle == 3)
|
||||
|
||||
if (_rotationAngle == 1 || _rotationAngle == 3)
|
||||
{
|
||||
targetWidth = _resolutionHeight;
|
||||
targetHeight = _resolutionWidth;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Ink_Canvas.Helpers;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.IO;
|
||||
@@ -14,7 +13,7 @@ namespace Ink_Canvas.Helpers
|
||||
/// </summary>
|
||||
public class DlassApiClient : IDisposable
|
||||
{
|
||||
private const string DEFAULT_BASE_URL = "https://dlass.tech";
|
||||
private const string DEFAULT_BASE_URL = "https://dlass.tech";
|
||||
private readonly string _appId;
|
||||
private readonly string _appSecret;
|
||||
private readonly string _baseUrl;
|
||||
@@ -37,13 +36,13 @@ namespace Ink_Canvas.Helpers
|
||||
_appSecret = appSecret ?? throw new ArgumentNullException(nameof(appSecret));
|
||||
_userToken = userToken;
|
||||
_baseUrl = baseUrl ?? DEFAULT_BASE_URL;
|
||||
|
||||
|
||||
_baseUrl = _baseUrl.TrimEnd('/');
|
||||
if (!_baseUrl.StartsWith("http://") && !_baseUrl.StartsWith("https://"))
|
||||
{
|
||||
_baseUrl = "https://" + _baseUrl;
|
||||
}
|
||||
|
||||
|
||||
_httpClient = new HttpClient
|
||||
{
|
||||
BaseAddress = new Uri(_baseUrl),
|
||||
@@ -122,7 +121,7 @@ namespace Ink_Canvas.Helpers
|
||||
}
|
||||
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, endpoint);
|
||||
|
||||
|
||||
if (requireAuth && !string.IsNullOrEmpty(token))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_userToken))
|
||||
@@ -179,7 +178,7 @@ namespace Ink_Canvas.Helpers
|
||||
}
|
||||
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, endpoint);
|
||||
|
||||
|
||||
if (requireAuth && !string.IsNullOrEmpty(token))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_userToken))
|
||||
@@ -242,7 +241,7 @@ namespace Ink_Canvas.Helpers
|
||||
}
|
||||
|
||||
var request = new HttpRequestMessage(HttpMethod.Put, endpoint);
|
||||
|
||||
|
||||
if (requireAuth && !string.IsNullOrEmpty(token))
|
||||
{
|
||||
// 如果是用户token,使用X-User-Token header
|
||||
@@ -306,7 +305,7 @@ namespace Ink_Canvas.Helpers
|
||||
}
|
||||
|
||||
var request = new HttpRequestMessage(HttpMethod.Delete, endpoint);
|
||||
|
||||
|
||||
if (requireAuth && !string.IsNullOrEmpty(token))
|
||||
{
|
||||
// 如果是用户token,使用X-User-Token header
|
||||
@@ -365,14 +364,14 @@ namespace Ink_Canvas.Helpers
|
||||
}
|
||||
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, endpoint);
|
||||
|
||||
|
||||
// 设置白板认证头
|
||||
request.Headers.Add("X-Board-ID", boardId);
|
||||
request.Headers.Add("X-Secret-Key", secretKey);
|
||||
|
||||
// 创建multipart/form-data内容
|
||||
var content = new MultipartFormDataContent();
|
||||
|
||||
|
||||
// 添加文件
|
||||
var fileContent = new ByteArrayContent(File.ReadAllBytes(filePath));
|
||||
var fileName = Path.GetFileName(filePath);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Ink_Canvas.Helpers;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
@@ -19,7 +18,7 @@ namespace Ink_Canvas.Helpers
|
||||
private const string APP_SECRET = "o7dx5b5ASGUMcM72PCpmRQYAhSijqaOVHoGyBK0IxbA";
|
||||
private const int BATCH_SIZE = 10; // 批量上传大小
|
||||
private const int MAX_RETRY_COUNT = 3; // 最大重试次数
|
||||
private const string QUEUE_FILE_NAME = "DlassUploadQueue.json";
|
||||
private const string QUEUE_FILE_NAME = "DlassUploadQueue.json";
|
||||
|
||||
/// <summary>
|
||||
/// 上传队列项
|
||||
@@ -189,7 +188,7 @@ namespace Ink_Canvas.Helpers
|
||||
try
|
||||
{
|
||||
var queueData = new List<UploadQueueItemData>();
|
||||
|
||||
|
||||
// 将队列转换为可序列化的格式
|
||||
foreach (var item in _uploadQueue)
|
||||
{
|
||||
@@ -202,7 +201,7 @@ namespace Ink_Canvas.Helpers
|
||||
}
|
||||
|
||||
var queueFilePath = GetQueueFilePath();
|
||||
|
||||
|
||||
// 如果队列为空,清空文件
|
||||
if (queueData.Count == 0)
|
||||
{
|
||||
@@ -211,17 +210,17 @@ namespace Ink_Canvas.Helpers
|
||||
}
|
||||
|
||||
var jsonContent = JsonConvert.SerializeObject(queueData, Formatting.Indented);
|
||||
|
||||
|
||||
// 使用临时文件写入,然后替换,确保原子性
|
||||
var tempFilePath = queueFilePath + ".tmp";
|
||||
File.WriteAllText(tempFilePath, jsonContent);
|
||||
|
||||
|
||||
// 如果原文件存在,先删除
|
||||
if (File.Exists(queueFilePath))
|
||||
{
|
||||
File.Delete(queueFilePath);
|
||||
}
|
||||
|
||||
|
||||
// 重命名临时文件
|
||||
File.Move(tempFilePath, queueFilePath);
|
||||
}
|
||||
@@ -431,7 +430,7 @@ namespace Ink_Canvas.Helpers
|
||||
WhiteboardInfo sharedWhiteboard = null;
|
||||
string apiBaseUrl = null;
|
||||
string userToken = null;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
var selectedClassName = MainWindow.Settings?.Dlass?.SelectedClassName;
|
||||
@@ -538,11 +537,11 @@ namespace Ink_Canvas.Helpers
|
||||
{
|
||||
// 检查是否是可重试的错误(超时、网络错误等)
|
||||
var errorMessage = ex.Message.ToLower();
|
||||
bool isRetryable = errorMessage.Contains("超时") ||
|
||||
bool isRetryable = errorMessage.Contains("超时") ||
|
||||
errorMessage.Contains("timeout") ||
|
||||
errorMessage.Contains("网络错误") ||
|
||||
errorMessage.Contains("network");
|
||||
|
||||
|
||||
if (isRetryable && IsRetryableError(item.FilePath))
|
||||
{
|
||||
// 检查重试次数
|
||||
|
||||
@@ -299,7 +299,7 @@ namespace Ink_Canvas.Helpers
|
||||
{
|
||||
positionToSave = _lastSwitchSlideIndex;
|
||||
}
|
||||
|
||||
|
||||
if (positionToSave > 0)
|
||||
{
|
||||
File.WriteAllText(Path.Combine(folderPath, "Position"), positionToSave.ToString());
|
||||
|
||||
@@ -107,7 +107,7 @@ namespace Ink_Canvas.Helpers
|
||||
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width,
|
||||
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height, true);
|
||||
}), DispatcherPriority.ApplicationIdle);
|
||||
|
||||
|
||||
_mainWindow.isFullScreenApplied = true; // 标记已应用全屏处理
|
||||
}
|
||||
}
|
||||
@@ -129,7 +129,7 @@ namespace Ink_Canvas.Helpers
|
||||
workingArea.X, workingArea.Y,
|
||||
workingArea.Width, workingArea.Height, true);
|
||||
}), DispatcherPriority.ApplicationIdle);
|
||||
|
||||
|
||||
_mainWindow.isFullScreenApplied = false; // 标记全屏处理已还原
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,15 +28,14 @@ using Application = System.Windows.Application;
|
||||
using Brushes = System.Windows.Media.Brushes;
|
||||
using Button = System.Windows.Controls.Button;
|
||||
using Cursor = System.Windows.Input.Cursor;
|
||||
using MouseEventArgs = System.Windows.Input.MouseEventArgs;
|
||||
using HorizontalAlignment = System.Windows.HorizontalAlignment;
|
||||
using VerticalAlignment = System.Windows.VerticalAlignment;
|
||||
using Cursors = System.Windows.Input.Cursors;
|
||||
using DpiChangedEventArgs = System.Windows.DpiChangedEventArgs;
|
||||
using File = System.IO.File;
|
||||
using GroupBox = System.Windows.Controls.GroupBox;
|
||||
using HorizontalAlignment = System.Windows.HorizontalAlignment;
|
||||
using MessageBox = iNKORE.UI.WPF.Modern.Controls.MessageBox;
|
||||
using Point = System.Windows.Point;
|
||||
using VerticalAlignment = System.Windows.VerticalAlignment;
|
||||
|
||||
namespace Ink_Canvas
|
||||
{
|
||||
@@ -67,7 +66,7 @@ namespace Ink_Canvas
|
||||
// 设置面板相关状态
|
||||
private bool userChangedNoFocusModeInSettings;
|
||||
private bool isTemporarilyDisablingNoFocusMode = false;
|
||||
|
||||
|
||||
// 全屏处理状态标志
|
||||
public bool isFullScreenApplied = false;
|
||||
|
||||
@@ -271,7 +270,7 @@ namespace Ink_Canvas
|
||||
|
||||
// 为滑块控件添加触摸事件支持
|
||||
AddTouchSupportToSliders();
|
||||
|
||||
|
||||
// 初始化计时器控件事件
|
||||
Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
@@ -280,24 +279,24 @@ namespace Ink_Canvas
|
||||
TimerControl.ShowMinimizedRequested += TimerControl_ShowMinimizedRequested;
|
||||
TimerControl.HideMinimizedRequested += TimerControl_HideMinimizedRequested;
|
||||
}
|
||||
|
||||
|
||||
if (MinimizedTimerControl != null && TimerControl != null)
|
||||
{
|
||||
MinimizedTimerControl.SetParentControl(TimerControl);
|
||||
}
|
||||
}), DispatcherPriority.Loaded);
|
||||
}
|
||||
|
||||
|
||||
private void TimerControl_ShowMinimizedRequested(object sender, EventArgs e)
|
||||
{
|
||||
var timerContainer = FindName("TimerContainer") as FrameworkElement;
|
||||
var minimizedContainer = FindName("MinimizedTimerContainer") as FrameworkElement;
|
||||
|
||||
|
||||
if (timerContainer != null && minimizedContainer != null)
|
||||
{
|
||||
double x = 0, y = 0;
|
||||
|
||||
if (timerContainer.HorizontalAlignment == HorizontalAlignment.Center &&
|
||||
|
||||
if (timerContainer.HorizontalAlignment == HorizontalAlignment.Center &&
|
||||
timerContainer.VerticalAlignment == VerticalAlignment.Center)
|
||||
{
|
||||
var timerPoint = timerContainer.TransformToAncestor(this).Transform(new Point(0, 0));
|
||||
@@ -310,30 +309,30 @@ namespace Ink_Canvas
|
||||
x = double.IsNaN(timerMargin.Left) ? 0 : timerMargin.Left;
|
||||
y = double.IsNaN(timerMargin.Top) ? 0 : timerMargin.Top;
|
||||
}
|
||||
|
||||
|
||||
minimizedContainer.Margin = new Thickness(x, y, 0, 0);
|
||||
minimizedContainer.HorizontalAlignment = HorizontalAlignment.Left;
|
||||
minimizedContainer.VerticalAlignment = VerticalAlignment.Top;
|
||||
|
||||
|
||||
timerContainer.Margin = new Thickness(x, y, 0, 0);
|
||||
timerContainer.HorizontalAlignment = HorizontalAlignment.Left;
|
||||
timerContainer.VerticalAlignment = VerticalAlignment.Top;
|
||||
|
||||
|
||||
timerContainer.Visibility = Visibility.Collapsed;
|
||||
minimizedContainer.Visibility = Visibility.Visible;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void TimerControl_HideMinimizedRequested(object sender, EventArgs e)
|
||||
{
|
||||
var timerContainer = FindName("TimerContainer") as FrameworkElement;
|
||||
var minimizedContainer = FindName("MinimizedTimerContainer") as FrameworkElement;
|
||||
|
||||
|
||||
if (timerContainer != null && minimizedContainer != null)
|
||||
{
|
||||
minimizedContainer.Visibility = Visibility.Collapsed;
|
||||
timerContainer.Visibility = Visibility.Visible;
|
||||
|
||||
|
||||
if (TimerControl != null)
|
||||
{
|
||||
TimerControl.UpdateActivityTime();
|
||||
@@ -643,7 +642,7 @@ namespace Ink_Canvas
|
||||
// 初始化UIA置顶开关
|
||||
ToggleSwitchUIAccessTopMost.IsOn = Settings.Advanced.EnableUIAccessTopMost;
|
||||
UpdateUIAccessTopMostVisibility();
|
||||
|
||||
|
||||
App.IsUIAccessTopMostEnabled = Settings.Advanced.EnableUIAccessTopMost;
|
||||
|
||||
// 初始化剪贴板监控
|
||||
@@ -692,14 +691,14 @@ namespace Ink_Canvas
|
||||
}
|
||||
}), DispatcherPriority.Loaded);
|
||||
}
|
||||
|
||||
|
||||
// 初始化计时器控件关联
|
||||
Dispatcher.BeginInvoke(new Action(() =>
|
||||
{
|
||||
if (TimerControl != null && MinimizedTimerControl != null)
|
||||
{
|
||||
MinimizedTimerControl.SetParentControl(TimerControl);
|
||||
|
||||
|
||||
TimerControl.ShowMinimizedRequested += (s, args) =>
|
||||
{
|
||||
if (TimerContainer != null && MinimizedTimerContainer != null && MinimizedTimerControl != null)
|
||||
@@ -709,7 +708,7 @@ namespace Ink_Canvas
|
||||
MinimizedTimerControl.Visibility = Visibility.Visible;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
TimerControl.HideMinimizedRequested += (s, args) =>
|
||||
{
|
||||
if (MinimizedTimerContainer != null && MinimizedTimerControl != null)
|
||||
@@ -802,7 +801,7 @@ namespace Ink_Canvas
|
||||
{
|
||||
LogHelper.WriteLogToFile($"关闭快抽悬浮按钮时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
|
||||
|
||||
if (!CloseIsFromButton && Settings.Advanced.IsSecondConfirmWhenShutdownApp)
|
||||
{
|
||||
// 第一个确认对话框
|
||||
@@ -1956,7 +1955,7 @@ namespace Ink_Canvas
|
||||
private static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
|
||||
[DllImport("kernel32.dll")]
|
||||
private static extern uint GetCurrentProcessId();
|
||||
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
|
||||
|
||||
@@ -2011,16 +2010,16 @@ namespace Ink_Canvas
|
||||
{
|
||||
if (nCode >= 0)
|
||||
{
|
||||
if (Settings.Advanced.IsNoFocusMode &&
|
||||
BtnPPTSlideShowEnd.Visibility == Visibility.Visible &&
|
||||
if (Settings.Advanced.IsNoFocusMode &&
|
||||
BtnPPTSlideShowEnd.Visibility == Visibility.Visible &&
|
||||
currentMode == 0)
|
||||
{
|
||||
KBDLLHOOKSTRUCT hookStruct = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT));
|
||||
uint vkCode = hookStruct.vkCode;
|
||||
|
||||
|
||||
if (wParam == (IntPtr)WM_KEYDOWN || wParam == (IntPtr)WM_SYSKEYDOWN)
|
||||
{
|
||||
if (vkCode == 0x22 || vkCode == 0x28 || vkCode == 0x27 ||
|
||||
if (vkCode == 0x22 || vkCode == 0x28 || vkCode == 0x27 ||
|
||||
vkCode == 0x4E || vkCode == 0x20)
|
||||
{
|
||||
Dispatcher.BeginInvoke(new Action(() =>
|
||||
@@ -2029,7 +2028,7 @@ namespace Ink_Canvas
|
||||
}), DispatcherPriority.Normal);
|
||||
return (IntPtr)1;
|
||||
}
|
||||
else if (vkCode == 0x21 || vkCode == 0x26 || vkCode == 0x25 ||
|
||||
else if (vkCode == 0x21 || vkCode == 0x26 || vkCode == 0x25 ||
|
||||
vkCode == 0x50)
|
||||
{
|
||||
Dispatcher.BeginInvoke(new Action(() =>
|
||||
@@ -2072,10 +2071,10 @@ namespace Ink_Canvas
|
||||
{
|
||||
var hwnd = new WindowInteropHelper(this).Handle;
|
||||
int exStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
|
||||
|
||||
bool shouldBeNoFocus = isTemporarilyDisablingNoFocusMode ?
|
||||
|
||||
bool shouldBeNoFocus = isTemporarilyDisablingNoFocusMode ?
|
||||
false : Settings.Advanced.IsNoFocusMode;
|
||||
|
||||
|
||||
if (shouldBeNoFocus)
|
||||
{
|
||||
SetWindowLong(hwnd, GWL_EXSTYLE, exStyle | WS_EX_NOACTIVATE);
|
||||
@@ -2185,8 +2184,8 @@ namespace Ink_Canvas
|
||||
|
||||
public void ResumeTopmostMaintenance()
|
||||
{
|
||||
if (Settings.Advanced.IsAlwaysOnTop &&
|
||||
Settings.Advanced.IsNoFocusMode &&
|
||||
if (Settings.Advanced.IsAlwaysOnTop &&
|
||||
Settings.Advanced.IsNoFocusMode &&
|
||||
!Settings.Advanced.EnableUIAccessTopMost)
|
||||
{
|
||||
if (topmostMaintenanceTimer != null && !isTopmostMaintenanceEnabled)
|
||||
@@ -2286,12 +2285,12 @@ namespace Ink_Canvas
|
||||
var toggle = sender as ToggleSwitch;
|
||||
Settings.Advanced.IsNoFocusMode = toggle != null && toggle.IsOn;
|
||||
SaveSettingsToFile();
|
||||
|
||||
|
||||
if (isTemporarilyDisablingNoFocusMode)
|
||||
{
|
||||
isTemporarilyDisablingNoFocusMode = false;
|
||||
}
|
||||
|
||||
|
||||
ApplyNoFocusMode();
|
||||
|
||||
// 如果启用了窗口置顶,需要重新应用置顶设置以处理无焦点模式的变化
|
||||
@@ -2322,13 +2321,13 @@ namespace Ink_Canvas
|
||||
if (!isLoaded) return;
|
||||
var toggle = sender as ToggleSwitch;
|
||||
bool newValue = toggle != null && toggle.IsOn;
|
||||
|
||||
|
||||
Settings.Advanced.EnableUIAccessTopMost = newValue;
|
||||
SaveSettingsToFile();
|
||||
ApplyUIAccessTopMost();
|
||||
|
||||
|
||||
App.IsUIAccessTopMostEnabled = newValue;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void Window_Activated(object sender, EventArgs e)
|
||||
@@ -3193,12 +3192,12 @@ namespace Ink_Canvas
|
||||
try
|
||||
{
|
||||
var visibility = Settings.Advanced.IsAlwaysOnTop ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
|
||||
if (UIAccessTopMostPanel != null)
|
||||
{
|
||||
UIAccessTopMostPanel.Visibility = visibility;
|
||||
}
|
||||
|
||||
|
||||
if (UIAccessTopMostDescription != null)
|
||||
{
|
||||
UIAccessTopMostDescription.Visibility = visibility;
|
||||
@@ -3222,7 +3221,7 @@ namespace Ink_Canvas
|
||||
// 检查是否以管理员权限运行
|
||||
var identity = WindowsIdentity.GetCurrent();
|
||||
var principal = new WindowsPrincipal(identity);
|
||||
|
||||
|
||||
if (principal.IsInRole(WindowsBuiltInRole.Administrator))
|
||||
{
|
||||
try
|
||||
@@ -3233,8 +3232,8 @@ namespace Ink_Canvas
|
||||
App.watchdogProcess.Kill();
|
||||
App.watchdogProcess = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// 调用UIAccess DLL
|
||||
if (Environment.Is64BitProcess)
|
||||
{
|
||||
@@ -3244,7 +3243,7 @@ namespace Ink_Canvas
|
||||
{
|
||||
PrepareUIAccessX86();
|
||||
}
|
||||
|
||||
|
||||
App.StartWatchdogIfNeeded();
|
||||
timerKillProcess.Start();
|
||||
}
|
||||
|
||||
@@ -536,13 +536,13 @@ namespace Ink_Canvas
|
||||
operatingGuideWindow.RefreshTheme();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 刷新计时器控件
|
||||
if (TimerControl != null)
|
||||
{
|
||||
TimerControl.RefreshTheme();
|
||||
}
|
||||
|
||||
|
||||
if (MinimizedTimerControl != null)
|
||||
{
|
||||
MinimizedTimerControl.RefreshTheme();
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
@@ -73,35 +73,40 @@ namespace Ink_Canvas
|
||||
/// <summary>
|
||||
/// 用於更新浮動工具欄的"手勢"按鈕和白板工具欄的"手勢"按鈕的樣式(開啟和關閉狀態)
|
||||
/// </summary>
|
||||
private void CheckEnableTwoFingerGestureBtnColorPrompt() {
|
||||
private void CheckEnableTwoFingerGestureBtnColorPrompt()
|
||||
{
|
||||
// 根据主题选择手势图标和颜色
|
||||
bool isDarkTheme = Settings.Appearance.Theme == 1 ||
|
||||
(Settings.Appearance.Theme == 2 && !IsSystemThemeLight());
|
||||
bool isLightTheme = !isDarkTheme;
|
||||
string gestureIconPath = isLightTheme ? "/Resources/new-icons/gesture.png" : "/Resources/new-icons/gesture_white.png";
|
||||
|
||||
|
||||
// 根据主题设置白板模式下的颜色
|
||||
Color boardBgColor, boardIconColor, boardTextColor, boardBorderColor;
|
||||
if (isLightTheme) {
|
||||
if (isLightTheme)
|
||||
{
|
||||
// 浅色主题
|
||||
boardBgColor = Color.FromRgb(244, 244, 245);
|
||||
boardIconColor = Color.FromRgb(24, 24, 27);
|
||||
boardTextColor = Color.FromRgb(24, 24, 27);
|
||||
boardBorderColor = Color.FromRgb(161, 161, 170);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
// 深色主题
|
||||
boardBgColor = Color.FromRgb(39, 39, 42);
|
||||
boardIconColor = Color.FromRgb(244, 244, 245);
|
||||
boardTextColor = Color.FromRgb(244, 244, 245);
|
||||
boardBorderColor = Color.FromRgb(113, 113, 122);
|
||||
}
|
||||
|
||||
if (ToggleSwitchEnableMultiTouchMode.IsOn) {
|
||||
|
||||
if (ToggleSwitchEnableMultiTouchMode.IsOn)
|
||||
{
|
||||
TwoFingerGestureSimpleStackPanel.Opacity = 0.5;
|
||||
TwoFingerGestureSimpleStackPanel.IsHitTestVisible = false;
|
||||
EnableTwoFingerGestureBtn.Source =
|
||||
new BitmapImage(new Uri(gestureIconPath, UriKind.Relative));
|
||||
|
||||
|
||||
BoardGesture.Background = new SolidColorBrush(boardBgColor);
|
||||
BoardGestureGeometry.Brush = new SolidColorBrush(boardIconColor);
|
||||
BoardGestureGeometry2.Brush = new SolidColorBrush(boardIconColor);
|
||||
@@ -110,25 +115,28 @@ namespace Ink_Canvas
|
||||
BoardGestureGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.DisabledGestureIcon);
|
||||
BoardGestureGeometry2.Geometry = Geometry.Parse("F0 M24,24z M0,0z");
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
TwoFingerGestureSimpleStackPanel.Opacity = 1;
|
||||
TwoFingerGestureSimpleStackPanel.IsHitTestVisible = true;
|
||||
if (Settings.Gesture.IsEnableTwoFingerGesture) {
|
||||
if (Settings.Gesture.IsEnableTwoFingerGesture)
|
||||
{
|
||||
EnableTwoFingerGestureBtn.Source =
|
||||
new BitmapImage(new Uri("/Resources/new-icons/gesture-enabled.png", UriKind.Relative));
|
||||
|
||||
|
||||
BoardGesture.Background = new SolidColorBrush(Color.FromRgb(37, 99, 235));
|
||||
BoardGestureGeometry.Brush = new SolidColorBrush(Colors.GhostWhite);
|
||||
BoardGestureGeometry2.Brush = new SolidColorBrush(Colors.GhostWhite);
|
||||
BoardGestureLabel.Foreground = new SolidColorBrush(Colors.GhostWhite);
|
||||
BoardGesture.BorderBrush = new SolidColorBrush(Color.FromRgb(37, 99, 235));
|
||||
BoardGestureGeometry.Geometry = Geometry.Parse(XamlGraphicsIconGeometries.EnabledGestureIcon);
|
||||
BoardGestureGeometry2.Geometry = Geometry.Parse("F0 M24,24z M0,0z "+XamlGraphicsIconGeometries.EnabledGestureIconBadgeCheck);
|
||||
BoardGestureGeometry2.Geometry = Geometry.Parse("F0 M24,24z M0,0z " + XamlGraphicsIconGeometries.EnabledGestureIconBadgeCheck);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
EnableTwoFingerGestureBtn.Source =
|
||||
new BitmapImage(new Uri(gestureIconPath, UriKind.Relative));
|
||||
|
||||
|
||||
BoardGesture.Background = new SolidColorBrush(boardBgColor);
|
||||
BoardGestureGeometry.Brush = new SolidColorBrush(boardIconColor);
|
||||
BoardGestureGeometry2.Brush = new SolidColorBrush(boardIconColor);
|
||||
@@ -474,7 +482,7 @@ namespace Ink_Canvas
|
||||
}
|
||||
|
||||
bool useLegacyUI = Settings.Appearance.UseLegacyFloatingBarUI;
|
||||
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case "pen":
|
||||
@@ -1958,7 +1966,7 @@ namespace Ink_Canvas
|
||||
if (Settings.ModeSettings.IsPPTOnlyMode && !isRetry)
|
||||
{
|
||||
await Task.Delay(2000); // 等待动画完成后再检查
|
||||
|
||||
|
||||
bool isFloatingBarVisible = false;
|
||||
await Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
@@ -2039,10 +2047,10 @@ namespace Ink_Canvas
|
||||
GridTransparencyFakeBackground.Background = Brushes.Transparent;
|
||||
|
||||
GridBackgroundCoverHolder.Visibility = Visibility.Collapsed;
|
||||
|
||||
|
||||
// 点击鼠标按钮退出批注模式时的全屏还原
|
||||
RestoreFullScreenOnExitAnnotationMode();
|
||||
|
||||
|
||||
inkCanvas.Select(new StrokeCollection());
|
||||
GridInkCanvasSelectionCover.Visibility = Visibility.Collapsed;
|
||||
|
||||
@@ -2167,7 +2175,7 @@ namespace Ink_Canvas
|
||||
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width,
|
||||
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height, true);
|
||||
}), DispatcherPriority.ApplicationIdle);
|
||||
|
||||
|
||||
isFullScreenApplied = true; // 标记已应用全屏处理
|
||||
}
|
||||
|
||||
@@ -3015,8 +3023,8 @@ namespace Ink_Canvas
|
||||
// 退出批注模式时的全屏还原处理
|
||||
private void RestoreFullScreenOnExitAnnotationMode()
|
||||
{
|
||||
if (Settings.Advanced.IsEnableAvoidFullScreenHelper &&
|
||||
isFullScreenApplied &&
|
||||
if (Settings.Advanced.IsEnableAvoidFullScreenHelper &&
|
||||
isFullScreenApplied &&
|
||||
currentMode == 0 && // 不在白板模式
|
||||
BtnPPTSlideShowEnd.Visibility != Visibility.Visible) // 不在PPT放映模式
|
||||
{
|
||||
@@ -3027,11 +3035,11 @@ namespace Ink_Canvas
|
||||
{
|
||||
// 退出批注模式,恢复到工作区域大小
|
||||
var workingArea = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
|
||||
MainWindow.MoveWindow(new WindowInteropHelper(this).Handle,
|
||||
MainWindow.MoveWindow(new WindowInteropHelper(this).Handle,
|
||||
workingArea.Left, workingArea.Top,
|
||||
workingArea.Width, workingArea.Height, true);
|
||||
}), DispatcherPriority.ApplicationIdle);
|
||||
|
||||
|
||||
isFullScreenApplied = false; // 标记全屏处理已还原
|
||||
}
|
||||
}
|
||||
@@ -3105,7 +3113,7 @@ namespace Ink_Canvas
|
||||
RestoreStrokes(true);
|
||||
|
||||
// 退出白板模式时取消全屏(仅在非PPT模式下)
|
||||
if (Settings.Advanced.IsEnableAvoidFullScreenHelper &&
|
||||
if (Settings.Advanced.IsEnableAvoidFullScreenHelper &&
|
||||
BtnPPTSlideShowEnd.Visibility != Visibility.Visible) // 不在PPT放映模式
|
||||
{
|
||||
// 恢复为非画板模式,重新启用全屏限制
|
||||
@@ -3115,11 +3123,11 @@ namespace Ink_Canvas
|
||||
{
|
||||
// 退出白板模式,恢复到工作区域大小
|
||||
var workingArea = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
|
||||
MainWindow.MoveWindow(new WindowInteropHelper(this).Handle,
|
||||
MainWindow.MoveWindow(new WindowInteropHelper(this).Handle,
|
||||
workingArea.Left, workingArea.Top,
|
||||
workingArea.Width, workingArea.Height, true);
|
||||
}), DispatcherPriority.ApplicationIdle);
|
||||
|
||||
|
||||
isFullScreenApplied = false; // 标记全屏处理已还原
|
||||
}
|
||||
|
||||
@@ -3180,7 +3188,7 @@ namespace Ink_Canvas
|
||||
RestoreStrokes();
|
||||
|
||||
// 进入白板模式时全屏(仅在非PPT模式下)
|
||||
if (Settings.Advanced.IsEnableAvoidFullScreenHelper &&
|
||||
if (Settings.Advanced.IsEnableAvoidFullScreenHelper &&
|
||||
BtnPPTSlideShowEnd.Visibility != Visibility.Visible) // 不在PPT放映模式
|
||||
{
|
||||
// 设置为画板模式,允许全屏操作
|
||||
@@ -3191,7 +3199,7 @@ namespace Ink_Canvas
|
||||
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width,
|
||||
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height, true);
|
||||
}), DispatcherPriority.ApplicationIdle);
|
||||
|
||||
|
||||
isFullScreenApplied = true; // 标记已应用全屏处理
|
||||
}
|
||||
|
||||
@@ -3230,7 +3238,7 @@ namespace Ink_Canvas
|
||||
}
|
||||
|
||||
StackPanelPPTButtons.Visibility = Visibility.Collapsed;
|
||||
|
||||
|
||||
if (Settings.Advanced.EnableUIAccessTopMost)
|
||||
{
|
||||
Topmost = true;
|
||||
@@ -3275,7 +3283,7 @@ namespace Ink_Canvas
|
||||
}
|
||||
|
||||
BtnHideInkCanvas.Content = "隐藏\n画板";
|
||||
|
||||
|
||||
// 进入批注模式时的全屏处理(仅当未应用过全屏处理时)
|
||||
if (Settings.Advanced.IsEnableAvoidFullScreenHelper && !isFullScreenApplied)
|
||||
{
|
||||
@@ -3287,7 +3295,7 @@ namespace Ink_Canvas
|
||||
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width,
|
||||
System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height, true);
|
||||
}), DispatcherPriority.ApplicationIdle);
|
||||
|
||||
|
||||
isFullScreenApplied = true; // 标记已应用全屏处理
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace Ink_Canvas
|
||||
#endregion
|
||||
|
||||
#region PPT State Management
|
||||
private bool isEnteredSlideShowEndEvent;
|
||||
private bool isEnteredSlideShowEndEvent;
|
||||
private bool isPresentationHaveBlackSpace;
|
||||
|
||||
// 长按翻页相关字段
|
||||
@@ -93,7 +93,7 @@ namespace Ink_Canvas
|
||||
// 上次播放位置相关字段
|
||||
private int _lastPlaybackPage = 0;
|
||||
private bool _shouldNavigateToLastPage = false;
|
||||
|
||||
|
||||
// 当前播放页码跟踪
|
||||
private int _currentSlideShowPosition = 0;
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace Ink_Canvas
|
||||
private DateTime _lastSlideSwitchTime = DateTime.MinValue;
|
||||
private int _pendingSlideIndex = -1;
|
||||
private System.Timers.Timer _slideSwitchDebounceTimer;
|
||||
private const int SlideSwitchDebounceMs = 150;
|
||||
private const int SlideSwitchDebounceMs = 150;
|
||||
private bool _isInkClearedByButton = false;
|
||||
#endregion
|
||||
|
||||
@@ -774,20 +774,20 @@ namespace Ink_Canvas
|
||||
try
|
||||
{
|
||||
await Task.Delay(100);
|
||||
|
||||
|
||||
await Application.Current.Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
ViewboxFloatingBar.UpdateLayout();
|
||||
|
||||
|
||||
// 如果浮动栏宽度仍未计算好,再等待一段时间
|
||||
if (ViewboxFloatingBar.ActualWidth <= 0)
|
||||
{
|
||||
LogHelper.WriteLogToFile("浮动栏宽度未准备好,等待布局完成", LogHelper.LogType.Trace);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
await Task.Delay(100);
|
||||
|
||||
|
||||
await Application.Current.Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
PureViewboxFloatingBarMarginAnimationInPPTMode(false);
|
||||
@@ -795,7 +795,7 @@ namespace Ink_Canvas
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
await Task.Delay(100);
|
||||
@@ -832,7 +832,7 @@ namespace Ink_Canvas
|
||||
var totalSlides = activePresentation.Slides.Count;
|
||||
|
||||
// 获取之前的页码(用于保存墨迹)
|
||||
var previousSlide = _currentSlideShowPosition > 0 ? _currentSlideShowPosition :
|
||||
var previousSlide = _currentSlideShowPosition > 0 ? _currentSlideShowPosition :
|
||||
(_pptManager?.GetCurrentSlideNumber() ?? 0);
|
||||
|
||||
if (_isInkClearedByButton)
|
||||
@@ -988,7 +988,7 @@ namespace Ink_Canvas
|
||||
if (GridTransparencyFakeBackground.Background != Brushes.Transparent)
|
||||
BtnHideInkCanvas_Click(BtnHideInkCanvas, null);
|
||||
SetCurrentToolMode(InkCanvasEditingMode.None);
|
||||
|
||||
|
||||
UpdateCurrentToolMode("cursor");
|
||||
SetFloatingBarHighlightPosition("cursor");
|
||||
}
|
||||
@@ -1237,7 +1237,7 @@ namespace Ink_Canvas
|
||||
// 重置上次播放位置相关字段
|
||||
_lastPlaybackPage = 0;
|
||||
_shouldNavigateToLastPage = false;
|
||||
|
||||
|
||||
// 重置当前播放页码跟踪
|
||||
_currentSlideShowPosition = 0;
|
||||
|
||||
@@ -1289,7 +1289,7 @@ namespace Ink_Canvas
|
||||
if (currentSlideIndex > 0 && currentSlideIndex != newSlideIndex)
|
||||
{
|
||||
bool canWrite = _singlePPTInkManager?.CanWriteInk(currentSlideIndex) == true;
|
||||
|
||||
|
||||
if (canWrite && inkCanvas.Strokes.Count > 0)
|
||||
{
|
||||
_singlePPTInkManager?.SaveCurrentSlideStrokes(currentSlideIndex, inkCanvas.Strokes);
|
||||
@@ -1304,7 +1304,7 @@ namespace Ink_Canvas
|
||||
|
||||
// 加载新页面的墨迹
|
||||
StrokeCollection newStrokes = _singlePPTInkManager?.SwitchToSlide(newSlideIndex, null);
|
||||
|
||||
|
||||
if (newStrokes != null && newStrokes.Count > 0)
|
||||
{
|
||||
inkCanvas.Strokes.Add(newStrokes);
|
||||
@@ -1440,7 +1440,7 @@ namespace Ink_Canvas
|
||||
try
|
||||
{
|
||||
var previousSlideBeforeNavigate = _pptManager?.GetCurrentSlideNumber() ?? 0;
|
||||
|
||||
|
||||
StrokeCollection strokesToSave = null;
|
||||
if (previousSlideBeforeNavigate > 0 && inkCanvas.Strokes.Count > 0)
|
||||
{
|
||||
@@ -1450,13 +1450,13 @@ namespace Ink_Canvas
|
||||
if (_pptManager?.TryNavigatePrevious() == true)
|
||||
{
|
||||
var currentSlideAfterNavigate = _pptManager?.GetCurrentSlideNumber() ?? 0;
|
||||
|
||||
|
||||
if (previousSlideBeforeNavigate == currentSlideAfterNavigate && previousSlideBeforeNavigate > 0)
|
||||
{
|
||||
Thread.Sleep(50);
|
||||
currentSlideAfterNavigate = _pptManager?.GetCurrentSlideNumber() ?? 0;
|
||||
}
|
||||
|
||||
|
||||
if (previousSlideBeforeNavigate != currentSlideAfterNavigate && previousSlideBeforeNavigate > 0)
|
||||
{
|
||||
if (inkCanvas.Strokes.Count > 0)
|
||||
@@ -1527,7 +1527,7 @@ namespace Ink_Canvas
|
||||
try
|
||||
{
|
||||
var previousSlideBeforeNavigate = _pptManager?.GetCurrentSlideNumber() ?? 0;
|
||||
|
||||
|
||||
StrokeCollection strokesToSave = null;
|
||||
if (previousSlideBeforeNavigate > 0 && inkCanvas.Strokes.Count > 0)
|
||||
{
|
||||
@@ -1537,13 +1537,13 @@ namespace Ink_Canvas
|
||||
if (_pptManager?.TryNavigateNext() == true)
|
||||
{
|
||||
var currentSlideAfterNavigate = _pptManager?.GetCurrentSlideNumber() ?? 0;
|
||||
|
||||
|
||||
if (previousSlideBeforeNavigate == currentSlideAfterNavigate && previousSlideBeforeNavigate > 0)
|
||||
{
|
||||
Thread.Sleep(50);
|
||||
currentSlideAfterNavigate = _pptManager?.GetCurrentSlideNumber() ?? 0;
|
||||
}
|
||||
|
||||
|
||||
if (previousSlideBeforeNavigate != currentSlideAfterNavigate && previousSlideBeforeNavigate > 0)
|
||||
{
|
||||
if (inkCanvas.Strokes.Count > 0)
|
||||
|
||||
@@ -149,7 +149,7 @@ namespace Ink_Canvas
|
||||
{
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// 保存元素信息
|
||||
var elementInfos = new List<CanvasElementInfo>();
|
||||
foreach (var child in inkCanvas.Children)
|
||||
|
||||
@@ -1855,7 +1855,7 @@ namespace Ink_Canvas
|
||||
// 检查是否是第一次打开(检查用户是否已设置Token)
|
||||
bool hasToken = !string.IsNullOrEmpty(Settings?.Dlass?.UserToken?.Trim());
|
||||
bool isFirstTime = !hasToken;
|
||||
|
||||
|
||||
if (isFirstTime)
|
||||
{
|
||||
// 第一次打开,询问用户是否已注册
|
||||
@@ -1866,7 +1866,7 @@ namespace Ink_Canvas
|
||||
"Dlass账号注册",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Question);
|
||||
|
||||
|
||||
if (result == MessageBoxResult.No)
|
||||
{
|
||||
// 用户未注册,打开浏览器
|
||||
@@ -1882,14 +1882,14 @@ namespace Ink_Canvas
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"打开浏览器时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
MessageBox.Show($"无法打开浏览器。请手动访问: https://dlass.tech/dashboard",
|
||||
MessageBox.Show($"无法打开浏览器。请手动访问: https://dlass.tech/dashboard",
|
||||
"提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
return; // 不打开设置窗口
|
||||
}
|
||||
// 如果用户选择"是",继续打开设置窗口
|
||||
}
|
||||
|
||||
|
||||
// 打开设置管理窗口
|
||||
var dlassSettingsWindow = new Windows.DlassSettingsWindow();
|
||||
dlassSettingsWindow.Owner = this;
|
||||
@@ -1945,7 +1945,7 @@ namespace Ink_Canvas
|
||||
private void ComboBoxAutoSaveStrokesInterval_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (!isLoaded || ComboBoxAutoSaveStrokesInterval.SelectedItem == null) return;
|
||||
|
||||
|
||||
var selectedItem = ComboBoxAutoSaveStrokesInterval.SelectedItem as System.Windows.Controls.ComboBoxItem;
|
||||
if (selectedItem?.Tag != null && int.TryParse(selectedItem.Tag.ToString(), out int intervalMinutes))
|
||||
{
|
||||
@@ -2720,13 +2720,13 @@ namespace Ink_Canvas
|
||||
{
|
||||
if (!isLoaded) return;
|
||||
Settings.RandSettings.EnableOvertimeCountUp = ToggleSwitchEnableOvertimeCountUp.IsOn;
|
||||
|
||||
|
||||
if (!ToggleSwitchEnableOvertimeCountUp.IsOn)
|
||||
{
|
||||
ToggleSwitchEnableOvertimeRedText.IsOn = false;
|
||||
Settings.RandSettings.EnableOvertimeRedText = false;
|
||||
}
|
||||
|
||||
|
||||
SaveSettingsToFile();
|
||||
}
|
||||
|
||||
@@ -2739,7 +2739,7 @@ namespace Ink_Canvas
|
||||
ToggleSwitchEnableOvertimeCountUp.IsOn = true;
|
||||
Settings.RandSettings.EnableOvertimeCountUp = true;
|
||||
}
|
||||
|
||||
|
||||
Settings.RandSettings.EnableOvertimeRedText = ToggleSwitchEnableOvertimeRedText.IsOn;
|
||||
SaveSettingsToFile();
|
||||
}
|
||||
@@ -2865,7 +2865,7 @@ namespace Ink_Canvas
|
||||
|
||||
// 保存设置到文件
|
||||
SaveSettingsToFile();
|
||||
|
||||
|
||||
// 根据设置状态显示或隐藏快抽悬浮按钮
|
||||
ShowQuickDrawFloatingButton();
|
||||
}
|
||||
|
||||
@@ -887,20 +887,20 @@ namespace Ink_Canvas
|
||||
ToggleSwitchUseLegacyTimerUI.IsOn = Settings.RandSettings.UseLegacyTimerUI;
|
||||
ToggleSwitchUseNewStyleUI.IsOn = Settings.RandSettings.UseNewStyleUI;
|
||||
ToggleSwitchEnableOvertimeCountUp.IsOn = Settings.RandSettings.EnableOvertimeCountUp;
|
||||
|
||||
|
||||
// 新点名UI设置
|
||||
ToggleSwitchUseNewRollCallUI.IsOn = Settings.RandSettings.UseNewRollCallUI;
|
||||
ToggleSwitchEnableMLAvoidance.IsOn = Settings.RandSettings.EnableMLAvoidance;
|
||||
MLAvoidanceHistorySlider.Value = Settings.RandSettings.MLAvoidanceHistoryCount;
|
||||
MLAvoidanceWeightSlider.Value = Settings.RandSettings.MLAvoidanceWeight;
|
||||
|
||||
|
||||
bool canEnableRedText = Settings.RandSettings.EnableOvertimeCountUp && Settings.RandSettings.EnableOvertimeRedText;
|
||||
ToggleSwitchEnableOvertimeRedText.IsOn = canEnableRedText;
|
||||
if (!canEnableRedText)
|
||||
{
|
||||
Settings.RandSettings.EnableOvertimeRedText = false;
|
||||
}
|
||||
|
||||
|
||||
TimerVolumeSlider.Value = Settings.RandSettings.TimerVolume;
|
||||
|
||||
// 渐进提醒设置
|
||||
@@ -929,16 +929,16 @@ namespace Ink_Canvas
|
||||
ToggleSwitchUseLegacyTimerUI.IsOn = Settings.RandSettings.UseLegacyTimerUI;
|
||||
ToggleSwitchUseNewStyleUI.IsOn = Settings.RandSettings.UseNewStyleUI;
|
||||
ToggleSwitchEnableOvertimeCountUp.IsOn = Settings.RandSettings.EnableOvertimeCountUp;
|
||||
|
||||
|
||||
bool canEnableRedText = Settings.RandSettings.EnableOvertimeCountUp && Settings.RandSettings.EnableOvertimeRedText;
|
||||
ToggleSwitchEnableOvertimeRedText.IsOn = canEnableRedText;
|
||||
if (!canEnableRedText)
|
||||
{
|
||||
Settings.RandSettings.EnableOvertimeRedText = false;
|
||||
}
|
||||
|
||||
|
||||
TimerVolumeSlider.Value = Settings.RandSettings.TimerVolume;
|
||||
|
||||
|
||||
// 渐进提醒设置
|
||||
ToggleSwitchEnableProgressiveReminder.IsOn = Settings.RandSettings.EnableProgressiveReminder;
|
||||
ProgressiveReminderVolumeSlider.Value = Settings.RandSettings.ProgressiveReminderVolume;
|
||||
|
||||
@@ -117,7 +117,8 @@ namespace Ink_Canvas
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnPen_Click(object sender, RoutedEventArgs e) {
|
||||
private void BtnPen_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
forceEraser = false;
|
||||
drawingShapeMode = 0;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
|
||||
@@ -126,8 +127,10 @@ namespace Ink_Canvas
|
||||
isLongPressSelected = false;
|
||||
}
|
||||
|
||||
private Task<bool> CheckIsDrawingShapesInMultiTouchMode() {
|
||||
if (isInMultiTouchMode) {
|
||||
private Task<bool> CheckIsDrawingShapesInMultiTouchMode()
|
||||
{
|
||||
if (isInMultiTouchMode)
|
||||
{
|
||||
ToggleSwitchEnableMultiTouchMode.IsOn = false;
|
||||
lastIsInMultiTouchMode = true;
|
||||
}
|
||||
@@ -135,18 +138,21 @@ namespace Ink_Canvas
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
public async void BtnDrawLine_Click(object sender, MouseButtonEventArgs e) {
|
||||
public async void BtnDrawLine_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
if (lastMouseDownSender == sender) {
|
||||
if (lastMouseDownSender == sender)
|
||||
{
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 1;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
CancelSingleFingerDragMode();
|
||||
CancelSingleFingerDragMode();
|
||||
}
|
||||
|
||||
lastMouseDownSender = null;
|
||||
if (isLongPressSelected) {
|
||||
if (isLongPressSelected)
|
||||
{
|
||||
if (ToggleSwitchDrawShapeBorderAutoHide.IsOn) CollapseBorderDrawShape();
|
||||
var dA = new DoubleAnimation(1, 1, new Duration(TimeSpan.FromMilliseconds(0)));
|
||||
ImageDrawLine.BeginAnimation(OpacityProperty, dA);
|
||||
@@ -155,18 +161,21 @@ namespace Ink_Canvas
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawDashedLine_Click(object sender, MouseButtonEventArgs e) {
|
||||
private async void BtnDrawDashedLine_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
if (lastMouseDownSender == sender) {
|
||||
if (lastMouseDownSender == sender)
|
||||
{
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 8;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
CancelSingleFingerDragMode();
|
||||
CancelSingleFingerDragMode();
|
||||
}
|
||||
|
||||
lastMouseDownSender = null;
|
||||
if (isLongPressSelected) {
|
||||
if (isLongPressSelected)
|
||||
{
|
||||
if (ToggleSwitchDrawShapeBorderAutoHide.IsOn) CollapseBorderDrawShape();
|
||||
var dA = new DoubleAnimation(1, 1, new Duration(TimeSpan.FromMilliseconds(0)));
|
||||
ImageDrawDashedLine.BeginAnimation(OpacityProperty, dA);
|
||||
@@ -175,18 +184,21 @@ namespace Ink_Canvas
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawDotLine_Click(object sender, MouseButtonEventArgs e) {
|
||||
private async void BtnDrawDotLine_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
if (lastMouseDownSender == sender) {
|
||||
if (lastMouseDownSender == sender)
|
||||
{
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 18;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
CancelSingleFingerDragMode();
|
||||
CancelSingleFingerDragMode();
|
||||
}
|
||||
|
||||
lastMouseDownSender = null;
|
||||
if (isLongPressSelected) {
|
||||
if (isLongPressSelected)
|
||||
{
|
||||
if (ToggleSwitchDrawShapeBorderAutoHide.IsOn) CollapseBorderDrawShape();
|
||||
var dA = new DoubleAnimation(1, 1, new Duration(TimeSpan.FromMilliseconds(0)));
|
||||
ImageDrawDotLine.BeginAnimation(OpacityProperty, dA);
|
||||
@@ -195,18 +207,21 @@ namespace Ink_Canvas
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawArrow_Click(object sender, MouseButtonEventArgs e) {
|
||||
private async void BtnDrawArrow_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
if (lastMouseDownSender == sender) {
|
||||
if (lastMouseDownSender == sender)
|
||||
{
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 2;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
CancelSingleFingerDragMode();
|
||||
CancelSingleFingerDragMode();
|
||||
}
|
||||
|
||||
lastMouseDownSender = null;
|
||||
if (isLongPressSelected) {
|
||||
if (isLongPressSelected)
|
||||
{
|
||||
if (ToggleSwitchDrawShapeBorderAutoHide.IsOn) CollapseBorderDrawShape();
|
||||
var dA = new DoubleAnimation(1, 1, new Duration(TimeSpan.FromMilliseconds(0)));
|
||||
ImageDrawArrow.BeginAnimation(OpacityProperty, dA);
|
||||
@@ -215,18 +230,21 @@ namespace Ink_Canvas
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawParallelLine_Click(object sender, MouseButtonEventArgs e) {
|
||||
private async void BtnDrawParallelLine_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
if (lastMouseDownSender == sender) {
|
||||
if (lastMouseDownSender == sender)
|
||||
{
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 15;
|
||||
inkCanvas.EditingMode = InkCanvasEditingMode.None;
|
||||
inkCanvas.IsManipulationEnabled = true;
|
||||
CancelSingleFingerDragMode();
|
||||
CancelSingleFingerDragMode();
|
||||
}
|
||||
|
||||
lastMouseDownSender = null;
|
||||
if (isLongPressSelected) {
|
||||
if (isLongPressSelected)
|
||||
{
|
||||
if (ToggleSwitchDrawShapeBorderAutoHide.IsOn) CollapseBorderDrawShape();
|
||||
var dA = new DoubleAnimation(1, 1, new Duration(TimeSpan.FromMilliseconds(0)));
|
||||
ImageDrawParallelLine.BeginAnimation(OpacityProperty, dA);
|
||||
@@ -235,7 +253,8 @@ namespace Ink_Canvas
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawCoordinate1_Click(object sender, MouseButtonEventArgs e) {
|
||||
private async void BtnDrawCoordinate1_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 11;
|
||||
@@ -245,7 +264,8 @@ namespace Ink_Canvas
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawCoordinate2_Click(object sender, MouseButtonEventArgs e) {
|
||||
private async void BtnDrawCoordinate2_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 12;
|
||||
@@ -255,7 +275,8 @@ namespace Ink_Canvas
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawCoordinate3_Click(object sender, MouseButtonEventArgs e) {
|
||||
private async void BtnDrawCoordinate3_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 13;
|
||||
@@ -265,7 +286,8 @@ namespace Ink_Canvas
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawCoordinate4_Click(object sender, MouseButtonEventArgs e) {
|
||||
private async void BtnDrawCoordinate4_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 14;
|
||||
@@ -275,7 +297,8 @@ namespace Ink_Canvas
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawCoordinate5_Click(object sender, MouseButtonEventArgs e) {
|
||||
private async void BtnDrawCoordinate5_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 17;
|
||||
@@ -285,7 +308,8 @@ namespace Ink_Canvas
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawRectangle_Click(object sender, MouseButtonEventArgs e) {
|
||||
private async void BtnDrawRectangle_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 3;
|
||||
@@ -295,7 +319,8 @@ namespace Ink_Canvas
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawRectangleCenter_Click(object sender, MouseButtonEventArgs e) {
|
||||
private async void BtnDrawRectangleCenter_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 19;
|
||||
@@ -305,7 +330,8 @@ namespace Ink_Canvas
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawEllipse_Click(object sender, MouseButtonEventArgs e) {
|
||||
private async void BtnDrawEllipse_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 4;
|
||||
@@ -315,7 +341,8 @@ namespace Ink_Canvas
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawCircle_Click(object sender, MouseButtonEventArgs e) {
|
||||
private async void BtnDrawCircle_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 5;
|
||||
@@ -325,7 +352,8 @@ namespace Ink_Canvas
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawCenterEllipse_Click(object sender, MouseButtonEventArgs e) {
|
||||
private async void BtnDrawCenterEllipse_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 16;
|
||||
@@ -335,7 +363,8 @@ namespace Ink_Canvas
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawCenterEllipseWithFocalPoint_Click(object sender, MouseButtonEventArgs e) {
|
||||
private async void BtnDrawCenterEllipseWithFocalPoint_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 23;
|
||||
@@ -345,7 +374,8 @@ namespace Ink_Canvas
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawDashedCircle_Click(object sender, MouseButtonEventArgs e) {
|
||||
private async void BtnDrawDashedCircle_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 10;
|
||||
@@ -355,7 +385,8 @@ namespace Ink_Canvas
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawHyperbola_Click(object sender, MouseButtonEventArgs e) {
|
||||
private async void BtnDrawHyperbola_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 24;
|
||||
@@ -366,7 +397,8 @@ namespace Ink_Canvas
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawHyperbolaWithFocalPoint_Click(object sender, MouseButtonEventArgs e) {
|
||||
private async void BtnDrawHyperbolaWithFocalPoint_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 25;
|
||||
@@ -377,7 +409,8 @@ namespace Ink_Canvas
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawParabola1_Click(object sender, MouseButtonEventArgs e) {
|
||||
private async void BtnDrawParabola1_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 20;
|
||||
@@ -387,7 +420,8 @@ namespace Ink_Canvas
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawParabolaWithFocalPoint_Click(object sender, MouseButtonEventArgs e) {
|
||||
private async void BtnDrawParabolaWithFocalPoint_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 22;
|
||||
@@ -397,7 +431,8 @@ namespace Ink_Canvas
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawParabola2_Click(object sender, MouseButtonEventArgs e) {
|
||||
private async void BtnDrawParabola2_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 21;
|
||||
@@ -407,7 +442,8 @@ namespace Ink_Canvas
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawCylinder_Click(object sender, MouseButtonEventArgs e) {
|
||||
private async void BtnDrawCylinder_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 6;
|
||||
@@ -417,7 +453,8 @@ namespace Ink_Canvas
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawCone_Click(object sender, MouseButtonEventArgs e) {
|
||||
private async void BtnDrawCone_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 7;
|
||||
@@ -427,7 +464,8 @@ namespace Ink_Canvas
|
||||
DrawShapePromptToPen();
|
||||
}
|
||||
|
||||
private async void BtnDrawCuboid_Click(object sender, MouseButtonEventArgs e) {
|
||||
private async void BtnDrawCuboid_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
await CheckIsDrawingShapesInMultiTouchMode();
|
||||
forceEraser = true;
|
||||
drawingShapeMode = 9;
|
||||
@@ -442,19 +480,24 @@ namespace Ink_Canvas
|
||||
|
||||
#endregion
|
||||
|
||||
private void inkCanvas_TouchMove(object sender, TouchEventArgs e) {
|
||||
private void inkCanvas_TouchMove(object sender, TouchEventArgs e)
|
||||
{
|
||||
if (isSingleFingerDragMode) return;
|
||||
if (drawingShapeMode != 0) {
|
||||
if (drawingShapeMode != 0)
|
||||
{
|
||||
//EraserContainer.Background = null;
|
||||
//ImageEraser.Visibility = Visibility.Visible;
|
||||
if (isWaitUntilNextTouchDown) return;
|
||||
if (dec.Count > 1) {
|
||||
if (dec.Count > 1)
|
||||
{
|
||||
isWaitUntilNextTouchDown = true;
|
||||
try {
|
||||
try
|
||||
{
|
||||
inkCanvas.Strokes.Remove(lastTempStroke);
|
||||
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
|
||||
}
|
||||
catch {
|
||||
catch
|
||||
{
|
||||
Trace.WriteLine("lastTempStrokeCollection failed.");
|
||||
}
|
||||
|
||||
@@ -478,7 +521,8 @@ namespace Ink_Canvas
|
||||
|
||||
#region 形状绘制主函数
|
||||
|
||||
private void MouseTouchMove(Point endP) {
|
||||
private void MouseTouchMove(Point endP)
|
||||
{
|
||||
// 禁用原有的FitToCurve,使用新的高级贝塞尔曲线平滑
|
||||
if (Settings.Canvas.FitToCurve) drawingAttributes.FitToCurve = false;
|
||||
// 在绘制过程中禁用浮动栏交互,避免干扰绘制
|
||||
@@ -498,10 +542,12 @@ namespace Ink_Canvas
|
||||
new Point(endP.X, endP.Y)
|
||||
};
|
||||
point = new StylusPointCollection(pointList);
|
||||
stroke = new Stroke(point) {
|
||||
stroke = new Stroke(point)
|
||||
{
|
||||
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
|
||||
};
|
||||
try {
|
||||
try
|
||||
{
|
||||
inkCanvas.Strokes.Remove(lastTempStroke);
|
||||
}
|
||||
catch { }
|
||||
@@ -512,10 +558,12 @@ namespace Ink_Canvas
|
||||
case 8:
|
||||
_currentCommitType = CommitReason.ShapeDrawing;
|
||||
strokes.Add(GenerateDashedLineStrokeCollection(iniP, endP));
|
||||
try {
|
||||
try
|
||||
{
|
||||
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
|
||||
}
|
||||
catch {
|
||||
catch
|
||||
{
|
||||
Trace.WriteLine("lastTempStrokeCollection failed.");
|
||||
}
|
||||
|
||||
@@ -525,10 +573,12 @@ namespace Ink_Canvas
|
||||
case 18:
|
||||
_currentCommitType = CommitReason.ShapeDrawing;
|
||||
strokes.Add(GenerateDotLineStrokeCollection(iniP, endP));
|
||||
try {
|
||||
try
|
||||
{
|
||||
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
|
||||
}
|
||||
catch {
|
||||
catch
|
||||
{
|
||||
Trace.WriteLine("lastTempStrokeCollection failed.");
|
||||
}
|
||||
|
||||
@@ -550,10 +600,12 @@ namespace Ink_Canvas
|
||||
new Point(endP.X + (w * cost + h * sint), endP.Y - (h * cost - w * sint))
|
||||
};
|
||||
point = new StylusPointCollection(pointList);
|
||||
stroke = new Stroke(point) {
|
||||
stroke = new Stroke(point)
|
||||
{
|
||||
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
|
||||
};
|
||||
try {
|
||||
try
|
||||
{
|
||||
inkCanvas.Strokes.Remove(lastTempStroke);
|
||||
}
|
||||
catch { }
|
||||
@@ -615,10 +667,12 @@ namespace Ink_Canvas
|
||||
new Point(endP.X + x * sinTheta, endP.Y + x * cosTheta)));
|
||||
strokes.Add(GenerateLineStroke(new Point(iniP.X + 3 * x * sinTheta, iniP.Y + 3 * x * cosTheta),
|
||||
new Point(endP.X + 3 * x * sinTheta, endP.Y + 3 * x * cosTheta)));
|
||||
try {
|
||||
try
|
||||
{
|
||||
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
|
||||
}
|
||||
catch {
|
||||
catch
|
||||
{
|
||||
Trace.WriteLine("lastTempStrokeCollection failed.");
|
||||
}
|
||||
|
||||
@@ -631,10 +685,12 @@ namespace Ink_Canvas
|
||||
new Point(endP.X, iniP.Y)));
|
||||
strokes.Add(GenerateArrowLineStroke(new Point(iniP.X, 2 * iniP.Y - (endP.Y + 20)),
|
||||
new Point(iniP.X, endP.Y)));
|
||||
try {
|
||||
try
|
||||
{
|
||||
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
|
||||
}
|
||||
catch {
|
||||
catch
|
||||
{
|
||||
Trace.WriteLine("lastTempStrokeCollection failed.");
|
||||
}
|
||||
|
||||
@@ -649,10 +705,12 @@ namespace Ink_Canvas
|
||||
new Point(endP.X, iniP.Y)));
|
||||
strokes.Add(GenerateArrowLineStroke(new Point(iniP.X, 2 * iniP.Y - (endP.Y + 20)),
|
||||
new Point(iniP.X, endP.Y)));
|
||||
try {
|
||||
try
|
||||
{
|
||||
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
|
||||
}
|
||||
catch {
|
||||
catch
|
||||
{
|
||||
Trace.WriteLine("lastTempStrokeCollection failed.");
|
||||
}
|
||||
|
||||
@@ -667,10 +725,12 @@ namespace Ink_Canvas
|
||||
strokes.Add(GenerateArrowLineStroke(
|
||||
new Point(iniP.X, iniP.Y + (iniP.Y - endP.Y) / Math.Abs(iniP.Y - endP.Y) * 25),
|
||||
new Point(iniP.X, endP.Y)));
|
||||
try {
|
||||
try
|
||||
{
|
||||
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
|
||||
}
|
||||
catch {
|
||||
catch
|
||||
{
|
||||
Trace.WriteLine("lastTempStrokeCollection failed.");
|
||||
}
|
||||
|
||||
@@ -686,10 +746,12 @@ namespace Ink_Canvas
|
||||
strokes.Add(GenerateArrowLineStroke(
|
||||
new Point(iniP.X, iniP.Y + (iniP.Y - endP.Y) / Math.Abs(iniP.Y - endP.Y) * 25),
|
||||
new Point(iniP.X, endP.Y)));
|
||||
try {
|
||||
try
|
||||
{
|
||||
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
|
||||
}
|
||||
catch {
|
||||
catch
|
||||
{
|
||||
Trace.WriteLine("lastTempStrokeCollection failed.");
|
||||
}
|
||||
|
||||
@@ -705,10 +767,12 @@ namespace Ink_Canvas
|
||||
d = (Math.Abs(iniP.X - endP.X) + Math.Abs(iniP.Y - endP.Y)) / 2;
|
||||
strokes.Add(GenerateArrowLineStroke(new Point(iniP.X, iniP.Y),
|
||||
new Point(iniP.X - d / 1.76, iniP.Y + d / 1.76)));
|
||||
try {
|
||||
try
|
||||
{
|
||||
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
|
||||
}
|
||||
catch {
|
||||
catch
|
||||
{
|
||||
Trace.WriteLine("lastTempStrokeCollection failed.");
|
||||
}
|
||||
|
||||
@@ -725,10 +789,12 @@ namespace Ink_Canvas
|
||||
new Point(iniP.X, iniP.Y)
|
||||
};
|
||||
point = new StylusPointCollection(pointList);
|
||||
stroke = new Stroke(point) {
|
||||
stroke = new Stroke(point)
|
||||
{
|
||||
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
|
||||
};
|
||||
try {
|
||||
try
|
||||
{
|
||||
inkCanvas.Strokes.Remove(lastTempStroke);
|
||||
}
|
||||
catch { }
|
||||
@@ -748,10 +814,12 @@ namespace Ink_Canvas
|
||||
new Point(iniP.X - a, iniP.Y - b)
|
||||
};
|
||||
point = new StylusPointCollection(pointList);
|
||||
stroke = new Stroke(point) {
|
||||
stroke = new Stroke(point)
|
||||
{
|
||||
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
|
||||
};
|
||||
try {
|
||||
try
|
||||
{
|
||||
inkCanvas.Strokes.Remove(lastTempStroke);
|
||||
}
|
||||
catch { }
|
||||
@@ -763,10 +831,12 @@ namespace Ink_Canvas
|
||||
_currentCommitType = CommitReason.ShapeDrawing;
|
||||
pointList = GenerateEllipseGeometry(iniP, endP);
|
||||
point = new StylusPointCollection(pointList);
|
||||
stroke = new Stroke(point) {
|
||||
stroke = new Stroke(point)
|
||||
{
|
||||
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
|
||||
};
|
||||
try {
|
||||
try
|
||||
{
|
||||
inkCanvas.Strokes.Remove(lastTempStroke);
|
||||
}
|
||||
catch { }
|
||||
@@ -780,10 +850,12 @@ namespace Ink_Canvas
|
||||
pointList = GenerateEllipseGeometry(new Point(iniP.X - R, iniP.Y - R),
|
||||
new Point(iniP.X + R, iniP.Y + R));
|
||||
point = new StylusPointCollection(pointList);
|
||||
stroke = new Stroke(point) {
|
||||
stroke = new Stroke(point)
|
||||
{
|
||||
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
|
||||
};
|
||||
try {
|
||||
try
|
||||
{
|
||||
inkCanvas.Strokes.Remove(lastTempStroke);
|
||||
}
|
||||
catch { }
|
||||
@@ -792,7 +864,8 @@ namespace Ink_Canvas
|
||||
inkCanvas.Strokes.Add(stroke);
|
||||
|
||||
// 如果启用了圆心标记功能,则绘制圆心
|
||||
if (Settings.Canvas.ShowCircleCenter) {
|
||||
if (Settings.Canvas.ShowCircleCenter)
|
||||
{
|
||||
DrawCircleCenter(iniP);
|
||||
}
|
||||
break;
|
||||
@@ -803,10 +876,12 @@ namespace Ink_Canvas
|
||||
pointList = GenerateEllipseGeometry(new Point(iniP.X - halfA, iniP.Y - halfB),
|
||||
new Point(iniP.X + halfA, iniP.Y + halfB));
|
||||
point = new StylusPointCollection(pointList);
|
||||
stroke = new Stroke(point) {
|
||||
stroke = new Stroke(point)
|
||||
{
|
||||
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
|
||||
};
|
||||
try {
|
||||
try
|
||||
{
|
||||
inkCanvas.Strokes.Remove(lastTempStroke);
|
||||
}
|
||||
catch { }
|
||||
@@ -821,46 +896,54 @@ namespace Ink_Canvas
|
||||
pointList = GenerateEllipseGeometry(new Point(iniP.X - a, iniP.Y - b),
|
||||
new Point(iniP.X + a, iniP.Y + b));
|
||||
point = new StylusPointCollection(pointList);
|
||||
stroke = new Stroke(point) {
|
||||
stroke = new Stroke(point)
|
||||
{
|
||||
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
|
||||
};
|
||||
strokes.Add(stroke);
|
||||
var c = Math.Sqrt(Math.Abs(a * a - b * b));
|
||||
StylusPoint stylusPoint;
|
||||
if (a > b) {
|
||||
if (a > b)
|
||||
{
|
||||
stylusPoint = new StylusPoint(iniP.X + c, iniP.Y, (float)1.0);
|
||||
point = new StylusPointCollection();
|
||||
point.Add(stylusPoint);
|
||||
stroke = new Stroke(point) {
|
||||
stroke = new Stroke(point)
|
||||
{
|
||||
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
|
||||
};
|
||||
strokes.Add(stroke.Clone());
|
||||
stylusPoint = new StylusPoint(iniP.X - c, iniP.Y, (float)1.0);
|
||||
point = new StylusPointCollection();
|
||||
point.Add(stylusPoint);
|
||||
stroke = new Stroke(point) {
|
||||
stroke = new Stroke(point)
|
||||
{
|
||||
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
|
||||
};
|
||||
strokes.Add(stroke.Clone());
|
||||
}
|
||||
else if (a < b) {
|
||||
else if (a < b)
|
||||
{
|
||||
stylusPoint = new StylusPoint(iniP.X, iniP.Y - c, (float)1.0);
|
||||
point = new StylusPointCollection();
|
||||
point.Add(stylusPoint);
|
||||
stroke = new Stroke(point) {
|
||||
stroke = new Stroke(point)
|
||||
{
|
||||
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
|
||||
};
|
||||
strokes.Add(stroke.Clone());
|
||||
stylusPoint = new StylusPoint(iniP.X, iniP.Y + c, (float)1.0);
|
||||
point = new StylusPointCollection();
|
||||
point.Add(stylusPoint);
|
||||
stroke = new Stroke(point) {
|
||||
stroke = new Stroke(point)
|
||||
{
|
||||
DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone()
|
||||
};
|
||||
strokes.Add(stroke.Clone());
|
||||
}
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
|
||||
}
|
||||
catch { }
|
||||
@@ -873,10 +956,12 @@ namespace Ink_Canvas
|
||||
R = GetDistance(iniP, endP);
|
||||
strokes = GenerateDashedLineEllipseStrokeCollection(new Point(iniP.X - R, iniP.Y - R),
|
||||
new Point(iniP.X + R, iniP.Y + R));
|
||||
try {
|
||||
try
|
||||
{
|
||||
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
|
||||
}
|
||||
catch {
|
||||
catch
|
||||
{
|
||||
Trace.WriteLine("lastTempStrokeCollection failed.");
|
||||
}
|
||||
|
||||
@@ -891,7 +976,8 @@ namespace Ink_Canvas
|
||||
var pointList2 = new List<Point>();
|
||||
var pointList3 = new List<Point>();
|
||||
var pointList4 = new List<Point>();
|
||||
if (drawMultiStepShapeCurrentStep == 0) {
|
||||
if (drawMultiStepShapeCurrentStep == 0)
|
||||
{
|
||||
//第一笔:画渐近线
|
||||
var k = Math.Abs((endP.Y - iniP.Y) / (endP.X - iniP.X));
|
||||
strokes.Add(
|
||||
@@ -902,24 +988,29 @@ namespace Ink_Canvas
|
||||
drawMultiStepShapeSpecialParameter3 = k;
|
||||
drawMultiStepShapeSpecialStrokeCollection = strokes;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
//第二笔:画双曲线
|
||||
// 先将第一笔的渐近线添加到strokes中
|
||||
if (drawMultiStepShapeSpecialStrokeCollection != null && drawMultiStepShapeSpecialStrokeCollection.Count > 0) {
|
||||
foreach (var asymptoteStroke in drawMultiStepShapeSpecialStrokeCollection) {
|
||||
if (drawMultiStepShapeSpecialStrokeCollection != null && drawMultiStepShapeSpecialStrokeCollection.Count > 0)
|
||||
{
|
||||
foreach (var asymptoteStroke in drawMultiStepShapeSpecialStrokeCollection)
|
||||
{
|
||||
strokes.Add(asymptoteStroke.Clone());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var k = drawMultiStepShapeSpecialParameter3;
|
||||
var isHyperbolaFocalPointOnXAxis = Math.Abs((endP.Y - iniP.Y) / (endP.X - iniP.X)) < k;
|
||||
if (isHyperbolaFocalPointOnXAxis) {
|
||||
if (isHyperbolaFocalPointOnXAxis)
|
||||
{
|
||||
// 焦点在 x 轴上
|
||||
a = Math.Sqrt(Math.Abs((endP.X - iniP.X) * (endP.X - iniP.X) -
|
||||
(endP.Y - iniP.Y) * (endP.Y - iniP.Y) / (k * k)));
|
||||
b = a * k;
|
||||
pointList = new List<Point>();
|
||||
for (var i = a; i <= Math.Abs(endP.X - iniP.X); i += 0.5) {
|
||||
for (var i = a; i <= Math.Abs(endP.X - iniP.X); i += 0.5)
|
||||
{
|
||||
var rY = Math.Sqrt(Math.Abs(k * k * i * i - b * b));
|
||||
pointList.Add(new Point(iniP.X + i, iniP.Y - rY));
|
||||
pointList2.Add(new Point(iniP.X + i, iniP.Y + rY));
|
||||
@@ -927,13 +1018,15 @@ namespace Ink_Canvas
|
||||
pointList4.Add(new Point(iniP.X - i, iniP.Y + rY));
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
// 焦点在 y 轴上
|
||||
a = Math.Sqrt(Math.Abs((endP.Y - iniP.Y) * (endP.Y - iniP.Y) -
|
||||
(endP.X - iniP.X) * (endP.X - iniP.X) * (k * k)));
|
||||
b = a / k;
|
||||
pointList = new List<Point>();
|
||||
for (var i = a; i <= Math.Abs(endP.Y - iniP.Y); i += 0.5) {
|
||||
for (var i = a; i <= Math.Abs(endP.Y - iniP.Y); i += 0.5)
|
||||
{
|
||||
var rX = Math.Sqrt(Math.Abs(i * i / k / k - b * b));
|
||||
pointList.Add(new Point(iniP.X - rX, iniP.Y + i));
|
||||
pointList2.Add(new Point(iniP.X + rX, iniP.Y + i));
|
||||
@@ -942,7 +1035,8 @@ namespace Ink_Canvas
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
point = new StylusPointCollection(pointList);
|
||||
stroke = new Stroke(point)
|
||||
{ DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };
|
||||
@@ -959,7 +1053,8 @@ namespace Ink_Canvas
|
||||
stroke = new Stroke(point)
|
||||
{ DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };
|
||||
strokes.Add(stroke.Clone());
|
||||
if (drawingShapeMode == 25) {
|
||||
if (drawingShapeMode == 25)
|
||||
{
|
||||
//画焦点
|
||||
c = Math.Sqrt(a * a + b * b);
|
||||
stylusPoint = isHyperbolaFocalPointOnXAxis
|
||||
@@ -968,7 +1063,7 @@ namespace Ink_Canvas
|
||||
point = new StylusPointCollection();
|
||||
point.Add(stylusPoint);
|
||||
stroke = new Stroke(point)
|
||||
{ DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };
|
||||
{ DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };
|
||||
strokes.Add(stroke.Clone());
|
||||
stylusPoint = isHyperbolaFocalPointOnXAxis
|
||||
? new StylusPoint(iniP.X - c, iniP.Y, (float)1.0)
|
||||
@@ -976,24 +1071,27 @@ namespace Ink_Canvas
|
||||
point = new StylusPointCollection();
|
||||
point.Add(stylusPoint);
|
||||
stroke = new Stroke(point)
|
||||
{ DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };
|
||||
{ DrawingAttributes = inkCanvas.DefaultDrawingAttributes.Clone() };
|
||||
strokes.Add(stroke.Clone());
|
||||
}
|
||||
}
|
||||
catch {
|
||||
catch
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
inkCanvas.Strokes.Remove(lastTempStrokeCollection);
|
||||
}
|
||||
catch {
|
||||
catch
|
||||
{
|
||||
Trace.WriteLine("lastTempStrokeCollection failed.");
|
||||
}
|
||||
|
||||
lastTempStrokeCollection = strokes;
|
||||
inkCanvas.Strokes.Add(strokes);
|
||||
lastTempStrokeCollection = strokes;
|
||||
inkCanvas.Strokes.Add(strokes);
|
||||
break;
|
||||
case 20:
|
||||
_currentCommitType = CommitReason.ShapeDrawing;
|
||||
@@ -1657,8 +1755,10 @@ namespace Ink_Canvas
|
||||
ViewboxFloatingBar.IsHitTestVisible = true;
|
||||
BlackboardUIGridForInkReplay.IsHitTestVisible = true;
|
||||
|
||||
if (drawingShapeMode == 5) {
|
||||
if (lastTempStroke != null) {
|
||||
if (drawingShapeMode == 5)
|
||||
{
|
||||
if (lastTempStroke != null)
|
||||
{
|
||||
var circle = new Circle(new Point(), 0, lastTempStroke);
|
||||
circle.R = GetDistance(circle.Stroke.StylusPoints[0].ToPoint(),
|
||||
circle.Stroke.StylusPoints[circle.Stroke.StylusPoints.Count / 2].ToPoint()) / 2;
|
||||
@@ -1670,25 +1770,31 @@ namespace Ink_Canvas
|
||||
circles.Add(circle);
|
||||
}
|
||||
|
||||
if (lastIsInMultiTouchMode) {
|
||||
if (lastIsInMultiTouchMode)
|
||||
{
|
||||
ToggleSwitchEnableMultiTouchMode.IsOn = true;
|
||||
lastIsInMultiTouchMode = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (drawingShapeMode != 9 && drawingShapeMode != 0 && drawingShapeMode != 24 && drawingShapeMode != 25) {
|
||||
if (drawingShapeMode != 9 && drawingShapeMode != 0 && drawingShapeMode != 24 && drawingShapeMode != 25)
|
||||
{
|
||||
if (isLongPressSelected) { }
|
||||
else {
|
||||
else
|
||||
{
|
||||
BtnPen_Click(null, null); //画完一次还原到笔模式
|
||||
if (lastIsInMultiTouchMode) {
|
||||
if (lastIsInMultiTouchMode)
|
||||
{
|
||||
ToggleSwitchEnableMultiTouchMode.IsOn = true;
|
||||
lastIsInMultiTouchMode = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (drawingShapeMode == 9) {
|
||||
if (isFirstTouchCuboid) {
|
||||
if (drawingShapeMode == 9)
|
||||
{
|
||||
if (isFirstTouchCuboid)
|
||||
{
|
||||
if (CuboidStrokeCollection == null) CuboidStrokeCollection = new StrokeCollection();
|
||||
isFirstTouchCuboid = false;
|
||||
var newIniP = new Point(Math.Min(CuboidFrontRectIniP.X, CuboidFrontRectEndP.X),
|
||||
@@ -1697,25 +1803,32 @@ namespace Ink_Canvas
|
||||
Math.Max(CuboidFrontRectIniP.Y, CuboidFrontRectEndP.Y));
|
||||
CuboidFrontRectIniP = newIniP;
|
||||
CuboidFrontRectEndP = newEndP;
|
||||
try {
|
||||
try
|
||||
{
|
||||
CuboidStrokeCollection.Add(lastTempStrokeCollection);
|
||||
}
|
||||
catch {
|
||||
catch
|
||||
{
|
||||
Trace.WriteLine("lastTempStrokeCollection failed.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
BtnPen_Click(null, null); //画完还原到笔模式
|
||||
if (lastIsInMultiTouchMode) {
|
||||
if (lastIsInMultiTouchMode)
|
||||
{
|
||||
ToggleSwitchEnableMultiTouchMode.IsOn = true;
|
||||
lastIsInMultiTouchMode = false;
|
||||
}
|
||||
|
||||
if (_currentCommitType == CommitReason.ShapeDrawing) {
|
||||
try {
|
||||
if (_currentCommitType == CommitReason.ShapeDrawing)
|
||||
{
|
||||
try
|
||||
{
|
||||
CuboidStrokeCollection.Add(lastTempStrokeCollection);
|
||||
}
|
||||
catch {
|
||||
catch
|
||||
{
|
||||
Trace.WriteLine("lastTempStrokeCollection failed.");
|
||||
}
|
||||
|
||||
@@ -1726,15 +1839,20 @@ namespace Ink_Canvas
|
||||
}
|
||||
}
|
||||
|
||||
if (drawingShapeMode == 24 || drawingShapeMode == 25) {
|
||||
if (drawMultiStepShapeCurrentStep == 0) {
|
||||
if (drawingShapeMode == 24 || drawingShapeMode == 25)
|
||||
{
|
||||
if (drawMultiStepShapeCurrentStep == 0)
|
||||
{
|
||||
drawMultiStepShapeCurrentStep = 1;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
drawMultiStepShapeCurrentStep = 0;
|
||||
if (drawMultiStepShapeSpecialStrokeCollection != null) {
|
||||
if (drawMultiStepShapeSpecialStrokeCollection != null)
|
||||
{
|
||||
var opFlag = false;
|
||||
switch (Settings.Canvas.HyperbolaAsymptoteOption) {
|
||||
switch (Settings.Canvas.HyperbolaAsymptoteOption)
|
||||
{
|
||||
case OptionalOperation.Yes:
|
||||
opFlag = true;
|
||||
break;
|
||||
@@ -1752,7 +1870,8 @@ namespace Ink_Canvas
|
||||
}
|
||||
|
||||
BtnPen_Click(null, null); //画完还原到笔模式
|
||||
if (lastIsInMultiTouchMode) {
|
||||
if (lastIsInMultiTouchMode)
|
||||
{
|
||||
ToggleSwitchEnableMultiTouchMode.IsOn = true;
|
||||
lastIsInMultiTouchMode = false;
|
||||
}
|
||||
@@ -1852,10 +1971,14 @@ namespace Ink_Canvas
|
||||
Debug.WriteLine($"绘制圆心标记失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
private void MainWindow_OnMouseMove(object sender, MouseEventArgs e) {
|
||||
if (e.StylusDevice == null) {
|
||||
private void MainWindow_OnMouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.StylusDevice == null)
|
||||
{
|
||||
System.Windows.Forms.Cursor.Show();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Windows.Forms.Cursor.Hide();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -847,7 +847,7 @@ namespace Ink_Canvas
|
||||
if (stroke.StylusPoints.Count >= 10)
|
||||
{
|
||||
List<Point> checkPoints;
|
||||
|
||||
|
||||
// 使用采样点进行更准确的判断
|
||||
if (Settings.Canvas.HighPrecisionLineStraighten)
|
||||
{
|
||||
@@ -890,7 +890,7 @@ namespace Ink_Canvas
|
||||
double quickRelativeThreshold = lineLength * quickThreshold;
|
||||
|
||||
// 使用平均偏差和最大偏差的综合判断
|
||||
double deviationThreshold = Settings.Canvas.HighPrecisionLineStraighten
|
||||
double deviationThreshold = Settings.Canvas.HighPrecisionLineStraighten
|
||||
? Math.Max(avgDeviation, maxDeviation * 0.7) // 高精度模式更严格
|
||||
: maxDeviation;
|
||||
|
||||
@@ -1310,7 +1310,7 @@ namespace Ink_Canvas
|
||||
Point end = stroke.StylusPoints.Last().ToPoint();
|
||||
double lineLength = GetDistance(start, end);
|
||||
double adaptiveThreshold = Settings.Canvas.AutoStraightenLineThreshold * GetResolutionScale();
|
||||
|
||||
|
||||
// 如果线条太短,不进行拉直处理
|
||||
if (lineLength < adaptiveThreshold)
|
||||
{
|
||||
@@ -1327,7 +1327,7 @@ namespace Ink_Canvas
|
||||
|
||||
Point endpoint1, endpoint2;
|
||||
bool shouldStraighten = TryGetStraightLineEndpoints(stroke, out endpoint1, out endpoint2);
|
||||
|
||||
|
||||
if (shouldStraighten)
|
||||
{
|
||||
Debug.WriteLine($"接受拉直:判断为直线,解释方差比例满足阈值");
|
||||
@@ -1559,7 +1559,7 @@ namespace Ink_Canvas
|
||||
Point p1 = stroke.StylusPoints[0].ToPoint();
|
||||
Point p2 = stroke.StylusPoints[1].ToPoint();
|
||||
double lineLength = GetDistance(p1, p2);
|
||||
|
||||
|
||||
if (lineLength < 10)
|
||||
return false;
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Ink;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
@@ -707,7 +706,7 @@ namespace Ink_Canvas
|
||||
dec.Clear();
|
||||
}
|
||||
isSingleFingerDragMode = false;
|
||||
|
||||
|
||||
if (drawingShapeMode == 0
|
||||
&& inkCanvas.EditingMode != InkCanvasEditingMode.EraseByPoint
|
||||
&& inkCanvas.EditingMode != InkCanvasEditingMode.EraseByStroke
|
||||
@@ -722,14 +721,14 @@ namespace Ink_Canvas
|
||||
private void Main_Grid_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
|
||||
{
|
||||
if (isInMultiTouchMode || !Settings.Gesture.IsEnableTwoFingerGesture) return;
|
||||
|
||||
|
||||
bool hasMultipleManipulators = e.Manipulators.Count() >= 2;
|
||||
bool shouldUseTwoFingerGesture = (dec.Count >= 2 && hasMultipleManipulators &&
|
||||
bool shouldUseTwoFingerGesture = (dec.Count >= 2 && hasMultipleManipulators &&
|
||||
(Settings.PowerPointSettings.IsEnableTwoFingerGestureInPresentationMode ||
|
||||
StackPanelPPTControls.Visibility != Visibility.Visible ||
|
||||
StackPanelPPTButtons.Visibility == Visibility.Collapsed)) ||
|
||||
isSingleFingerDragMode;
|
||||
|
||||
|
||||
if (shouldUseTwoFingerGesture)
|
||||
{
|
||||
var md = e.DeltaManipulation;
|
||||
|
||||
@@ -604,7 +604,7 @@ namespace Ink_Canvas
|
||||
public bool EnableUIAccessTopMost { get; set; } = false;
|
||||
|
||||
[JsonProperty("windowMode")]
|
||||
public bool WindowMode { get; set; } = true;
|
||||
public bool WindowMode { get; set; } = true;
|
||||
}
|
||||
|
||||
public class InkToShape
|
||||
@@ -624,7 +624,7 @@ namespace Ink_Canvas
|
||||
[JsonProperty("lineStraightenSensitivity")]
|
||||
public double LineStraightenSensitivity { get; set; } = 0.20;
|
||||
[JsonProperty("lineNormalizationThreshold")]
|
||||
public double LineNormalizationThreshold { get; set; } = 0.5;
|
||||
public double LineNormalizationThreshold { get; set; } = 0.5;
|
||||
}
|
||||
|
||||
public class RandSettings
|
||||
|
||||
@@ -43,27 +43,27 @@ namespace Ink_Canvas
|
||||
TimeSpan timeSpan = DateTime.Now - startTime;
|
||||
TimeSpan totalTimeSpan = new TimeSpan(hour, minute, second);
|
||||
double spentTimePercent = timeSpan.TotalMilliseconds / (totalSeconds * 1000.0);
|
||||
|
||||
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
if (!isOvertimeMode)
|
||||
{
|
||||
TimeSpan leftTimeSpan = totalTimeSpan - timeSpan;
|
||||
if (leftTimeSpan.Milliseconds > 0) leftTimeSpan += new TimeSpan(0, 0, 1);
|
||||
|
||||
|
||||
ProcessBarTime.CurrentValue = 1 - spentTimePercent;
|
||||
TextBlockHour.Text = leftTimeSpan.Hours.ToString("00");
|
||||
TextBlockMinute.Text = leftTimeSpan.Minutes.ToString("00");
|
||||
TextBlockSecond.Text = leftTimeSpan.Seconds.ToString("00");
|
||||
TbCurrentTime.Text = leftTimeSpan.ToString(@"hh\:mm\:ss");
|
||||
|
||||
|
||||
if (spentTimePercent >= 1 && MainWindow.Settings.RandSettings?.EnableOvertimeCountUp == true)
|
||||
{
|
||||
isOvertimeMode = true;
|
||||
ProcessBarTime.CurrentValue = 0;
|
||||
ProcessBarTime.Visibility = Visibility.Collapsed;
|
||||
BorderStopTime.Visibility = Visibility.Collapsed;
|
||||
|
||||
|
||||
// 播放提醒音
|
||||
PlayTimerSound();
|
||||
}
|
||||
@@ -87,7 +87,7 @@ namespace Ink_Canvas
|
||||
TextBlockHour.Foreground = new SolidColorBrush(StringToColor("#FF5B5D5F"));
|
||||
}
|
||||
BorderStopTime.Visibility = Visibility.Collapsed;
|
||||
|
||||
|
||||
// 播放提醒音
|
||||
PlayTimerSound();
|
||||
}
|
||||
@@ -99,7 +99,7 @@ namespace Ink_Canvas
|
||||
TextBlockMinute.Text = overtimeSpan.Minutes.ToString("00");
|
||||
TextBlockSecond.Text = overtimeSpan.Seconds.ToString("00");
|
||||
TbCurrentTime.Text = overtimeSpan.ToString(@"hh\:mm\:ss");
|
||||
|
||||
|
||||
if (MainWindow.Settings.RandSettings?.EnableOvertimeRedText == true)
|
||||
{
|
||||
TextBlockHour.Foreground = Brushes.Red;
|
||||
@@ -124,7 +124,7 @@ namespace Ink_Canvas
|
||||
bool isTimerRunning = false;
|
||||
bool isPaused = false;
|
||||
bool useLegacyUI = false;
|
||||
bool isOvertimeMode = false;
|
||||
bool isOvertimeMode = false;
|
||||
|
||||
Timer timer = new Timer();
|
||||
|
||||
@@ -288,7 +288,7 @@ namespace Ink_Canvas
|
||||
TextBlockHour.Foreground = textForeground3;
|
||||
else
|
||||
TextBlockHour.Foreground = new SolidColorBrush(StringToColor("#FF5B5D5F"));
|
||||
|
||||
|
||||
isOvertimeMode = false;
|
||||
ProcessBarTime.Visibility = Visibility.Visible;
|
||||
}
|
||||
@@ -311,7 +311,7 @@ namespace Ink_Canvas
|
||||
isPaused = false;
|
||||
ProcessBarTime.CurrentValue = 0;
|
||||
ProcessBarTime.IsPaused = false;
|
||||
|
||||
|
||||
isOvertimeMode = false;
|
||||
ProcessBarTime.Visibility = Visibility.Visible;
|
||||
}
|
||||
@@ -416,7 +416,7 @@ namespace Ink_Canvas
|
||||
|
||||
isPaused = false;
|
||||
isTimerRunning = true;
|
||||
isOvertimeMode = false;
|
||||
isOvertimeMode = false;
|
||||
ProcessBarTime.Visibility = Visibility.Visible;
|
||||
timer.Start();
|
||||
UpdateStopTime();
|
||||
|
||||
@@ -25,25 +25,25 @@ namespace Ink_Canvas.Windows
|
||||
public DlassSettingsWindow(MainWindow mainWindow = null)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
|
||||
// 初始化班级下拉框
|
||||
CmbClassSelection.Items.Clear();
|
||||
CmbClassSelection.Items.Add("(等待连接)");
|
||||
CmbClassSelection.SelectedIndex = 0;
|
||||
CmbClassSelection.IsEnabled = false;
|
||||
|
||||
|
||||
// 加载保存的token
|
||||
LoadUserToken();
|
||||
|
||||
|
||||
// 加载自动上传设置
|
||||
LoadAutoUploadSettings();
|
||||
|
||||
|
||||
// 初始化API客户端(优先使用用户token)
|
||||
InitializeApiClient();
|
||||
|
||||
|
||||
// 窗口关闭时释放资源
|
||||
Closed += (s, e) => _apiClient?.Dispose();
|
||||
|
||||
|
||||
// 测试连接
|
||||
_ = TestConnectionAsync();
|
||||
}
|
||||
@@ -55,7 +55,7 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
var userToken = GetUserToken();
|
||||
var apiBaseUrl = MainWindow.Settings?.Dlass?.ApiBaseUrl;
|
||||
|
||||
|
||||
if (string.IsNullOrEmpty(apiBaseUrl) || apiBaseUrl.Contains("api.dlass.tech"))
|
||||
{
|
||||
apiBaseUrl = "https://dlass.tech";
|
||||
@@ -65,7 +65,7 @@ namespace Ink_Canvas.Windows
|
||||
MainWindow.SaveSettingsToFile();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!string.IsNullOrEmpty(userToken))
|
||||
{
|
||||
_apiClient = new DlassApiClient(APP_ID, APP_SECRET, baseUrl: apiBaseUrl, userToken: userToken);
|
||||
@@ -107,7 +107,7 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
var savedTokens = GetSavedTokens();
|
||||
var currentToken = GetUserToken();
|
||||
|
||||
|
||||
CmbSavedTokens.Items.Clear();
|
||||
if (savedTokens.Count > 0)
|
||||
{
|
||||
@@ -138,9 +138,9 @@ namespace Ink_Canvas.Windows
|
||||
CmbSavedTokens.SelectedIndex = 0;
|
||||
CmbSavedTokens.IsEnabled = false;
|
||||
}
|
||||
|
||||
|
||||
TxtNewToken.Text = string.Empty;
|
||||
|
||||
|
||||
if (!string.IsNullOrEmpty(currentToken))
|
||||
{
|
||||
TxtTokenStatus.Text = "已选择Token";
|
||||
@@ -176,7 +176,7 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
MainWindow.Settings.Dlass.SavedTokens = new List<string>();
|
||||
}
|
||||
|
||||
|
||||
if (!string.IsNullOrEmpty(token) && !MainWindow.Settings.Dlass.SavedTokens.Contains(token))
|
||||
{
|
||||
MainWindow.Settings.Dlass.SavedTokens.Add(token);
|
||||
@@ -203,7 +203,7 @@ namespace Ink_Canvas.Windows
|
||||
private void LoadClasses(List<WhiteboardInfo> whiteboards, UserInfo user = null)
|
||||
{
|
||||
CmbClassSelection.Items.Clear();
|
||||
|
||||
|
||||
if (whiteboards != null && whiteboards.Count > 0)
|
||||
{
|
||||
var teacherName = user?.Username ?? "未知教师";
|
||||
@@ -212,7 +212,7 @@ namespace Ink_Canvas.Windows
|
||||
.GroupBy(w => w.ClassName)
|
||||
.OrderBy(g => g.Key)
|
||||
.ToList();
|
||||
|
||||
|
||||
foreach (var group in classGroups)
|
||||
{
|
||||
var className = group.Key;
|
||||
@@ -224,7 +224,7 @@ namespace Ink_Canvas.Windows
|
||||
TeacherName = teacherName
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
var savedClassName = MainWindow.Settings?.Dlass?.SelectedClassName ?? string.Empty;
|
||||
if (!string.IsNullOrEmpty(savedClassName))
|
||||
{
|
||||
@@ -243,7 +243,7 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
CmbClassSelection.SelectedIndex = 0;
|
||||
}
|
||||
|
||||
|
||||
CmbClassSelection.IsEnabled = true;
|
||||
}
|
||||
else
|
||||
@@ -339,7 +339,7 @@ namespace Ink_Canvas.Windows
|
||||
delayMinutes = 60;
|
||||
TxtUploadDelayMinutes.Text = "60";
|
||||
}
|
||||
|
||||
|
||||
MainWindow.Settings.Dlass.AutoUploadDelayMinutes = delayMinutes;
|
||||
MainWindow.SaveSettingsToFile();
|
||||
}
|
||||
@@ -398,13 +398,13 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
var selectedToken = CmbSavedTokens.SelectedItem.ToString();
|
||||
SaveUserToken(selectedToken);
|
||||
|
||||
|
||||
_apiClient?.Dispose();
|
||||
InitializeApiClient();
|
||||
|
||||
|
||||
TxtTokenStatus.Text = "已选择Token";
|
||||
TxtTokenStatus.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(34, 197, 94));
|
||||
|
||||
|
||||
_ = TestConnectionAsync();
|
||||
}
|
||||
}
|
||||
@@ -430,14 +430,14 @@ namespace Ink_Canvas.Windows
|
||||
|
||||
AddTokenToList(token);
|
||||
SaveUserToken(token);
|
||||
|
||||
|
||||
_apiClient?.Dispose();
|
||||
InitializeApiClient();
|
||||
|
||||
|
||||
LoadUserToken();
|
||||
|
||||
|
||||
MessageBox.Show("Token已成功保存并已选择", "成功", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
|
||||
|
||||
_ = TestConnectionAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -465,24 +465,24 @@ namespace Ink_Canvas.Windows
|
||||
if (result == MessageBoxResult.Yes)
|
||||
{
|
||||
RemoveTokenFromList(selectedToken);
|
||||
|
||||
|
||||
if (GetUserToken() == selectedToken)
|
||||
{
|
||||
SaveUserToken(string.Empty);
|
||||
}
|
||||
|
||||
|
||||
_apiClient?.Dispose();
|
||||
InitializeApiClient();
|
||||
|
||||
|
||||
LoadUserToken();
|
||||
|
||||
|
||||
CmbClassSelection.Items.Clear();
|
||||
CmbClassSelection.Items.Add("(等待连接)");
|
||||
CmbClassSelection.SelectedIndex = 0;
|
||||
CmbClassSelection.IsEnabled = false;
|
||||
_currentWhiteboards.Clear();
|
||||
_currentUser = null;
|
||||
|
||||
|
||||
TxtConnectionStatus.Text = "未连接";
|
||||
TxtConnectionStatus.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(161, 161, 170));
|
||||
}
|
||||
@@ -513,7 +513,7 @@ namespace Ink_Canvas.Windows
|
||||
// 示例:保存设置到服务器
|
||||
// var settings = new { ... };
|
||||
// await _apiClient.PostAsync<ApiResponse>("/api/settings", settings);
|
||||
|
||||
|
||||
MessageBox.Show("设置已保存", "成功", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
Close();
|
||||
}
|
||||
@@ -566,21 +566,21 @@ namespace Ink_Canvas.Windows
|
||||
app_secret = APP_SECRET,
|
||||
user_token = userToken
|
||||
};
|
||||
|
||||
|
||||
var result = await _apiClient.PostAsync<AuthWithTokenResponse>("/api/whiteboard/framework/auth-with-token", authData, requireAuth: false);
|
||||
|
||||
|
||||
if (result != null && result.Success)
|
||||
{
|
||||
var whiteboards = result.Whiteboards ?? new List<WhiteboardInfo>();
|
||||
_currentWhiteboards = whiteboards;
|
||||
_currentUser = result.User;
|
||||
var whiteboardCount = whiteboards.Count;
|
||||
|
||||
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
TxtConnectionStatus.Text = $"已连接 (找到 {whiteboardCount} 个白板)";
|
||||
TxtConnectionStatus.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(34, 197, 94));
|
||||
|
||||
|
||||
// 加载班级列表
|
||||
LoadClasses(whiteboards, result.User);
|
||||
});
|
||||
@@ -596,11 +596,11 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
throw new Exception("Token格式可能不正确(长度过短,至少需要10个字符)");
|
||||
}
|
||||
|
||||
|
||||
LogHelper.WriteLogToFile($"Token验证失败: {ex.Message}", LogHelper.LogType.Error);
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -609,7 +609,7 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
TxtConnectionStatus.Text = "连接失败";
|
||||
TxtConnectionStatus.Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(239, 68, 68));
|
||||
|
||||
|
||||
// 清空班级列表
|
||||
CmbClassSelection.Items.Clear();
|
||||
CmbClassSelection.Items.Add("(无可用班级)");
|
||||
@@ -620,9 +620,9 @@ namespace Ink_Canvas.Windows
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region API响应模型
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// auth-with-token接口响应模型
|
||||
/// </summary>
|
||||
@@ -630,17 +630,17 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
[Newtonsoft.Json.JsonProperty("success")]
|
||||
public bool Success { get; set; }
|
||||
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("whiteboards")]
|
||||
public List<WhiteboardInfo> Whiteboards { get; set; }
|
||||
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("count")]
|
||||
public int Count { get; set; }
|
||||
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("user")]
|
||||
public UserInfo User { get; set; }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 白板信息模型
|
||||
/// </summary>
|
||||
@@ -648,32 +648,32 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
[Newtonsoft.Json.JsonProperty("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("board_id")]
|
||||
public string BoardId { get; set; }
|
||||
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("secret_key")]
|
||||
public string SecretKey { get; set; }
|
||||
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("class_name")]
|
||||
public string ClassName { get; set; }
|
||||
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("class_id")]
|
||||
public int ClassId { get; set; }
|
||||
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("is_online")]
|
||||
public bool IsOnline { get; set; }
|
||||
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("last_heartbeat")]
|
||||
public string LastHeartbeat { get; set; }
|
||||
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("created_at")]
|
||||
public string CreatedAt { get; set; }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 用户信息模型
|
||||
/// </summary>
|
||||
@@ -681,14 +681,14 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
[Newtonsoft.Json.JsonProperty("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("username")]
|
||||
public string Username { get; set; }
|
||||
|
||||
|
||||
[Newtonsoft.Json.JsonProperty("email")]
|
||||
public string Email { get; set; }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 班级选择项
|
||||
/// </summary>
|
||||
@@ -697,13 +697,13 @@ namespace Ink_Canvas.Windows
|
||||
public string DisplayText { get; set; }
|
||||
public string ClassName { get; set; }
|
||||
public string TeacherName { get; set; }
|
||||
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return DisplayText;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Timers;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
using System.Timers;
|
||||
|
||||
namespace Ink_Canvas.Windows
|
||||
{
|
||||
@@ -23,23 +23,23 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
InitializeComponent();
|
||||
parentControl = parent;
|
||||
|
||||
|
||||
this.Left = 0;
|
||||
this.Top = 0;
|
||||
this.Width = SystemParameters.PrimaryScreenWidth;
|
||||
this.Height = SystemParameters.PrimaryScreenHeight;
|
||||
|
||||
updateTimer = new System.Timers.Timer(100);
|
||||
|
||||
updateTimer = new System.Timers.Timer(100);
|
||||
updateTimer.Elapsed += UpdateTimer_Elapsed;
|
||||
updateTimer.Start();
|
||||
|
||||
|
||||
parentControl.TimerCompleted += ParentWindow_TimerCompleted;
|
||||
|
||||
|
||||
var mainWindow = Application.Current.MainWindow as MainWindow;
|
||||
if (mainWindow != null)
|
||||
{
|
||||
mainWindow.PauseTopmostMaintenance();
|
||||
|
||||
|
||||
var timerContainer = mainWindow.FindName("TimerContainer") as FrameworkElement;
|
||||
if (timerContainer != null)
|
||||
{
|
||||
@@ -47,11 +47,11 @@ namespace Ink_Canvas.Windows
|
||||
timerContainer.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 确保窗口置顶
|
||||
Loaded += FullscreenTimerWindow_Loaded;
|
||||
}
|
||||
|
||||
|
||||
private void FullscreenTimerWindow_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// 使用延迟确保窗口完全加载后再应用置顶
|
||||
@@ -60,7 +60,7 @@ namespace Ink_Canvas.Windows
|
||||
ApplyTopmost();
|
||||
}), System.Windows.Threading.DispatcherPriority.Loaded);
|
||||
}
|
||||
|
||||
|
||||
#region Win32 API 声明和置顶管理
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
|
||||
@@ -118,29 +118,29 @@ namespace Ink_Canvas.Windows
|
||||
this.Close();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
UpdateTimeDisplay();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private bool ShouldCloseWindow()
|
||||
{
|
||||
if (parentControl == null) return true;
|
||||
|
||||
|
||||
if (MainWindow.Settings.RandSettings?.EnableOvertimeCountUp == true)
|
||||
{
|
||||
if (parentControl.IsTimerRunning)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
var remainingTime = parentControl.GetRemainingTime();
|
||||
if (remainingTime.HasValue && remainingTime.Value.TotalSeconds < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -198,17 +198,17 @@ namespace Ink_Canvas.Windows
|
||||
|
||||
SetDigitDisplay("FullHour1Display", Math.Abs(hours / 10) % 10, shouldShowRed);
|
||||
SetDigitDisplay("FullHour2Display", (hours % 10 + 10) % 10, shouldShowRed);
|
||||
|
||||
|
||||
SetDigitDisplay("FullMinute1Display", minutes / 10, shouldShowRed);
|
||||
SetDigitDisplay("FullMinute2Display", minutes % 10, shouldShowRed);
|
||||
|
||||
|
||||
SetDigitDisplay("FullSecond1Display", seconds / 10, shouldShowRed);
|
||||
SetDigitDisplay("FullSecond2Display", seconds % 10, shouldShowRed);
|
||||
|
||||
|
||||
SetColonDisplay(shouldShowRed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void ParentWindow_TimerCompleted(object sender, EventArgs e)
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
@@ -228,7 +228,7 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
path.Data = geometry;
|
||||
}
|
||||
|
||||
|
||||
// 设置颜色
|
||||
if (isRed)
|
||||
{
|
||||
@@ -249,7 +249,7 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
var colon1 = this.FindName("FullColon1Display") as TextBlock;
|
||||
var colon2 = this.FindName("FullColon2Display") as TextBlock;
|
||||
|
||||
|
||||
if (colon1 != null)
|
||||
{
|
||||
if (isRed)
|
||||
@@ -261,7 +261,7 @@ namespace Ink_Canvas.Windows
|
||||
colon1.Foreground = Brushes.White;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (colon2 != null)
|
||||
{
|
||||
if (isRed)
|
||||
@@ -301,12 +301,12 @@ namespace Ink_Canvas.Windows
|
||||
if (mainWindow != null)
|
||||
{
|
||||
mainWindow.ResumeTopmostMaintenance();
|
||||
|
||||
|
||||
var timerContainer = mainWindow.FindName("TimerContainer") as FrameworkElement;
|
||||
if (timerContainer != null && previousTimerContainerVisibility == Visibility.Visible)
|
||||
{
|
||||
timerContainer.Visibility = Visibility.Visible;
|
||||
|
||||
|
||||
// 重置5秒最小化计时
|
||||
if (parentControl != null)
|
||||
{
|
||||
@@ -314,12 +314,12 @@ namespace Ink_Canvas.Windows
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (parentControl != null)
|
||||
{
|
||||
parentControl.TimerCompleted -= ParentWindow_TimerCompleted;
|
||||
}
|
||||
|
||||
|
||||
// 清理资源
|
||||
if (updateTimer != null)
|
||||
{
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using iNKORE.UI.WPF.Modern;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Timers;
|
||||
using System.Windows;
|
||||
@@ -5,8 +7,6 @@ using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
using Microsoft.Win32;
|
||||
using iNKORE.UI.WPF.Modern;
|
||||
|
||||
namespace Ink_Canvas.Windows
|
||||
{
|
||||
@@ -21,36 +21,36 @@ namespace Ink_Canvas.Windows
|
||||
public MinimizedTimerControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
|
||||
updateTimer = new System.Timers.Timer(100);
|
||||
updateTimer.Elapsed += UpdateTimer_Elapsed;
|
||||
updateTimer.Start();
|
||||
|
||||
|
||||
ApplyTheme();
|
||||
|
||||
|
||||
// 监听主题变化事件
|
||||
SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged;
|
||||
|
||||
|
||||
Unloaded += MinimizedTimerControl_Unloaded;
|
||||
}
|
||||
|
||||
|
||||
private void MinimizedTimerControl_Unloaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// 取消订阅主题变化事件
|
||||
SystemEvents.UserPreferenceChanged -= SystemEvents_UserPreferenceChanged;
|
||||
|
||||
|
||||
if (parentControl != null)
|
||||
{
|
||||
parentControl.TimerCompleted -= ParentControl_TimerCompleted;
|
||||
}
|
||||
|
||||
|
||||
if (updateTimer != null)
|
||||
{
|
||||
updateTimer.Stop();
|
||||
updateTimer.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
|
||||
{
|
||||
// 当主题变化时,重新应用主题
|
||||
@@ -59,7 +59,7 @@ namespace Ink_Canvas.Windows
|
||||
RefreshTheme();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 刷新主题
|
||||
/// </summary>
|
||||
@@ -69,7 +69,7 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
// 重新应用主题
|
||||
ApplyTheme();
|
||||
|
||||
|
||||
// 强制刷新UI
|
||||
InvalidateVisual();
|
||||
}
|
||||
@@ -85,9 +85,9 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
parentControl.TimerCompleted -= ParentControl_TimerCompleted;
|
||||
}
|
||||
|
||||
|
||||
parentControl = parent;
|
||||
|
||||
|
||||
if (parentControl != null)
|
||||
{
|
||||
parentControl.TimerCompleted += ParentControl_TimerCompleted;
|
||||
@@ -105,7 +105,7 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (ShouldHide())
|
||||
{
|
||||
this.Visibility = Visibility.Collapsed;
|
||||
@@ -116,34 +116,34 @@ namespace Ink_Canvas.Windows
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
UpdateTimeDisplay();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private bool ShouldHide()
|
||||
{
|
||||
if (parentControl == null) return true;
|
||||
|
||||
|
||||
if (parentControl.IsFullscreenWindowOpen)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (MainWindow.Settings.RandSettings?.EnableOvertimeCountUp == true)
|
||||
{
|
||||
if (parentControl.IsTimerRunning)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
var remainingTime = parentControl.GetRemainingTime();
|
||||
if (remainingTime.HasValue && remainingTime.Value.TotalSeconds < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -201,17 +201,17 @@ namespace Ink_Canvas.Windows
|
||||
|
||||
SetDigitDisplay("MinHour1Display", Math.Abs(hours / 10) % 10, shouldShowRed);
|
||||
SetDigitDisplay("MinHour2Display", (hours % 10 + 10) % 10, shouldShowRed);
|
||||
|
||||
|
||||
SetDigitDisplay("MinMinute1Display", minutes / 10, shouldShowRed);
|
||||
SetDigitDisplay("MinMinute2Display", minutes % 10, shouldShowRed);
|
||||
|
||||
|
||||
SetDigitDisplay("MinSecond1Display", seconds / 10, shouldShowRed);
|
||||
SetDigitDisplay("MinSecond2Display", seconds % 10, shouldShowRed);
|
||||
|
||||
|
||||
SetColonDisplay(shouldShowRed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void ParentControl_TimerCompleted(object sender, EventArgs e)
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
@@ -231,7 +231,7 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
path.Data = geometry;
|
||||
}
|
||||
|
||||
|
||||
if (isRed)
|
||||
{
|
||||
path.Fill = Brushes.Red;
|
||||
@@ -256,7 +256,7 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
var colon1 = this.FindName("MinColon1Display") as TextBlock;
|
||||
var colon2 = this.FindName("MinColon2Display") as TextBlock;
|
||||
|
||||
|
||||
if (colon1 != null)
|
||||
{
|
||||
if (isRed)
|
||||
@@ -277,7 +277,7 @@ namespace Ink_Canvas.Windows
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (colon2 != null)
|
||||
{
|
||||
if (isRed)
|
||||
@@ -322,7 +322,7 @@ namespace Ink_Canvas.Windows
|
||||
System.Diagnostics.Debug.WriteLine($"应用主题时出错: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void ApplyTheme(Settings settings)
|
||||
{
|
||||
try
|
||||
@@ -349,7 +349,7 @@ namespace Ink_Canvas.Windows
|
||||
SetDarkThemeBorder();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 刷新数字和冒号显示的颜色
|
||||
if (parentControl != null)
|
||||
{
|
||||
@@ -361,7 +361,7 @@ namespace Ink_Canvas.Windows
|
||||
System.Diagnostics.Debug.WriteLine($"应用最小化计时器窗口主题出错: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private bool IsSystemThemeLight()
|
||||
{
|
||||
var light = false;
|
||||
@@ -432,13 +432,13 @@ namespace Ink_Canvas.Windows
|
||||
}
|
||||
Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
|
||||
private bool isDragging = false;
|
||||
private bool isDragStarted = false;
|
||||
private Point dragStartPoint;
|
||||
private Point containerStartPosition;
|
||||
private const double DragThreshold = 5.0; // 拖动阈值,像素
|
||||
|
||||
|
||||
private void MainBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.ClickCount == 2)
|
||||
@@ -447,13 +447,13 @@ namespace Ink_Canvas.Windows
|
||||
if (parentControl != null)
|
||||
{
|
||||
parentControl.UpdateActivityTime();
|
||||
|
||||
|
||||
var mainWindow = Application.Current.MainWindow as MainWindow;
|
||||
if (mainWindow != null)
|
||||
{
|
||||
var timerContainer = mainWindow.FindName("TimerContainer") as FrameworkElement;
|
||||
var minimizedContainer = mainWindow.FindName("MinimizedTimerContainer") as FrameworkElement;
|
||||
|
||||
|
||||
if (timerContainer != null && minimizedContainer != null)
|
||||
{
|
||||
timerContainer.Visibility = Visibility.Visible;
|
||||
@@ -474,18 +474,18 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
var point = e.GetPosition(minimizedContainer);
|
||||
var mainWindowPoint = minimizedContainer.TransformToAncestor(mainWindow).Transform(point);
|
||||
|
||||
|
||||
// 初始化拖动状态,但不立即开始拖动
|
||||
isDragging = false;
|
||||
isDragStarted = false;
|
||||
dragStartPoint = mainWindowPoint;
|
||||
|
||||
|
||||
var margin = minimizedContainer.Margin;
|
||||
containerStartPosition = new Point(margin.Left, margin.Top);
|
||||
|
||||
|
||||
if (double.IsNaN(containerStartPosition.X) || containerStartPosition.X < 0) containerStartPosition.X = 0;
|
||||
if (double.IsNaN(containerStartPosition.Y) || containerStartPosition.Y < 0) containerStartPosition.Y = 0;
|
||||
|
||||
|
||||
// 捕获鼠标并订阅事件,等待判断是拖动还是点击
|
||||
minimizedContainer.CaptureMouse();
|
||||
minimizedContainer.MouseMove += MinimizedContainer_MouseMove;
|
||||
@@ -495,42 +495,42 @@ namespace Ink_Canvas.Windows
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void MinimizedContainer_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
var mainWindow = Application.Current.MainWindow as MainWindow;
|
||||
if (mainWindow == null) return;
|
||||
|
||||
|
||||
var minimizedContainer = mainWindow.FindName("MinimizedTimerContainer") as FrameworkElement;
|
||||
if (minimizedContainer == null) return;
|
||||
|
||||
|
||||
var currentPoint = e.GetPosition(mainWindow);
|
||||
var deltaX = currentPoint.X - dragStartPoint.X;
|
||||
var deltaY = currentPoint.Y - dragStartPoint.Y;
|
||||
var distance = Math.Sqrt(deltaX * deltaX + deltaY * deltaY);
|
||||
|
||||
|
||||
// 如果移动距离超过阈值,开始拖动
|
||||
if (!isDragStarted && distance > DragThreshold)
|
||||
{
|
||||
isDragStarted = true;
|
||||
isDragging = true;
|
||||
}
|
||||
|
||||
|
||||
// 如果已经开始拖动,更新位置
|
||||
if (isDragging)
|
||||
{
|
||||
var timerContainer = mainWindow.FindName("TimerContainer") as FrameworkElement;
|
||||
|
||||
|
||||
var newX = containerStartPosition.X + deltaX;
|
||||
var newY = containerStartPosition.Y + deltaY;
|
||||
|
||||
|
||||
if (newX < 0) newX = 0;
|
||||
if (newY < 0) newY = 0;
|
||||
|
||||
|
||||
minimizedContainer.Margin = new Thickness(newX, newY, 0, 0);
|
||||
minimizedContainer.HorizontalAlignment = HorizontalAlignment.Left;
|
||||
minimizedContainer.VerticalAlignment = VerticalAlignment.Top;
|
||||
|
||||
|
||||
if (timerContainer != null)
|
||||
{
|
||||
timerContainer.Margin = new Thickness(newX, newY, 0, 0);
|
||||
@@ -539,12 +539,12 @@ namespace Ink_Canvas.Windows
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void MinimizedContainer_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
var mainWindow = Application.Current.MainWindow as MainWindow;
|
||||
if (mainWindow == null) return;
|
||||
|
||||
|
||||
var minimizedContainer = mainWindow.FindName("MinimizedTimerContainer") as FrameworkElement;
|
||||
if (minimizedContainer != null)
|
||||
{
|
||||
@@ -552,14 +552,14 @@ namespace Ink_Canvas.Windows
|
||||
minimizedContainer.MouseMove -= MinimizedContainer_MouseMove;
|
||||
minimizedContainer.MouseLeftButtonUp -= MinimizedContainer_MouseLeftButtonUp;
|
||||
}
|
||||
|
||||
|
||||
// 如果没有开始拖动(移动距离小于阈值),则视为单击,恢复主窗口
|
||||
if (!isDragStarted)
|
||||
{
|
||||
if (parentControl != null)
|
||||
{
|
||||
parentControl.UpdateActivityTime();
|
||||
|
||||
|
||||
var timerContainer = mainWindow.FindName("TimerContainer") as FrameworkElement;
|
||||
if (timerContainer != null && minimizedContainer != null)
|
||||
{
|
||||
@@ -568,7 +568,7 @@ namespace Ink_Canvas.Windows
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
isDragging = false;
|
||||
isDragStarted = false;
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace Ink_Canvas
|
||||
try
|
||||
{
|
||||
var resources = this.Resources;
|
||||
|
||||
|
||||
if (theme == "Light")
|
||||
{
|
||||
// 应用浅色主题资源
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using Ink_Canvas.Helpers;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Timers;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
@@ -10,8 +12,6 @@ using System.Windows.Input;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
using Newtonsoft.Json;
|
||||
using System.Runtime.InteropServices;
|
||||
using MessageBox = iNKORE.UI.WPF.Modern.Controls.MessageBox;
|
||||
|
||||
namespace Ink_Canvas
|
||||
@@ -48,7 +48,7 @@ namespace Ink_Canvas
|
||||
|
||||
InitializeUI();
|
||||
ApplyTheme(MainWindow.Settings);
|
||||
|
||||
|
||||
// 初始化点名相关变量
|
||||
InitializeRollCallData();
|
||||
}
|
||||
@@ -63,10 +63,10 @@ namespace Ink_Canvas
|
||||
|
||||
InitializeUI();
|
||||
ApplyTheme(MainWindow.Settings);
|
||||
|
||||
|
||||
// 初始化点名相关变量
|
||||
InitializeRollCallData();
|
||||
|
||||
|
||||
if (isSingleDrawMode)
|
||||
{
|
||||
if (ControlOptionsGrid != null)
|
||||
@@ -85,7 +85,7 @@ namespace Ink_Canvas
|
||||
ResetBtn.IsEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 单次抽模式:自动开始抽选
|
||||
if (isSingleDrawMode)
|
||||
{
|
||||
@@ -108,19 +108,19 @@ namespace Ink_Canvas
|
||||
|
||||
// 保存设置
|
||||
this.settings = settings;
|
||||
|
||||
|
||||
// 设置单次抽模式
|
||||
isSingleDrawMode = isSingleDraw;
|
||||
|
||||
InitializeUI();
|
||||
ApplyTheme(settings);
|
||||
|
||||
|
||||
// 初始化设置
|
||||
InitializeSettings();
|
||||
|
||||
|
||||
// 初始化点名相关变量
|
||||
InitializeRollCallData();
|
||||
|
||||
|
||||
// 单次抽模式:禁用控制面板,阻止用户点击按钮
|
||||
if (isSingleDrawMode)
|
||||
{
|
||||
@@ -141,7 +141,7 @@ namespace Ink_Canvas
|
||||
ResetBtn.IsEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 单次抽模式:自动开始抽选
|
||||
if (isSingleDrawMode)
|
||||
{
|
||||
@@ -165,43 +165,43 @@ namespace Ink_Canvas
|
||||
private Timer rollCallTimer;
|
||||
private Random random = new Random();
|
||||
private DateTime lastActivityTime = DateTime.Now;
|
||||
|
||||
|
||||
// 机器学习相关
|
||||
private static RollCallHistoryData historyData = null;
|
||||
private static readonly object historyLock = new object();
|
||||
private static int maxRecentHistory = 20;
|
||||
private static double avoidanceWeight = 0.8;
|
||||
private const double FREQUENCY_WEIGHT = 0.2;
|
||||
|
||||
private static double avoidanceWeight = 0.8;
|
||||
private const double FREQUENCY_WEIGHT = 0.2;
|
||||
|
||||
// 概率相关
|
||||
private const double DEFAULT_PROBABILITY = 1.0;
|
||||
private const double BASE_PROBABILITY_DECAY_FACTOR = 0.5;
|
||||
private const double MIN_PROBABILITY = 0.01;
|
||||
private const double PROBABILITY_RECOVERY_RATE = 0.2;
|
||||
private const double FREQUENCY_BOOST_FACTOR = 2.0;
|
||||
|
||||
private const double DEFAULT_PROBABILITY = 1.0;
|
||||
private const double BASE_PROBABILITY_DECAY_FACTOR = 0.5;
|
||||
private const double MIN_PROBABILITY = 0.01;
|
||||
private const double PROBABILITY_RECOVERY_RATE = 0.2;
|
||||
private const double FREQUENCY_BOOST_FACTOR = 2.0;
|
||||
|
||||
// 单次抽相关
|
||||
private bool isSingleDrawMode = false;
|
||||
private Random singleDrawRandom = new Random();
|
||||
|
||||
|
||||
// 设置相关
|
||||
private Settings settings;
|
||||
private int autoCloseWaitTime = 2500; // 自动关闭等待时间(毫秒)
|
||||
|
||||
|
||||
// 点名模式
|
||||
private string selectedRollCallMode = "Random"; // 默认随机点名
|
||||
|
||||
|
||||
// 外部点名相关
|
||||
private string selectedExternalCaller = "ClassIsland";
|
||||
|
||||
|
||||
// 开始点名按钮的数据
|
||||
private string originalStartBtnIconData = "M5 7C5 8.06087 5.42143 9.07828 6.17157 9.82843C6.92172 10.5786 7.93913 11 9 11C10.0609 11 11.0783 10.5786 11.8284 9.82843C12.5786 9.07828 13 8.06087 13 7C13 5.93913 12.5786 4.92172 11.8284 4.17157C11.0783 3.42143 10.0609 3 9 3C7.93913 3 6.92172 3.42143 6.17157 4.17157C5.42143 4.92172 5 5.93913 5 7Z M3 21V19C3 17.9391 3.42143 16.9217 4.17157 16.1716C4.92172 15.4214 5.93913 15 7 15H11C12.0609 15 13.0783 15.4214 13.8284 16.1716C14.5786 16.9217 15 17.9391 15 19V21 M16 3.13C16.8604 3.35031 17.623 3.85071 18.1676 4.55232C18.7122 5.25392 19.0078 6.11683 19.0078 7.005C19.0078 7.89318 18.7122 8.75608 18.1676 9.45769C17.623 10.1593 16.8604 10.6597 16 10.88 M21 21V19C20.9949 18.1172 20.6979 17.2608 20.1553 16.5644C19.6126 15.868 18.8548 15.3707 18 15.15";
|
||||
private string originalStartBtnText = "开始点名";
|
||||
|
||||
|
||||
// 外部点名按钮的数据
|
||||
private string externalCallerBtnIconData = "M9 15L15 9 M11 6L11.463 5.464C12.4008 4.52633 13.6727 3.9996 14.9989 3.99969C16.325 3.99979 17.5968 4.52669 18.5345 5.4645C19.4722 6.40231 19.9989 7.67419 19.9988 9.00035C19.9987 10.3265 19.4718 11.5983 18.534 12.536L18 13 M13.0001 18L12.6031 18.534C11.6544 19.4722 10.3739 19.9984 9.03964 19.9984C7.70535 19.9984 6.42489 19.4722 5.47614 18.534C5.0085 18.0716 4.63724 17.521 4.38385 16.9141C4.13047 16.3073 4 15.6561 4 14.9985C4 14.3408 4.13047 13.6897 4.38385 13.0829C4.63724 12.476 5.0085 11.9254 5.47614 11.463L6.00014 11";
|
||||
private string externalCallerBtnText = "外部点名";
|
||||
|
||||
|
||||
// JSON文件路径
|
||||
private static readonly string ConfigsFolder = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configs");
|
||||
private static readonly string RollCallHistoryJsonPath = System.IO.Path.Combine(ConfigsFolder, "RollCallHistory.json");
|
||||
@@ -211,7 +211,7 @@ namespace Ink_Canvas
|
||||
private void InitializeUI()
|
||||
{
|
||||
UpdateCountDisplay();
|
||||
LoadNamesFromFile();
|
||||
LoadNamesFromFile();
|
||||
UpdateListCountDisplay();
|
||||
LoadRollCallHistory();
|
||||
LoadSettings();
|
||||
@@ -308,7 +308,7 @@ namespace Ink_Canvas
|
||||
private void InitializeRollCallData()
|
||||
{
|
||||
// 初始化点名定时器
|
||||
rollCallTimer = new Timer(100);
|
||||
rollCallTimer = new Timer(100);
|
||||
rollCallTimer.Elapsed += RollCallTimer_Elapsed;
|
||||
}
|
||||
|
||||
@@ -375,7 +375,7 @@ namespace Ink_Canvas
|
||||
{
|
||||
// 更新窗口资源
|
||||
var resources = this.Resources;
|
||||
|
||||
|
||||
if (theme == "Light")
|
||||
{
|
||||
// 应用浅色主题资源
|
||||
@@ -459,10 +459,10 @@ namespace Ink_Canvas
|
||||
private List<string> SelectNamesSequentially(List<string> availableNames, int count)
|
||||
{
|
||||
if (availableNames.Count == 0) return new List<string>();
|
||||
|
||||
|
||||
var selectedNames = new List<string>();
|
||||
int startIndex = 0;
|
||||
|
||||
|
||||
// 从历史记录中找到上次选择的位置
|
||||
if (historyData.History != null && historyData.History.Count > 0)
|
||||
{
|
||||
@@ -476,13 +476,13 @@ namespace Ink_Canvas
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < count && i < availableNames.Count; i++)
|
||||
{
|
||||
int index = (startIndex + i) % availableNames.Count;
|
||||
selectedNames.Add(availableNames[index]);
|
||||
}
|
||||
|
||||
|
||||
return selectedNames;
|
||||
}
|
||||
|
||||
@@ -492,15 +492,15 @@ namespace Ink_Canvas
|
||||
private List<string> SelectNamesInGroups(List<string> availableNames, int count)
|
||||
{
|
||||
if (availableNames.Count == 0) return new List<string>();
|
||||
|
||||
|
||||
var selectedNames = new List<string>();
|
||||
int groupSize = Math.Max(1, availableNames.Count / count);
|
||||
|
||||
|
||||
for (int i = 0; i < count && i * groupSize < availableNames.Count; i++)
|
||||
{
|
||||
int startIndex = i * groupSize;
|
||||
int endIndex = Math.Min(startIndex + groupSize, availableNames.Count);
|
||||
|
||||
|
||||
// 从当前组中随机选择一个人
|
||||
var group = availableNames.GetRange(startIndex, endIndex - startIndex);
|
||||
if (group.Count > 0)
|
||||
@@ -509,7 +509,7 @@ namespace Ink_Canvas
|
||||
selectedNames.Add(group[randomIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return selectedNames;
|
||||
}
|
||||
#endregion
|
||||
@@ -646,12 +646,12 @@ namespace Ink_Canvas
|
||||
{
|
||||
// 获取基础概率
|
||||
double baseProbability = GetNameProbability(name);
|
||||
|
||||
|
||||
// 根据最近历史记录调整概率
|
||||
double adjustedProbability = AdjustProbabilityByRecentHistory(name, baseProbability);
|
||||
|
||||
|
||||
double finalProbability = AdjustProbabilityByFrequency(name, adjustedProbability);
|
||||
|
||||
|
||||
nameProbabilities[name] = finalProbability;
|
||||
}
|
||||
|
||||
@@ -692,13 +692,13 @@ namespace Ink_Canvas
|
||||
int recentCount = recentHistory.Count(n => n == name);
|
||||
|
||||
if (recentCount == 0)
|
||||
return baseProbability;
|
||||
return baseProbability;
|
||||
|
||||
double recentFrequency = (double)recentCount / Math.Min(recentHistory.Count, maxRecentHistory);
|
||||
|
||||
|
||||
double reductionFactor = 1.0 - (recentFrequency * avoidanceWeight);
|
||||
reductionFactor = Math.Max(reductionFactor, MIN_PROBABILITY / DEFAULT_PROBABILITY); // 确保不会降得太低
|
||||
|
||||
|
||||
return baseProbability * reductionFactor;
|
||||
}
|
||||
|
||||
@@ -732,20 +732,20 @@ namespace Ink_Canvas
|
||||
double frequencyRatio = nameFrequency / averageFrequency;
|
||||
|
||||
double frequencyGap = 1.0 - frequencyRatio;
|
||||
double boostFactor = FREQUENCY_BOOST_FACTOR * frequencyGap * frequencyGap;
|
||||
|
||||
double boostFactor = FREQUENCY_BOOST_FACTOR * frequencyGap * frequencyGap;
|
||||
|
||||
// 增加概率
|
||||
double boostedProbability = baseProbability * (1.0 + boostFactor);
|
||||
|
||||
|
||||
return Math.Min(boostedProbability, DEFAULT_PROBABILITY * 10.0);
|
||||
}
|
||||
else if (nameFrequency > averageFrequency)
|
||||
{
|
||||
double frequencyRatio = nameFrequency / averageFrequency;
|
||||
|
||||
double reductionFactor = 1.0 - (frequencyRatio - 1.0) * 0.3;
|
||||
|
||||
double reductionFactor = 1.0 - (frequencyRatio - 1.0) * 0.3;
|
||||
reductionFactor = Math.Max(reductionFactor, MIN_PROBABILITY / DEFAULT_PROBABILITY);
|
||||
|
||||
|
||||
return baseProbability * reductionFactor;
|
||||
}
|
||||
|
||||
@@ -782,8 +782,8 @@ namespace Ink_Canvas
|
||||
int nameCount = kvp.Value;
|
||||
|
||||
// 获取当前保存的概率(如果不存在则使用默认值)
|
||||
double currentProbability = historyData.NameProbabilities.ContainsKey(name)
|
||||
? historyData.NameProbabilities[name]
|
||||
double currentProbability = historyData.NameProbabilities.ContainsKey(name)
|
||||
? historyData.NameProbabilities[name]
|
||||
: DEFAULT_PROBABILITY;
|
||||
|
||||
// 计算该名字的选中频率
|
||||
@@ -795,24 +795,24 @@ namespace Ink_Canvas
|
||||
// 计算频率差异比例
|
||||
double frequencyRatio = nameFrequency / averageFrequency;
|
||||
double frequencyGap = 1.0 - frequencyRatio;
|
||||
double boostFactor = FREQUENCY_BOOST_FACTOR * frequencyGap * frequencyGap;
|
||||
|
||||
double boostFactor = FREQUENCY_BOOST_FACTOR * frequencyGap * frequencyGap;
|
||||
|
||||
// 增加概率
|
||||
double boostedProbability = currentProbability * (1.0 + boostFactor);
|
||||
|
||||
|
||||
// 限制最大概率,避免过高
|
||||
boostedProbability = Math.Min(boostedProbability, DEFAULT_PROBABILITY * 10.0);
|
||||
|
||||
|
||||
// 保存更新后的概率
|
||||
historyData.NameProbabilities[name] = boostedProbability;
|
||||
}
|
||||
else if (nameFrequency > averageFrequency)
|
||||
{
|
||||
double frequencyRatio = nameFrequency / averageFrequency;
|
||||
|
||||
double reductionFactor = 1.0 - (frequencyRatio - 1.0) * 0.3;
|
||||
|
||||
double reductionFactor = 1.0 - (frequencyRatio - 1.0) * 0.3;
|
||||
reductionFactor = Math.Max(reductionFactor, MIN_PROBABILITY / DEFAULT_PROBABILITY);
|
||||
|
||||
|
||||
double reducedProbability = currentProbability * reductionFactor;
|
||||
historyData.NameProbabilities[name] = reducedProbability;
|
||||
}
|
||||
@@ -963,19 +963,19 @@ namespace Ink_Canvas
|
||||
{
|
||||
double nameFrequency = (double)historyData.NameFrequency[name] / totalSelections;
|
||||
double averageFrequency = 1.0 / uniqueNamesCount;
|
||||
|
||||
|
||||
if (nameFrequency > averageFrequency)
|
||||
{
|
||||
double frequencyRatio = nameFrequency / averageFrequency;
|
||||
frequencyBasedDecay = 1.0 - (frequencyRatio - 1.0) * 0.2;
|
||||
frequencyBasedDecay = 1.0 - (frequencyRatio - 1.0) * 0.2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
double decayFactor = BASE_PROBABILITY_DECAY_FACTOR * (1.0 + avoidanceWeight) * frequencyBasedDecay;
|
||||
decayFactor = Math.Min(decayFactor, 0.85);
|
||||
|
||||
decayFactor = Math.Min(decayFactor, 0.85);
|
||||
|
||||
double newProbability = currentProbability * decayFactor;
|
||||
newProbability = Math.Max(newProbability, MIN_PROBABILITY); // 确保不低于最小概率
|
||||
historyData.NameProbabilities[name] = newProbability;
|
||||
@@ -1120,7 +1120,7 @@ namespace Ink_Canvas
|
||||
MainResultDisplay.Text = "";
|
||||
MainResultDisplay.Visibility = Visibility.Collapsed;
|
||||
MultiResultScrollViewer.Visibility = Visibility.Visible;
|
||||
|
||||
|
||||
// 显示所有结果(最多20个)
|
||||
Result1Display.Text = results.Count > 0 ? results[0] : "";
|
||||
Result2Display.Text = results.Count > 1 ? results[1] : "";
|
||||
@@ -1150,10 +1150,10 @@ namespace Ink_Canvas
|
||||
private void CountPlus_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (isRollCalling) return;
|
||||
|
||||
|
||||
// 获取老点名UI的设置
|
||||
int maxPeopleLimit = settings?.RandSettings?.RandWindowOnceMaxStudents ?? 10;
|
||||
|
||||
|
||||
if (isSingleDrawMode)
|
||||
{
|
||||
// 单次抽模式:最多选择60个数字,但受设置限制
|
||||
@@ -1176,7 +1176,7 @@ namespace Ink_Canvas
|
||||
}
|
||||
currentCount = Math.Min(currentCount + 1, maxCount);
|
||||
}
|
||||
|
||||
|
||||
UpdateCountDisplay();
|
||||
}
|
||||
|
||||
@@ -1194,7 +1194,7 @@ namespace Ink_Canvas
|
||||
// 打开名单导入窗口,与老点名UI保持一致
|
||||
var namesInputWindow = new NamesInputWindow();
|
||||
namesInputWindow.ShowDialog();
|
||||
|
||||
|
||||
// 重新加载名单
|
||||
LoadNamesFromFile();
|
||||
UpdateListCountDisplay();
|
||||
@@ -1260,7 +1260,7 @@ namespace Ink_Canvas
|
||||
{
|
||||
// 存储选择的模式
|
||||
selectedRollCallMode = mode;
|
||||
|
||||
|
||||
// 重置所有按钮状态
|
||||
RandomModeText.FontWeight = FontWeights.Normal;
|
||||
RandomModeText.Opacity = 0.6;
|
||||
@@ -1271,7 +1271,7 @@ namespace Ink_Canvas
|
||||
GroupModeText.FontWeight = FontWeights.Normal;
|
||||
GroupModeText.Opacity = 0.6;
|
||||
GroupModeText.Foreground = new SolidColorBrush(Color.FromRgb(102, 102, 102));
|
||||
|
||||
|
||||
// 重置外部点名模式按钮状态
|
||||
ExternalCallerModeText.FontWeight = FontWeights.Normal;
|
||||
ExternalCallerModeText.Opacity = 0.6;
|
||||
@@ -1288,13 +1288,13 @@ namespace Ink_Canvas
|
||||
RandomModeText.Foreground = new SolidColorBrush(Colors.White);
|
||||
SegmentedIndicator.HorizontalAlignment = HorizontalAlignment.Left;
|
||||
SegmentedIndicator.CornerRadius = new CornerRadius(7.5, 0, 0, 7.5);
|
||||
|
||||
|
||||
// 添加动画效果
|
||||
var randomAnimation = new System.Windows.Media.Animation.ThicknessAnimation(
|
||||
new Thickness(0, 0, 0, 0),
|
||||
TimeSpan.FromMilliseconds(200));
|
||||
SegmentedIndicator.BeginAnimation(Border.MarginProperty, randomAnimation);
|
||||
|
||||
|
||||
// 恢复开始点名按钮的原始图标和文字
|
||||
RestoreStartRollCallButton();
|
||||
UpdateStatusDisplay("已选择点名模式: 随机点名");
|
||||
@@ -1305,13 +1305,13 @@ namespace Ink_Canvas
|
||||
SequentialModeText.Foreground = new SolidColorBrush(Colors.White);
|
||||
SegmentedIndicator.HorizontalAlignment = HorizontalAlignment.Left;
|
||||
SegmentedIndicator.CornerRadius = new CornerRadius(0, 0, 0, 0);
|
||||
|
||||
|
||||
// 添加动画效果 - 移动到中间位置
|
||||
var sequentialAnimation = new System.Windows.Media.Animation.ThicknessAnimation(
|
||||
new Thickness(100, 0, 0, 0),
|
||||
TimeSpan.FromMilliseconds(200));
|
||||
SegmentedIndicator.BeginAnimation(Border.MarginProperty, sequentialAnimation);
|
||||
|
||||
|
||||
// 恢复开始点名按钮的原始图标和文字
|
||||
RestoreStartRollCallButton();
|
||||
UpdateStatusDisplay("已选择点名模式: 顺序点名");
|
||||
@@ -1322,13 +1322,13 @@ namespace Ink_Canvas
|
||||
GroupModeText.Foreground = new SolidColorBrush(Colors.White);
|
||||
SegmentedIndicator.HorizontalAlignment = HorizontalAlignment.Left;
|
||||
SegmentedIndicator.CornerRadius = new CornerRadius(0, 7.5, 7.5, 0);
|
||||
|
||||
|
||||
// 添加动画效果 - 移动到右侧位置
|
||||
var groupAnimation = new System.Windows.Media.Animation.ThicknessAnimation(
|
||||
new Thickness(200, 0, 0, 0),
|
||||
TimeSpan.FromMilliseconds(200));
|
||||
SegmentedIndicator.BeginAnimation(Border.MarginProperty, groupAnimation);
|
||||
|
||||
|
||||
// 恢复开始点名按钮的原始图标和文字
|
||||
RestoreStartRollCallButton();
|
||||
UpdateStatusDisplay("已选择点名模式: 分组点名");
|
||||
@@ -1339,10 +1339,10 @@ namespace Ink_Canvas
|
||||
ExternalCallerModeText.Opacity = 1.0;
|
||||
ExternalCallerModeText.Foreground = new SolidColorBrush(Colors.White);
|
||||
ExternalCallerModeIndicator.Visibility = Visibility.Visible;
|
||||
|
||||
|
||||
// 隐藏其他模式的指示器
|
||||
SegmentedIndicator.Visibility = Visibility.Collapsed;
|
||||
|
||||
|
||||
// 切换到外部点名按钮的图标和文字
|
||||
UpdateStartRollCallButtonForExternal();
|
||||
UpdateStatusDisplay($"已选择点名模式: 外部点名 ({selectedExternalCaller})");
|
||||
@@ -1354,7 +1354,7 @@ namespace Ink_Canvas
|
||||
LogHelper.WriteLogToFile($"设置点名模式选择时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 更新开始点名按钮为外部点名样式
|
||||
/// </summary>
|
||||
@@ -1369,14 +1369,14 @@ namespace Ink_Canvas
|
||||
// 外部点名使用按钮前景色而不是主按钮前景色
|
||||
StartRollCallBtnIcon.Stroke = (Brush)FindResource("NewRollCallWindowButtonForeground");
|
||||
}
|
||||
|
||||
|
||||
// 更新文字
|
||||
if (StartRollCallBtnText != null)
|
||||
{
|
||||
StartRollCallBtnText.Text = externalCallerBtnText;
|
||||
StartRollCallBtnText.Foreground = (Brush)FindResource("NewRollCallWindowButtonForeground");
|
||||
}
|
||||
|
||||
|
||||
// 更新按钮背景色为普通按钮背景
|
||||
StartRollCallBtn.Background = (Brush)FindResource("NewRollCallWindowButtonBackground");
|
||||
}
|
||||
@@ -1385,7 +1385,7 @@ namespace Ink_Canvas
|
||||
LogHelper.WriteLogToFile($"更新开始点名按钮为外部点名样式时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 恢复开始点名按钮的原始样式
|
||||
/// </summary>
|
||||
@@ -1399,14 +1399,14 @@ namespace Ink_Canvas
|
||||
StartRollCallBtnIcon.Data = Geometry.Parse(originalStartBtnIconData);
|
||||
StartRollCallBtnIcon.Stroke = (Brush)FindResource("NewRollCallWindowPrimaryButtonForeground");
|
||||
}
|
||||
|
||||
|
||||
// 恢复文字
|
||||
if (StartRollCallBtnText != null)
|
||||
{
|
||||
StartRollCallBtnText.Text = originalStartBtnText;
|
||||
StartRollCallBtnText.Foreground = (Brush)FindResource("NewRollCallWindowPrimaryButtonForeground");
|
||||
}
|
||||
|
||||
|
||||
// 恢复按钮背景色为主按钮背景
|
||||
StartRollCallBtn.Background = (Brush)FindResource("NewRollCallWindowPrimaryButtonBackground");
|
||||
}
|
||||
@@ -1443,7 +1443,7 @@ namespace Ink_Canvas
|
||||
if (ExternalCallerTypeComboBox.SelectedItem is ComboBoxItem selectedItem)
|
||||
{
|
||||
selectedExternalCaller = selectedItem.Content.ToString();
|
||||
|
||||
|
||||
if (selectedRollCallMode == "External")
|
||||
{
|
||||
UpdateStatusDisplay($"已选择外部点名: {selectedExternalCaller}");
|
||||
@@ -1456,7 +1456,7 @@ namespace Ink_Canvas
|
||||
}
|
||||
}
|
||||
|
||||
private static bool isExternalCallerFirstClick = true;
|
||||
private static bool isExternalCallerFirstClick = true;
|
||||
|
||||
private void ExternalCaller_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
@@ -1513,7 +1513,7 @@ namespace Ink_Canvas
|
||||
ExternalCaller_Click(sender, e);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (isSingleDrawMode)
|
||||
{
|
||||
// 单次抽模式:直接开始抽选
|
||||
@@ -1576,18 +1576,18 @@ namespace Ink_Canvas
|
||||
{
|
||||
const int animationTimes = 100; // 动画次数
|
||||
const int sleepTime = 5; // 每次动画间隔(毫秒)
|
||||
|
||||
|
||||
new System.Threading.Thread(() =>
|
||||
{
|
||||
List<string> usedNames = new List<string>();
|
||||
|
||||
|
||||
// 确保动画期间主显示区域可见
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
MainResultDisplay.Visibility = Visibility.Visible;
|
||||
MultiResultScrollViewer.Visibility = Visibility.Collapsed;
|
||||
});
|
||||
|
||||
|
||||
for (int i = 0; i < animationTimes; i++)
|
||||
{
|
||||
// 随机选择一个名字进行动画显示
|
||||
@@ -1595,7 +1595,7 @@ namespace Ink_Canvas
|
||||
{
|
||||
int randomIndex = new Random().Next(0, nameList.Count);
|
||||
string displayName = nameList[randomIndex];
|
||||
|
||||
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
// 确保主显示区域在动画期间保持可见
|
||||
@@ -1603,16 +1603,16 @@ namespace Ink_Canvas
|
||||
MainResultDisplay.Text = displayName;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
System.Threading.Thread.Sleep(sleepTime);
|
||||
}
|
||||
|
||||
|
||||
// 动画结束,显示最终结果
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
// 根据选择的模式进行不同的点名逻辑
|
||||
var selectedNames = SelectNamesByMode(nameList, currentCount);
|
||||
|
||||
|
||||
// 更新历史记录
|
||||
UpdateRollCallHistory(selectedNames);
|
||||
|
||||
@@ -1646,40 +1646,40 @@ namespace Ink_Canvas
|
||||
{
|
||||
const int animationTimes = 100; // 动画次数
|
||||
const int sleepTime = 5; // 每次动画间隔(毫秒)
|
||||
|
||||
|
||||
new System.Threading.Thread(() =>
|
||||
{
|
||||
List<int> usedNumbers = new List<int>();
|
||||
|
||||
|
||||
// 确保动画期间主显示区域可见
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
MainResultDisplay.Visibility = Visibility.Visible;
|
||||
MultiResultScrollViewer.Visibility = Visibility.Collapsed;
|
||||
});
|
||||
|
||||
|
||||
for (int i = 0; i < animationTimes; i++)
|
||||
{
|
||||
// 随机选择一个数字进行动画显示
|
||||
int randomNumber = new Random().Next(1, 61); // 1-60
|
||||
|
||||
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
// 确保主显示区域在动画期间保持可见
|
||||
MainResultDisplay.Visibility = Visibility.Visible;
|
||||
MainResultDisplay.Text = randomNumber.ToString();
|
||||
});
|
||||
|
||||
|
||||
System.Threading.Thread.Sleep(sleepTime);
|
||||
}
|
||||
|
||||
|
||||
// 动画结束,显示最终结果
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
// 根据选择的模式进行不同的抽选逻辑
|
||||
var numberList = Enumerable.Range(1, 60).Select(n => n.ToString()).ToList();
|
||||
var selectedNumbers = SelectNamesByMode(numberList, currentCount);
|
||||
|
||||
|
||||
// 更新历史记录
|
||||
UpdateRollCallHistory(selectedNumbers);
|
||||
|
||||
@@ -1724,7 +1724,7 @@ namespace Ink_Canvas
|
||||
{
|
||||
const int animationTimes = 100; // 动画次数
|
||||
const int sleepTime = 5; // 每次动画间隔(毫秒),参考老点名窗口
|
||||
|
||||
|
||||
new System.Threading.Thread(() =>
|
||||
{
|
||||
if (nameList.Count > 0)
|
||||
@@ -1746,7 +1746,7 @@ namespace Ink_Canvas
|
||||
private void StartSingleDrawNameAnimation(int animationTimes, int sleepTime)
|
||||
{
|
||||
List<string> usedNames = new List<string>();
|
||||
|
||||
|
||||
for (int i = 0; i < animationTimes; i++)
|
||||
{
|
||||
// 随机选择一个名字进行动画显示,避免立即重复
|
||||
@@ -1755,23 +1755,23 @@ namespace Ink_Canvas
|
||||
{
|
||||
randomName = nameList[singleDrawRandom.Next(0, nameList.Count)];
|
||||
} while (usedNames.Count > 0 && usedNames[usedNames.Count - 1] == randomName);
|
||||
|
||||
|
||||
usedNames.Add(randomName);
|
||||
|
||||
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
MainResultDisplay.Text = randomName;
|
||||
});
|
||||
|
||||
|
||||
System.Threading.Thread.Sleep(sleepTime);
|
||||
}
|
||||
|
||||
|
||||
// 动画结束,显示最终结果
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
// 根据选择的模式进行不同的抽选逻辑
|
||||
var selectedNames = SelectNamesByMode(nameList, currentCount);
|
||||
|
||||
|
||||
// 更新历史记录
|
||||
UpdateRollCallHistory(selectedNames);
|
||||
|
||||
@@ -1783,7 +1783,7 @@ namespace Ink_Canvas
|
||||
isRollCalling = false;
|
||||
StartRollCallBtn.Visibility = Visibility.Visible;
|
||||
StopRollCallBtn.Visibility = Visibility.Collapsed;
|
||||
|
||||
|
||||
if (isSingleDrawMode)
|
||||
{
|
||||
new System.Threading.Thread(() =>
|
||||
@@ -1819,7 +1819,7 @@ namespace Ink_Canvas
|
||||
private void StartSingleDrawNumberAnimation(int animationTimes, int sleepTime)
|
||||
{
|
||||
List<int> usedNumbers = new List<int>();
|
||||
|
||||
|
||||
for (int i = 0; i < animationTimes; i++)
|
||||
{
|
||||
// 随机选择一个数字进行动画显示,避免立即重复
|
||||
@@ -1828,27 +1828,27 @@ namespace Ink_Canvas
|
||||
{
|
||||
randomNumber = singleDrawRandom.Next(1, 61); // 1-60
|
||||
} while (usedNumbers.Count > 0 && usedNumbers[usedNumbers.Count - 1] == randomNumber);
|
||||
|
||||
|
||||
usedNumbers.Add(randomNumber);
|
||||
|
||||
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
MainResultDisplay.Text = randomNumber.ToString();
|
||||
});
|
||||
|
||||
|
||||
System.Threading.Thread.Sleep(sleepTime);
|
||||
}
|
||||
|
||||
|
||||
// 动画结束,显示最终结果
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
// 根据选择的模式进行不同的抽选逻辑
|
||||
var numberList = Enumerable.Range(1, 60).Select(n => n.ToString()).ToList();
|
||||
var selectedNumbers = SelectNamesByMode(numberList, currentCount);
|
||||
|
||||
|
||||
// 更新历史记录
|
||||
UpdateRollCallHistory(selectedNumbers);
|
||||
|
||||
|
||||
if (selectedNumbers.Count == 1)
|
||||
{
|
||||
MainResultDisplay.Text = selectedNumbers[0];
|
||||
@@ -1858,19 +1858,19 @@ namespace Ink_Canvas
|
||||
{
|
||||
MainResultDisplay.Text = "抽选结果";
|
||||
MultiResultPanel.Visibility = Visibility.Visible;
|
||||
|
||||
|
||||
Result1Display.Text = selectedNumbers.Count > 0 ? selectedNumbers[0] : "";
|
||||
Result2Display.Text = selectedNumbers.Count > 1 ? selectedNumbers[1] : "";
|
||||
Result3Display.Text = selectedNumbers.Count > 2 ? selectedNumbers[2] : "";
|
||||
|
||||
|
||||
UpdateStatusDisplay($"抽选完成,共选择 {selectedNumbers.Count} 个数字");
|
||||
}
|
||||
|
||||
|
||||
// 停止点名状态
|
||||
isRollCalling = false;
|
||||
StartRollCallBtn.Visibility = Visibility.Visible;
|
||||
StopRollCallBtn.Visibility = Visibility.Collapsed;
|
||||
|
||||
|
||||
if (isSingleDrawMode)
|
||||
{
|
||||
new System.Threading.Thread(() =>
|
||||
@@ -1908,21 +1908,21 @@ namespace Ink_Canvas
|
||||
{
|
||||
var selectedNumbers = new List<string>();
|
||||
var usedNumbers = new List<int>();
|
||||
|
||||
|
||||
for (int i = 0; i < count && usedNumbers.Count < 60; i++)
|
||||
{
|
||||
int randomNumber = singleDrawRandom.Next(1, 61); // 1-60
|
||||
|
||||
|
||||
// 避免重复选择
|
||||
while (usedNumbers.Contains(randomNumber))
|
||||
{
|
||||
randomNumber = singleDrawRandom.Next(1, 61);
|
||||
}
|
||||
|
||||
|
||||
usedNumbers.Add(randomNumber);
|
||||
selectedNumbers.Add(randomNumber.ToString());
|
||||
}
|
||||
|
||||
|
||||
return selectedNumbers;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
using Ink_Canvas.Helpers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
using System.Runtime.InteropServices;
|
||||
using Newtonsoft.Json;
|
||||
using System.IO;
|
||||
|
||||
namespace Ink_Canvas
|
||||
{
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using Ink_Canvas.Helpers;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using Newtonsoft.Json;
|
||||
using MessageBox = iNKORE.UI.WPF.Modern.Controls.MessageBox;
|
||||
|
||||
namespace Ink_Canvas
|
||||
{
|
||||
@@ -95,26 +94,26 @@ namespace Ink_Canvas
|
||||
// 显示统计信息
|
||||
int totalCount = historyData.History.Count;
|
||||
string lastUpdate = historyData.LastUpdate.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
|
||||
// 计算累计统计信息
|
||||
var statsLines = new System.Collections.Generic.List<string>();
|
||||
statsLines.Add($"");
|
||||
statsLines.Add($"");
|
||||
statsLines.Add($"累计抽选次数统计:");
|
||||
|
||||
|
||||
// 按累计次数降序排序显示
|
||||
var sortedStats = nameCountDict.OrderByDescending(kvp => kvp.Value).ToList();
|
||||
foreach (var kvp in sortedStats)
|
||||
{
|
||||
statsLines.Add($" {kvp.Key}: {kvp.Value}次");
|
||||
}
|
||||
|
||||
|
||||
statsLines.Add($"");
|
||||
statsLines.Add($"共 {totalCount} 条记录,最后更新:{lastUpdate}");
|
||||
|
||||
|
||||
// 组合历史记录和统计信息
|
||||
TextBoxHistory.Text = string.Join(Environment.NewLine, historyLines) +
|
||||
Environment.NewLine +
|
||||
TextBoxHistory.Text = string.Join(Environment.NewLine, historyLines) +
|
||||
Environment.NewLine +
|
||||
string.Join(Environment.NewLine, statsLines);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -184,7 +183,7 @@ namespace Ink_Canvas
|
||||
try
|
||||
{
|
||||
var resources = this.Resources;
|
||||
|
||||
|
||||
if (theme == "Light")
|
||||
{
|
||||
// 应用浅色主题资源
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Ink_Canvas.Helpers;
|
||||
using Microsoft.Win32;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Media;
|
||||
@@ -7,10 +9,6 @@ using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
using Newtonsoft.Json;
|
||||
using System.Windows.Threading;
|
||||
using Microsoft.Win32;
|
||||
namespace Ink_Canvas.Windows
|
||||
{
|
||||
/// <summary>
|
||||
@@ -41,25 +39,25 @@ namespace Ink_Canvas.Windows
|
||||
|
||||
// 应用主题
|
||||
ApplyTheme();
|
||||
|
||||
|
||||
// 初始化隐藏定时器
|
||||
hideTimer = new Timer(1000); // 每秒检查一次
|
||||
hideTimer.Elapsed += HideTimer_Elapsed;
|
||||
lastActivityTime = DateTime.Now;
|
||||
|
||||
|
||||
// 监听主题变化事件
|
||||
SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged;
|
||||
|
||||
|
||||
// 监听卸载事件,清理资源
|
||||
Unloaded += TimerControl_Unloaded;
|
||||
}
|
||||
|
||||
|
||||
private void TimerControl_Unloaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// 取消订阅主题变化事件
|
||||
SystemEvents.UserPreferenceChanged -= SystemEvents_UserPreferenceChanged;
|
||||
}
|
||||
|
||||
|
||||
private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
|
||||
{
|
||||
// 当主题变化时,重新应用主题
|
||||
@@ -68,7 +66,7 @@ namespace Ink_Canvas.Windows
|
||||
RefreshTheme();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 刷新主题
|
||||
/// </summary>
|
||||
@@ -78,7 +76,7 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
// 重新应用主题
|
||||
ApplyTheme();
|
||||
|
||||
|
||||
// 强制刷新UI
|
||||
InvalidateVisual();
|
||||
}
|
||||
@@ -87,23 +85,23 @@ namespace Ink_Canvas.Windows
|
||||
LogHelper.WriteLogToFile($"刷新计时器窗口主题出错: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region 事件定义
|
||||
/// <summary>
|
||||
/// 计时器完成事件
|
||||
/// </summary>
|
||||
public event EventHandler TimerCompleted;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 关闭事件 - 通知主窗口隐藏容器
|
||||
/// </summary>
|
||||
public event EventHandler CloseRequested;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 显示最小化视图事件
|
||||
/// </summary>
|
||||
public event EventHandler ShowMinimizedRequested;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 隐藏最小化视图事件
|
||||
/// </summary>
|
||||
@@ -129,7 +127,7 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
TimeSpan leftTimeSpan = totalTimeSpan - timeSpan;
|
||||
if (leftTimeSpan.Milliseconds > 0) leftTimeSpan += new TimeSpan(0, 0, 1);
|
||||
|
||||
|
||||
int totalHours = (int)leftTimeSpan.TotalHours;
|
||||
int displayHours = totalHours;
|
||||
|
||||
@@ -141,10 +139,10 @@ namespace Ink_Canvas.Windows
|
||||
SetDigitDisplay("Digit4Display", leftTimeSpan.Minutes % 10);
|
||||
SetDigitDisplay("Digit5Display", leftTimeSpan.Seconds / 10);
|
||||
SetDigitDisplay("Digit6Display", leftTimeSpan.Seconds % 10);
|
||||
|
||||
|
||||
SetColonDisplay(false);
|
||||
|
||||
if (leftTimeSpan.TotalSeconds <= 6 && leftTimeSpan.TotalSeconds > 0 &&
|
||||
|
||||
if (leftTimeSpan.TotalSeconds <= 6 && leftTimeSpan.TotalSeconds > 0 &&
|
||||
MainWindow.Settings.RandSettings?.EnableProgressiveReminder == true &&
|
||||
!hasPlayedProgressiveReminder)
|
||||
{
|
||||
@@ -165,19 +163,19 @@ namespace Ink_Canvas.Windows
|
||||
SetDigitDisplay("Digit4Display", 0);
|
||||
SetDigitDisplay("Digit5Display", 0);
|
||||
SetDigitDisplay("Digit6Display", 0);
|
||||
|
||||
|
||||
SetColonDisplay(false);
|
||||
timer.Stop();
|
||||
isTimerRunning = false;
|
||||
StartPauseIcon.Data = Geometry.Parse(PlayIconData);
|
||||
PlayTimerSound();
|
||||
|
||||
|
||||
// 禁用全屏按钮
|
||||
if (FullscreenBtn != null)
|
||||
{
|
||||
FullscreenBtn.IsEnabled = false;
|
||||
}
|
||||
|
||||
|
||||
TimerCompleted?.Invoke(this, EventArgs.Empty);
|
||||
HandleTimerCompletion();
|
||||
}
|
||||
@@ -206,7 +204,7 @@ namespace Ink_Canvas.Windows
|
||||
SetDigitDisplay("Digit4Display", minutesOnes, shouldShowRed);
|
||||
SetDigitDisplay("Digit5Display", secondsTens, shouldShowRed);
|
||||
SetDigitDisplay("Digit6Display", secondsOnes, shouldShowRed);
|
||||
|
||||
|
||||
SetColonDisplay(shouldShowRed);
|
||||
}
|
||||
});
|
||||
@@ -224,22 +222,22 @@ namespace Ink_Canvas.Windows
|
||||
|
||||
bool isTimerRunning = false;
|
||||
bool isPaused = false;
|
||||
bool isOvertimeMode = false;
|
||||
bool isOvertimeMode = false;
|
||||
TimeSpan remainingTime = TimeSpan.Zero;
|
||||
bool hasPlayedProgressiveReminder = false;
|
||||
|
||||
bool hasPlayedProgressiveReminder = false;
|
||||
|
||||
Timer timer = new Timer();
|
||||
private Timer hideTimer;
|
||||
private DateTime lastActivityTime;
|
||||
private DateTime lastActivityTime;
|
||||
public TimeSpan? GetTotalTimeSpan()
|
||||
{
|
||||
return new TimeSpan(hour, minute, second);
|
||||
}
|
||||
|
||||
|
||||
public TimeSpan? GetElapsedTime()
|
||||
{
|
||||
if (isPaused) return null;
|
||||
|
||||
|
||||
return DateTime.Now - startTime;
|
||||
}
|
||||
|
||||
@@ -336,7 +334,7 @@ namespace Ink_Canvas.Windows
|
||||
SetDarkThemeBorder();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 刷新数字和冒号显示的颜色
|
||||
UpdateDigitDisplays();
|
||||
}
|
||||
@@ -379,7 +377,7 @@ namespace Ink_Canvas.Windows
|
||||
SetDigitDisplay("Digit4Display", minute % 10);
|
||||
SetDigitDisplay("Digit5Display", second / 10);
|
||||
SetDigitDisplay("Digit6Display", second % 10);
|
||||
|
||||
|
||||
SetColonDisplay(false);
|
||||
}
|
||||
|
||||
@@ -394,10 +392,10 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
// 计算已经过去的时间
|
||||
TimeSpan elapsedTime = DateTime.Now - startTime;
|
||||
|
||||
|
||||
// 计算新的总时间
|
||||
TimeSpan newTotalTime = new TimeSpan(hour, minute, second);
|
||||
|
||||
|
||||
// 如果新设置的时间小于已经过去的时间,则设置为0
|
||||
if (newTotalTime <= elapsedTime)
|
||||
{
|
||||
@@ -428,10 +426,10 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
// 计算已经过去的时间
|
||||
TimeSpan elapsedTime = DateTime.Now - startTime;
|
||||
|
||||
|
||||
// 计算新的总时间
|
||||
TimeSpan newTotalTime = new TimeSpan(newHour, newMinute, newSecond);
|
||||
|
||||
|
||||
// 如果新设置的时间小于已经过去的时间,则设置为0
|
||||
if (newTotalTime <= elapsedTime)
|
||||
{
|
||||
@@ -456,13 +454,13 @@ namespace Ink_Canvas.Windows
|
||||
public TimeSpan? GetRemainingTime()
|
||||
{
|
||||
if (isPaused) return null;
|
||||
|
||||
|
||||
var elapsed = DateTime.Now - startTime;
|
||||
var totalTimeSpan = new TimeSpan(hour, minute, second);
|
||||
var leftTimeSpan = totalTimeSpan - elapsed;
|
||||
|
||||
|
||||
if (leftTimeSpan.Milliseconds > 0) leftTimeSpan += new TimeSpan(0, 0, 1);
|
||||
|
||||
|
||||
return leftTimeSpan;
|
||||
}
|
||||
|
||||
@@ -486,14 +484,14 @@ namespace Ink_Canvas.Windows
|
||||
if (path != null)
|
||||
{
|
||||
digit = Math.Max(0, Math.Min(9, digit));
|
||||
|
||||
|
||||
string resourceKey = $"Digit{digit}";
|
||||
var geometry = this.FindResource(resourceKey) as Geometry;
|
||||
if (geometry != null)
|
||||
{
|
||||
path.Data = geometry;
|
||||
}
|
||||
|
||||
|
||||
if (isRed)
|
||||
{
|
||||
path.Fill = Brushes.Red;
|
||||
@@ -521,7 +519,7 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
var colon1 = this.FindName("Colon1Display") as TextBlock;
|
||||
var colon2 = this.FindName("Colon2Display") as TextBlock;
|
||||
|
||||
|
||||
if (colon1 != null)
|
||||
{
|
||||
if (isRed)
|
||||
@@ -541,7 +539,7 @@ namespace Ink_Canvas.Windows
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (colon2 != null)
|
||||
{
|
||||
if (isRed)
|
||||
@@ -816,15 +814,15 @@ namespace Ink_Canvas.Windows
|
||||
isPaused = false;
|
||||
isTimerRunning = true;
|
||||
isOvertimeMode = false;
|
||||
hasPlayedProgressiveReminder = false;
|
||||
hasPlayedProgressiveReminder = false;
|
||||
timer.Start();
|
||||
|
||||
|
||||
// 启动隐藏定时器
|
||||
hideTimer.Start();
|
||||
|
||||
// 保存到最近计时记录
|
||||
SaveRecentTimer();
|
||||
|
||||
|
||||
// 启用全屏按钮
|
||||
if (FullscreenBtn != null)
|
||||
{
|
||||
@@ -836,31 +834,31 @@ namespace Ink_Canvas.Windows
|
||||
private void Reset_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
UpdateActivityTime();
|
||||
|
||||
|
||||
if (isTimerRunning)
|
||||
{
|
||||
// 停止计时器
|
||||
timer.Stop();
|
||||
isTimerRunning = false;
|
||||
isPaused = false;
|
||||
|
||||
|
||||
if (hideTimer != null)
|
||||
{
|
||||
hideTimer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
UpdateDigitDisplays();
|
||||
SetColonDisplay(false);
|
||||
|
||||
|
||||
if (StartPauseIcon != null)
|
||||
{
|
||||
StartPauseIcon.Data = Geometry.Parse(PlayIconData);
|
||||
}
|
||||
|
||||
|
||||
isOvertimeMode = false;
|
||||
hasPlayedProgressiveReminder = false;
|
||||
|
||||
|
||||
// 禁用全屏按钮
|
||||
if (FullscreenBtn != null)
|
||||
{
|
||||
@@ -1146,10 +1144,10 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
// 如果存在重复,将其移到最前面
|
||||
string duplicateTimer = GetRecentTimerByIndex(existingIndex);
|
||||
|
||||
|
||||
// 移除重复项
|
||||
RemoveRecentTimerByIndex(existingIndex);
|
||||
|
||||
|
||||
// 将重复项添加到最前面
|
||||
recentTimer6 = recentTimer5;
|
||||
recentTimer5 = recentTimer4;
|
||||
@@ -1354,9 +1352,9 @@ namespace Ink_Canvas.Windows
|
||||
}
|
||||
|
||||
private FullscreenTimerWindow fullscreenWindow;
|
||||
|
||||
|
||||
public bool IsFullscreenWindowOpen => fullscreenWindow != null && fullscreenWindow.IsVisible;
|
||||
|
||||
|
||||
private void Fullscreen_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (fullscreenWindow != null && fullscreenWindow.IsVisible)
|
||||
@@ -1365,7 +1363,7 @@ namespace Ink_Canvas.Windows
|
||||
fullscreenWindow = null;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (isTimerRunning && !isPaused)
|
||||
{
|
||||
fullscreenWindow = new FullscreenTimerWindow(this);
|
||||
@@ -1374,7 +1372,7 @@ namespace Ink_Canvas.Windows
|
||||
HideMinimizedRequested?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void MainBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
UpdateActivityTime();
|
||||
@@ -1393,7 +1391,7 @@ namespace Ink_Canvas.Windows
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void TitleBar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
UpdateActivityTime();
|
||||
@@ -1412,25 +1410,25 @@ namespace Ink_Canvas.Windows
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private bool isDragging = false;
|
||||
private Point dragStartPoint;
|
||||
private Point containerStartPosition;
|
||||
|
||||
|
||||
private void DragTimerContainer(MainWindow mainWindow, Point startPoint, MouseButtonEventArgs e)
|
||||
{
|
||||
var timerContainer = mainWindow.FindName("TimerContainer") as FrameworkElement;
|
||||
if (timerContainer == null) return;
|
||||
|
||||
|
||||
isDragging = true;
|
||||
dragStartPoint = startPoint;
|
||||
|
||||
if (timerContainer.HorizontalAlignment == HorizontalAlignment.Center ||
|
||||
|
||||
if (timerContainer.HorizontalAlignment == HorizontalAlignment.Center ||
|
||||
timerContainer.VerticalAlignment == VerticalAlignment.Center)
|
||||
{
|
||||
var timerPoint = timerContainer.TransformToAncestor(mainWindow).Transform(new Point(0, 0));
|
||||
containerStartPosition = new Point(timerPoint.X, timerPoint.Y);
|
||||
|
||||
|
||||
timerContainer.Margin = new Thickness(containerStartPosition.X, containerStartPosition.Y, 0, 0);
|
||||
timerContainer.HorizontalAlignment = HorizontalAlignment.Left;
|
||||
timerContainer.VerticalAlignment = VerticalAlignment.Top;
|
||||
@@ -1439,44 +1437,44 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
var margin = timerContainer.Margin;
|
||||
containerStartPosition = new Point(margin.Left, margin.Top);
|
||||
|
||||
|
||||
if (double.IsNaN(containerStartPosition.X) || containerStartPosition.X < 0) containerStartPosition.X = 0;
|
||||
if (double.IsNaN(containerStartPosition.Y) || containerStartPosition.Y < 0) containerStartPosition.Y = 0;
|
||||
}
|
||||
|
||||
|
||||
timerContainer.CaptureMouse();
|
||||
timerContainer.MouseMove += TimerContainer_MouseMove;
|
||||
timerContainer.MouseLeftButtonUp += TimerContainer_MouseLeftButtonUp;
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
|
||||
private void TimerContainer_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (!isDragging) return;
|
||||
|
||||
|
||||
UpdateActivityTime();
|
||||
|
||||
|
||||
var mainWindow = Application.Current.MainWindow as MainWindow;
|
||||
if (mainWindow == null) return;
|
||||
|
||||
|
||||
var timerContainer = mainWindow.FindName("TimerContainer") as FrameworkElement;
|
||||
var minimizedContainer = mainWindow.FindName("MinimizedTimerContainer") as FrameworkElement;
|
||||
if (timerContainer == null) return;
|
||||
|
||||
|
||||
var currentPoint = e.GetPosition(mainWindow);
|
||||
var deltaX = currentPoint.X - dragStartPoint.X;
|
||||
var deltaY = currentPoint.Y - dragStartPoint.Y;
|
||||
|
||||
|
||||
var newX = containerStartPosition.X + deltaX;
|
||||
var newY = containerStartPosition.Y + deltaY;
|
||||
|
||||
|
||||
if (newX < 0) newX = 0;
|
||||
if (newY < 0) newY = 0;
|
||||
|
||||
|
||||
timerContainer.Margin = new Thickness(newX, newY, 0, 0);
|
||||
timerContainer.HorizontalAlignment = HorizontalAlignment.Left;
|
||||
timerContainer.VerticalAlignment = VerticalAlignment.Top;
|
||||
|
||||
|
||||
if (minimizedContainer != null && minimizedContainer.Visibility == Visibility.Visible)
|
||||
{
|
||||
minimizedContainer.Margin = new Thickness(newX, newY, 0, 0);
|
||||
@@ -1484,16 +1482,16 @@ namespace Ink_Canvas.Windows
|
||||
minimizedContainer.VerticalAlignment = VerticalAlignment.Top;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void TimerContainer_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (!isDragging) return;
|
||||
|
||||
|
||||
isDragging = false;
|
||||
|
||||
|
||||
var mainWindow = Application.Current.MainWindow as MainWindow;
|
||||
if (mainWindow == null) return;
|
||||
|
||||
|
||||
var timerContainer = mainWindow.FindName("TimerContainer") as FrameworkElement;
|
||||
if (timerContainer != null)
|
||||
{
|
||||
@@ -1502,7 +1500,7 @@ namespace Ink_Canvas.Windows
|
||||
timerContainer.MouseLeftButtonUp -= TimerContainer_MouseLeftButtonUp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void HandleTimerCompletion()
|
||||
{
|
||||
// 计时器结束时,如果显示的是最小化视图,恢复到主窗口视图
|
||||
@@ -1513,7 +1511,7 @@ namespace Ink_Canvas.Windows
|
||||
{
|
||||
var timerContainer = mainWindow.FindName("TimerContainer") as FrameworkElement;
|
||||
var minimizedContainer = mainWindow.FindName("MinimizedTimerContainer") as FrameworkElement;
|
||||
|
||||
|
||||
// 如果最小化视图可见,恢复到主窗口视图
|
||||
if (minimizedContainer != null && minimizedContainer.Visibility == Visibility.Visible)
|
||||
{
|
||||
@@ -1521,11 +1519,11 @@ namespace Ink_Canvas.Windows
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// 重置计时器状态
|
||||
ResetTimerState();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 重置计时器状态
|
||||
/// </summary>
|
||||
@@ -1539,32 +1537,32 @@ namespace Ink_Canvas.Windows
|
||||
timer.Stop();
|
||||
isTimerRunning = false;
|
||||
isPaused = false;
|
||||
|
||||
|
||||
if (hideTimer != null)
|
||||
{
|
||||
hideTimer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 重置时间到默认值
|
||||
hour = 0;
|
||||
minute = 5;
|
||||
second = 0;
|
||||
|
||||
|
||||
// 更新显示
|
||||
UpdateDigitDisplays();
|
||||
SetColonDisplay(false);
|
||||
|
||||
|
||||
// 重置图标
|
||||
if (StartPauseIcon != null)
|
||||
{
|
||||
StartPauseIcon.Data = Geometry.Parse(PlayIconData);
|
||||
}
|
||||
|
||||
|
||||
// 重置状态标志
|
||||
isOvertimeMode = false;
|
||||
hasPlayedProgressiveReminder = false;
|
||||
|
||||
|
||||
// 禁用全屏按钮
|
||||
if (FullscreenBtn != null)
|
||||
{
|
||||
@@ -1572,15 +1570,15 @@ namespace Ink_Canvas.Windows
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void HideTimer_Elapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
if (!isTimerRunning || isPaused) return;
|
||||
|
||||
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
var timeSinceLastActivity = DateTime.Now - lastActivityTime;
|
||||
|
||||
|
||||
if (timeSinceLastActivity.TotalSeconds >= 5)
|
||||
{
|
||||
var mainWindow = Application.Current.MainWindow as MainWindow;
|
||||
@@ -1595,17 +1593,17 @@ namespace Ink_Canvas.Windows
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void UpdateActivityTime()
|
||||
{
|
||||
lastActivityTime = DateTime.Now;
|
||||
|
||||
|
||||
var mainWindow = Application.Current.MainWindow as MainWindow;
|
||||
if (mainWindow != null)
|
||||
{
|
||||
var timerContainer = mainWindow.FindName("TimerContainer") as FrameworkElement;
|
||||
var minimizedContainer = mainWindow.FindName("MinimizedTimerContainer") as FrameworkElement;
|
||||
|
||||
|
||||
if (timerContainer != null && minimizedContainer != null)
|
||||
{
|
||||
if (timerContainer.Visibility == Visibility.Collapsed && minimizedContainer.Visibility == Visibility.Visible)
|
||||
|
||||
Reference in New Issue
Block a user