ueforth icon indicating copy to clipboard operation
ueforth copied to clipboard

mouse --> getMousePosition

Open MPETREMANN11 opened this issue 1 year ago • 0 comments

\ 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];
~

MPETREMANN11 avatar Apr 04 '23 21:04 MPETREMANN11