jerosoler / Drawflow

Simple flow library 🖥️🖱️
https://jerosoler.github.io/Drawflow/
MIT License
4.41k stars 713 forks source link

Suggestion to get exact mouse position #847

Open savi8sant8s opened 3 months ago

savi8sant8s commented 3 months ago
...
if (e.type === "touchmove") {
      this.mouse_x = e_pos_x;
      this.mouse_y = e_pos_y;
}
this.dispatch('mouseMove', {x: e_pos_x,y: e_pos_y });

//Exact mouse position
const mouse_pos_x = e_pos_x * ( this.precanvas.clientWidth / (this.precanvas.clientWidth * this.zoom)) - (this.precanvas.getBoundingClientRect().x *  ( this.precanvas.clientWidth / (this.precanvas.clientWidth * this.zoom)) );
const mouse_pos_y = e_pos_y * ( this.precanvas.clientHeight / (this.precanvas.clientHeight * this.zoom)) - (this.precanvas.getBoundingClientRect().y *  ( this.precanvas.clientHeight / (this.precanvas.clientHeight * this.zoom)) );

this.dispatch('mouseMoveExact', {x: mouse_pos_x,y: mouse_pos_y });
...