mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
WinUI and Avalonia mouse capture
This commit is contained in:
parent
716841eee2
commit
fe18d0fc3a
|
|
@ -27,11 +27,11 @@ namespace MapControl
|
|||
public static readonly StyledProperty<double> MouseWheelZoomDeltaProperty =
|
||||
DependencyPropertyHelper.Register<Map, double>(nameof(MouseWheelZoomDelta), 0.25);
|
||||
|
||||
private double mouseWheelDelta;
|
||||
private IPointer pointer1;
|
||||
private IPointer pointer2;
|
||||
private Point position1;
|
||||
private Point position2;
|
||||
private double mouseWheelDelta;
|
||||
|
||||
public ManipulationModes ManipulationModes
|
||||
{
|
||||
|
|
@ -90,35 +90,18 @@ namespace MapControl
|
|||
base.OnPointerPressed(e);
|
||||
}
|
||||
|
||||
private void HandlePointerReleased(IPointer pointer, bool releaseCapture)
|
||||
protected override void OnPointerCaptureLost(PointerCaptureLostEventArgs e)
|
||||
{
|
||||
if (pointer == pointer1 || pointer == pointer2)
|
||||
if (e.Pointer == pointer1 || e.Pointer == pointer2)
|
||||
{
|
||||
if (pointer == pointer1)
|
||||
if (e.Pointer == pointer1)
|
||||
{
|
||||
pointer1 = pointer2;
|
||||
position1 = position2;
|
||||
}
|
||||
|
||||
pointer2 = null;
|
||||
|
||||
if (releaseCapture)
|
||||
{
|
||||
pointer.Capture(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPointerReleased(PointerReleasedEventArgs e)
|
||||
{
|
||||
HandlePointerReleased(e.Pointer, true);
|
||||
|
||||
base.OnPointerReleased(e);
|
||||
}
|
||||
|
||||
protected override void OnPointerCaptureLost(PointerCaptureLostEventArgs e)
|
||||
{
|
||||
HandlePointerReleased(e.Pointer, false);
|
||||
|
||||
base.OnPointerCaptureLost(e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ namespace MapControl
|
|||
public static readonly DependencyProperty MouseWheelZoomDeltaProperty =
|
||||
DependencyPropertyHelper.Register<Map, double>(nameof(MouseWheelZoomDelta), 0.25);
|
||||
|
||||
private Point? mousePosition;
|
||||
private uint capturedPointerId;
|
||||
private double mouseWheelDelta;
|
||||
|
||||
public Map()
|
||||
|
|
@ -37,7 +37,7 @@ namespace MapControl
|
|||
|
||||
ManipulationDelta += OnManipulationDelta;
|
||||
PointerPressed += OnPointerPressed;
|
||||
PointerReleased += OnPointerReleased;
|
||||
PointerCaptureLost += OnPointerCaptureLost;
|
||||
PointerWheelChanged += OnPointerWheelChanged;
|
||||
}
|
||||
|
||||
|
|
@ -53,11 +53,9 @@ namespace MapControl
|
|||
|
||||
private void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
|
||||
{
|
||||
if (mousePosition.HasValue)
|
||||
if (capturedPointerId != 0)
|
||||
{
|
||||
var p = e.Position;
|
||||
TranslateMap(new Point(p.X - mousePosition.Value.X, p.Y - mousePosition.Value.Y));
|
||||
mousePosition = p;
|
||||
TranslateMap(e.Delta.Translation);
|
||||
}
|
||||
else if (e.PointerDeviceType != PointerDeviceType.Mouse)
|
||||
{
|
||||
|
|
@ -67,24 +65,20 @@ namespace MapControl
|
|||
|
||||
private void OnPointerPressed(object sender, PointerRoutedEventArgs e)
|
||||
{
|
||||
var point = e.GetCurrentPoint(this);
|
||||
|
||||
if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse &&
|
||||
e.KeyModifiers == VirtualKeyModifiers.None &&
|
||||
point.Properties.IsLeftButtonPressed &&
|
||||
e.GetCurrentPoint(this).Properties.IsLeftButtonPressed &&
|
||||
CapturePointer(e.Pointer))
|
||||
{
|
||||
mousePosition = point.Position;
|
||||
capturedPointerId = e.Pointer.PointerId;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPointerReleased(object sender, PointerRoutedEventArgs e)
|
||||
private void OnPointerCaptureLost(object sender, PointerRoutedEventArgs e)
|
||||
{
|
||||
if (mousePosition.HasValue &&
|
||||
e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
|
||||
if (capturedPointerId == e.Pointer.PointerId)
|
||||
{
|
||||
mousePosition = null;
|
||||
ReleasePointerCapture(e.Pointer);
|
||||
capturedPointerId = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue