Skip to content

Commit

Permalink
Fix potential Null at runtime & better follow Output Modes coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrcubix committed Aug 21, 2024
1 parent 7a19b26 commit 80ff7e1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
4 changes: 1 addition & 3 deletions OTD.EnhancedOutputMode.Lib/Tools/TouchSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ public void Dispose() {}
[BooleanProperty("Toggle Touch", ""),
DefaultPropertyValue(true),
ToolTip("OTD.EnhancedOutputMode:\n\n" +
"When Enabled, touch reports will be handled in Enhanced output modes."
)
]
"When Enabled, touch reports will be handled in Enhanced output modes.")]
public bool IsTouchToggled { get; set; }

[BooleanProperty("Disable When Pen in Range", ""),
Expand Down
12 changes: 6 additions & 6 deletions OTD.EnhancedOutputMode/Output/EnhancedAbsoluteOutputMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private void Initialize()
protected void UpdateTouchTransformMatrix()
{
if (Input != null && Output != null && Tablet?.Digitizer != null && TouchSettings != null)
this.touchTransformationMatrix = CalculateTouchTransformation(Input, Output, Tablet.Digitizer);
this.touchTransformationMatrix = CalculateTouchTransformation(Input, Output, Tablet.Digitizer, TouchSettings);

var halfDisplayWidth = Output?.Width / 2 ?? 0;
var halfDisplayHeight = Output?.Height / 2 ?? 0;
Expand All @@ -86,12 +86,12 @@ protected void UpdateTouchTransformMatrix()
this.max = new Vector2(maxX, maxY);
}

protected Matrix3x2 CalculateTouchTransformation(Area input, Area output, DigitizerIdentifier tablet)
protected static Matrix3x2 CalculateTouchTransformation(Area input, Area output, DigitizerIdentifier tablet, TouchSettings settings)
{
// Convert raw tablet data to millimeters
var res = Matrix3x2.CreateScale(
tablet.Width / TouchSettings.MaxX,
tablet.Height / TouchSettings.MaxY);
tablet.Width / settings.MaxX,
tablet.Height / settings.MaxY);

// Translate to the center of input area
res *= Matrix3x2.CreateTranslation(
Expand Down Expand Up @@ -150,7 +150,7 @@ public override void Read(IDeviceReport report)

protected virtual bool HandleTouch(IDeviceReport report, ITouchReport touchReport)
{
if (!TouchSettings.IsTouchToggled) return false;
if (TouchSettings == null || !TouchSettings.IsTouchToggled) return false;

// Check if the pen was in range recently and skip report if it was
if (TouchSettings.DisableWhenPenInRange)
Expand Down Expand Up @@ -186,7 +186,7 @@ protected bool ShouldReport(IDeviceReport report, ref ITabletReport tabletreport

#region Touch Transposition

protected Vector2? TransposeTouch(ITabletReport report)
public Vector2? TransposeTouch(ITabletReport report)
{
var pos = new Vector2(report.Position.X, report.Position.Y);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public override void Read(IDeviceReport report)

protected virtual bool HandleTouch(IDeviceReport report, ITouchReport touchReport)
{
if (!TouchSettings.IsTouchToggled) return false;
if (TouchSettings == null || !TouchSettings.IsTouchToggled) return false;

// Check if the pen was in range recently and skip report if it was
if (TouchSettings.DisableWhenPenInRange)
Expand Down

0 comments on commit 80ff7e1

Please sign in to comment.