From 3db03e7a89d9e701f8aead85ef307fd5f3e4c9ec Mon Sep 17 00:00:00 2001 From: Alkaline Thunder Date: Fri, 28 Dec 2018 00:46:11 -0500 Subject: [PATCH] Allow the desktop to be skinned. --- ShiftOS/ShiftOS/Desktop.cs | 22 ++++++++++++++++++++++ ShiftOS/ShiftOS/ShiftOS.csproj | 2 ++ ShiftOS/ShiftOS/Skin.cs | 19 +++++++++++++++++++ ShiftOS/ShiftOS/SkinContext.cs | 23 +++++++++++++++++++++++ ShiftOS/ShiftOS/SystemContext.cs | 18 ++++++++++++++++++ 5 files changed, 84 insertions(+) create mode 100644 ShiftOS/ShiftOS/Skin.cs create mode 100644 ShiftOS/ShiftOS/SkinContext.cs diff --git a/ShiftOS/ShiftOS/Desktop.cs b/ShiftOS/ShiftOS/Desktop.cs index a33461e..25d01f2 100644 --- a/ShiftOS/ShiftOS/Desktop.cs +++ b/ShiftOS/ShiftOS/Desktop.cs @@ -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; + } } } } diff --git a/ShiftOS/ShiftOS/ShiftOS.csproj b/ShiftOS/ShiftOS/ShiftOS.csproj index cc47277..d8e4c7b 100644 --- a/ShiftOS/ShiftOS/ShiftOS.csproj +++ b/ShiftOS/ShiftOS/ShiftOS.csproj @@ -54,6 +54,8 @@ + + Desktop.cs diff --git a/ShiftOS/ShiftOS/Skin.cs b/ShiftOS/ShiftOS/Skin.cs new file mode 100644 index 0000000..8aa3329 --- /dev/null +++ b/ShiftOS/ShiftOS/Skin.cs @@ -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; + } +} diff --git a/ShiftOS/ShiftOS/SkinContext.cs b/ShiftOS/ShiftOS/SkinContext.cs new file mode 100644 index 0000000..dbab213 --- /dev/null +++ b/ShiftOS/ShiftOS/SkinContext.cs @@ -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; + } + } +} diff --git a/ShiftOS/ShiftOS/SystemContext.cs b/ShiftOS/ShiftOS/SystemContext.cs index 2dc70da..13c7561 100644 --- a/ShiftOS/ShiftOS/SystemContext.cs +++ b/ShiftOS/ShiftOS/SystemContext.cs @@ -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.