2020-01-30 20:51:29 +01:00
|
|
|
export default class Mouse
|
|
|
|
{
|
|
|
|
constructor()
|
|
|
|
{
|
|
|
|
this.isPressedLeft = false;
|
|
|
|
this.isPressedRight = false;
|
|
|
|
this.isPressedMiddle = false;
|
|
|
|
this.x = 0;
|
|
|
|
this.y = 0;
|
|
|
|
|
|
|
|
this.addListenerMouseUp();
|
|
|
|
this.addListenerMouseDown();
|
|
|
|
this.addListenerMouseMove()
|
|
|
|
}
|
|
|
|
|
|
|
|
addListenerMouseUp()
|
|
|
|
{
|
|
|
|
window.addEventListener(
|
|
|
|
'mouseup',
|
|
|
|
(event) => {
|
2020-01-30 23:40:42 +01:00
|
|
|
console.log(this);
|
|
|
|
|
2020-01-30 20:51:29 +01:00
|
|
|
switch (event.button) {
|
|
|
|
case 0:
|
|
|
|
this.isPressedLeft = false;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
this.isPressedMiddle = false;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
this.isPressedRight = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
addListenerMouseMove()
|
|
|
|
{
|
|
|
|
window.addEventListener(
|
|
|
|
'mousemove',
|
|
|
|
(event) => {
|
|
|
|
this.x = event.clientX;
|
|
|
|
this.y = event.clientY;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
addListenerMouseDown()
|
|
|
|
{
|
|
|
|
window.addEventListener(
|
|
|
|
'mousedown',
|
|
|
|
(event) => {
|
|
|
|
switch (event.button) {
|
|
|
|
case 0:
|
|
|
|
this.isPressedLeft = true;
|
2020-01-30 23:40:42 +01:00
|
|
|
console.log(this);
|
2020-01-30 20:51:29 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
this.isPressedMiddle = true;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
this.isPressedRight = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|