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

[Windows] Fix GraphicsView to support gestures #7077

Merged
merged 1 commit into from May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -18,7 +18,17 @@
Margin="12"
Text="Invalidate"
Clicked="OnButtonClicked"/>
<Label x:Name="labelInteractions" Margin="12" />
<StackLayout
Margin="12">
<Label
Text="GraphicsView Interactions" />
<Label
x:Name="labelInteractions" />
<Label
Text="GraphicsView Gestures" />
<Label
x:Name="labelGestures" />
</StackLayout>
<GraphicsView
x:Name="GraphicsView"
HeightRequest="500"
Expand All @@ -30,7 +40,13 @@
StartHoverInteraction="GraphicsView_StartHoverInteraction"
MoveHoverInteraction="GraphicsView_MoveHoverInteraction"
EndHoverInteraction="GraphicsView_EndHoverInteraction"
Drawable="{StaticResource GraphicsDrawable}"/>
Drawable="{StaticResource GraphicsDrawable}">
<GraphicsView.GestureRecognizers>
<TapGestureRecognizer Tapped="GraphicsView_Tapped" />
<PanGestureRecognizer PanUpdated="GraphicsView_PanUpdated" />
<PinchGestureRecognizer PinchUpdated="GraphicsView_PinchUpdated" />
</GraphicsView.GestureRecognizers>
</GraphicsView>
</StackLayout>
</views:BasePage.Content>
</views:BasePage>
Expand Up @@ -37,12 +37,30 @@ void GraphicsView_MoveHoverInteraction(object sender, TouchEventArgs e)
void GraphicsView_EndHoverInteraction(object sender, EventArgs e)
=> UpdateInteractions("End Hover");

void GraphicsView_Tapped(object sender, EventArgs args)
=> UpdateGestures("TapGestureRecognizer");

void GraphicsView_PanUpdated(object sender, PanUpdatedEventArgs args)
=> UpdateGestures("PanGestureRecognizer");

void GraphicsView_PinchUpdated(object sender, PinchGestureUpdatedEventArgs args)
=> UpdateGestures("PinchGestureRecognizer ");

void UpdateInteractions(string name, TouchEventArgs e)
{
Dispatcher.DispatchAsync(() =>
labelInteractions.Text = $"{name}: "
+ string.Join(", ", e.Touches.Select(t => $"[{Math.Round(t.X, 1)},{Math.Round(t.Y, 1)}]"))
+ $" IsInsideBounds: {e.IsInsideBounds}");

Dispatcher.DispatchAsync(() =>
labelGestures.Text = string.Empty);
}

void UpdateGestures(string name)
{
Dispatcher.DispatchAsync(() =>
labelGestures.Text = $"{name}");
}

void UpdateInteractions(string name)
Expand Down
1 change: 1 addition & 0 deletions src/Controls/src/Core/HandlerImpl/GraphicsView.Impl.cs
Expand Up @@ -34,6 +34,7 @@ public void Invalidate()
void IGraphicsView.EndHoverInteraction() => EndHoverInteraction?.Invoke(this, EventArgs.Empty);

void IGraphicsView.EndInteraction(PointF[] points, bool isInsideBounds) => EndInteraction?.Invoke(this, new TouchEventArgs(points, isInsideBounds));

void IGraphicsView.StartHoverInteraction(PointF[] points) => StartHoverInteraction?.Invoke(this, new TouchEventArgs(points, true));

void IGraphicsView.MoveHoverInteraction(PointF[] points) => MoveHoverInteraction?.Invoke(this, new TouchEventArgs(points, true));
Expand Down
15 changes: 4 additions & 11 deletions src/Core/src/Platform/Windows/PlatformTouchGraphicsView.cs
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls;
using Microsoft.Maui.Graphics.Win2D;
using Microsoft.UI.Xaml.Input;
using Microsoft.Maui.Graphics;
Expand All @@ -17,6 +14,8 @@ public class PlatformTouchGraphicsView : UserControl

public PlatformTouchGraphicsView()
{
ManipulationMode = ManipulationModes.All;

Content = _platformGraphicsView = new W2DGraphicsView();
}

Expand All @@ -36,15 +35,12 @@ PointF[] GetViewPoints(PointerRoutedEventArgs e)

protected override void OnPointerEntered(PointerRoutedEventArgs e)
{
e.Handled = true;
_isInBounds = true;
_graphicsView?.StartHoverInteraction(GetViewPoints(e));
}

protected override void OnPointerCanceled(PointerRoutedEventArgs e)
{
e.Handled = true;

if (_isTouching)
{
_isTouching = false;
Expand All @@ -55,7 +51,6 @@ protected override void OnPointerCanceled(PointerRoutedEventArgs e)

protected override void OnPointerExited(PointerRoutedEventArgs e)
{
e.Handled = true;
_isInBounds = false;

_graphicsView?.EndHoverInteraction();
Expand All @@ -69,7 +64,6 @@ protected override void OnPointerExited(PointerRoutedEventArgs e)

protected override void OnPointerMoved(PointerRoutedEventArgs e)
{
e.Handled = true;
var points = GetViewPoints(e);

_graphicsView?.MoveHoverInteraction(points);
Expand All @@ -80,7 +74,6 @@ protected override void OnPointerMoved(PointerRoutedEventArgs e)

protected override void OnPointerPressed(PointerRoutedEventArgs e)
{
e.Handled = true;
var points = GetViewPoints(e);
_isTouching = true;
_graphicsView?.StartInteraction(points);
Expand All @@ -102,4 +95,4 @@ protected override void OnPointerReleased(PointerRoutedEventArgs e)

public void Disconnect() => _graphicsView = null;
}
}
}