diff --git a/.gitignore b/.gitignore index babb3119d3..92dd5d2d48 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,12 @@ GoOS/.vs/GoOS/v17/.suo /.idea/ GoOS/.idea/ +/.vs +/GoOS/obj/* +GoOS/obj/Debug/net6.0/GoOS.assets.cache +GoOS/obj/Debug/net6.0/GoOS.csproj.AssemblyReference.cache +GoOS/obj/GoOS.csproj.nuget.dgspec.json +GoOS/obj/GoOS.csproj.nuget.g.props +GoOS/obj/GoOS.csproj.nuget.g.targets +GoOS/obj/project.assets.json +GoOS/obj/project.nuget.cache diff --git a/Art/Screenshot1.png b/Art/Screenshot1.png new file mode 100644 index 0000000000..2f108aa090 Binary files /dev/null and b/Art/Screenshot1.png differ diff --git a/Art/Screenshot2.png b/Art/Screenshot2.png new file mode 100644 index 0000000000..584113cd3c Binary files /dev/null and b/Art/Screenshot2.png differ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cd8b4fa095..9c51072615 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,12 +1,13 @@ +# Contributing All Contributions should be made in the form of a Pull Request -(unless i Owen2k6 have added you as a contributor) +(unless Owen2k6 added you as a collaborator) -Your Pull request will require me to review and approve it before merging into the code. +Your Pull request will require Owen to review and approve it before merging into the code. -Do not mess up anything VS does. keep the directory similar for gods sake! +Do not mess up anything Visual Studio (if you don't use Rider) does. keep the directory similar for god's sake! -Pull Request guidelines: -1. all changes must be presented -2. a video must be attached showing this code working in a VM - ¬ If anything is missed, the PR will be denied. -3. Code must be reviewed by either Owen2k6 or other developers "and Owen2k6" before this PR is merged in fully +## Pull Request guidelines: +- All changes must be presented +- A video must be attached showing this code working in a VM + - If anything is missed, the PR will be denied. +- Code must be reviewed by either Owen2k6 or other developers "and Owen2k6" before this PR is merged in fully. diff --git a/GoOS/9xCode/Interpreter.cs b/GoOS/9xCode/Interpreter.cs new file mode 100644 index 0000000000..87ffd64406 --- /dev/null +++ b/GoOS/9xCode/Interpreter.cs @@ -0,0 +1,976 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using System.Threading; +using GoOS.GUI; +using PrismAPI.Graphics; +using static ConsoleColorEx; +using Console = BetterConsole; +using ConsoleColor = PrismAPI.Graphics.Color; + +// 9xCode Beta 3.1 +// Licensed under the MIT license +// Use permitted in GoOS + +namespace GoOS._9xCode +{ + public static partial class Interpreter + { + public static void Run(string file) + { + if (!File.Exists(file)) + { + HandleError("9xCode", "Script doesn't exist!"); + } + + Console.Title = $"{file.Substring(file.LastIndexOf(@"\")).Replace(".9xc", "")} - 9xCode"; + Console.ForegroundColor = White; + Interpret(File.ReadAllLines(file)); + } + + private static bool Interpreting = false; + + private static void Interpret(string[] code) + { + Interpreting = true; + + Console.ForegroundColor = Cyan; + Console.WriteLine("Mobren 9xCode Interpreter Version b3.1\n"); + Console.ForegroundColor = White; + + bool SysLib = false, ConsoleLib = false, IOLib = false, TimeLib = false, _9xGLLib = false, GoOSLib = false; + + Dictionary Booleans = new Dictionary() { }; + Dictionary Integers = new Dictionary() { }; + Dictionary Strings = new Dictionary() { { "Version", "b3.0" } }; + Dictionary Colors = new Dictionary() { }; + Dictionary Windows = new Dictionary(); + + for (int i = 0; i < code.Length; i++) + { + if (Interpreting) + { + try + { + WindowManager.Update(); // Don't lock the WM + + string line = code[i].Trim().Replace("\\n", "\n"); + + #region Globals + + if (ConsoleLib) + { + if (Colors.ContainsKey("ForeColor")) + { + Colors.Remove("ForeColor"); + } + if (Colors.ContainsKey("BackColor")) + { + Colors.Remove("BackColor"); + } + if (Integers.ContainsKey("CursorX")) + { + Integers.Remove("CursorX"); + } + if (Integers.ContainsKey("CursorY")) + { + Integers.Remove("CursorY"); + } + if (Booleans.ContainsKey("Cursor")) + { + Booleans.Remove("Cursor"); + } + + Colors.Add("ForeColor", Console.ForegroundColor); + Colors.Add("BackColor", Console.BackgroundColor); + Integers.Add("CursorX", Console.CursorLeft); + Integers.Add("CursorY", Console.CursorTop); + Booleans.Add("Cursor", Console.CursorVisible); + } + + if (TimeLib) + { + if (Integers.ContainsKey("Milliseconds")) + { + Integers.Remove("Milliseconds"); + } + if (Integers.ContainsKey("Seconds")) + { + Integers.Remove("Seconds"); + } + if (Integers.ContainsKey("Minutes")) + { + Integers.Remove("Minutes"); + } + if (Integers.ContainsKey("Hours")) + { + Integers.Remove("Hours"); + } + + Integers.Add("Milliseconds", DateTime.Now.Millisecond); + Integers.Add("Seconds", DateTime.Now.Second); + Integers.Add("Minutes", DateTime.Now.Minute); + Integers.Add("Hours", DateTime.Now.Hour); + } + + #endregion + + #region Standard library + + if (line == string.Empty) + { + continue; + } + + if (line.StartsWith(";")) + { + continue; + } + + else if (line.StartsWith("endif")) + { + continue; + } + + if (line.Contains(";")) + { + int start = line.IndexOf(';'); + line = line.Remove(start).Trim(); + } + + if (line.StartsWith("import")) + { + string sub = line.Substring(7); + + if (sub.StartsWith("System")) + { + SysLib = true; + continue; + } + + else if (sub.StartsWith("Console")) + { + ConsoleLib = true; + continue; + } + + else if (sub.StartsWith("IO")) + { + IOLib = true; + continue; + } + + else if (sub.StartsWith("Time")) + { + TimeLib = true; + continue; + } + + else if (sub.StartsWith("9xGL")) + { + _9xGLLib = true; + continue; + } + + else if (sub.StartsWith("GoOS")) + { + GoOSLib = true; + continue; + } + + else + { + HandleError("Error", "Unknown library."); + } + } + + else if (line.StartsWith("Bool")) + { + if (line.Contains('=')) + { + string key = line.Substring(5, line.IndexOf(" =") - 5); + string sub = line.Substring(line.IndexOf("= ") + 2).ToLower(); + + #region Console library + + if (!ConsoleLib) + { + if (key == "Cursor") + { + HandleError("Error", "Console library not imported"); + break; + } + } + + if (ConsoleLib && key == "Cursor") + { + Console.CursorVisible = Convert.ToBoolean(sub); + continue; + } + + #endregion + + if (Booleans.ContainsKey(key)) + { + Booleans.Remove(key); + } + + Booleans.Add(key, Convert.ToBoolean(sub)); + continue; + } + else + { + string key = line.Substring(5); + + if (Booleans.ContainsKey(key)) + { + Booleans.Remove(key); + } + + Booleans.Add(key, false); + continue; + } + } + + else if (line.StartsWith("Color")) + { + if (line.Contains('=')) + { + string key = line.Substring(6, line.IndexOf(" =") - 6); + string sub = line.Substring(line.IndexOf("= ") + 2); + + #region Console library + + if (!ConsoleLib) + { + if (key == "ForeColor" || key == "BackColor") + { + HandleError("Error", "Console library not imported"); + break; + } + } + + if (ConsoleLib && key == "ForeColor") + { + if (StringToConsoleColor.TryGetValue(sub, out ConsoleColor colval1)) + { + Console.ForegroundColor = colval1; + } + continue; + } + + if (ConsoleLib && key == "BackColor") + { + if (StringToConsoleColor.TryGetValue(sub, out ConsoleColor colval2)) + { + Console.BackgroundColor = colval2; + } + continue; + } + + #endregion + + if (Colors.ContainsKey(key)) + { + Colors.Remove(key); + } + + if (StringToConsoleColor.TryGetValue(sub, out ConsoleColor colval3)) + { + Colors.Add(key, colval3); + } + else + { + HandleError("Syntax Error", "Unknown Color."); + } + continue; + } + else + { + string key = line.Substring(6); + + if (Booleans.ContainsKey(key)) + { + Booleans.Remove(key); + } + + Booleans.Add(key, false); + continue; + } + } + + else if (line.StartsWith("Int")) + { + if (line.Contains('=')) + { + string key = line.Substring(4, line.IndexOf(" =") - 4); + string sub = line.Substring(line.IndexOf("= ") + 2); + + if (Integers.ContainsKey(key)) + { + Integers.Remove(key); + } + + #region Console library + + if (!ConsoleLib) + { + if (sub.StartsWith("CursorX") || sub.StartsWith("CursorY")) + { + HandleError("Error", "Console library not imported"); + break; + } + } + + if (ConsoleLib && key == "CursorX") + { + Console.CursorLeft = Convert.ToInt32(sub); + continue; + } + + if (ConsoleLib && key == "CursorY") + { + Console.CursorTop = Convert.ToInt32(sub); + continue; + } + + #endregion + + #region Time library + + if (!TimeLib) + { + if (sub.StartsWith("Seconds") || sub.StartsWith("Minutes") || sub.Equals("Hours")) + { + HandleError("Error", "Time library not imported"); + break; + } + } + + #endregion + + if (TimeLib && sub.StartsWith("Seconds")) + { + Integers.Add(key, DateTime.Now.Second); + } + else if (TimeLib && sub.StartsWith("Minutes")) + { + Integers.Add(key, DateTime.Now.Minute); + } + else if (TimeLib && sub.StartsWith("Hours")) + { + Integers.Add(key, DateTime.Now.Hour); + } + else if (sub.StartsWith("0x")) + { + sub.Remove(0, 2); + Integers.Add(key, Convert.ToInt32(sub, 16)); + } + else + { + Integers.Add(key, Convert.ToInt32(sub)); + } + continue; + } + else if (line.Contains("++")) + { + string key = line.Substring(4, line.IndexOf("++") - 4); + + if (!Integers.TryGetValue(key, out int intval)) + { + HandleError("Error", "Unknown variable."); + break; + } + + if (Integers.ContainsKey(key)) + { + Integers.Remove(key); + } + + Integers.Add(key, intval + 1); + } + else if (line.Contains("--")) + { + string key = line.Substring(4, line.IndexOf("--") - 4); + + if (!Integers.TryGetValue(key, out int intval)) + { + HandleError("Error", "Unknown variable."); + break; + } + + if (Integers.ContainsKey(key)) + { + Integers.Remove(key); + } + + Integers.Add(key, intval - 1); + } + else + { + string key = line.Substring(4); + + if (Integers.ContainsKey(key)) + { + Integers.Remove(key); + } + + Integers.Add(key, 0); + continue; + } + } + + else if (line.StartsWith("String")) + { + if (line.Contains('=')) + { + string key = line.Substring(7, line.IndexOf(" =") - 7); + + if (Strings.ContainsKey(key)) + { + Strings.Remove(key); + } + + if (!IOLib) + { + if (line.Substring(line.IndexOf("= ") + 2).StartsWith("ReadFile")) + { + HandleError("Error", "IO library not imported"); + break; + } + } + + if (IOLib && line.Substring(line.IndexOf("= ") + 2).StartsWith("ReadFile")) + { + string arg = line.Split('>')[2].Trim().Replace("\"", ""); + + if (Strings.TryGetValue(arg.Trim(), out string strval)) + { + arg = strval; + } + + Strings.Add(key, File.ReadAllText(arg)); + } + else if (line.Substring(line.IndexOf("= ") + 2).StartsWith("ReadLine")) + { + Strings.Add(key, Console.ReadLine()); + } + else if (line.Substring(line.IndexOf("= ") + 2).StartsWith("Read")) + { + Strings.Add(key, Console.ReadKey(true).Key.ToString()); + } + else + { + Strings.Add(key, line.Substring(line.IndexOf("\"") + 1, line.LastIndexOf("\"") - (line.IndexOf("\"") + 1))); + } + continue; + } + else + { + string key = line.Substring(7); + + if (Strings.ContainsKey(key)) + { + Strings.Remove(key); + } + + Strings.Add(key, ""); + continue; + } + } + + else if (_9xGLLib && line.StartsWith("Window")) + { + if (line.Contains('=')) + { + string key = line.Substring(7, line.IndexOf(" =") - 7); + + if (Windows.ContainsKey(key)) + { + Windows.Remove(key); + } + + if (_9xGLLib && line.Substring(line.IndexOf("= ") + 2).StartsWith("GetWindow")) + { + string[] args2 = line.Split('>')[2].Trim().Split(','); + + if (args2.Length < 3) + { + HandleError("Error", "Argument underflow."); + break; + } + if (args2.Length > 3) + { + HandleError("Error", "Argument overflow."); + break; + } + + Window wnd = new Window(); + ushort width, height; + + if (args2[0].Trim().Contains('"')) + wnd.Title = args2[0].Substring(1, args2[0].Length - 2); + else if (Strings.TryGetValue(args2[0].Trim(), out string strval)) + wnd.Title = strval; + + if (Integers.TryGetValue(args2[1].Trim(), out int widthval)) + width = Convert.ToUInt16(widthval); + else + width = Convert.ToUInt16(args2[1].Trim()); + + if (Integers.TryGetValue(args2[2].Trim(), out int heightval)) + height = Convert.ToUInt16(heightval); + else + height = Convert.ToUInt16(args2[2].Trim()); + + wnd.Contents = new Canvas(width, height); + wnd.Visible = true; + wnd.Closable = true; + + wnd.Contents.Clear(Color.LightGray); + wnd.RenderSystemStyleBorder(); + + Windows.Add(key, wnd); + WindowManager.AddWindow(wnd); + } + continue; + } + else + { + string key = line.Substring(7); + + if (Strings.ContainsKey(key)) + { + Strings.Remove(key); + } + + Strings.Add(key, ""); + continue; + } + } + + else if (line.StartsWith("if")) + { + int start = line.IndexOf('('); + int end = line.IndexOf(')') - start; + + string[] comparation; + int endif = 0; + + for (int o = i; o < code.Length; o++) + { + if (code[o] == "endif") + { + endif = o; + break; + } + } + + if (line.Contains('=')) + { + comparation = line.Substring(4).Split('='); + + if (Integers.TryGetValue(comparation[0].Trim(), out int intval)) + { + comparation[1] = comparation[1].Substring(1, comparation[1].Length - 2); + if (comparation[1] != intval.ToString()) + { + i = endif + 1; + } + } + else if (Strings.TryGetValue(comparation[0].Trim(), out string strval)) + { + comparation[1] = comparation[1].Substring(comparation[1].IndexOf('"') + 1, comparation[1].LastIndexOf('"') - 2); + if (comparation[1] != strval) + { + i = endif + 1; + } + } + else if (Booleans.TryGetValue(comparation[0].Trim(), out bool bolval)) + { + comparation[1] = comparation[1].Substring(1, comparation[1].Length - 2); + if (comparation[1] != bolval.ToString().ToLower()) + { + i = endif + 1; + } + } + continue; + } + else if (line.Contains('!')) + { + comparation = line.Substring(4).Split('!'); + + if (Integers.TryGetValue(comparation[0].Trim(), out int intval)) + { + comparation[1] = comparation[1].Substring(1, comparation[1].Length - 2); + if (comparation[1] == intval.ToString()) + { + i = endif + 1; + } + } + else if (Strings.TryGetValue(comparation[0].Trim(), out string strval)) + { + comparation[1] = comparation[1].Substring(comparation[1].IndexOf('"') + 1, comparation[1].LastIndexOf('"') - 2); + if (comparation[1] == strval) + { + i = endif + 1; + } + } + else if (Booleans.TryGetValue(comparation[0].Trim(), out bool bolval)) + { + comparation[1] = comparation[1].Substring(1, comparation[1].Length - 2); + if (comparation[1] == bolval.ToString().ToLower()) + { + i = endif + 1; + } + } + continue; + } + } + + #endregion + + #region System library + + else if (SysLib && line.StartsWith("Stop")) + { + break; + } + + else if (SysLib && line.StartsWith("Goto") && line.Contains(">>")) + { + string arg = line.Split('>')[2]; + + if (Integers.TryGetValue(arg, out int value)) + { + arg = value.ToString(); + } + + i = Convert.ToInt32(line.Split('>')[2]) - 2; + continue; + } + + else if (SysLib && line.StartsWith("Delay") && line.Contains(">>")) + { + string arg = line.Split('>')[2]; + + if (Integers.TryGetValue(arg, out int value)) + { + arg = value.ToString(); + } + + Thread.Sleep(Convert.ToInt32(arg)); + continue; + } + + #endregion + + #region Console library + + else if (ConsoleLib && line.StartsWith("Write") && line.Contains(">>") || ConsoleLib && line.StartsWith("Print") && line.Contains(">>")) + { + string[] args = line.Split('>')[2].Trim().Split(','); + + foreach (string arg in args) + { + string sub = arg.Trim(); + + if (arg.Contains("\"")) + { + Console.Write(sub.Substring(1, sub.Length - 2)); + } + else if (Booleans.TryGetValue(sub, out bool bolval)) + { + Console.Write(bolval); + } + else if (Integers.TryGetValue(sub, out int intval)) + { + Console.Write(intval); + } + else if (Colors.TryGetValue(sub, out ConsoleColor colval)) + { + Console.Write(colval); + } + else if (Strings.TryGetValue(sub, out string strval)) + { + Console.Write(strval); + } + else + { + Console.Write(sub); + } + } + + if (line.StartsWith("Print")) + { + Console.Write('\n'); + } + continue; + } + + else if (ConsoleLib && line.StartsWith("Clear")) + { + Console.Clear(); + continue; + } + + else if (ConsoleLib && line.StartsWith("Read")) + { + Console.ReadKey(true); + continue; + } + + else if (ConsoleLib && line.StartsWith("ReadLine")) + { + Console.ReadLine(); + continue; + } + + #endregion + + #region IO library + + else if (IOLib && line.StartsWith("MkFile") && line.Contains(">>")) + { + string sub = line.Split('>')[2].Trim(); + sub = sub.Substring(1, sub.Length - 2); + + if (Strings.TryGetValue(sub, out string strval)) + { + sub = strval; + } + + using (FileStream stream = new FileStream(sub, FileMode.Create)) + { + stream.Close(); + } + continue; + } + + else if (IOLib && line.StartsWith("MkDir") && line.Contains(">>")) + { + string sub = line.Split('>')[2].Trim(); + sub = sub.Substring(1, sub.Length - 2); + + if (Strings.TryGetValue(sub, out string strval)) + { + sub = strval; + } + + Directory.CreateDirectory(sub); + continue; + } + + else if (IOLib && line.StartsWith("WrFile") && line.Contains(">>")) + { + string[] args = line.Split('>')[2].Trim().Split(','); + + if (Strings.TryGetValue(args[0].Replace("\"", ""), out string strval1)) + { + args[0] = strval1; + } + + if (Strings.TryGetValue(args[1].Remove(0, 1), out string strval2)) + { + args[1] = strval2; + } + + using (FileStream stream = new FileStream(args[0].Replace("\"", ""), FileMode.Open)) + { + byte[] bytes; + if (args[1].Contains('"')) + { + args[1] = args[1].Replace("\"", ""); + bytes = Encoding.UTF8.GetBytes(args[1].Remove(0, 1)); + } + else + { + bytes = Encoding.UTF8.GetBytes(args[1]); + } + + stream.Write(bytes, 0, bytes.Length); + } + } + + #endregion + + #region 9xGL Library + + else if (_9xGLLib && line.StartsWith("DrawString") && line.Contains(">>")) + { + string[] args = line.Split('>')[2].Trim().Split(','); + + if (args.Length < 5) + { + HandleError("Error", "Argument underflow."); + break; + } + if (args.Length > 5) + { + HandleError("Error", "Argument overflow."); + break; + } + + if (!Windows.TryGetValue(args[0].Trim(), out Window wndval)) + { + HandleError("Error", "Unknown variable."); + break; + } + + if (!Strings.TryGetValue(args[1].Trim(), out string strval)) + { + if (args[1].Trim().Contains('"')) + { + strval = args[1].Trim().Substring(1, args[1].Length - 3); + } + else + { + HandleError("Error", "Unknown variable."); + break; + } + } + + if (!Integers.TryGetValue(args[2].Trim(), out int xval)) + { + xval = Convert.ToInt32(args[2].Trim()); + } + + if (!Integers.TryGetValue(args[3].Trim(), out int yval)) + { + yval = Convert.ToInt32(args[3].Trim()); + } + + if (!Colors.TryGetValue(args[4].Trim(), out Color colval)) + { + if (StringToConsoleColor.TryGetValue(args[4].Trim(), out Color colval2)) + { + colval = colval2; + } + else + { + HandleError("Syntax Error", "Unknown Color."); + } + } + + wndval.Contents.DrawString(xval, yval, strval, Fonts.Font_1x, colval); + } + + else if (_9xGLLib && line.StartsWith("SetWindowPos") && line.Contains(">>")) + { + string[] args = line.Split('>')[2].Trim().Split(','); + + if (args.Length < 3) + { + HandleError("Error", "Argument underflow."); + break; + } + if (args.Length > 3) + { + HandleError("Error", "Argument overflow."); + break; + } + + if (!Windows.TryGetValue(args[0].Trim(), out Window wndval)) + { + HandleError("Error", "Unknown variable."); + break; + } + + if (Integers.TryGetValue(args[1].Trim(), out int xval)) + { + wndval.X = xval; + } + else + { + wndval.X = Convert.ToInt32(args[1].Trim()); + } + + if (Integers.TryGetValue(args[2].Trim(), out int yval)) + { + wndval.Y = yval; + } + else + { + wndval.Y = Convert.ToInt32(args[2].Trim()); + } + + wndval.X = xval; + wndval.Y = yval; + } + + #endregion + + #region GoOS Library + + else if (GoOSLib && line.StartsWith("EnableKillingSystemTasks")) + { + GUI.Apps.TaskManager.pko = true; + } + + else if (GoOSLib && line.StartsWith("DisableKillingSystemTasks")) + { + GUI.Apps.TaskManager.pko = false; + } + + else if (GoOSLib && line.StartsWith("RegProg") && line.Contains(">>")) + { + string[] args = line.Split('>')[2].Trim().Split(','); + + if (args.Length < 1) + { + HandleError("Error", "Argument underflow."); + break; + } + if (args.Length > 1) + { + HandleError("Error", "Argument overflow."); + break; + } + + if (!Strings.TryGetValue(args[0].Trim(), out string strval)) + { + if (args[0].Trim().Contains('"')) + { + strval = args[0].Trim().Substring(1, args[0].Length - 3); + } + else + { + HandleError("Error", "Unknown variable."); + break; + } + } + + if (!Directory.Exists(@"0:\content\prf\" + strval + @"\")) + { + Directory.CreateDirectory(@"0:\content\prf\" + strval + @"\"); + } + } + + #endregion + + else + { + HandleError("Syntax Error", "Unknown function.\nMaybe try importing a library?"); + } + } + catch (Exception ex) + { + HandleError("9xCode", "Unhandled exception in runtime:\n" + ex.Message); + } + } + } + + while (WindowManager.ContainsAWindow(new List(Windows.Values))) + { + WindowManager.Update(); + } + } + + private static void HandleError(string Title, string Message) + { + Dialogue.Show(Title, Message, null, WindowManager.errorIcon); + Interpreting = false; + } + } +} \ No newline at end of file diff --git a/GoOS/9xCode/StringToConsoleColor.cs b/GoOS/9xCode/StringToConsoleColor.cs new file mode 100644 index 0000000000..3b7e288569 --- /dev/null +++ b/GoOS/9xCode/StringToConsoleColor.cs @@ -0,0 +1,21 @@ +using System.Collections.Generic; +using ConsoleColor = PrismAPI.Graphics.Color; +using static ConsoleColorEx; + +namespace GoOS._9xCode +{ + public static partial class Interpreter + { + private static Dictionary StringToConsoleColor = new Dictionary() + { + { "Black", Black }, { "DarkBlue", DarkBlue }, + { "DarkGreen", DarkGreen }, { "DarkCyan", DarkCyan }, + { "DarkRed", DarkRed },{ "DarkMagenta", DarkMagenta }, + { "DarkYellow", DarkYellow }, { "Gray", Gray }, + { "DarkGray", DarkGray },{ "Blue", Blue }, + { "Green", Green },{ "Cyan", Cyan }, + { "Red", Red }, { "Magenta", Magenta }, + { "Yellow", Yellow }, { "White", White }, + }; + } +} \ No newline at end of file diff --git a/GoOS/BetterConsole/BetterConsole.cs b/GoOS/BetterConsole/BetterConsole.cs index f618ec1943..5b7287749c 100644 --- a/GoOS/BetterConsole/BetterConsole.cs +++ b/GoOS/BetterConsole/BetterConsole.cs @@ -1,27 +1,34 @@ using System; using System.Collections.Generic; +using Cosmos.Core.Memory; using Cosmos.System; +using GoOS.GUI; +using GoOS.Themes; using IL2CPU.API.Attribs; -using PrismAPI.Hardware.GPU; using PrismAPI.Graphics; using PrismAPI.Graphics.Fonts; -using GoOS.Themes; -using Cosmos.Core.Memory; -using GoOS; /// /// class /// public static class BetterConsole { - [ManifestResourceStream(ResourceName = "GoOS.Resources.Font_1x.btf")] private static byte[] rawFont; - [ManifestResourceStream(ResourceName = "GoOS.Resources.Credits05.bmp")] private static byte[] easterEgg; + /* The raw global font */ + [ManifestResourceStream(ResourceName = "GoOS.Resources.Font_1x.btf")] + public static byte[] rawFont; - private static Font font; + /* The credits easter egg */ + [ManifestResourceStream(ResourceName = "GoOS.Resources.Credits05.bmp")] + private static byte[] easterEgg; - public static Display Canvas; + /* The global font */ + public static Font font; - private static ushort charWidth = 8, charHeight = 16; + /* The canvas for the console */ + public static Canvas Canvas; + + /* Character width and height */ + public static ushort charWidth = 8, charHeight = 16; private static List menuOptions = new() { @@ -29,39 +36,57 @@ public static class BetterConsole "Reboot" }; + public static bool ConsoleMode = false; + + public static bool Visible = false; + /// /// The X position of the cursor /// public static int CursorLeft = 0; + /// /// The Y position of the cursor /// public static int CursorTop = 0; + /// /// The width of the /// public static ushort WindowWidth = 0; + /// /// The height of the /// public static ushort WindowHeight = 0; + /// /// The foreground color of the /// public static Color ForegroundColor = Color.White; + /// /// The background color of the /// public static Color BackgroundColor = Color.Black; + /// /// Determines if the cursor is visible /// public static bool CursorVisible = true; + /// /// Determines if every command calls Render() when finishes /// public static bool DoubleBufferedMode = false; + /// + /// The queue of key events to send to the + /// + public static Queue KeyBuffer = new Queue(); + + public static string Title = "GTerm"; + /// /// Initializes the /// @@ -70,7 +95,8 @@ public static class BetterConsole public static void Init(ushort width, ushort height) { font = new Font(rawFont, charHeight); - Canvas = Display.GetDisplay(width, height); + //Canvas = Display.GetDisplay(width, height); + Canvas = new Canvas(width, height); WindowWidth = Convert.ToUInt16(width / charWidth); WindowHeight = Convert.ToUInt16(height / charHeight); Canvas.Clear(); @@ -82,7 +108,8 @@ public static void Init(ushort width, ushort height) public static void Clear(bool render = true) { Canvas.Clear(BackgroundColor); - CursorLeft = 0; CursorTop = 0; + CursorLeft = 0; + CursorTop = 0; if (render || !DoubleBufferedMode) Render(); } @@ -90,7 +117,10 @@ public static void Clear(bool render = true) /// /// Renders the /// - public static void Render() => Canvas.Update(); + public static void Render() + { + WindowManager.Update(); + } /// /// Writes a string to the @@ -113,6 +143,7 @@ public static void Write(object text, bool quick = false) CursorLeft++; } } + if (!DoubleBufferedMode) Render(); } @@ -126,15 +157,49 @@ public static void Write(object text, bool quick = false) /// /// Reads input from the user /// - /// Print the key that the user pressed - /// The key that the user pressed - public static ConsoleKeyInfo ReadKey(bool intercept = false) + /// Print the key pressed + /// The key pressed + public static ConsoleKeyInfo ReadKey(bool intercept = true) { - ConsoleKeyInfo key = System.Console.ReadKey(); - if (!intercept) Write(key.KeyChar); - return key; + while (true) + { + if (CursorVisible) + { + Canvas.DrawString(CursorLeft * charWidth, CursorTop * charHeight, '_'.ToString(), font, ForegroundColor); + } + + var keyPressed = KeyBuffer.TryDequeue(out var key); + if (keyPressed) + { + if (intercept == false) + { + Write(key.KeyChar); + } + + bool xShift = (key.Modifiers & ConsoleModifiers.Shift) == ConsoleModifiers.Shift; + bool xAlt = (key.Modifiers & ConsoleModifiers.Alt) == ConsoleModifiers.Alt; + bool xControl = (key.Modifiers & ConsoleModifiers.Control) == ConsoleModifiers.Control; + + return new ConsoleKeyInfo(key.KeyChar, key.Key.ToConsoleKey(), xShift, xAlt, xControl); + } + else + { + WindowManager.Update(); + } + + if (CursorVisible) + { + // Just to be safe + Canvas.DrawString((CursorLeft - 1) * charWidth, CursorTop * charHeight, '_'.ToString(), font, Color.Black); + Canvas.DrawString((CursorLeft + 1) * charWidth, CursorTop * charHeight, '_'.ToString(), font, Color.Black); + Canvas.DrawString(CursorLeft * charWidth, (CursorTop - 1) * charHeight, '_'.ToString(), font, Color.Black); + Canvas.DrawString(CursorLeft * charWidth, (CursorTop + 1) * charHeight, '_'.ToString(), font, Color.Black); + } + } } + private static string lastInput = string.Empty; + /// /// Gets input from the user /// @@ -149,152 +214,172 @@ public static string ReadLine() { if (CursorVisible) { - PutChar('_', CursorLeft, CursorTop); + PutChar('_', CursorLeft, CursorTop, true); Render(); } - var key = KeyboardManager.ReadKey(); - switch (key.Key) + var keyPressed = KeyBuffer.TryDequeue(out var key); + if (keyPressed) { - case ConsoleKeyEx.Enter: - PutChar(' ', CursorLeft, CursorTop); - CursorLeft = 0; CursorTop++; - Newline(); - reading = false; - break; - - case ConsoleKeyEx.Backspace: - if (!(CursorLeft == startCursorLeft && CursorTop == startY)) - { - if (CursorLeft == 0) - { - PutChar(' ', CursorLeft, CursorTop); // Erase the cursor - CursorTop--; - CursorLeft = Canvas.Width / charWidth - 1; - PutChar(' ', CursorLeft, CursorTop); // Erase the actual character - } - else - { - PutChar(' ', CursorLeft, CursorTop); // Erase the cursor - CursorLeft--; - PutChar(' ', CursorLeft, CursorTop); // Erase the actual character - } - returnValue = returnValue.Remove(returnValue.Length - 1); // Remove the last character of the string - } - break; - - case ConsoleKeyEx.Tab: - Write(new string(' ', 4)); - returnValue += new string(' ', 4); - break; - - default: - if (KeyboardManager.ControlPressed) - { - if (key.Key == ConsoleKeyEx.G) - { - string collected = Heap.Collect() + " items collected"; - Init(Canvas.Width, Canvas.Height); - Canvas.DrawString(Canvas.Width - (collected.Length * 8) - 8, Canvas.Height - 32, collected, font, ThemeManager.WindowText); - SetCursorPosition(0, 0); - GoOS.Kernel.DrawPrompt(); - Write(returnValue); - } - else if (key.Key == ConsoleKeyEx.L) - { - Clear(); - returnValue = string.Empty; - reading = false; - } - else if (KeyboardManager.ShiftPressed && key.Key == ConsoleKeyEx.E) + switch (key.Key) + { + case ConsoleKeyEx.Enter: + PutChar(' ', CursorLeft, CursorTop); + CursorLeft = 0; + CursorTop++; + Newline(); + lastInput = returnValue; + reading = false; + break; + + case ConsoleKeyEx.Backspace: + if (!(CursorLeft == startCursorLeft && CursorTop == startY)) { - Write("> "); - string input = ReadLine(); - if (input == "e015") + if (CursorLeft == 0) { - Clear(); - Canvas.DrawImage(0, 0, Image.FromBitmap(easterEgg, false), false); - Canvas.Update(); - ReadKey(true); - Clear(); + PutChar(' ', CursorLeft, CursorTop); // Erase the cursor + CursorTop--; + CursorLeft = Canvas.Width / charWidth - 1; + PutChar(' ', CursorLeft, CursorTop); // Erase the actual character } else { - Write("Nope"); + PutChar(' ', CursorLeft, CursorTop); // Erase the cursor + CursorLeft--; + PutChar(' ', CursorLeft, CursorTop); // Erase the actual character } - } - else if (KeyboardManager.AltPressed && key.Key == ConsoleKeyEx.Delete) - { - int selected = 0; - Clear(); - Canvas.DrawRectangle((Canvas.Width / 2) - (144 / 2) + 0, (Canvas.Height / 2) - ((menuOptions.Count + 4) * 16 / 2) + 0, 144, Convert.ToUInt16((menuOptions.Count + 4) * 16), 0, ThemeManager.WindowBorder); - Canvas.DrawRectangle((Canvas.Width / 2) - (144 / 2) + 1, (Canvas.Height / 2) - ((menuOptions.Count + 4) * 16 / 2) + 1, 144, Convert.ToUInt16((menuOptions.Count + 4) * 16), 0, ThemeManager.WindowBorder); + returnValue = + returnValue.Remove(returnValue.Length - 1); // Remove the last character of the string + } - Refresh: - if (selected > menuOptions.Count - 1) + break; + case ConsoleKeyEx.Tab: + Write(new string(' ', 4)); + returnValue += new string(' ', 4); + break; + + case ConsoleKeyEx.UpArrow: + SetCursorPosition(startCursorLeft, startY); + Write(new string(' ', returnValue.Length)); + SetCursorPosition(startCursorLeft, startY); + Write(lastInput); + returnValue = lastInput; + break; + + default: + if (KeyboardManager.ControlPressed) + { + if (key.Key == ConsoleKeyEx.G) { - selected = 0; + string collected = Heap.Collect() + " items collected"; + Canvas.DrawString(Canvas.Width - (collected.Length * 8) - 8, Canvas.Height - 32, collected, font, ThemeManager.WindowText); + Write(returnValue); } - if (selected < 0) + else if (key.Key == ConsoleKeyEx.L) { - selected = menuOptions.Count - 1; + Clear(); + returnValue = string.Empty; + reading = false; } - - for (int i = 0; i < menuOptions.Count; i++) + else if (KeyboardManager.ShiftPressed && key.Key == ConsoleKeyEx.E) { - SetCursorPosition((WindowWidth / 2) - (15 / 2) - 1, (WindowHeight / 2) - 1 + (i * 2)); - if (i == selected) + Write("> "); + string input = ReadLine(); + if (input == "e015") { - ForegroundColor = ThemeManager.Background; - BackgroundColor = ThemeManager.WindowText; + Clear(); + Canvas.DrawImage(0, 0, Image.FromBitmap(easterEgg, false), false); + ReadKey(true); + Clear(); } - else + } + else if (ConsoleMode && KeyboardManager.AltPressed && key.Key == ConsoleKeyEx.Delete) + { + int selected = 0; + + Clear(); + Canvas.DrawRectangle((Canvas.Width / 2) - (144 / 2) + 0, + (Canvas.Height / 2) - ((menuOptions.Count + 4) * 16 / 2) + 0, 144, + Convert.ToUInt16((menuOptions.Count + 4) * 16), 0, ThemeManager.WindowBorder); + Canvas.DrawRectangle((Canvas.Width / 2) - (144 / 2) + 1, + (Canvas.Height / 2) - ((menuOptions.Count + 4) * 16 / 2) + 1, 144, + Convert.ToUInt16((menuOptions.Count + 4) * 16), 0, ThemeManager.WindowBorder); + + Refresh: + if (selected > menuOptions.Count - 1) { - ForegroundColor = ThemeManager.WindowText; - BackgroundColor = ThemeManager.Background; + selected = 0; } - Write(menuOptions[i]); - } - var key2 = KeyboardManager.ReadKey(); - switch (key2.Key) - { - case ConsoleKeyEx.Escape: - break; - - case ConsoleKeyEx.Enter: - if (menuOptions[selected] == menuOptions[0]) - GoOS.ControlPanel.Launch(); - else if (menuOptions[selected] == menuOptions[1]) - Power.Reboot(); - break; - - case ConsoleKeyEx.UpArrow: - selected--; - goto Refresh; - - case ConsoleKeyEx.DownArrow: - selected++; - goto Refresh; - - default: - goto Refresh; - } + if (selected < 0) + { + selected = menuOptions.Count - 1; + } + + for (int i = 0; i < menuOptions.Count; i++) + { + SetCursorPosition((WindowWidth / 2) - (15 / 2) - 1, + (WindowHeight / 2) - 1 + (i * 2)); + if (i == selected) + { + ForegroundColor = ThemeManager.Background; + BackgroundColor = ThemeManager.WindowText; + } + else + { + ForegroundColor = ThemeManager.WindowText; + BackgroundColor = ThemeManager.Background; + } + + Write(menuOptions[i]); + } + + var key2 = KeyboardManager.ReadKey(); + switch (key2.Key) + { + case ConsoleKeyEx.Escape: + break; + + case ConsoleKeyEx.Enter: + if (menuOptions[selected] == menuOptions[0]) + GoOS.ControlPanel.Launch(); + else if (menuOptions[selected] == menuOptions[1]) + Power.Reboot(); + break; + + case ConsoleKeyEx.UpArrow: + selected--; + goto Refresh; + + case ConsoleKeyEx.DownArrow: + selected++; + goto Refresh; + + default: + goto Refresh; + } - Clear(); - GoOS.Kernel.DrawPrompt(); + Clear(); + GoOS.Kernel.DrawPrompt(); + } } - } - else - { - Write(key.KeyChar.ToString()); - Newline(); - returnValue += key.KeyChar; - } - break; + else + { + Write(key.KeyChar.ToString()); + Newline(); + returnValue += key.KeyChar; + } + + break; + } + + Render(); + } + else + { + WindowManager.Update(); } - Render(); } return returnValue; @@ -322,6 +407,7 @@ public static void Beep(uint freq = 800, uint duration = 125) } #region Private functions + private static void Newline() { if (CursorLeft >= Canvas.Width / charWidth) @@ -329,20 +415,17 @@ private static void Newline() CursorLeft = 0; CursorTop++; } + if (CursorTop >= Canvas.Height / charHeight) { - Canvas.DrawFilledRectangle(0, 0, Canvas.Width, charHeight, 0, Color.Black); - for (int y = charHeight; y < Canvas.Height; y++) - { - for (int CursorLeft = 0; CursorLeft < Canvas.Width; CursorLeft++) - { - Canvas[CursorLeft, y - charHeight] = Canvas[CursorLeft, y]; - } - } + Canvas.DrawImage(0, -charHeight, Canvas, false); Canvas.DrawFilledRectangle(0, Canvas.Height - charHeight, Canvas.Width, charHeight, 0, Color.Black); - CursorLeft = 0; CursorTop = (Canvas.Height / charHeight) - 1; + CursorLeft = 0; + CursorTop = (Canvas.Height / charHeight) - 1; + if (!DoubleBufferedMode) Render(); + Heap.Collect(); } } @@ -350,10 +433,12 @@ private static void Newline() public static void PutChar(char c, int CursorLeft, int y, bool quick = false) { if (!quick) - Canvas.DrawFilledRectangle(CursorLeft * charWidth, y * charHeight, Convert.ToUInt16(charWidth + (charWidth / 8)), charHeight, 0, BackgroundColor); //yes this is correct + Canvas.DrawFilledRectangle(CursorLeft * charWidth, y * charHeight, + Convert.ToUInt16(charWidth + (charWidth / 8)), charHeight, 0, BackgroundColor); //yes this is correct if (c != ' ') Canvas.DrawString(CursorLeft * charWidth, y * charHeight, c.ToString(), font, ForegroundColor); } + #endregion } @@ -378,4 +463,4 @@ public static class ConsoleColorEx public static readonly Color Magenta = new Color(255, 85, 255); public static readonly Color Yellow = new Color(255, 255, 85); public static readonly Color White = new Color(255, 255, 255); -} +} \ No newline at end of file diff --git a/GoOS/BetterConsole/VMBetterConsole.cs b/GoOS/BetterConsole/VMBetterConsole.cs new file mode 100644 index 0000000000..032f2353cd --- /dev/null +++ b/GoOS/BetterConsole/VMBetterConsole.cs @@ -0,0 +1,443 @@ +using System; +using System.Collections.Generic; +using Cosmos.Core.Memory; +using Cosmos.System; +using GoOS.GUI; +using GoOS.Themes; +using IL2CPU.API.Attribs; +using PrismAPI.Graphics; +using PrismAPI.Graphics.Fonts; + +/// +/// class +/// +public class VMBetterConsole +{ + /* The raw global font */ + [ManifestResourceStream(ResourceName = "GoOS.Resources.Font_1x.btf")] + public byte[] rawFont; + + /* The credits easter egg */ + [ManifestResourceStream(ResourceName = "GoOS.Resources.Credits05.bmp")] + private byte[] easterEgg; + + /* The global font */ + public Font font; + + /* The canvas for the console */ + public Canvas Canvas; + + /* Character width and height */ + public ushort charWidth = 8, charHeight = 16; + + /*private List menuOptions = new() + { + "Launch Settings", + "Reboot" + };*/ + + public bool ConsoleMode = false; + + public bool Visible = false; + + /// + /// The X position of the cursor + /// + public int CursorLeft = 0; + + /// + /// The Y position of the cursor + /// + public int CursorTop = 0; + + /// + /// The width of the + /// + public ushort WindowWidth = 0; + + /// + /// The height of the + /// + public ushort WindowHeight = 0; + + /// + /// The foreground color of the + /// + public Color ForegroundColor = Color.White; + + /// + /// The background color of the + /// + public Color BackgroundColor = Color.Black; + + /// + /// Determines if the cursor is visible + /// + public bool CursorVisible = true; + + /// + /// Determines if every command calls Render() when finishes + /// + public bool DoubleBufferedMode = false; + + /// + /// The queue of key events to send to the + /// + public Queue KeyBuffer = new Queue(); + + /// + /// Initializes the + /// + /// The width of the canvas + /// The height of the canvas + public VMBetterConsole(ushort width, ushort height) + { + font = new Font(rawFont, charHeight); + //Canvas = Display.GetDisplay(width, height); + Canvas = new Canvas(width, height); + WindowWidth = Convert.ToUInt16(width / charWidth); + WindowHeight = Convert.ToUInt16(height / charHeight); + Canvas.Clear(); + } + + /// + /// Clears the console + /// + public void Clear(bool render = true) + { + Canvas.Clear(BackgroundColor); + CursorLeft = 0; + CursorTop = 0; + if (render || !DoubleBufferedMode) + Render(); + } + + /// + /// Renders the + /// + public void Render() + { + WindowManager.Update(); + } + + /// + /// Writes a string to the + /// + /// The string to write + public void Write(object text, bool quick = false) + { + foreach (char c in text.ToString()) + { + Newline(); + + if (c == '\n') + { + CursorLeft = 0; + CursorTop++; + } + else + { + PutChar(c, CursorLeft, CursorTop, quick); + CursorLeft++; + } + } + + if (!DoubleBufferedMode) + Render(); + } + + /// + /// Writes a string to the + /// + /// The string to write + public void WriteLine(object text = null, bool quick = false) => Write(text + "\n", quick); + + /// + /// Reads input from the user + /// + /// Print the key pressed + /// The key pressed + public ConsoleKeyInfo ReadKey(bool intercept = true) + { + while (true) + { + if (CursorVisible) + { + Canvas.DrawString(CursorLeft * charWidth, CursorTop * charHeight, '_'.ToString(), font, ForegroundColor); + } + + var keyPressed = KeyBuffer.TryDequeue(out var key); + if (keyPressed) + { + if (intercept == false) + { + Write(key.KeyChar); + } + + bool xShift = (key.Modifiers & ConsoleModifiers.Shift) == ConsoleModifiers.Shift; + bool xAlt = (key.Modifiers & ConsoleModifiers.Alt) == ConsoleModifiers.Alt; + bool xControl = (key.Modifiers & ConsoleModifiers.Control) == ConsoleModifiers.Control; + + return new ConsoleKeyInfo(key.KeyChar, key.Key.ToConsoleKey(), xShift, xAlt, xControl); + } + else + { + WindowManager.Update(); + } + + if (CursorVisible) + { + // Just to be safe + Canvas.DrawString((CursorLeft - 1) * charWidth, CursorTop * charHeight, '_'.ToString(), font, Color.Black); + Canvas.DrawString((CursorLeft + 1) * charWidth, CursorTop * charHeight, '_'.ToString(), font, Color.Black); + } + } + } + + /// + /// Gets input from the user + /// + /// The teCursorLeftt that the user typed + public string ReadLine() + { + int startCursorLeft = CursorLeft, startY = CursorTop; + string returnValue = string.Empty; + + bool reading = true; + while (reading) + { + if (CursorVisible) + { + PutChar('_', CursorLeft, CursorTop, true); + Render(); + } + + var keyPressed = KeyBuffer.TryDequeue(out var key); + if (keyPressed) + { + switch (key.Key) + { + case ConsoleKeyEx.Enter: + PutChar(' ', CursorLeft, CursorTop); + CursorLeft = 0; + CursorTop++; + Newline(); + reading = false; + break; + + case ConsoleKeyEx.Backspace: + if (!(CursorLeft == startCursorLeft && CursorTop == startY)) + { + if (CursorLeft == 0) + { + PutChar(' ', CursorLeft, CursorTop); // Erase the cursor + CursorTop--; + CursorLeft = Canvas.Width / charWidth - 1; + PutChar(' ', CursorLeft, CursorTop); // Erase the actual character + } + else + { + PutChar(' ', CursorLeft, CursorTop); // Erase the cursor + CursorLeft--; + PutChar(' ', CursorLeft, CursorTop); // Erase the actual character + } + + returnValue = + returnValue.Remove(returnValue.Length - 1); // Remove the last character of the string + } + + break; + case ConsoleKeyEx.Tab: + Write(new string(' ', 4)); + returnValue += new string(' ', 4); + break; + + default: + if (KeyboardManager.ControlPressed) + { + if (key.Key == ConsoleKeyEx.G) + { + string collected = Heap.Collect() + " items collected"; + //Init(Canvas.Width, Canvas.Height); + Canvas.DrawString(Canvas.Width - (collected.Length * 8) - 8, Canvas.Height - 32, + collected, font, ThemeManager.WindowText); + // SetCursorPosition(0, 0); + // GoOS.Kernel.DrawPrompt(); + Write(returnValue); + } + else if (key.Key == ConsoleKeyEx.L) + { + Clear(); + returnValue = string.Empty; + reading = false; + } + else if (KeyboardManager.ShiftPressed && key.Key == ConsoleKeyEx.E) + { + Write("> "); + string input = ReadLine(); + if (input == "e015") + { + Clear(); + Canvas.DrawImage(0, 0, Image.FromBitmap(easterEgg, false), false); + //Canvas.Update(); it stopped working? + ReadKey(true); + Clear(); + } + else + { + Write("Nope"); + } + } + /*else if (KeyboardManager.AltPressed && key.Key == ConsoleKeyEx.Delete) + { + int selected = 0; + + Clear(); + Canvas.DrawRectangle((Canvas.Width / 2) - (144 / 2) + 0, + (Canvas.Height / 2) - ((menuOptions.Count + 4) * 16 / 2) + 0, 144, + Convert.ToUInt16((menuOptions.Count + 4) * 16), 0, ThemeManager.WindowBorder); + Canvas.DrawRectangle((Canvas.Width / 2) - (144 / 2) + 1, + (Canvas.Height / 2) - ((menuOptions.Count + 4) * 16 / 2) + 1, 144, + Convert.ToUInt16((menuOptions.Count + 4) * 16), 0, ThemeManager.WindowBorder); + + Refresh: + if (selected > menuOptions.Count - 1) + { + selected = 0; + } + + if (selected < 0) + { + selected = menuOptions.Count - 1; + } + + for (int i = 0; i < menuOptions.Count; i++) + { + SetCursorPosition((WindowWidth / 2) - (15 / 2) - 1, + (WindowHeight / 2) - 1 + (i * 2)); + if (i == selected) + { + ForegroundColor = ThemeManager.Background; + BackgroundColor = ThemeManager.WindowText; + } + else + { + ForegroundColor = ThemeManager.WindowText; + BackgroundColor = ThemeManager.Background; + } + + Write(menuOptions[i]); + } + + var key2 = KeyboardManager.ReadKey(); + switch (key2.Key) + { + case ConsoleKeyEx.Escape: + break; + + case ConsoleKeyEx.Enter: + if (menuOptions[selected] == menuOptions[0]) + ControlPanel.Launch(); + else if (menuOptions[selected] == menuOptions[1]) + Power.Reboot(); + break; + + case ConsoleKeyEx.UpArrow: + selected--; + goto Refresh; + + case ConsoleKeyEx.DownArrow: + selected++; + goto Refresh; + + default: + goto Refresh; + } + + Clear(); + GoOS.Kernel.DrawPrompt(); + }*/ + } + else + { + Write(key.KeyChar.ToString()); + Newline(); + returnValue += key.KeyChar; + } + + break; + } + + Render(); + } + else + { + WindowManager.Update(); + } + } + + return returnValue; + } + + /// + /// Set the cursor position of the + /// + /// The CursorLeft position of the cursor + /// The Y position of the cursor + public void SetCursorPosition(int x, int y) + { + CursorLeft = x; + CursorTop = y; + } + + public (int Left, int Top) GetCursorPosition() + { + return (CursorLeft, CursorTop); + } + + public void Beep(uint freq = 800, uint duration = 125) + { + PCSpeaker.Beep(freq, duration); + } + + #region Private functions + + private void Newline() + { + if (CursorLeft >= Canvas.Width / charWidth) + { + CursorLeft = 0; + CursorTop++; + } + + if (CursorTop >= Canvas.Height / charHeight) + { + Canvas.DrawFilledRectangle(0, 0, Canvas.Width, charHeight, 0, Color.Black); + for (int y = charHeight; y < Canvas.Height; y++) + { + for (int CursorLeft = 0; CursorLeft < Canvas.Width; CursorLeft++) + { + Canvas[CursorLeft, y - charHeight] = Canvas[CursorLeft, y]; + } + } + + Canvas.DrawFilledRectangle(0, Canvas.Height - charHeight, Canvas.Width, charHeight, 0, Color.Black); + CursorLeft = 0; + CursorTop = (Canvas.Height / charHeight) - 1; + if (!DoubleBufferedMode) + Render(); + Heap.Collect(); + } + } + + public void PutChar(char c, int CursorLeft, int y, bool quick = false) + { + if (!quick) + Canvas.DrawFilledRectangle(CursorLeft * charWidth, y * charHeight, + Convert.ToUInt16(charWidth + (charWidth / 8)), charHeight, 0, BackgroundColor); //yes this is correct + if (c != ' ') + Canvas.DrawString(CursorLeft * charWidth, y * charHeight, c.ToString(), font, ForegroundColor); + } + + #endregion +} diff --git a/GoOS/Commands/ExtendedFilesystem.cs b/GoOS/Commands/ExtendedFilesystem.cs new file mode 100644 index 0000000000..f5027ce297 --- /dev/null +++ b/GoOS/Commands/ExtendedFilesystem.cs @@ -0,0 +1,70 @@ +using System.Reflection.Metadata.Ecma335; + +namespace GoOS.Commands; + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Console = BetterConsole; + +public class ExtendedFilesystem +{ + public static void CopyFile(string from, string to) + { + if (from.Contains("\\")) + { + //Console.WriteLine("1"); + string whatToRemove = from.Substring(from.LastIndexOf("\\")); + + string FullName = from.Replace(whatToRemove, ""); + + string name = FullName.Substring(FullName.IndexOf(".")); + + var Contents = File.ReadAllText(from); + File.Create(to + FullName); + File.WriteAllText(to + FullName, Contents); + } + else + { + //Console.WriteLine("2"); + string FullName = from; + + string name = FullName.Substring(FullName.IndexOf(".")); + + var Contents = File.ReadAllText(from); + File.Create(to + FullName); + File.WriteAllText(to + FullName, Contents); + } + } + + public static void MoveFile(string from, string to) + { + if (from.Contains("\\")) + { + string whatToRemove = from.Substring(from.LastIndexOf("\\")); + + string FullName = from.Replace(whatToRemove, ""); + + string name = FullName.Substring(FullName.IndexOf(".")); + + var Contents = File.ReadAllText(from); + File.Create(to + FullName); + File.WriteAllText(to + FullName, Contents); + File.Delete(from); + } + else + { + string FullName = from; + + string name = FullName.Substring(FullName.IndexOf(".")); + + var Contents = File.ReadAllText(from); + File.Create(to + FullName); + File.WriteAllText(to + FullName, Contents); + File.Delete(from); + } + } +} \ No newline at end of file diff --git a/GoOS/Commands/GoCodeInstaller.cs b/GoOS/Commands/GoCodeInstaller.cs new file mode 100644 index 0000000000..86f2a5f7eb --- /dev/null +++ b/GoOS/Commands/GoCodeInstaller.cs @@ -0,0 +1,144 @@ +using System; +using System.IO; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using GoOS.Themes; +using static GoOS.Core; + +namespace GoOS.Commands; + +public class GoCodeInstaller +{ + public static void Install(string file) + { + try + { + ExtendedFilesystem.CopyFile(file, @"0:\content\GCI\"); + + + if (file.Contains(".gexe")) + { + if (file.Contains("\\")) + { + //Console.WriteLine("3"); + + string whatToRemove = file.Substring(file.LastIndexOf("\\")); + + string FullName = file.Replace(whatToRemove, ""); + + string name = FullName.Replace(".gexe", ""); + + string location = @"0:\content\GCI\" + FullName; + + Kernel.InstalledPrograms.Add(name, location); + } + else + { + //Console.WriteLine("4"); + + string FullName = file; + + string name = FullName.Replace(".gexe", ""); + + string location = @"0:\content\GCI\" + FullName; + + Kernel.InstalledPrograms.Add(name, location); + } + } + else if (file.Contains(".goexe")) + { + if (file.Contains("\\")) + { + string whatToRemove = file.Substring(file.LastIndexOf("\\")); + + string FullName = file.Replace(whatToRemove, ""); + + string name = FullName.Replace(".goexe", ""); + + string location = @"0:\content\GCI\" + FullName; + + Kernel.InstalledPrograms.Add(name, location); + } + else + { + string FullName = file; + + string name = FullName.Replace(".goexe", ""); + + string location = @"0:\content\GCI\" + FullName; + + Kernel.InstalledPrograms.Add(name, location); + } + } + } + catch (Exception e) + { + log(ThemeManager.ErrorText, "Error whilst trying to install file: " + e); + } + } + + public static void CheckForInstalledPrograms() + { + try + { + var directory_list = Directory.GetFiles(@"0:\content\GCI\"); + + foreach (var file in directory_list) + { + if (file.EndsWith(".gexe")) + { + string name = file.Replace(".gexe", ""); + + string location = @"0:\content\GCI\" + file; + + if (!Kernel.InstalledPrograms.ContainsKey(name)) + Kernel.InstalledPrograms.Add(name, location); + } + else if (file.EndsWith(".goexe")) + { + string name = file.Replace(".goexe", ""); + + string location = @"0:\content\GCI\" + file; + + if (!Kernel.InstalledPrograms.ContainsKey(name)) + Kernel.InstalledPrograms.Add(name, location); + } + } + } + catch (Exception e) + { + log(ThemeManager.ErrorText, "Error whilst trying to detect installed programs: " + e); + } + } + + public static void Uninstall(string name) + { + if (Kernel.InstalledPrograms.ContainsKey(name)) + { + string rootass = @"0:\"; + + string currentDIRRRRRR = Directory.GetCurrentDirectory(); + + Directory.SetCurrentDirectory(rootass); + + Kernel.InstalledPrograms.TryGetValue(name, out string locat); + + string TrueLocat = locat; + + if (locat.Contains(@"0:\")) + { + TrueLocat = TrueLocat.Replace(@"0:\", ""); + } + + File.Delete(TrueLocat); + Kernel.InstalledPrograms.Remove(name); + + Directory.SetCurrentDirectory(currentDIRRRRRR); + } + } +} \ No newline at end of file diff --git a/GoOS/Commands/Help.cs b/GoOS/Commands/Help.cs index 63d3b9815d..cf72ee68bd 100644 --- a/GoOS/Commands/Help.cs +++ b/GoOS/Commands/Help.cs @@ -29,7 +29,7 @@ public static void Main() log(ThemeManager.WindowText, "cd.. - Go to the parent directory."); log(ThemeManager.WindowText, "cdr - Jump to root from anywhere."); log(ThemeManager.WindowText, "dir - List all files and folders in the current directory."); - log(ThemeManager.WindowText, "vm {vmname} - Make a file."); + log(ThemeManager.WindowText, "vm {vmname} - Launches a \"VM\"."); log(ThemeManager.WindowText, "settheme - Change the theme."); break; case 3: diff --git a/GoOS/Commands/Vm.cs b/GoOS/Commands/Vm.cs index b9742b1fee..ba9d3765eb 100644 --- a/GoOS/Commands/Vm.cs +++ b/GoOS/Commands/Vm.cs @@ -1,28 +1,25 @@ -using System.IO; +using System; +using System.IO; namespace GoOS.Commands { - internal class Vm + public class VM { - public static void command(string args) + public static void Run(string args) { - string uprootdir = @"0:\content\vrt\"; - string rootdir = @"0:\content\vrt\ChaOS\"; + if (!Directory.Exists(@"0:\content\vrt\")) + Directory.CreateDirectory(@"0:\content\vrt\"); - if (!Directory.Exists(uprootdir)) + if (!Directory.Exists(@"0:\content\vrt\ChaOS\")) + Directory.CreateDirectory(@"0:\content\vrt\ChaOS\"); + + if (args.Equals("ChaOS", StringComparison.OrdinalIgnoreCase)) { - Directory.CreateDirectory(uprootdir); - if (!Directory.Exists(rootdir)) - { - Directory.CreateDirectory(rootdir); - } - } - else if (!Directory.Exists(rootdir)) - { - Directory.CreateDirectory(rootdir); - } + Virtualisation.ChaOS.Kernel Kernel = new Virtualisation.ChaOS.Kernel(); + Kernel.Start(); - GoOS.Virtualisation.ChaOS.ChaOS.boot(@"0:\content\vrt\ChaOS\"); + Kernel = null; + } } } } \ No newline at end of file diff --git a/GoOS/Commands/run.cs b/GoOS/Commands/run.cs index e025877c7a..8778b6a38d 100644 --- a/GoOS/Commands/run.cs +++ b/GoOS/Commands/run.cs @@ -5,6 +5,9 @@ using System.Text; using Cosmos.Core; using Cosmos.HAL; +using Cosmos.System; +using GoOS.GUI; +using GoOS.GUI.Apps; using GoOS.Themes; using Console = BetterConsole; using static ConsoleColorEx; @@ -18,13 +21,25 @@ public class Run static Dictionary Integers = new Dictionary() { }; - public static void Main(string run) + public static string[] InstallLines; + + public static string[] splitit = null; + + public static Window window = null; + + public static Boolean windowed = false; + + public static ushort windowwidth = 0; + public static ushort windowheight = 0; + + public static void Main(string run, bool usecurrentdir = true) { String inputaman = run; try { - //log(Blue, "GoOS Admin: Attempting to run " + inputaman); + log(Cyan, "Goplex Studios GoOS GoCode Interpreter\n"); + if (!inputaman.EndsWith(".gexe") && !inputaman.EndsWith(".goexe")) { log(ThemeManager.ErrorText, "Incompatible format."); @@ -34,597 +49,733 @@ public static void Main(string run) if (inputaman.EndsWith(".goexe") || inputaman.EndsWith(".gexe")) { string fuckingprogramname = null; - log(Yellow, "Application.Start"); - var content = File.ReadAllLines(Directory.GetCurrentDirectory() + "\\" + inputaman); + //log(Yellow, "Application.Start"); + string[] content; + if (usecurrentdir) + { + content = File.ReadAllLines(Directory.GetCurrentDirectory() + "\\" + inputaman); + } + else + { + content = File.ReadAllLines(inputaman); + } string theysaid = null; ConsoleKey keypressed = ConsoleKey.O; String endmessage = "Process has ended."; Boolean hasbeenregistered = false; + int lengthOverride = 0; + bool poo = false; - for (int i = 0; i < content.Length; i++) - { + bool installMode = false; + string installName = "blank"; + + for (int i = 0; i < content.Length + lengthOverride; i++) { string line = content[i]; - - if (poo) - { - line = line.Split(": ")[1].Trim(); - poo = false; - } - - //log(Magenta, "LINE FOUND: CONTENT: " + line); - - if (line.StartsWith("#")) - { - } - if (line.StartsWith("")) + if (Cosmos.System.KeyboardManager.TryReadKey(out var key)) { - } - - if (line.StartsWith("goto")) - { - try - { - String howlong = line.Split("=")[1]; - int potato = Convert.ToInt32(howlong); - i = potato; - } - catch (Exception) + if (key.Key == ConsoleKeyEx.Escape) { - Console.WriteLine("owen caused 9/11"); + i = content.Length; } } - - if (line.StartsWith("sleep")) + + if (line.TrimStart().StartsWith("install")) { - String howlong = line.Split("=")[1]; - int potato = Convert.ToInt32(howlong); - - //while (true) - //{ - // Console.WriteLine("Haha you've been fooled!"); - //} - - System.Threading.Thread.Sleep(potato); + installName = line.Split('=')[1]; + installMode = true; } - - if (line.StartsWith("input")) + + if (installMode) { - if (line == "input=") + if (!line.TrimStart().StartsWith("end")) { - textcolour(Blue); - theysaid = Console.ReadLine(); + InstallLines.Append(line); } else { - String addon = line.Replace("input=", ""); - write(addon); - textcolour(Blue); - theysaid = Console.ReadLine(); + InstallLines.Append("end"); + + Make.MakeFile(@"0:\content\GMI\" + installName); } } - - if (line.StartsWith("stop")) + else if (!installMode) { - if (line == "stop=") + if (poo) { - textcolour(Blue); - log(Green, "Press any key to continue..."); - Console.ReadKey(); - Console.WriteLine(); + line = line.Split(">")[1].Trim(); + + // > goto=5 + //[0] [1] + + poo = false; } - else + + //log(Magenta, "LINE FOUND: CONTENT: " + line); + + if (line.StartsWith("#")) { - String addon = line.Replace("stop=", ""); - textcolour(DarkRed); - write(addon); - textcolour(Blue); - Console.ReadKey(); - Console.WriteLine(); } - } - - if (line.StartsWith("endmsg")) - { - endmessage = line.Replace("endmsg=", ""); - } - if (line.StartsWith("regprog")) - { - if (hasbeenregistered) + if (line.StartsWith("")) { - log(ThemeManager.ErrorText, - "Attempted second register. Application may be attempting to reregister as another application!!!"); - break; } - fuckingprogramname = line.Replace("regprog=", ""); - hasbeenregistered = true; - if (!Directory.Exists(@"0:\content\prf\")) + if (line.StartsWith("goto")) { - Directory.CreateDirectory(@"0:\content\prf\"); - if (!Directory.Exists(@"0:\content\prf\" + fuckingprogramname + @"\")) + try { - Directory.CreateDirectory(@"0:\content\prf\" + fuckingprogramname + @"\"); + String howlong = line.Split("=")[1]; + int potato = Convert.ToInt32(howlong); + i = potato - 2; + } + catch (Exception) + { + Console.WriteLine("owen caused 9/11"); } } - else if (!Directory.Exists(@"0:\content\prf\" + fuckingprogramname + @"\")) + + if (line.StartsWith("sleep")) { - Directory.CreateDirectory(@"0:\content\prf\" + fuckingprogramname + @"\"); - } - } + String howlong = line.Split("=")[1]; + int potato = Convert.ToInt32(howlong); - if (line.StartsWith("string")) - { - string whythehellnotwork = line.Replace(@"string ", ""); - string varName = whythehellnotwork.Split(@" = ")[0]; - string varContents = whythehellnotwork.Split(@" = ")[1]; + //while (true) + //{ + // Console.WriteLine("Haha you've been fooled!"); + //} - if (Strings.ContainsKey(varName)) - { - Strings.Remove(varName); + System.Threading.Thread.Sleep(potato); } - - Strings.Add(varName, varContents); - } - if (line.StartsWith("int")) - { - int intCont = 0; - string whythehellnotwork = line.Replace(@"int ", ""); - string varName = whythehellnotwork.Split(@" = ")[0]; - string varContents = whythehellnotwork.Split(@" = ")[1]; - try + if (line.StartsWith("input")) { - intCont = int.Parse(varContents); + if (line == "input=") + { + textcolour(Blue); + theysaid = Console.ReadLine(); + } + else + { + String addon = line.Replace("input=", ""); + write(addon); + textcolour(Blue); + theysaid = Console.ReadLine(); + } } - catch + + if (line.StartsWith("stop")) { - Console.WriteLine(@"Integer: int " + varName + " is formatted incorrectly."); + if (line == "stop=") + { + textcolour(Blue); + log(Green, "Press any key to continue..."); + Console.ReadKey(); + Console.WriteLine(); + } + else + { + String addon = line.Replace("stop=", ""); + textcolour(DarkRed); + write(addon); + textcolour(Blue); + Console.ReadKey(); + Console.WriteLine(); + } } - string trueCont = intCont.ToString(); - - if (Integers.ContainsKey(varName)) + if (line.StartsWith("endmsg")) { - Integers.Remove(varName); + endmessage = line.Replace("endmsg=", ""); } - - Strings.Add(varName, trueCont); - } - - if (line.StartsWith(@"print=")) - { - string assSplitter = line.Replace(@"print=", ""); - // we like splitting ass round here - - string[] ARE_YOU_GONNA_SINK_OR_SWIM_IN_questionMark_FIGHTING_FOR_MY_ATTENTION_questionMark_ONE_LOOK_GOT_YOU_LIMPING_comma_ANNY_GOT_YOU_SIMPIN = assSplitter.Split(" + "); - - foreach (var ASS in ARE_YOU_GONNA_SINK_OR_SWIM_IN_questionMark_FIGHTING_FOR_MY_ATTENTION_questionMark_ONE_LOOK_GOT_YOU_LIMPING_comma_ANNY_GOT_YOU_SIMPIN) + if (line.StartsWith("regprog")) { - if (ASS.Contains("\"")) + if (hasbeenregistered) { - string thighs = ASS.Replace("\"", ""); - string AccountingForNewline = thighs; - - if (thighs.Contains("\\n")) - { - AccountingForNewline = thighs.Replace("\\n", "\n"); - } - - /////////////////////////////////////// Trying to make \n work //////////////////////////////////////// - // Input: "Hi!\nHello." // - // What I want it to output: "Hi!\n" "Hello." // - // (and actually make a new line) // - // Just that the code itself has the quotes removed, I had to use them to show the separate strings. // - /////////////////////////////////////////////////////////////////////////////////////////////////////// - - Console.Write(AccountingForNewline); + log(ThemeManager.ErrorText, + "Attempted second register. Application may be attempting to reregister as another application!!!"); + break; } - else if (Strings.TryGetValue(ASS, out string what)) + + fuckingprogramname = line.Replace("regprog=", ""); + hasbeenregistered = true; + if (!Directory.Exists(@"0:\content\prf\")) { - try - { - Console.Write(what); - } - catch + Directory.CreateDirectory(@"0:\content\prf\"); + if (!Directory.Exists(@"0:\content\prf\" + fuckingprogramname + @"\")) { - Console.Write("owen is gay"); + Directory.CreateDirectory(@"0:\content\prf\" + fuckingprogramname + @"\"); } } - else if (Integers.TryGetValue(ASS, out int whatint)) + else if (!Directory.Exists(@"0:\content\prf\" + fuckingprogramname + @"\")) { - try - { - Console.Write(what); - } - catch - { - Console.WriteLine("owen is gay"); - } + Directory.CreateDirectory(@"0:\content\prf\" + fuckingprogramname + @"\"); } } - } - - if (line.StartsWith(@"println=")) - { - string assSplitter = line.Replace(@"println=", ""); - // we like splitting ass round here - - string[] ARE_YOU_GONNA_SINK_OR_SWIM_IN_questionMark_FIGHTING_FOR_MY_ATTENTION_questionMark_ONE_LOOK_GOT_YOU_LIMPING_comma_ANNY_GOT_YOU_SIMPIN = assSplitter.Split(" + "); - for (int e = 0; e < ARE_YOU_GONNA_SINK_OR_SWIM_IN_questionMark_FIGHTING_FOR_MY_ATTENTION_questionMark_ONE_LOOK_GOT_YOU_LIMPING_comma_ANNY_GOT_YOU_SIMPIN.Length; e++) + if (line.StartsWith("string")) { - if (ARE_YOU_GONNA_SINK_OR_SWIM_IN_questionMark_FIGHTING_FOR_MY_ATTENTION_questionMark_ONE_LOOK_GOT_YOU_LIMPING_comma_ANNY_GOT_YOU_SIMPIN[e].Contains("\"")) + string whythehellnotwork = line.Replace(@"string ", ""); + string varName = whythehellnotwork.Split(@" = ")[0]; + string varContents = whythehellnotwork.Split(@" = ")[1]; + + if (Strings.ContainsKey(varName)) { - string thighs = ARE_YOU_GONNA_SINK_OR_SWIM_IN_questionMark_FIGHTING_FOR_MY_ATTENTION_questionMark_ONE_LOOK_GOT_YOU_LIMPING_comma_ANNY_GOT_YOU_SIMPIN[e].Replace("\"", ""); - string AccountingForNewline = thighs; + Strings.Remove(varName); + } - if (thighs.Contains("\\n")) - { - AccountingForNewline = thighs.Replace("\\n", "\n"); - } + Strings.Add(varName, varContents); + } - /////////////////////////////////////// Trying to make \n work //////////////////////////////////////// - // Input: "Hi!\nHello." // - // What I want it to output: "Hi!\n" "Hello." // - // (and actually make a new line) // - // Just that the code itself has the quotes removed, I had to use them to show the separate strings. // - /////////////////////////////////////////////////////////////////////////////////////////////////////// - - Console.Write(AccountingForNewline); + if (line.StartsWith("int")) + { + int intCont = 0; + string whythehellnotwork = line.Replace(@"int ", ""); + string varName = whythehellnotwork.Split(@" = ")[0]; + string varContents = whythehellnotwork.Split(@" = ")[1]; + try + { + intCont = int.Parse(varContents); } - else if (Strings.TryGetValue(ARE_YOU_GONNA_SINK_OR_SWIM_IN_questionMark_FIGHTING_FOR_MY_ATTENTION_questionMark_ONE_LOOK_GOT_YOU_LIMPING_comma_ANNY_GOT_YOU_SIMPIN[e], out string what)) + catch { - try - { - Console.Write(what); - } - catch - { - Console.Write("owen is gay"); - } + Console.WriteLine(@"Integer: int " + varName + " is formatted incorrectly."); } - else if (Integers.TryGetValue(ARE_YOU_GONNA_SINK_OR_SWIM_IN_questionMark_FIGHTING_FOR_MY_ATTENTION_questionMark_ONE_LOOK_GOT_YOU_LIMPING_comma_ANNY_GOT_YOU_SIMPIN[e], out int whatint)) + + string trueCont = intCont.ToString(); + + if (Integers.ContainsKey(varName)) { - try - { - Console.Write(what); - } - catch - { - Console.WriteLine("owen is gay"); - } + Integers.Remove(varName); } - } - - Console.WriteLine(); - } - if (line.StartsWith("if")) - { - string[] args = line.Split(" "); - if (args[2] == " == ") + Strings.Add(varName, trueCont); + } + + if (line.StartsWith(@"print=")) { - if (Strings.TryGetValue(args[1].Trim(), out string strval)) + string assSplitter = line.Replace(@"print=", ""); + // we like splitting ass round here + + string[] + ARE_YOU_GONNA_SINK_OR_SWIM_IN_questionMark_FIGHTING_FOR_MY_ATTENTION_questionMark_ONE_LOOK_GOT_YOU_LIMPING_comma_ANNY_GOT_YOU_SIMPIN = + assSplitter.Split(" + "); + + foreach (var ASS in + ARE_YOU_GONNA_SINK_OR_SWIM_IN_questionMark_FIGHTING_FOR_MY_ATTENTION_questionMark_ONE_LOOK_GOT_YOU_LIMPING_comma_ANNY_GOT_YOU_SIMPIN) { - if (strval == args[4]) + if (ASS.Contains("\"")) { - poo = true; - i--; - continue; + string thighs = ASS.Replace("\"", ""); + string AccountingForNewline = thighs; + + if (thighs.Contains("\\n")) + { + AccountingForNewline = thighs.Replace("\\n", "\n"); + } + + /////////////////////////////////////// Trying to make \n work //////////////////////////////////////// + // Input: "Hi!\nHello." // + // What I want it to output: "Hi!\n" "Hello." // + // (and actually make a new line) // + // Just that the code itself has the quotes removed, I had to use them to show the separate strings. // + /////////////////////////////////////////////////////////////////////////////////////////////////////// + + Console.Write(AccountingForNewline); } - else + else if (Strings.TryGetValue(ASS, out string what)) { - poo = false; - continue; + try + { + Console.Write(what); + } + catch + { + Console.Write("owen is gay"); + } + } + else if (Integers.TryGetValue(ASS, out int whatint)) + { + try + { + Console.Write(what); + } + catch + { + Console.WriteLine("owen is gay"); + } } } } - } - if (line.StartsWith(@"save=")) - { - string whatvartosave = line.Substring(5); - if (Strings.TryGetValue(whatvartosave, out string strval)) + if (line.StartsWith(@"println=")) { - if (Directory.Exists(@"0:\content\prf\")) + string assSplitter = line.Replace(@"println=", ""); + // we like splitting ass round here + + string[] + ARE_YOU_GONNA_SINK_OR_SWIM_IN_questionMark_FIGHTING_FOR_MY_ATTENTION_questionMark_ONE_LOOK_GOT_YOU_LIMPING_comma_ANNY_GOT_YOU_SIMPIN = + assSplitter.Split(" + "); + + for (int e = 0; + e < + ARE_YOU_GONNA_SINK_OR_SWIM_IN_questionMark_FIGHTING_FOR_MY_ATTENTION_questionMark_ONE_LOOK_GOT_YOU_LIMPING_comma_ANNY_GOT_YOU_SIMPIN + .Length; + e++) { - if (!File.Exists(@"0:\content\prf\" + fuckingprogramname + @"\" + whatvartosave + - @".txt")) + if + (ARE_YOU_GONNA_SINK_OR_SWIM_IN_questionMark_FIGHTING_FOR_MY_ATTENTION_questionMark_ONE_LOOK_GOT_YOU_LIMPING_comma_ANNY_GOT_YOU_SIMPIN + [e].Contains("\"")) { - File.Create(@"0:\content\prf\" + fuckingprogramname + @"\" + whatvartosave + - @".txt"); - TextWriter tw = new StreamWriter(@"0:\content\prf\" + fuckingprogramname + - @"\" + whatvartosave + @".txt"); - tw.WriteLine(strval); - tw.Write(@"type=string"); - tw.Close(); + string thighs = + ARE_YOU_GONNA_SINK_OR_SWIM_IN_questionMark_FIGHTING_FOR_MY_ATTENTION_questionMark_ONE_LOOK_GOT_YOU_LIMPING_comma_ANNY_GOT_YOU_SIMPIN + [e].Replace("\"", ""); + string AccountingForNewline = thighs; + + if (thighs.Contains("\\n")) + { + AccountingForNewline = thighs.Replace("\\n", "\n"); + } + + /////////////////////////////////////// Trying to make \n work //////////////////////////////////////// + // Input: "Hi!\nHello." // + // What I want it to output: "Hi!\n" "Hello." // + // (and actually make a new line) // + // Just that the code itself has the quotes removed, I had to use them to show the separate strings. // + /////////////////////////////////////////////////////////////////////////////////////////////////////// + + Console.Write(AccountingForNewline); } - else if (File.Exists(@"0:\content\prf\" + fuckingprogramname + @"\" + - whatvartosave + @".txt")) + else if (Strings.TryGetValue( + ARE_YOU_GONNA_SINK_OR_SWIM_IN_questionMark_FIGHTING_FOR_MY_ATTENTION_questionMark_ONE_LOOK_GOT_YOU_LIMPING_comma_ANNY_GOT_YOU_SIMPIN + [e], out string what)) { - TextWriter tw = new StreamWriter(@"0:\content\prf\" + fuckingprogramname + - @"\" + whatvartosave + @".txt"); - tw.WriteLine(strval); - tw.Write(@"type=string"); - tw.Close(); + try + { + Console.Write(what); + } + catch + { + Console.Write("owen is gay"); + } } - } - else if (!Directory.Exists(@"0:\content\prf\")) - { - Directory.CreateDirectory(@"0:\content\prf\"); - if (!File.Exists(@"0:\content\prf\" + fuckingprogramname + @"\" + whatvartosave + - @".txt")) + else if (Integers.TryGetValue( + ARE_YOU_GONNA_SINK_OR_SWIM_IN_questionMark_FIGHTING_FOR_MY_ATTENTION_questionMark_ONE_LOOK_GOT_YOU_LIMPING_comma_ANNY_GOT_YOU_SIMPIN + [e], out int whatint)) { - File.Create(@"0:\content\prf\" + fuckingprogramname + @"\" + whatvartosave + - @".txt"); - TextWriter tw = new StreamWriter(@"0:\content\prf\" + fuckingprogramname + - @"\" + whatvartosave + @".txt"); - tw.WriteLine(strval); - tw.Write(@"type=string"); - tw.Close(); + try + { + Console.Write(what); + } + catch + { + Console.WriteLine("owen is gay"); + } } - else if (File.Exists(@"0:\content\prf\" + fuckingprogramname + @"\" + - whatvartosave + @".txt")) + } + + Console.WriteLine(); + } + + if (line.StartsWith("if")) + { + string[] args = line.Split(" "); + + if (args[2] == "==") + { + if (Strings.TryGetValue(args[1].Trim(), out string strval)) { - TextWriter tw = new StreamWriter(@"0:\content\prf\" + fuckingprogramname + - @"\" + whatvartosave + @".txt"); - tw.WriteLine(strval); - tw.Write(@"type=string"); - tw.Close(); + if (strval == args[3]) + { + poo = true; + i--; + continue; + } + else + { + poo = false; + continue; + } } } } - else if (Integers.TryGetValue(whatvartosave, out int intval)) + + if (line.StartsWith(@"save=")) { - if (Directory.Exists(@"0:\content\prf\")) + string whatvartosave = line.Substring(5); + if (Strings.TryGetValue(whatvartosave, out string strval)) { - if (!File.Exists(@"0:\content\prf\" + fuckingprogramname + @"\" + whatvartosave + - @".txt")) + if (Directory.Exists(@"0:\content\prf\")) { - File.Create(@"0:\content\prf\" + fuckingprogramname + @"\" + whatvartosave + - @".txt"); - TextWriter tw = new StreamWriter(@"0:\content\prf\" + fuckingprogramname + - @"\" + whatvartosave + @".txt"); - tw.WriteLine(intval); - tw.Write(@"type=int"); - tw.Close(); + if (!File.Exists(@"0:\content\prf\" + fuckingprogramname + @"\" + + whatvartosave + + @".txt")) + { + File.Create(@"0:\content\prf\" + fuckingprogramname + @"\" + whatvartosave + + @".txt"); + TextWriter tw = new StreamWriter(@"0:\content\prf\" + fuckingprogramname + + @"\" + whatvartosave + @".txt"); + tw.WriteLine(strval); + tw.Write(@"type=string"); + tw.Close(); + } + else if (File.Exists(@"0:\content\prf\" + fuckingprogramname + @"\" + + whatvartosave + @".txt")) + { + TextWriter tw = new StreamWriter(@"0:\content\prf\" + fuckingprogramname + + @"\" + whatvartosave + @".txt"); + tw.WriteLine(strval); + tw.Write(@"type=string"); + tw.Close(); + } } - else if (File.Exists(@"0:\content\prf\" + fuckingprogramname + @"\" + - whatvartosave + @".txt")) + else if (!Directory.Exists(@"0:\content\prf\")) { - TextWriter tw = new StreamWriter(@"0:\content\prf\" + fuckingprogramname + - @"\" + whatvartosave + @".txt"); - tw.WriteLine(intval); - tw.Write(@"type=int"); - tw.Close(); + Directory.CreateDirectory(@"0:\content\prf\"); + if (!File.Exists(@"0:\content\prf\" + fuckingprogramname + @"\" + + whatvartosave + + @".txt")) + { + File.Create(@"0:\content\prf\" + fuckingprogramname + @"\" + whatvartosave + + @".txt"); + TextWriter tw = new StreamWriter(@"0:\content\prf\" + fuckingprogramname + + @"\" + whatvartosave + @".txt"); + tw.WriteLine(strval); + tw.Write(@"type=string"); + tw.Close(); + } + else if (File.Exists(@"0:\content\prf\" + fuckingprogramname + @"\" + + whatvartosave + @".txt")) + { + TextWriter tw = new StreamWriter(@"0:\content\prf\" + fuckingprogramname + + @"\" + whatvartosave + @".txt"); + tw.WriteLine(strval); + tw.Write(@"type=string"); + tw.Close(); + } } } - else if (!Directory.Exists(@"0:\content\prf\")) + else if (Integers.TryGetValue(whatvartosave, out int intval)) { - Directory.CreateDirectory(@"0:\content\prf\"); - if (!File.Exists(@"0:\content\prf\" + fuckingprogramname + @"\" + whatvartosave + - @".txt")) + if (Directory.Exists(@"0:\content\prf\")) { - File.Create(@"0:\content\prf\" + fuckingprogramname + @"\" + whatvartosave + - @".txt"); - TextWriter tw = new StreamWriter(@"0:\content\prf\" + fuckingprogramname + - @"\" + whatvartosave + @".txt"); - tw.WriteLine(intval); - tw.Write(@"type=int"); - tw.Close(); + if (!File.Exists(@"0:\content\prf\" + fuckingprogramname + @"\" + + whatvartosave + + @".txt")) + { + File.Create(@"0:\content\prf\" + fuckingprogramname + @"\" + whatvartosave + + @".txt"); + TextWriter tw = new StreamWriter(@"0:\content\prf\" + fuckingprogramname + + @"\" + whatvartosave + @".txt"); + tw.WriteLine(intval); + tw.Write(@"type=int"); + tw.Close(); + } + else if (File.Exists(@"0:\content\prf\" + fuckingprogramname + @"\" + + whatvartosave + @".txt")) + { + TextWriter tw = new StreamWriter(@"0:\content\prf\" + fuckingprogramname + + @"\" + whatvartosave + @".txt"); + tw.WriteLine(intval); + tw.Write(@"type=int"); + tw.Close(); + } } - else if (File.Exists(@"0:\content\prf\" + fuckingprogramname + @"\" + - whatvartosave + @".txt")) + else if (!Directory.Exists(@"0:\content\prf\")) { - TextWriter tw = new StreamWriter(@"0:\content\prf\" + fuckingprogramname + - @"\" + whatvartosave + @".txt"); - tw.WriteLine(intval); - tw.Write(@"type=int"); - tw.Close(); + Directory.CreateDirectory(@"0:\content\prf\"); + if (!File.Exists(@"0:\content\prf\" + fuckingprogramname + @"\" + + whatvartosave + + @".txt")) + { + File.Create(@"0:\content\prf\" + fuckingprogramname + @"\" + whatvartosave + + @".txt"); + TextWriter tw = new StreamWriter(@"0:\content\prf\" + fuckingprogramname + + @"\" + whatvartosave + @".txt"); + tw.WriteLine(intval); + tw.Write(@"type=int"); + tw.Close(); + } + else if (File.Exists(@"0:\content\prf\" + fuckingprogramname + @"\" + + whatvartosave + @".txt")) + { + TextWriter tw = new StreamWriter(@"0:\content\prf\" + fuckingprogramname + + @"\" + whatvartosave + @".txt"); + tw.WriteLine(intval); + tw.Write(@"type=int"); + tw.Close(); + } } } } - } - if (line.StartsWith(@"load=")) - { - int intCont = 0; - string whatvartoload = line.Substring(5); - string ass = null; - string assType = null; - if (Strings.TryGetValue(whatvartoload, out string strval)) + if (line.StartsWith(@"load=")) { - if (File.Exists( - @"0:\content\prf\" + fuckingprogramname + @"\" + whatvartoload + @".txt")) + int intCont = 0; + string whatvartoload = line.Substring(5); + string ass = null; + string assType = null; + if (Strings.TryGetValue(whatvartoload, out string strval)) { - using (StreamReader streamReader = new StreamReader( - @"0:\content\prf\" + fuckingprogramname + @"\" + whatvartoload + @".txt", - Encoding.UTF8)) + if (File.Exists( + @"0:\content\prf\" + fuckingprogramname + @"\" + whatvartoload + @".txt")) { - ass = File.ReadLines(@"0:\content\prf\" + fuckingprogramname + @"\" + - whatvartoload + @".txt").Skip(0).Take(1).First(); - assType = File - .ReadLines(@"0:\content\prf\" + fuckingprogramname + @"\" + whatvartoload + - @".txt").Skip(1).Take(1).First(); - string assSplitter2 = assType.Split('=')[1]; - if (assSplitter2 == "string") + using (StreamReader streamReader = new StreamReader( + @"0:\content\prf\" + fuckingprogramname + @"\" + whatvartoload + + @".txt", + Encoding.UTF8)) { - if (Strings.ContainsKey(whatvartoload)) + ass = File.ReadLines(@"0:\content\prf\" + fuckingprogramname + @"\" + + whatvartoload + @".txt").Skip(0).Take(1).First(); + assType = File + .ReadLines(@"0:\content\prf\" + fuckingprogramname + @"\" + + whatvartoload + + @".txt").Skip(1).Take(1).First(); + string assSplitter2 = assType.Split('=')[1]; + if (assSplitter2 == "string") { - Strings.Remove(whatvartoload); - } - - Strings.Add(whatvartoload, ass); - } + if (Strings.ContainsKey(whatvartoload)) + { + Strings.Remove(whatvartoload); + } - if (assSplitter2 == "int") - { - try - { - intCont = int.Parse(ass); + Strings.Add(whatvartoload, ass); } - catch - { - Console.WriteLine(@"Load: int " + whatvartoload + - " is formatted incorrectly."); - } - - string trueCont = intCont.ToString(); - if (Integers.ContainsKey(whatvartoload)) + if (assSplitter2 == "int") { - Integers.Remove(whatvartoload); + try + { + intCont = int.Parse(ass); + } + catch + { + Console.WriteLine(@"Load: int " + whatvartoload + + " is formatted incorrectly."); + } + + string trueCont = intCont.ToString(); + + if (Integers.ContainsKey(whatvartoload)) + { + Integers.Remove(whatvartoload); + } + + Integers.Add(whatvartoload, intCont); } - - Integers.Add(whatvartoload, intCont); } } } } - } - if (line.StartsWith("frontcolor=")) - { - string ass = line.Substring(11); - if (ass == "white") - { - Console.ForegroundColor = White; - } - else if (ass == "blue") - { - Console.ForegroundColor = Blue; - } - else if (ass == "green") - { - Console.ForegroundColor = Green; - } - else if (ass == "yellow") - { - Console.ForegroundColor = Yellow; - } - else if (ass == "black") - { - Console.ForegroundColor = Black; - } - else if (ass == "cyan") - { - Console.ForegroundColor = Cyan; - } - else if (ass == "gray") - { - Console.ForegroundColor = Gray; - } - else if (ass == "magenta") + if (line.StartsWith("frontcolor=")) { - Console.ForegroundColor = Magenta; - } - else if (ass == "red") - { - Console.ForegroundColor = Red; - } - else if (ass == "darkblue") - { - Console.ForegroundColor = DarkBlue; - } - else if (ass == "darkcyan") - { - Console.ForegroundColor = DarkCyan; - } - else if (ass == "darkgray") - { - Console.ForegroundColor = DarkGray; - } - else if (ass == "darkgreen") - { - Console.ForegroundColor = DarkGreen; + string ass = line.Substring(11); + if (ass == "white") + { + Console.ForegroundColor = White; + } + else if (ass == "blue") + { + Console.ForegroundColor = Blue; + } + else if (ass == "green") + { + Console.ForegroundColor = Green; + } + else if (ass == "yellow") + { + Console.ForegroundColor = Yellow; + } + else if (ass == "black") + { + Console.ForegroundColor = Black; + } + else if (ass == "cyan") + { + Console.ForegroundColor = Cyan; + } + else if (ass == "gray") + { + Console.ForegroundColor = Gray; + } + else if (ass == "magenta") + { + Console.ForegroundColor = Magenta; + } + else if (ass == "red") + { + Console.ForegroundColor = Red; + } + else if (ass == "darkblue") + { + Console.ForegroundColor = DarkBlue; + } + else if (ass == "darkcyan") + { + Console.ForegroundColor = DarkCyan; + } + else if (ass == "darkgray") + { + Console.ForegroundColor = DarkGray; + } + else if (ass == "darkgreen") + { + Console.ForegroundColor = DarkGreen; + } + else if (ass == "darkmageneta") + { + Console.ForegroundColor = DarkMagenta; + } + else if (ass == "darkred") + { + Console.ForegroundColor = DarkRed; + } + else if (ass == "darkyellow") + { + Console.ForegroundColor = DarkYellow; + } } - else if (ass == "darkmageneta") + + if (line.StartsWith("backcolor=")) { - Console.ForegroundColor = DarkMagenta; + string ass = line.Substring(10); + if (ass == "white") + { + Console.BackgroundColor = White; + } + else if (ass == "blue") + { + Console.BackgroundColor = Blue; + } + else if (ass == "green") + { + Console.BackgroundColor = Green; + } + else if (ass == "yellow") + { + Console.BackgroundColor = Yellow; + } + else if (ass == "black") + { + Console.BackgroundColor = Black; + } + else if (ass == "cyan") + { + Console.BackgroundColor = Cyan; + } + else if (ass == "gray") + { + Console.BackgroundColor = Gray; + } + else if (ass == "magenta") + { + Console.BackgroundColor = Magenta; + } + else if (ass == "red") + { + Console.BackgroundColor = Red; + } + else if (ass == "darkblue") + { + Console.BackgroundColor = DarkBlue; + } + else if (ass == "darkcyan") + { + Console.BackgroundColor = DarkCyan; + } + else if (ass == "darkgray") + { + Console.BackgroundColor = DarkGray; + } + else if (ass == "darkgreen") + { + Console.BackgroundColor = DarkGreen; + } + else if (ass == "darkmageneta") + { + Console.BackgroundColor = DarkMagenta; + } + else if (ass == "darkred") + { + Console.BackgroundColor = DarkRed; + } + else if (ass == "darkyellow") + { + Console.BackgroundColor = DarkYellow; + } } - else if (ass == "darkred") + } + // Window production center + if (line.StartsWith("size window width = ")) + { + splitit = line.Split("= "); + if (splitit.Length < 2 || splitit.Length > 2) { - Console.ForegroundColor = DarkRed; + Console.WriteLine("Invalid parameters for sizing window. Ref Documentation"); + break; } - else if (ass == "darkyellow") + + windowwidth = ushort.Parse(splitit[1]); + + } + if (line.StartsWith("size window height = ")) + { + splitit = line.Split("= "); + if (splitit.Length < 2 || splitit.Length > 2) { - Console.ForegroundColor = DarkYellow; + Console.WriteLine("Invalid parameters for sizing window. Ref Documentation"); + break; } + + windowheight = ushort.Parse(splitit[1]); + } - if (line.StartsWith("backcolor=")) + if (line.StartsWith("produce window =")) { - string ass = line.Substring(10); - if (ass == "white") - { - Console.BackgroundColor = White; - } - else if (ass == "blue") - { - Console.BackgroundColor = Blue; - } - else if (ass == "green") - { - Console.BackgroundColor = Green; - } - else if (ass == "yellow") - { - Console.BackgroundColor = Yellow; - } - else if (ass == "black") - { - Console.BackgroundColor = Black; - } - else if (ass == "cyan") - { - Console.BackgroundColor = Cyan; - } - else if (ass == "gray") - { - Console.BackgroundColor = Gray; - } - else if (ass == "magenta") + if (windowheight == null || windowwidth == null || windowwidth == 0 || windowheight == 0) { - Console.BackgroundColor = Magenta; - } - else if (ass == "red") - { - Console.BackgroundColor = Red; - } - else if (ass == "darkblue") - { - Console.BackgroundColor = DarkBlue; - } - else if (ass == "darkcyan") - { - Console.BackgroundColor = DarkCyan; - } - else if (ass == "darkgray") - { - Console.BackgroundColor = DarkGray; - } - else if (ass == "darkgreen") - { - Console.BackgroundColor = DarkGreen; + Console.WriteLine("Window size has not been set. Please set it before producing a window."); + break; } - else if (ass == "darkmageneta") + splitit = line.Split("="); + if (splitit.Length < 2 || splitit[1].Equals("")) { - Console.BackgroundColor = DarkMagenta; + Console.WriteLine("This window has not been issued a name. It will use the registered program title."); + if (hasbeenregistered == false) + { + Console.WriteLine("Unregistered application. Will not allow access to WindowManager"); + break; + } + + window = new CustomInterface(fuckingprogramname, windowwidth, windowheight); + WindowManager.AddWindow(window); + windowed = true; + Console.WriteLine("TIP: Window created. Any drawing on the window must be done prior to loading another."); } - else if (ass == "darkred") + else { - Console.BackgroundColor = DarkRed; + window = new CustomInterface(splitit[1], windowwidth, windowheight); + WindowManager.AddWindow(window); + windowed = true; + Console.WriteLine("TIP: Window created. Any drawing on the window must be done prior to loading another."); } - else if (ass == "darkyellow") + } + + if (line.StartsWith("produce wstring = ")) + { + splitit = line.Split(" = "); + if(splitit.Length < 4 || splitit.Length > 4) { - Console.BackgroundColor = DarkYellow; + Console.WriteLine("Invalid parameters for producing a wstring. Ref Documentation"); + break; } + CustomInterface.AddString(window, splitit[1], int.Parse(splitit[2]), int.Parse(splitit[3])); } } diff --git a/GoOS/DotNetClr.dll b/GoOS/DotNetClr.dll new file mode 100644 index 0000000000..599fd85fd7 Binary files /dev/null and b/GoOS/DotNetClr.dll differ diff --git a/GoOS/DotNetParser.dll b/GoOS/DotNetParser.dll new file mode 100644 index 0000000000..e38cd2e170 Binary files /dev/null and b/GoOS/DotNetParser.dll differ diff --git a/GoOS/GUI/Apps/AppManager.cs b/GoOS/GUI/Apps/AppManager.cs new file mode 100644 index 0000000000..eb7884cbed --- /dev/null +++ b/GoOS/GUI/Apps/AppManager.cs @@ -0,0 +1,117 @@ +using System; +using IL2CPU.API.Attribs; +using PrismAPI.Graphics; + +namespace GoOS.GUI.Apps +{ + public class AppManager : Window + { + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.gterm.bmp")] private static byte[] gtermIconRaw; + private static Canvas gtermIcon = Image.FromBitmap(gtermIconRaw, false); + + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.clock.bmp")] private static byte[] clockIconRaw; + private static Canvas clockIcon = Image.FromBitmap(clockIconRaw, false); + + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.TaskManager.bmp")] private static byte[] taskmanIconRaw; + private static Canvas taskmanIcon = Image.FromBitmap(taskmanIconRaw, false); + + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.ide.bmp")] private static byte[] ideIconRaw; + private static Canvas ideIcon = Image.FromBitmap(ideIconRaw, false); + + Button[] AppButtons; + Button CloseButton; + + public AppManager() + { + // Generate the fonts. + Fonts.Generate(); + + // Create the window. + Contents = new Canvas(400, 350); + Title = "GoOS Applications"; + Visible = true; + Closable = true; + SetDock(WindowDock.Auto); + + // Initialize the controls. + AppButtons = new Button[] + { + new Button(this, 10, 52, 64, 80, "GTerm") + { + UseSystemStyle = false, + BackgroundColour = Color.LightGray, + SelectionColour = new Color(100, 100, 100), + TextColour = Color.White, + + Image = gtermIcon, + Clicked = GTerm_Click + }, + new Button(this, 84, 52, 96, 80, "Task Manager") + { + UseSystemStyle = false, + BackgroundColour = Color.LightGray, + SelectionColour = new Color(100, 100, 100), + TextColour = Color.White, + + Image = taskmanIcon, + Clicked = TaskMan_Click + }, + new Button(this, 10, 184, 64, 80, "Clock") + { + UseSystemStyle = false, + BackgroundColour = Color.LightGray, + SelectionColour = new Color(100, 100, 100), + TextColour = Color.White, + + Image = clockIcon, + Clicked = Clock_Click + }, + new Button(this, 84, 184, 64, 80, "IDE") + { + UseSystemStyle = false, + BackgroundColour = Color.LightGray, + SelectionColour = new Color(100, 100, 100), + TextColour = Color.White, + + Image = ideIcon, + Clicked = IDE_Click + } + }; + CloseButton = new Button(this, Convert.ToUInt16(Contents.Width - 90), Convert.ToUInt16(Contents.Height - 30), 80, 20, "Close") { Clicked = CloseButton_Click }; + + // Paint the window. + Contents.Clear(Color.LightGray); + RenderSystemStyleBorder(); + Contents.DrawFilledRectangle(2, Convert.ToUInt16(Contents.Height - 40), Convert.ToUInt16(Contents.Width - 4), 38, 0, Color.DeepGray); + Contents.DrawString(10, 10, "System Applications", Fonts.Font_2x, Color.White); + Contents.DrawString(10, 142, "Accessories", Fonts.Font_2x, Color.White); + foreach (Button AppButton in AppButtons) AppButton.Render(); + CloseButton.Render(); + } + + private void GTerm_Click() + { + WindowManager.AddWindow(new GTerm()); + } + + private void TaskMan_Click() + { + WindowManager.AddWindow(new TaskManager()); + } + + private void Clock_Click() + { + WindowManager.AddWindow(new Clock()); + } + + private void IDE_Click() + { + WindowManager.AddWindow(new GoIDE.ProjectsFrame()); + } + + private void CloseButton_Click() + { + Dispose(); + } + } +} \ No newline at end of file diff --git a/GoOS/GUI/Apps/BrownGhost.cs b/GoOS/GUI/Apps/BrownGhost.cs new file mode 100644 index 0000000000..7e57ac4fd5 --- /dev/null +++ b/GoOS/GUI/Apps/BrownGhost.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using GoOS.GUI; +using IL2CPU.API.Attribs; +using PrismAPI.Graphics; + +namespace GoOS.GUI.Apps +{ + public class BrownGhost : Window + { + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.brown_ghost.bmp")] static byte[] brownGhostRaw; + static Canvas brownGhost = Image.FromBitmap(brownGhostRaw, false); + + public BrownGhost() + { + Contents = new Canvas(238, 150); + Title = "Boooo"; + Visible = true; + Closable = true; + SetDock(WindowDock.Auto); + + Fonts.Generate(); + + Contents.Clear(Color.Black); + RenderSystemStyleBorder(); + Contents.DrawImage(10, 51, brownGhost); + Contents.DrawString(61, 67, "Aaaa! A brown ghost!", Fonts.Font_1x, Color.White); + } + } +} diff --git a/GoOS/GUI/Apps/Clock.cs b/GoOS/GUI/Apps/Clock.cs new file mode 100644 index 0000000000..c0124629bc --- /dev/null +++ b/GoOS/GUI/Apps/Clock.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using IL2CPU.API.Attribs; +using PrismAPI.Graphics; +using PrismAPI.UI; + +namespace GoOS.GUI.Apps +{ + public class Clock : Window + { + private byte lastSecond = Cosmos.HAL.RTC.Second; + + private bool digitalView = false; + + private string[] contextMenuButtons = + { + " Analog view", + " Digital view" + }; + + public Clock() + { + // Generate the fonts. + Fonts.Generate(); + + // Create the window. + Contents = new Canvas(192, 192); + Title = "Clock"; + Visible = true; + Closable = true; + Sizable = true; + SetDock(WindowDock.Auto); + } + + private void RenderHand(int originX, int originY, int handLength, double radians, Color color) + { + int x = originX + (int)(handLength * Math.Sin(radians)); + int y = originY - (int)(handLength * Math.Cos(radians)); + Contents.DrawLine(originX, originY, x, y, color); + } + + public override void Paint() + { + // Paint the window. + DateTime now = DateTime.Now; + string timeText = DateTime.Now.ToString("HH:mm:ss"); + + Contents.Clear(Color.White); + RenderSystemStyleBorder(); + + if (!digitalView) + { + ushort originX = (ushort)(Contents.Width / 2); + ushort originY = (ushort)(Contents.Height / 2); + ushort diameter = (ushort)(Math.Min(Contents.Width, Contents.Height) * 0.75f); + ushort radius = (ushort)(diameter / 2); + + Contents.DrawCircle(originX, originY, radius, Color.Black); + + for (int i = 1; i <= 12; i++) + { + int numX = (int)(originX + (Math.Sin(i * Math.PI / 6) * radius * 0.8)); + int numY = (int)(originY - Math.Cos(i * Math.PI / 6) * radius * 0.8); + Contents.DrawFilledCircle(numX, numY, 2, Color.Black); + } + + /* Second hand */ + double second = now.Second; + double secondRad = second * Math.PI / 30; + RenderHand(originX, originY, radius, secondRad, Color.Red); + + /* Minute hand*/ + double minute = now.Minute + (second / 60); + double minuteRad = minute * Math.PI / 30; + RenderHand(originX, originY, (int)(radius * 0.75f), minuteRad, Color.Black); + + /* Hour hand */ + double hour = now.Hour + (minute / 60); + double hourRad = hour * Math.PI / 6; + RenderHand(originX, originY, (int)(radius * 0.5f), hourRad, Color.Black); + } + else + { + int x = (Contents.Width / 2) - (Fonts.Font_2x.MeasureString(timeText) / 2); + int y = (Contents.Height / 2) - (32 / 2); + + Contents.DrawString(x, y, timeText, Fonts.Font_2x, Color.CoolGreen); + } + } + + public override void HandleRun() + { + base.HandleRun(); + + if (Cosmos.HAL.RTC.Second != lastSecond) + { + lastSecond = Cosmos.HAL.RTC.Second; + Paint(); + } + } + + public override void ShowContextMenu() + { + ContextMenu.Show(contextMenuButtons, 112, ContextMenu_Handle); + } + + private void ContextMenu_Handle(string item) + { + digitalView = item == contextMenuButtons[1]; + Paint(); + } + } +} diff --git a/GoOS/GUI/Apps/CustomInterface.cs b/GoOS/GUI/Apps/CustomInterface.cs new file mode 100644 index 0000000000..bb886a0220 --- /dev/null +++ b/GoOS/GUI/Apps/CustomInterface.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using IL2CPU.API.Attribs; +using PrismAPI.Graphics; + +namespace GoOS.GUI.Apps +{ + public class CustomInterface : Window + { + + Button closeButton; + + public CustomInterface(string Name, ushort width, ushort height) + { + if (Name == null) + { + Name = "Unnamed application"; + } + Contents = new Canvas(width, height); + Contents.Clear(Color.LightGray); + Title = Name; + Visible = true; //Any non OS application must always be visible and closable. No exceptions. + Closable = true; + SetDock(WindowDock.Center); + } + + public static void AddString(Window me, string Text, int X, int Y) + { + me.Contents.DrawString(X, Y, Text, BetterConsole.font, Color.Black); + } + } +} \ No newline at end of file diff --git a/GoOS/GUI/Apps/Cut.cs b/GoOS/GUI/Apps/Cut.cs new file mode 100644 index 0000000000..120d1c6f19 --- /dev/null +++ b/GoOS/GUI/Apps/Cut.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using IL2CPU.API.Attribs; +using PrismAPI.Graphics; +using System.IO; +using System.Threading; + +namespace GoOS.GUI.Apps; + +public class Cut : Window +{ + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.Notepad.CUT.bmp")] + private static byte[] cutIconRaw; + + private static Canvas cutIcon = Image.FromBitmap(cutIconRaw, false); + + public Cut() + { + Contents = new Canvas(148, 150); + Title = "Cut"; + Visible = true; + Closable = false; + Unkillable = true; + SetDock(WindowDock.Auto); + + Contents.Clear(Color.White); + RenderSystemStyleBorder(); + + Contents.DrawImage(0, 0, cutIcon, true); + } +} \ No newline at end of file diff --git a/GoOS/GUI/Apps/Desktop.cs b/GoOS/GUI/Apps/Desktop.cs new file mode 100644 index 0000000000..0aa36c3fc5 --- /dev/null +++ b/GoOS/GUI/Apps/Desktop.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Cosmos.System; +using GoOS.GUI.Models; +using IL2CPU.API.Attribs; +using PrismAPI.Graphics; + +namespace GoOS.GUI.Apps +{ + public class Desktop : Window + { + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.folder.bmp")] private static byte[] folderIconRaw; + private static Canvas folderIcon = Image.FromBitmap(folderIconRaw, false); + + Button FolderButton; + + public Desktop() + { + Fonts.Generate(); + + Contents = new Canvas(WindowManager.Canvas.Width, Convert.ToUInt16(WindowManager.Canvas.Height - 28)); + Contents.Clear(Kernel.DesktopColour); + Title = nameof(Desktop); + Visible = true; + Closable = false; + HasTitlebar = false; + Unkillable = true; + SetDock(WindowDock.None); + + FolderButton = new Button(this, 20, 20, 64, 80, "Apps") + { + UseSystemStyle = false, + BackgroundColour = Kernel.DesktopColour, + TextColour = Color.White, + + Image = folderIcon, + Clicked = FolderButton_Click + }; + + FolderButton.Render(); + string line1 = "GoOS " + Kernel.BuildType + " " + Kernel.version; + string line2 = "Development build"; + + Contents.DrawString(Contents.Width - Fonts.Font_1x.MeasureString(line1)-1, Contents.Height - 29, line1, Fonts.Font_1x, Color.White); + Contents.DrawString(Contents.Width - Fonts.Font_1x.MeasureString(line2)-1, Contents.Height - 17, line2, Fonts.Font_1x, Color.White); + } + + private void FolderButton_Click() + { + WindowManager.AddWindow(new AppManager()); + } + } +} diff --git a/GoOS/GUI/Apps/GCLauncher.cs b/GoOS/GUI/Apps/GCLauncher.cs new file mode 100644 index 0000000000..0e3b4afc72 --- /dev/null +++ b/GoOS/GUI/Apps/GCLauncher.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using IL2CPU.API.Attribs; +using PrismAPI.Graphics; +using PrismAPI.UI.Controls; + +namespace GoOS.GUI.Apps +{ + public class GCLauncher : Window + { + + Button LaunchButton; + Input WhatToLaunch; + + public GCLauncher() + { + Contents = new Canvas(400, 200); + Contents.Clear(Color.LightGray); + Title = "GoCode Launcher"; + Visible = true; + Closable = true; + SetDock(WindowDock.Center); + + WhatToLaunch = new Input(this,5,5,390,20, "Provide a path to your gexe file. (\\path\\to\\file.gexe)"); + WhatToLaunch.Render(); + LaunchButton = new Button(this, 5, 30, 390, 20, "Launch"){ + Clicked = GCVM_Click + };; + LaunchButton.Render(); + + + } + + private void GCVM_Click() + { + WindowManager.AddWindow(new GCVM(this.WhatToLaunch.Text)); + } + + public class GCVM : Window + { + + public static VMBetterConsole VMTERM; + + public GCVM(string path) + { + try + { + VMTERM = new VMBetterConsole(640, 480); + + Contents = VMTERM.Canvas; + Title = "GoCode Console Output"; + Visible = true; + Closable = true; + SetDock(WindowDock.Auto); + VMTERM.Visible = true; + + GoOS.Commands.VM.Run("run "+path); + } + catch (Exception eee) + { + Dialogue.Show( + "Error", + eee.Message, + null, // default buttons + WindowManager.errorIcon); + } + + } + } + } +} \ No newline at end of file diff --git a/GoOS/GUI/Apps/GTerm.cs b/GoOS/GUI/Apps/GTerm.cs new file mode 100644 index 0000000000..b070369ef7 --- /dev/null +++ b/GoOS/GUI/Apps/GTerm.cs @@ -0,0 +1,34 @@ +using Cosmos.System; +using PrismAPI.Graphics.Fonts; + +namespace GoOS.GUI.Apps +{ + public class GTerm : Window + { + public GTerm(bool overrideTitle = true) + { + if (overrideTitle) BetterConsole.Title = "GTerm"; + + Contents = BetterConsole.Canvas; + Title = BetterConsole.Title; + Visible = true; + Closable = true; + SetDock(WindowDock.Auto); + BetterConsole.font = new Font(BetterConsole.rawFont, BetterConsole.charHeight); + BetterConsole.Visible = true; + } + + public override void HandleRun() + { + if (!BetterConsole.Visible) + { + Closing = true; + } + } + + public override void HandleKey(KeyEvent key) + { + BetterConsole.KeyBuffer.Enqueue(key); + } + } +} diff --git a/GoOS/GUI/Apps/GoIDE/IDEFrame.cs b/GoOS/GUI/Apps/GoIDE/IDEFrame.cs new file mode 100644 index 0000000000..3e3a2124a8 --- /dev/null +++ b/GoOS/GUI/Apps/GoIDE/IDEFrame.cs @@ -0,0 +1,97 @@ +using System; +using System.IO; +using IL2CPU.API.Attribs; +using PrismAPI.Graphics; +using GoCode = GoOS.Commands.Run; +using Console = BetterConsole; + +namespace GoOS.GUI.Apps.GoIDE +{ + public class IDEFrame : Window + { + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.GoIDE.run.bmp")] static byte[] runRaw; + static Canvas RunImage = Image.FromBitmap(runRaw, false); + + Button SaveButton; + Button RunButton; + InputNUMBERS Code; + + string ProjectName, ProjectPath; + bool Is9xCode; + + public IDEFrame(string projectName, string projectPath, bool is9xCode) + { + try + { + // Store project name and project path to local variable. + ProjectName = projectName; + ProjectPath = projectPath; + Is9xCode = is9xCode; + + // Create the window. + Contents = new Canvas(800, 600); + Title = projectName + " - GoIDE"; + Visible = true; + Closable = true; + SetDock(WindowDock.Auto); + + // Initialize the controls. + SaveButton = new Button(this, 2, 2, 48, 18, "Save") { Clicked = SaveButton_Click, UseSystemStyle = false, BackgroundColour = Color.LightGray }; + RunButton = new Button(this, Convert.ToUInt16(Contents.Width - 42), 2, 40, 18, "Run") { Clicked = RunButton_Click, UseSystemStyle = false, BackgroundColour = Color.LightGray }; + Code = new InputNUMBERS(this, 2, 20, Convert.ToUInt16(Contents.Width - 4), Convert.ToUInt16(Contents.Height - 43), string.Empty) { MultiLine = true }; + Code.Text = File.ReadAllText(projectPath); + + // Paint the window. + Paint("Loaded"); + } + catch (Exception ex) + { + Dialogue.Show("GoIDE", "Something went wrong.\nPlease try again.\n\n" + ex, null, WindowManager.errorIcon); + } + } + + void Paint(string status) + { + Contents.Clear(Color.LightGray); + RenderSystemStyleBorder(); + Contents.DrawImage(Contents.Width - 62, 0, RunImage); + SaveButton.Render(); + RunButton.Render(); + Code.Render(); + Contents.DrawString(4, Contents.Height - 20, status, Fonts.Font_1x, Color.LighterBlack); + } + + bool Debugging = false; + + void SaveButton_Click() + { + File.WriteAllText(ProjectPath, Code.Text); + Paint("Saved"); + } + + void RunButton_Click() + { + if (!Debugging) + { + Debugging = true; + + File.WriteAllText(ProjectPath, Code.Text); + + Console.Clear(); + Console.Title = "Terminal - GoIDE"; + WindowManager.AddWindow(new GTerm(false)); + Console.Clear(); + + if (!Is9xCode) + GoCode.Main(ProjectPath, false); + else + _9xCode.Interpreter.Run(ProjectPath); + + Console.Clear(); + WindowManager.RemoveWindowByTitle("Terminal - GoIDE"); + + Debugging = false; + } + } + } +} diff --git a/GoOS/GUI/Apps/GoIDE/ImportFrame.cs b/GoOS/GUI/Apps/GoIDE/ImportFrame.cs new file mode 100644 index 0000000000..1be3b945d7 --- /dev/null +++ b/GoOS/GUI/Apps/GoIDE/ImportFrame.cs @@ -0,0 +1,75 @@ +using System; +using System.IO; +using IL2CPU.API.Attribs; +using PrismAPI.Graphics; +using PrismAPI.Graphics.Fonts; + +namespace GoOS.GUI.Apps.GoIDE +{ + public class ImportProjectFrame : Window + { + Button ImportButton; + Button CancelButton; + + Input ScriptLocation; + + public ImportProjectFrame() + { + try + { + // Generate the fonts. + Fonts.Generate(); + + // Create the window. + Contents = new Canvas(400, 300); + Title = "Load project - GoIDE"; + Visible = true; + Closable = true; + SetDock(WindowDock.Center); + + // Initialize the controls. + ImportButton = new Button(this, Convert.ToUInt16(Contents.Width - 180), Convert.ToUInt16(Contents.Height - 30), 80, 20, "Import") { Clicked = ImportButton_Click }; + CancelButton = new Button(this, Convert.ToUInt16(Contents.Width - 90), Convert.ToUInt16(Contents.Height - 30), 80, 20, "Cancel") { Clicked = CancelButton_Click }; + ScriptLocation = new Input(this, 100, 52, Convert.ToUInt16(Contents.Width - 110), 20, @"0:\"); + + // Paint the window. + Contents.Clear(Color.LightGray); + RenderSystemStyleBorder(); + Contents.DrawString(10, 10, "Import project", Fonts.Font_2x, Color.White); + Contents.DrawString(10, 52, "Location: ", Fonts.Font_1x, Color.White); + Contents.DrawFilledRectangle(2, Convert.ToUInt16(Contents.Height - 40), Convert.ToUInt16(Contents.Width - 4), 38, 0, Color.DeepGray); + ImportButton.Render(); + CancelButton.Render(); + ScriptLocation.Render(); + } + catch + { + Dialogue.Show("GoIDE", "Something went wrong.\nPlease try again.", null, WindowManager.errorIcon); + } + } + + void ImportButton_Click() + { + // Import the file. + string name = ScriptLocation.Text.Substring(ScriptLocation.Text.LastIndexOf(@"\")); + string location = ScriptLocation.Text.Trim(); + + if (!File.Exists(location)) + { + Dialogue.Show("GoIDE", "File doesn't exist.", null, WindowManager.errorIcon); + return; + } + + File.WriteAllBytes(@"0:\content\prf\GoIDE\Projects\" + name, File.ReadAllBytes(location)); + + WindowManager.AddWindow(new ProjectsFrame()); + Dispose(); + } + + void CancelButton_Click() + { + WindowManager.AddWindow(new ProjectsFrame()); + Dispose(); + } + } +} diff --git a/GoOS/GUI/Apps/GoIDE/LoadProjectFrame.cs b/GoOS/GUI/Apps/GoIDE/LoadProjectFrame.cs new file mode 100644 index 0000000000..e32686be7a --- /dev/null +++ b/GoOS/GUI/Apps/GoIDE/LoadProjectFrame.cs @@ -0,0 +1,73 @@ +using System; +using System.IO; +using IL2CPU.API.Attribs; +using PrismAPI.Graphics; +using PrismAPI.Graphics.Fonts; + +namespace GoOS.GUI.Apps.GoIDE +{ + public class LoadProjectFrame : Window + { + Button LoadButton; + Button CancelButton; + + Input ScriptLocation; + + public LoadProjectFrame() + { + try + { + // Generate the fonts. + Fonts.Generate(); + + // Create the window. + Contents = new Canvas(400, 300); + Title = "Load project - GoIDE"; + Visible = true; + Closable = true; + SetDock(WindowDock.Center); + + // Initialize the controls. + LoadButton = new Button(this, Convert.ToUInt16(Contents.Width - 180), Convert.ToUInt16(Contents.Height - 30), 80, 20, "Load") { Clicked = LoadButton_Click }; + CancelButton = new Button(this, Convert.ToUInt16(Contents.Width - 90), Convert.ToUInt16(Contents.Height - 30), 80, 20, "Cancel") { Clicked = CancelButton_Click }; + ScriptLocation = new Input(this, 100, 52, Convert.ToUInt16(Contents.Width - 110), 20, @"0:\"); + + // Paint the window. + Contents.Clear(Color.LightGray); + RenderSystemStyleBorder(); + Contents.DrawString(10, 10, "Load project", Fonts.Font_2x, Color.White); + Contents.DrawString(10, 52, "Location: ", Fonts.Font_1x, Color.White); + Contents.DrawFilledRectangle(2, Convert.ToUInt16(Contents.Height - 40), Convert.ToUInt16(Contents.Width - 4), 38, 0, Color.DeepGray); + LoadButton.Render(); + CancelButton.Render(); + ScriptLocation.Render(); + } + catch + { + Dialogue.Show("GoIDE", "Something went wrong.\nPlease try again.", null, WindowManager.errorIcon); + } + } + + void LoadButton_Click() + { + // Load the file. + string name = ScriptLocation.Text.Substring(ScriptLocation.Text.LastIndexOf(@"\")); + string location = ScriptLocation.Text.Trim(); + + if (!File.Exists(location)) + { + Dialogue.Show("GoIDE", "File doesn't exist.", null, WindowManager.errorIcon); + return; + } + + WindowManager.AddWindow(new IDEFrame(name.Remove(name.LastIndexOf(".")).Substring(1), location, name.EndsWith(".9xc"))); + Dispose(); + } + + void CancelButton_Click() + { + WindowManager.AddWindow(new ProjectsFrame()); + Dispose(); + } + } +} diff --git a/GoOS/GUI/Apps/GoIDE/NewProjectFrame.cs b/GoOS/GUI/Apps/GoIDE/NewProjectFrame.cs new file mode 100644 index 0000000000..859a7d8d3c --- /dev/null +++ b/GoOS/GUI/Apps/GoIDE/NewProjectFrame.cs @@ -0,0 +1,117 @@ +using System; +using System.IO; +using PrismAPI.Graphics; + +namespace GoOS.GUI.Apps.GoIDE +{ + public class NewProjectFrame : Window + { + Button CreateButton; + Button CancelButton; + Button GoCodeButton; + Button _9xCodeButton; + + Input ScriptName; + Input ScriptLocation; + + public NewProjectFrame() + { + try + { + // Generate the fonts. + Fonts.Generate(); + + // Create the window. + Contents = new Canvas(400, 300); + Title = "New project - GoIDE"; + Visible = true; + Closable = true; + SetDock(WindowDock.Center); + + // Initialize the controls. + CreateButton = new Button(this, Convert.ToUInt16(Contents.Width - 180), Convert.ToUInt16(Contents.Height - 30), 80, 20, "Create") { Clicked = CreateButton_Click }; + CancelButton = new Button(this, Convert.ToUInt16(Contents.Width - 90), Convert.ToUInt16(Contents.Height - 30), 80, 20, "Cancel") { Clicked = CancelButton_Click }; + GoCodeButton = new Button(this, 100, 112, 80, 20, "GoCode") { Clicked = GoCodeButton_Click, AppearPressed = true }; + _9xCodeButton = new Button(this, 190, 112, 80, 20, "9xCode") { Clicked = _9xCodeButton_Click, AppearPressed = false }; + ScriptName = new Input(this, 100, 52, Convert.ToUInt16(Contents.Width - 110), 20, "Project1"); + ScriptLocation = new Input(this, 100, 82, Convert.ToUInt16(Contents.Width - 110), 20, @"0:\content\prf\GoIDE\Projects"); + + // Paint the window. + Contents.Clear(Color.LightGray); + RenderSystemStyleBorder(); + Contents.DrawString(10, 10, "New project", Fonts.Font_2x, Color.White); + Contents.DrawString(10, 52, "Name: ", Fonts.Font_1x, Color.White); + Contents.DrawString(10, 82, "Location: ", Fonts.Font_1x, Color.White); + Contents.DrawString(10, 112, "Language: ", Fonts.Font_1x, Color.White); + Contents.DrawFilledRectangle(2, Convert.ToUInt16(Contents.Height - 40), Convert.ToUInt16(Contents.Width - 4), 38, 0, Color.DeepGray); + CreateButton.Render(); + CancelButton.Render(); + ScriptName.Render(); + ScriptLocation.Render(); + GoCodeButton.Render(); + _9xCodeButton.Render(); + } + catch + { + Dialogue.Show("GoIDE", "Something went wrong.\nPlease try again.", null, WindowManager.errorIcon); + } + } + + void CreateButton_Click() + { + // Create the file + string name = ScriptName.Text; + string location = ScriptLocation.Text; + + if (name.Trim() == string.Empty) + name = "Project1"; + + if (location.Trim() == string.Empty) + location = @"0:\content\prf\GoIDE\Projects"; + + if (!location.EndsWith(@"\")) + location += @"\"; + + if (!Directory.Exists(location)) + { + Dialogue.Show("GoIDE", "Invalid path.", null, WindowManager.errorIcon); + return; + } + + if (File.Exists(location + name + (GoCodeButton.AppearPressed ? ".gexe" : ".9xc"))) + { + Dialogue.Show("GoIDE", "File already exists.", null, WindowManager.errorIcon); + return; + } + + File.Create(location + name + (GoCodeButton.AppearPressed ? ".gexe" : ".9xc")); + + WindowManager.AddWindow(new IDEFrame(name, location + name + (GoCodeButton.AppearPressed ? ".gexe" : ".9xc"), _9xCodeButton.AppearPressed ? true : false)); + Dispose(); + } + + void CancelButton_Click() + { + WindowManager.AddWindow(new ProjectsFrame()); + Dispose(); + } + + void GoCodeButton_Click() + { + // Toggle the GoCode and 9xCode buttons + GoCodeButton.AppearPressed = true; + _9xCodeButton.AppearPressed = false; + GoCodeButton.Render(); + _9xCodeButton.Render(); + } + + void _9xCodeButton_Click() + { + // Toggle the GoCode and 9xCode buttons + GoCodeButton.AppearPressed = false; + _9xCodeButton.AppearPressed = true; + GoCodeButton.Render(); + _9xCodeButton.Render(); + } + } +} diff --git a/GoOS/GUI/Apps/GoIDE/ProjectsFrame.cs b/GoOS/GUI/Apps/GoIDE/ProjectsFrame.cs new file mode 100644 index 0000000000..6779fd48af --- /dev/null +++ b/GoOS/GUI/Apps/GoIDE/ProjectsFrame.cs @@ -0,0 +1,111 @@ +using System; +using System.IO; +using PrismAPI.Graphics; + +namespace GoOS.GUI.Apps.GoIDE +{ + public class ProjectsFrame : Window + { + Button[] RecentProjectsButtons; + Button DeleteButton; + Button ImportButton; + Button LoadExistingButton; + Button CreateNewButton; + + public ProjectsFrame() + { + try + { + // Create the directories. + if (!Directory.Exists(@"0:\content\prf\GoIDE") || !Directory.Exists(@"0:\content\prf\GoIDE\Projects") || !Directory.Exists(@"0:\content\prf\GoIDE\SaveData")) + { + WindowManager.AddWindow(new WelcomeFrame()); + Dispose(); return; + } + + // Generate the fonts. + Fonts.Generate(); + + // Create the window. + Contents = new Canvas(400, 300); + Title = "All projects - GoIDE"; + Visible = true; + Closable = true; + SetDock(WindowDock.Center); + + // Initialize the controls. + string[] recentProjects = Directory.GetFiles(@"0:\content\prf\GoIDE\Projects\"); + + RecentProjectsButtons = new Button[recentProjects.Length]; + + for (int i = 0; i < recentProjects.Length; i++) + { + RecentProjectsButtons[i] = new Button(this, Convert.ToUInt16(10 + (i / 10 * 185)), Convert.ToUInt16(52 + ((i * 20) - (i / 10 * 200))), Convert.ToUInt16(recentProjects[i].Length * 8), 20, recentProjects[i]) + { + Name = recentProjects[i], + UseSystemStyle = false, + BackgroundColour = Color.LightGray, + SelectionColour = new Color(100, 100, 100), + HasSelectionColour = true, + ClickedAlt = RecentProjects_Click + }; + } + + DeleteButton = new Button(this, Convert.ToUInt16(Contents.Width - 380), Convert.ToUInt16(Contents.Height - 30), 64, 20, "Delete") { Clicked = DeleteButton_Click }; + ImportButton = new Button(this, Convert.ToUInt16(Contents.Width - 306), Convert.ToUInt16(Contents.Height - 30), 64, 20, "Import") { Clicked = ImportButton_Click }; + LoadExistingButton = new Button(this, Convert.ToUInt16(Contents.Width - 234), Convert.ToUInt16(Contents.Height - 30), 120, 20, "Load existing") { Clicked = LoadExistingButton_Click }; + CreateNewButton = new Button(this, Convert.ToUInt16(Contents.Width - 106), Convert.ToUInt16(Contents.Height - 30), 96, 20, "Create new") { Clicked = CreateNewButton_Click }; + + // Paint the window. + Contents.Clear(Color.LightGray); + RenderSystemStyleBorder(); + Contents.DrawFilledRectangle(2, Convert.ToUInt16(Contents.Height - 40), Convert.ToUInt16(Contents.Width - 4), 38, 0, Color.DeepGray); + Contents.DrawString(10, 10, "All projects", Fonts.Font_2x, Color.White); + foreach (Button i in RecentProjectsButtons) i.Render(); + DeleteButton.Render(); + ImportButton.Render(); + LoadExistingButton.Render(); + CreateNewButton.Render(); + } + catch { } + } + + private void RecentProjects_Click(string i) + { + if (DeleteButton.AppearPressed) + { + File.Delete(@"0:\content\prf\GoIDE\Projects\" + i); + Dispose(); + WindowManager.AddWindow(new ProjectsFrame()); + } + else + { + WindowManager.AddWindow(new IDEFrame(i.Remove(i.LastIndexOf(".")), @"0:\content\prf\GoIDE\Projects\" + i, i.EndsWith(".9xc"))); + Dispose(); + } + } + + private void ImportButton_Click() + { + WindowManager.AddWindow(new ImportProjectFrame()); + Dispose(); + } + + private void LoadExistingButton_Click() + { + WindowManager.AddWindow(new LoadProjectFrame()); + Dispose(); + } + + private void CreateNewButton_Click() + { + WindowManager.AddWindow(new NewProjectFrame()); + Dispose(); + } + + private void DeleteButton_Click() + { + DeleteButton.AppearPressed = !DeleteButton.AppearPressed; + } + } +} diff --git a/GoOS/GUI/Apps/GoIDE/WelcomeFrame.cs b/GoOS/GUI/Apps/GoIDE/WelcomeFrame.cs new file mode 100644 index 0000000000..f9173e7460 --- /dev/null +++ b/GoOS/GUI/Apps/GoIDE/WelcomeFrame.cs @@ -0,0 +1,52 @@ +using System; +using System.IO; +using PrismAPI.Graphics; + +namespace GoOS.GUI.Apps.GoIDE +{ + public class WelcomeFrame : Window + { + Button CancelButton; + Button NextButton; + + public WelcomeFrame() + { + // Create the window. + AutoCreate(WindowDock.Center, 400, 300, "Welcome - GoIDE"); + + // Initialize the controls. + CancelButton = new Button(this, Convert.ToUInt16(Contents.Width - 132), Convert.ToUInt16(Contents.Height - 30), 64, 20, "Cancel") { Clicked = CancelButton_Click }; + NextButton = new Button(this, Convert.ToUInt16(Contents.Width - 58), Convert.ToUInt16(Contents.Height - 30), 48, 20, "Next") { Clicked = NextButton_Click }; + + // Paint the window. + Contents.Clear(Color.LightGray); + RenderSystemStyleBorder(); + Contents.DrawFilledRectangle(2, Convert.ToUInt16(Contents.Height - 40), Convert.ToUInt16(Contents.Width - 4), 38, 0, Color.DeepGray); + Contents.DrawString(10, 10, "Welcome", Fonts.Font_2x, Color.White); + Contents.DrawString(10, 52, "Welcome to GoIDE! This program will let you\ncreate and debug GoOS applications.\n\nGoIDE currently supports GoCode and 9xCode.\n\nPress next to install GoIDE and create a new\nproject.", Fonts.Font_1x, Color.White); + CancelButton.Render(); + NextButton.Render(); + } + + private void NextButton_Click() + { + Dialogue msg = new Dialogue("Setup Wizard", "Installing GoIDE...", default, Dialogue.infoIcon); + WindowManager.AddWindow(msg); + WindowManager.Update(); + + Directory.CreateDirectory(@"0:\content\prf\GoIDE"); + Directory.CreateDirectory(@"0:\content\prf\GoIDE\Projects"); + Directory.CreateDirectory(@"0:\content\prf\GoIDE\SaveData"); + + msg.Dispose(); + Dispose(); + WindowManager.AddWindow(new NewProjectFrame()); + } + + private void CancelButton_Click() + { + Dispose(); + Dialogue.Show("GoIDE", "You have canceled GoIDE setup.", default, WindowManager.errorIcon); + } + } +} diff --git a/GoOS/GUI/Apps/GoVM.cs b/GoOS/GUI/Apps/GoVM.cs new file mode 100644 index 0000000000..a517048da6 --- /dev/null +++ b/GoOS/GUI/Apps/GoVM.cs @@ -0,0 +1,74 @@ +using System; +using PrismAPI.Graphics; +namespace GoOS.GUI.Apps; + +public class GoVM : Window +{ + private Button ChaOS_VM_b; + private bool oig = true; + + public GoVM() + { + Contents = new Canvas(300, 300); + Title = "Home - GoVM"; + Visible = true; + Closable = true; + SetDock(WindowDock.Auto); + + ChaOS_VM_b = new Button(this, 5, 5, 60, 20, "ChaOS") + { + Clicked = ChaOS_VM_b_Click + }; + + Contents.Clear(Color.White); + RenderSystemStyleBorder(); + + ChaOS_VM_b.Render(); + } + + private void ChaOS_VM_b_Click() + { + if (oig) + { + oig = false; + WindowManager.AddWindow(new ChaOS_VM()); + } + } +} + +public class ChaOS_VM : Window +{ + + public static VMBetterConsole VMTERM; + + public ChaOS_VM() + { + /*Dialogue.Show( + "Error", + "Owen is gay ;)", + null, // default buttons + WindowManager.errorIcon);*/ + try + { + VMTERM = new VMBetterConsole(800, 600); + + Contents = VMTERM.Canvas; + Title = "ChaOS - GoVM"; + Visible = true; + Closable = true; + SetDock(WindowDock.Auto); + VMTERM.Visible = true; + + //GoOS.Commands.VM.Run("chaos"); + } + catch (Exception eee) + { + Dialogue.Show( + "Error", + eee.Message, + null, // default buttons + WindowManager.errorIcon); + } + + } +} \ No newline at end of file diff --git a/GoOS/GUI/Apps/Gosplorer.cs b/GoOS/GUI/Apps/Gosplorer.cs new file mode 100644 index 0000000000..b1fed48212 --- /dev/null +++ b/GoOS/GUI/Apps/Gosplorer.cs @@ -0,0 +1,464 @@ +using System; +using System.IO; +using System.Linq; +using System.Reflection; +using Cosmos.System; +using IL2CPU.API.Attribs; +using PrismAPI.Graphics; +using GoOS.Commands; +using PrismAPI.Graphics.Fonts; + +namespace GoOS.GUI.Apps; + +public class Gosplorer : Window +{ + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.Gosplorer.NEW.bmp")] + private static byte[] NewIconRaw; + + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.Gosplorer.BIN.bmp")] + private static byte[] BinIconRaw; + + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.Gosplorer.CHILD.bmp")] + private static byte[] ChildIconRaw; + + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.Gosplorer.PARENT.bmp")] + private static byte[] ParentIconRaw; + + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.Gosplorer.MOVE.bmp")] + private static byte[] MoveIconRaw; + + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.Notepad.COPY.bmp")] + private static byte[] copyIconRaw; + + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.Notepad.PASTE.bmp")] + private static byte[] pasteIconRaw; + + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.Gosplorer.REFRESH.bmp")] + private static byte[] refIconRaw; + + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.Gosplorer.LOADINNOTEPAD.bmp")] + private static byte[] linIconRaw; + + private static Canvas newIcon = Image.FromBitmap(NewIconRaw, false); + private static Canvas binIcon = Image.FromBitmap(BinIconRaw, false); + private static Canvas childIcon = Image.FromBitmap(ChildIconRaw, false); + private static Canvas parentIcon = Image.FromBitmap(ParentIconRaw, false); + private static Canvas moveIcon = Image.FromBitmap(MoveIconRaw, false); + private static Canvas copyIcon = Image.FromBitmap(copyIconRaw, false); + private static Canvas pasteIcon = Image.FromBitmap(pasteIconRaw, false); + private static Canvas refIcon = Image.FromBitmap(refIconRaw, false); + private static Canvas linIcon = Image.FromBitmap(linIconRaw, false); + + List DAF; + Button Parent; + Button Child; + Button Move; + Button Bin; + Button New; + Button Ref; + Button Lin; + private Input cdirdis; + + // TODO: Implement copy & paste. + Button Copy; + Button Paste; + + private string cdir5000 = @"0:\"; + + private string clickcounter = ""; + private int ccnum = 0; + + public Gosplorer() + { + BetterConsole.font = new Font(BetterConsole.rawFont, BetterConsole.charHeight); + Contents = new Canvas(500, 310); + Title = "Gosplorer"; + Visible = true; + Closable = true; + Unkillable = false; + SetDock(WindowDock.Auto); + + New = new Button(this, 5, 5, 15, 15, "") + { + //UseSystemStyle = false, + BackgroundColour = Color.White, + TextColour = Color.Black, + + Image = newIcon, + Clicked = NewClick + }; + + Lin = new Button(this, 125, 5, 15, 15, "") + { + //UseSystemStyle = false, + BackgroundColour = Color.White, + TextColour = Color.Black, + + Image = linIcon, + Clicked = LinClick + }; + + Ref = new Button(this, 105, 5, 15, 15, "") + { + //UseSystemStyle = false, + BackgroundColour = Color.White, + TextColour = Color.Black, + + Image = refIcon, + Clicked = RefClick + }; + + Bin = new Button(this, 25, 5, 15, 15, "") + { + //UseSystemStyle = false, + BackgroundColour = Color.White, + TextColour = Color.Black, + + Image = binIcon, + Clicked = BinClick + }; + + Parent = new Button(this, 45, 5, 15, 15, "") + { + //UseSystemStyle = false, + BackgroundColour = Color.White, + TextColour = Color.Black, + + Image = parentIcon, + Clicked = ParentClick + }; + + Child = new Button(this, 65, 5, 15, 15, "") + { + //UseSystemStyle = false, + BackgroundColour = Color.White, + TextColour = Color.Black, + + Image = childIcon, + Clicked = ChildClick + }; + + Move = new Button(this, 85, 5, 15, 15, "") + { + //UseSystemStyle = false, + BackgroundColour = Color.White, + TextColour = Color.Black, + + Image = moveIcon, + Clicked = MoveClick + }; + + // FFS build + + DAF = new List(this, 5, 25, Convert.ToUInt16(Contents.Width - 10), Convert.ToUInt16(310 - 50), + "Directory Listing", Array.Empty()) + { + Clicked = ListClick + }; + + // Render the buttons. + Contents.Clear(Color.LightGray); // >:^( + RenderSystemStyleBorder(); + + Bin.Render(); + Parent.Render(); + Child.Render(); + Move.Render(); + New.Render(); + Ref.Render(); + Lin.Render(); + + Update(true); + } + + private void Update(bool UpdateSelection) + { + string cdir3003 = @"0:\"; + if (cdir5000.Contains(@"0:\\")) + { + cdir3003 = cdir5000.Replace(@"0:\\", @"0:\"); + } + + var directory_list = Directory.GetFiles(cdir3003); + var directory2_list = Directory.GetDirectories(cdir3003); + + int fullLength = directory_list.Length + directory2_list.Length; + + DAF.Items = new string[fullLength]; + + for (int i = 0; i < directory2_list.Length; i++) + DAF.Items[i] = directory2_list[i]; + + for (int i = 0; i < directory_list.Length; i++) + DAF.Items[i + directory2_list.Length] = directory_list[i]; + + if (UpdateSelection) + { + DAF.Selected = 0; + } + + cdirdis = new Input(this, 5, 310 - 20, 500 - 10, 15, " " + cdir3003) + { + //UseSystemStyle = false, + ReadOnly = true + }; + + cdirdis.Render(); + DAF.Render(); + } + + private void ListClick() + { + string WhatWasClicked = DAF.Items[DAF.Selected]; + + if (clickcounter == WhatWasClicked) + { + ccnum++; + if (ccnum >= 2) + { + DoubleHandler(WhatWasClicked); + } + } + else + { + clickcounter = WhatWasClicked; + ccnum = 1; + } + } + + private void DoubleHandler(string Item) + { + if (Item.Contains('.')) + { + string filefigured = cdir5000 + @"\" + Item; + WindowManager.AddWindow(new Notepad(true, filefigured)); + } + else + { + cdir5000 = cdir5000 + @"\" + Item; + Update(true); + } + } + + private void RefClick() + { + Update(false); + } + + private void LinClick() + { + if (DAF.Items[DAF.Selected].Contains('.')) + { + string filefigured = cdir5000 + @"\" + DAF.Items[DAF.Selected]; + WindowManager.AddWindow(new Notepad(true, filefigured)); + } + } + + private void BinClick() + { + string cdir3003 = cdir5000; + string args = DAF.Items[DAF.Selected]; + + string bdir = Directory.GetCurrentDirectory(); + Directory.SetCurrentDirectory(cdir3003); + + if (args.Contains("0:\\")) + { + args.Replace(@"0:\", ""); + } + + if (File.Exists(Directory.GetCurrentDirectory() + @"\" + args)) + File.Delete(Directory.GetCurrentDirectory() + @"\" + args); + else if (Directory.Exists(Directory.GetCurrentDirectory() + @"\" + args)) + Directory.Delete(Directory.GetCurrentDirectory() + @"\" + args, true); + else + { + Dialogue.Show( + "Error", + "File or Directory not found!", + null, // default buttons + WindowManager.errorIcon); + } + + Directory.SetCurrentDirectory(bdir); + + Update(false); + } + + private void ParentClick() + { + if (cdir5000 == @"0:\\" || cdir5000 == "0:\\") + { + } + else + { + string cdir3003 = cdir5000; + + string parentofcdir3003 = cdir3003.Remove(cdir3003.LastIndexOf("\\")); + + cdir5000 = parentofcdir3003; + + Update(true); + } + } + + private void ChildClick() + { + string cdir3003 = cdir5000; + + if (!DAF.Items[DAF.Selected].Contains('.')) + { + cdir5000 = cdir3003 + @"\" + DAF.Items[DAF.Selected]; + Update(true); + } + } + + private void MoveClick() + { + WindowManager.AddWindow(new MoveFWindow(DAF.Items[DAF.Selected], cdir5000)); + } + + private void NewClick() + { + WindowManager.AddWindow(new NewFDWindow(DAF.Items[DAF.Selected], cdir5000)); + } +} + +public class NewFDWindow : Window +{ + private Button OK; + private Button Canel; + private Input Filename; + + private string cdir = ""; + + private string gsel = ""; + + + public NewFDWindow(string selected, string lcdir) + { + cdir = lcdir; + gsel = selected; + + BetterConsole.font = new Font(BetterConsole.rawFont, BetterConsole.charHeight); + Contents = new Canvas(300, 80); + Title = "New - Gosplorer"; + Visible = true; + Closable = false; + Unkillable = false; + SetDock(WindowDock.Auto); + + OK = new Button(this, 5, 50, 60, 20, "Ok") + { + Clicked = OKClick + }; + Canel = new Button(this, 300 - 65, 50, 60, 20, "Cancel") + { + Clicked = CancelClick + }; + Filename = new Input(this, 5, 25, 300 - 10, 20, "") + { + }; + + Contents.Clear(Color.LightGray); // >:^( + RenderSystemStyleBorder(); + + OK.Render(); + Canel.Render(); + Filename.Render(); + + Contents.DrawString(5, 5, "Please input file name below:", BetterConsole.font, Color.White); + } + + private void OKClick() + { + string fn = Filename.Text; + string args = fn; + + if (!fn.Contains('.')) + { + if (!Directory.Exists(args)) + Directory.CreateDirectory(cdir + @"\" + args); + + Dispose(); + } + else + { + if (args.Contains(@"if")) + { + args.Replace(@"if", "THAT NAME IS FORBIDDEN"); + } + + //potato2 = potato2.Split("mkfile ")[1]; + if (!File.Exists(args)) + File.Create(cdir + @"\" + args); + + Dispose(); + } + } + + private void CancelClick() + { + Dispose(); + } +} + +public class MoveFWindow : Window +{ + private Button OK; + private Button Canel; + private Input Filename; + + private string gsel = ""; + + private string cdir = ""; + + public MoveFWindow(string selected, string lcdir) + { + gsel = selected; + cdir = lcdir; + + BetterConsole.font = new Font(BetterConsole.rawFont, BetterConsole.charHeight); + Contents = new Canvas(300, 80); + Title = "Move - Gosplorer"; + Visible = true; + Closable = false; + Unkillable = false; + SetDock(WindowDock.Auto); + + OK = new Button(this, 5, 50, 60, 20, "Ok") + { + Clicked = OKClick + }; + Canel = new Button(this, 300 - 65, 50, 60, 20, "Cancel") + { + Clicked = CancelClick + }; + Filename = new Input(this, 5, 25, 300 - 10, 20, "") + { + }; + + Contents.Clear(Color.LightGray); // >:^( + RenderSystemStyleBorder(); + + OK.Render(); + Canel.Render(); + Filename.Render(); + + Contents.DrawString(5, 5, "Please input new location below:", BetterConsole.font, Color.White); + } + + private void OKClick() + { + string from = cdir + "\\" + gsel; + + string to = Filename.Text + "\\" + gsel; + + GoOS.Commands.ExtendedFilesystem.MoveFile(from, to); + } + + private void CancelClick() + { + Dispose(); + } +} \ No newline at end of file diff --git a/GoOS/GUI/Apps/Notepad.cs b/GoOS/GUI/Apps/Notepad.cs new file mode 100644 index 0000000000..c072571ca2 --- /dev/null +++ b/GoOS/GUI/Apps/Notepad.cs @@ -0,0 +1,402 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using IL2CPU.API.Attribs; +using PrismAPI.Graphics; +using System.IO; +using System.Net.Security; +using System.Threading; +using GoOS.Security; + +namespace GoOS.GUI.Apps; + +public class Notepad : Window +{ + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.Notepad.SAVE.bmp")] + private static byte[] saveIconRaw; + + private static Canvas saveIcon = Image.FromBitmap(saveIconRaw, false); + + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.Notepad.COPY.bmp")] + private static byte[] copyIconRaw; + + private static Canvas copyIcon = Image.FromBitmap(copyIconRaw, false); + + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.Notepad.PASTE.bmp")] + private static byte[] pasteIconRaw; + + private static Canvas pasteIcon = Image.FromBitmap(pasteIconRaw, false); + + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.question.bmp")] + private static byte[] questionRaw; + + + private static Canvas question = Image.FromBitmap(questionRaw, false); + + private Button SaveButton; + private Button CopyButton; + private Button PasteButton; + private InputNUMBERS AttemptOne; + private Input Dialog_TextBox; + + private string infi = ""; + + + public Notepad(bool openFile, string fileToOpen) + { + string infi = fileToOpen; + + Contents = new Canvas(500, 300); + Title = "GoOS Notepad"; + Visible = true; + Closable = true; + SetDock(WindowDock.Auto); + + AttemptOne = new InputNUMBERS(this, 5, 25, 500 - 10, 300 - 30, "") + { + MultiLine = true + }; + + SaveButton = new Button(this, 5, 5, 15, 15, "") + { + //UseSystemStyle = false, + BackgroundColour = Color.White, + TextColour = Color.Black, + + Image = saveIcon, + Clicked = SaveClick + }; + + CopyButton = new Button(this, 25, 5, 15, 15, "") + { + //UseSystemStyle = false, + BackgroundColour = Color.White, + TextColour = Color.Black, + + Image = copyIcon, + Clicked = CopyClick + }; + + PasteButton = new Button(this, 45, 5, 15, 15, "") + { + //UseSystemStyle = false, + BackgroundColour = Color.White, + TextColour = Color.Black, + + Image = pasteIcon, + Clicked = PasteClick + }; + + Contents.Clear(Color.LightGray); + RenderSystemStyleBorder(); + + SaveButton.Render(); + CopyButton.Render(); + PasteButton.Render(); + //AttemptOne.Render(); + + if (openFile) + { + LoadFile(fileToOpen); + } + else + { + AttemptOne.Render(); + } + } + + private void LoadFile(string filefile) + { + string infi = filefile; + + string toreturn = ""; + string[] lines = File.ReadAllLines(filefile); + foreach (var line in lines) + { + toreturn = toreturn + line + "\n"; + } + + AttemptOne.Text = toreturn; + + AttemptOne.Render(); + } + + private void SaveClick() + { + string shittosave = AttemptOne.Text; + + string punchyouintheface = HashPasswordSha256(shittosave); + + /* BUILD YOU DAMNED COMPILER FROM HELL! */ + + if (punchyouintheface.Contains("YwB49Aqwtew1XeHJk0+rrEDtRq7Y6kfF5zGV9sKNe6w=")) + { + WindowManager.AddWindow(new Cut()); + } + else if (punchyouintheface.Contains("P0LqY7Fbr9GbGncLcBkxKhGheiV72MIE5oTrAQSnaSI=")) + { + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + WindowManager.AddWindow(new Cut()); + } + + + WindowManager.AddWindow(new NotepadSaveAs(infi, shittosave)); + } + + internal static string HashPasswordSha256(string hellomario) + { + Sha256 sha256 = new Sha256(); + + byte[] passwordBytesUnhashed = Encoding.Unicode.GetBytes(hellomario); + sha256.AddData(passwordBytesUnhashed, 0, (uint)passwordBytesUnhashed.Length); + + return Convert.ToBase64String(sha256.GetHash()); + } + + private void CopyClick() + { + } + + private void PasteClick() + { + } +} + +public class NotepadSaveAs : Window +{ + private Button SaveButton; + private Button CancelButton; + private Input AttemptOne; + + private string sts = ""; + + public NotepadSaveAs(string placetheholderofthetextplease, string stufftosave) + { + sts = stufftosave; + + Contents = new Canvas(300, 80); + Title = "Save - GoOS Notepad"; + Visible = true; + Closable = false; + SetDock(WindowDock.Auto); + + SaveButton = new Button(this, 5, 50, 60, 20, "Save") + { + Clicked = SaveClick + }; + + CancelButton = new Button(this, 300 - 65, 50, 60, 20, "Cancel") + { + Clicked = Dispose + }; + + AttemptOne = new Input(this, 5, 25, 300 - 10, 20, "") + { + }; + + Contents.Clear(Color.LightGray); + RenderSystemStyleBorder(); + + Contents.DrawString(5, 5, "Please input file name below:", BetterConsole.font, Color.White); + + AttemptOne.Text = placetheholderofthetextplease; + AttemptOne.Text = placetheholderofthetextplease; + AttemptOne.Text = placetheholderofthetextplease; + AttemptOne.Text = placetheholderofthetextplease; + AttemptOne.Text = placetheholderofthetextplease; + AttemptOne.Text = placetheholderofthetextplease; + AttemptOne.Text = placetheholderofthetextplease; + AttemptOne.Text = placetheholderofthetextplease; + AttemptOne.Text = placetheholderofthetextplease; + AttemptOne.Text = placetheholderofthetextplease; + AttemptOne.Text = placetheholderofthetextplease; + AttemptOne.Text = placetheholderofthetextplease; + AttemptOne.Text = placetheholderofthetextplease; + + SaveButton.Render(); + CancelButton.Render(); + AttemptOne.Render(); + + AttemptOne.Text = placetheholderofthetextplease; + AttemptOne.Text = placetheholderofthetextplease; + AttemptOne.Text = placetheholderofthetextplease; + AttemptOne.Text = placetheholderofthetextplease; + AttemptOne.Text = placetheholderofthetextplease; + AttemptOne.Text = placetheholderofthetextplease; + AttemptOne.Text = placetheholderofthetextplease; + AttemptOne.Text = placetheholderofthetextplease; + } + + private void SaveClick() + { + try + { + Commands.Make.MakeFile(AttemptOne.Text); + File.WriteAllText(AttemptOne.Text, sts); + Dialogue.Show( + "Saved!", + "Your file has been saved.", + null); + + Dispose(); + } + catch (Exception e) + { + Dialogue.Show( + "Error", + e.Message, + null, // default buttons + WindowManager.errorIcon); + } + } +} \ No newline at end of file diff --git a/GoOS/GUI/Apps/Paintbrush.cs b/GoOS/GUI/Apps/Paintbrush.cs new file mode 100644 index 0000000000..384b45820b --- /dev/null +++ b/GoOS/GUI/Apps/Paintbrush.cs @@ -0,0 +1,313 @@ +using System; +using Cosmos.System; +using GoOS.GUI.Models; +using IL2CPU.API.Attribs; +using PrismAPI.Graphics; + +namespace GoOS.GUI.Apps +{ + public enum PaintTools + { + Brush = 0, + Bucket = 1, + Text = 2, + Rubber + } + + public class Paintbrush : Window + { + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.Paint.colors.bmp")] private static byte[] colorTableRaw; + private static Canvas colorTable = Image.FromBitmap(colorTableRaw, false); + + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.Paint.brush.bmp")] private static byte[] brushRaw; + private static Canvas brush = Image.FromBitmap(brushRaw, false); + + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.Paint.bucket.bmp")] private static byte[] bucketRaw; + private static Canvas bucket = Image.FromBitmap(bucketRaw, false); + + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.Paint.text.bmp")] private static byte[] textRaw; + private static Canvas text = Image.FromBitmap(textRaw, false); + + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.question.bmp")] private static byte[] questionRaw; + private static Canvas question = Image.FromBitmap(questionRaw, false); + + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.mouse_text.bmp")] private static byte[] mouse_textRaw; + private static Canvas mouse_text = Image.FromBitmap(mouse_textRaw, false); + + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.Paint.rubber.bmp")] private static byte[] rubberRaw; + private static Canvas rubber = Image.FromBitmap(rubberRaw, false); + + private bool IsOverColorTable { get { return MouseManager.X > X + 54 && MouseManager.X < X + 278 && MouseManager.Y > Y + Convert.ToUInt16(Contents.Height - 26) && MouseManager.Y < Y + Convert.ToUInt16(Contents.Height + 6); } } + + private bool IsOverPaintableArea { get { return MouseManager.X > X && MouseManager.X < X + Contents.Width - BrushSize && MouseManager.Y > Y + TITLE_BAR_HEIGHT && MouseManager.Y < Y + Convert.ToUInt16(Contents.Height - 36); } } + + private Color SelectedColor = Color.Black; + + private Button AboutButton; + + private Button[] Utilities; + + private Input Dialog_TextBox; + + private PaintTools Utility; + + private int OldX, OldY; + + private int BrushSize = 1; + + private int TextX, TextY; + + private Color BackgroundColor = Color.White; + + public Paintbrush() + { + Contents = new Canvas(324, 300); + Contents.Clear(BackgroundColor); + Title = "Paintbrush"; + Visible = true; + Closable = true; + SetDock(WindowDock.Auto); + + AboutButton = new Button(this, Convert.ToUInt16(Contents.Width - 36), Convert.ToUInt16(Contents.Height - 38), 24, 20, "?") { Clicked = ShowAboutDialog }; + Utilities = new Button[4] + { + new Button(this, 12, Convert.ToUInt16(Contents.Height - 42), 16, 16, string.Empty) + { + Image = brush, + Clicked = Pencil_Click + }, + new Button(this, 28, Convert.ToUInt16(Contents.Height - 42), 16, 16, string.Empty) + { + Image = bucket, + Clicked = Bucket_Click + }, + new Button(this, 12, Convert.ToUInt16(Contents.Height - 26), 16, 16, string.Empty) + { + Image = text, + Clicked = Text_Click + }, + new Button(this, 28, Convert.ToUInt16(Contents.Height - 26), 16, 16, string.Empty) + { + Image = rubber, + Clicked = Rubber_Click + } + }; + + RenderPanel(); + } + + public override void HandleKey(KeyEvent key) + { + switch (key.Key) + { + case ConsoleKeyEx.F1: + ShowAboutDialog(); + break; + + case ConsoleKeyEx.F2: + WindowManager.AddWindow(new BrownGhost()); + break; + } + + // TODO: implement ctrl + z + } + + private void Pencil_Click() + { + Utility = PaintTools.Brush; + + Dialogue pencilDialogue = new Dialogue( + "Brush size", + "Please input brush size:", + new System.Collections.Generic.List() + { + new DialogueButton() + { + Text = "OK", + Callback = Pencil_Handler + }, + new DialogueButton() + { + Text = "Cancel", + } + }, + question); + + Dialog_TextBox = new Input(pencilDialogue, 80, 52, 232, 20, BrushSize.ToString()); + + WindowManager.AddWindow(pencilDialogue); + } + + private void Pencil_Handler() + { + int value = Convert.ToInt32(Dialog_TextBox.Text.Trim()); + + if (Dialog_TextBox.Text.Trim().Length == 0 || value < 1) + { + BrushSize = 1; + throw new Exception("You must input a valid brush size"); + } + + BrushSize = value; + } + + private void Bucket_Click() + { + Utility = PaintTools.Bucket; + } + + private void Text_Click() + { + Utility = PaintTools.Text; + } + + private void Rubber_Click() + { + Utility = PaintTools.Rubber; + } + + private void Text_Handler() + { + Contents.DrawString(TextX, TextY, Dialog_TextBox.Text, BetterConsole.font, SelectedColor); + } + + public override void HandleRun() + { + if (!WindowManager.AreThereDraggingWindows && Focused && IsMouseOver && IsOverPaintableArea) + { + switch (Utility) + { + case PaintTools.Brush: + WindowManager.MouseToDraw = brush; + WindowManager.MouseOffsetX = 4; + WindowManager.MouseOffsetY = 14; + break; + + case PaintTools.Bucket: + WindowManager.MouseToDraw = bucket; + break; + + case PaintTools.Text: + WindowManager.MouseToDraw = mouse_text; + break; + + case PaintTools.Rubber: + WindowManager.MouseToDraw = rubber; + break; + } + + if (MouseManager.LastMouseState == MouseState.None) + { + OldX = (int)MouseManager.X; + OldY = (int)MouseManager.Y; + } + + if (MouseManager.MouseState == MouseState.Left && (OldX != MouseManager.X || OldY != MouseManager.Y)) + { + switch (Utility) + { + case PaintTools.Brush: + DrawLine(OldX - X - 1, OldY - Y - 19, (int)MouseManager.X - X - 1, (int)MouseManager.Y - Y - 19, (ushort)BrushSize, SelectedColor); + OldX = (int)MouseManager.X; + OldY = (int)MouseManager.Y; + break; + + case PaintTools.Rubber: + DrawLine(OldX - X - 1, OldY - Y - 19, (int)MouseManager.X - X - 1, (int)MouseManager.Y - Y - 19, 10, BackgroundColor); + OldX = (int)MouseManager.X; + OldY = (int)MouseManager.Y; + break; + } + } + } + } + + public override void HandleClick(MouseEventArgs e) + { + if (IsOverPaintableArea) + { + switch (Utility) + { + case PaintTools.Bucket: + Contents.DrawFilledRectangle(0, 0, Convert.ToUInt16(Contents.Width - 2), Convert.ToUInt16(Contents.Height - 52), 0, SelectedColor); + BackgroundColor = SelectedColor; + break; + + case PaintTools.Text: + TextX = (int)MouseManager.X - X - 1; + TextY = (int)MouseManager.Y - Y - 1; + + Dialogue pencilDialogue = new Dialogue( + "Label text", + "Please input label text:", + new System.Collections.Generic.List() + { + new DialogueButton() + { + Text = "OK", + Callback = Text_Handler + }, + new DialogueButton() + { + Text = "Cancel", + } + }, + question); + + Dialog_TextBox = new Input(pencilDialogue, 80, 52, 232, 20, string.Empty); + + WindowManager.AddWindow(pencilDialogue); + break; + } + } + + if (IsOverColorTable) + SelectedColor = Contents[(int)MouseManager.X - X - 1, (int)MouseManager.Y - Y - 19]; + + RenderButtons(); + } + + private void RenderPanel() + { + Contents.DrawFilledRectangle(2, Convert.ToUInt16(Contents.Height - 52), Convert.ToUInt16(Contents.Width - 4), 50, 0, Color.DeepGray); + Contents.DrawImage(54, Convert.ToUInt16(Contents.Height - 42), colorTable, false); + RenderButtons(); + RenderSystemStyleBorder(); + } + + private void RenderButtons() + { + AboutButton.pressed = false; + AboutButton.Render(); + + foreach (var util in Utilities) + { + util.pressed = false; + util.Render(); + } + } + + /* Paint utilities */ + private void DrawPoint(int X, int Y, ushort size, Color color) + { + Contents.DrawFilledRectangle(X, Y, size, size, 0, color); + } + + private void DrawLine(int X1, int Y1, int X2, int Y2, ushort size, Color color) + { + int DX = Math.Abs(X2 - X1), SX = X1 < X2 ? 1 : -1; + int DY = Math.Abs(Y2 - Y1), SY = Y1 < Y2 ? 1 : -1; + int err = (DX > DY ? DX : -DY) / 2; + + while (X1 != X2 || Y1 != Y2) + { + DrawPoint(X1, Y1, size, color); + + int E2 = err; + + if (E2 > -DX) { err -= DY; X1 += SX; } + if (E2 < DY) { err += DX; Y1 += SY; } + } + } + } +} diff --git a/GoOS/GUI/Apps/StartMenu.cs b/GoOS/GUI/Apps/StartMenu.cs new file mode 100644 index 0000000000..33d28c25d4 --- /dev/null +++ b/GoOS/GUI/Apps/StartMenu.cs @@ -0,0 +1,164 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Cosmos.System; +using IL2CPU.API.Attribs; +using PrismAPI.Graphics; +using PrismAPI.Hardware.GPU; + +namespace GoOS.GUI.Apps +{ + public class StartMenu : Window + { + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.user.bmp")] private static byte[] userImageRaw; + private static Canvas userImage = Image.FromBitmap(userImageRaw, false); + + [ManifestResourceStream(ResourceName = "GoOS.Resources.GUI.shutdown.bmp")] private static byte[] shutdownIconRaw; + private static Canvas shutdownIcon = Image.FromBitmap(shutdownIconRaw, false); + + + List