1 using Mesen.GUI.Config;
2 using Mesen.GUI.Forms;
3 using System;
4 using System.Collections.Generic;
5 using System.ComponentModel;
6 using System.Data;
7 using System.Drawing;
8 using System.Linq;
9 using System.Text;
10 using System.Threading.Tasks;
11 using System.Windows.Forms;
12 
13 namespace Mesen.GUI.Debugger
14 {
15 	public partial class frmWatchWindow : BaseForm
16 	{
17 		private InteropEmu.NotificationListener _notifListener;
18 
frmWatchWindow()19 		public frmWatchWindow()
20 		{
21 			InitializeComponent();
22 
23 			if(!DesignMode) {
24 				if(!ConfigManager.Config.DebugInfo.WatchWindowSize.IsEmpty) {
25 					this.StartPosition = FormStartPosition.Manual;
26 					this.Size = ConfigManager.Config.DebugInfo.WatchWindowSize;
27 					this.Location = ConfigManager.Config.DebugInfo.WatchWindowLocation;
28 				}
29 
30 				this.toolTip.SetToolTip(picWatchHelp, ctrlWatch.GetTooltipText());
31 			}
32 		}
33 
OnLoad(EventArgs e)34 		protected override void OnLoad(EventArgs e)
35 		{
36 			base.OnLoad(e);
37 
38 			if(!DesignMode) {
39 				DebugWorkspaceManager.GetWorkspace();
40 				DebugWorkspaceManager.AutoLoadDbgFiles(true);
41 				_notifListener = new InteropEmu.NotificationListener(ConfigManager.Config.DebugInfo.DebugConsoleId);
42 				_notifListener.OnNotification += _notifListener_OnNotification;
43 				ctrlWatch.UpdateWatch(true);
44 			}
45 		}
46 
OnFormClosing(FormClosingEventArgs e)47 		protected override void OnFormClosing(FormClosingEventArgs e)
48 		{
49 			base.OnFormClosing(e);
50 
51 			ConfigManager.Config.DebugInfo.WatchWindowSize = this.WindowState != FormWindowState.Normal ? this.RestoreBounds.Size : this.Size;
52 			ConfigManager.Config.DebugInfo.WatchWindowLocation = this.WindowState != FormWindowState.Normal ? this.RestoreBounds.Location : this.Location;
53 			ConfigManager.ApplyChanges();
54 		}
55 
OnFormClosed(FormClosedEventArgs e)56 		protected override void OnFormClosed(FormClosedEventArgs e)
57 		{
58 			base.OnFormClosed(e);
59 
60 			if(_notifListener != null) {
61 				_notifListener.Dispose();
62 				_notifListener = null;
63 			}
64 		}
65 
_notifListener_OnNotification(InteropEmu.NotificationEventArgs e)66 		private void _notifListener_OnNotification(InteropEmu.NotificationEventArgs e)
67 		{
68 			switch(e.NotificationType) {
69 				case InteropEmu.ConsoleNotificationType.PpuFrameDone:
70 					if(ConfigManager.Config.DebugInfo.RefreshWhileRunning) {
71 						this.BeginInvoke((MethodInvoker)(() => {
72 							ctrlWatch.UpdateWatch(false);
73 						}));
74 					}
75 					break;
76 
77 				case InteropEmu.ConsoleNotificationType.CodeBreak:
78 					this.BeginInvoke((MethodInvoker)(() => {
79 						ctrlWatch.UpdateWatch(false);
80 					}));
81 					break;
82 			}
83 		}
84 	}
85 }
86