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

[BUG] DrawingView drawing continues even after mouse release #1671

Open
2 tasks done
shineoa opened this issue Jan 31, 2024 · 4 comments
Open
2 tasks done

[BUG] DrawingView drawing continues even after mouse release #1671

shineoa opened this issue Jan 31, 2024 · 4 comments
Assignees
Labels
area/views Issue/Discussion/PR that has to do with Views bug Something isn't working

Comments

@shineoa
Copy link

shineoa commented Jan 31, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

Current Behavior

When user clicks inside the DrawingView control and starts drawing, later user releases the mous outside the DrawingView control. Afterwards user comes back the DrawingView control without pressing the mouse left button, the drawing will continue.

Expected Behavior

When user releases mouse outside the DrawingView should be considered as end of drawing. Thereafter, when user comes inside the control should not continue the drawing.

Steps To Reproduce

  1. Click the mouse left button inside the DrawingView control
  2. Do some drawing holding the mouse left button pressed
  3. Without releasing the mouse button, move outside the DrawingView control
  4. Release the mouse left button outside the DrawingView control
  5. Move the mouse without pressing left button inside DrawingView
  6. You will notice drawing is still continues, this is not the expected behavior.

Link to public reproduction project repository

Not yet

Environment

- .NET MAUI CommunityToolkit:6.0.0
- OS:Windows 10 Enterprise
- .NET MAUI:net 7.0

Anything else?

Mouse should be captured during the start of drawing, later MouseCapture release event should be listened and stop the drawing.

@shineoa shineoa added bug Something isn't working unverified labels Jan 31, 2024
@VladislavAntonyuk
Copy link
Collaborator

I am not sure we can control if the user released the button outside the control. probably the event won't be triggered.
we may probably check if mouse is pressed on entering the DrawingView and start drawing in that case

@shineoa
Copy link
Author

shineoa commented Jan 31, 2024

I think that is a decent solution for this problem.

@vhugogarcia vhugogarcia added the area/views Issue/Discussion/PR that has to do with Views label Jan 31, 2024
@VladislavAntonyuk VladislavAntonyuk self-assigned this Jan 31, 2024
@JonasSuchy
Copy link

I found a solution for anyone interested:

public class MyDrawingViewHandler : DrawingViewHandler
{
    private class MyMauiDrawingView : MauiDrawingView
    {
        protected override void OnPointerExited(PointerRoutedEventArgs e)
        {
            base.OnPointerExited(e);
            OnPointerReleased(e);
        }

        protected override void OnPointerEntered(PointerRoutedEventArgs e)
        {
            base.OnPointerEntered(e);
            if (e.Pointer.IsInContact)
                OnPointerPressed(e);
        }
    }

    protected override MauiDrawingView CreatePlatformView()
    {
        return new MyMauiDrawingView();
    }
}

This mostly replicates the behavior from other platforms, except that the drawing is restarted when the pointer enters the DrawingView, even if the mouse button was released and pressed again outside the bounds of the DrawingView.

@Toine-db
Copy link

Toine-db commented Jul 24, 2024

I had the same issue that drawing lines continued out of bounds.
It wasn't a big issue for me because it wasn't visible to the user, it happend behind other controls.

But....when using DrawingView.GetImageStream() the lines out of bound suddenly appeared in the saved/captured image.

For this I made a workaround using CaptureAsync().....for anyone interested

        if (myDrawingView.Lines.Any())
        {
            var capturedControl = await MyDrawingViewContainer.CaptureAsync();
            if (capturedControl != null)
            {
                await using var stream = await capturedControl.OpenReadAsync();
                var data = await stream.GetBytesAsync();
                
                // save image as PNG or.....
            }
        }

This crops the image to the only visible part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/views Issue/Discussion/PR that has to do with Views bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants
@Toine-db @vhugogarcia @JonasSuchy @VladislavAntonyuk @shineoa and others