Skip to content

Commit 90eb77c

Browse files
committed
moved theme related to /Graphics and ui improvements
1 parent 736dc66 commit 90eb77c

9 files changed

Lines changed: 263 additions & 180 deletions

File tree

Graphics/MenuRenderer.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Drawing;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows.Forms;
8+
9+
namespace RacingDSX.Graphics
10+
{
11+
public class MenuRenderer : ToolStripProfessionalRenderer
12+
{
13+
Color colorDefault;
14+
Color colorPress;
15+
Color colorArrow;
16+
17+
public MenuRenderer(Color colorDefault, Color colorPress, Color colorArrow) : base()
18+
{
19+
this.colorDefault = colorDefault;
20+
this.colorPress = colorPress;
21+
this.colorArrow = colorArrow;
22+
}
23+
24+
protected override void OnRenderDropDownButtonBackground(ToolStripItemRenderEventArgs e)
25+
{
26+
var g = e.Graphics;
27+
var rect = new Rectangle(Point.Empty, e.Item.Size);
28+
29+
Color bg;
30+
31+
if (e.Item.Pressed)
32+
{
33+
bg = colorPress;
34+
}
35+
else if (e.Item.Selected)
36+
{
37+
bg = colorPress;
38+
}
39+
else
40+
{
41+
bg = colorDefault;
42+
}
43+
44+
using var brush = new SolidBrush(bg);
45+
g.FillRectangle(brush, rect);
46+
}
47+
48+
protected override void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e)
49+
{
50+
var g = e.Graphics;
51+
var rect = new Rectangle(Point.Empty, e.ImageRectangle.Size);
52+
53+
g.FillRectangle(e.Item is ToolStripMenuItem item && item.Checked ? new SolidBrush(Color.FromArgb(120, 69, 162, 255)) : Brushes.Transparent, rect);
54+
}
55+
56+
protected override void OnRenderArrow(ToolStripArrowRenderEventArgs e)
57+
{
58+
e.ArrowColor = colorArrow;
59+
60+
base.OnRenderArrow(e);
61+
}
62+
}
63+
}

Graphics/ThemeManager.cs

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
using Microsoft.Win32;
2+
using RacingDSX.Graphics;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.ComponentModel;
6+
using System.Drawing;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using System.Windows.Forms;
11+
12+
13+
namespace RacingDSX.Graphics
14+
{
15+
16+
class ThemeManager
17+
{
18+
public static ThemeObject CurrentTheme { get; set; } = Themes.Dark;
19+
20+
public static bool IsDesignMode =>
21+
LicenseManager.UsageMode == LicenseUsageMode.Designtime;
22+
23+
public static void ApplyTheme(Control control)
24+
{
25+
if (control == null)
26+
return;
27+
28+
Suspend(control);
29+
30+
ApplyToControl(control);
31+
32+
Resume(control);
33+
}
34+
35+
private static void ApplyToControl(Control control)
36+
{
37+
control.BackColor = CurrentTheme.BackColor;
38+
control.ForeColor = CurrentTheme.ForeColor;
39+
40+
if (control is Button button)
41+
{
42+
button.ForeColor = CurrentTheme.ButtonForeColor;
43+
button.BackColor = CurrentTheme.ButtonBackColor;
44+
button.FlatStyle = CurrentTheme.ButtonFlatStyle;
45+
button.FlatAppearance.BorderSize = CurrentTheme.ButtonAppearanceBorderSize;
46+
button.FlatAppearance.BorderColor = CurrentTheme.ButtonAppearanceBorderColor;
47+
button.FlatAppearance.MouseOverBackColor = CurrentTheme.ButtonAppearanceMouseOverBackColor;
48+
}
49+
50+
if (control is TextBox || control is ListView || control is ListBox || control is ComboBox)
51+
{
52+
control.ForeColor = CurrentTheme.TextBoxForeColor;
53+
control.BackColor = CurrentTheme.TextBoxBackColor;
54+
}
55+
56+
if (control is ToolStrip toolStrip)
57+
{
58+
foreach (ToolStripItem item in toolStrip.Items)
59+
{
60+
if(item is ToolStripDropDownButton dropdownButton)
61+
{
62+
dropdownButton.Owner.Renderer = new MenuRenderer(CurrentTheme.BackColor, CurrentTheme.ButtonAppearanceMouseOverBackColor, CurrentTheme.ForeColor);
63+
}
64+
}
65+
}
66+
67+
foreach (Control child in control.Controls)
68+
{
69+
ApplyToControl(child);
70+
}
71+
}
72+
73+
private static void Suspend(Control control)
74+
{
75+
control.SuspendLayout();
76+
77+
foreach (Control child in control.Controls)
78+
{
79+
Suspend(child);
80+
}
81+
}
82+
83+
private static void Resume(Control control)
84+
{
85+
foreach (Control child in control.Controls)
86+
{
87+
Resume(child);
88+
}
89+
90+
control.ResumeLayout();
91+
}
92+
93+
public static bool IsDarkMode()
94+
{
95+
using var key = Registry.CurrentUser.OpenSubKey(
96+
@"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize");
97+
98+
if (key?.GetValue("AppsUseLightTheme") is int value)
99+
{
100+
return value == 0;
101+
}
102+
103+
return false;
104+
}
105+
}
106+
}

Graphics/ThemeObject.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Drawing;
2+
using System.Windows.Forms;
3+
4+
5+
namespace RacingDSX.Graphics
6+
{
7+
public class ThemeObject
8+
{
9+
public Color BackColor { get; set; }
10+
public Color SurfaceColor { get; set; }
11+
public Color ForeColor { get; set; }
12+
public Color BorderColor { get; set; }
13+
public Color AccentColor { get; set; }
14+
public Color ButtonBackColor { get; set; }
15+
public Color ButtonForeColor { get; set; }
16+
public Color TextBoxBackColor { get; set; }
17+
public Color TextBoxForeColor { get; set; }
18+
public FlatStyle ButtonFlatStyle { get; set; }
19+
public int ButtonAppearanceBorderSize { get; set; }
20+
public Color ButtonAppearanceBorderColor { get; set; }
21+
public Color ButtonAppearanceMouseOverBackColor { get; set; }
22+
}
23+
}

Graphics/Themes.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System.Drawing;
2+
using System.Windows.Forms;
3+
4+
namespace RacingDSX.Graphics
5+
{
6+
public static class Themes
7+
{
8+
public static readonly ThemeObject Plain = new()
9+
{
10+
BackColor = SystemColors.Control,
11+
SurfaceColor = SystemColors.ControlLight,
12+
ForeColor = SystemColors.ControlText,
13+
BorderColor = SystemColors.ControlDark,
14+
AccentColor = SystemColors.Highlight,
15+
ButtonBackColor = SystemColors.Control,
16+
ButtonForeColor = SystemColors.ControlText,
17+
TextBoxBackColor = SystemColors.Window,
18+
TextBoxForeColor = SystemColors.WindowText,
19+
ButtonFlatStyle = FlatStyle.Standard
20+
};
21+
22+
public static readonly ThemeObject Dark = new()
23+
{
24+
BackColor = Color.FromArgb(30, 30, 30),
25+
SurfaceColor = Color.FromArgb(45, 45, 45),
26+
ForeColor = Color.White,
27+
BorderColor = Color.FromArgb(70, 70, 70),
28+
AccentColor = Color.FromArgb(0, 120, 215),
29+
ButtonBackColor = Color.FromArgb(50, 50, 50),
30+
ButtonForeColor = Color.White,
31+
TextBoxBackColor = Color.FromArgb(50, 50, 50),
32+
TextBoxForeColor = Color.White,
33+
ButtonFlatStyle = FlatStyle.Flat,
34+
ButtonAppearanceBorderSize = 0,
35+
ButtonAppearanceMouseOverBackColor = Color.FromArgb(60, 60, 60),
36+
};
37+
38+
public static readonly ThemeObject Light = new()
39+
{
40+
BackColor = Color.White,
41+
SurfaceColor = Color.FromArgb(240, 240, 240),
42+
ForeColor = Color.Black,
43+
BorderColor = Color.LightGray,
44+
AccentColor = Color.FromArgb(0, 120, 215),
45+
ButtonBackColor = Color.FromArgb(230, 230, 230),
46+
ButtonForeColor = Color.Black,
47+
TextBoxBackColor = Color.White,
48+
TextBoxForeColor = Color.Black,
49+
ButtonFlatStyle = FlatStyle.Flat,
50+
ButtonAppearanceBorderSize = 1,
51+
ButtonAppearanceBorderColor = Color.DarkGray,
52+
ButtonAppearanceMouseOverBackColor = Color.FromArgb(220, 220, 220),
53+
};
54+
}
55+
}

Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace RacingDSX
1515

1616
public class Program
1717
{
18-
public const string VERSION = "0.7.4";
18+
public const string VERSION = "0.7.5";
1919

2020
static void Main(string[] args)
2121
{

0 commit comments

Comments
 (0)