diff options
Diffstat (limited to 'ShiftOS.Frontend/GraphicsSubsystem')
| -rw-r--r-- | ShiftOS.Frontend/GraphicsSubsystem/GraphicsContext.cs | 10 | ||||
| -rw-r--r-- | ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs | 47 |
2 files changed, 55 insertions, 2 deletions
diff --git a/ShiftOS.Frontend/GraphicsSubsystem/GraphicsContext.cs b/ShiftOS.Frontend/GraphicsSubsystem/GraphicsContext.cs index 173a024..43292c0 100644 --- a/ShiftOS.Frontend/GraphicsSubsystem/GraphicsContext.cs +++ b/ShiftOS.Frontend/GraphicsSubsystem/GraphicsContext.cs @@ -89,7 +89,7 @@ namespace ShiftOS.Frontend.GraphicsSubsystem public void Clear(Color c) { - DrawRectangle(_startx, _starty, _maxwidth, _maxheight, c); + DrawRectangle(0, 0, _maxwidth, _maxheight, c); } public void DrawLine(int x, int y, int x1, int y1, int thickness, Texture2D tex2) @@ -152,7 +152,13 @@ namespace ShiftOS.Frontend.GraphicsSubsystem { using(var gfx = System.Drawing.Graphics.FromImage(bmp)) { - gfx.DrawString(text, font, new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B)), 0, 0); + var textformat = new System.Drawing.StringFormat(System.Drawing.StringFormat.GenericTypographic); + textformat.FormatFlags = System.Drawing.StringFormatFlags.MeasureTrailingSpaces; + textformat.Trimming = System.Drawing.StringTrimming.None; + textformat.FormatFlags |= System.Drawing.StringFormatFlags.NoClip; + + gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; + gfx.DrawString(text, font, new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B)), 0, 0, textformat); } var lck = bmp.LockBits(new System.Drawing.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]; diff --git a/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs b/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs index bd173d2..12738a8 100644 --- a/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs +++ b/ShiftOS.Frontend/GraphicsSubsystem/UIManager.cs @@ -100,6 +100,14 @@ namespace ShiftOS.Frontend.GraphicsSubsystem ctrl.Layout(); } + public static void InvalidateAll() + { + foreach(var ctrl in topLevels) + { + ctrl.Invalidate(); + } + } + public static void ProcessMouseState(MouseState state) { foreach(var ctrl in topLevels.ToArray()) @@ -110,11 +118,50 @@ namespace ShiftOS.Frontend.GraphicsSubsystem public static void ProcessKeyEvent(KeyEvent e) { + if (e.ControlDown && e.Key == Keys.T) + { + AppearanceManager.SetupWindow(new Apps.Terminal()); + return; + } FocusedControl?.ProcessKeyEvent(e); } private static Texture2D DesktopBackground = null; + public static Dictionary<string, Texture2D> SkinTextures = new Dictionary<string, Texture2D>(); + + public static void ResetSkinTextures(GraphicsDevice graphics) + { + SkinTextures.Clear(); + foreach(var byteArray in SkinEngine.LoadedSkin.GetType().GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).Where(x=>x.FieldType == typeof(byte[]))) + { + var imgAttrib = byteArray.GetCustomAttributes(false).FirstOrDefault(x => x is ImageAttribute) as ImageAttribute; + if(imgAttrib != null) + { + var img = SkinEngine.GetImage(imgAttrib.Name); + if(img != null) + { + var bmp = (System.Drawing.Bitmap)img; + var lck = bmp.LockBits(new System.Drawing.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); + var tex2 = new Texture2D(graphics, bmp.Width, bmp.Height); + 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; + } + tex2.SetData<byte>(data); + SkinTextures.Add(imgAttrib.Name, tex2); + } + } + } + } + + public static Queue<Action> CrossThreadOperations = new Queue<Action>(); public static void DrawBackgroundLayer(GraphicsDevice graphics, SpriteBatch batch, int width, int height) |
