From a10440a45c40652b13e883aec832a0c8ded685e8 Mon Sep 17 00:00:00 2001 From: John T Date: Sun, 5 Nov 2017 18:47:46 -0500 Subject: Added a half-complete ShiftFS and did some code cleanup --- ShiftOS.Engine/WindowManager/ShiftWM.cs | 215 ++++++++++++++++---------------- 1 file changed, 109 insertions(+), 106 deletions(-) (limited to 'ShiftOS.Engine/WindowManager/ShiftWM.cs') 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 Windows { get; } = new ObservableCollection(); - public static ShiftWindow GetShiftWindow(this UserControl control) - { - return Windows.First(p => (uint) control.Tag == p.Id); - } - - /// - /// Shows a new ShiftWindow based on a UserControl. - /// - /// The UserControl to use - /// The program's title - /// The icon to show - /// Checks if this is an infobox - /// Enables or disables resizing - /// - 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); + } + + /// + /// Shows a new ShiftWindow based on a UserControl. + /// + /// The UserControl to use + /// The program's title + /// The icon to show + /// Checks if this is an infobox + /// Enables or disables resizing + /// + 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; - } - - /// - /// Shows a new infobox. - /// - /// The title of the infobox. - /// The infobox's content. - /// The ButtonType used for the infobox. - /// - 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; + } + + /// + /// Shows a new infobox. + /// + /// The title of the infobox. + /// The infobox's content. + /// The ButtonType used for the infobox. + /// + 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 -- cgit v1.2.3