using System; using System.Collections.Generic; using System.Text; using Cosmos.HAL; using System.Drawing; using static Cosmos.HAL.VGADriver; namespace Cosmos.System.Graphics { /// /// VGACanvas class. Used to control screen. /// public class VGACanvas : Canvas { /// /// Private boolean whether VGA graphics mode is enabled or not /// bool _Enabled; /// /// The HAL VGA driver /// private readonly VGADriver _VGADriver; /// /// VGA graphics mode Canvas constructor - see Canvas.cs /// /// public VGACanvas(Mode aMode) : base() { Global.mDebugger.Send("Creating VGACanvas with mode"); _VGADriver = new VGADriver(); _VGADriver.SetGraphicsMode(ModeToScreenSize(aMode), (VGADriver.ColorDepth)(int)aMode.ColorDepth); Mode = aMode; Enabled = true; } /// /// Creates a VGA graphics mode with the default mode /// public VGACanvas() : base() { Enabled = true; Mode = DefaultGraphicMode; Global.mDebugger.Send("Creating VGACanvas with standard mode"); _VGADriver = new VGADriver(); _VGADriver.SetGraphicsMode(ModeToScreenSize(DefaultGraphicMode), (VGADriver.ColorDepth)(int)DefaultGraphicMode.ColorDepth); } /// /// Gets or sets the VGA graphics mode /// public override Mode Mode { get; set; } /// /// Clears the screen of all pixels /// /// public override void Clear(Color aColor) { var paletteIndex = _VGADriver.GetClosestColorInPalette(aColor); _VGADriver.DrawFilledRectangle(0,0, _VGADriver.PixelWidth, _VGADriver.PixelHeight, paletteIndex); } /// /// Disables VGA graphics mode, parent method returns to 80x25 text mode /// public override void Disable() { if (Enabled) { Enabled = false; } } /// /// Draws an array of colors /// /// /// /// /// public override void DrawArray(Color[] aColors, Point aPoint, int aWidth, int aHeight) { base.DrawArray(aColors, aPoint, aWidth, aHeight); } /// /// Draws an array of colors, specifiying X and Y coords /// /// /// /// /// /// public override void DrawArray(Color[] aColors, int aX, int aY, int aWidth, int aHeight) { throw new NotImplementedException(); } /// /// Draws a circle /// /// /// /// /// public override void DrawCircle(Pen aPen, int aXCenter, int aYCenter, int aRadius) { base.DrawCircle(aPen, aXCenter, aYCenter, aRadius); } /// /// Draws a circle /// /// /// /// public override void DrawCircle(Pen aPen, Point aPoint, int aRadius) { base.DrawCircle(aPen, aPoint, aRadius); } /// /// Draws an ellipse /// /// /// /// /// /// public override void DrawEllipse(Pen aPen, int aXCenter, int aYCenter, int aXRadius, int aYRadius) { base.DrawEllipse(aPen, aXCenter, aYCenter, aXRadius, aYRadius); } /// /// Draws an ellipse /// /// /// /// /// public override void DrawEllipse(Pen aPen, Point aPoint, int aXRadius, int aYRadius) { base.DrawEllipse(aPen, aPoint, aXRadius, aYRadius); } /// /// Draws a filled circle /// /// /// /// /// public override void DrawFilledCircle(Pen aPen, int aX0, int aY0, int aRadius) { base.DrawFilledCircle(aPen, aX0, aY0, aRadius); } /// /// Draws a filled circle /// /// /// /// public override void DrawFilledCircle(Pen aPen, Point aPoint, int aRadius) { base.DrawFilledCircle(aPen, aPoint, aRadius); } /// /// Draws a filled ellipse /// /// /// /// /// public override void DrawFilledEllipse(Pen aPen, Point aPoint, int aHeight, int aWidth) { base.DrawFilledEllipse(aPen, aPoint, aHeight, aWidth); } /// /// Draws a filled ellipse /// /// /// /// /// /// public override void DrawFilledEllipse(Pen aPen, int aX, int aY, int aHeight, int aWidth) { base.DrawFilledEllipse(aPen, aX, aY, aHeight, aWidth); } /// /// Draws a filled rectangle /// /// /// /// /// public override void DrawFilledRectangle(Pen aPen, Point aPoint, int aWidth, int aHeight) { DrawFilledRectangle(aPen, aPoint.X, aPoint.Y, aWidth, aHeight); } /// /// Draws a filled rectangle /// /// /// /// /// /// public override void DrawFilledRectangle(Pen aPen, int aXStart, int aYStart, int aWidth, int aHeight) { _VGADriver.DrawFilledRectangle(aXStart, aYStart, aWidth, aHeight, _VGADriver.GetClosestColorInPalette(aPen.Color)); } /// /// Draws a line (in the sand?) /// /// /// /// /// /// public override void DrawLine(Pen aPen, int aX1, int aY1, int aX2, int aY2) { base.DrawLine(aPen, aX1, aY1, aX2, aY2); } /// /// Draws a point /// /// /// /// public override void DrawPoint(Pen aPen, int aX, int aY) { _VGADriver.SetPixel((uint)aX, (uint)aY, aPen.Color); } /// /// Draws a point /// /// /// /// public void DrawPoint(uint aColor, int aX, int aY) { _VGADriver.SetPixel((uint)aX, (uint)aY, aColor); } /// /// Draws a point /// /// /// /// public override void DrawPoint(Pen aPen, float aX, float aY) { throw new NotImplementedException(); } /// /// Draws a polygon /// /// /// public override void DrawPolygon(Pen aPen, params Point[] aPoints) { base.DrawPolygon(aPen, aPoints); } /// /// Draws a rectangle /// /// /// /// /// public override void DrawRectangle(Pen aPen, Point aPoint, int aWidth, int aHeight) { base.DrawRectangle(aPen, aPoint, aWidth, aHeight); } /// /// Draws a rectangle /// /// /// /// /// /// public override void DrawRectangle(Pen aPen, int aX, int aY, int aWidth, int aHeight) { base.DrawRectangle(aPen, aX, aY, aWidth, aHeight); } /// /// Draws a square /// /// /// /// public override void DrawSquare(Pen aPen, Point aPoint, int aSize) { base.DrawSquare(aPen, aPoint, aSize); } /// /// Draws a square /// /// /// /// /// public override void DrawSquare(Pen aPen, int aX, int aY, int aSize) { base.DrawSquare(aPen, aX, aY, aSize); } /// /// Draws a triangle /// /// /// /// /// public override void DrawTriangle(Pen aPen, Point aPoint0, Point aPoint1, Point aPoint2) { base.DrawTriangle(aPen, aPoint0, aPoint1, aPoint2); } /// /// Draws a triangle /// /// /// /// /// /// /// /// public override void DrawTriangle(Pen aPen, int aV1x, int aV1y, int aV2x, int aV2y, int aV3x, int aV3y) { base.DrawTriangle(aPen, aV1x, aV1y, aV2x, aV2y, aV3x, aV3y); } /// /// List of available resolutions /// private static readonly List _AvailableModes = new List { new Mode(640, 480, ColorDepth.ColorDepth4), new Mode(720, 480, ColorDepth.ColorDepth4), new Mode(320, 200, ColorDepth.ColorDepth8) }; public override List AvailableModes { get { return _AvailableModes; } } /// /// Retrieves the RGB value of a specified pixel /// /// /// /// public override Color GetPointColor(int aX, int aY) { return Color.FromArgb((int)(_VGADriver.GetPixel((uint)aX, (uint)aY))); } /// /// The default graphics mode /// public override Mode DefaultGraphicMode => new Mode(640, 480, ColorDepth.ColorDepth4); /// /// Boolean value whether VGA is in graphics mode or not /// public bool Enabled { get => _Enabled; private set => _Enabled = value; } private ScreenSize ModeToScreenSize(Mode aMode) { if (aMode.Columns == 320 && aMode.Rows == 200) { return ScreenSize.Size320x200; } else if (aMode.Columns == 640 && aMode.Rows == 480) { return ScreenSize.Size640x480; } else if (aMode.Columns == 720 && aMode.Rows == 480) { return ScreenSize.Size720x480; } else { throw new NotImplementedException(); } } public override void Display() { } } }