Skip to content

Commit bfba8f0

Browse files
committed
Initial theme switching
1 parent 54b7a7b commit bfba8f0

File tree

3 files changed

+117
-17
lines changed

3 files changed

+117
-17
lines changed

Source/RunActivity/Viewer3D/Debugging/DebugViewerBetaForm.Designer.cs

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/RunActivity/Viewer3D/Debugging/DebugViewerBetaForm.cs

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public partial class DispatchViewerBeta : Form
2525
/// </summary>
2626
public readonly Simulator simulator;
2727
private MapDataProvider MapDataProvider;
28+
private MapThemeProvider MapThemeProvider;
29+
private ThemeStyle Theme;
2830
/// <summary>
2931
/// Used to periodically check if we should shift the view when the
3032
/// user is holding down a "shift view" button.
@@ -58,6 +60,7 @@ public partial class DispatchViewerBeta : Form
5860
/// contains the last position of the mouse
5961
/// </summary>
6062
private System.Drawing.Point LastCursorPosition = new System.Drawing.Point();
63+
6164
public Pen redPen = new Pen(Color.FromArgb(244, 67, 54));
6265
public Pen greenPen = new Pen(Color.FromArgb(76, 175, 80));
6366
public Pen orangePen = new Pen(Color.FromArgb(255, 235, 59));
@@ -67,6 +70,18 @@ public partial class DispatchViewerBeta : Form
6770
public Pen PlatformPen = new Pen(Color.Blue);
6871
public Pen TrackPen = new Pen(Color.FromArgb(46, 64, 83));
6972
public Pen ZoomTargetPen = new Pen(Color.FromArgb(46, 64, 83));
73+
74+
public Font trainFont = new Font("Segoe UI Semibold", 10, FontStyle.Bold);
75+
public Font sidingFont = new Font("Segoe UI Semibold", 10, FontStyle.Regular);
76+
public Font PlatformFont = new Font("Segoe UI Semibold", 10, FontStyle.Regular);
77+
public Font SignalFont = new Font("Segoe UI Semibold", 10, FontStyle.Regular);
78+
private SolidBrush trainBrush = new SolidBrush(Color.Red);
79+
public SolidBrush sidingBrush = new SolidBrush(Color.Blue);
80+
public SolidBrush PlatformBrush = new SolidBrush(Color.DarkBlue);
81+
public SolidBrush SignalBrush = new SolidBrush(Color.DarkRed);
82+
public SolidBrush InactiveTrainBrush = new SolidBrush(Color.DarkRed);
83+
private Color MapCanvasColor = Color.White;
84+
7085
// the train selected by leftclicking the mouse
7186
public Train PickedTrain;
7287
/// <summary>
@@ -81,16 +96,6 @@ public partial class DispatchViewerBeta : Form
8196
public float maxY = float.MinValue;
8297

8398
public int RedrawCount;
84-
public Font trainFont = new Font("Segoe UI Semibold", 10, FontStyle.Bold);
85-
public Font sidingFont = new Font("Segoe UI Semibold", 10, FontStyle.Regular);
86-
public Font PlatformFont = new Font("Segoe UI Semibold", 10, FontStyle.Regular);
87-
public Font SignalFont = new Font("Segoe UI Semibold", 10, FontStyle.Regular);
88-
private SolidBrush trainBrush = new SolidBrush(Color.Red);
89-
public SolidBrush sidingBrush = new SolidBrush(Color.Blue);
90-
public SolidBrush PlatformBrush = new SolidBrush(Color.DarkBlue);
91-
public SolidBrush SignalBrush = new SolidBrush(Color.DarkRed);
92-
public SolidBrush InactiveTrainBrush = new SolidBrush(Color.DarkRed);
93-
9499
private double lastUpdateTime;
95100

96101
private bool MapCustomizationVisible = false;
@@ -106,6 +111,7 @@ public DispatchViewerBeta(Simulator simulator, Viewer viewer)
106111
this.simulator = simulator;
107112
Viewer = viewer;
108113
MapDataProvider = new MapDataProvider(this);
114+
MapThemeProvider = new MapThemeProvider();
109115
nodes = simulator.TDB.TrackDB.TrackNodes;
110116

111117
InitializeForm();
@@ -132,6 +138,8 @@ public DispatchViewerBeta(Simulator simulator, Viewer viewer)
132138
void InitializeForm()
133139
{
134140
MapDataProvider.SetControls();
141+
MapThemeProvider.InitializeThemes();
142+
Theme = MapThemeProvider.LightTheme;
135143

136144
float[] dashPattern = { 4, 2 };
137145
ZoomTargetPen.DashPattern = dashPattern;
@@ -281,7 +289,7 @@ public void CheckPlayers()
281289
// If `PlayersList` hasn't changed since we've last checked, we should not clear/update
282290
// `playersView` to avoid flickering
283291
if (!PlayersListChanged) return;
284-
292+
285293
playersView.Items.Clear();
286294
Console.Beep();
287295
foreach (var p in PlayersList)
@@ -389,7 +397,7 @@ public void GenerateView(bool dragging = false)
389397
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
390398

391399
subX = minX + ViewWindow.X; subY = minY + ViewWindow.Y;
392-
g.Clear(Color.White);
400+
g.Clear(MapCanvasColor);
393401

394402
xScale = mapCanvas.Width / ViewWindow.Width;
395403
yScale = mapCanvas.Height / ViewWindow.Height;
@@ -1137,6 +1145,34 @@ public void DrawTrainPath(Train train, float subX, float subY, Pen pathPen, Grap
11371145
}
11381146
#endregion
11391147

1148+
#region themes
1149+
private void ApplyThemeRecursively(System.Windows.Forms.Control parent)
1150+
{
1151+
foreach (System.Windows.Forms.Control c in parent.Controls)
1152+
{
1153+
if (c is Button && c?.Tag?.ToString() != "mapCustomization")
1154+
{
1155+
Button b = (Button)c;
1156+
b.BackColor = Theme.BackColor;
1157+
b.ForeColor = Theme.ForeColor;
1158+
b.FlatStyle = Theme.FlatStyle;
1159+
}
1160+
else if (c is GroupBox || c is Panel)
1161+
{
1162+
c.BackColor = Theme.PanelBackColor;
1163+
c.ForeColor = Theme.ForeColor;
1164+
}
1165+
else
1166+
{
1167+
c.BackColor = Theme.PanelBackColor;
1168+
c.ForeColor = Theme.ForeColor;
1169+
}
1170+
1171+
ApplyThemeRecursively(c);
1172+
}
1173+
}
1174+
#endregion
1175+
11401176
/// <summary>
11411177
/// Generates a rectangle representing a dot being drawn.
11421178
/// </summary>
@@ -1697,6 +1733,22 @@ private void DispatchViewerBeta_Resize(object sender, EventArgs e)
16971733
InitializeImage();
16981734
}
16991735

1736+
private void rotateThemesButton_Click(object sender, EventArgs e)
1737+
{
1738+
if (Theme == MapThemeProvider.LightTheme)
1739+
{
1740+
Theme = MapThemeProvider.DarkTheme;
1741+
}
1742+
else
1743+
{
1744+
Theme = MapThemeProvider.LightTheme;
1745+
}
1746+
1747+
ApplyThemeRecursively(this);
1748+
MapCanvasColor = Theme.MapCanvasColor;
1749+
TrackPen.Color = Theme.TrackColor;
1750+
}
1751+
17001752
private void DispatchViewerBeta_FormClosing(object sender, FormClosingEventArgs e)
17011753
{
17021754
// Prevent the window from closing; instead, hide it
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System.Drawing;
2+
using System.Windows.Forms;
3+
using Orts.Formats.Msts;
4+
5+
namespace Orts.Viewer3D.Debugging
6+
{
7+
public class MapThemeProvider
8+
{
9+
public ThemeStyle LightTheme;
10+
public ThemeStyle DarkTheme;
11+
12+
public void InitializeThemes()
13+
{
14+
LightTheme = new ThemeStyle
15+
{
16+
BackColor = Color.Transparent,
17+
ForeColor = SystemColors.ControlText,
18+
PanelBackColor = SystemColors.Control,
19+
FlatStyle = FlatStyle.Standard,
20+
MapCanvasColor = Color.White,
21+
TrackColor = Color.FromArgb(46, 64, 83),
22+
};
23+
24+
DarkTheme = new ThemeStyle
25+
{
26+
BackColor = Color.FromArgb(44, 62, 80),
27+
ForeColor = Color.FromArgb(247, 249, 249),
28+
PanelBackColor = Color.FromArgb(28, 40, 51),
29+
FlatStyle = FlatStyle.Flat,
30+
MapCanvasColor = Color.FromArgb(44, 62, 80),
31+
TrackColor = Color.FromArgb(234, 236, 238),
32+
};
33+
}
34+
}
35+
36+
public class ThemeStyle
37+
{
38+
public Color BackColor;
39+
public Color ForeColor;
40+
public Color PanelBackColor;
41+
public FlatStyle FlatStyle;
42+
public Color MapCanvasColor;
43+
public Color TrackColor;
44+
}
45+
}
46+
47+

0 commit comments

Comments
 (0)