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++) for (var c = 0; c < previousPoints.Count; c++)
{ {
var pt = previousPoints[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); points[points.Length - 1] = GetCurrentPoint(relativeTo);

17
src/Avalonia.Input/PointerPoint.cs

@ -84,6 +84,23 @@ namespace Avalonia.Input
IsBarrelButtonPressed = isBarrel; 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(); 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. /// Pointer position, in client DIPs.
/// </summary> /// </summary>
public Point Position { get; set; } 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() public RawPointerPoint()
{ {
Position = default; this = default;
} }
} }
} }

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

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

Loading…
Cancel
Save