@@ -19,11 +19,13 @@ namespace OTD.EnhancedOutputMode.Output
1919 public class EnhancedRelativeOutputMode : RelativeOutputMode , IPointerProvider < IRelativePointer >
2020 {
2121 private readonly ITabletReport _convertedReport = new TouchConvertedReport ( ) ;
22+ private readonly HPETDeltaStopwatch _touchStopwatch = new ( true ) ;
2223 private readonly HPETDeltaStopwatch _penStopwatch = new ( true ) ;
2324 private TouchSettings _touchSettings = TouchSettings . Default ;
2425 private bool _initialized = false ;
2526 private bool skipReport = false ;
2627 private int _lastTouchID = - 1 ;
28+ private Vector2 ? _lastTransformedTouchPos ;
2729 private Vector2 _lastPos ;
2830
2931 public Matrix3x2 TouchTransformationMatrix { get ; protected set ; }
@@ -37,7 +39,11 @@ public class EnhancedRelativeOutputMode : RelativeOutputMode, IPointerProvider<I
3739
3840 public IList < IAuxFilter > AuxFilters { get ; set ; } = Array . Empty < IAuxFilter > ( ) ;
3941
40- public TouchSettings TouchSettings { get ; private set ; } = TouchSettings . Default ;
42+ public TouchSettings TouchSettings
43+ {
44+ get => _touchSettings ;
45+ set => _touchSettings = value ?? TouchSettings . Default ;
46+ }
4147
4248 #region Initialization
4349
@@ -46,7 +52,7 @@ public void Initialize()
4652 if ( Elements == null )
4753 return ;
4854
49- _touchSettings = Elements . OfType < TouchSettings > ( ) . FirstOrDefault ( ) ?? TouchSettings . Default ;
55+ TouchSettings = Elements . OfType < TouchSettings > ( ) . FirstOrDefault ( ) ?? TouchSettings . Default ;
5056
5157 // Gather custom filters
5258 // TODO: someone replace this system with the IPositionedPipelineElement bullshit somehow
@@ -58,9 +64,23 @@ public void Initialize()
5864
5965 TouchTransformationMatrix = TransformationMatrix ;
6066
67+ if ( _touchSettings . MatchPenSensibilityInRelativeMode )
68+ UpdateTouchTransformMatrix ( ) ;
69+
6170 _initialized = true ;
6271 }
6372
73+ private void UpdateTouchTransformMatrix ( )
74+ {
75+ // Pen & Touch digitizer suffer from a difference in resolution,
76+ // resulting in different speeds for the same sensitivity.
77+ var XMultiplier = Tablet . Properties . Specifications . Digitizer . MaxX / _touchSettings . MaxX ;
78+ var YMultiplier = Tablet . Properties . Specifications . Digitizer . MaxY / _touchSettings . MaxY ;
79+
80+ // This should achieve about the same speed as the pen
81+ TouchTransformationMatrix = TransformationMatrix * Matrix3x2 . CreateScale ( XMultiplier , YMultiplier ) ;
82+ }
83+
6484 #endregion
6585
6686 #region Report Handling
@@ -89,6 +109,7 @@ public override void Read(IDeviceReport deviceReport)
89109 if ( _lastTouchID != TouchConvertedReport . CurrentFirstTouchID && TouchConvertedReport . CurrentFirstTouchID != - 1 )
90110 {
91111 _lastPos = _convertedReport . Position ;
112+ _lastTransformedTouchPos = null ;
92113 skipReport = true ;
93114 }
94115
@@ -99,8 +120,6 @@ public override void Read(IDeviceReport deviceReport)
99120 base . Read ( _convertedReport ) ; // We send another report instead of overwriting the touch report since plugins might rely on it
100121 else
101122 skipReport = false ;
102-
103- _lastPos = _convertedReport . Position ;
104123 }
105124 else if ( deviceReport is IAbsolutePositionReport ) // Restart the pen stopwatch when a pen report is received
106125 if ( _touchSettings . DisableWhenPenInRange )
@@ -109,6 +128,20 @@ public override void Read(IDeviceReport deviceReport)
109128 base . Read ( deviceReport ) ;
110129 }
111130
131+ protected override IAbsolutePositionReport Transform ( IAbsolutePositionReport report )
132+ {
133+ if ( report is not TouchConvertedReport )
134+ return base . Transform ( report ) ;
135+
136+ var pos = Vector2 . Transform ( report . Position , TouchTransformationMatrix ) ;
137+ var delta = pos - _lastTransformedTouchPos ;
138+ _lastTransformedTouchPos = pos ;
139+
140+ report . Position = delta . GetValueOrDefault ( ) ;
141+
142+ return report ;
143+ }
144+
112145 protected override void OnOutput ( IDeviceReport report )
113146 {
114147 if ( report is IAuxReport auxReport )
0 commit comments