Browse Source

Introduced RawPointerPoint for usage with IntermediatePoints (#7581)

Introduced RawPointerPoint for usage with IntermediatePoints
release/0.10.13
Nikita Tsukanov 4 years ago
committed by Dan Walmsley
parent
commit
a9d683bb8f
  1. 2
      src/Avalonia.Input/MouseDevice.cs
  2. 15
      src/Avalonia.Input/PointerEventArgs.cs
  3. 58
      src/Avalonia.Input/Raw/RawPointerEventArgs.cs
  4. 10
      src/Shared/RawEventGrouping.cs

2
src/Avalonia.Input/MouseDevice.cs

@ -264,7 +264,7 @@ namespace Avalonia.Input
} }
private bool MouseMove(IMouseDevice device, ulong timestamp, IInputRoot root, Point p, PointerPointProperties properties, private bool MouseMove(IMouseDevice device, ulong timestamp, IInputRoot root, Point p, PointerPointProperties properties,
KeyModifiers inputModifiers, IReadOnlyList<Point>? intermediatePoints) KeyModifiers inputModifiers, Lazy<IReadOnlyList<RawPointerPoint>?>? intermediatePoints)
{ {
device = device ?? throw new ArgumentNullException(nameof(device)); device = device ?? throw new ArgumentNullException(nameof(device));
root = root ?? throw new ArgumentNullException(nameof(root)); root = root ?? throw new ArgumentNullException(nameof(root));

15
src/Avalonia.Input/PointerEventArgs.cs

@ -11,7 +11,7 @@ namespace Avalonia.Input
private readonly IVisual? _rootVisual; private readonly IVisual? _rootVisual;
private readonly Point _rootVisualPosition; private readonly Point _rootVisualPosition;
private readonly PointerPointProperties _properties; private readonly PointerPointProperties _properties;
private readonly IReadOnlyList<Point>? _previousPoints; private Lazy<IReadOnlyList<RawPointerPoint>?>? _previousPoints;
public PointerEventArgs(RoutedEvent routedEvent, public PointerEventArgs(RoutedEvent routedEvent,
IInteractive? source, IInteractive? source,
@ -38,7 +38,7 @@ namespace Avalonia.Input
ulong timestamp, ulong timestamp,
PointerPointProperties properties, PointerPointProperties properties,
KeyModifiers modifiers, KeyModifiers modifiers,
IReadOnlyList<Point>? previousPoints) Lazy<IReadOnlyList<RawPointerPoint>?>? previousPoints)
: this(routedEvent, source, pointer, rootVisual, rootVisualPosition, timestamp, properties, modifiers) : this(routedEvent, source, pointer, rootVisual, rootVisualPosition, timestamp, properties, modifiers)
{ {
_previousPoints = previousPoints; _previousPoints = previousPoints;
@ -121,13 +121,14 @@ namespace Avalonia.Input
/// <returns></returns> /// <returns></returns>
public IReadOnlyList<PointerPoint> GetIntermediatePoints(IVisual? relativeTo) public IReadOnlyList<PointerPoint> GetIntermediatePoints(IVisual? relativeTo)
{ {
if (_previousPoints == null || _previousPoints.Count == 0) var previousPoints = _previousPoints?.Value;
if (previousPoints == null || previousPoints.Count == 0)
return new[] { GetCurrentPoint(relativeTo) }; return new[] { GetCurrentPoint(relativeTo) };
var points = new PointerPoint[_previousPoints.Count + 1]; var points = new PointerPoint[previousPoints.Count + 1];
for (var c = 0; c < _previousPoints.Count; c++) for (var c = 0; c < previousPoints.Count; c++)
{ {
var pt = _previousPoints[c]; var pt = previousPoints[c];
points[c] = new PointerPoint(Pointer, GetPosition(pt, relativeTo), _properties); points[c] = new PointerPoint(Pointer, GetPosition(pt.Position, relativeTo), _properties);
} }
points[points.Length - 1] = GetCurrentPoint(relativeTo); points[points.Length - 1] = GetCurrentPoint(relativeTo);

58
src/Avalonia.Input/Raw/RawPointerEventArgs.cs

@ -30,6 +30,8 @@ namespace Avalonia.Input.Raw
/// </summary> /// </summary>
public class RawPointerEventArgs : RawInputEventArgs public class RawPointerEventArgs : RawInputEventArgs
{ {
private RawPointerPoint _point;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="RawPointerEventArgs"/> class. /// Initializes a new instance of the <see cref="RawPointerEventArgs"/> class.
/// </summary> /// </summary>
@ -55,11 +57,50 @@ namespace Avalonia.Input.Raw
Type = type; Type = type;
InputModifiers = inputModifiers; InputModifiers = inputModifiers;
} }
/// <summary>
/// Initializes a new instance of the <see cref="RawPointerEventArgs"/> class.
/// </summary>
/// <param name="device">The associated device.</param>
/// <param name="timestamp">The event timestamp.</param>
/// <param name="root">The root from which the event originates.</param>
/// <param name="type">The type of the event.</param>
/// <param name="point">The point properties and position, in client DIPs.</param>
/// <param name="inputModifiers">The input modifiers.</param>
public RawPointerEventArgs(
IInputDevice device,
ulong timestamp,
IInputRoot root,
RawPointerEventType type,
RawPointerPoint point,
RawInputModifiers inputModifiers)
: base(device, timestamp, root)
{
Contract.Requires<ArgumentNullException>(device != null);
Contract.Requires<ArgumentNullException>(root != null);
Point = point;
Type = type;
InputModifiers = inputModifiers;
}
/// <summary>
/// Gets the pointer properties and position, in client DIPs.
/// </summary>
public RawPointerPoint Point
{
get => _point;
set => _point = value;
}
/// <summary> /// <summary>
/// Gets the mouse position, in client DIPs. /// Gets the mouse position, in client DIPs.
/// </summary> /// </summary>
public Point Position { get; set; } public Point Position
{
get => _point.Position;
set => _point.Position = value;
}
/// <summary> /// <summary>
/// Gets the type of the event. /// Gets the type of the event.
@ -75,6 +116,19 @@ namespace Avalonia.Input.Raw
/// Points that were traversed by a pointer since the previous relevant event, /// Points that were traversed by a pointer since the previous relevant event,
/// only valid for Move and TouchUpdate /// only valid for Move and TouchUpdate
/// </summary> /// </summary>
public IReadOnlyList<Point>? IntermediatePoints { get; set; } public Lazy<IReadOnlyList<RawPointerPoint>?>? IntermediatePoints { get; set; }
}
public struct RawPointerPoint
{
/// <summary>
/// Pointer position, in client DIPs.
/// </summary>
public Point Position { get; set; }
public RawPointerPoint()
{
Position = default;
}
} }
} }

10
src/Shared/RawEventGrouping.cs

@ -53,7 +53,7 @@ internal class RawEventGrouper : IDisposable
_eventCallback?.Invoke(ev); _eventCallback?.Invoke(ev);
if (ev is RawPointerEventArgs { IntermediatePoints: PooledList<Point> list }) if (ev is RawPointerEventArgs { IntermediatePoints.Value: PooledList<RawPointerPoint> list })
list.Dispose(); list.Dispose();
if (Dispatcher.UIThread.HasJobsWithPriority(DispatcherPriority.Input + 1)) if (Dispatcher.UIThread.HasJobsWithPriority(DispatcherPriority.Input + 1))
@ -110,10 +110,14 @@ internal class RawEventGrouper : IDisposable
AddToQueue(args); AddToQueue(args);
} }
private static IReadOnlyList<RawPointerPoint> GetPooledList() => new PooledList<RawPointerPoint>();
private static readonly Func<IReadOnlyList<RawPointerPoint>> s_getPooledListDelegate = GetPooledList;
private static void MergeEvents(RawPointerEventArgs last, RawPointerEventArgs current) private static void MergeEvents(RawPointerEventArgs last, RawPointerEventArgs current)
{ {
last.IntermediatePoints ??= new PooledList<Point>();
((PooledList<Point>)last.IntermediatePoints).Add(last.Position); last.IntermediatePoints ??= new Lazy<IReadOnlyList<RawPointerPoint>?>(s_getPooledListDelegate);
((PooledList<RawPointerPoint>)last.IntermediatePoints.Value!).Add(new RawPointerPoint { Position = last.Position });
last.Position = current.Position; last.Position = current.Position;
last.Timestamp = current.Timestamp; last.Timestamp = current.Timestamp;
last.InputModifiers = current.InputModifiers; last.InputModifiers = current.InputModifiers;

Loading…
Cancel
Save