ueforth
ueforth copied to clipboard
mouse --> getMousePosition
\ The word mouse delivers the position of the mouse pointer from the origin x y (0, 0)
\ of the HTML page and not from the origin of the canvas.
\ The word getMousePosition retrieves and recalculates the relative position of the
\ mouse pointer from the origin of the canvas.
JSWORD: getMousePosition { -- mousex mousey }
var offset = {x: 0, y: 0};
var node = context.ctx.canvas;
while (node) {
offset.x += node.offsetLeft;
offset.y += node.offsetTop;
node = node.offsetParent;
}
return [context.mouse_x-offset.x, context.mouse_y-offset.y];
~