aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Engine
diff options
context:
space:
mode:
Diffstat (limited to 'ShiftOS.Engine')
-rw-r--r--ShiftOS.Engine/Misc/IniFile.cs50
-rw-r--r--ShiftOS.Engine/Misc/Tools.cs (renamed from ShiftOS.Engine/Tools.cs)14
-rw-r--r--ShiftOS.Engine/Properties/AssemblyInfo.cs3
-rw-r--r--ShiftOS.Engine/ShiftFS/ShiftDirectory.cs50
-rw-r--r--ShiftOS.Engine/ShiftFS/ShiftDrive.cs20
-rw-r--r--ShiftOS.Engine/ShiftFS/ShiftFS.cs34
-rw-r--r--ShiftOS.Engine/ShiftFS/ShiftFSObject.cs25
-rw-r--r--ShiftOS.Engine/ShiftFS/ShiftFile.cs48
-rw-r--r--ShiftOS.Engine/ShiftOS.Engine.csproj8
-rw-r--r--ShiftOS.Engine/Terminal/Commands/Hello.cs26
-rw-r--r--ShiftOS.Engine/Terminal/TerminalBackend.cs71
-rw-r--r--ShiftOS.Engine/Terminal/TerminalCommand.cs20
-rw-r--r--ShiftOS.Engine/WindowManager/InfoboxTemplate.cs162
-rw-r--r--ShiftOS.Engine/WindowManager/ShiftSkinData.cs39
-rw-r--r--ShiftOS.Engine/WindowManager/ShiftWM.cs215
-rw-r--r--ShiftOS.Engine/WindowManager/ShiftWindow.cs99
-rw-r--r--ShiftOS.Engine/packages.config1
17 files changed, 552 insertions, 333 deletions
diff --git a/ShiftOS.Engine/Misc/IniFile.cs b/ShiftOS.Engine/Misc/IniFile.cs
new file mode 100644
index 0000000..e31583f
--- /dev/null
+++ b/ShiftOS.Engine/Misc/IniFile.cs
@@ -0,0 +1,50 @@
+using System.Runtime.InteropServices;
+using System.Text;
+
+namespace ShiftOS.Engine.Misc
+{
+ /// <summary>
+ /// Create a New INI file to store or load data
+ /// </summary>
+ public class IniFile
+ {
+ readonly string _path;
+
+ public IniFile(string iniPath) => _path = iniPath;
+
+ [DllImport("kernel32")]
+ static extern long WritePrivateProfileString(
+ string section,
+ string key,
+ string val,
+ string filePath);
+
+ [DllImport("kernel32")]
+ static extern int GetPrivateProfileString(
+ string section,
+ string key,
+ string def,
+ StringBuilder retVal,
+ int size,
+ string filePath);
+
+ public void WriteValue(string section, string key, string value)
+ {
+ WritePrivateProfileString(section, key, value, _path);
+ }
+
+ public string ReadValue(string section, string key)
+ {
+ var temp = new StringBuilder(255);
+ GetPrivateProfileString(
+ section,
+ key,
+ "",
+ temp,
+ 255,
+ _path);
+
+ return temp.ToString();
+ }
+ }
+} \ No newline at end of file
diff --git a/ShiftOS.Engine/Tools.cs b/ShiftOS.Engine/Misc/Tools.cs
index 792ccef..6430084 100644
--- a/ShiftOS.Engine/Tools.cs
+++ b/ShiftOS.Engine/Misc/Tools.cs
@@ -1,26 +1,24 @@
using System;
using System.Drawing;
-using System.Drawing.Imaging;
-using System.IO;
using System.Runtime.InteropServices;
-namespace ShiftOS.Engine
+namespace ShiftOS.Engine.Misc
{
/// <summary>
- /// Random class full of unassorted [but also uncategorizable] tools.
+ /// Random class full of unassorted [but also uncategorizable] tools.
/// </summary>
public static class Tools
{
public static Random Rnd = new Random();
[DllImport("user32.dll", CharSet = CharSet.Auto)]
- public extern static bool DestroyIcon(IntPtr handle);
+ public static extern bool DestroyIcon(IntPtr handle);
public static Icon ToIcon(this Bitmap bm)
{
- Icon tempicon = Icon.FromHandle(bm.GetHicon());
+ var tempicon = Icon.FromHandle(bm.GetHicon());
- Icon newIcon = tempicon.Clone() as Icon;
+ var newIcon = tempicon.Clone() as Icon;
//for some reason this exists
DestroyIcon(tempicon.Handle);
@@ -28,4 +26,4 @@ namespace ShiftOS.Engine
return newIcon;
}
}
-}
+} \ No newline at end of file
diff --git a/ShiftOS.Engine/Properties/AssemblyInfo.cs b/ShiftOS.Engine/Properties/AssemblyInfo.cs
index 0a17339..51aee88 100644
--- a/ShiftOS.Engine/Properties/AssemblyInfo.cs
+++ b/ShiftOS.Engine/Properties/AssemblyInfo.cs
@@ -1,5 +1,4 @@
using System.Reflection;
-using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
@@ -33,4 +32,4 @@ using System.Runtime.InteropServices;
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file
diff --git a/ShiftOS.Engine/ShiftFS/ShiftDirectory.cs b/ShiftOS.Engine/ShiftFS/ShiftDirectory.cs
new file mode 100644
index 0000000..64ac4f2
--- /dev/null
+++ b/ShiftOS.Engine/ShiftFS/ShiftDirectory.cs
@@ -0,0 +1,50 @@
+using System.Collections.ObjectModel;
+using System.IO;
+using System.Linq;
+
+namespace ShiftOS.Engine.ShiftFS
+{
+ public class ShiftDirectory : ShiftFsObject
+ {
+ public ShiftDirectory(string path) : base(path)
+ {
+ path = path.Replace(ShiftFs.SavePath, "");
+ var dir = new DirectoryInfo(Path.Combine(ShiftFs.SavePath, path));
+ Name = dir.Name;
+ FullDiskName = dir.FullName;
+ FullName = path;
+
+ Children.CollectionChanged += (sender, e) => { };
+ }
+
+ public ShiftFsObject this[string name] => Children.First(f => f.Name == name);
+ public ShiftFsObject this[int index] => Children[index];
+
+ public new ShiftDirectory Parent => new ShiftDirectory(new DirectoryInfo(FullDiskName).Parent.FullName);
+
+ public ObservableCollection<ShiftFsObject> Children
+ {
+ get
+ {
+ var collection = new ObservableCollection<ShiftFsObject>();
+
+ foreach (var dir in new DirectoryInfo(Path.Combine(ShiftFs.SavePath, FullName)).EnumerateDirectories())
+ {
+ collection.Add(new ShiftDirectory(dir.FullName));
+ }
+
+ foreach (var file in new DirectoryInfo(Path.Combine(ShiftFs.SavePath, FullName)).EnumerateFiles())
+ {
+ collection.Add(new ShiftFile(file.FullName.Replace(ShiftFs.SavePath, "")));
+ }
+
+ return collection;
+ }
+ }
+
+ public ObservableCollection<ShiftFile> Files => new ObservableCollection<ShiftFile>(Children.OfType<ShiftFile>());
+
+ public ObservableCollection<ShiftDirectory> Directories
+ => new ObservableCollection<ShiftDirectory>(Children.OfType<ShiftDirectory>());
+ }
+} \ No newline at end of file
diff --git a/ShiftOS.Engine/ShiftFS/ShiftDrive.cs b/ShiftOS.Engine/ShiftFS/ShiftDrive.cs
new file mode 100644
index 0000000..cde9e8d
--- /dev/null
+++ b/ShiftOS.Engine/ShiftFS/ShiftDrive.cs
@@ -0,0 +1,20 @@
+using System.IO;
+using ShiftOS.Engine.Misc;
+
+namespace ShiftOS.Engine.ShiftFS
+{
+ public class ShiftDrive
+ {
+ internal ShiftDrive(DirectoryInfo dir)
+ {
+ Label = dir.Name;
+ var file = new IniFile(Path.Combine(dir.FullName, "driveinfo.ini"));
+ Letter = char.TryParse(file.ReadValue("", "DriveLetter"), out var letter) ? letter : '?';
+ Contents = new ShiftDirectory(dir.FullName);
+ }
+
+ public string Label { get; }
+ public char Letter { get; }
+ public ShiftDirectory Contents { get; }
+ }
+} \ No newline at end of file
diff --git a/ShiftOS.Engine/ShiftFS/ShiftFS.cs b/ShiftOS.Engine/ShiftFS/ShiftFS.cs
new file mode 100644
index 0000000..d188bee
--- /dev/null
+++ b/ShiftOS.Engine/ShiftFS/ShiftFS.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.ObjectModel;
+using System.IO;
+
+namespace ShiftOS.Engine.ShiftFS
+{
+ public static class ShiftFs
+ {
+ internal static readonly string SavePath = Path.Combine(Environment.CurrentDirectory, "Save") + "\\";
+
+ public static ObservableCollection<ShiftDrive> Drives = new ObservableCollection<ShiftDrive>();
+
+ static ShiftFs()
+ {
+ if (Directory.Exists(SavePath))
+ {
+ var info = new DirectoryInfo(SavePath);
+ foreach (var dir in info.EnumerateDirectories())
+ {
+ Drives.Add(new ShiftDrive(dir));
+ }
+ }
+ else
+ {
+ CreateSaveFile();
+ }
+ }
+
+ public static void CreateSaveFile()
+ {
+ throw new NotImplementedException();
+ }
+ }
+} \ No newline at end of file
diff --git a/ShiftOS.Engine/ShiftFS/ShiftFSObject.cs b/ShiftOS.Engine/ShiftFS/ShiftFSObject.cs
new file mode 100644
index 0000000..69750fa
--- /dev/null
+++ b/ShiftOS.Engine/ShiftFS/ShiftFSObject.cs
@@ -0,0 +1,25 @@
+using System.IO;
+
+namespace ShiftOS.Engine.ShiftFS
+{
+ public abstract class ShiftFsObject
+ {
+ protected ShiftFsObject(string path)
+ {
+ if (!File.Exists(Path.Combine(ShiftFs.SavePath, path)) && !Directory.Exists(Path.Combine(ShiftFs.SavePath, path)))
+ {
+ throw new FileNotFoundException();
+ }
+ }
+
+ public string Name { get; set; }
+ public ShiftDirectory Parent { get; protected set; }
+ public string FullName { get; set; }
+ protected string FullDiskName { get; set; }
+
+ public void Delete()
+ {
+ File.Delete(FullDiskName);
+ }
+ }
+} \ No newline at end of file
diff --git a/ShiftOS.Engine/ShiftFS/ShiftFile.cs b/ShiftOS.Engine/ShiftFS/ShiftFile.cs
new file mode 100644
index 0000000..1a2413c
--- /dev/null
+++ b/ShiftOS.Engine/ShiftFS/ShiftFile.cs
@@ -0,0 +1,48 @@
+using System;
+using System.IO;
+using System.Runtime.Serialization.Formatters.Binary;
+
+namespace ShiftOS.Engine.ShiftFS
+{
+ public class ShiftFile : ShiftFsObject
+ {
+ public ShiftFile(string path) : base(path)
+ {
+ path = path.Replace(ShiftFs.SavePath, "");
+
+ using (var fs = new FileStream(Path.Combine(ShiftFs.SavePath, path), FileMode.Open))
+ {
+ Bytes = new MemoryStream();
+ fs.CopyTo(Bytes);
+ }
+
+ var file = new FileInfo(Path.Combine(ShiftFs.SavePath, path));
+
+ Name = file.Name;
+ FullDiskName = file.FullName;
+ FullName = path;
+ }
+
+ public new ShiftDirectory Parent => new ShiftDirectory(new FileInfo(FullDiskName).Directory.FullName);
+
+ public MemoryStream Bytes { get; set; }
+ public long Length => Bytes.Length;
+ }
+
+ public class ShiftFile<T> : ShiftFile // please C# gods let us constrain to attributes
+ {
+ public ShiftFile(string path) : base(path)
+ {
+ if (!typeof(T).IsSerializable)
+ {
+ throw new InvalidOperationException("Non-serializable types are not supported");
+ }
+ }
+
+ public T Object
+ {
+ get => (T) new BinaryFormatter().Deserialize(Bytes);
+ set => new BinaryFormatter().Serialize(Bytes, value);
+ }
+ }
+} \ No newline at end of file
diff --git a/ShiftOS.Engine/ShiftOS.Engine.csproj b/ShiftOS.Engine/ShiftOS.Engine.csproj
index 3a505fb..ca3638e 100644
--- a/ShiftOS.Engine/ShiftOS.Engine.csproj
+++ b/ShiftOS.Engine/ShiftOS.Engine.csproj
@@ -46,16 +46,22 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="Misc\IniFile.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
+ <Compile Include="ShiftFS\ShiftDirectory.cs" />
+ <Compile Include="ShiftFS\ShiftDrive.cs" />
+ <Compile Include="ShiftFS\ShiftFile.cs" />
+ <Compile Include="ShiftFS\ShiftFS.cs" />
+ <Compile Include="ShiftFS\ShiftFSObject.cs" />
<Compile Include="Terminal\Commands\Hello.cs" />
<Compile Include="Terminal\TerminalBackend.cs" />
<Compile Include="Terminal\TerminalCommand.cs" />
- <Compile Include="Tools.cs" />
+ <Compile Include="Misc\Tools.cs" />
<Compile Include="WindowManager\InfoboxTemplate.cs">
<SubType>UserControl</SubType>
</Compile>
diff --git a/ShiftOS.Engine/Terminal/Commands/Hello.cs b/ShiftOS.Engine/Terminal/Commands/Hello.cs
index 531bd1f..7d4b82f 100644
--- a/ShiftOS.Engine/Terminal/Commands/Hello.cs
+++ b/ShiftOS.Engine/Terminal/Commands/Hello.cs
@@ -1,21 +1,9 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace ShiftOS.Engine.Terminal.Commands
+namespace ShiftOS.Engine.Terminal.Commands
{
- public class Hello : TerminalCommand
- {
- public override string GetName()
- {
- return "Hello";
- }
+ public class Hello : TerminalCommand
+ {
+ public override string GetName() => "Hello";
- public override string Run(params string[] parameters)
- {
- return "Oh, HELLO, " + String.Join(" ", parameters);
- }
- }
-}
+ public override string Run(params string[] parameters) => "Oh, HELLO, " + string.Join(" ", parameters);
+ }
+} \ No newline at end of file
diff --git a/ShiftOS.Engine/Terminal/TerminalBackend.cs b/ShiftOS.Engine/Terminal/TerminalBackend.cs
index 7103238..793b748 100644
--- a/ShiftOS.Engine/Terminal/TerminalBackend.cs
+++ b/ShiftOS.Engine/Terminal/TerminalBackend.cs
@@ -2,45 +2,46 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
-using System.Text;
-using System.Threading.Tasks;
namespace ShiftOS.Engine.Terminal
{
- public static class TerminalBackend
- {
- // The line below gets all the terminal commands in... well... the entire ShiftOS.Engine
- public static IEnumerable<TerminalCommand> instances = from t in Assembly.GetExecutingAssembly().GetTypes()
- where t.IsSubclassOf(typeof(TerminalCommand))
- && t.GetConstructor(Type.EmptyTypes) != null
- select Activator.CreateInstance(t) as TerminalCommand;
+ public static class TerminalBackend
+ {
+ // The line below gets all the terminal commands in... well... the entire ShiftOS.Engine
+ static readonly IEnumerable<TerminalCommand> Instances = from t in Assembly.GetExecutingAssembly().GetTypes()
+ where t.IsSubclassOf(typeof(TerminalCommand)) &&
+ t.GetConstructor(Type.EmptyTypes) != null
+ select (TerminalCommand) Activator.CreateInstance(t);
- /// <summary>
- /// Runs a terminal command.
- /// </summary>
- /// <param name="command"></param>
- /// <returns>Returns all the output from that command.</returns>
- public static string RunCommand(string command)
- {
- string name;
- try { name = command.Split(' ')[0]; } catch { name = command; }
+ /// <summary>
+ /// Runs a terminal command.
+ /// </summary>
+ /// <param name="command"></param>
+ /// <returns>Returns all the output from that command.</returns>
+ public static string RunCommand(string command)
+ {
+ string name;
+ try
+ {
+ name = command.Split(' ')[0];
+ }
+ catch
+ {
+ name = command;
+ }
- var theParams = new string[command.Split(' ').Length - 1];
- Array.Copy(command.Split(' '), 1, theParams, 0, command.Split(' ').Length - 1);
+ var theParams = new string[command.Split(' ').Length - 1];
+ Array.Copy(command.Split(' '), 1, theParams, 0, command.Split(' ').Length - 1);
- foreach (TerminalCommand instance in instances)
- {
- if (instance.GetName() == name)
- return instance.Run(theParams);
- }
+ foreach (var instance in Instances)
+ {
+ if (instance.GetName() == name)
+ {
+ return instance.Run(theParams);
+ }
+ }
- return "The command cannot be found.";
- }
-
- // An extra function ;)
- private static Type[] GetTypesInNamespace(Assembly assembly, string nameSpace)
- {
- return assembly.GetTypes().Where(t => String.Equals(t.Namespace, nameSpace, StringComparison.Ordinal)).ToArray();
- }
- }
-}
+ return "The command cannot be found.";
+ }
+ }
+} \ No newline at end of file
diff --git a/ShiftOS.Engine/Terminal/TerminalCommand.cs b/ShiftOS.Engine/Terminal/TerminalCommand.cs
index a344122..81a34b9 100644
--- a/ShiftOS.Engine/Terminal/TerminalCommand.cs
+++ b/ShiftOS.Engine/Terminal/TerminalCommand.cs
@@ -1,15 +1,9 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace ShiftOS.Engine.Terminal
+namespace ShiftOS.Engine.Terminal
{
- public abstract class TerminalCommand
- {
- public abstract string GetName();
+ public abstract class TerminalCommand
+ {
+ public abstract string GetName();
- public abstract string Run(params string[] parameters);
- }
-}
+ public abstract string Run(params string[] parameters);
+ }
+} \ No newline at end of file
diff --git a/ShiftOS.Engine/WindowManager/InfoboxTemplate.cs b/ShiftOS.Engine/WindowManager/InfoboxTemplate.cs
index 948df22..c2b45e0 100644
--- a/ShiftOS.Engine/WindowManager/InfoboxTemplate.cs
+++ b/ShiftOS.Engine/WindowManager/InfoboxTemplate.cs
@@ -1,94 +1,94 @@
using System;
using System.Drawing;
-using System.Windows.Forms;
-using System.Media;
using System.IO;
+using System.Media;
+using System.Windows.Forms;
+using ShiftOS.Engine.Properties;
namespace ShiftOS.Engine.WindowManager
{
- public partial class InfoboxTemplate : UserControl
- {
- Stream _str;
- private int _buttonChoice;
- private int _buttonSelected;
- public InfoboxTemplate(ButtonType type)
- {
- InitializeComponent();
-
- switch (type)
- {
- case ButtonType.Ok:
- btnOpt1.Text = "OK";
- btnOpt2.Hide();
- btnOpt1.Location = new Point(109, 134);
- _buttonChoice = 1;
- break;
- case ButtonType.OkCancel:
- btnOpt1.Text = "OK";
- btnOpt2.Text = "Cancel";
- _buttonChoice = 2;
- break;
- case ButtonType.YesNo:
- btnOpt1.Text = "Yes";
- btnOpt2.Text = "No";
- _buttonChoice = 3;
- break;
- }
- }
+ public partial class InfoboxTemplate : UserControl
+ {
+ public enum ButtonType
+ {
+ YesNo,
+ OkCancel,
+ Ok
+ }
- public enum ButtonType
- {
- YesNo,
- OkCancel,
- Ok
- }
+ public enum DialogResult
+ {
+ Yes,
+ No,
+ Cancel,
+ Ok
+ }
- public enum DialogResult
- {
- Yes,
- No,
- Cancel,
- Ok
- }
+ int _buttonChoice;
+ int _buttonSelected;
+ Stream _str;
- private void btnOpt1_Click(object sender, EventArgs e)
- {
- switch (btnOpt1.Text)
- {
- case "OK":
- ParentForm?.Close();
- break;
- case "Yes":
- _buttonSelected = 2;
- ParentForm?.Close();
- break;
- }
- }
+ public InfoboxTemplate(ButtonType type)
+ {
+ InitializeComponent();
- private void btnOpt2_Click(object sender, EventArgs e)
- {
- switch (btnOpt2.Text)
- {
- case "No":
- _buttonSelected = 3;
- break;
- case "Cancel":
- _buttonSelected = 4;
- break;
- }
- }
+ switch (type)
+ {
+ case ButtonType.Ok:
+ btnOpt1.Text = "OK";
+ btnOpt2.Hide();
+ btnOpt1.Location = new Point(109, 134);
+ _buttonChoice = 1;
+ break;
+ case ButtonType.OkCancel:
+ btnOpt1.Text = "OK";
+ btnOpt2.Text = "Cancel";
+ _buttonChoice = 2;
+ break;
+ case ButtonType.YesNo:
+ btnOpt1.Text = "Yes";
+ btnOpt2.Text = "No";
+ _buttonChoice = 3;
+ break;
+ }
+ }
- public void Play()
- {
- _str = Properties.Resources.infobox;
- SoundPlayer sp = new SoundPlayer(_str);
- sp.Play();
- sp.Stream.Position = 0;
- }
+ void btnOpt1_Click(object sender, EventArgs e)
+ {
+ switch (btnOpt1.Text)
+ {
+ case "OK":
+ ParentForm?.Close();
+ break;
+ case "Yes":
+ _buttonSelected = 2;
+ ParentForm?.Close();
+ break;
+ }
+ }
- private void InfoboxTemplate_Load(object sender, EventArgs e)
- => Play();
+ void btnOpt2_Click(object sender, EventArgs e)
+ {
+ switch (btnOpt2.Text)
+ {
+ case "No":
+ _buttonSelected = 3;
+ break;
+ case "Cancel":
+ _buttonSelected = 4;
+ break;
+ }
+ }
+
+ public void Play()
+ {
+ _str = Resources.infobox;
+ var sp = new SoundPlayer(_str);
+ sp.Play();
+ sp.Stream.Position = 0;
+ }
-
- }
-}
+ void InfoboxTemplate_Load(object sender, EventArgs e)
+ => Play();
+ }
+} \ No newline at end of file
diff --git a/ShiftOS.Engine/WindowManager/ShiftSkinData.cs b/ShiftOS.Engine/WindowManager/ShiftSkinData.cs
index 9f4bf45..2c8c4c8 100644
--- a/ShiftOS.Engine/WindowManager/ShiftSkinData.cs
+++ b/ShiftOS.Engine/WindowManager/ShiftSkinData.cs
@@ -2,22 +2,23 @@
namespace ShiftOS.Engine.WindowManager
{
- public abstract class ShiftSkinData
- {
- // ColorData
- public static Color leftTopCornerColor = Color.Empty;
- public static Color titleBarColor = Color.Empty;
- public static Color rightTopCornerColor = Color.Empty;
- public static Color btnCloseColor = Color.Empty;
- public static Color btnMaxColor = Color.Empty;
- public static Color btnMinColor = Color.Empty;
- public static Color btnCloseHoverColor = Color.Empty;
- public static Color btnMaxHoverColor = Color.Empty;
- public static Color btnMinHoverColor = Color.Empty;
- public static Color leftSideColor = Color.Empty;
- public static Color rightSideColor = Color.Empty;
- public static Color leftBottomCornerColor = Color.Empty;
- public static Color bottomSideColor = Color.Empty;
- public static Color rightBottomCornerColor = Color.Empty;
- }
-}
+ public abstract class ShiftSkinData
+ {
+ // ColorData
+ public static Color LeftTopCornerColor = Color.Empty;
+
+ public static Color TitleBarColor = Color.Empty;
+ public static Color RightTopCornerColor = Color.Empty;
+ public static Color BtnCloseColor = Color.Empty;
+ public static Color BtnMaxColor = Color.Empty;
+ public static Color BtnMinColor = Color.Empty;
+ public static Color BtnCloseHoverColor = Color.Empty;
+ public static Color BtnMaxHoverColor = Color.Empty;
+ public static Color BtnMinHoverColor = Color.Empty;
+ public static Color LeftSideColor = Color.Empty;
+ public static Color RightSideColor = Color.Empty;
+ public static Color LeftBottomCornerColor = Color.Empty;
+ public static Color BottomSideColor = Color.Empty;
+ public static Color RightBottomCornerColor = Color.Empty;
+ }
+} \ No newline at end of file
diff --git a/ShiftOS.Engine/WindowManager/ShiftWM.cs b/ShiftOS.Engine/WindowManager/ShiftWM.cs
index 64b84f9..b6079bd 100644
--- a/ShiftOS.Engine/WindowManager/ShiftWM.cs
+++ b/ShiftOS.Engine/WindowManager/ShiftWM.cs
@@ -1,126 +1,129 @@
-using System;
-using System.Collections.ObjectModel;
+using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
+using ShiftOS.Engine.Misc;
+using ShiftOS.Engine.Properties;
using static ShiftOS.Engine.WindowManager.InfoboxTemplate;
namespace ShiftOS.Engine.WindowManager
{
- public static class ShiftWM
- {
+ public static class ShiftWm
+ {
public static ObservableCollection<ShiftWindow> Windows { get; } = new ObservableCollection<ShiftWindow>();
- public static ShiftWindow GetShiftWindow(this UserControl control)
- {
- return Windows.First(p => (uint) control.Tag == p.Id);
- }
-
- /// <summary>
- /// Shows a new ShiftWindow based on a UserControl.
- /// </summary>
- /// <param name="content">The UserControl to use</param>
- /// <param name="title">The program's title</param>
- /// <param name="icon">The icon to show</param>
- /// <param name="showAsInfobox">Checks if this is an infobox</param>
- /// <param name="resize">Enables or disables resizing</param>
- /// <returns></returns>
- public static ShiftWindow Init(UserControl content, string title, Icon icon, bool showAsInfobox = false, bool resize = true)
- {
- // Setup Window
- ShiftWindow app = new ShiftWindow
- {
- Text = title,
- Title = {Text = title}
- };
-
- app.Width = content.Width + app.leftSide.Width + app.rightSide.Width;
- app.Height = content.Height + app.bottomSide.Height + app.titleBar.Height;
-
- if (ShiftSkinData.titleBarColor == Color.Empty)
- {
- Color borderColor = Color.FromArgb(64, 64, 64);
- ShiftSkinData.btnCloseColor = Color.Black;
- ShiftSkinData.btnMaxColor = Color.Black;
- ShiftSkinData.btnMinColor = Color.Black;
- ShiftSkinData.leftTopCornerColor = borderColor;
- ShiftSkinData.titleBarColor = borderColor;
- ShiftSkinData.rightTopCornerColor = borderColor;
- ShiftSkinData.leftSideColor = borderColor;
- ShiftSkinData.rightSideColor = borderColor;
- ShiftSkinData.leftBottomCornerColor = borderColor;
- ShiftSkinData.bottomSideColor = borderColor;
- ShiftSkinData.rightBottomCornerColor = borderColor;
- }
-
- app.btnClose.BackColor = ShiftSkinData.btnCloseColor;
- app.btnMax.BackColor = ShiftSkinData.btnMaxColor;
- app.btnMin.BackColor = ShiftSkinData.btnMinColor;
- app.leftTopCorner.BackColor = ShiftSkinData.leftTopCornerColor;
- app.titleBar.BackColor = ShiftSkinData.titleBarColor;
- app.rightTopCorner.BackColor = ShiftSkinData.rightTopCornerColor;
- app.leftSide.BackColor = ShiftSkinData.leftSideColor;
- app.rightSide.BackColor = ShiftSkinData.rightSideColor;
- app.leftBottomCorner.BackColor = ShiftSkinData.leftBottomCornerColor;
- app.bottomSide.BackColor = ShiftSkinData.bottomSideColor;
- app.rightBottomCorner.BackColor = ShiftSkinData.rightBottomCornerColor;
-
-
- // Icon Setup
- if (icon == null)
- {
- app.programIcon.Hide();
- app.programIcon.Image = Properties.Resources.nullIcon;
- app.Title.Location = new Point(2, 7);
- }
-
- else
- {
- app.programIcon.Image = icon.ToBitmap();
- app.Icon = icon;
- }
+ public static ShiftWindow GetShiftWindow(this UserControl control)
+ {
+ return Windows.First(p => (uint) control.Tag == p.Id);
+ }
+
+ /// <summary>
+ /// Shows a new ShiftWindow based on a UserControl.
+ /// </summary>
+ /// <param name="content">The UserControl to use</param>
+ /// <param name="title">The program's title</param>
+ /// <param name="icon">The icon to show</param>
+ /// <param name="showAsInfobox">Checks if this is an infobox</param>
+ /// <param name="resize">Enables or disables resizing</param>
+ /// <returns></returns>
+ public static ShiftWindow Init(
+ UserControl content,
+ string title,
+ Icon icon,
+ bool showAsInfobox = false,
+ bool resize = true)
+ {
+ // Setup Window
+ var app = new ShiftWindow
+ {
+ Text = title,
+ Title = { Text = title }
+ };
+
+ app.Width = content.Width + app.leftSide.Width + app.rightSide.Width;
+ app.Height = content.Height + app.bottomSide.Height + app.titleBar.Height;
+
+ if (ShiftSkinData.TitleBarColor == Color.Empty)
+ {
+ var borderColor = Color.FromArgb(64, 64, 64);
+ ShiftSkinData.BtnCloseColor = Color.Black;
+ ShiftSkinData.BtnMaxColor = Color.Black;
+ ShiftSkinData.BtnMinColor = Color.Black;
+ ShiftSkinData.LeftTopCornerColor = borderColor;
+ ShiftSkinData.TitleBarColor = borderColor;
+ ShiftSkinData.RightTopCornerColor = borderColor;
+ ShiftSkinData.LeftSideColor = borderColor;
+ ShiftSkinData.RightSideColor = borderColor;
+ ShiftSkinData.LeftBottomCornerColor = borderColor;
+ ShiftSkinData.BottomSideColor = borderColor;
+ ShiftSkinData.RightBottomCornerColor = borderColor;
+ }
+
+ app.btnClose.BackColor = ShiftSkinData.BtnCloseColor;
+ app.btnMax.BackColor = ShiftSkinData.BtnMaxColor;
+ app.btnMin.BackColor = ShiftSkinData.BtnMinColor;
+ app.leftTopCorner.BackColor = ShiftSkinData.LeftTopCornerColor;
+ app.titleBar.BackColor = ShiftSkinData.TitleBarColor;
+ app.rightTopCorner.BackColor = ShiftSkinData.RightTopCornerColor;
+ app.leftSide.BackColor = ShiftSkinData.LeftSideColor;
+ app.rightSide.BackColor = ShiftSkinData.RightSideColor;
+ app.leftBottomCorner.BackColor = ShiftSkinData.LeftBottomCornerColor;
+ app.bottomSide.BackColor = ShiftSkinData.BottomSideColor;
+ app.rightBottomCorner.BackColor = ShiftSkinData.RightBottomCornerColor;
+
+
+ // Icon Setup
+ if (icon == null)
+ {
+ app.programIcon.Hide();
+ app.programIcon.Image = Resources.nullIcon;
+ app.Title.Location = new Point(2, 7);
+ }
+
+ else
+ {
+ app.programIcon.Image = icon.ToBitmap();
+ app.Icon = icon;
+ }
// Setup UC
content.Parent = app.programContent;
- content.BringToFront();
- content.Dock = DockStyle.Fill;
- app.Show();
+ content.BringToFront();
+ content.Dock = DockStyle.Fill;
+ app.Show();
- content.Tag = app.SetId();
+ content.Tag = app.SetId();
Debug.WriteLine($"usercontrol: {content.Tag} window: {app.Id}");
- app.Closed += (sender, args) =>
- {
- Windows.Remove((ShiftWindow) sender);
- };
+ app.Closed += (sender, args) => { Windows.Remove((ShiftWindow) sender); };
Windows.Add(app);
- if (content is IShiftWindowExtensions extensions)
- {
- extensions.OnLoaded(app);
- }
-
- return app;
- }
-
- /// <summary>
- /// Shows a new infobox.
- /// </summary>
- /// <param name="title">The title of the infobox.</param>
- /// <param name="body">The infobox's content.</param>
- /// <param name="type">The ButtonType used for the infobox.</param>
- /// <returns></returns>
- public static InfoboxTemplate StartInfoboxSession(string title, string body, ButtonType type)
- {
- InfoboxTemplate info = new InfoboxTemplate(type)
- {
- label1 = { Text = body }
- };
- Init(info, title, Properties.Resources.iconInfoBox_fw.ToIcon(), true, false);
- return info;
- }
- }
-}
+ if (content is IShiftWindowExtensions extensions)
+ {
+ extensions.OnLoaded(app);
+ }
+
+ return app;
+ }
+
+ /// <summary>
+ /// Shows a new infobox.
+ /// </summary>
+ /// <param name="title">The title of the infobox.</param>
+ /// <param name="body">The infobox's content.</param>
+ /// <param name="type">The ButtonType used for the infobox.</param>
+ /// <returns></returns>
+ public static InfoboxTemplate StartInfoboxSession(string title, string body, ButtonType type)
+ {
+ var info = new InfoboxTemplate(type)
+ {
+ label1 = { Text = body }
+ };
+ Init(info, title, Resources.iconInfoBox_fw.ToIcon(), true, false);
+ return info;
+ }
+ }
+} \ No newline at end of file
diff --git a/ShiftOS.Engine/WindowManager/ShiftWindow.cs b/ShiftOS.Engine/WindowManager/ShiftWindow.cs
index a8b9c79..aa327f1 100644
--- a/ShiftOS.Engine/WindowManager/ShiftWindow.cs
+++ b/ShiftOS.Engine/WindowManager/ShiftWindow.cs
@@ -1,74 +1,76 @@
using System;
-using System.Drawing;
using System.Linq;
-using System.Windows.Forms;
using System.Runtime.InteropServices;
+using System.Windows.Forms;
+using ShiftOS.Engine.Misc;
namespace ShiftOS.Engine.WindowManager
{
- public partial class ShiftWindow : Form
- {
- public uint Id { get; private set; }
+ public partial class ShiftWindow : Form
+ {
+ const int WmNclbuttondown = 0xA1;
+ const int HtCaption = 0x2;
- public UserControl ChildControl { get; set; }
+ public ShiftWindow()
+ {
+ InitializeComponent();
+ }
- public ShiftWindow()
- {
- InitializeComponent();
- }
+ public uint Id { get; private set; }
+
+ public UserControl ChildControl { get; set; }
- public uint SetId()
- {
+ public uint SetId()
+ {
do
{
- Id = (uint)Tools.Rnd.Next(100000, 999999);
- }
- while (ShiftWM.Windows.FirstOrDefault(w => w.Id == Id) != null);
+ Id = (uint) Tools.Rnd.Next(100000, 999999);
+ } while (ShiftWm.Windows.FirstOrDefault(w => w.Id == Id) != null);
- return Id;
- }
+ return Id;
+ }
- private const int WM_NCLBUTTONDOWN = 0xA1;
- private const int HT_CAPTION = 0x2;
+ [DllImport("user32.dll")]
+ static extern int SendMessage(
+ IntPtr hWnd,
+ int msg,
+ int wParam,
+ int lParam);
- [DllImportAttribute("user32.dll")]
- private static extern int SendMessage(IntPtr hWnd,
- int Msg, int wParam, int lParam);
+ [DllImport("user32.dll")]
+ static extern bool ReleaseCapture();
- [DllImportAttribute("user32.dll")]
- private static extern bool ReleaseCapture();
+ void Programtopbar_drag(object sender, MouseEventArgs e)
+ {
+ if (e.Button != MouseButtons.Left) return;
- private void Programtopbar_drag(object sender, MouseEventArgs e)
- {
- if (e.Button != MouseButtons.Left) return;
+ ReleaseCapture();
+ SendMessage(Handle, WmNclbuttondown, HtCaption, 0);
+ }
- ReleaseCapture();
- SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
- }
+ void closebutton_Click(object sender, EventArgs e)
+ => Close();
- private void closebutton_Click(object sender, EventArgs e)
- => this.Close();
+ void closebutton_MouseEnter(object sender, EventArgs e)
+ => btnClose.BackColor = ShiftSkinData.BtnCloseHoverColor;
- private void closebutton_MouseEnter(object sender, EventArgs e)
- => btnClose.BackColor = ShiftSkinData.btnCloseHoverColor;
+ void closebutton_MouseLeave(object sender, EventArgs e)
+ => btnClose.BackColor = ShiftSkinData.BtnCloseColor;
- private void closebutton_MouseLeave(object sender, EventArgs e)
- => btnClose.BackColor = ShiftSkinData.btnCloseColor;
+ void maximizebutton_MouseEnter(object sender, EventArgs e)
+ => btnMax.BackColor = ShiftSkinData.BtnMaxHoverColor;
- private void maximizebutton_MouseEnter(object sender, EventArgs e)
- => btnMax.BackColor = ShiftSkinData.btnMaxHoverColor;
+ void maximizebutton_MouseLeave(object sender, EventArgs e)
+ => btnMax.BackColor = ShiftSkinData.BtnMaxColor;
- private void maximizebutton_MouseLeave(object sender, EventArgs e)
- => btnMax.BackColor = ShiftSkinData.btnMaxColor;
+ void minimizebutton_MouseEnter(object sender, EventArgs e)
+ => btnMin.BackColor = ShiftSkinData.BtnMinHoverColor;
- private void minimizebutton_MouseEnter(object sender, EventArgs e)
- => btnMin.BackColor = ShiftSkinData.btnMinHoverColor;
-
- private void minimizebutton_MouseLeave(object sender, EventArgs e)
- => btnMin.BackColor = ShiftSkinData.btnMinColor;
+ void minimizebutton_MouseLeave(object sender, EventArgs e)
+ => btnMin.BackColor = ShiftSkinData.BtnMinColor;
- /*
+ /*
private void closebutton_MouseDown(object sender, MouseEventArgs e)
=> btnClose.BackColor = Color.Black;
@@ -77,12 +79,11 @@ namespace ShiftOS.Engine.WindowManager
private void minimizebutton_MouseDown(object sender, MouseEventArgs e)
=> btnMin.BackColor = Color.Black;
- */
-
+ */
}
public interface IShiftWindowExtensions
{
void OnLoaded(ShiftWindow window);
}
-}
+} \ No newline at end of file
diff --git a/ShiftOS.Engine/packages.config b/ShiftOS.Engine/packages.config
index ee51c23..a96650b 100644
--- a/ShiftOS.Engine/packages.config
+++ b/ShiftOS.Engine/packages.config
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
+
<packages>
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net45" />
</packages> \ No newline at end of file