-
Notifications
You must be signed in to change notification settings - Fork 981
Closed
Description
MouseDragPan still calculates mouse down pixel after UserInteractionProcessor.Disable() is called
It happens when I Drag some IAixsLine objects, I call UserInteractionProcessor.Disable() in PointerPressed callback and UserInteractionProcessor.Enable() is called when PointerReleased is fired like the demo did.
However when I release the object, plot enter pan mode automaticly and plot located to where I start dragging the object. That indicates that MouseDragPan is still calculating mouse down pixel even if UserInteractionProcessor is disabled.
ScottPlot.Avalonia 5.0.44
namespace SpeckStudio.Avalonia.Controls.Views;
public partial class ScottSignalPlotView : UserControl
{
public ScottSignalPlotView()
{
InitializeComponent();
plot.Plot.Add.Signal(ScottPlot.Generate.Sin());
plot.Plot.Add.Signal(ScottPlot.Generate.Cos());
plot.PointerPressed += Plot_PointerPressed;
plot.PointerMoved += Plot_PointerMoved;
plot.PointerReleased += Plot_PointerReleased;
var verticalLine = plot.Plot.Add.VerticalLine(0.5, 3);
verticalLine.IsDraggable = true;
verticalLine.Text = "Marker1";
var horizontalLine = plot.Plot.Add.HorizontalLine(0.5, 3);
horizontalLine.IsDraggable = true;
horizontalLine.Text = "Marker2";
horizontalLine.LabelAlignment = Alignment.MiddleRight;
}
AxisLine? PlottableBeingDragged = null;
private void Plot_PointerReleased(object sender, PointerReleasedEventArgs e)
{
PlottableBeingDragged = null;
plot.UserInputProcessor.Enable(); // enable panning again
}
private void Plot_PointerMoved(object sender, PointerEventArgs e)
{
// this rectangle is the area around the mouse in coordinate units
var position = e.GetCurrentPoint(this);
CoordinateRect rect = plot.Plot.GetCoordinateRect((float)position.Position.X, (float)position.Position.Y, radius: 10);
if (PlottableBeingDragged is null)
{
//set cursor based on what's beneath the plottable
var lineUnderMouse = GetLineUnderMouse(e);
if (lineUnderMouse is null) Cursor = new Cursor(StandardCursorType.Arrow);
else if (lineUnderMouse.IsDraggable && lineUnderMouse is VerticalLine) Cursor = new Cursor(StandardCursorType.SizeWestEast);
else if (lineUnderMouse.IsDraggable && lineUnderMouse is HorizontalLine) Cursor = new Cursor(StandardCursorType.SizeNorthSouth);
}
else
{
// update the position of the plottable being dragged
if (PlottableBeingDragged is HorizontalLine hl)
{
hl.Y = rect.VerticalCenter;
hl.Text = $"{hl.Y:0.00}";
}
else if (PlottableBeingDragged is VerticalLine vl)
{
vl.X = rect.HorizontalCenter;
vl.Text = $"{vl.X:0.00}";
}
plot.Refresh();
}
}
MouseDragPanEx dragPan = null;
private void Plot_PointerPressed(object sender, PointerPressedEventArgs e)
{
PlottableBeingDragged = GetLineUnderMouse(e);
if (PlottableBeingDragged != null)
{
plot.UserInputProcessor.Disable();
}
}
private AxisLine? GetLineUnderMouse(PointerEventArgs e)
{
var position = e.GetCurrentPoint(this);
CoordinateRect rect = plot.Plot.GetCoordinateRect((float)position.Position.X, (float)position.Position.Y, radius: 10);
foreach (AxisLine axLine in plot.Plot.GetPlottables<AxisLine>())
{
if (axLine.IsUnderMouse(rect))
return axLine;
}
return null;
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels