improve:计时器
This commit is contained in:
@@ -13,13 +13,13 @@ namespace Ink_Canvas
|
||||
/// </summary>
|
||||
public partial class MinimizedTimerWindow : Window
|
||||
{
|
||||
private SeewoStyleTimerWindow parentWindow;
|
||||
private NewStyleTimerWindow parentWindow;
|
||||
private System.Timers.Timer updateTimer;
|
||||
private bool isMouseOver = false;
|
||||
private bool isDragging = false;
|
||||
private Point lastMousePosition;
|
||||
|
||||
public MinimizedTimerWindow(SeewoStyleTimerWindow parent)
|
||||
public MinimizedTimerWindow(NewStyleTimerWindow parent)
|
||||
{
|
||||
InitializeComponent();
|
||||
parentWindow = parent;
|
||||
@@ -41,14 +41,45 @@ namespace Ink_Canvas
|
||||
|
||||
private void UpdateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
if (parentWindow != null && parentWindow.IsTimerRunning)
|
||||
if (parentWindow != null)
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
if (ShouldCloseWindow())
|
||||
{
|
||||
this.Close();
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateTimeDisplay();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private bool ShouldCloseWindow()
|
||||
{
|
||||
if (parentWindow == null) return true;
|
||||
|
||||
if (MainWindow.Settings.RandSettings?.EnableOvertimeCountUp == true)
|
||||
{
|
||||
if (parentWindow.IsTimerRunning)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var remainingTime = parentWindow.GetRemainingTime();
|
||||
if (remainingTime.HasValue && remainingTime.Value.TotalSeconds < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return !parentWindow.IsTimerRunning;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateTimeDisplay()
|
||||
{
|
||||
@@ -59,21 +90,56 @@ namespace Ink_Canvas
|
||||
if (remainingTime.HasValue)
|
||||
{
|
||||
var timeSpan = remainingTime.Value;
|
||||
int hours = (int)timeSpan.TotalHours;
|
||||
int minutes = timeSpan.Minutes;
|
||||
int seconds = timeSpan.Seconds;
|
||||
bool isOvertimeMode = timeSpan.TotalSeconds < 0;
|
||||
bool shouldShowRed = isOvertimeMode && MainWindow.Settings.RandSettings?.EnableOvertimeRedText == true;
|
||||
|
||||
int hours, minutes, seconds;
|
||||
|
||||
if (isOvertimeMode)
|
||||
{
|
||||
var totalTimeSpan = parentWindow.GetTotalTimeSpan();
|
||||
if (totalTimeSpan.HasValue)
|
||||
{
|
||||
var elapsedTime = parentWindow.GetElapsedTime();
|
||||
if (elapsedTime.HasValue)
|
||||
{
|
||||
var overtimeSpan = elapsedTime.Value - totalTimeSpan.Value;
|
||||
hours = (int)overtimeSpan.TotalHours;
|
||||
minutes = overtimeSpan.Minutes;
|
||||
seconds = overtimeSpan.Seconds;
|
||||
}
|
||||
else
|
||||
{
|
||||
hours = 0;
|
||||
minutes = 0;
|
||||
seconds = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hours = 0;
|
||||
minutes = 0;
|
||||
seconds = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hours = (int)timeSpan.TotalHours;
|
||||
minutes = timeSpan.Minutes;
|
||||
seconds = timeSpan.Seconds;
|
||||
}
|
||||
|
||||
// 更新小时显示
|
||||
SetDigitDisplay("MinHour1Display", hours / 10);
|
||||
SetDigitDisplay("MinHour2Display", hours % 10);
|
||||
SetDigitDisplay("MinHour1Display", hours / 10, shouldShowRed);
|
||||
SetDigitDisplay("MinHour2Display", hours % 10, shouldShowRed);
|
||||
|
||||
// 更新分钟显示
|
||||
SetDigitDisplay("MinMinute1Display", minutes / 10);
|
||||
SetDigitDisplay("MinMinute2Display", minutes % 10);
|
||||
SetDigitDisplay("MinMinute1Display", minutes / 10, shouldShowRed);
|
||||
SetDigitDisplay("MinMinute2Display", minutes % 10, shouldShowRed);
|
||||
|
||||
// 更新秒显示
|
||||
SetDigitDisplay("MinSecond1Display", seconds / 10);
|
||||
SetDigitDisplay("MinSecond2Display", seconds % 10);
|
||||
SetDigitDisplay("MinSecond1Display", seconds / 10, shouldShowRed);
|
||||
SetDigitDisplay("MinSecond2Display", seconds % 10, shouldShowRed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +151,7 @@ namespace Ink_Canvas
|
||||
});
|
||||
}
|
||||
|
||||
private void SetDigitDisplay(string pathName, int digit)
|
||||
private void SetDigitDisplay(string pathName, int digit, bool isRed = false)
|
||||
{
|
||||
var path = this.FindName(pathName) as Path;
|
||||
if (path != null)
|
||||
@@ -96,6 +162,25 @@ namespace Ink_Canvas
|
||||
{
|
||||
path.Data = geometry;
|
||||
}
|
||||
|
||||
// 设置颜色
|
||||
if (isRed)
|
||||
{
|
||||
path.Fill = Brushes.Red;
|
||||
}
|
||||
else
|
||||
{
|
||||
var defaultBrush = this.FindResource("NewTimerWindowDigitForeground") as Brush;
|
||||
if (defaultBrush != null)
|
||||
{
|
||||
path.Fill = defaultBrush;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool isLightTheme = IsLightTheme();
|
||||
path.Fill = isLightTheme ? Brushes.Black : Brushes.White;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user