Allow the desktop to be skinned.

This commit is contained in:
Alkaline Thunder 2018-12-28 00:46:11 -05:00
parent 563c26e43b
commit 3db03e7a89
5 changed files with 84 additions and 0 deletions

View file

@ -22,7 +22,29 @@ namespace ShiftOS
private void UpdateTimer_Tick(object sender, EventArgs e) private void UpdateTimer_Tick(object sender, EventArgs e)
{ {
// Update current time of day.
this.CurrentTime.Text = CurrentSystem.GetTimeOfDay(); this.CurrentTime.Text = CurrentSystem.GetTimeOfDay();
// We get our background colors from the skin.
this.BackColor = this.CurrentSystem.GetSkinContext().GetSkinData().DesktopBackgroundColor;
this.DesktopPanel.BackColor = this.CurrentSystem.GetSkinContext().GetSkinData().DesktopPanelBackgroundColor;
// Desktop panel must get its height from the skin.
this.DesktopPanel.Height = this.CurrentSystem.GetSkinContext().GetSkinData().DesktopPanelHeight;
// Set up the panel clock's position.
this.CurrentTime.Top = this.CurrentSystem.GetSkinContext().GetSkinData().PanelClockFromTop;
this.CurrentTime.Left = (DesktopPanel.Width - CurrentTime.Width) - this.CurrentSystem.GetSkinContext().GetSkinData().PanelClockFromSide;
// Determine the desktop panel dock
if(this.CurrentSystem.GetSkinContext().GetSkinData().IsDesktopPanelAtTop)
{
this.DesktopPanel.Dock = DockStyle.Top;
}
else
{
this.DesktopPanel.Dock = DockStyle.Bottom;
}
} }
} }
} }

View file

@ -54,6 +54,8 @@
</Compile> </Compile>
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Skin.cs" />
<Compile Include="SkinContext.cs" />
<Compile Include="SystemContext.cs" /> <Compile Include="SystemContext.cs" />
<EmbeddedResource Include="Desktop.resx"> <EmbeddedResource Include="Desktop.resx">
<DependentUpon>Desktop.cs</DependentUpon> <DependentUpon>Desktop.cs</DependentUpon>

19
ShiftOS/ShiftOS/Skin.cs Normal file
View file

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Threading.Tasks;
namespace ShiftOS
{
public class Skin
{
public int DesktopPanelHeight = 24;
public Color DesktopPanelBackgroundColor = Color.Gray;
public Color DesktopBackgroundColor = Color.Black;
public int PanelClockFromTop = 2;
public int PanelClockFromSide = 4;
public bool IsDesktopPanelAtTop = true;
}
}

View file

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ShiftOS
{
public class SkinContext
{
private Skin _skin = null;
public SkinContext()
{
_skin = new Skin();
}
public Skin GetSkinData()
{
return _skin;
}
}
}

View file

@ -10,8 +10,15 @@ namespace ShiftOS
public class SystemContext : IDisposable public class SystemContext : IDisposable
{ {
private Desktop _desktop = null; private Desktop _desktop = null;
private SkinContext _skinContext = null;
private int _codepoints = 0; private int _codepoints = 0;
private void LoadCurrentSkin()
{
// TODO: Load it from a filesystem of some sort.
_skinContext = new SkinContext();
}
public void Dispose() public void Dispose()
{ {
_desktop = null; _desktop = null;
@ -22,16 +29,27 @@ namespace ShiftOS
return this._codepoints; return this._codepoints;
} }
public SkinContext GetSkinContext()
{
return this._skinContext;
}
public void Initialize() public void Initialize()
{ {
// We can't initialize the game twice. // We can't initialize the game twice.
if (_desktop != null) if (_desktop != null)
throw new InvalidOperationException("ShiftOS is already initialized."); throw new InvalidOperationException("ShiftOS is already initialized.");
Console.WriteLine("Bootstrapping WinForms...");
// Set up WinForms to run normally. // Set up WinForms to run normally.
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
Console.WriteLine("Loading current skin...");
this.LoadCurrentSkin();
Console.WriteLine("Loading desktop...");
using (_desktop = new Desktop(this)) using (_desktop = new Desktop(this))
{ {
// Run Windows Forms. // Run Windows Forms.