Skip to content

Commit 12b98c8

Browse files
author
Lauren McCarthy
committed
fixes #1162 fixes #972
1 parent 1c4117f commit 12b98c8

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

src/core/core.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ var p5 = function(sketch, node, sync) {
334334
}
335335

336336
this._setProperty('frameCount', this.frameCount + 1);
337+
this._updatePMouseCoords();
338+
this._updatePTouchCoords();
337339
this.redraw();
338340
this._frameRate = 1000.0/(now - this._lastFrameTime);
339341
this._lastFrameTime = now;

src/events/mouse.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,10 @@ p5.prototype._updateMouseCoords = function(e) {
304304
if(e.type === 'touchstart' ||
305305
e.type === 'touchmove' ||
306306
e.type === 'touchend') {
307-
this._updatePTouchCoords();
308307
this._setProperty('mouseX', this.touchX);
309308
this._setProperty('mouseY', this.touchY);
310309
} else {
311310
if(this._curElement !== null) {
312-
this._updatePMouseCoords();
313311
var mousePos = getMousePos(this._curElement.elt, e);
314312
this._setProperty('mouseX', mousePos.x);
315313
this._setProperty('mouseY', mousePos.y);
@@ -430,6 +428,7 @@ p5.prototype._onmousemove = function(e){
430428
var context = this._isGlobal ? window : this;
431429
var executeDefault;
432430
this._updateMouseCoords(e);
431+
this._updateTouchCoords(e);
433432
if (!this.isMousePressed) {
434433
if (typeof context.mouseMoved === 'function') {
435434
executeDefault = context.mouseMoved(e);
@@ -449,7 +448,6 @@ p5.prototype._onmousemove = function(e){
449448
if(executeDefault === false) {
450449
e.preventDefault();
451450
}
452-
this._updateTouchCoords(e);
453451
}
454452
}
455453
};
@@ -503,6 +501,7 @@ p5.prototype._onmousedown = function(e) {
503501
this._setProperty('mouseIsPressed', true);
504502
this._setMouseButton(e);
505503
this._updateMouseCoords(e);
504+
this._updateTouchCoords(e);
506505
if (typeof context.mousePressed === 'function') {
507506
executeDefault = context.mousePressed(e);
508507
if(executeDefault === false) {
@@ -513,7 +512,6 @@ p5.prototype._onmousedown = function(e) {
513512
if(executeDefault === false) {
514513
e.preventDefault();
515514
}
516-
this._updateTouchCoords(e);
517515
}
518516
};
519517

@@ -574,7 +572,6 @@ p5.prototype._onmouseup = function(e) {
574572
if(executeDefault === false) {
575573
e.preventDefault();
576574
}
577-
this._updateTouchCoords(e);
578575
}
579576
};
580577

src/events/touch.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,20 @@ p5.prototype._updateTouchCoords = function(e) {
6969
if(e.type === 'mousedown' ||
7070
e.type === 'mousemove' ||
7171
e.type === 'mouseup'){
72-
this._updatePMouseCoords();
7372
this._setProperty('touchX', this.mouseX);
7473
this._setProperty('touchY', this.mouseY);
7574
} else {
76-
this._updatePTouchCoords();
77-
var touchInfo = getTouchInfo(this._curElement.elt, e, 0);
78-
this._setProperty('touchX', touchInfo.x);
79-
this._setProperty('touchY', touchInfo.y);
75+
if(this._curElement !== null) {
76+
var touchInfo = getTouchInfo(this._curElement.elt, e, 0);
77+
this._setProperty('touchX', touchInfo.x);
78+
this._setProperty('touchY', touchInfo.y);
8079

81-
var touches = [];
82-
for(var i = 0; i < e.touches.length; i++){
83-
touches[i] = getTouchInfo(this._curElement.elt, e, i);
80+
var touches = [];
81+
for(var i = 0; i < e.touches.length; i++){
82+
touches[i] = getTouchInfo(this._curElement.elt, e, i);
83+
}
84+
this._setProperty('touches', touches);
8485
}
85-
this._setProperty('touches', touches);
8686
}
8787
};
8888

@@ -146,6 +146,7 @@ p5.prototype._ontouchstart = function(e) {
146146
var context = this._isGlobal ? window : this;
147147
var executeDefault;
148148
this._updateTouchCoords(e);
149+
this._updateMouseCoords(e);
149150
this._setProperty('touchIsDown', true);
150151
if(typeof context.touchStarted === 'function') {
151152
executeDefault = context.touchStarted(e);
@@ -203,6 +204,7 @@ p5.prototype._ontouchmove = function(e) {
203204
var context = this._isGlobal ? window : this;
204205
var executeDefault;
205206
this._updateTouchCoords(e);
207+
this._updateMouseCoords(e);
206208
if (typeof context.touchMoved === 'function') {
207209
executeDefault = context.touchMoved(e);
208210
if(executeDefault === false) {
@@ -213,7 +215,6 @@ p5.prototype._ontouchmove = function(e) {
213215
if(executeDefault === false) {
214216
e.preventDefault();
215217
}
216-
this._updateMouseCoords(e);
217218
}
218219
};
219220

@@ -258,6 +259,7 @@ p5.prototype._ontouchmove = function(e) {
258259
*/
259260
p5.prototype._ontouchend = function(e) {
260261
this._updateTouchCoords(e);
262+
this._updateMouseCoords(e);
261263
if (this.touches.length === 0) {
262264
this._setProperty('touchIsDown', false);
263265
}
@@ -273,7 +275,6 @@ p5.prototype._ontouchend = function(e) {
273275
if(executeDefault === false) {
274276
e.preventDefault();
275277
}
276-
this._updateMouseCoords(e);
277278
}
278279
};
279280

0 commit comments

Comments
 (0)