Skip to content

Commit c6b313a

Browse files
committed
Make it permanent to cycle between all available themes by using the F9 key.
1 parent fd12de9 commit c6b313a

3 files changed

Lines changed: 87 additions & 22 deletions

File tree

Source/Clients/NostalgicPlayer/Windows/WindowFormBase2.cs

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
/* license of NostalgicPlayer is keep. See the LICENSE file for more */
44
/* information. */
55
/******************************************************************************/
6+
using System;
67
using System.Drawing;
78
using System.Windows.Forms;
89
using Polycode.NostalgicPlayer.Client.GuiPlayer.Containers.Settings;
910
using Polycode.NostalgicPlayer.Client.GuiPlayer.Windows.MainWindow;
11+
using Polycode.NostalgicPlayer.Controls.Events;
1012
using Polycode.NostalgicPlayer.Controls.Forms;
1113
using Polycode.NostalgicPlayer.Controls.Images;
1214
using Polycode.NostalgicPlayer.Controls.Theme.Interfaces;
13-
using Polycode.NostalgicPlayer.Controls.Theme.Purple;
14-
using Polycode.NostalgicPlayer.Controls.Theme.Standard;
1515
using Polycode.NostalgicPlayer.Kit.Utility.Interfaces;
1616

1717
namespace Polycode.NostalgicPlayer.Client.GuiPlayer.Windows
@@ -39,6 +39,7 @@ public class WindowFormBase2 : NostalgicForm, IWindowForm
3939

4040
private WindowSettings windowSettings;
4141
private IThemeManager themeManager;
42+
private Guid selectedTheme;
4243

4344
/********************************************************************/
4445
/// <summary>
@@ -56,6 +57,10 @@ public void InitializeBaseForm(IMainWindowApi mainWindowApi, ISettings settings,
5657
allWindowSettings = settings;
5758
this.themeManager = themeManager;
5859

60+
// Find current theme ID
61+
selectedTheme = themeManager.CurrentTheme.Id;
62+
themeManager.ThemeChanged += ThemeManager_ThemeChanged;
63+
5964
// Set how the window should act in the task bar and task switcher.
6065
// Only apply to child windows - the main window (where mainWindowApi.Form
6166
// is not yet initialized) should always keep its default ShowInTaskbar = true
@@ -200,11 +205,17 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
200205
break;
201206
}
202207

203-
//XX Denne skal slettes når jeg er færdig
204-
case Keys.F12:
208+
case Keys.F9:
205209
{
206-
theme = !theme;
207-
themeManager.SwitchTheme(theme ? new PurpleTheme() : new StandardTheme());
210+
Guid[] availableThemes = themeManager.GetAvailableThemes();
211+
int currentThemeIndex = availableThemes.IndexOf(selectedTheme);
212+
213+
if ((currentThemeIndex + 1) == availableThemes.Length)
214+
currentThemeIndex = -1;
215+
216+
selectedTheme = availableThemes[currentThemeIndex + 1];
217+
218+
themeManager.SwitchTheme(selectedTheme);
208219

209220
return true;
210221
}
@@ -213,7 +224,18 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
213224

214225
return base.ProcessCmdKey(ref msg, keyData);
215226
}
216-
private bool theme = false;
227+
228+
229+
230+
/********************************************************************/
231+
/// <summary>
232+
/// Is called when the theme changes
233+
/// </summary>
234+
/********************************************************************/
235+
private void ThemeManager_ThemeChanged(object sender, ThemeChangedEventArgs e)
236+
{
237+
selectedTheme = e.NewTheme.Id;
238+
}
217239

218240

219241

Source/NostalgicPlayer.Controls/Theme/Interfaces/IThemeManager.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
/* license of NostalgicPlayer is keep. See the LICENSE file for more */
44
/* information. */
55
/******************************************************************************/
6+
using System;
7+
using System.Collections.Generic;
68
using Polycode.NostalgicPlayer.Controls.Events;
79

810
namespace Polycode.NostalgicPlayer.Controls.Theme.Interfaces
@@ -17,19 +19,24 @@ public interface IThemeManager
1719
/// </summary>
1820
event ThemeChangedEventHandler ThemeChanged;
1921

22+
/// <summary>
23+
/// Return all available themes that can be used
24+
/// </summary>
25+
Guid[] GetAvailableThemes();
26+
2027
/// <summary>
2128
/// Return the current theme
2229
/// </summary>
23-
public ITheme CurrentTheme { get; }
30+
ITheme CurrentTheme { get; }
2431

2532
/// <summary>
2633
/// Switch to the new theme given
2734
/// </summary>
28-
public void SwitchTheme(ITheme newTheme);
35+
void SwitchTheme(Guid themeId);
2936

3037
/// <summary>
3138
/// Refresh all controls
3239
/// </summary>
33-
public void RefreshControls();
40+
void RefreshControls();
3441
}
3542
}

Source/NostalgicPlayer.Controls/Theme/ThemeManager.cs

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
/* information. */
55
/******************************************************************************/
66
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
79
using Polycode.NostalgicPlayer.Controls.Events;
810
using Polycode.NostalgicPlayer.Controls.Theme.Interfaces;
11+
using Polycode.NostalgicPlayer.Controls.Theme.Purple;
912
using Polycode.NostalgicPlayer.Controls.Theme.Standard;
1013

1114
namespace Polycode.NostalgicPlayer.Controls.Theme
@@ -17,7 +20,13 @@ namespace Polycode.NostalgicPlayer.Controls.Theme
1720
/// </summary>
1821
internal class ThemeManager : IThemeManager, IDisposable
1922
{
20-
private ITheme theme;
23+
private readonly ITheme[] embeddedThemes =
24+
[
25+
new StandardTheme(),
26+
new PurpleTheme()
27+
];
28+
29+
private ITheme currentTheme;
2130

2231
/********************************************************************/
2332
/// <summary>
@@ -26,7 +35,7 @@ internal class ThemeManager : IThemeManager, IDisposable
2635
/********************************************************************/
2736
public ThemeManager()
2837
{
29-
theme = new StandardTheme();
38+
currentTheme = embeddedThemes[0];
3039
}
3140

3241

@@ -38,10 +47,13 @@ public ThemeManager()
3847
/********************************************************************/
3948
public void Dispose()
4049
{
41-
if (theme is IDisposable disposable)
42-
disposable.Dispose();
50+
foreach (ITheme theme in embeddedThemes)
51+
{
52+
if (theme is IDisposable disposable)
53+
disposable.Dispose();
54+
}
4355

44-
theme = null;
56+
currentTheme = null;
4557
}
4658

4759

@@ -55,12 +67,24 @@ public void Dispose()
5567

5668

5769

70+
/********************************************************************/
71+
/// <summary>
72+
/// Return all available themes that can be used
73+
/// </summary>
74+
/********************************************************************/
75+
public Guid[] GetAvailableThemes()
76+
{
77+
return GetThemes().Select(x => x.Id).ToArray();
78+
}
79+
80+
81+
5882
/********************************************************************/
5983
/// <summary>
6084
/// Return the current theme
6185
/// </summary>
6286
/********************************************************************/
63-
public ITheme CurrentTheme => theme;
87+
public ITheme CurrentTheme => currentTheme;
6488

6589

6690

@@ -69,12 +93,11 @@ public void Dispose()
6993
/// Switch to the new theme given
7094
/// </summary>
7195
/********************************************************************/
72-
public void SwitchTheme(ITheme newTheme)
96+
public void SwitchTheme(Guid themeId)
7397
{
74-
if (theme is IDisposable disposable)
75-
disposable.Dispose();
76-
77-
theme = newTheme;
98+
currentTheme = GetThemes().FirstOrDefault(x => x.Id == themeId);
99+
if (currentTheme == null)
100+
currentTheme = embeddedThemes[0];
78101

79102
RefreshControls();
80103
}
@@ -89,7 +112,20 @@ public void SwitchTheme(ITheme newTheme)
89112
public void RefreshControls()
90113
{
91114
if (ThemeChanged != null)
92-
ThemeChanged(this, new ThemeChangedEventArgs(theme));
115+
ThemeChanged(this, new ThemeChangedEventArgs(currentTheme));
116+
}
117+
118+
#region Private methods
119+
/********************************************************************/
120+
/// <summary>
121+
/// Return all available themes that can be used
122+
/// </summary>
123+
/********************************************************************/
124+
private IEnumerable<ITheme> GetThemes()
125+
{
126+
foreach (ITheme theme in embeddedThemes)
127+
yield return theme;
93128
}
129+
#endregion
94130
}
95131
}

0 commit comments

Comments
 (0)