Skip to content

Commit ab8ae50

Browse files
author
lauren mccarthy
committed
moving update coords per issue #367
1 parent 62e8e86 commit ab8ae50

File tree

5 files changed

+92
-56
lines changed

5 files changed

+92
-56
lines changed

lib/p5.js

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! p5.js v0.3.5 September 09, 2014 */
1+
/*! p5.js v0.3.5 September 11, 2014 */
22
var shim = function (require) {
33
window.requestDraw = function () {
44
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback, element) {
@@ -199,6 +199,8 @@ var core = function (require, shim, constants) {
199199
f.call(this);
200200
});
201201
userDraw();
202+
this._updatePMouseCoords();
203+
this._updatePTouchCoords();
202204
this._registeredMethods.post.forEach(function (f) {
203205
f.call(this);
204206
});
@@ -2953,30 +2955,32 @@ var inputmouse = function (require, core, constants) {
29532955
p5.prototype.mouseButton = 0;
29542956
p5.prototype.mouseIsPressed = false;
29552957
p5.prototype.isMousePressed = false;
2956-
p5.prototype.updateMouseCoords = function (e) {
2957-
var mousePos = getMousePos(this._curElement.elt, e);
2958-
this._setProperty('pmouseX', this.mouseX);
2959-
this._setProperty('pmouseY', this.mouseY);
2958+
p5.prototype._updateMouseCoords = function (e) {
29602959
if (e.type === 'touchstart' || e.type === 'touchmove') {
29612960
this._setProperty('mouseX', this.touchX);
29622961
this._setProperty('mouseY', this.touchY);
29632962
} else {
2963+
var mousePos = getMousePos(this._curElement.elt, e);
29642964
this._setProperty('mouseX', mousePos.x);
29652965
this._setProperty('mouseY', mousePos.y);
29662966
}
2967-
this._setProperty('pwinMouseX', this.winMouseX);
2968-
this._setProperty('pwinMouseY', this.winMouseY);
29692967
this._setProperty('winMouseX', e.pageX);
29702968
this._setProperty('winMouseY', e.pageY);
29712969
};
2970+
p5.prototype._updatePMouseCoords = function (e) {
2971+
this._setProperty('pmouseX', this.mouseX);
2972+
this._setProperty('pmouseY', this.mouseY);
2973+
this._setProperty('pwinMouseX', this.winMouseX);
2974+
this._setProperty('pwinMouseY', this.winMouseY);
2975+
};
29722976
function getMousePos(canvas, evt) {
29732977
var rect = canvas.getBoundingClientRect();
29742978
return {
29752979
x: evt.clientX - rect.left,
29762980
y: evt.clientY - rect.top
29772981
};
29782982
}
2979-
p5.prototype.setMouseButton = function (e) {
2983+
p5.prototype._setMouseButton = function (e) {
29802984
if (e.button === 1) {
29812985
this._setProperty('mouseButton', constants.CENTER);
29822986
} else if (e.button === 2) {
@@ -2992,7 +2996,7 @@ var inputmouse = function (require, core, constants) {
29922996
p5.prototype.onmousemove = function (e) {
29932997
var context = this._isGlobal ? window : this;
29942998
var executeDefault;
2995-
this.updateMouseCoords(e);
2999+
this._updateMouseCoords(e);
29963000
if (!this.isMousePressed) {
29973001
if (typeof context.mouseMoved === 'function') {
29983002
executeDefault = context.mouseMoved(e);
@@ -3011,7 +3015,7 @@ var inputmouse = function (require, core, constants) {
30113015
if (!executeDefault) {
30123016
e.preventDefault();
30133017
}
3014-
this.setTouchPoints(e);
3018+
this._updateTouchCoords(e);
30153019
}
30163020
}
30173021
};
@@ -3020,7 +3024,7 @@ var inputmouse = function (require, core, constants) {
30203024
var executeDefault;
30213025
this._setProperty('isMousePressed', true);
30223026
this._setProperty('mouseIsPressed', true);
3023-
this.setMouseButton(e);
3027+
this._setMouseButton(e);
30243028
if (typeof context.mousePressed === 'function') {
30253029
executeDefault = context.mousePressed(e);
30263030
if (executeDefault !== undefined && !executeDefault) {
@@ -3031,7 +3035,7 @@ var inputmouse = function (require, core, constants) {
30313035
if (!executeDefault) {
30323036
e.preventDefault();
30333037
}
3034-
this.setTouchPoints(e);
3038+
this._updateTouchCoords(e);
30353039
}
30363040
};
30373041
p5.prototype.onmouseup = function (e) {
@@ -3049,7 +3053,7 @@ var inputmouse = function (require, core, constants) {
30493053
if (!executeDefault) {
30503054
e.preventDefault();
30513055
}
3052-
this.setTouchPoints(e);
3056+
this._updateTouchCoords(e);
30533057
}
30543058
};
30553059
p5.prototype.onclick = function (e) {
@@ -3103,15 +3107,16 @@ var inputtouch = function (require, core) {
31033107
var p5 = core;
31043108
p5.prototype.touchX = 0;
31053109
p5.prototype.touchY = 0;
3110+
p5.prototype.ptouchX = 0;
3111+
p5.prototype.ptouchY = 0;
31063112
p5.prototype.touches = [];
3107-
p5.prototype.setTouchPoints = function (e) {
3108-
var context = this._isGlobal ? window : this;
3113+
p5.prototype._updateTouchCoords = function (e) {
31093114
if (e.type === 'mousedown' || e.type === 'mousemove') {
3110-
context._setProperty('touchX', context.mouseX);
3111-
context._setProperty('touchY', context.mouseY);
3115+
this._setProperty('touchX', this.mouseX);
3116+
this._setProperty('touchY', this.mouseY);
31123117
} else {
3113-
context._setProperty('touchX', e.changedTouches[0].pageX);
3114-
context._setProperty('touchY', e.changedTouches[0].pageY);
3118+
this._setProperty('touchX', e.changedTouches[0].pageX);
3119+
this._setProperty('touchY', e.changedTouches[0].pageY);
31153120
var touches = [];
31163121
for (var i = 0; i < e.changedTouches.length; i++) {
31173122
var ct = e.changedTouches[i];
@@ -3120,13 +3125,17 @@ var inputtouch = function (require, core) {
31203125
y: ct.pageY
31213126
};
31223127
}
3123-
context._setProperty('touches', touches);
3128+
this._setProperty('touches', touches);
31243129
}
31253130
};
3131+
p5.prototype._updatePTouchCoords = function () {
3132+
this._setProperty('ptouchX', this.touchX);
3133+
this._setProperty('ptouchY', this.touchY);
3134+
};
31263135
p5.prototype.ontouchstart = function (e) {
31273136
var context = this._isGlobal ? window : this;
31283137
var executeDefault;
3129-
this.setTouchPoints(e);
3138+
this._updateTouchCoords(e);
31303139
if (typeof context.touchStarted === 'function') {
31313140
executeDefault = context.touchStarted(e);
31323141
if (!executeDefault) {
@@ -3137,13 +3146,12 @@ var inputtouch = function (require, core) {
31373146
if (!executeDefault) {
31383147
e.preventDefault();
31393148
}
3140-
this.setMouseButton(e);
31413149
}
31423150
};
31433151
p5.prototype.ontouchmove = function (e) {
31443152
var context = this._isGlobal ? window : this;
31453153
var executeDefault;
3146-
this.setTouchPoints(e);
3154+
this._updateTouchCoords(e);
31473155
if (typeof context.touchMoved === 'function') {
31483156
executeDefault = context.touchMoved(e);
31493157
if (!executeDefault) {
@@ -3154,7 +3162,7 @@ var inputtouch = function (require, core) {
31543162
if (!executeDefault) {
31553163
e.preventDefault();
31563164
}
3157-
this.updateMouseCoords(e);
3165+
this._updateMouseCoords(e);
31583166
}
31593167
};
31603168
p5.prototype.ontouchend = function (e) {
@@ -3170,7 +3178,7 @@ var inputtouch = function (require, core) {
31703178
if (!executeDefault) {
31713179
e.preventDefault();
31723180
}
3173-
this.updateMouseCoords(e);
3181+
this._updateMouseCoords(e);
31743182
}
31753183
};
31763184
return p5;

lib/p5.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/core.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ define(function (require) {
280280
f.call(this);
281281
});
282282
userDraw();
283+
this._updatePMouseCoords();
284+
this._updatePTouchCoords();
283285
// call any registered post functions
284286
this._registeredMethods.post.forEach(function(f) {
285287
f.call(this);

src/input/mouse.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,24 +100,26 @@ define(function (require) {
100100
p5.prototype.mouseIsPressed = false;
101101
p5.prototype.isMousePressed = false; // both are supported
102102

103-
p5.prototype.updateMouseCoords = function(e) {
104-
var mousePos = getMousePos(this._curElement.elt, e);
105-
106-
this._setProperty('pmouseX', this.mouseX);
107-
this._setProperty('pmouseY', this.mouseY);
103+
p5.prototype._updateMouseCoords = function(e) {
108104
if(e.type === 'touchstart' || e.type === 'touchmove') {
109105
this._setProperty('mouseX', this.touchX);
110106
this._setProperty('mouseY', this.touchY);
111107
} else {
108+
var mousePos = getMousePos(this._curElement.elt, e);
112109
this._setProperty('mouseX', mousePos.x);
113110
this._setProperty('mouseY', mousePos.y);
114111
}
115-
this._setProperty('pwinMouseX', this.winMouseX);
116-
this._setProperty('pwinMouseY', this.winMouseY);
117112
this._setProperty('winMouseX', e.pageX);
118113
this._setProperty('winMouseY', e.pageY);
119114
};
120115

116+
p5.prototype._updatePMouseCoords = function(e) {
117+
this._setProperty('pmouseX', this.mouseX);
118+
this._setProperty('pmouseY', this.mouseY);
119+
this._setProperty('pwinMouseX', this.winMouseX);
120+
this._setProperty('pwinMouseY', this.winMouseY);
121+
};
122+
121123
function getMousePos(canvas, evt) {
122124
var rect = canvas.getBoundingClientRect();
123125
return {
@@ -126,7 +128,7 @@ define(function (require) {
126128
};
127129
}
128130

129-
p5.prototype.setMouseButton = function(e) {
131+
p5.prototype._setMouseButton = function(e) {
130132
if (e.button === 1) {
131133
this._setProperty('mouseButton', constants.CENTER);
132134
} else if (e.button === 2) {
@@ -195,7 +197,7 @@ define(function (require) {
195197
p5.prototype.onmousemove = function(e){
196198
var context = this._isGlobal ? window : this;
197199
var executeDefault;
198-
this.updateMouseCoords(e);
200+
this._updateMouseCoords(e);
199201
if (!this.isMousePressed) {
200202
if (typeof context.mouseMoved === 'function') {
201203
executeDefault = context.mouseMoved(e);
@@ -215,7 +217,7 @@ define(function (require) {
215217
if(!executeDefault) {
216218
e.preventDefault();
217219
}
218-
this.setTouchPoints(e);
220+
this._updateTouchCoords(e);
219221
}
220222
}
221223
};
@@ -255,7 +257,7 @@ define(function (require) {
255257
var executeDefault;
256258
this._setProperty('isMousePressed', true);
257259
this._setProperty('mouseIsPressed', true);
258-
this.setMouseButton(e);
260+
this._setMouseButton(e);
259261
if (typeof context.mousePressed === 'function') {
260262
executeDefault = context.mousePressed(e);
261263
if(executeDefault !== undefined && !executeDefault) {
@@ -266,7 +268,7 @@ define(function (require) {
266268
if(!executeDefault) {
267269
e.preventDefault();
268270
}
269-
this.setTouchPoints(e);
271+
this._updateTouchCoords(e);
270272
}
271273
};
272274

@@ -313,7 +315,7 @@ define(function (require) {
313315
if(!executeDefault) {
314316
e.preventDefault();
315317
}
316-
this.setTouchPoints(e);
318+
this._updateTouchCoords(e);
317319
}
318320
};
319321

src/input/touch.js

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,35 @@ define(function (require) {
2222

2323
/**
2424
* The system variable touchY always contains the horizontal position of
25-
* one finger, relative to (0, 0) of the canvas. This is best used for
25+
* one finger, relative to (0, 0) of the canvas in the frame previous to the
26+
* current frame. This is best used for
2627
* single touch interactions. For multi-touch interactions, use the
2728
* touches[] array.
2829
*
2930
* @property touchY
3031
*/
3132
p5.prototype.touchY = 0;
3233

34+
/**
35+
* The system variable touchY always contains the horizontal position of
36+
* one finger, relative to (0, 0) of the canvas in the frame previous to the
37+
* current frame. This is best used for
38+
* single touch interactions. For multi-touch interactions, use the
39+
* touches[] array.
40+
*
41+
* @property ptouchX
42+
*/
43+
p5.prototype.ptouchX = 0;
44+
45+
/**
46+
* The system variable pmouseY always contains the vertical position of the
47+
* mouse in the frame previous to the current frame, relative to (0, 0) of
48+
* the canvas.
49+
*
50+
* @property ptouchY
51+
*/
52+
p5.prototype.ptouchY = 0;
53+
3354
/**
3455
* The system variable touches[] contains an array of the positions of all
3556
* current touch points, relative to (0, 0) of the canvas. Each element in
@@ -39,25 +60,28 @@ define(function (require) {
3960
*/
4061
p5.prototype.touches = [];
4162

42-
p5.prototype.setTouchPoints = function(e) {
43-
var context = this._isGlobal ? window : this;
44-
63+
p5.prototype._updateTouchCoords = function(e) {
4564
if(e.type === 'mousedown' || e.type === 'mousemove'){
46-
context._setProperty('touchX', context.mouseX);
47-
context._setProperty('touchY', context.mouseY);
65+
this._setProperty('touchX', this.mouseX);
66+
this._setProperty('touchY', this.mouseY);
4867
} else {
49-
context._setProperty('touchX', e.changedTouches[0].pageX);
50-
context._setProperty('touchY', e.changedTouches[0].pageY);
68+
this._setProperty('touchX', e.changedTouches[0].pageX);
69+
this._setProperty('touchY', e.changedTouches[0].pageY);
5170

5271
var touches = [];
5372
for(var i = 0; i < e.changedTouches.length; i++){
5473
var ct = e.changedTouches[i];
5574
touches[i] = {x: ct.pageX, y: ct.pageY};
5675
}
57-
context._setProperty('touches', touches);
76+
this._setProperty('touches', touches);
5877
}
5978
};
6079

80+
p5.prototype._updatePTouchCoords = function() {
81+
this._setProperty('ptouchX', this.touchX);
82+
this._setProperty('ptouchY', this.touchY);
83+
};
84+
6185
/**
6286
* The touchStarted() function is called once after every time a touch is
6387
* registered. If no touchStarted() function is defined, the mousePressed()
@@ -68,7 +92,7 @@ define(function (require) {
6892
p5.prototype.ontouchstart = function(e) {
6993
var context = this._isGlobal ? window : this;
7094
var executeDefault;
71-
this.setTouchPoints(e);
95+
this._updateTouchCoords(e);
7296
if(typeof context.touchStarted === 'function') {
7397
executeDefault = context.touchStarted(e);
7498
if(!executeDefault) {
@@ -79,7 +103,7 @@ define(function (require) {
79103
if(!executeDefault) {
80104
e.preventDefault();
81105
}
82-
this.setMouseButton(e);
106+
//this._setMouseButton(e);
83107
}
84108
};
85109

@@ -93,7 +117,7 @@ define(function (require) {
93117
p5.prototype.ontouchmove = function(e) {
94118
var context = this._isGlobal ? window : this;
95119
var executeDefault;
96-
this.setTouchPoints(e);
120+
this._updateTouchCoords(e);
97121
if (typeof context.touchMoved === 'function') {
98122
executeDefault = context.touchMoved(e);
99123
if(!executeDefault) {
@@ -104,7 +128,7 @@ define(function (require) {
104128
if(!executeDefault) {
105129
e.preventDefault();
106130
}
107-
this.updateMouseCoords(e);
131+
this._updateMouseCoords(e);
108132
}
109133
};
110134

@@ -128,7 +152,7 @@ define(function (require) {
128152
if(!executeDefault) {
129153
e.preventDefault();
130154
}
131-
this.updateMouseCoords(e);
155+
this._updateMouseCoords(e);
132156
}
133157
};
134158

0 commit comments

Comments
 (0)