Make anything inheriting FormBase slightly less ugly on Linux

This commit is contained in:
YoshiRulz 2020-12-23 18:44:06 +10:00
parent 515f5cf9b0
commit 62f90f11f2
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
2 changed files with 36 additions and 0 deletions

View File

@ -2,14 +2,33 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Common;
using BizHawk.WinForms.Controls;
namespace BizHawk.Client.EmuHawk
{
public class FormBase : Form
{
/// <summary>
/// Under Mono, <see cref="SystemColors.Control">SystemColors.Control</see> returns an ugly beige.<br/>
/// This method recursively replaces the <see cref="Control.BackColor"/> of the given <paramref name="control"/> (can be a <see cref="Form"/>) with <see cref="Color.WhiteSmoke"/>
/// iff they have the default of <see cref="SystemColors.Control">SystemColors.Control</see>.<br/>
/// (Also adds a custom <see cref="ToolStrip.Renderer"/> to <see cref="ToolStrip">ToolStrips</see> to change their colors.)
/// </summary>
public static void FixBackColorOnControls(Control control)
{
if (control.BackColor == SystemColors.Control) control.BackColor = Color.WhiteSmoke;
foreach (Control c1 in control.Controls)
{
if (c1 is ToolStrip ts) ts.Renderer = new ToolStripProfessionalRenderer(new LinuxColorTable());
else FixBackColorOnControls(c1);
}
}
private string? _windowTitleStatic;
public virtual bool BlocksInputWhenFocused { get; } = true;
@ -33,6 +52,7 @@ namespace BizHawk.Client.EmuHawk
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (OSTailoredCode.IsUnixHost) FixBackColorOnControls(this);
UpdateWindowTitle();
}

View File

@ -0,0 +1,16 @@
#nullable enable
using System.Drawing;
using System.Windows.Forms;
namespace BizHawk.WinForms.Controls
{
public sealed class LinuxColorTable : ProfessionalColorTable
{
public override Color MenuStripGradientBegin { get; } = Color.WhiteSmoke;
public override Color ToolStripDropDownBackground { get; } = Color.WhiteSmoke;
public override Color ToolStripGradientEnd { get; } = Color.WhiteSmoke;
}
}