mirror of
https://github.com/Alee14/shiftos-challenge.git
synced 2025-01-22 11:11:47 -05:00
Allow the desktop to be skinned.
This commit is contained in:
parent
563c26e43b
commit
3db03e7a89
5 changed files with 84 additions and 0 deletions
|
@ -22,7 +22,29 @@ namespace ShiftOS
|
|||
|
||||
private void UpdateTimer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
// Update current time of day.
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,6 +54,8 @@
|
|||
</Compile>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Skin.cs" />
|
||||
<Compile Include="SkinContext.cs" />
|
||||
<Compile Include="SystemContext.cs" />
|
||||
<EmbeddedResource Include="Desktop.resx">
|
||||
<DependentUpon>Desktop.cs</DependentUpon>
|
||||
|
|
19
ShiftOS/ShiftOS/Skin.cs
Normal file
19
ShiftOS/ShiftOS/Skin.cs
Normal 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;
|
||||
}
|
||||
}
|
23
ShiftOS/ShiftOS/SkinContext.cs
Normal file
23
ShiftOS/ShiftOS/SkinContext.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,8 +10,15 @@ namespace ShiftOS
|
|||
public class SystemContext : IDisposable
|
||||
{
|
||||
private Desktop _desktop = null;
|
||||
private SkinContext _skinContext = null;
|
||||
private int _codepoints = 0;
|
||||
|
||||
private void LoadCurrentSkin()
|
||||
{
|
||||
// TODO: Load it from a filesystem of some sort.
|
||||
_skinContext = new SkinContext();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_desktop = null;
|
||||
|
@ -22,16 +29,27 @@ namespace ShiftOS
|
|||
return this._codepoints;
|
||||
}
|
||||
|
||||
public SkinContext GetSkinContext()
|
||||
{
|
||||
return this._skinContext;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
// We can't initialize the game twice.
|
||||
if (_desktop != null)
|
||||
throw new InvalidOperationException("ShiftOS is already initialized.");
|
||||
|
||||
Console.WriteLine("Bootstrapping WinForms...");
|
||||
|
||||
// Set up WinForms to run normally.
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
|
||||
Console.WriteLine("Loading current skin...");
|
||||
this.LoadCurrentSkin();
|
||||
|
||||
Console.WriteLine("Loading desktop...");
|
||||
using (_desktop = new Desktop(this))
|
||||
{
|
||||
// Run Windows Forms.
|
||||
|
|
Loading…
Reference in a new issue