From 15b3b356b0b7be41bd7d975528c46b30c3558988 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 3 Jul 2017 15:41:35 -0400 Subject: I fixed and broke stuff at the same time! --- ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs | 32 ++++++++++--------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'ShiftOS.Frontend/GraphicsSubsystem') diff --git a/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs b/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs index 372c5a6..97ad52d 100644 --- a/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs +++ b/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs @@ -21,7 +21,7 @@ namespace ShiftOS.Frontend.GraphicsSubsystem public static void LayoutUpdate() { - foreach (var toplevel in topLevels) + foreach (var toplevel in topLevels.ToArray()) toplevel.Layout(); } @@ -40,32 +40,26 @@ namespace ShiftOS.Frontend.GraphicsSubsystem t.Start(); } + public static Dictionary TextureCaches = new Dictionary(); public static void DrawControls(GraphicsDevice graphics, SpriteBatch batch) { foreach (var ctrl in topLevels.ToArray()) { - using(var bmp = new System.Drawing.Bitmap(ctrl.Width, ctrl.Height)) + int hc = ctrl.GetHashCode(); + if (ctrl.RequiresPaint) { - var gfx = System.Drawing.Graphics.FromImage(bmp); - ctrl.Paint(gfx); - bmp.SetOpacity((float)ctrl.Opacity); - //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); - for(int i = 0; i < rgb.Length; i+=4) + var bmp = new System.Drawing.Bitmap(ctrl.Width, ctrl.Height); + ctrl.Paint(System.Drawing.Graphics.FromImage(bmp)); + if (TextureCaches.ContainsKey(hc)) { - byte r = rgb[i]; - byte b = rgb[i + 2]; - rgb[i] = b; - rgb[i + 2] = r; + TextureCaches[hc].Dispose(); + TextureCaches.Remove(hc); } - 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); + TextureCaches.Add(hc, new Texture2D(graphics, ctrl.Width, ctrl.Height)); + TextureCaches[hc].SetData(ctrl.PaintCache); } + batch.Draw(TextureCaches[hc], new Rectangle(ctrl.X, ctrl.Y, ctrl.Width, ctrl.Height), Color.White); } } @@ -139,7 +133,7 @@ namespace ShiftOS.Frontend.GraphicsSubsystem { public static char ToCharacter(this Keys key, bool shift) { - char c = ' '; + char c = '\0'; switch (key) { case Keys.Space: -- cgit v1.2.3