using System; using System.Diagnostics; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using System.Windows.Interop; namespace Conjure.Arcade.Overlay { public class MainOverlay : OverlayWindow { private readonly TickEngine _tickEngine; private Process? _targetProcess; private const string TARGET_PROCESS = "notepad"; private readonly TextBlock _overlayText; private bool _isPaused; private HotkeyManager? _hotkeyManager; private bool _isVisible; public MainOverlay() { _tickEngine = new TickEngine(Update, 60); Loaded += OnLoaded; Closed += OnClosed; // Set semi-transparent background Background = new SolidColorBrush(Color.FromArgb(128, 0, 0, 0)); // Create and configure the text _overlayText = new TextBlock { Text = "Overlay Active", Foreground = Brushes.White, FontSize = 24, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; // Add text to the window Content = _overlayText; // Add key event handler KeyDown += OnKeyDown; // Update text block UpdateOverlayText(); // Start hidden Visibility = Visibility.Hidden; _isVisible = false; } private void OnLoaded(object sender, RoutedEventArgs e) { var windowHandle = new WindowInteropHelper(this).Handle; _hotkeyManager = new HotkeyManager(windowHandle, ToggleOverlay); _hotkeyManager.Register(); _targetProcess = WindowUtils.FindProcess(TARGET_PROCESS); if (_targetProcess == null) { MessageBox.Show($"Could not find process: {TARGET_PROCESS}"); Close(); return; } _tickEngine.Start(); } private void OnClosed(object? sender, EventArgs e) { _hotkeyManager?.Unregister(); _tickEngine.Stop(); } private void Update() { if (_targetProcess?.HasExited ?? true) { Dispatcher.Invoke(Close); return; } var handle = _targetProcess.MainWindowHandle; if (WindowUtils.GetWindowBounds(handle, out var rect)) { Dispatcher.Invoke(() => { Left = rect.Left; Top = rect.Top; Width = rect.Right - rect.Left; Height = rect.Bottom - rect.Top; }); } } private void ToggleOverlay() { _isVisible = !_isVisible; _isPaused = _isVisible; // Pause when visible, unpause when hidden Visibility = _isVisible ? Visibility.Visible : Visibility.Hidden; if (_targetProcess != null) { if (_isPaused) WindowUtils.SuspendProcess(_targetProcess); else WindowUtils.ResumeProcess(_targetProcess); UpdateOverlayText(); } } // Remove the space key handler since we're using the hotkey now private void OnKeyDown(object sender, KeyEventArgs e) { // Empty or remove this method } private void UpdateOverlayText() { _overlayText.Text = _isPaused ? "PAUSED (Ctrl+Alt+O to Resume)" : "Running"; } } }