aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Frontend/Desktop
diff options
context:
space:
mode:
Diffstat (limited to 'ShiftOS.Frontend/Desktop')
-rw-r--r--ShiftOS.Frontend/Desktop/Desktop.cs384
-rw-r--r--ShiftOS.Frontend/Desktop/WindowManager.cs480
2 files changed, 864 insertions, 0 deletions
diff --git a/ShiftOS.Frontend/Desktop/Desktop.cs b/ShiftOS.Frontend/Desktop/Desktop.cs
new file mode 100644
index 0000000..85949e2
--- /dev/null
+++ b/ShiftOS.Frontend/Desktop/Desktop.cs
@@ -0,0 +1,384 @@
+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.Apps;
+using ShiftOS.Frontend.GraphicsSubsystem;
+using static ShiftOS.Engine.SkinEngine;
+
+
+namespace ShiftOS.Frontend.Desktop
+{
+ public class Desktop : GUI.Control, IDesktop
+ {
+ bool alOpen = false;
+ int alX = 0;
+ int alY = 0;
+
+ public Desktop()
+ {
+ SaveSystem.GameReady += () =>
+ {
+ Show();
+ SetupDesktop();
+ };
+
+ MouseMove += (loc) =>
+ {
+ if(alOpen == true)
+ {
+ if(loc.X >= alX && loc.Y >= alY)
+ {
+ int height = LauncherItems[0].Height * LauncherItems.Count;
+ int width = LauncherItems[0].Width;
+ if(loc.X <= alX + width && loc.Y <= alY + height)
+ {
+ foreach(var item in LauncherItems)
+ {
+ if(loc.X >= alX && loc.Y >= alY + item.Y && loc.X <= alX + width && loc.Y <= alY + item.Y + item.Height)
+ {
+ alSelectedItem = LauncherItems.IndexOf(item);
+ Invalidate();
+ return;
+ }
+ }
+ }
+ else
+ {
+ alSelectedItem = -1;
+ Invalidate();
+ return;
+ }
+ }
+ }
+ };
+ }
+
+ public string DesktopName
+ {
+ get
+ {
+ return "ShiftOS MonoGame Desktop";
+ }
+ }
+
+ private int alSelectedItem = -1;
+
+ public void Close()
+ {
+ UIManager.StopHandling(this);
+ }
+
+ public Size GetSize()
+ {
+ return UIManager.Viewport;
+ }
+
+ public void HideAppLauncher()
+ {
+ alOpen = false;
+ Invalidate();
+ }
+
+ public void InvokeOnWorkerThread(Action act)
+ {
+ UIManager.CrossThreadOperations.Enqueue(act);
+ }
+
+ public void KillWindow(IWindowBorder border)
+ {
+ }
+
+ public void MaximizeWindow(IWindowBorder brdr)
+ {
+ }
+
+ public void MinimizeWindow(IWindowBorder brdr)
+ {
+ }
+
+ public void OpenAppLauncher(Point loc)
+ {
+ alX = loc.X;
+ alY = loc.Y;
+ alOpen = true;
+ alSelectedItem = -1;
+ Invalidate();
+ }
+
+ public void PopulateAppLauncher(LauncherItem[] items)
+ {
+ int y = 0;
+ int height = 0;
+ int[] widths = new int[items.Length];
+ using(var gfx = System.Drawing.Graphics.FromImage(new System.Drawing.Bitmap(1, 1)))
+ {
+ LauncherItems.Clear();
+ for(int i = 0; i < items.Length; i++)
+ {
+ string name = Localization.Parse(items[i].DisplayData.Name);
+ var measure = gfx.SmartMeasureString(name, LoadedSkin.MainFont);
+ if (height < (int)measure.Height)
+ height = (int)measure.Height;
+ widths[i] = 120 + (int)measure.Width;
+
+ }
+
+ int width = widths.Max();
+
+ foreach(var aitem in items)
+ {
+ var item = new AppLauncherItem
+ {
+ Data = aitem,
+ X = 0,
+ Y = y,
+ Height = height,
+ Width = width
+ };
+ LauncherItems.Add(item);
+ y += item.Height;
+ }
+
+ }
+ Invalidate();
+ }
+
+ public void PopulatePanelButtons()
+ {
+ PanelButtons.Clear();
+ foreach(var win in AppearanceManager.OpenForms)
+ {
+ var border = win as WindowBorder;
+ var pbtn = new PanelButtonData();
+ pbtn.Title = border.Text;
+ pbtn.Window = border;
+ PanelButtons.Add(pbtn);
+ }
+
+ Invalidate();
+ }
+
+ public void PushNotification(string app, string title, string message)
+ {
+ }
+
+ public void RestoreWindow(IWindowBorder brdr)
+ {
+ }
+
+ public void SetupDesktop()
+ {
+ Invalidate();
+ }
+
+ public void Show()
+ {
+ UIManager.AddTopLevel(this);
+ Visible = true;
+ Invalidate();
+ }
+
+ public void ShowWindow(IWindowBorder border)
+ {
+ }
+
+ private string dateTimeString = "";
+
+ protected override void OnLayout()
+ {
+ SendToBack();
+ X = 0;
+ Y = 0;
+ Width = GetSize().Width;
+ Height = GetSize().Height;
+ var now = DateTime.Now.TimeOfDay;
+ var newDateTimeString = $"{now.Hours}:{now.Minutes}:{now.Seconds}";
+ if(newDateTimeString != dateTimeString)
+ {
+ dateTimeString = newDateTimeString;
+ Invalidate();
+ }
+
+ }
+
+ private List<PanelButtonData> PanelButtons = new List<PanelButtonData>();
+ private List<AppLauncherItem> LauncherItems = new List<AppLauncherItem>();
+
+ public override void MouseStateChanged()
+ {
+ //This statement closes the app launcher. If we do this after opening it, we can't open it at all as it instantly closes.
+ if (alOpen == true && MouseLeftDown == true)
+ {
+ if(alSelectedItem != -1)
+ {
+ var item = LauncherItems[alSelectedItem];
+ AppearanceManager.SetupWindow((IShiftOSWindow)Activator.CreateInstance(item.Data.LaunchType, null));
+ }
+ alOpen = false;
+ Invalidate();
+ return;
+ }
+
+
+ var al_left = LoadedSkin.AppLauncherFromLeft;
+ var al_size = LoadedSkin.AppLauncherHolderSize;
+ if(MouseX >= al_left.X && MouseY >= al_left.Y && MouseX <= al_left.X + al_size.Width && MouseY <= al_left.Y + al_size.Height)
+ {
+ if(alOpen == false && MouseLeftDown == true)
+ {
+ alX = 0;
+ if(LoadedSkin.DesktopPanelPosition == 0)
+ {
+ alY = LoadedSkin.DesktopPanelHeight;
+ }
+ else
+ {
+ alY = (Height - LoadedSkin.DesktopPanelHeight) - (LauncherItems[0].Height * LauncherItems.Count);
+ }
+ alOpen = true;
+ Invalidate();
+ }
+
+ }
+
+ }
+
+ protected override void OnPaint(GraphicsContext gfx)
+ {
+ //Let's get data for the desktop panel.
+
+ //We need the width and the height and the position.
+
+ int dp_height = LoadedSkin.DesktopPanelHeight;
+ int dp_position = (LoadedSkin.DesktopPanelPosition == 0) ? 0 : Height - dp_height;
+ int dp_width = Width;
+
+ //Alright, now we need to know if we should draw using a texture or a color
+ if (UIManager.SkinTextures.ContainsKey("desktoppanel"))
+ {
+ //Draw with the texture
+ gfx.DrawRectangle(0, dp_position, dp_width, dp_height, UIManager.SkinTextures["desktoppanel"]);
+ }
+ else
+ {
+ //draw with a color
+ var color = UIManager.SkinTextures["DesktopPanelColor"];
+ gfx.DrawRectangle(0, dp_position, dp_width, dp_height, color);
+ }
+
+ //Alright, now App Launcher.
+ var al_left = LoadedSkin.AppLauncherFromLeft;
+ var holderSize = LoadedSkin.AppLauncherHolderSize;
+ if (UIManager.SkinTextures.ContainsKey("applauncher"))
+ {
+ gfx.DrawRectangle(al_left.X, dp_position + al_left.Y, holderSize.Width, holderSize.Height, UIManager.SkinTextures["applauncher"]);
+ }
+ var altextmeasure = gfx.MeasureString(LoadedSkin.AppLauncherText, LoadedSkin.AppLauncherFont);
+ int altextx = (holderSize.Width - (int)altextmeasure.X) / 2;
+ int altexty = (holderSize.Height - (int)altextmeasure.Y) / 2;
+ gfx.DrawString(LoadedSkin.AppLauncherText, altextx, altexty, LoadedSkin.AppLauncherTextColor.ToMonoColor(), LoadedSkin.AppLauncherFont);
+ //Panel clock.
+
+ var panelClockRight = LoadedSkin.DesktopPanelClockFromRight;
+ var panelClockTextColor = LoadedSkin.DesktopPanelClockColor.ToMonoColor();
+
+
+ var measure = gfx.MeasureString(dateTimeString, LoadedSkin.DesktopPanelClockFont);
+
+ int panelclockleft = Width - (int)measure.X;
+ int panelclockwidth = Width - panelclockleft;
+
+ if (UIManager.SkinTextures.ContainsKey("panelclockbg"))
+ {
+ //draw the background using panelclock texture
+ gfx.DrawRectangle(panelclockleft, dp_position, panelclockwidth, dp_height, UIManager.SkinTextures["panelclockbg"]);
+ }
+ else
+ {
+ //draw using the bg color
+ var pcBGColor = UIManager.SkinTextures["DesktopPanelClockBackgroundColor"];
+ gfx.DrawRectangle(panelclockleft, dp_position, panelclockwidth, dp_height, pcBGColor);
+ }
+
+ int text_left = (panelclockwidth - (int)measure.X) / 2;
+ int text_top = (dp_height - (int)measure.Y) / 2;
+
+ //draw string
+ gfx.DrawString(dateTimeString, panelclockleft + text_left, dp_position + text_top, panelClockTextColor, LoadedSkin.DesktopPanelClockFont);
+
+ int initialGap = LoadedSkin.PanelButtonHolderFromLeft;
+ int offset = initialGap;
+
+ foreach(var pbtn in PanelButtons)
+ {
+ offset += LoadedSkin.PanelButtonFromLeft.X;
+
+ int pbtnfromtop = LoadedSkin.PanelButtonFromTop;
+ int pbtnwidth = LoadedSkin.PanelButtonSize.Width;
+ int pbtnheight = LoadedSkin.PanelButtonSize.Height;
+
+ //Draw panel button background...
+ if (UIManager.SkinTextures.ContainsKey("panelbutton"))
+ {
+ gfx.DrawRectangle(offset, dp_position + pbtnfromtop, pbtnwidth, pbtnheight, UIManager.SkinTextures["panelbutton"]);
+ }
+ else
+ {
+ gfx.DrawRectangle(offset, dp_position + pbtnfromtop, pbtnwidth, pbtnheight, UIManager.SkinTextures["PanelButtonColor"]);
+ }
+
+ //now we draw the text
+
+ gfx.DrawString(pbtn.Title, offset + 2, dp_position + pbtnfromtop + 2, LoadedSkin.PanelButtonTextColor.ToMonoColor(), LoadedSkin.PanelButtonFont);
+
+ offset += LoadedSkin.PanelButtonSize.Width;
+ }
+
+ if (alOpen)
+ {
+ int height = (LauncherItems[0].Height * LauncherItems.Count) + 2;
+ int width = LauncherItems[0].Width + 2;
+ gfx.DrawRectangle(alX, alY, width, height, UIManager.SkinTextures["Menu_MenuBorder"]);
+ gfx.DrawRectangle(alX+1, alY+1, width-2, height-2, UIManager.SkinTextures["Menu_ToolStripDropDownBackground"]);
+ gfx.DrawRectangle(alX+1, alY+1, 18, height-2, UIManager.SkinTextures["Menu_ImageMarginGradientBegin"]);
+
+ foreach(var item in LauncherItems)
+ {
+ if(LauncherItems.IndexOf(item) == alSelectedItem)
+ {
+ gfx.DrawRectangle(alX+1, alY + item.Y+1, item.Width-2, item.Height, UIManager.SkinTextures["Menu_MenuItemSelected"]);
+ }
+ gfx.DrawString(Localization.Parse(item.Data.DisplayData.Name), alX + 21, alY + item.Y+1, LoadedSkin.Menu_TextColor.ToMonoColor(), LoadedSkin.MainFont);
+ }
+ }
+ }
+ }
+
+ public class PanelButtonData
+ {
+ public string Title { get; set; }
+ public WindowBorder Window { get; set; }
+
+ public bool IsActive
+ {
+ get
+ {
+ return Window.IsFocusedControl || Window.ContainsFocusedControl;
+ }
+ }
+ }
+
+
+ public class AppLauncherItem
+ {
+ public Engine.LauncherItem Data { get; set; }
+ public int X { get; set; }
+ public int Y { get; set; }
+ public int Width { get; set; }
+ public int Height { get; set; }
+ }
+}
diff --git a/ShiftOS.Frontend/Desktop/WindowManager.cs b/ShiftOS.Frontend/Desktop/WindowManager.cs
new file mode 100644
index 0000000..22c61bf
--- /dev/null
+++ b/ShiftOS.Frontend/Desktop/WindowManager.cs
@@ -0,0 +1,480 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Drawing;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.Xna.Framework.Graphics;
+using ShiftOS.Engine;
+using ShiftOS.Frontend.GraphicsSubsystem;
+using static ShiftOS.Engine.SkinEngine;
+
+namespace ShiftOS.Frontend.Desktop
+{
+ public class WindowManager : Engine.WindowManager
+ {
+ public override void Close(IShiftOSWindow win)
+ {
+ var brdr = RunningBorders.FirstOrDefault(x => x.ParentWindow == win);
+ if (brdr != null)
+ {
+ brdr.Close();
+ RunningBorders.Remove(brdr);
+ if (AppearanceManager.OpenForms.Contains(brdr))
+ {
+ AppearanceManager.OpenForms.Remove(brdr);
+ TileWindows();
+ Engine.Desktop.ResetPanelButtons();
+ }
+ win = null;
+ }
+ }
+
+ private List<WindowBorder> RunningBorders = new List<WindowBorder>();
+
+ public override void InvokeAction(Action act)
+ {
+ UIManager.CrossThreadOperations.Enqueue(act);
+ }
+
+ public override void Maximize(IWindowBorder border)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override void Minimize(IWindowBorder border)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override void SetTitle(IShiftOSWindow win, string title)
+ {
+ var brdr = RunningBorders.FirstOrDefault(x => x.ParentWindow == win);
+ if (brdr != null)
+ brdr.Text = title;
+ }
+
+ public override void SetupDialog(IShiftOSWindow win)
+ {
+ 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();
+ }
+
+ private int MaxCount
+ {
+ get
+ {
+ if (Shiftorium.UpgradeInstalled("wm_unlimited_windows"))
+ return int.MaxValue;
+ if (Shiftorium.UpgradeInstalled("wm_4_windows"))
+ return 4;
+ if (Shiftorium.UpgradeInstalled("wm_2_windows"))
+ return 2;
+ return 1;
+ }
+ }
+
+ public override void SetupWindow(IShiftOSWindow win)
+ {
+ if (!Shiftorium.UpgradeAttributesUnlocked(win.GetType()))
+ {
+ Console.WriteLine("Application not found on system.");
+ return;
+ }
+ while(AppearanceManager.OpenForms.Count >= MaxCount)
+ {
+ AppearanceManager.OpenForms[0].Close();
+ AppearanceManager.OpenForms.RemoveAt(0);
+ }
+ 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();
+ if (!Shiftorium.UpgradeInstalled("wm_free_placement"))
+ {
+ TileWindows();
+ }
+ }
+
+ public void TileWindows()
+ {
+ if (AppearanceManager.OpenForms.Count == 0)
+ return;
+ else if(AppearanceManager.OpenForms.Count == 1)
+ {
+ var wb = (WindowBorder)AppearanceManager.OpenForms[0];
+ wb.X = 0;
+ wb.Y = 0;
+ wb.ResizeWindow(UIManager.Viewport.Width, UIManager.Viewport.Height);
+ }
+ }
+ }
+
+ public class WindowBorder : GUI.Control, IWindowBorder
+ {
+ private string _text = "ShiftOS window";
+ private GUI.Control _hostedwindow = null;
+
+ public void ResizeWindow(int width, int height)
+ {
+ int titleheight = Shiftorium.UpgradeInstalled("wm_titlebar") ? LoadedSkin.TitlebarHeight : 0;
+ int leftwidth = Shiftorium.UpgradeInstalled("window_borders") ? LoadedSkin.LeftBorderWidth : 0;
+ int bottomheight = Shiftorium.UpgradeInstalled("window_borders") ? LoadedSkin.BottomBorderWidth : 0;
+ int rightwidth = Shiftorium.UpgradeInstalled("window_borders") ? LoadedSkin.RightBorderWidth : 0;
+ _hostedwindow.Width = width - leftwidth - rightwidth;
+ _hostedwindow.Height = height - bottomheight - titleheight;
+ Width = width;
+ Height = height;
+
+ }
+
+ public WindowBorder()
+ {
+ X = 720;
+ Y = 480;
+ MouseDown += () =>
+ {
+ var scnloc = PointToScreen(MouseX, MouseY);
+ mouseprevx = scnloc.X;
+ mouseprevy = scnloc.Y;
+ moving = true;
+ };
+ MouseMove += (loc) =>
+ {
+ if (moving == true)
+ {
+ var scnloc = PointToScreen(MouseX, MouseY);
+ int differencex = scnloc.X - mouseprevx;
+ int differencey = scnloc.Y - mouseprevy;
+ X -= differencex;
+ Y -= differencey;
+ mouseprevx = scnloc.X;
+ mouseprevy = scnloc.Y;
+ }
+ };
+ MouseUp += () =>
+ {
+ moving = false;
+ };
+ }
+
+ private bool moving = false;
+ private int mouseprevx = 0;
+ private int mouseprevy = 0;
+
+
+ public IShiftOSWindow ParentWindow
+ {
+ get
+ {
+ return (IShiftOSWindow)_hostedwindow;
+ }
+
+ set
+ {
+ _hostedwindow = (GUI.Control)value;
+ ClearControls();
+ AddControl(_hostedwindow);
+ Width = LoadedSkin.LeftBorderWidth + _hostedwindow.Width + LoadedSkin.RightBorderWidth;
+ Height = LoadedSkin.BottomBorderWidth + _hostedwindow.Height + LoadedSkin.TitlebarHeight;
+
+ }
+ }
+
+ public bool IsDialog { get; set; }
+
+ public string Text
+ {
+ get
+ {
+ return _text;
+ }
+
+ set
+ {
+ _text = value;
+ }
+ }
+
+ public void Close()
+ {
+ Visible = false;
+ UIManager.StopHandling(this);
+ }
+
+ private int lastmousex, lastmousey = 0;
+
+ protected override void OnLayout()
+ {
+ if (moving)
+ {
+ var screenpoint = PointToScreen(MouseX, MouseY);
+ this.X = lastmousex + screenpoint.X;
+ this.Y = lastmousey + screenpoint.Y;
+ }
+ int titlebarheight = Shiftorium.UpgradeInstalled("wm_titlebar") ? LoadedSkin.TitlebarHeight : 0;
+ int borderleft = Shiftorium.UpgradeInstalled("window_borders") ? LoadedSkin.LeftBorderWidth : 0;
+ int borderright = Shiftorium.UpgradeInstalled("window_borders") ? LoadedSkin.RightBorderWidth : 0;
+ int borderbottom = Shiftorium.UpgradeInstalled("window_borders") ? LoadedSkin.BottomBorderWidth : 0;
+ _hostedwindow.X = borderleft;
+ _hostedwindow.Y = titlebarheight;
+ Width = _hostedwindow.X + _hostedwindow.Width + LoadedSkin.RightBorderWidth;
+ Height = _hostedwindow.Y + _hostedwindow.Height + LoadedSkin.BottomBorderWidth;
+ }
+
+
+
+ protected override void OnPaint(GraphicsContext gfx)
+ {
+ int titleheight = LoadedSkin.TitlebarHeight;
+ int leftborderwidth = LoadedSkin.LeftBorderWidth;
+ int rightborderwidth = LoadedSkin.RightBorderWidth;
+ int bottomborderwidth = LoadedSkin.BottomBorderWidth;
+
+ if (Shiftorium.UpgradeInstalled("wm_titlebar"))
+ {
+ var titlebarcolor = UIManager.SkinTextures["TitleBackgroundColor"];
+ var titlefont = LoadedSkin.TitleFont;
+ var titletextcolor = LoadedSkin.TitleTextColor;
+ var titletextleft = LoadedSkin.TitleTextLeft;
+ bool titletextcentered = LoadedSkin.TitleTextCentered;
+
+ 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.
+ //and the colors
+ var leftcolor = UIManager.SkinTextures["TitleLeftCornerBackground"];
+ var rightcolor = UIManager.SkinTextures["TitleRightCornerBackground"];
+ //and the widths
+ var leftwidth = LoadedSkin.TitleLeftCornerWidth;
+ var rightwidth = LoadedSkin.TitleRightCornerWidth;
+
+ //draw left corner
+ if(UIManager.SkinTextures.ContainsKey("titleleft"))
+ {
+ gfx.DrawRectangle(0, 0, leftwidth, titleheight, UIManager.SkinTextures["titleleft"]);
+ }
+ else
+ {
+ gfx.DrawRectangle(0, 0, leftwidth, titleheight, leftcolor);
+ }
+
+ //draw right corner
+ if (UIManager.SkinTextures.ContainsKey("titleright"))
+ {
+ gfx.DrawRectangle(titlebarleft + titlebarwidth, 0, rightwidth, titleheight, UIManager.SkinTextures["titleright"]);
+ }
+ else
+ {
+ gfx.DrawRectangle(titlebarleft + titlebarwidth, 0, rightwidth, titleheight, rightcolor);
+ }
+ }
+
+ if (!UIManager.SkinTextures.ContainsKey("titlebar"))
+ {
+ //draw the title bg
+ gfx.DrawRectangle(titlebarleft, 0, titlebarwidth, titleheight, titlebarcolor);
+
+ }
+ else
+ {
+ gfx.DrawRectangle(titlebarleft, 0, titlebarwidth, titleheight, UIManager.SkinTextures["titlebar"]);
+ }
+ //Now we draw the title text.
+ var textMeasure = gfx.MeasureString(Text, titlefont);
+ PointF textloc;
+ if (titletextcentered)
+ textloc = new PointF((titlebarwidth - textMeasure.X) / 2,
+ titletextleft.Y);
+ else
+ textloc = new PointF(titlebarleft + titletextleft.X, titletextleft.Y);
+
+ gfx.DrawString(Text, (int)textloc.X, (int)textloc.Y, titletextcolor.ToMonoColor(), titlefont);
+
+ var tbuttonpos = LoadedSkin.TitleButtonPosition;
+
+ //Draw close button
+ if(Shiftorium.UpgradeInstalled("close_button"))
+ {
+ var closebuttonsize = LoadedSkin.CloseButtonSize;
+ var closebuttonright = LoadedSkin.CloseButtonFromSide;
+ if (LoadedSkin.TitleButtonPosition == 0)
+ closebuttonright = new Point(Width - closebuttonsize.Width - closebuttonright.X, closebuttonright.Y);
+ if (!UIManager.SkinTextures.ContainsKey("closebutton"))
+ {
+ gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, UIManager.SkinTextures["CloseButtonColor"]);
+ }
+ else
+ {
+ gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, UIManager.SkinTextures["closebutton"]);
+ }
+ }
+ //Draw maximize button
+ if (Shiftorium.UpgradeInstalled("maximize_button"))
+ {
+ var closebuttonsize = LoadedSkin.MaximizeButtonSize;
+ var closebuttonright = LoadedSkin.MaximizeButtonFromSide;
+ if (LoadedSkin.TitleButtonPosition == 0)
+ closebuttonright = new Point(Width - closebuttonsize.Width - closebuttonright.X, closebuttonright.Y);
+
+ if (!UIManager.SkinTextures.ContainsKey("maximizebutton"))
+ {
+ gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, UIManager.SkinTextures["MaximizeButtonColor"]);
+ }
+ else
+ {
+ gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, UIManager.SkinTextures["maximizebutton"]);
+ }
+ }
+ //Draw minimize button
+ if (Shiftorium.UpgradeInstalled("minimize_button"))
+ {
+ var closebuttonsize = LoadedSkin.MinimizeButtonSize;
+ var closebuttonright = LoadedSkin.MinimizeButtonFromSide;
+ if (LoadedSkin.TitleButtonPosition == 0)
+ closebuttonright = new Point(Width - closebuttonsize.Width - closebuttonright.X, closebuttonright.Y);
+ if (!UIManager.SkinTextures.ContainsKey("minimizebutton"))
+ {
+ gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, UIManager.SkinTextures["MinimizeButtonColor"]);
+ }
+ else
+ {
+ gfx.DrawRectangle(closebuttonright.X, closebuttonright.Y, closebuttonsize.Width, closebuttonsize.Height, UIManager.SkinTextures["minimizebutton"]);
+ }
+
+ }
+ }
+ else
+ {
+ //Set the titleheight to 0.
+ titleheight = 0;
+
+ }
+
+ if (Shiftorium.UpgradeInstalled("window_borders"))
+ {
+ //Some variables we'll need...
+ int bottomlocy = Height - LoadedSkin.BottomBorderWidth;
+ int bottomlocx = leftborderwidth;
+ int bottomwidth = Width - bottomlocx - rightborderwidth;
+ int brightlocx = Width - rightborderwidth;
+
+ var borderleftcolor = (ContainsFocusedControl || IsFocusedControl) ? UIManager.SkinTextures["BorderLeftBackground"] : UIManager.SkinTextures["BorderInactiveLeftBackground"];
+ var borderrightcolor = (ContainsFocusedControl || IsFocusedControl) ? UIManager.SkinTextures["BorderRightBackground"] : UIManager.SkinTextures["BorderInactiveRightBackground"];
+ var borderbottomcolor = (ContainsFocusedControl || IsFocusedControl) ? UIManager.SkinTextures["BorderBottomBackground"] : UIManager.SkinTextures["BorderInactiveBottomBackground"];
+ var borderbleftcolor = (ContainsFocusedControl || IsFocusedControl) ? UIManager.SkinTextures["BorderBottomLeftBackground"] : UIManager.SkinTextures["BorderInactiveBottomLeftBackground"];
+ var borderbrightcolor = (ContainsFocusedControl || IsFocusedControl) ? UIManager.SkinTextures["BorderBottomRightBackground"] : UIManager.SkinTextures["BorderInactiveBottomRightBackground"];
+
+
+ //draw border corners
+ //BOTTOM LEFT
+ if (!UIManager.SkinTextures.ContainsKey("bottomlborder"))
+ {
+ gfx.DrawRectangle(0, bottomlocy, leftborderwidth, bottomborderwidth, borderbleftcolor);
+ }
+ else
+ {
+ gfx.DrawRectangle(0, bottomlocy, leftborderwidth, bottomborderwidth, UIManager.SkinTextures["bottomlborder"]);
+ }
+
+ //BOTTOM RIGHT
+ if (!UIManager.SkinTextures.ContainsKey("bottomrborder"))
+ {
+ gfx.DrawRectangle(brightlocx, bottomlocy, rightborderwidth, bottomborderwidth, borderbrightcolor);
+ }
+ else
+ {
+ gfx.DrawRectangle(brightlocx, bottomlocy, rightborderwidth, bottomborderwidth, UIManager.SkinTextures["bottomrborder"]);
+ }
+
+ //BOTTOM
+ if (!UIManager.SkinTextures.ContainsKey("bottomborder"))
+ {
+ gfx.DrawRectangle(leftborderwidth, bottomlocy, bottomwidth, bottomborderwidth, borderbottomcolor);
+ }
+ else
+ {
+ gfx.DrawRectangle(leftborderwidth, bottomlocy, bottomwidth, bottomborderwidth, UIManager.SkinTextures["bottomborder"]);
+ }
+
+ //LEFT
+ if (!UIManager.SkinTextures.ContainsKey("leftborder"))
+ {
+ gfx.DrawRectangle(0, titleheight, leftborderwidth, Height - titleheight - bottomborderwidth, borderleftcolor);
+ }
+ else
+ {
+ gfx.DrawRectangle(0, titleheight, leftborderwidth, Height - titleheight - bottomborderwidth, UIManager.SkinTextures["leftborder"]);
+ }
+
+ //RIGHT
+ if (!UIManager.SkinTextures.ContainsKey("rightborder"))
+ {
+ gfx.DrawRectangle(brightlocx, titleheight, rightborderwidth, Height - titleheight - bottomborderwidth, borderrightcolor);
+ }
+ else
+ {
+ gfx.DrawRectangle(brightlocx, titleheight, rightborderwidth, Height - titleheight - bottomborderwidth, UIManager.SkinTextures["rightborder"]);
+ }
+
+ }
+
+ gfx.DrawRectangle(leftborderwidth, titleheight, Width - leftborderwidth - rightborderwidth, Height - titleheight - bottomborderwidth, UIManager.SkinTextures["ControlColor"]);
+ //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.
+
+ //Painting of the canvas is done by the Paint() method.
+ }
+
+ }
+
+ public static class ImageExtensioons
+ {
+ public static Texture2D ToTexture2D(this Image image, GraphicsDevice device)
+ {
+ var bmp = (Bitmap)image;
+ var lck = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
+ var data = new byte[Math.Abs(lck.Stride) * lck.Height];
+ Marshal.Copy(lck.Scan0, data, 0, data.Length);
+ bmp.UnlockBits(lck);
+ for(int i = 0; i < data.Length; i += 4)
+ {
+ byte r = data[i];
+ byte b = data[i + 2];
+ data[i] = b;
+ data[i + 2] = r;
+ }
+ var tex2 = new Texture2D(device, bmp.Width, bmp.Height);
+ tex2.SetData<byte>(data);
+ return tex2;
+ }
+ }
+}