diff --git a/js/sketch.js b/js/sketch.js index dc1347d..9ba40d8 100755 --- a/js/sketch.js +++ b/js/sketch.js @@ -207,15 +207,34 @@ node = eventMap[ index ]; + var retinaScaleWrapper = function (fn) { + + return function () { + + context.save(); + context.scale( ratio, ratio ); + + var result = fn.apply(this, arguments); + + context.restore(); + + return result; + }; + }; + if ( isString( node ) ) target[ ( on ? 'add' : 'remove' ) + 'EventListener' ].call( target, node, handler, false ); - else if ( isFunction( node ) ) + else if ( isFunction( node ) ) { + + if ( is2D && context.retina ) + + node = retinaScaleWrapper( node ); handler = node; - else target = node; + } else target = node; } } @@ -241,8 +260,6 @@ context.millis += context.dt; context.now = clock; - trigger( context.update ); - // Pre draw if ( is2D ) { @@ -260,6 +277,7 @@ // Draw + trigger( context.update ); trigger( context.draw ); // Post draw @@ -313,13 +331,6 @@ touch.x = touch.pageX - bounds.left - (win.scrollX || win.pageXOffset); touch.y = touch.pageY - bounds.top - (win.scrollY || win.pageYOffset); - if ( context.retina && is2D && ratio ) { - - touch.x *= ratio; - touch.y *= ratio; - - } - return touch; } diff --git a/js/sketch.min.js b/js/sketch.min.js index 8ec8fd7..dfdc25a 100644 --- a/js/sketch.min.js +++ b/js/sketch.min.js @@ -1,2 +1,2 @@ /* Copyright (C) 2013 Justin Windle, http://soulwire.co.uk */ -!function(e,t){"object"==typeof exports?module.exports=t(e,e.document):"function"==typeof define&&define.amd?define(function(){return t(e,e.document)}):e.Sketch=t(e,e.document)}("undefined"!=typeof window?window:this,function(e,t){"use strict";function n(e){return"[object Array]"==Object.prototype.toString.call(e)}function o(e){return"function"==typeof e}function r(e){return"number"==typeof e}function i(e){return"string"==typeof e}function u(e){return C[e]||String.fromCharCode(e)}function a(e,t,n){for(var o in t)!n&&o in e||(e[o]=t[o]);return e}function c(e,t){return function(){e.apply(t,arguments)}}function s(e){var t={};for(var n in e)o(e[n])?t[n]=c(e[n],e):t[n]=e[n];return t}function l(e){function t(t){o(t)&&t.apply(e,[].splice.call(arguments,1))}function n(e){for(_=0;_