diff --git a/source/Cosmos.System2/Graphics/Canvas.cs b/source/Cosmos.System2/Graphics/Canvas.cs index 7cd896d4b3..a6ac312140 100644 --- a/source/Cosmos.System2/Graphics/Canvas.cs +++ b/source/Cosmos.System2/Graphics/Canvas.cs @@ -529,13 +529,17 @@ public virtual void DrawRectangle(Color color, int x, int y, int width, int heig /// The starting point Y coordinate. /// The width of the rectangle. /// The height of the rectangle. - public virtual void DrawFilledRectangle(Color color, int xStart, int yStart, int width, int height) + public virtual void DrawFilledRectangle(Color color, int xStart, int yStart, int width, int height, bool preventOffBoundPixels = true) { if (height == -1) { height = width; } - + if (preventOffBoundPixels) + { + width = Math.Min(width, (int)Mode.Width - xStart); + height = Math.Min(height, (int)Mode.Height - yStart); + } for (int y = yStart; y < yStart + height; y++) { DrawLine(color, xStart, y, xStart + width - 1, y); diff --git a/source/Cosmos.System2/Graphics/SVGAIICanvas.cs b/source/Cosmos.System2/Graphics/SVGAIICanvas.cs index c5b0b82f7f..32a01de9fe 100644 --- a/source/Cosmos.System2/Graphics/SVGAIICanvas.cs +++ b/source/Cosmos.System2/Graphics/SVGAIICanvas.cs @@ -80,12 +80,17 @@ public override void DrawPoint(Color color, int x, int y) driver.SetPixel((uint)x, (uint)y, (uint)color.ToArgb()); } - public override void DrawFilledRectangle(Color color, int xStart, int yStart, int width, int height) + public override void DrawFilledRectangle(Color color, int xStart, int yStart, int width, int height, bool preventOffBoundPixels = true) { var argb = color.ToArgb(); var frameSize = (int)driver.FrameSize; + if(preventOffBoundPixels) + { + width = Math.Min(width, (int)mode.Width - xStart); + height = Math.Min(height, (int)mode.Height - yStart); + } + - // For now write directly into video memory, once _xSVGADriver.Fill will be faster it will have to be changed for (int i = yStart; i < yStart + height; i++) { driver.videoMemory.Fill(GetPointOffset(xStart, i) + (int)frameSize, width, argb); @@ -352,7 +357,7 @@ public override void DrawImage(Image image, int x, int y, bool preventOffBoundPi var height = (int)image.Height; var frameSize = (int)driver.FrameSize; var data = image.RawData; - if(preventOffBoundPixels) + if (preventOffBoundPixels) { var maxWidth = Math.Min(width, (int)mode.Width - x); var maxHeight = Math.Min(height, (int)mode.Height - y); diff --git a/source/Cosmos.System2/Graphics/VBECanvas.cs b/source/Cosmos.System2/Graphics/VBECanvas.cs index b2c7091020..bb86dbf1be 100644 --- a/source/Cosmos.System2/Graphics/VBECanvas.cs +++ b/source/Cosmos.System2/Graphics/VBECanvas.cs @@ -248,9 +248,10 @@ public override void DrawArray(Color[] aColors, int aX, int aY, int aWidth, int } } - public override void DrawFilledRectangle(Color aColor, int aX, int aY, int aWidth, int aHeight) + public override void DrawFilledRectangle(Color aColor, int aX, int aY, int aWidth, int aHeight, bool preventOffBoundPixels = true) { // ClearVRAM clears one uint at a time. So we clear pixelwise not byte wise. That's why we divide by 32 and not 8. + if(preventOffBoundPixels) aWidth = (int)(Math.Min(aWidth, Mode.Width - aX) * (int)Mode.ColorDepth / 32); var color = aColor.ToArgb(); diff --git a/source/Cosmos.System2/Graphics/VGACanvas.cs b/source/Cosmos.System2/Graphics/VGACanvas.cs index 50934b030a..2157e06dee 100644 --- a/source/Cosmos.System2/Graphics/VGACanvas.cs +++ b/source/Cosmos.System2/Graphics/VGACanvas.cs @@ -86,8 +86,13 @@ public override void Disable() } } - public override void DrawFilledRectangle(Color aColor, int aXStart, int aYStart, int aWidth, int aHeight) + public override void DrawFilledRectangle(Color aColor, int aXStart, int aYStart, int aWidth, int aHeight, bool preventOffBoundPixels = true) { + if (preventOffBoundPixels) + { + aWidth = Math.Min(aWidth, (int)Mode.Width - aXStart); + aHeight = Math.Min(aHeight, (int)Mode.Height - aYStart); + } driver.DrawFilledRectangle(aXStart, aYStart, aWidth, aHeight, driver.GetClosestColorInPalette(aColor)); }