diff --git a/PrismOS/Kernel.cs b/PrismOS/Kernel.cs index 268c3898..ba6ff798 100644 --- a/PrismOS/Kernel.cs +++ b/PrismOS/Kernel.cs @@ -17,8 +17,7 @@ public unsafe class Kernel : Cosmos.System.Kernel (() => { VFS.Initialize(true); }, "Initilizing VFS..."), (() => { VFSManager.RegisterVFS(VFS); }, "Registering VFS..."), (() => { new DHCPClient().SendDiscoverPacket(); DNS = new(); }, "Starting network services..."), - (() => { _ = new Libraries.Applications.Terminal(); }, "Creating terminal..."), - (() => { _ = new Libraries.Applications.AppTemplate1(); }, "Creating f..."), + (() => { _ = new Libraries.Applications.AppTemplate1(); }, "Creating app..."), }; public static CosmosVFS VFS = new(); public static DnsClient DNS = new(); diff --git a/PrismOS/Libraries/Graphics/GUI/Button.cs b/PrismOS/Libraries/Graphics/GUI/Button.cs index d9ec8a94..a934fef3 100644 --- a/PrismOS/Libraries/Graphics/GUI/Button.cs +++ b/PrismOS/Libraries/Graphics/GUI/Button.cs @@ -6,17 +6,15 @@ public class Button : Element public override void Update(Canvas Canvas, Window Parent) { - if (Visible && Parent.Visible && Theme != null) - { - Color BG = Clicked ? Theme.BackgroundClick : Hovering ? Theme.BackgroundHover : Theme.Background; - Color FG = Clicked ? Theme.ForegroundClick : Hovering ? Theme.ForegroundHover : Theme.Foreground; + Color BG = Clicked ? Theme.BackgroundClick : Hovering ? Theme.BackgroundHover : Theme.Background; + Color FG = Clicked ? Theme.ForegroundClick : Hovering ? Theme.ForegroundHover : Theme.Foreground; - int SX = Parent.X + X + ((Width / 2) - Text.Length * Canvas.Font.Default.Width / 2); - int SY = Parent.Y + Y + ((Height / 2) - (Text.Split('\n').Length * Canvas.Font.Default.Height / 2)); + int SX = Parent.X + X + ((Width / 2) - Text.Length * Canvas.Font.Default.Width / 2); + int SY = Parent.Y + Y + ((Height / 2) - (Text.Split('\n').Length * Canvas.Font.Default.Height / 2)); - Canvas.DrawFilledRectangle(Parent.X + X, Parent.Y + Y, Width, Height, Radius, BG); - Canvas.DrawString(SX, SY, Text, FG); - } + Canvas.DrawFilledRectangle(Parent.X + X, Parent.Y + Y, Width, Height, Radius, BG); + Canvas.DrawString(SX, SY, Text, FG); + Canvas.DrawRectangle(Parent.X + X, Parent.Y + Y, Width - 1, Height - 1, Radius, Theme.Foreground); } } } \ No newline at end of file diff --git a/PrismOS/Libraries/Graphics/GUI/Clock.cs b/PrismOS/Libraries/Graphics/GUI/Clock.cs index bb755dea..7fb9b69b 100644 --- a/PrismOS/Libraries/Graphics/GUI/Clock.cs +++ b/PrismOS/Libraries/Graphics/GUI/Clock.cs @@ -8,13 +8,10 @@ public class Clock : Element public override void Update(Canvas Canvas, Window Parent) { - if (Visible && Parent.Visible && Theme != null) - { - Canvas.DrawFilledCircle(Parent.X + X, Parent.Y + Y, Radius, Theme.Background); - Canvas.DrawAngledLine(Parent.X + X, Parent.Y + Y, DateTime.Now.Hour * 30, Radius - 45, Theme.Background); - Canvas.DrawAngledLine(Parent.X + X, Parent.Y + Y, DateTime.Now.Minute * 6, Radius - 25, Theme.Background); - Canvas.DrawAngledLine(Parent.X + X, Parent.Y + Y, DateTime.Now.Second * 6, Radius - 5, Theme.Accent); - } + Canvas.DrawFilledCircle(Parent.X + X, Parent.Y + Y, Radius, Theme.Background); + Canvas.DrawAngledLine(Parent.X + X, Parent.Y + Y, DateTime.Now.Hour * 30, Radius - 45, Theme.Background); + Canvas.DrawAngledLine(Parent.X + X, Parent.Y + Y, DateTime.Now.Minute * 6, Radius - 25, Theme.Background); + Canvas.DrawAngledLine(Parent.X + X, Parent.Y + Y, DateTime.Now.Second * 6, Radius - 5, Theme.Accent); } } } \ No newline at end of file diff --git a/PrismOS/Libraries/Graphics/GUI/Image.cs b/PrismOS/Libraries/Graphics/GUI/Image.cs index 1f11ce09..3933f0dd 100644 --- a/PrismOS/Libraries/Graphics/GUI/Image.cs +++ b/PrismOS/Libraries/Graphics/GUI/Image.cs @@ -6,7 +6,7 @@ public class Image : Element public override void Update(Canvas Canvas, Window Parent) { - if (Visible && Parent.Visible && Source != null) + if (Source != null) { if (Width == default || Height == default) { diff --git a/PrismOS/Libraries/Graphics/GUI/Label.cs b/PrismOS/Libraries/Graphics/GUI/Label.cs index 2bfcfbf9..c9c5a1e7 100644 --- a/PrismOS/Libraries/Graphics/GUI/Label.cs +++ b/PrismOS/Libraries/Graphics/GUI/Label.cs @@ -7,10 +7,7 @@ public class Label : Element public override void Update(Canvas Canvas, Window Parent) { - if (Visible && Parent.Visible && Theme != null) - { - Canvas.DrawString(Parent.X + X + (Width / 2), Parent.Y + Y + (Height / 2), Text, Theme.Foreground, Underline, Crossout, Center); - } + Canvas.DrawString(Parent.X + X + (Width / 2), Parent.Y + Y + (Height / 2), Text, Theme.Foreground, Underline, Crossout, Center); } } } \ No newline at end of file diff --git a/PrismOS/Libraries/Graphics/GUI/Panel.cs b/PrismOS/Libraries/Graphics/GUI/Panel.cs index fc6def6c..11b7c19a 100644 --- a/PrismOS/Libraries/Graphics/GUI/Panel.cs +++ b/PrismOS/Libraries/Graphics/GUI/Panel.cs @@ -4,10 +4,7 @@ public class Panel : Element { public override void Update(Canvas Canvas, Window Parent) { - if (Visible && Parent.Visible && Theme != null) - { - Canvas.DrawFilledRectangle(Parent.X + X, Parent.Y + Y, Width, Height, Radius, Theme.Background); - } + Canvas.DrawFilledRectangle(Parent.X + X, Parent.Y + Y, Width, Height, Radius, Theme.Background); } } } \ No newline at end of file diff --git a/PrismOS/Libraries/Graphics/GUI/Textbox.cs b/PrismOS/Libraries/Graphics/GUI/Textbox.cs index 33b64536..91a1f25a 100644 --- a/PrismOS/Libraries/Graphics/GUI/Textbox.cs +++ b/PrismOS/Libraries/Graphics/GUI/Textbox.cs @@ -7,27 +7,28 @@ public class Textbox : Element public override void Update(Canvas Canvas, Window Parent) { - if (Visible && Parent.Visible && Theme != null) + if (Parent == Runtime.Windows[^1] && Cosmos.System.KeyboardManager.TryReadKey(out var Key)) { - if (Text.Length == 0 && Hint.Length != 0) + if (Key.Key == Cosmos.System.ConsoleKeyEx.Backspace) { - Canvas.DrawString(Parent.X + X, Parent.Y + Y, Hint, Theme.ForegroundHint); + Text = Text[0..(Text.Length - 1)]; } - if (Cosmos.System.KeyboardManager.TryReadKey(out var Key)) + else { - if (Key.Key == Cosmos.System.ConsoleKeyEx.Backspace) - { - Text = Text[0..(Text.Length - 1)]; - } - else - { - Text += Key.KeyChar; - } + Text += Key.KeyChar; } + } - Canvas.DrawFilledRectangle(Parent.X + X, Parent.Y + Y, Width, Height, Radius, Theme.Background); - Canvas.DrawString(Parent.X + X, Parent.Y + Y, Text, Theme.Background); + Canvas.DrawFilledRectangle(Parent.X + X, Parent.Y + Y, Width, Height, Radius, Theme.Background); + if (Text.Length == 0 && Hint.Length != 0) + { + Canvas.DrawString(Parent.X + X + (Width / 2), Parent.Y + Y + (Height / 2), Hint, Theme.ForegroundHint, true); + } + else + { + Canvas.DrawString(Parent.X + X + (Width / 2), Parent.Y + Y + (Height / 2), Text, Theme.Foreground, true); } + Canvas.DrawRectangle(Parent.X + X, Parent.Y + Y, Width, Height, Radius, Theme.Foreground); } } } \ No newline at end of file diff --git a/PrismOS/Libraries/Graphics/GUI/Window.cs b/PrismOS/Libraries/Graphics/GUI/Window.cs index 9171dc54..ef609d79 100644 --- a/PrismOS/Libraries/Graphics/GUI/Window.cs +++ b/PrismOS/Libraries/Graphics/GUI/Window.cs @@ -1,16 +1,14 @@ -using Mouse = Cosmos.System.MouseManager; -using System.Collections.Generic; +using System.Collections.Generic; namespace PrismOS.Libraries.Graphics.GUI { public class Window { - public int X, Y, Width, Height, Radius; + public int X, Y, Width, Height, Radius, IX, IY; public List Elements = new(); public bool Visible = true, Draggable = true, TitleVisible = true, Moving; public Theme Theme; public string Text; - public int IX, IY; public void Update(Canvas Canvas) { diff --git a/PrismOS/Libraries/Runtime.cs b/PrismOS/Libraries/Runtime.cs index 970760b6..081397a2 100644 --- a/PrismOS/Libraries/Runtime.cs +++ b/PrismOS/Libraries/Runtime.cs @@ -40,33 +40,43 @@ public static void Update() Window.Y = (int)Mouse.Y - Window.IY; } } + + Window.Update(Canvas.Current); foreach (Element E in Window.Elements) { #region Calculations E.OnUpdate.Invoke(); - - if (IsMouseWithin(Window.X+E.X, Window.Y+E.Y, E.Width, E.Height)) { - E.Hovering=true; - if (Cosmos.System.MouseManager.MouseState==Cosmos.System.MouseState.Left) { - E.Clicked=true; - } else { - if (E.Clicked) { - E.Clicked=false; + + if (IsMouseWithin(Window.X + E.X, Window.Y + E.Y, E.Width, E.Height) && Window == Windows[^1]) + { + E.Hovering = true; + if (Mouse.MouseState == Cosmos.System.MouseState.Left) + { + E.Clicked = true; + } + else + { + if (E.Clicked) + { + E.Clicked = false; E.OnClick(); } } - } else { - E.Hovering=false; + } + else + { + E.Hovering = false; } #endregion - E.Update(Canvas.Current, Window); + if (Window.Visible && E.Visible) + { + E.Update(Canvas.Current, Window); + } } - - Window.Update(Canvas.Current); } } @@ -106,5 +116,10 @@ public static void Stop() } Cosmos.System.Power.Shutdown(); } + + public static bool IsMouseWithin(int X, int Y, int Width, int Height) + { + return Mouse.X >= X && Mouse.X <= X + Width && Mouse.Y >= Y && Mouse.Y <= Y + Height; + } } -} +} \ No newline at end of file diff --git a/PrismOS/PrismOS.csproj b/PrismOS/PrismOS.csproj index 08bae7cb..a016831a 100644 --- a/PrismOS/PrismOS.csproj +++ b/PrismOS/PrismOS.csproj @@ -34,6 +34,11 @@ + + + + + diff --git a/PrismOS/Libraries/Applications/Terminal.cs b/PrismOS/Text/Terminal.txt similarity index 93% rename from PrismOS/Libraries/Applications/Terminal.cs rename to PrismOS/Text/Terminal.txt index 4b3b54a3..3ede836e 100644 --- a/PrismOS/Libraries/Applications/Terminal.cs +++ b/PrismOS/Text/Terminal.txt @@ -3,7 +3,7 @@ using System.Collections.Generic; using PrismOS.Libraries; -namespace PrismOS.Libraries.Applications +namespace PrismOS.Text { public class Terminal : Runtime.Application { @@ -14,7 +14,7 @@ public class Command public string Usage { get; set; } public string Permission { get; set; } public System.Action Target { get; set; } - } + } public List Commands; public Button Button1 = new(); public Window Window = new(); @@ -32,7 +32,7 @@ public override void OnCreate() Description = "Clear the console", Permission = "User", Usage = "[ Empty ]", - Target = (object Arguments) => { Label1.Text += "> "; }, + Target = (Arguments) => { Label1.Text += "> "; }, }, new() { @@ -40,7 +40,7 @@ public override void OnCreate() Description = "Get the current time", Permission = "User", Usage = "[ Empty ]", - Target = (object Arguments) => { Label1.Text += System.DateTime.Now.ToString("M/d/yyyy, h:mm t UTC+z") + "\n"; } + Target = (Arguments) => { Label1.Text += System.DateTime.Now.ToString("M/d/yyyy, h:mm t UTC+z") + "\n"; } }, new() { @@ -48,7 +48,7 @@ public override void OnCreate() Description = "Echo some text back", Permission = "User", Usage = "[ Empty ]", - Target = (object Args) => { Label1.Text += Args + "\n"; }, + Target = (Args) => { Label1.Text += Args + "\n"; }, }, }; @@ -112,7 +112,7 @@ public override void OnUpdate() Label1.Text += Temp[I] + '\n'; } } - + if (Cosmos.System.KeyboardManager.TryReadKey(out var Key)) { switch (Key.Key)