1- /*! p5.js v0.3.2 August 15 , 2014 */
1+ /*! p5.js v0.3.2 August 16 , 2014 */
22var shim = function ( require ) {
33 window . requestDraw = function ( ) {
44 return window . requestAnimationFrame || window . webkitRequestAnimationFrame || window . mozRequestAnimationFrame || window . oRequestAnimationFrame || window . msRequestAnimationFrame || function ( callback , element ) {
@@ -2953,8 +2953,13 @@ var inputmouse = function (require, core, constants) {
29532953 var mousePos = getMousePos ( this . _curElement . elt , e ) ;
29542954 this . _setProperty ( 'pmouseX' , this . mouseX ) ;
29552955 this . _setProperty ( 'pmouseY' , this . mouseY ) ;
2956- this . _setProperty ( 'mouseX' , mousePos . x ) ;
2957- this . _setProperty ( 'mouseY' , mousePos . y ) ;
2956+ if ( e . type === 'touchstart' || e . type === 'touchmove' ) {
2957+ this . _setProperty ( 'mouseX' , this . touchX ) ;
2958+ this . _setProperty ( 'mouseY' , this . touchY ) ;
2959+ } else {
2960+ this . _setProperty ( 'mouseX' , mousePos . x ) ;
2961+ this . _setProperty ( 'mouseY' , mousePos . y ) ;
2962+ }
29582963 this . _setProperty ( 'pwinMouseX' , this . winMouseX ) ;
29592964 this . _setProperty ( 'pwinMouseY' , this . winMouseY ) ;
29602965 this . _setProperty ( 'winMouseX' , e . pageX ) ;
@@ -2974,6 +2979,10 @@ var inputmouse = function (require, core, constants) {
29742979 this . _setProperty ( 'mouseButton' , constants . RIGHT ) ;
29752980 } else {
29762981 this . _setProperty ( 'mouseButton' , constants . LEFT ) ;
2982+ if ( e . type === 'touchstart' || e . type === 'touchmove' ) {
2983+ this . _setProperty ( 'mouseX' , this . touchX ) ;
2984+ this . _setProperty ( 'mouseY' , this . touchY ) ;
2985+ }
29772986 }
29782987 } ;
29792988 p5 . prototype . onmousemove = function ( e ) {
@@ -2984,13 +2993,15 @@ var inputmouse = function (require, core, constants) {
29842993 context . mouseMoved ( e ) ;
29852994 } else if ( typeof context . touchMoved === 'function' ) {
29862995 e . preventDefault ( ) ;
2996+ this . setTouchPoints ( e ) ;
29872997 context . touchMoved ( e ) ;
29882998 }
29892999 } else {
29903000 if ( typeof context . mouseDragged === 'function' ) {
29913001 context . mouseDragged ( e ) ;
29923002 } else if ( typeof context . touchMoved === 'function' ) {
29933003 e . preventDefault ( ) ;
3004+ this . setTouchPoints ( e ) ;
29943005 context . touchMoved ( e ) ;
29953006 }
29963007 }
@@ -3004,6 +3015,7 @@ var inputmouse = function (require, core, constants) {
30043015 context . mousePressed ( e ) ;
30053016 } else if ( typeof context . touchStarted === 'function' ) {
30063017 e . preventDefault ( ) ;
3018+ this . setTouchPoints ( e ) ;
30073019 context . touchStarted ( e ) ;
30083020 }
30093021 } ;
@@ -3015,6 +3027,7 @@ var inputmouse = function (require, core, constants) {
30153027 context . mouseReleased ( e ) ;
30163028 } else if ( typeof context . touchEnded === 'function' ) {
30173029 e . preventDefault ( ) ;
3030+ this . setTouchPoints ( e ) ;
30183031 context . touchEnded ( e ) ;
30193032 }
30203033 } ;
@@ -3067,48 +3080,56 @@ var inputtouch = function (require, core) {
30673080 p5 . prototype . touches = [ ] ;
30683081 p5 . prototype . setTouchPoints = function ( e ) {
30693082 var context = this . _isGlobal ? window : this ;
3070- context . _setProperty ( 'touchX' , e . changedTouches [ 0 ] . pageX ) ;
3071- context . _setProperty ( 'touchY' , e . changedTouches [ 0 ] . pageY ) ;
3072- var touches = [ ] ;
3073- for ( var i = 0 ; i < e . changedTouches . length ; i ++ ) {
3074- var ct = e . changedTouches [ i ] ;
3075- touches [ i ] = {
3076- x : ct . pageX ,
3077- y : ct . pageY
3078- } ;
3083+ if ( e . type === 'mousedown' || e . type === 'mousemove' ) {
3084+ context . _setProperty ( 'touchX' , context . mouseX ) ;
3085+ context . _setProperty ( 'touchY' , context . mouseY ) ;
3086+ } else {
3087+ context . _setProperty ( 'touchX' , e . changedTouches [ 0 ] . pageX ) ;
3088+ context . _setProperty ( 'touchY' , e . changedTouches [ 0 ] . pageY ) ;
3089+ var touches = [ ] ;
3090+ for ( var i = 0 ; i < e . changedTouches . length ; i ++ ) {
3091+ var ct = e . changedTouches [ i ] ;
3092+ touches [ i ] = {
3093+ x : ct . pageX ,
3094+ y : ct . pageY
3095+ } ;
3096+ }
3097+ context . _setProperty ( 'touches' , touches ) ;
30793098 }
3080- context . _setProperty ( 'touches' , touches ) ;
30813099 } ;
30823100 p5 . prototype . ontouchstart = function ( e ) {
30833101 var context = this . _isGlobal ? window : this ;
3084- context . setTouchPoints ( e ) ;
3102+ this . setTouchPoints ( e ) ;
30853103 if ( typeof context . touchStarted === 'function' ) {
30863104 e . preventDefault ( ) ;
30873105 context . touchStarted ( e ) ;
30883106 } else if ( typeof context . mousePressed === 'function' ) {
30893107 e . preventDefault ( ) ;
3108+ this . setMouseButton ( e ) ;
30903109 context . mousePressed ( e ) ;
30913110 }
30923111 } ;
30933112 p5 . prototype . ontouchmove = function ( e ) {
30943113 var context = this . _isGlobal ? window : this ;
3095- context . setTouchPoints ( e ) ;
3114+ this . setTouchPoints ( e ) ;
30963115 if ( typeof context . touchMoved === 'function' ) {
30973116 e . preventDefault ( ) ;
30983117 context . touchMoved ( e ) ;
30993118 } else if ( typeof context . mouseDragged === 'function' ) {
31003119 e . preventDefault ( ) ;
3120+ this . updateMouseCoords ( e ) ;
31013121 context . mouseDragged ( e ) ;
31023122 }
31033123 } ;
31043124 p5 . prototype . ontouchend = function ( e ) {
31053125 var context = this . _isGlobal ? window : this ;
3106- context . setTouchPoints ( e ) ;
3126+ this . setTouchPoints ( e ) ;
31073127 if ( typeof context . touchEnded === 'function' ) {
31083128 e . preventDefault ( ) ;
31093129 context . touchEnded ( e ) ;
31103130 } else if ( typeof context . mouseReleased === 'function' ) {
31113131 e . preventDefault ( ) ;
3132+ this . updateMouseCoords ( e ) ;
31123133 context . mouseReleased ( e ) ;
31133134 }
31143135 } ;
0 commit comments