Question

How do i develop GUI in C# Cosmos?

cosmos OS

No correct solution

OTHER TIPS

Here is how (with milestone 5, but its similar for other versions). Cosmos does the VGA stuff for you. It also does the mouse and keyboard. I haven't been able to make a keyboard yet, but I have a working mouse (although I havent been able to find out how to see if buttons are down). Ill show you the VGA functions to get you started. First, you need this namespace:

using Cosmos.Hardware;

Then, a variable for the screen to live in. Add this class level variable:

 VGAScreen screen:

Then, to initialize it, add this code to your BeforeRun() method:

screen = new VGAScreen();
screen.SetMode320x200x8();
screen.Clear(0);

Finally, you can set the color of pixels with:

screen.SetPixel320x200x8(uint x, uint y, uint c);

You set the x any y and the color, c. Colors are in 256 color format. Math is involved to make shapes.

You'll have to write the VGA driver first. And the mouse driver. And probably get the garbage collector going. So much to do.

YES! you can, i have a some what a good gui, and a working mouse driver. so yeah, it's possible, but takes time and you need to know what to write and read when you're doing the mouse-driver, otherwise, it's possible.

I'm a big COSMOS guy, and if anyone comes across this later I want to leave a way to do it as of 10/12/2015.

Before we start I HIGHLY recommend using the devkit not the userkit. While the devkit is intended for modifying Cosmos itself, you can keep entirely away from that and close the VS window when it finishes installing. The devkit has all the features the userkit has, but the userkit only updates once every month or so, maybe more, and the devkit is updated every few days with the latest bugfixes and features. You should definitely download the devkit instead, because it has the most support too.

Alright so to get VGA, open up a new Visual Studio window. Create a new Class Library and name it whatever the heck you want.

Go to references and add a reference to Cosmos.HAL, Cosmos.Common, and Cosmos.System. You can find them at %appdata%\Roaming\Cosmos User Kit

Go into AssemblyInfo.cs and add using Cosmos.Common;, and at the bottom add the following line: [assembly: Ring(Ring.System)]

Alright great, now you need to go in and create a new class named whatever.

At the top, add a using Cosmos.HAL and using System.

Add two lines:

public static VGAScreen screen = new VGAScreen(); and public static Mouse mi = new Mouse(); Name screen and mi whatever you want.

Create an Init and Tick method named whatever.

Here's an example Init method:

public static void InitVGA() {
    //Make SURE you have this exact line or else it won't work!  Any size other than 320x200 is broken, and 8-bit is the highest VGA compatible color depth.
    screen.SetGraphicsMode(VGAScreen.ScreenSize.Size320x200, VGAScreen.ColorDepth.BitDepth8);
    //There's a bug currently where only 6-bit color is supported with 8-bit.  0x3f is pure white.
    screen.Clear(0x3f);

    //mi.Initialize(320, 200);
}

Now in the Tick method, just add whatever. Anything you want to happen every like milisecond or so. It could be, like, drawing the mouse or something. You can find that elsewhere on the internet, that's a bit of a long story.

There you go, now you have working VGA!

You can set pixels with screen.SetPixel320x200x8(x, y, color);

Applicable colors range from 0-3f. It follows the generic console colors 0-f but just adds a ton more options.

Now, just build this dll and ref it into your main OS. Now add the methods yourvgaclass.Init to the BeforeRun method in the kernel, and yourvgaclass.Tick to the Run method in the kernel.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top