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

PrimitiveDrawing DrawSolidRectangle() and DrawSolidCircle() should have bool outline parameters #727

Open
ericrrichards opened this issue Mar 19, 2021 · 0 comments

Comments

@ericrrichards
Copy link

It would be helpful if the MonoGame.Extended.VectorDraw.PrimitiveDrawing class had optional parameters on the DrawSolidRectangle and DrawSolidCircle methods to fill the shape with the same color that is specified, along the pattern of the DrawSolidPolygon and DrawSolidEllipse methods. Currently there's no way to do this, and so you get a shape with the desired color only on the outline, and a 50% alpha fill color.

For example:

public void DrawSolidRectangle(Vector2 location, float width, float height, Color color, /*added optional parameter*/ bool outline=true)
{
    if (!_primitiveBatch.IsReady())
        throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything.");

    Vector2[] rectVerts = new Vector2[4]
    {
        new Vector2(0, 0),
        new Vector2(width, 0),
        new Vector2(width, height),
        new Vector2(0, height)
    };

    DrawSolidPolygon(location, rectVerts, color, /*pass parameter through*/ outline);
}
public void DrawSolidCircle(Vector2 center, float radius, Color color, /*add optional parameter*/ bool outline=true)
{
    if (!_primitiveBatch.IsReady())
        throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything.");

    const double increment = Math.PI * 2.0 / CircleSegments;
    double theta = 0.0;

    Color colorFill = color * (outline ? 0.5f : 1.0f); // same fill color logic from DrawSolidPolygon()

    Vector2 v0 = center + radius * new Vector2((float)Math.Cos(theta), (float)Math.Sin(theta));
    theta += increment;

    for (int i = 1; i < CircleSegments - 1; i++)
    {
        Vector2 v1 = center + radius * new Vector2((float)Math.Cos(theta), (float)Math.Sin(theta));
        Vector2 v2 = center + radius * new Vector2((float)Math.Cos(theta + increment), (float)Math.Sin(theta + increment));

        _primitiveBatch.AddVertex(v0, colorFill, PrimitiveType.TriangleList);
        _primitiveBatch.AddVertex(v1, colorFill, PrimitiveType.TriangleList);
        _primitiveBatch.AddVertex(v2, colorFill, PrimitiveType.TriangleList);

        theta += increment;
    }
    if (outline) // skip if not outlining, as in DrawSolidPolygon()
        DrawCircle(center, radius, color);            
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant