dotnet / Microsoft.Maui.Graphics

An experimental cross-platform native graphics library.
MIT License
682 stars 63 forks source link

Incorrect clipping on a scaled canvas #428

Open rick-palmsens opened 2 years ago

rick-palmsens commented 2 years ago

Description When applying a scale to the canvas, it limits the size at which you can clip. It seems to be inversely proportional to the scale. So a scale of 2.0 reduces the size by 50%, while 1.5 reduces the size by 33%. Either way, it makes it impossible to apply a clipping rectangle while in a scaled canvas, since it cannot be larger than canvasSize / scale. Anything beyond that is clipped either way.

This is happening with the Win2D backend, I don't know how any of the other backends behave.

Code canvas.ResetState() is used at the beginning and the end since that is also broken: #405

public void Draw(ICanvas canvas, RectF dirtyRect)
{
    canvas.ResetState();

    // Scale the canvas
    const float scale = 1.5f;
    canvas.Scale(1 / scale, 1 / scale);

    // Create a rectangle much larger than the screen
    var largeRect = Rect.FromLTRB(-100000.0, -100000.0, 100000.0, 100000.0);

    // Apply a clip rect so large that it shouldn't do anything
    canvas.ClipRectangle(largeRect);

    // Draw a rectangle that should definitely fill the entire screen
    canvas.FillColor = Colors.Red;
    canvas.FillRectangle(largeRect);

    canvas.ResetState();
}

Screenshots scale = 1.0 image

scale = 1.5 image

scale = 2.0 image

Versions

Paul-NORVEN commented 1 year ago

I have the same issue, also radial gradient is not working either!

Broken clip   gradient

All displaying fine on Mac using MacCatalyst.

Mac Working