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 =
|
public static readonly StyledProperty<double> MouseWheelZoomDeltaProperty =
|
||||||
DependencyPropertyHelper.Register<Map, double>(nameof(MouseWheelZoomDelta), 0.25);
|
DependencyPropertyHelper.Register<Map, double>(nameof(MouseWheelZoomDelta), 0.25);
|
||||||
|
|
||||||
private double mouseWheelDelta;
|
|
||||||
private IPointer pointer1;
|
private IPointer pointer1;
|
||||||
private IPointer pointer2;
|
private IPointer pointer2;
|
||||||
private Point position1;
|
private Point position1;
|
||||||
private Point position2;
|
private Point position2;
|
||||||
|
private double mouseWheelDelta;
|
||||||
|
|
||||||
public ManipulationModes ManipulationModes
|
public ManipulationModes ManipulationModes
|
||||||
{
|
{
|
||||||
|
|
@ -90,35 +90,18 @@ namespace MapControl
|
||||||
base.OnPointerPressed(e);
|
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;
|
pointer1 = pointer2;
|
||||||
position1 = position2;
|
position1 = position2;
|
||||||
}
|
}
|
||||||
|
|
||||||
pointer2 = null;
|
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);
|
base.OnPointerCaptureLost(e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ namespace MapControl
|
||||||
public static readonly DependencyProperty MouseWheelZoomDeltaProperty =
|
public static readonly DependencyProperty MouseWheelZoomDeltaProperty =
|
||||||
DependencyPropertyHelper.Register<Map, double>(nameof(MouseWheelZoomDelta), 0.25);
|
DependencyPropertyHelper.Register<Map, double>(nameof(MouseWheelZoomDelta), 0.25);
|
||||||
|
|
||||||
private Point? mousePosition;
|
private uint capturedPointerId;
|
||||||
private double mouseWheelDelta;
|
private double mouseWheelDelta;
|
||||||
|
|
||||||
public Map()
|
public Map()
|
||||||
|
|
@ -37,7 +37,7 @@ namespace MapControl
|
||||||
|
|
||||||
ManipulationDelta += OnManipulationDelta;
|
ManipulationDelta += OnManipulationDelta;
|
||||||
PointerPressed += OnPointerPressed;
|
PointerPressed += OnPointerPressed;
|
||||||
PointerReleased += OnPointerReleased;
|
PointerCaptureLost += OnPointerCaptureLost;
|
||||||
PointerWheelChanged += OnPointerWheelChanged;
|
PointerWheelChanged += OnPointerWheelChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -53,11 +53,9 @@ namespace MapControl
|
||||||
|
|
||||||
private void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
|
private void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (mousePosition.HasValue)
|
if (capturedPointerId != 0)
|
||||||
{
|
{
|
||||||
var p = e.Position;
|
TranslateMap(e.Delta.Translation);
|
||||||
TranslateMap(new Point(p.X - mousePosition.Value.X, p.Y - mousePosition.Value.Y));
|
|
||||||
mousePosition = p;
|
|
||||||
}
|
}
|
||||||
else if (e.PointerDeviceType != PointerDeviceType.Mouse)
|
else if (e.PointerDeviceType != PointerDeviceType.Mouse)
|
||||||
{
|
{
|
||||||
|
|
@ -67,24 +65,20 @@ namespace MapControl
|
||||||
|
|
||||||
private void OnPointerPressed(object sender, PointerRoutedEventArgs e)
|
private void OnPointerPressed(object sender, PointerRoutedEventArgs e)
|
||||||
{
|
{
|
||||||
var point = e.GetCurrentPoint(this);
|
|
||||||
|
|
||||||
if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse &&
|
if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse &&
|
||||||
e.KeyModifiers == VirtualKeyModifiers.None &&
|
e.KeyModifiers == VirtualKeyModifiers.None &&
|
||||||
point.Properties.IsLeftButtonPressed &&
|
e.GetCurrentPoint(this).Properties.IsLeftButtonPressed &&
|
||||||
CapturePointer(e.Pointer))
|
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 &&
|
if (capturedPointerId == e.Pointer.PointerId)
|
||||||
e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
|
|
||||||
{
|
{
|
||||||
mousePosition = null;
|
capturedPointerId = 0;
|
||||||
ReleasePointerCapture(e.Pointer);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue