Make Debug Window Expandable/Movable

- Makes the debug window expandable
- Removes debug form attachment from main form so it's moveable
This commit is contained in:
Frog
2026-07-25 01:44:52 -07:00
parent 17dc574172
commit d0b93f76ff
5 changed files with 40 additions and 52 deletions
+6 -6
View File
@@ -66,16 +66,16 @@ partial class DebugForm
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new System.Drawing.Size(560, 337);
ControlBox = false;
ControlBox = true;
Controls.Add(testGameButton);
Controls.Add(debugTextBox);
FormBorderStyle = FormBorderStyle.FixedSingle;
MaximizeBox = false;
MinimizeBox = false;
FormBorderStyle = FormBorderStyle.Sizable;
MaximizeBox = true;
MinimizeBox = true;
Name = "DebugForm";
Padding = new Padding(10);
ShowIcon = false;
ShowInTaskbar = false;
ShowIcon = true;
ShowInTaskbar = true;
StartPosition = FormStartPosition.Manual;
Text = "Debug";
ResumeLayout(false);
+30 -42
View File
@@ -13,8 +13,6 @@ internal sealed partial class DebugForm : CustomForm
internal static bool IsOpen { get; private set; }
private Form attachedForm;
private DebugForm()
{
InitializeComponent();
@@ -36,35 +34,8 @@ internal sealed partial class DebugForm : CustomForm
}
}
protected override void WndProc(ref Message message) // make form immovable by user
internal void Open(Form owner = null)
{
if (message.Msg == 0x0112) // WM_SYSCOMMAND
{
int command = message.WParam.ToInt32() & 0xFFF0;
if (command == 0xF010) // SC_MOVE
return;
}
base.WndProc(ref message);
}
internal void Attach(Form form)
{
if (attachedForm is not null)
{
attachedForm.Activated -= OnChange;
attachedForm.LocationChanged -= OnChange;
attachedForm.SizeChanged -= OnChange;
attachedForm.VisibleChanged -= OnChange;
}
attachedForm = form;
attachedForm.Activated += OnChange;
attachedForm.LocationChanged += OnChange;
attachedForm.SizeChanged += OnChange;
attachedForm.VisibleChanged += OnChange;
UpdateAttachment();
if (!IsOpen)
{
IsOpen = true;
@@ -85,17 +56,34 @@ internal sealed partial class DebugForm : CustomForm
Log(args.Message, color);
};
}
}
private void OnChange(object sender, EventArgs args) => UpdateAttachment();
private void UpdateAttachment()
{
if (attachedForm is null || !attachedForm.Visible)
return;
//Size = new(Size.Width, attachedForm.Size.Height);
Location = new(attachedForm.Right, attachedForm.Top);
BringToFrontWithoutActivation();
if (owner is not null)
{
Owner = owner;
StartPosition = FormStartPosition.Manual;
if (owner.Visible)
{
Location = new(owner.Right, owner.Top);
Show();
Activate();
}
else
{
EventHandler onShown = null;
onShown = (_, _) =>
{
Location = new(owner.Right, owner.Top);
owner.Shown -= onShown;
Show();
Activate();
};
owner.Shown += onShown;
}
}
else
{
Show();
Activate();
}
}
internal void Log(string text) => Log(text, LogTextBox.Error);
@@ -116,4 +104,4 @@ internal sealed partial class DebugForm : CustomForm
using TestGameForm form = new(this);
_ = form.ShowDialog(this);
}
}
}
+2 -2
View File
@@ -1495,7 +1495,7 @@ internal sealed partial class MainForm : CustomForm
InheritLocation(form);
Show();
#if DEBUG
DebugForm.Current.Attach(this);
DebugForm.Current.Open(this);
#endif
OnLoad();
}
@@ -1505,7 +1505,7 @@ internal sealed partial class MainForm : CustomForm
form.Show();
Hide();
#if DEBUG
DebugForm.Current.Attach(form);
DebugForm.Current.Open(form);
#endif
}
+1 -1
View File
@@ -38,7 +38,7 @@ internal sealed partial class UpdateForm : CustomForm
form.Show();
Hide();
#if DEBUG
DebugForm.Current.Attach(form);
DebugForm.Current.Open(form);
#endif
ThemeManager.Apply(form); // apply current theme when transitioning
}
+1 -1
View File
@@ -107,7 +107,7 @@ internal static class Program
AppSettings = ProgramData.LoadSettings(); // load persisted settings
using UpdateForm form = new();
#if DEBUG
DebugForm.Current.Attach(form);
DebugForm.Current.Open(form);
#endif
// Apply initial theme (dark by default)
Utility.ThemeManager.Apply(form);