Skip to content

Commit

Permalink
fixing mouseX, mouseY and touchX, touchY for noCanvas and createCanva…
Browse files Browse the repository at this point in the history
…s(0, 0) cases closes #3749
  • Loading branch information
Lauren McCarthy committed May 17, 2019
1 parent e838315 commit 9977673
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/events/mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ function getMousePos(canvas, w, h, evt) {
}
}
var rect = canvas.getBoundingClientRect();
var sx = canvas.scrollWidth / w;
var sy = canvas.scrollHeight / h;
var sx = canvas.scrollWidth / w || 1;
var sy = canvas.scrollHeight / h || 1;
return {
x: (evt.clientX - rect.left) / sx,
y: (evt.clientY - rect.top) / sy,
Expand Down
4 changes: 2 additions & 2 deletions src/events/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ p5.prototype._updateTouchCoords = function(e) {
function getTouchInfo(canvas, w, h, e, i) {
i = i || 0;
var rect = canvas.getBoundingClientRect();
var sx = canvas.scrollWidth / w;
var sy = canvas.scrollHeight / h;
var sx = canvas.scrollWidth / w || 1;
var sy = canvas.scrollHeight / h || 1;
var touch = e.touches[i] || e.changedTouches[i];
return {
x: (touch.clientX - rect.left) / sx,
Expand Down

0 comments on commit 9977673

Please sign in to comment.