Skip to content

Commit

Permalink
Add pen as device type and pressure for iOS touch events
Browse files Browse the repository at this point in the history
  • Loading branch information
richirisu authored and mattleibow committed Feb 9, 2024
1 parent 0176323 commit 0803ef6
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,23 @@ private bool FireEvent(SKTouchAction actionType, UITouch touch, bool inContact)
var cgPoint = touch.LocationInView(View);
var point = scalePixels(cgPoint.X, cgPoint.Y);

var args = new SKTouchEventArgs(id, actionType, point, inContact);
var deviceType = GetDeviceType(touch);

var pressure = (float)touch.Force;

var args = new SKTouchEventArgs(id, actionType, SKMouseButton.Left, deviceType, point, inContact, 0, pressure);
onTouchAction(args);
return args.Handled;
}

private static SKTouchDeviceType GetDeviceType(UITouch touch) =>
touch.Type switch
{
UITouchType.Direct => SKTouchDeviceType.Touch,
UITouchType.Indirect => SKTouchDeviceType.Touch,
UITouchType.Stylus => SKTouchDeviceType.Pen,
UITouchType.IndirectPointer => SKTouchDeviceType.Touch,
_ => SKTouchDeviceType.Touch,
};
}
}

0 comments on commit 0803ef6

Please sign in to comment.