-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
RawPointerEventArgs.cs
161 lines (145 loc) · 4.94 KB
/
RawPointerEventArgs.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
using System;
using System.Collections.Generic;
using Avalonia.Metadata;
namespace Avalonia.Input.Raw
{
public enum RawPointerEventType
{
LeaveWindow,
LeftButtonDown,
LeftButtonUp,
RightButtonDown,
RightButtonUp,
MiddleButtonDown,
MiddleButtonUp,
XButton1Down,
XButton1Up,
XButton2Down,
XButton2Up,
Move,
Wheel,
NonClientLeftButtonDown,
TouchBegin,
TouchUpdate,
TouchEnd,
TouchCancel,
Magnify,
Rotate,
Swipe
}
/// <summary>
/// A raw mouse event.
/// </summary>
[PrivateApi]
public class RawPointerEventArgs : RawInputEventArgs
{
private RawPointerPoint _point;
/// <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="position">The mouse position, in client DIPs.</param>
/// <param name="inputModifiers">The input modifiers.</param>
public RawPointerEventArgs(
IInputDevice device,
ulong timestamp,
IInputRoot root,
RawPointerEventType type,
Point position,
RawInputModifiers inputModifiers)
: base(device, timestamp, root)
{
Point = new RawPointerPoint();
Position = position;
Type = type;
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)
{
Point = point;
Type = type;
InputModifiers = inputModifiers;
}
/// <summary>
/// Gets the raw pointer identifier.
/// </summary>
public long RawPointerId { get; set; }
/// <summary>
/// Gets the pointer properties and position, in client DIPs.
/// </summary>
public RawPointerPoint Point
{
get => _point;
set => _point = value;
}
/// <summary>
/// Gets the mouse position, in client DIPs.
/// </summary>
public Point Position
{
get => _point.Position;
set => _point.Position = value;
}
/// <summary>
/// Gets the type of the event.
/// </summary>
public RawPointerEventType Type { get; set; }
/// <summary>
/// Gets the input modifiers.
/// </summary>
public RawInputModifiers InputModifiers { get; set; }
/// <summary>
/// Points that were traversed by a pointer since the previous relevant event,
/// only valid for Move and TouchUpdate
/// </summary>
public Lazy<IReadOnlyList<RawPointerPoint>?>? IntermediatePoints { get; set; }
internal (IInputElement? element, IInputElement? firstEnabledAncestor) InputHitTestResult { get; set; }
}
[PrivateApi]
public record struct RawPointerPoint
{
/// <summary>
/// Pointer position, in client DIPs.
/// </summary>
public Point Position { get; set; }
/// <inheritdoc cref="PointerPointProperties.Twist" />
public float Twist { get; set; }
/// <inheritdoc cref="PointerPointProperties.Pressure" />
public float Pressure { get; set; }
/// <inheritdoc cref="PointerPointProperties.XTilt" />
public float XTilt { get; set; }
/// <inheritdoc cref="PointerPointProperties.YTilt" />
public float YTilt { get; set; }
/// <inheritdoc cref="PointerPointProperties.ContactRect" />
public Rect ContactRect
{
get => _contactRect ?? new Rect(Position, new Size());
set => _contactRect = value;
}
private Rect? _contactRect;
public RawPointerPoint()
{
this = default;
Pressure = 0.5f;
}
}
}