1- /*! p5.js v0.3.5 September 09 , 2014 */
1+ /*! p5.js v0.3.5 September 11 , 2014 */
22var 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 ;
0 commit comments