-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWarningOverlayForm.cs
More file actions
104 lines (86 loc) · 3.38 KB
/
WarningOverlayForm.cs
File metadata and controls
104 lines (86 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Diagnostics;
using System.Drawing;
using System.Media;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace KidTimerLock
{
public partial class WarningOverlayForm : Form
{
private Timer flashTimer;
// private int flashCount = 0;
private int currentFlashCount = 0;
public WarningOverlayForm(string message)
{
InitializeComponent();
FormBorderStyle = FormBorderStyle.None;
StartPosition = FormStartPosition.Manual;
TopMost = true;
ShowInTaskbar = false;
BackColor = AppConfig.OverlayColour; // Use hardcoded (for now) overlay colour
Opacity = 0.75;
Size = new Size(250, 50);
Location = new Point(
Screen.PrimaryScreen.WorkingArea.Width / 2 - Width / 2,
Screen.PrimaryScreen.WorkingArea.Height / 2 - Height / 2
);
var label = new Label
{
Text = message,
ForeColor = AppConfig.TextColour, // Use hardcoded text colour
Font = AppConfig.OverlayFont, // Use hardcoded font
Dock = DockStyle.Fill,
TextAlign = ContentAlignment.MiddleCenter
};
Controls.Add(label);
// Start the flashing timer
flashTimer = new Timer();
flashTimer.Interval = ConfigManager.Config.FlashInterval; // Use configurable interval
flashTimer.Tick += flashTimer_Tick;
flashTimer.Start();
if (ConfigManager.Config.AudibleBeep) Task.Run(() => Console.Beep(1000, ConfigManager.Config.FlashInterval)); // beep on first flash - messy but whatever
//// Start the close timer
//var closeTimer = new Timer();
//closeTimer.Interval = flashTimer.Interval * ConfigManager.Config.FlashCount * 2; // Total duration for which overlay is active
//Debug.WriteLine($"{flashTimer.Interval}");
//Debug.WriteLine($"{closeTimer.Interval}");
//closeTimer.Tick += (s, e) => { Close(); };
//closeTimer.Start();
}
private void flashTimer_Tick(object sender, EventArgs e)
{
// Toggle visibility
this.Visible = !this.Visible;
// Only count a full flash cycle (on+off), i.e. every 2 ticks
if (!this.Visible)
{
currentFlashCount++;
if (currentFlashCount >= ConfigManager.Config.FlashCount)
{
flashTimer.Stop();
this.Close();
}
} else
{
if (ConfigManager.Config.AudibleBeep) Task.Run(() => Console.Beep(1000, ConfigManager.Config.FlashInterval)); // beep on first flash - messy but whatever
}
}
private void WarningOverlayForm_Load(object sender, EventArgs e)
{
}
public static void CloseAllOverlays()
{
foreach (Form openForm in Application.OpenForms)
{
if (openForm is WarningOverlayForm)
{
openForm.Close();
break;
}
}
// Also reset any state flags if needed
// TimerForm.warningsShown.Clear();
}
}
}