From 98b393e40716716476caec2beb81a1398cc98047 Mon Sep 17 00:00:00 2001 From: Evan Lawrence Date: Fri, 13 May 2022 23:43:34 -0700 Subject: [PATCH] add settings app and attempt to fix backspace for textboxes --- PrismOS/Kernel.cs | 125 +++++++++++++++--- .../Graphics/GUI/Elements/Textbox.cs | 2 +- 2 files changed, 105 insertions(+), 22 deletions(-) diff --git a/PrismOS/Kernel.cs b/PrismOS/Kernel.cs index 05f3cdf9..42dc673b 100644 --- a/PrismOS/Kernel.cs +++ b/PrismOS/Kernel.cs @@ -27,37 +27,61 @@ public unsafe class Kernel : Cosmos.System.Kernel { WM = new(); - Window TaskBar = new() + Window Settings = new() { - X = (Canvas.Width / 2) - ((Canvas.Width - 256) / 2), - Y = Canvas.Height - 64, - Width = Canvas.Width - 256, - Height = 32, + X = 200, + Y = 200, + Width = 400, + Height = 150, Radius = GlobalRadius, - Draggable = false, - TitleVisible = false, - Text = "System.Core.TaskBar", + Text = "Settings", + Visible = false, Elements = new() { + // Close button new Button() { - X = 0, - Y = 0, + X = 400 - 15, + Y = -15, + Width = 15, + Height = 15, + Radius = GlobalRadius, + Text = "X", + OnClick = (ref Element E, ref Window Parent) => + { + Parent.Visible = false; + }, + }, + + new Textbox() + { + X = 200 - 64, + Y = 75 - 8, Width = 128, - Height = 32, - Text = "Apps", + Height = 16, Radius = GlobalRadius, + }, + new Button() // 1080p + { + X = 200 - 64, + Y = 75 + 8, + Width = 128, + Height = 16, + Radius = GlobalRadius, + Text = "Set resolution", OnClick = (ref Element E, ref Window Parent) => { - WM.Windows[1].Visible = !WM.Windows[1].Visible; + string[] Data = ((Textbox)Parent.Elements[0]).Text.Split('x'); + Canvas.VBE.DisableDisplay(); + Canvas = new(int.Parse(Data[0]), int.Parse(Data[1])); }, - } + }, }, }; Window AppMenu = new() { - X = (Canvas.Width / 2) - 256, - Y = (Canvas.Height / 2) - 256, + X = 200, + Y = 200, Width = 512, Height = 256, Radius = GlobalRadius, @@ -82,9 +106,10 @@ public unsafe class Kernel : Cosmos.System.Kernel new Button() { - X = 15, Y = 15, - Width = 50, - Height = 15, + X = 15, + Y = 15, + Width = 128, + Height = 20, Radius = GlobalRadius, Text = "Clock", OnClick = (ref Element E, ref Window Parent) => @@ -92,15 +117,57 @@ public unsafe class Kernel : Cosmos.System.Kernel WM.ShowMessage("Error", "Application not implementeed yet!", "Ok"); }, }, + new Button() + { + X = 128 + 20, + Y = 15, + Width = 128, + Height = 20, + Radius = GlobalRadius, + Text = "Settings", + OnClick = (ref Element E, ref Window Parent) => + { + WM.Windows[WM.Windows.IndexOf(Settings)].Visible = !WM.Windows[WM.Windows.IndexOf(Settings)].Visible; + }, + }, + }, + }; + Window TaskBar = new() + { + X = (Canvas.Width / 2) - 256, + Y = Canvas.Height - 64, + Width = 512, + Height = 32, + Radius = GlobalRadius, + Draggable = false, + TitleVisible = false, + Text = "System.Core.TaskBar", + Elements = new() + { + new Button() + { + X = 0, + Y = 0, + Width = 128, + Height = 32, + Text = "Apps", + Radius = GlobalRadius, + OnClick = (ref Element E, ref Window Parent) => + { + WM.Windows[WM.Windows.IndexOf(AppMenu)].Visible = !WM.Windows[WM.Windows.IndexOf(AppMenu)].Visible; + }, + } }, }; WM.Windows.Add(TaskBar); WM.Windows.Add(AppMenu); + WM.Windows.Add(Settings); + WM.ShowMessage("Help screen", "Hello! Welcome to the prism desktop.\nPress +/- to set global radius. Press enter to restart the desktop.\n", "Ok"); }, "Starting desktop..."), (() => { Booting = false; }, "Updating boot status..."), }; - public const int GlobalRadius = 6; + public static int GlobalRadius = 6; public static WindowManager WM; public static CosmosVFS VFS; public static DnsClient DNS; @@ -123,7 +190,23 @@ protected override void Run() { try { - Canvas.DrawString(15, 15, $"FPS: {Canvas.FPS}\nFree Memmory: {Cosmos.Core.GCImplementation.GetAvailableRAM()} MB", Color.Black); + if (KeyboardManager.TryReadKey(out var Key)) + { + switch (Key.Key) + { + case ConsoleKeyEx.NumPlus: + GlobalRadius++; + break; + case ConsoleKeyEx.NumMinus: + GlobalRadius = GlobalRadius == 0 ? 0 : GlobalRadius - 1; + break; + case ConsoleKeyEx.Enter: + Cosmos.Core.GCImplementation.Free(WM); + BootTasks[^2].Item1.Invoke(); + break; + } + } + Canvas.DrawString(15, 15, $"FPS: {Canvas.FPS}\nFree Memmory: {Cosmos.Core.GCImplementation.GetAvailableRAM()} MB\nGlobal radius: " + GlobalRadius, Color.Black); WM.Update(Canvas); Canvas.Update(true); } diff --git a/PrismOS/Libraries/Graphics/GUI/Elements/Textbox.cs b/PrismOS/Libraries/Graphics/GUI/Elements/Textbox.cs index 8296bc95..9e9c5bfa 100644 --- a/PrismOS/Libraries/Graphics/GUI/Elements/Textbox.cs +++ b/PrismOS/Libraries/Graphics/GUI/Elements/Textbox.cs @@ -13,7 +13,7 @@ public override void Update(Canvas Canvas, WindowManager.Window Parent) { if (Key.Key == Cosmos.System.ConsoleKeyEx.Backspace) { - Text.Remove(Text.Length); + Text.Remove(Text.Length - 1); } else {