FosterFramework / Foster

A small C# game framework
MIT License
422 stars 37 forks source link

Add `Batcher.ImageStretch` #78

Closed codecat closed 6 months ago

codecat commented 6 months ago

I need an ImageStretch method to render images stretched. So far I've been using the following extension method:

public static void ImageStretched(this Batcher batch, in Subtexture subtex, in Rect rect, Color color)
{
    batch.SetTexture(subtex.Texture);
    batch.Quad(
        rect.TopLeft, rect.TopRight, rect.BottomRight, rect.BottomLeft,
        subtex.TexCoords0, subtex.TexCoords1, subtex.TexCoords2, subtex.TexCoords3,
        color
    );
}

The following could be a good starting point for a PR, but decided not to make a PR right away because I wasn't sure which overloads the method should have.

public void ImageStretch(in Subtexture subtex, in Rect rect, Color color)
{
    SetTexture(subtex.Texture);
    Quad(
        rect.TopLeft, rect.TopRight, rect.BottomRight, rect.BottomLeft,
        subtex.TexCoords0, subtex.TexCoords1, subtex.TexCoords2, subtex.TexCoords3,
        color);
}

public void ImageStretch(in Subtexture subtex, in Rect rect, Color c0, Color c1, Color c2, Color c3)
{
    SetTexture(subtex.Texture);
    Quad(
        rect.TopLeft, rect.TopRight, rect.BottomRight, rect.BottomLeft,
        subtex.TexCoords0, subtex.TexCoords1, subtex.TexCoords2, subtex.TexCoords3,
        c0, c1, c2, c3);
}
kuujoo commented 6 months ago

I'm surprised that these don't exist yet. PR should be okay.