diff options
| author | Michael <[email protected]> | 2017-07-03 15:41:35 -0400 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-07-03 15:41:35 -0400 |
| commit | 15b3b356b0b7be41bd7d975528c46b30c3558988 (patch) | |
| tree | 9f10e88a4931351ca9dced6212aba960c5e51a8c /ShiftOS.Frontend/GUI/Control.cs | |
| parent | 659ccfb29d68df8c8ae64501186cdbf4d87c1d52 (diff) | |
| download | shiftos_thereturn-15b3b356b0b7be41bd7d975528c46b30c3558988.tar.gz shiftos_thereturn-15b3b356b0b7be41bd7d975528c46b30c3558988.tar.bz2 shiftos_thereturn-15b3b356b0b7be41bd7d975528c46b30c3558988.zip | |
I fixed and broke stuff at the same time!
Diffstat (limited to 'ShiftOS.Frontend/GUI/Control.cs')
| -rw-r--r-- | ShiftOS.Frontend/GUI/Control.cs | 66 |
1 files changed, 64 insertions, 2 deletions
diff --git a/ShiftOS.Frontend/GUI/Control.cs b/ShiftOS.Frontend/GUI/Control.cs index 90e7ba5..fcd5bf0 100644 --- a/ShiftOS.Frontend/GUI/Control.cs +++ b/ShiftOS.Frontend/GUI/Control.cs @@ -10,6 +10,7 @@ using ShiftOS.Frontend.GraphicsSubsystem; using System.Drawing.Imaging; using System.Drawing.Drawing2D; using Microsoft.Xna.Framework; +using System.Runtime.InteropServices; namespace ShiftOS.Frontend.GUI { @@ -36,6 +37,48 @@ namespace ShiftOS.Frontend.GUI private int _mouseX = 0; private int _mouseY = 0; private bool _captureMouse = false; + + public bool RequiresPaint + { + get + { + bool requires_child_repaint = false; + foreach (var child in _children) + { + requires_child_repaint = child.RequiresPaint; + if (requires_child_repaint) + break; + } + return _invalidated || requires_child_repaint; + } + } + + public Image TextureCache + { + get + { + return _texCache; + } + } + + public byte[] PaintCache + { + get + { + var data = _texCache.LockBits(new System.Drawing.Rectangle(0, 0, Width, Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); + var rgb = new byte[Math.Abs(data.Stride) * data.Height]; + Marshal.Copy(data.Scan0, rgb, 0, rgb.Length); + for(int i = 0; i < rgb.Length; i += 4) + { + byte r = rgb[i]; + byte b = rgb[i + 2]; + rgb[i] = b; + rgb[i + 2] = r; + } + _texCache.UnlockBits(data); + return rgb; + } + } public bool CaptureMouse { @@ -74,6 +117,9 @@ namespace ShiftOS.Frontend.GUI } set { + if (_anchor == value) + return; + _anchor = value; Invalidate(); } @@ -96,6 +142,8 @@ namespace ShiftOS.Frontend.GUI } set { + if (_opacity == value) + return; _opacity = value; Invalidate(); } @@ -164,6 +212,9 @@ namespace ShiftOS.Frontend.GUI } set { + if (_visible == value) + return; + _visible = value; Invalidate(); } @@ -213,6 +264,8 @@ namespace ShiftOS.Frontend.GUI } set { + if (_x == value) + return; _x = value; Invalidate(); } @@ -226,6 +279,8 @@ namespace ShiftOS.Frontend.GUI } set { + if (_y == value) + return; _y = value; Invalidate(); } @@ -239,6 +294,8 @@ namespace ShiftOS.Frontend.GUI } set { + if (_w == value) + return; _w = value; Invalidate(); } @@ -252,6 +309,8 @@ namespace ShiftOS.Frontend.GUI } set { + if (_h == value) + return; _h = value; Invalidate(); } @@ -329,7 +388,6 @@ namespace ShiftOS.Frontend.GUI } _invalidated = false; } - gfx.DrawImage(_texCache, 0, 0); foreach (var child in _children) { if (child.Visible) @@ -339,6 +397,10 @@ namespace ShiftOS.Frontend.GUI var cBmp = new Bitmap(child.Width, child.Height); child.Paint(System.Drawing.Graphics.FromImage(cBmp)); cBmp.SetOpacity((float)child.Opacity); + using(var cGfx = Graphics.FromImage(_texCache)) + { + cGfx.DrawImage(child.TextureCache, child.X, child.Y); + } child._invalidated = false; child._texCache = cBmp; gfx.DrawImage(cBmp, new System.Drawing.Point(child.X, child.Y)); @@ -352,7 +414,7 @@ namespace ShiftOS.Frontend.GUI } } } - + gfx.DrawImage(_texCache, 0, 0); } } |
