Creating a GUI: The Basics

CGS Basics

In this tutorial, you will learn how to get started with the Cosmos Graphic Subsystem, CGS from here on.

Note

Some features may not be in the userkit, but as more userkits are released, more features will become more available. If you choose to download the developer kit however, you’ll have the bleeding edge version of Cosmos. This is also a tutorial for a C# kernel, so be aware of that. Cosmos is made in C#, but you can use other .NET languages, but for these purposes, C# will be used.

Steps
  1. First, put Canvas canvas; in the main kernel class public class Kernel : Sys.Kernel.
using System;
using Sys = Cosmos.System;
using Cosmos.System.Graphics;

namespace GraphicTest
{
    public class Kernel : Sys.Kernel
    {
        Canvas canvas;

        protected override void BeforeRun()
        {
  1. In a public void, type in canvas = FullScreenCanvas.GetFullScreenCanvas(); Note that it can be called from any public methods, but the main BeforeRun method is used in this example.
    In the same public void, type in canvas.Clear(Color.Blue);. You can also replace the color with anything you want.
protected override void BeforeRun()
        {
            /* If all works correctly you should not really see this :-) */
            Console.WriteLine("Cosmos booted successfully. Let's go in Graphic Mode");

            canvas = FullScreenCanvas.GetFullScreenCanvas();

            canvas.Clear(Color.Blue);
        }

        protected override void Run()
        {
  1. In the same methods, or after the canvas has been initialized, you can start playing around with methods inside of the CGS. Here’s a working example you can use of CGS. Make a new operating system and replace your Kernel.cs with the following code:
using System;
using Sys = Cosmos.System;
using Cosmos.System.Graphics;

namespace GraphicTest
{
    public class Kernel : Sys.Kernel
    {
        Canvas canvas;

        protected override void BeforeRun()
        {
            /* If all works correctly you should not really see this :-) */
            Console.WriteLine("Cosmos booted successfully. Let's go in Graphic Mode");

            canvas = FullScreenCanvas.GetFullScreenCanvas();

            canvas.Clear(Color.Blue);
        }

        protected override void Run()
        {
            try
            {
                /* A red Point */
                Pen pen = new Pen(Color.Red);
                canvas.DrawPoint(pen, 69, 69);

                /* A GreenYellow horizontal line */
                pen.Color = Color.GreenYellow;
                canvas.DrawLine(pen, 250, 100, 400, 100);

                /* An IndianRed vertical line */
                pen.Color = Color.IndianRed;
                canvas.DrawLine(pen, 350, 150, 350, 250);

                /* A MintCream diagonal line */
                pen.Color = Color.MintCream;
                canvas.DrawLine(pen, 250, 150, 400, 250);

                /* A PaleVioletRed rectangle */
                pen.Color = Color.PaleVioletRed;
                canvas.DrawRectangle(pen, 350, 350, 80, 60);

                Console.ReadKey();

                /* Let's try to change mode...*/
                canvas.Mode = new Mode(800, 600, ColorDepth.ColorDepth32);

                /* A LimeGreen rectangle */
                pen.Color = Color.LimeGreen;
                canvas.DrawRectangle(pen, 450, 450, 80, 60);

                Console.ReadKey();

                Stop();
            }
            catch (Exception e)
            {
                mDebugger.Send("Exception occurred: " + e.Message);
                mDebugger.Send(e.Message);
                Stop();
            }
        }
    }
}

Happy creating!