Cosmos/Demos/CosmosGraphicSubsystem/Kernel.cs
Quajak 8c70d57bed -Added new ctor from byte array of pixels
-Added note that ctor with Memory stream does not work, as memory streams do not work correctly
-Improved the cosmos graphic system example
2018-03-26 17:40:20 +02:00

121 lines
5.6 KiB
C#

using System;
using Cosmos.System.Graphics;
using Sys = Cosmos.System;
/*
* Beware Demo Kernels are not recompiled when its dependencies changes!
* To force recompilation right click on on the Cosmos icon of the demo solution and do "Build".
*/
namespace Cosmos_Graphic_Subsytem
{
public class Kernel : Sys.Kernel
{
private Canvas canvas;
private Bitmap bitmap;
protected override void BeforeRun()
{
Console.WriteLine("Cosmos booted successfully. Let's go in Graphic Mode");
Console.WriteLine("Using default graphics mode");
//Mode start = new Mode(800, 600, ColorDepth.ColorDepth32);
bitmap = new Bitmap(10, 10,
new byte[] { 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0,
255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255,
0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255,
0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 23, 59, 88, 255,
23, 59, 88, 255, 0, 255, 243, 255, 0, 255, 243, 255, 23, 59, 88, 255, 23, 59, 88, 255, 0, 255, 243, 255, 0,
255, 243, 255, 0, 255, 243, 255, 23, 59, 88, 255, 153, 57, 12, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255,
243, 255, 0, 255, 243, 255, 153, 57, 12, 255, 23, 59, 88, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243,
255, 0, 255, 243, 255, 0, 255, 243, 255, 72, 72, 72, 255, 72, 72, 72, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0,
255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 72, 72,
72, 255, 72, 72, 72, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255,
10, 66, 148, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255,
243, 255, 10, 66, 148, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 10, 66, 148, 255, 10, 66, 148, 255,
10, 66, 148, 255, 10, 66, 148, 255, 10, 66, 148, 255, 10, 66, 148, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255,
243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 10, 66, 148, 255, 10, 66, 148, 255, 10, 66, 148, 255, 10, 66, 148,
255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255,
0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, 0, 255, 243, 255, }, ColorDepth.ColorDepth32);
Console.WriteLine("Press any key to continue!");
Console.ReadKey(true);
// Create new instance of FullScreenCanvas, using default graphics mode
canvas = FullScreenCanvas.GetFullScreenCanvas(); // canvas = GetFullScreenCanvas(start);
/* Clear the Screen with the color 'Blue' */
canvas.Clear(Color.Blue);
}
protected override void Run()
{
try
{
mDebugger.Send("Run");
/* 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);
pen.Color = Color.Chartreuse;
canvas.DrawCircle(pen, 69, 69, 10);
pen.Color = Color.LightSalmon;
canvas.DrawEllipse(pen, 400, 300, 100, 150);
pen.Color = Color.MediumPurple;
canvas.DrawPolygon(pen, new Point(200, 250), new Point(250, 300), new Point(220, 350), new Point(210, 275));
canvas.DrawImage(bitmap, new Point(20, 20));
/*
* It will be really beautiful to do here:
* canvas.DrawString(pen, "Please press any key to continue the Demo...");
*/
Console.ReadKey();
/* Let's try to change mode...*/
canvas.Mode = new Mode(800, 600, ColorDepth.ColorDepth32);
//If the background is not redrawn, it gets corrupted
canvas.Clear(Color.Blue);
/* A LimeGreen rectangle */
pen.Color = Color.LimeGreen;
canvas.DrawRectangle(pen, 450, 450, 80, 60);
/* A filled rectange */
pen.Color = Color.Chocolate;
canvas.DrawFilledRectangle(pen, 200, 150, 400, 300);
/*
* It will be really beautiful to do here:
* canvas.DrawString(pen, "Please press any key to end the Demo...");
*/
Console.ReadKey();
Sys.Power.Shutdown();
}
catch (Exception e)
{
Console.WriteLine($"Got fatal exception {e.Message}");
}
}
}
}