Make mouse behavior better
This commit is contained in:
12
mouse.ts
12
mouse.ts
@@ -14,7 +14,7 @@ const mouseButtonsDown = {
|
||||
[M.MIDDLE]: false,
|
||||
};
|
||||
const mouseEvents: Array<{
|
||||
type: "click" | "down" | "up" | "move",
|
||||
type: "click" | "down" | "up" | "move" | "dblclick",
|
||||
button: typeof M[keyof typeof M],
|
||||
x: number,
|
||||
y: number,
|
||||
@@ -35,9 +35,9 @@ const eventPixelCoords = (evt: WindowMouseEvent) => {
|
||||
}
|
||||
}
|
||||
|
||||
// addEventListener("dblclick", (evt) => {
|
||||
// console.log("dblclick", evt.button, evt.clientX, evt.clientY);
|
||||
// });
|
||||
addEventListener("dblclick", (evt) => {
|
||||
mouseEvents.push({type: "dblclick", button: evt.button, ...eventPixelCoords(evt)});
|
||||
});
|
||||
|
||||
addEventListener("click", (evt) => {
|
||||
mouseEvents.push({type: "click", button: evt.button, ...eventPixelCoords(evt)});
|
||||
@@ -87,6 +87,10 @@ export const mouseClick = (button: number = M.LEFT) => {
|
||||
return mouseEvents.some(ev => ev.button === button && ev.type === "click");
|
||||
}
|
||||
|
||||
export const mouseDoubleClick = (button: number = M.LEFT) => {
|
||||
return mouseEvents.some(ev => ev.button === button && ev.type === "dblclick");
|
||||
}
|
||||
|
||||
export const mouseHeld = (button: number = M.LEFT) => {
|
||||
return mouseButtonsDown[button];
|
||||
}
|
||||
Reference in New Issue
Block a user