Skip to content

Commit

Permalink
🎨 Add Alpha Color support to DrawFilledRectangle
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicdaman authored Oct 22, 2024
1 parent e42447d commit c55e7ab
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions source/Cosmos.System2/Graphics/Canvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -569,19 +569,24 @@ public virtual void DrawRectangle(Color color, int x, int y, int width, int heig
/// <param name="height">The height of the rectangle.</param>
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);
}
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 j = yStart; j < yStart + height; j++)
{
for (int i = xStart; i < xStart + width; i++)
{
DrawPoint(color, i, j);
}
}
}

/// <summary>
Expand Down Expand Up @@ -988,4 +993,4 @@ public static Color AlphaBlend(Color to, Color from, byte alpha)
return Color.FromArgb(R, G, B);
}
}
}
}

0 comments on commit c55e7ab

Please sign in to comment.