williamngan / pts

A library for visualization and creative-coding
https://ptsjs.org
Apache License 2.0
5.19k stars 182 forks source link

[Question] Manually provide mouse coords? #141

Open braebo opened 3 years ago

braebo commented 3 years ago

Currently, when hovering over a button or link placed on top of the canvas, the mouse position tracking is lost.

I'm using svelte, and I have easy access to the mouse coords already:

<script>
    import PT from './PT.svelte';
    let x, y;
    function mouse(e) {
        x = e.clientX;
        y = e.clientY;
    }
</script>

<svelte:window on:mousemove={(e) => mouse(e)} />

<PT {x} {y}/>

These coords are never lost regarless of what UI element I'm hovering over, so ideally I would like to just use my x and y instead of the bindMouse() function.

Unless there is a way to prevent the PT from losing the mouse position?

Thanks in advance!!

williamngan commented 3 years ago

Hi @FractalHQ -- two quick ideas:

  1. Have you tried the useCapture = true option in addEventListener?

  2. If you just want to hack it, you can try to set the internal _pointer directly. Eg, space._pointer.to(x, y).

I love Svelte though haven't spent much time in it. Hope this makes sense.