Skip to content

Commit

Permalink
fixed some shtuff
Browse files Browse the repository at this point in the history
  • Loading branch information
terminal-cs committed May 31, 2022
1 parent ab25e8f commit 05947ba
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 65 deletions.
3 changes: 1 addition & 2 deletions PrismOS/Kernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 7 additions & 9 deletions PrismOS/Libraries/Graphics/GUI/Button.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
11 changes: 4 additions & 7 deletions PrismOS/Libraries/Graphics/GUI/Clock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion PrismOS/Libraries/Graphics/GUI/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
5 changes: 1 addition & 4 deletions PrismOS/Libraries/Graphics/GUI/Label.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
5 changes: 1 addition & 4 deletions PrismOS/Libraries/Graphics/GUI/Panel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
29 changes: 15 additions & 14 deletions PrismOS/Libraries/Graphics/GUI/Textbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
6 changes: 2 additions & 4 deletions PrismOS/Libraries/Graphics/GUI/Window.cs
Original file line number Diff line number Diff line change
@@ -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<Element> 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)
{
Expand Down
43 changes: 29 additions & 14 deletions PrismOS/Libraries/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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;
}
}
}
}
5 changes: 5 additions & 0 deletions PrismOS/PrismOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
<None Remove="Files\Cursor.bmp" />
<None Remove="Files\Logo.bmp" />
<None Remove="Files\Wallpaper.bmp" />
<None Remove="Text\Terminal.txt" />
</ItemGroup>

<ItemGroup>
<Compile Include="Text\Terminal.txt" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Collections.Generic;
using PrismOS.Libraries;

namespace PrismOS.Libraries.Applications
namespace PrismOS.Text
{
public class Terminal : Runtime.Application
{
Expand All @@ -14,7 +14,7 @@ public class Command
public string Usage { get; set; }
public string Permission { get; set; }
public System.Action<object> Target { get; set; }
}
}
public List<Command> Commands;
public Button Button1 = new();
public Window Window = new();
Expand All @@ -32,23 +32,23 @@ public override void OnCreate()
Description = "Clear the console",
Permission = "User",
Usage = "[ Empty ]",
Target = (object Arguments) => { Label1.Text += "> "; },
Target = (Arguments) => { Label1.Text += "> "; },
},
new()
{
Name = "time",
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()
{
Name = "echo",
Description = "Echo some text back",
Permission = "User",
Usage = "[ Empty ]",
Target = (object Args) => { Label1.Text += Args + "\n"; },
Target = (Args) => { Label1.Text += Args + "\n"; },
},
};

Expand Down Expand Up @@ -112,7 +112,7 @@ public override void OnUpdate()
Label1.Text += Temp[I] + '\n';
}
}

if (Cosmos.System.KeyboardManager.TryReadKey(out var Key))
{
switch (Key.Key)
Expand Down

0 comments on commit 05947ba

Please sign in to comment.