Browse Source

WIP on intermediate points win

Stylus
Max Katz 4 years ago
parent
commit
c646343bee
  1. 3
      src/Avalonia.Input/PointerEventArgs.cs
  2. 17
      src/Avalonia.Input/PointerPoint.cs
  3. 10
      src/Avalonia.Input/Raw/RawPointerEventArgs.cs
  4. 141
      src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs

3
src/Avalonia.Input/PointerEventArgs.cs

@ -128,7 +128,8 @@ namespace Avalonia.Input
for (var c = 0; c < previousPoints.Count; c++)
{
var pt = previousPoints[c];
points[c] = new PointerPoint(Pointer, GetPosition(pt.Position, relativeTo), _properties);
var pointProperties = new PointerPointProperties(_properties, pt);
points[c] = new PointerPoint(Pointer, GetPosition(pt.Position, relativeTo), pointProperties);
}
points[points.Length - 1] = GetCurrentPoint(relativeTo);

17
src/Avalonia.Input/PointerPoint.cs

@ -84,6 +84,23 @@ namespace Avalonia.Input
IsBarrelButtonPressed = isBarrel;
}
internal PointerPointProperties(PointerPointProperties basedOn, Raw.RawPointerPoint rawPoint)
{
IsLeftButtonPressed = basedOn.IsLeftButtonPressed;
IsMiddleButtonPressed = basedOn.IsMiddleButtonPressed;
IsRightButtonPressed = basedOn.IsRightButtonPressed;
IsXButton1Pressed = basedOn.IsXButton1Pressed;
IsXButton2Pressed = basedOn.IsXButton2Pressed;
IsInverted = basedOn.IsInverted;
IsEraser = basedOn.IsEraser;
IsBarrelButtonPressed = basedOn.IsBarrelButtonPressed;
Twist = rawPoint.Twist;
Pressure = rawPoint.Pressure;
XTilt = rawPoint.XTilt;
YTilt = rawPoint.YTilt;
}
public static PointerPointProperties None { get; } = new PointerPointProperties();
}

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

@ -128,10 +128,16 @@ namespace Avalonia.Input.Raw
/// Pointer position, in client DIPs.
/// </summary>
public Point Position { get; set; }
public float Twist { get; set; }
public float Pressure { get; set; }
public float XTilt { get; set; }
public float YTilt { get; set; }
public RawPointerPoint()
{
Position = default;
this = default;
}
}
}

141
src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs

@ -1,4 +1,6 @@
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Text;
@ -413,78 +415,105 @@ namespace Avalonia.Win32
case WindowsMessage.WM_POINTERUPDATE:
{
GetDevicePointerInfo(wParam, out var device, out var info, ref timestamp);
Point[]? intermediatePoints = null;
if (info.pointerType == PointerInputType.PT_TOUCH
&& ShouldIgnoreTouchEmulatedMessage())
{
break;
}
var historyCount = (int)info.historyCount;
Lazy<IReadOnlyList<RawPointerPoint>> intermediatePoints = null;
if (info.historyCount > 1)
{
if (info.pointerType == PointerInputType.PT_TOUCH)
intermediatePoints = new Lazy<IReadOnlyList<RawPointerPoint>>(() =>
{
if (ShouldIgnoreTouchEmulatedMessage())
var list = new List<RawPointerPoint>(historyCount - 1);
if (info.pointerType == PointerInputType.PT_TOUCH)
{
break;
}
var pointerId = (uint)(ToInt32(wParam) & 0xFFFF);
var historyCount = (int)info.historyCount;
var historyTouchInfos = new POINTER_TOUCH_INFO[historyCount];
if (GetPointerTouchInfoHistory(pointerId, ref historyCount, historyTouchInfos))
{
//last info is the same as the current so skip it
for (int i = 0; i < historyCount - 1; i++)
var pointerId = (uint)(ToInt32(wParam) & 0xFFFF);
var historyTouchInfos = ArrayPool<POINTER_TOUCH_INFO>.Shared.Rent(historyCount);
try
{
if (GetPointerTouchInfoHistory(pointerId, ref historyCount, historyTouchInfos))
{
//last info is the same as the current so skip it
for (int i = 0; i < historyCount - 1; i++)
{
var historyTouchInfo = historyTouchInfos[i];
var historyInfo = historyTouchInfo.pointerInfo;
var historyPoint = PointToClient(new PixelPoint(
historyInfo.ptPixelLocationX, historyInfo.ptPixelLocationY));
list.Add(new RawPointerPoint
{
Position = historyPoint,
});
}
}
}
finally
{
var historyTouchInfo = historyTouchInfos[i];
var historyInfo = historyTouchInfo.pointerInfo;
var historyEventType = GetEventType(message, historyInfo);
var historyPoint = PointToClient(new PixelPoint(
historyInfo.ptPixelLocationX, historyInfo.ptPixelLocationY));
var historyModifiers = GetInputModifiers(historyInfo.dwKeyStates);
var historyTimestamp = historyInfo.dwTime == 0 ? timestamp : historyInfo.dwTime;
Input?.Invoke(new RawTouchEventArgs(_touchDevice, historyTimestamp, _owner,
historyEventType, historyPoint, historyModifiers, historyInfo.pointerId));
ArrayPool<POINTER_TOUCH_INFO>.Shared.Return(historyTouchInfos);
}
}
}
else if (info.pointerType == PointerInputType.PT_PEN)
{
var pointerId = (uint)(ToInt32(wParam) & 0xFFFF);
var historyCount = (int)info.historyCount;
var historyPenInfos = new POINTER_PEN_INFO[historyCount];
if (GetPointerPenInfoHistory(pointerId, ref historyCount, historyPenInfos))
else if (info.pointerType == PointerInputType.PT_PEN)
{
//last info is the same as the current so skip it
for (int i = 0; i < historyCount - 1; i++)
var pointerId = (uint)(ToInt32(wParam) & 0xFFFF);
var historyPenInfos = ArrayPool<POINTER_PEN_INFO>.Shared.Rent(historyCount);
try
{
var historyPenInfo = historyPenInfos[i];
var historyInfo = historyPenInfo.pointerInfo;
var historyEventType = GetEventType(message, historyInfo);
var historyPoint = PointToClient(new PixelPoint(
historyInfo.ptPixelLocationX, historyInfo.ptPixelLocationY));
var historyModifiers = GetInputModifiers(historyInfo.dwKeyStates);
var historyTimestamp = historyInfo.dwTime == 0 ? timestamp : historyInfo.dwTime;
ApplyPenInfo(historyPenInfo);
Input?.Invoke(new RawPointerEventArgs(_penDevice, historyTimestamp, _owner,
historyEventType, historyPoint, historyModifiers));
if (GetPointerPenInfoHistory(pointerId, ref historyCount, historyPenInfos))
{
//last info is the same as the current so skip it
for (int i = 0; i < historyCount - 1; i++)
{
var historyPenInfo = historyPenInfos[i];
var historyInfo = historyPenInfo.pointerInfo;
var historyPoint = PointToClient(new PixelPoint(
historyInfo.ptPixelLocationX, historyInfo.ptPixelLocationY));
list.Add(new RawPointerPoint
{
Position = historyPoint,
Pressure = historyPenInfo.pressure,
Twist = historyPenInfo.rotation,
XTilt = historyPenInfo.tiltX,
YTilt = historyPenInfo.tiltX
});
}
}
}
finally
{
ArrayPool<POINTER_PEN_INFO>.Shared.Return(historyPenInfos);
}
}
}
else
{
var pointerId = (uint)(ToInt32(wParam) & 0xFFFF);
var historyCount = (int)info.historyCount;
var historyInfos = new POINTER_INFO[historyCount];
if (GetPointerInfoHistory(pointerId, ref historyCount, historyInfos))
else
{
//last info is the same as the current so skip it
intermediatePoints = new Point[historyCount - 1];
for (int i = 0;i < historyCount - 1; i++)
var pointerId = (uint)(ToInt32(wParam) & 0xFFFF);
var historyInfos = ArrayPool<POINTER_INFO>.Shared.Rent(historyCount);
try
{
if (GetPointerInfoHistory(pointerId, ref historyCount, historyInfos))
{
//last info is the same as the current so skip it
for (int i = 0; i < historyCount - 1; i++)
{
var historyInfo = historyInfos[i];
var historyPoint = PointToClient(new PixelPoint(
historyInfo.ptPixelLocationX, historyInfo.ptPixelLocationY));
list.Add(new RawPointerPoint
{
Position = historyPoint
});
}
}
}
finally
{
var historyInfo = historyInfos[i];
intermediatePoints[i] = PointToClient(new PixelPoint(
historyInfo.ptPixelLocationX, historyInfo.ptPixelLocationY));
ArrayPool<POINTER_INFO>.Shared.Return(historyInfos);
}
}
}
return list;
});
}
var eventType = GetEventType(message, info);

Loading…
Cancel
Save