-
Notifications
You must be signed in to change notification settings - Fork 0
/
TabletFixes.cs
60 lines (47 loc) · 1.72 KB
/
TabletFixes.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
using System.Numerics;
using OpenTabletDriver.Plugin.Attributes;
using OpenTabletDriver.Plugin.Output;
using OpenTabletDriver.Plugin.Tablet;
namespace OpenTabletDriver.Compatibility;
[PluginName("Tablet Fixes")]
public class TabletFixes : IPositionedPipelineElement<IDeviceReport>
{
private Vector2 _lastPos;
private float _lastPressure;
public PipelinePosition Position => PipelinePosition.PreTransform;
public event Action<IDeviceReport>? Emit;
[BooleanProperty("Fix tail end", "Fixes the erroneous tail end produced by some tablets when lifting pen.")]
public bool FixTailEnd { get; set; }
[BooleanProperty("Reverse vertical tilt", "Reverses the direction of the vertical tilt.")]
public bool ReverseVerticalTilt { get; set; }
public void Consume(IDeviceReport value)
{
if (FixTailEnd)
ApplyTailEndFix(value);
if (ReverseVerticalTilt)
ApplyVerticalTiltReverse(value);
Emit?.Invoke(value);
}
private void ApplyTailEndFix(IDeviceReport value)
{
if (value is ITabletReport tabletReport)
{
if (_lastPressure > 0 && tabletReport.Pressure == 0)
{
var currentPos = tabletReport.Position;
tabletReport.Position = _lastPos;
Emit?.Invoke(tabletReport);
tabletReport.Position = currentPos;
}
_lastPos = tabletReport.Position;
_lastPressure = tabletReport.Pressure;
}
}
private static void ApplyVerticalTiltReverse(IDeviceReport value)
{
if (value is ITiltReport tiltReport)
{
tiltReport.Tilt = new Vector2(tiltReport.Tilt.X, -tiltReport.Tilt.Y);
}
}
}