Mostly just for nicity. I did manually clean up a few things, but other than that, this basically was just importing configs from cvm3/crusttest, adding prettier as a dev dependency, and just ctrl-shift-I on every typescript file part of the codebase
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
function maskContains(mask: number, bit: number): boolean {
|
|
return (mask & bit) == bit;
|
|
}
|
|
|
|
export default class Mouse {
|
|
left: boolean = false;
|
|
middle: boolean = false;
|
|
right: boolean = false;
|
|
scrollDown: boolean = false;
|
|
scrollUp: boolean = false;
|
|
x: number = 0;
|
|
y: number = 0;
|
|
constructor() {}
|
|
|
|
makeMask() {
|
|
var mask = 0;
|
|
if (this.left) mask |= 1;
|
|
if (this.middle) mask |= 2;
|
|
if (this.right) mask |= 4;
|
|
if (this.scrollUp) mask |= 8;
|
|
if (this.scrollDown) mask |= 16;
|
|
return mask;
|
|
}
|
|
|
|
initFromMouseEvent(e: MouseEvent) {
|
|
this.left = maskContains(e.buttons, 1);
|
|
this.right = maskContains(e.buttons, 2);
|
|
this.middle = maskContains(e.buttons, 4);
|
|
|
|
this.x = e.offsetX;
|
|
this.y = e.offsetY;
|
|
}
|
|
|
|
// don't think there's a good way of shoehorning this in processEvent so ..
|
|
// (I guess could union e to be MouseEvent|WheelEvent and put this in there, but it'd be a
|
|
// completely unnesscary runtime check for a one-event situation, so having it be seperate
|
|
// and even call the MouseEvent implementation is more than good enough)
|
|
initFromWheelEvent(ev: WheelEvent) {
|
|
this.initFromMouseEvent(ev as MouseEvent);
|
|
|
|
// Now do the actual wheel handling
|
|
if (ev.deltaY < 0) this.scrollUp = true;
|
|
else if (ev.deltaY > 0) this.scrollDown = true;
|
|
}
|
|
}
|