Skip to content

Commit

Permalink
fix issues with render pixel ratio, closes #686, closes #687
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Nov 17, 2018
1 parent 773510f commit d577477
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/core/Mouse.js
Expand Up @@ -34,7 +34,7 @@ var Common = require('../core/Common');
mouse.scale = { x: 1, y: 1 };
mouse.wheelDelta = 0;
mouse.button = -1;
mouse.pixelRatio = mouse.element.getAttribute('data-pixel-ratio') || 1;
mouse.pixelRatio = parseInt(mouse.element.getAttribute('data-pixel-ratio'), 10) || 1;

mouse.sourceEvents = {
mousemove: null,
Expand Down
15 changes: 11 additions & 4 deletions src/render/Render.js
Expand Up @@ -155,7 +155,6 @@ var Mouse = require('../core/Mouse');
canvas.height = options.height * pixelRatio;
canvas.style.width = options.width + 'px';
canvas.style.height = options.height + 'px';
render.context.scale(pixelRatio, pixelRatio);
};

/**
Expand Down Expand Up @@ -267,7 +266,11 @@ var Mouse = require('../core/Mouse');
boundsScaleX = boundsWidth / render.options.width,
boundsScaleY = boundsHeight / render.options.height;

render.context.scale(1 / boundsScaleX, 1 / boundsScaleY);
render.context.setTransform(
render.options.pixelRatio / boundsScaleX, 0, 0,
render.options.pixelRatio / boundsScaleY, 0, 0
);

render.context.translate(-render.bounds.min.x, -render.bounds.min.y);
};

Expand Down Expand Up @@ -348,15 +351,19 @@ var Mouse = require('../core/Mouse');
// update mouse
if (render.mouse) {
Mouse.setScale(render.mouse, {
x: (render.bounds.max.x - render.bounds.min.x) / render.canvas.width,
y: (render.bounds.max.y - render.bounds.min.y) / render.canvas.height
x: (render.bounds.max.x - render.bounds.min.x) / render.options.width,
y: (render.bounds.max.y - render.bounds.min.y) / render.options.height
});

Mouse.setOffset(render.mouse, render.bounds.min);
}
} else {
constraints = allConstraints;
bodies = allBodies;

if (render.options.pixelRatio !== 1) {
render.context.setTransform(render.options.pixelRatio, 0, 0, render.options.pixelRatio, 0, 0);
}
}

if (!options.wireframes || (engine.enableSleeping && options.showSleeping)) {
Expand Down

0 comments on commit d577477

Please sign in to comment.