Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎨 Add Alpha Color support to DrawFilledRectangle #3094

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
}
Loading