improve:计时器UI
将计时器窗口整合至主窗口,优化全屏计时逻辑
This commit is contained in:
@@ -8,37 +8,35 @@ using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Media.Animation;
|
||||
|
||||
namespace Ink_Canvas
|
||||
namespace Ink_Canvas.Windows
|
||||
{
|
||||
/// <summary>
|
||||
/// 最小化计时器窗口
|
||||
/// </summary>
|
||||
public partial class MinimizedTimerWindow : Window
|
||||
{
|
||||
private NewStyleTimerWindow parentWindow;
|
||||
private TimerControl parentControl;
|
||||
private System.Timers.Timer updateTimer;
|
||||
private bool isMouseOver = false;
|
||||
private bool isDragging = false;
|
||||
private Point lastMousePosition;
|
||||
|
||||
public MinimizedTimerWindow(NewStyleTimerWindow parent)
|
||||
public MinimizedTimerWindow(TimerControl parent)
|
||||
{
|
||||
InitializeComponent();
|
||||
parentWindow = parent;
|
||||
parentControl = parent;
|
||||
|
||||
// 设置窗口位置
|
||||
this.Left = parent.Left;
|
||||
this.Top = parent.Top;
|
||||
var mainWindow = Application.Current.MainWindow as MainWindow;
|
||||
if (mainWindow != null)
|
||||
{
|
||||
this.Left = mainWindow.Left;
|
||||
this.Top = mainWindow.Top;
|
||||
}
|
||||
|
||||
// 根据分辨率和DPI缩放窗口
|
||||
ScaleWindowForResolution();
|
||||
|
||||
// 启动更新定时器
|
||||
updateTimer = new System.Timers.Timer(100); // 100ms更新一次
|
||||
updateTimer = new System.Timers.Timer(100);
|
||||
updateTimer.Elapsed += UpdateTimer_Elapsed;
|
||||
updateTimer.Start();
|
||||
|
||||
parentWindow.TimerCompleted += ParentWindow_TimerCompleted;
|
||||
parentControl.TimerCompleted += ParentWindow_TimerCompleted;
|
||||
|
||||
// 应用主题
|
||||
ApplyTheme();
|
||||
@@ -141,7 +139,7 @@ namespace Ink_Canvas
|
||||
|
||||
private void UpdateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
if (parentWindow != null)
|
||||
if (parentControl != null)
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
@@ -158,16 +156,16 @@ namespace Ink_Canvas
|
||||
|
||||
private bool ShouldCloseWindow()
|
||||
{
|
||||
if (parentWindow == null) return true;
|
||||
if (parentControl == null) return true;
|
||||
|
||||
if (MainWindow.Settings.RandSettings?.EnableOvertimeCountUp == true)
|
||||
{
|
||||
if (parentWindow.IsTimerRunning)
|
||||
if (parentControl.IsTimerRunning)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var remainingTime = parentWindow.GetRemainingTime();
|
||||
var remainingTime = parentControl.GetRemainingTime();
|
||||
if (remainingTime.HasValue && remainingTime.Value.TotalSeconds < 0)
|
||||
{
|
||||
return false;
|
||||
@@ -177,16 +175,15 @@ namespace Ink_Canvas
|
||||
}
|
||||
else
|
||||
{
|
||||
return !parentWindow.IsTimerRunning;
|
||||
return !parentControl.IsTimerRunning;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateTimeDisplay()
|
||||
{
|
||||
if (parentWindow == null) return;
|
||||
if (parentControl == null) return;
|
||||
|
||||
// 获取剩余时间
|
||||
var remainingTime = parentWindow.GetRemainingTime();
|
||||
var remainingTime = parentControl.GetRemainingTime();
|
||||
if (remainingTime.HasValue)
|
||||
{
|
||||
var timeSpan = remainingTime.Value;
|
||||
@@ -197,10 +194,10 @@ namespace Ink_Canvas
|
||||
|
||||
if (isOvertimeMode)
|
||||
{
|
||||
var totalTimeSpan = parentWindow.GetTotalTimeSpan();
|
||||
var totalTimeSpan = parentControl.GetTotalTimeSpan();
|
||||
if (totalTimeSpan.HasValue)
|
||||
{
|
||||
var elapsedTime = parentWindow.GetElapsedTime();
|
||||
var elapsedTime = parentControl.GetElapsedTime();
|
||||
if (elapsedTime.HasValue)
|
||||
{
|
||||
var overtimeSpan = elapsedTime.Value - totalTimeSpan.Value;
|
||||
@@ -232,11 +229,9 @@ namespace Ink_Canvas
|
||||
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);
|
||||
|
||||
@@ -424,18 +419,10 @@ namespace Ink_Canvas
|
||||
isDragging = false;
|
||||
this.ReleaseMouseCapture();
|
||||
|
||||
// 如果点击时间很短,认为是单击,恢复主窗口
|
||||
var clickDuration = DateTime.Now - lastClickTime;
|
||||
if (clickDuration.TotalMilliseconds < 200) // 200ms内认为是单击
|
||||
if (clickDuration.TotalMilliseconds < 200)
|
||||
{
|
||||
// 恢复主窗口
|
||||
if (parentWindow != null)
|
||||
{
|
||||
parentWindow.Show();
|
||||
parentWindow.Activate();
|
||||
parentWindow.WindowState = WindowState.Normal;
|
||||
this.Close();
|
||||
}
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -464,19 +451,18 @@ namespace Ink_Canvas
|
||||
|
||||
private void CloseButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// 停止计时器并关闭窗口
|
||||
if (parentWindow != null)
|
||||
if (parentControl != null)
|
||||
{
|
||||
parentWindow.StopTimer();
|
||||
parentControl.StopTimer();
|
||||
}
|
||||
this.Close();
|
||||
}
|
||||
|
||||
protected override void OnClosed(EventArgs e)
|
||||
{
|
||||
if (parentWindow != null)
|
||||
if (parentControl != null)
|
||||
{
|
||||
parentWindow.TimerCompleted -= ParentWindow_TimerCompleted;
|
||||
parentControl.TimerCompleted -= ParentWindow_TimerCompleted;
|
||||
}
|
||||
|
||||
// 清理资源
|
||||
|
||||
Reference in New Issue
Block a user