Files
CreamInstaller/CreamInstaller/Forms/DebugForm.cs
T
Frog 593f396c54 Add Test Game Generator for Steam and Epic
- Added Test Game Generator to the Debug window for creating fake installed game entries for testing
- Updated ThemeManager to properly theme ListBox controls in dark mode
- Labels now use transparent backgrounds for better appearance
2026-05-27 01:20:03 -07:00

90 lines
2.4 KiB
C#

using System;
using System.Drawing;
using System.Windows.Forms;
using CreamInstaller.Components;
using CreamInstaller.Utility;
namespace CreamInstaller.Forms;
internal sealed partial class DebugForm : CustomForm
{
private static DebugForm current;
private Form attachedForm;
private DebugForm()
{
InitializeComponent();
debugTextBox.BackColor = LogTextBox.Background;
}
internal static DebugForm Current
{
get
{
if (current is not null && (current.Disposing || current.IsDisposed))
current = null;
return current ??= new();
}
}
protected override void WndProc(ref Message message) // make form immovable by user
{
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();
}
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();
}
internal void Log(string text) => Log(text, LogTextBox.Error);
internal void Log(string text, Color color)
{
if (!debugTextBox.Disposing && !debugTextBox.IsDisposed)
Invoke(() =>
{
if (debugTextBox.Text.Length > 0)
debugTextBox.AppendText(Environment.NewLine, color, true);
debugTextBox.AppendText(text, color, true);
});
}
private void OnTestGame(object sender, EventArgs e)
{
using TestGameForm form = new(this);
_ = form.ShowDialog(this);
}
}