Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scaling retina coordinates for all callbacks #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions js/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -241,8 +260,6 @@
context.millis += context.dt;
context.now = clock;

trigger( context.update );

// Pre draw

if ( is2D ) {
Expand All @@ -260,6 +277,7 @@

// Draw

trigger( context.update );
trigger( context.draw );

// Post draw
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion js/sketch.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.