Skip to content

Commit

Permalink
EditorCanvas would detect touch or mouse draggings
Browse files Browse the repository at this point in the history
  • Loading branch information
iconstudio committed Oct 7, 2023
1 parent b984a23 commit 363aaee
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
1 change: 1 addition & 0 deletions Editor/TestEditor/Infrastructures/EditorCanvas.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<Grid x:Name="ContentFrame"
PointerPressed="ContentFrame_PointerPressed"
PointerMoved="ContentFrame_PointerMoved"
PointerReleased="ContentFrame_PointerReleased"
PointerExited="ContentFrame_PointerExited">
<canvas:CanvasControl x:Name="Canvas"/>
Expand Down
61 changes: 57 additions & 4 deletions Editor/TestEditor/Infrastructures/EditorCanvas.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
using Microsoft.Graphics.Canvas.UI;
using Microsoft.Graphics.Canvas.UI.Xaml;
using Microsoft.UI.Input;
using Microsoft.UI.Xaml.Input;

using TestEditor.Contents;
using TestEditor.Editor;

using Windows.Foundation;

namespace TestEditor
{
public sealed partial class EditorCanvas : UserControl
public sealed partial class EditorCanvas : UserControl
{
private bool isDragging;
private PointerRoutedEventArgs lastDragArgs;

private class NullEditorPageException : NullReferenceException
{
public NullEditorPageException(string message) : base(message)
Expand Down Expand Up @@ -64,16 +69,64 @@ private void Render(CanvasControl sender, CanvasDrawEventArgs e)
}
}

private void ContentFrame_PointerPressed(object sender, PointerRoutedEventArgs e)
private void ContentFrame_PointerPressed(object _, PointerRoutedEventArgs e)
{
var point = e.GetCurrentPoint(this);
if (point.PointerDeviceType is PointerDeviceType.Touch
|| (point.PointerDeviceType is PointerDeviceType.Mouse && point.Properties.IsMiddleButtonPressed))
{
if (!isDragging)
{
isDragging = true;
lastDragArgs = e;
}
}
else if (point.Position is Point pos)
{
var x = pos.X;
var y = pos.Y;

if (point.IsInContact)
{

}
}
}
private void ContentFrame_PointerReleased(object sender, PointerRoutedEventArgs e)
private void ContentFrame_PointerMoved(object _, PointerRoutedEventArgs e)
{
var point = e.GetCurrentPoint(this);

if (isDragging && point.PointerId == lastDragArgs.Pointer.PointerId)
{

return;
}
}
private void ContentFrame_PointerReleased(object _, PointerRoutedEventArgs e)
{
var point = e.GetCurrentPoint(this);
if (point.PointerDeviceType is PointerDeviceType.Touch
|| (point.PointerDeviceType is PointerDeviceType.Mouse && point.Properties.IsMiddleButtonPressed))
{
if (isDragging && point.PointerId == lastDragArgs.Pointer.PointerId)
{
isDragging = false;
lastDragArgs = e;
}
}
}
private void ContentFrame_PointerExited(object sender, PointerRoutedEventArgs e)
private void ContentFrame_PointerExited(object _, PointerRoutedEventArgs e)
{
var point = e.GetCurrentPoint(this);

if (isDragging && point.PointerId == lastDragArgs.Pointer.PointerId)
{
isDragging = false;
lastDragArgs = e;

return;
}


}
}
Expand Down

0 comments on commit 363aaee

Please sign in to comment.