From 6f3a5cba2ea08ea6f442e2336b74f32f4bbc0604 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 2 Jul 2017 21:48:10 -0400 Subject: A day's worth of hell... which is turning into heaven. --- ShiftOS.Frontend/Desktop/Desktop.cs | 85 ++++++++++++++ ShiftOS.Frontend/Desktop/WindowManager.cs | 180 +++++++++++++++++++++++++++++- 2 files changed, 259 insertions(+), 6 deletions(-) create mode 100644 ShiftOS.Frontend/Desktop/Desktop.cs (limited to 'ShiftOS.Frontend/Desktop') diff --git a/ShiftOS.Frontend/Desktop/Desktop.cs b/ShiftOS.Frontend/Desktop/Desktop.cs new file mode 100644 index 0000000..5bcf3a9 --- /dev/null +++ b/ShiftOS.Frontend/Desktop/Desktop.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ShiftOS.Engine; + +namespace ShiftOS.Frontend.Desktop +{ + public class Desktop : GUI.Control, IDesktop + { + public string DesktopName + { + get + { + return "ShiftOS MonoGame Desktop"; + } + } + + public void Close() + { + throw new NotImplementedException(); + } + + public Size GetSize() + { + return new Size(Width, Height); + } + + public void HideAppLauncher() + { + + } + + public void InvokeOnWorkerThread(Action act) + { + act?.Invoke(); + } + + public void KillWindow(IWindowBorder border) + { + } + + public void MaximizeWindow(IWindowBorder brdr) + { + } + + public void MinimizeWindow(IWindowBorder brdr) + { + } + + public void OpenAppLauncher(Point loc) + { + } + + public void PopulateAppLauncher(LauncherItem[] items) + { + } + + public void PopulatePanelButtons() + { + } + + public void PushNotification(string app, string title, string message) + { + } + + public void RestoreWindow(IWindowBorder brdr) + { + } + + public void SetupDesktop() + { + } + + public void Show() + { + } + + public void ShowWindow(IWindowBorder border) + { + } + } +} diff --git a/ShiftOS.Frontend/Desktop/WindowManager.cs b/ShiftOS.Frontend/Desktop/WindowManager.cs index d17cd37..2450986 100644 --- a/ShiftOS.Frontend/Desktop/WindowManager.cs +++ b/ShiftOS.Frontend/Desktop/WindowManager.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using ShiftOS.Engine; using ShiftOS.Frontend.GraphicsSubsystem; +using static ShiftOS.Engine.SkinEngine; namespace ShiftOS.Frontend.Desktop { @@ -12,9 +14,16 @@ namespace ShiftOS.Frontend.Desktop { public override void Close(IShiftOSWindow win) { - + var brdr = RunningBorders.FirstOrDefault(x => x.ParentWindow == win); + if (brdr != null) + { + brdr.Close(); + win = null; + } } + private List RunningBorders = new List(); + public override void InvokeAction(Action act) { act?.Invoke(); @@ -32,17 +41,44 @@ namespace ShiftOS.Frontend.Desktop public override void SetTitle(IShiftOSWindow win, string title) { - throw new NotImplementedException(); + var brdr = RunningBorders.FirstOrDefault(x => x.ParentWindow == win); + if (brdr != null) + brdr.Text = title; } public override void SetupDialog(IShiftOSWindow win) { - throw new NotImplementedException(); + var wb = new WindowBorder(); + wb.Width = (win as GUI.Control).Width + LoadedSkin.LeftBorderWidth + LoadedSkin.RightBorderWidth; + wb.Height = (win as GUI.Control).Height + LoadedSkin.TitlebarHeight + LoadedSkin.BottomBorderWidth; + wb.ParentWindow = win; + wb.IsDialog = true; + UIManager.AddTopLevel(wb); + RunningBorders.Add(wb); + win.OnLoad(); + win.OnUpgrade(); + win.OnSkinLoad(); } public override void SetupWindow(IShiftOSWindow win) { - throw new NotImplementedException(); + if (!Shiftorium.UpgradeAttributesUnlocked(win.GetType())) + { + Console.WriteLine("Application not found on system."); + return; + } + var wb = new WindowBorder(); + wb.Width = (win as GUI.Control).Width + LoadedSkin.LeftBorderWidth + LoadedSkin.RightBorderWidth; + wb.Height = (win as GUI.Control).Height + LoadedSkin.TitlebarHeight + LoadedSkin.BottomBorderWidth; + wb.ParentWindow = win; + wb.IsDialog = true; + UIManager.AddTopLevel(wb); + AppearanceManager.OpenForms.Add(wb); + RunningBorders.Add(wb); + win.OnLoad(); + win.OnUpgrade(); + win.OnSkinLoad(); + } } @@ -61,9 +97,13 @@ namespace ShiftOS.Frontend.Desktop set { _hostedwindow = (GUI.Control)value; + ClearControls(); + AddControl(_hostedwindow); } } + public bool IsDialog { get; set; } + public string Text { get @@ -83,10 +123,138 @@ namespace ShiftOS.Frontend.Desktop UIManager.StopHandling(this); } - public override void MouseStateChanged() + public override void Paint(Graphics gfx) { - //todo: close, minimize, maximize, drag, resize + int titleheight = LoadedSkin.TitlebarHeight; + int leftborderwidth = LoadedSkin.LeftBorderWidth; + int rightborderwidth = LoadedSkin.RightBorderWidth; + int bottomborderwidth = LoadedSkin.BottomBorderWidth; + + if (Shiftorium.UpgradeInstalled("wm_titlebar") || true) + { + var titlebarcolor = LoadedSkin.TitleBackgroundColor; + var titlefont = LoadedSkin.TitleFont; + var titletextcolor = LoadedSkin.TitleTextColor; + var titletextleft = LoadedSkin.TitleTextLeft; + bool titletextcentered = LoadedSkin.TitleTextCentered; + + var titlebarbg = GetImage("titlebar"); + var titlebarlayout = GetImageLayout("titlebar"); + + var drawcorners = LoadedSkin.ShowTitleCorners; + int titlebarleft = 0; + int titlebarwidth = Width; + if (drawcorners) + { + //set titleleft to the first corner width + titlebarleft = LoadedSkin.TitleLeftCornerWidth; + titlebarwidth -= titlebarleft; + titlebarwidth -= LoadedSkin.TitleRightCornerWidth; + + //Let's get the left and right images. + var leftimage = GetImage("titlebarleft"); + var rightimage = GetImage("titlebarright"); + //and the colors + var leftcolor = LoadedSkin.TitleLeftCornerBackground; + var rightcolor = LoadedSkin.TitleRightCornerBackground; + //and the layouts... + var leftlayout = GetImageLayout("titlebarleft"); + var rightlayout = GetImageLayout("titlebarright"); + //and the widths + var leftwidth = LoadedSkin.TitleLeftCornerWidth; + var rightwidth = LoadedSkin.TitleRightCornerWidth; + + //draw left corner + if(leftimage != null) + { + var resized = ResizeImage(leftimage, leftwidth, titleheight); + gfx.DrawImage(resized, 0, 0); + } + else + { + gfx.FillRectangle(new SolidBrush(leftcolor), new Rectangle(0, 0, leftwidth, titleheight)); + } + + //draw right corner + if (rightimage != null) + { + var resized = ResizeImage(rightimage, rightwidth, titleheight); + gfx.DrawImage(resized, titlebarleft+titlebarwidth, 0); + } + else + { + gfx.FillRectangle(new SolidBrush(rightcolor), new Rectangle(titlebarleft+titlebarwidth, 0, rightwidth, titleheight)); + } + } + if (titlebarbg == null) + { + //draw the title bg + gfx.FillRectangle(new SolidBrush(titlebarcolor), new Rectangle(titlebarleft, 0, titlebarwidth, titleheight)); + + + } + else + { + var resized = ResizeImage(titlebarbg, titlebarwidth, titleheight); + gfx.DrawImage(resized, titlebarleft, 0); + } + //Now we draw the title text. + var textMeasure = gfx.MeasureString(_text, titlefont); + PointF textloc; + if (titletextcentered) + textloc = new PointF((titlebarwidth - textMeasure.Width) / 2, + titletextleft.Y); + else + textloc = new PointF(titlebarleft + titletextleft.X, titletextleft.Y); + + gfx.DrawString(_text, titlefont, new SolidBrush(titletextcolor), textloc); + + var tbuttonpos = LoadedSkin.TitleButtonPosition; + + //Draw close button + if(Shiftorium.UpgradeInstalled("close_button") || true) + { + var closebuttoncolor = LoadedSkin.CloseButtonColor; + var closebuttonsize = LoadedSkin.CloseButtonSize; + var closebuttonright = LoadedSkin.CloseButtonFromSide; + + gfx.FillRectangle(new SolidBrush(closebuttoncolor), new Rectangle(closebuttonright, closebuttonsize)); + + } + } + else + { + //Set the titleheight to 0. + titleheight = 0; + + } + + //So here's what we're gonna do now. + //Now that we have a titlebar and window borders... + //We're going to composite the hosted window + //and draw it to the remaining area. + + //First let's GET the window. + if(_hostedwindow != null) + { + var win = _hostedwindow; + //Now let's create a new bitmap to draw onto, the same size as the client area. + using(var bmp = new Bitmap(Width, Height - titleheight)) + { + //Now, let's create a graphics object. + using(var cgfx = Graphics.FromImage(bmp)) + { + //And composite... + win.Paint(cgfx); + + } + //Now draw the bitmap to our client area + gfx.DrawImage(bmp, 0, titleheight); + //We now have a full window. + } + } } + } } -- cgit v1.2.3