218 lines
7.4 KiB
C#
218 lines
7.4 KiB
C#
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
|
|
namespace gregExtractor;
|
|
|
|
internal static class DarkTheme
|
|
{
|
|
public static readonly Color Background = Color.FromArgb(30, 30, 30);
|
|
public static readonly Color Surface = Color.FromArgb(37, 37, 38);
|
|
public static readonly Color SurfaceAlt = Color.FromArgb(45, 45, 48);
|
|
public static readonly Color Border = Color.FromArgb(62, 62, 66);
|
|
public static readonly Color Foreground = Color.FromArgb(241, 241, 241);
|
|
public static readonly Color MutedForeground = Color.FromArgb(185, 185, 185);
|
|
public static readonly Color Accent = Color.FromArgb(14, 99, 156);
|
|
|
|
public static void Apply(Form form)
|
|
{
|
|
form.BackColor = Background;
|
|
form.ForeColor = Foreground;
|
|
|
|
ApplyToControlTree(form);
|
|
EnableDarkTabs(form);
|
|
}
|
|
|
|
private static void ApplyToControlTree(Control root)
|
|
{
|
|
foreach (Control control in root.Controls)
|
|
{
|
|
ApplyToControl(control);
|
|
if (control.HasChildren)
|
|
ApplyToControlTree(control);
|
|
}
|
|
}
|
|
|
|
private static void ApplyToControl(Control control)
|
|
{
|
|
switch (control)
|
|
{
|
|
case TabControl tabControl:
|
|
tabControl.BackColor = Background;
|
|
tabControl.ForeColor = Foreground;
|
|
tabControl.DrawMode = TabDrawMode.OwnerDrawFixed;
|
|
tabControl.DrawItem -= OnTabControlDrawItem;
|
|
tabControl.DrawItem += OnTabControlDrawItem;
|
|
break;
|
|
|
|
case TabPage tabPage:
|
|
tabPage.BackColor = Background;
|
|
tabPage.ForeColor = Foreground;
|
|
break;
|
|
|
|
case GroupBox groupBox:
|
|
groupBox.BackColor = Surface;
|
|
groupBox.ForeColor = Foreground;
|
|
break;
|
|
|
|
case SplitContainer split:
|
|
split.BackColor = Surface;
|
|
split.ForeColor = Foreground;
|
|
break;
|
|
|
|
case FlowLayoutPanel flow:
|
|
flow.BackColor = Surface;
|
|
flow.ForeColor = Foreground;
|
|
break;
|
|
|
|
case TableLayoutPanel table:
|
|
table.BackColor = Surface;
|
|
table.ForeColor = Foreground;
|
|
break;
|
|
|
|
case Panel panel:
|
|
panel.BackColor = Surface;
|
|
panel.ForeColor = Foreground;
|
|
break;
|
|
|
|
case TextBox textBox:
|
|
ApplyTextBoxTheme(textBox);
|
|
break;
|
|
|
|
case RichTextBox richTextBox:
|
|
richTextBox.BackColor = SurfaceAlt;
|
|
richTextBox.ForeColor = Foreground;
|
|
richTextBox.BorderStyle = BorderStyle.FixedSingle;
|
|
break;
|
|
|
|
case DataGridView grid:
|
|
ApplyDataGridTheme(grid);
|
|
break;
|
|
|
|
case Button button:
|
|
ApplyButtonTheme(button);
|
|
break;
|
|
|
|
case CheckBox checkBox:
|
|
checkBox.BackColor = Surface;
|
|
checkBox.ForeColor = Foreground;
|
|
break;
|
|
|
|
case ComboBox comboBox:
|
|
comboBox.BackColor = SurfaceAlt;
|
|
comboBox.ForeColor = Foreground;
|
|
comboBox.FlatStyle = FlatStyle.Flat;
|
|
break;
|
|
|
|
case Label label:
|
|
label.BackColor = Color.Transparent;
|
|
label.ForeColor = Foreground;
|
|
break;
|
|
|
|
default:
|
|
control.BackColor = Surface;
|
|
control.ForeColor = Foreground;
|
|
break;
|
|
}
|
|
}
|
|
|
|
private static void ApplyTextBoxTheme(TextBox textBox)
|
|
{
|
|
textBox.BackColor = SurfaceAlt;
|
|
textBox.ForeColor = Foreground;
|
|
textBox.BorderStyle = BorderStyle.FixedSingle;
|
|
|
|
if (textBox.ReadOnly)
|
|
{
|
|
textBox.BackColor = Color.FromArgb(42, 42, 42);
|
|
textBox.ForeColor = MutedForeground;
|
|
}
|
|
}
|
|
|
|
private static void ApplyButtonTheme(Button button)
|
|
{
|
|
button.BackColor = SurfaceAlt;
|
|
button.ForeColor = Foreground;
|
|
button.FlatStyle = FlatStyle.Flat;
|
|
button.FlatAppearance.BorderColor = Border;
|
|
button.FlatAppearance.BorderSize = 1;
|
|
button.FlatAppearance.MouseOverBackColor = Color.FromArgb(55, 55, 60);
|
|
button.FlatAppearance.MouseDownBackColor = Accent;
|
|
button.UseVisualStyleBackColor = false;
|
|
}
|
|
|
|
private static void ApplyDataGridTheme(DataGridView grid)
|
|
{
|
|
grid.BackgroundColor = Surface;
|
|
grid.GridColor = Border;
|
|
grid.BorderStyle = BorderStyle.None;
|
|
|
|
grid.EnableHeadersVisualStyles = false;
|
|
grid.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
|
|
grid.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
|
|
|
|
grid.ColumnHeadersDefaultCellStyle.BackColor = Color.FromArgb(51, 51, 55);
|
|
grid.ColumnHeadersDefaultCellStyle.ForeColor = Foreground;
|
|
grid.ColumnHeadersDefaultCellStyle.SelectionBackColor = Color.FromArgb(62, 62, 66);
|
|
grid.ColumnHeadersDefaultCellStyle.SelectionForeColor = Foreground;
|
|
|
|
grid.RowHeadersDefaultCellStyle.BackColor = Color.FromArgb(51, 51, 55);
|
|
grid.RowHeadersDefaultCellStyle.ForeColor = Foreground;
|
|
grid.RowHeadersDefaultCellStyle.SelectionBackColor = Color.FromArgb(62, 62, 66);
|
|
grid.RowHeadersDefaultCellStyle.SelectionForeColor = Foreground;
|
|
|
|
grid.DefaultCellStyle.BackColor = SurfaceAlt;
|
|
grid.DefaultCellStyle.ForeColor = Foreground;
|
|
grid.DefaultCellStyle.SelectionBackColor = Accent;
|
|
grid.DefaultCellStyle.SelectionForeColor = Color.White;
|
|
|
|
grid.AlternatingRowsDefaultCellStyle.BackColor = Color.FromArgb(39, 39, 42);
|
|
grid.AlternatingRowsDefaultCellStyle.ForeColor = Foreground;
|
|
grid.AlternatingRowsDefaultCellStyle.SelectionBackColor = Accent;
|
|
grid.AlternatingRowsDefaultCellStyle.SelectionForeColor = Color.White;
|
|
}
|
|
|
|
private static void EnableDarkTabs(Control root)
|
|
{
|
|
foreach (Control control in root.Controls)
|
|
{
|
|
if (control is TabControl tabControl)
|
|
{
|
|
tabControl.DrawMode = TabDrawMode.OwnerDrawFixed;
|
|
tabControl.DrawItem -= OnTabControlDrawItem;
|
|
tabControl.DrawItem += OnTabControlDrawItem;
|
|
}
|
|
|
|
if (control.HasChildren)
|
|
EnableDarkTabs(control);
|
|
}
|
|
}
|
|
|
|
private static void OnTabControlDrawItem(object? sender, DrawItemEventArgs eventArgs)
|
|
{
|
|
if (sender is not TabControl tabControl)
|
|
return;
|
|
|
|
Rectangle rectangle = eventArgs.Bounds;
|
|
bool selected = (eventArgs.State & DrawItemState.Selected) == DrawItemState.Selected;
|
|
|
|
Color back = selected ? SurfaceAlt : Surface;
|
|
Color fore = selected ? Foreground : MutedForeground;
|
|
|
|
using var backgroundBrush = new SolidBrush(back);
|
|
using var textBrush = new SolidBrush(fore);
|
|
using var borderPen = new Pen(Border);
|
|
|
|
eventArgs.Graphics.FillRectangle(backgroundBrush, rectangle);
|
|
eventArgs.Graphics.DrawRectangle(borderPen, rectangle);
|
|
|
|
string text = tabControl.TabPages[eventArgs.Index].Text;
|
|
TextRenderer.DrawText(
|
|
eventArgs.Graphics,
|
|
text,
|
|
tabControl.Font,
|
|
rectangle,
|
|
fore,
|
|
TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
|
|
}
|
|
}
|