Skip to content

Commit

Permalink
fix: 修正触摸设备模拟的抬起逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
SlimeNull committed May 27, 2024
1 parent 9035118 commit 0b3afd5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 26 deletions.
15 changes: 6 additions & 9 deletions EleCho.WpfSuite/Utilities/MouseTouchDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,13 @@ private static void MouseUp(object sender, MouseEventArgs e)
var device = _device;
_device = null;

if (_stylusMoved)
device.Position = e.GetPosition(null);
device.ReportUp();
device.Deactivate();

if (_currentMouseUIElement is not null)
{
device.Position = e.GetPosition(null);
device.ReportUp();
device.Deactivate();

if (_currentMouseUIElement is not null)
{
e.MouseDevice.Capture(null);
}
e.MouseDevice.Capture(null);
}
}
}
Expand Down
23 changes: 7 additions & 16 deletions EleCho.WpfSuite/Utilities/StylusTouchDevice.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -68,8 +69,6 @@ private static void StylusDown(object sender, StylusDownEventArgs e)

_stylusMoved = false;
_stylusDownPosition = currentPosition;

Console.WriteLine($"Stylus down, position: {currentPosition}");
}

private static void StylusMove(object sender, StylusEventArgs e)
Expand All @@ -83,7 +82,6 @@ private static void StylusMove(object sender, StylusEventArgs e)
_device.IsActive &&
(_stylusMoved || GetPointDistance(_stylusDownPosition, currentPosition) >= GetMoveThreshold(dependencyObject)))
{
Console.WriteLine("Stylus report move");
_device.Position = currentPosition;
_device.ReportMove();

Expand All @@ -92,7 +90,6 @@ private static void StylusMove(object sender, StylusEventArgs e)
{
_currentStylusUIElement = element;
e.StylusDevice.Capture(_currentStylusUIElement, CaptureMode.SubTree);
Console.WriteLine("Stylus captured element");
}

_stylusMoved = true;
Expand All @@ -109,19 +106,13 @@ private static void StylusUp(object sender, StylusEventArgs e)
var device = _device;
_device = null;

if (_stylusMoved)
{
device.Position = e.GetPosition(null);
device.ReportUp();
device.Deactivate();

Console.WriteLine("Stylus report up");
device.Position = e.GetPosition(null);
device.ReportUp();
device.Deactivate();

if (_currentStylusUIElement is not null)
{
e.StylusDevice.Capture(null);
Console.WriteLine("Stylus released capture");
}
if (_currentStylusUIElement is not null)
{
e.StylusDevice.Capture(null);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion WpfTest/Tests/ScrollTestPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
Margin="0 0 0 24">
<TextBlock Text="Scroll Test"
FontSize="26"/>
<TextBlock Text="The content on the left can be scrolled by dragging with the mouse, and the content on the right can be scrolled by dragging with the pen." />
<TextBlock TextWrapping="Wrap"
Text="The content on the left can be scrolled by dragging with the mouse, and the content on the right can be scrolled by dragging with the pen." />
</ws:StackPanel>

<Border Grid.Row="1"
Expand Down

0 comments on commit 0b3afd5

Please sign in to comment.