From 181f94e70106dce186623d0d35d2646f2cc9dab3 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 5 Jul 2017 10:34:09 -0400 Subject: HEAPS of desktop stuff --- ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs | 33 +++++++++++-------------- 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'ShiftOS.Frontend/GraphicsSubsystem') diff --git a/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs b/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs index 12738a8..ac8c6f2 100644 --- a/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs +++ b/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs @@ -49,12 +49,23 @@ namespace ShiftOS.Frontend.GraphicsSubsystem if (ctrl.Visible == true) { int hc = ctrl.GetHashCode(); + if (!TextureCaches.ContainsKey(hc)) + { + ctrl.Invalidate(); + continue; + } var _target = TextureCaches[hc]; batch.Draw(_target, new Rectangle(ctrl.X, ctrl.Y, ctrl.Width, ctrl.Height), Color.White); } } } + public static void SendToBack(Control ctrl) + { + topLevels.Remove(ctrl); + topLevels.Insert(0, ctrl); + } + public static void DrawControlsToTargets(GraphicsDevice graphics, SpriteBatch batch, int width, int height) { foreach (var ctrl in topLevels.ToArray().Where(x=>x.Visible==true)) @@ -80,9 +91,10 @@ namespace ShiftOS.Frontend.GraphicsSubsystem { graphics.SetRenderTarget(_target); graphics.DepthStencilState = new DepthStencilState() { DepthBufferEnable = true }; - batch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, + batch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone); + graphics.Clear(Color.Transparent); var gfxContext = new GraphicsContext(graphics, batch, 0, 0, _target.Width, _target.Height); ctrl.Paint(gfxContext); @@ -169,24 +181,9 @@ namespace ShiftOS.Frontend.GraphicsSubsystem if (SkinEngine.LoadedSkin == null) SkinEngine.Init(); graphics.Clear(SkinEngine.LoadedSkin.DesktopColor.ToMonoColor()); - var desktopbg = SkinEngine.GetImage("desktopbackground"); - if(desktopbg != null) + if (SkinTextures.ContainsKey("desktopbackground")) { - var bmp = (System.Drawing.Bitmap)SkinEngine.GetImage("desktopbackground"); - GUI.Control.ResizeImage(bmp, width, height); - var _lock = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); - var rgb = new byte[Math.Abs(_lock.Stride) * _lock.Height]; - Marshal.Copy(_lock.Scan0, rgb, 0, rgb.Length); - bmp.UnlockBits(_lock); - bmp.Dispose(); - if(DesktopBackground == null) - { - DesktopBackground = new Texture2D(graphics, width, height); - } - - DesktopBackground.SetData(rgb); - - batch.Draw(DesktopBackground, new Rectangle(0, 0, width, height), Color.White); + batch.Draw(SkinTextures["desktopbackground"], new Rectangle(0, 0, Viewport.Width, Viewport.Height), Color.White); } } -- cgit v1.2.3