-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrokenGUI.cs
More file actions
196 lines (177 loc) · 6.16 KB
/
Copy pathbrokenGUI.cs
File metadata and controls
196 lines (177 loc) · 6.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
using System;
using System.Collections.Generic;
using System.Text;
using Sys = Cosmos.System;
using Cosmos.System.Graphics;
using Cosmos.System.Network;
using Cosmos.HAL;
using Cosmos.System.Network.Config;
using Cosmos.System.Network.IPv4;
using System.IO;
using Cosmos.System.Network.IPv4.UDP.DHCP;
using System.Threading;
using Cosmos.Core;
namespace IronOS
{
public class Kernel : Sys.Kernel
{
Canvas canvas;
private string xFirstByte;
private Sys.Network.IPv4.EndPoint EndPoint;
NetworkDevice nic = NetworkDevice.GetDeviceByName("eth0");
private bool isGuiMode = false;
private int mouseX = 100;
private int mouseY = 100;
private int buttonX = 80;
private int buttonY = 100;
private int buttonWidth = 140;
private int buttonHeight = 25;
private bool mousePreviouslyDown = false;
protected override void BeforeRun()
{
IPConfig.Enable(nic, new Address(192, 168, 1, 69), new Address(255, 255, 255, 0), new Address(192, 168, 1, 254));
using (var xClient = new DHCPClient())
{
xClient.SendDiscoverPacket();
}
System.Console.ForegroundColor = ConsoleColor.Green;
System.Console.WriteLine("Iron OS Has Booted Successfully.");
System.Console.WriteLine(@"
,-. _,---._ __ / \
/ ) .-' `./ / \
( ( ,' `/ /|
\ `-"" \'\ / |
`. , \ \ / |
/`. ,'-`----Y |
( ; | '
| ,-. ,-' | /
| | ( | Iron OS | /
) | \ `.___v1.0.2__|/
`--' `--'
");
System.Console.WriteLine("Type 'help' for commands.");
}
protected override void Run()
{
if (!isGuiMode)
{
string input = System.Console.ReadLine();
HandleThisCommand(input);
}
else
{
while (isGuiMode)
{
try
{
DrawGUI();
}
catch (Exception ex)
{
System.Console.Clear();
System.Console.WriteLine("GUI Error: " + ex.Message);
isGuiMode = false;
}
}
}
}
private void DrawGUI()
{
canvas.Clear(Color.Black);
canvas.Mode = new Mode(800, 600, ColorDepth.ColorDepth32);
Pen winPen = new Pen(Color.DarkGray);
Pen borderPen = new Pen(Color.White);
Pen buttonPen = new Pen(Color.LightGray);
Pen cursorPen = new Pen(Color.Yellow);
Pen whitePen = new Pen(Color.White);
Pen blackPen = new Pen(Color.Black);
// Test square to verify graphics mode works
for (int x = 0; x < 50; x++)
{
for (int y = 0; y < 50; y++)
{
canvas.DrawPoint(whitePen, x, y);
}
}
int winX = 50, winY = 50, winWidth = 300, winHeight = 160;
for (int i = 0; i < winWidth; i++)
{
canvas.DrawPoint(borderPen, winX + i, winY);
canvas.DrawPoint(borderPen, winX + i, winY + winHeight);
}
for (int i = 0; i < winHeight; i++)
{
canvas.DrawPoint(borderPen, winX, winY + i);
canvas.DrawPoint(borderPen, winX + winWidth, winY + i);
}
for (int i = 1; i < winWidth; i++)
{
for (int j = 1; j < winHeight; j++)
{
canvas.DrawPoint(winPen, winX + i, winY + j);
}
}
canvas.DrawString("Iron OS GUI Mode", PCScreenFont.Default, whitePen, winX + 10, winY + 10);
for (int i = 0; i < buttonWidth; i++)
{
for (int j = 0; j < buttonHeight; j++)
{
canvas.DrawPoint(buttonPen, buttonX + i, buttonY + j);
}
}
canvas.DrawString("Click Me", PCScreenFont.Default, blackPen, buttonX + 30, buttonY + 5);
canvas.DrawPoint(cursorPen, mouseX, mouseY);
mouseX = (int)MouseManager.X;
mouseY = (int)MouseManager.Y;
bool mouseNowDown = MouseManager.MouseState == MouseState.Left;
if (mouseNowDown && !mousePreviouslyDown)
{
if (mouseX >= buttonX && mouseX <= buttonX + buttonWidth &&
mouseY >= buttonY && mouseY <= buttonY + buttonHeight)
{
canvas.Clear(Color.DarkBlue);
canvas.DrawString("You clicked the button!", PCScreenFont.Default, whitePen, 100, 100);
Thread.Sleep(1000);
}
}
mousePreviouslyDown = mouseNowDown;
Thread.Sleep(30);
}
private void HandleThisCommand(string input)
{
if (input == "help")
{
System.Console.WriteLine("Commands: help, about, clear, shutdown, restart, gui");
}
else if (input == "about")
{
System.Console.WriteLine("Iron OS v1.0.2 - Custom OS built using COSMOS.");
}
else if (input == "clear")
{
System.Console.Clear();
}
else if (input == "shutdown")
{
System.Console.WriteLine("Shutting down...");
Thread.Sleep(2000);
Sys.Power.Shutdown();
}
else if (input == "restart")
{
System.Console.WriteLine("Restarting...");
Thread.Sleep(2000);
Sys.Power.Reboot();
}
else if (input == "gui")
{
canvas = FullScreenCanvas.GetFullScreenCanvas();
isGuiMode = true;
}
else
{
System.Console.WriteLine("Unknown command.");
}
}
}
}