Skip to content

Commit fbffbc1

Browse files
committed
Consistent movedX and movedY behaviour across zoom levels
1 parent 57638a0 commit fbffbc1

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/events/mouse.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -819,21 +819,27 @@ p5.prototype.mouseIsPressed = false;
819819

820820
p5.prototype._updateNextMouseCoords = function(e) {
821821
if (this._curElement !== null && (!e.touches || e.touches.length > 0)) {
822+
this._updateMouseCoords();
823+
822824
const mousePos = getMousePos(
823825
this._curElement.elt,
824826
this.width,
825827
this.height,
826828
e
827829
);
828-
this._setProperty('movedX', e.movementX);
829-
this._setProperty('movedY', e.movementY);
830+
830831
this._setProperty('mouseX', mousePos.x);
831832
this._setProperty('mouseY', mousePos.y);
832833
this._setProperty('winMouseX', mousePos.winX);
833834
this._setProperty('winMouseY', mousePos.winY);
835+
836+
const deltaX = this.mouseX - this.pmouseX;
837+
const deltaY = this.mouseY - this.pmouseY;
838+
this._setProperty('movedX', deltaX);
839+
this._setProperty('movedY', deltaY);
834840
}
841+
835842
if (!this._hasMouseInteracted) {
836-
// For first draw, make previous and next equal
837843
this._updateMouseCoords();
838844
this._setProperty('_hasMouseInteracted', true);
839845
}

0 commit comments

Comments
 (0)