Update Map.WinUI.cs

This commit is contained in:
ClemensFischer 2025-06-11 22:39:54 +02:00
parent 71e7e29200
commit 140f800f33

View file

@ -31,11 +31,11 @@ namespace MapControl
| ManipulationModes.TranslateY
| ManipulationModes.TranslateInertia;
ManipulationDelta += OnManipulationDelta;
ManipulationCompleted += OnManipulationCompleted;
PointerWheelChanged += OnPointerWheelChanged;
PointerPressed += OnPointerPressed;
PointerMoved += OnPointerMoved;
PointerWheelChanged += OnPointerWheelChanged;
ManipulationDelta += OnManipulationDelta;
ManipulationCompleted += OnManipulationCompleted;
}
/// <summary>
@ -48,47 +48,6 @@ namespace MapControl
set => SetValue(MouseWheelZoomDeltaProperty, value);
}
private void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
if (manipulationEnabled.HasValue && manipulationEnabled.Value)
{
if (e.PointerDeviceType == PointerDeviceType.Mouse)
{
TranslateMap(e.Delta.Translation);
}
else
{
TransformMap(e.Position, e.Delta.Translation, e.Delta.Rotation, e.Delta.Scale);
}
}
}
private void OnManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
manipulationEnabled = null;
}
private void OnPointerPressed(object sender, PointerRoutedEventArgs e)
{
// Set manipulationEnabled before ManipulationStarted.
// IsLeftButtonPressed: input was triggered by the primary action mode of an input device.
//
manipulationEnabled =
e.GetCurrentPoint(this).Properties.IsLeftButtonPressed &&
e.KeyModifiers == VirtualKeyModifiers.None;
}
private void OnPointerMoved(object sender, PointerRoutedEventArgs e)
{
// Set manipulationEnabled before ManipulationStarted when no PointerPressed was received.
//
if (!manipulationEnabled.HasValue &&
e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
{
manipulationEnabled = e.KeyModifiers == VirtualKeyModifiers.None;
}
}
private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
{
if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)
@ -110,5 +69,46 @@ namespace MapControl
}
}
}
private void OnPointerPressed(object sender, PointerRoutedEventArgs e)
{
// Set manipulationEnabled before ManipulationStarted.
// IsLeftButtonPressed: input was triggered by the primary action mode of an input device.
//
manipulationEnabled =
e.GetCurrentPoint(this).Properties.IsLeftButtonPressed &&
e.KeyModifiers == VirtualKeyModifiers.None;
}
private void OnPointerMoved(object sender, PointerRoutedEventArgs e)
{
// Set manipulationEnabled before ManipulationStarted when no PointerPressed was received.
//
if (!manipulationEnabled.HasValue &&
e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
{
manipulationEnabled = e.KeyModifiers == VirtualKeyModifiers.None;
}
}
private void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
if (manipulationEnabled.HasValue && manipulationEnabled.Value)
{
if (e.PointerDeviceType == PointerDeviceType.Mouse)
{
TranslateMap(e.Delta.Translation);
}
else
{
TransformMap(e.Position, e.Delta.Translation, e.Delta.Rotation, e.Delta.Scale);
}
}
}
private void OnManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
manipulationEnabled = null;
}
}
}