Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Web] Stylus support #3107

Merged
merged 19 commits into from
Sep 19, 2024
Merged
21 changes: 10 additions & 11 deletions src/web/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,18 @@ export function tryExtractStylusData(
return;
}

// @ts-ignore This property exists (https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent#instance_properties)
const eventAzimuthAngle = event.azimuthAngle;
// @ts-ignore This property exists (https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent#instance_properties)
const eventAltitudeAngle = event.altitudeAngle;
m-bert marked this conversation as resolved.
Show resolved Hide resolved

if (event.tiltX === 0 && event.tiltY === 0) {
// If we are in this branch, it means that either tilt properties are not supported and we have to calculate them from altitude and azimuth angles,
// or stylus is perpendicular to the screen and we can use altitude / azimuth instead of tilt

// If azimuth and altitude are undefined in this branch, it means that we are either perpendicular to the screen,
// or that none of the position sets is supported. In that case, we can treat stylus as perpendicular
//
// @ts-ignore This property exists (https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent#instance_properties)
if (event.azimuthAngle === undefined || event.altitudeAngle === undefined) {
if (eventAzimuthAngle === undefined || eventAltitudeAngle === undefined) {
return {
tiltX: 0,
tiltY: 0,
Expand All @@ -83,19 +86,15 @@ export function tryExtractStylusData(
}

const { tiltX, tiltY } = spherical2tilt(
// @ts-ignore This property exists (https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent#instance_properties)
event.altitudeAngle,
// @ts-ignore This property exists (https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent#instance_properties)
event.azimuthAngle
eventAltitudeAngle,
eventAzimuthAngle
);

return {
tiltX,
tiltY,
// @ts-ignore This property exists (https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent#instance_properties)
azimuthAngle: event.azimuthAngle,
// @ts-ignore This property exists (https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent#instance_properties)
altitudeAngle: event.altitudeAngle,
azimuthAngle: eventAzimuthAngle,
altitudeAngle: eventAltitudeAngle,
pressure: event.pressure,
};
}
Expand Down
Loading