From dad09c9e7c1ff68a157836b636f13f25d27e050a Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 2 Jul 2017 13:31:39 -0400 Subject: Render text onscreen --- ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs | 82 +++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs (limited to 'ShiftOS.Frontend/GraphicsSubsystem') diff --git a/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs b/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs new file mode 100644 index 0000000..fdd5f99 --- /dev/null +++ b/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; +using ShiftOS.Engine; +using ShiftOS.Frontend.Desktop; + +namespace ShiftOS.Frontend.GraphicsSubsystem +{ + public static class UIManager + { + private static List topLevels = new List(); + + public static void DrawControls(GraphicsDevice graphics, SpriteBatch batch) + { + foreach (var ctrl in topLevels) + { + using(var bmp = new System.Drawing.Bitmap(ctrl.Width, ctrl.Height)) + { + var gfx = System.Drawing.Graphics.FromImage(bmp); + ctrl.Paint(gfx); + //get the bits of the bitmap + var data = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); + byte[] rgb = new byte[Math.Abs(data.Stride) * data.Height]; + Marshal.Copy(data.Scan0, rgb, 0, rgb.Length); + bmp.UnlockBits(data); + var tex2 = new Texture2D(graphics, bmp.Width, bmp.Height); + tex2.SetData(rgb); + batch.Draw(tex2, new Rectangle(ctrl.X, ctrl.Y, ctrl.Width, ctrl.Height), Color.White); + } + } + } + + public static void AddTopLevel(GUI.Control ctrl) + { + if (!topLevels.Contains(ctrl)) + topLevels.Add(ctrl); + } + + public static void ProcessMouseState(MouseState state) + { + foreach(var ctrl in topLevels) + { + if (ctrl.ProcessMouseState(state) == true) + break; + } + } + + + + public static void DrawBackgroundLayer(GraphicsDevice graphics, SpriteBatch batch, int width, int height) + { + if (SkinEngine.LoadedSkin == null) + SkinEngine.Init(); + graphics.Clear(SkinEngine.LoadedSkin.DesktopColor.ToMonoColor()); + var desktopbg = SkinEngine.GetImage("desktopbackground"); + if(desktopbg != null) + { + var tex2 = new Texture2D(graphics, desktopbg.Width, desktopbg.Height); + tex2.SetData(SkinEngine.LoadedSkin.DesktopBackgroundImage); + batch.Draw(tex2, new Rectangle(0, 0, width, height), Color.White); + } + } + + public static Color ToMonoColor(this System.Drawing.Color color) + { + return new Color(color.R, color.G, color.B, color.A); + } + + internal static void StopHandling(GUI.Control ctrl) + { + if (topLevels.Contains(ctrl)) + topLevels.Remove(ctrl); + ctrl = null; + } + } +} -- cgit v1.2.3