2023-02-16 00:04:40 +03:00
|
|
|
export class Pointer {
|
|
|
|
static #x;
|
|
|
|
static #y;
|
|
|
|
|
|
|
|
static init() {
|
|
|
|
this.#x = 0;
|
|
|
|
this.#y = 0;
|
|
|
|
|
|
|
|
window.addEventListener('mousemove', this.mouseMove);
|
|
|
|
window.addEventListener('mousedown', this.mouseDown);
|
|
|
|
window.addEventListener('mouseup', this.mouseUp);
|
|
|
|
}
|
|
|
|
|
2023-04-06 18:03:40 +03:00
|
|
|
static set pos({ x, y }) {
|
|
|
|
this.#x = x;
|
|
|
|
this.#y = y;
|
|
|
|
}
|
2023-02-16 00:04:40 +03:00
|
|
|
static get pos() {
|
|
|
|
return { x: this.#x, y: this.#y };
|
|
|
|
}
|
|
|
|
|
|
|
|
static mouseMove = (e) => {
|
|
|
|
this.pos = { x: e.pageX, y: e.pageY };
|
2023-04-06 18:03:40 +03:00
|
|
|
};
|
2023-02-16 00:04:40 +03:00
|
|
|
|
|
|
|
static mouseDown = (e) => {
|
|
|
|
this.pos = { x: e.pageX, y: e.pageY };
|
2023-04-06 18:03:40 +03:00
|
|
|
};
|
2023-02-16 00:04:40 +03:00
|
|
|
|
|
|
|
static mouseUp = (e) => {
|
|
|
|
this.pos = { x: e.pageX, y: e.pageY };
|
2023-04-06 18:03:40 +03:00
|
|
|
};
|
2023-02-16 00:04:40 +03:00
|
|
|
}
|