bypass for browser that calculate layer*

Bypasses the kinda slow getBoundingClientRect for browsers that actually
support CSS transforms for cursors

Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>
This commit is contained in:
Victor Seiji Hariki 2022-12-07 18:45:51 -03:00
parent 9a08408456
commit 361efc76f2

View file

@ -59,8 +59,14 @@ mouse.registerContext(
"world", "world",
(evn, ctx) => { (evn, ctx) => {
// Fix because in chrome layerX and layerY simply doesnt work // Fix because in chrome layerX and layerY simply doesnt work
/** @type {HTMLDivElement} */ ctx.coords.prev.x = ctx.coords.pos.x;
const target = evn.target; ctx.coords.prev.y = ctx.coords.pos.y;
if (evn.layerX !== evn.clientX || evn.layerY !== evn.clientY) {
ctx.coords.pos.x = evn.layerX;
ctx.coords.pos.y = evn.layerY;
return;
}
// Get element bounding rect // Get element bounding rect
const bb = imageCollection.element.getBoundingClientRect(); const bb = imageCollection.element.getBoundingClientRect();
@ -78,8 +84,6 @@ mouse.registerContext(
const layerY = ((y - bb.top) / bb.height) * h; const layerY = ((y - bb.top) / bb.height) * h;
// //
ctx.coords.prev.x = ctx.coords.pos.x;
ctx.coords.prev.y = ctx.coords.pos.y;
ctx.coords.pos.x = Math.round(layerX); ctx.coords.pos.x = Math.round(layerX);
ctx.coords.pos.y = Math.round(layerY); ctx.coords.pos.y = Math.round(layerY);
}, },