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

DrawingContext state is broken in some cases #16610

Closed
VladimirDrobyshev opened this issue Aug 6, 2024 · 1 comment · Fixed by #16363
Closed

DrawingContext state is broken in some cases #16610

VladimirDrobyshev opened this issue Aug 6, 2024 · 1 comment · Fixed by #16363

Comments

@VladimirDrobyshev
Copy link
Contributor

Describe the bug

DrawingContext continues to apply transformation after its state is disposed

To Reproduce

The following control draws Pink rectange at wrong position, (300, 300) instead of (100 ,100):

using Avalonia;
using Avalonia.Controls;
using Avalonia.Media;

namespace AvaloniaTransformBug;

public partial class CustomControl : UserControl
{
    public CustomControl()
    {
        InitializeComponent();
    }

    public override void Render(DrawingContext context)
    {
        using (var clipState = context.PushClip(Bounds))
        {
            using (var optionsState = context.PushRenderOptions(new RenderOptions { EdgeMode = EdgeMode.Aliased }))
            {
                using (var transformState = context.PushTransform(Matrix.CreateTranslation(200, 200)))
                {
                    context.FillRectangle(Brushes.Goldenrod, new Rect(0, 0, 100, 100));
                }
            }
            using (var optionsState = context.PushRenderOptions(new RenderOptions { EdgeMode = EdgeMode.Aliased }))
            {
                context.FillRectangle(Brushes.DeepPink, new Rect(100, 100, 50, 50));
            }
        }
    }
}

Window:

<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:AvaloniaTransformBug"
        x:Class="AvaloniaTransformBug.MainWindow"
        Title="AvaloniaTransformBug">
    <local:CustomControl x:Name="Renderer" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="20" />
</Window>

Expected behavior

The Pink rectangle drawns at excepted position

Avalonia version

11.1.2-rc1

OS

Windows

Additional context

Actual behaviour
изображение

Excepted behaviour
изображение

@workgroupengineering
Copy link
Contributor

PR #16363 solve the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants