Skip to content

Instantly share code, notes, and snippets.

@joehonton
Created February 21, 2021 03:42
Show Gist options
  • Save joehonton/9b6dbe6d6b1617c0281fc61832f381bc to your computer and use it in GitHub Desktop.
Save joehonton/9b6dbe6d6b1617c0281fc61832f381bc to your computer and use it in GitHub Desktop.
class FingerPointer {
constructor(event) {
this.pointerId = event.pointerId;
this.pointerType = event.pointerType;
this.epsilonX = event.width;
this.epsilonY = event.height;
this.initial = {
x: event.offsetX,
y: event.offsetY,
t: Date.now()
};
this.latest = {
x: event.offsetX,
y: event.offsetY,
t: Date.now()
};
this.deltaT = 0;
this.deltaX = 0;
this.deltaY = 0;
this.deltaXY = 0;
this.directionX = '';
this.directionY = '';
if (event.buttons == undefined) {
this.leftButtonDown = false;
this.wheelButtonDown = false;
this.rightButtonDown = false;
}
else {
this.leftButtonDown =
(event.buttons & 0b0001) ? true : false;
this.rightButtonDown =
(event.buttons & 0b0010) ? true : false;
this.wheelButtonDown =
(event.buttons & 0b0100) ? true : false;
}
this.ctrlKey = !!event.ctrlKey;
this.altKey = !!event.altKey;
this.shiftKey = !!event.shiftKey;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment