Skip to content

Commit d577477

Browse files
committed
fix issues with render pixel ratio, closes #686, closes #687
1 parent 773510f commit d577477

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/core/Mouse.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var Common = require('../core/Common');
3434
mouse.scale = { x: 1, y: 1 };
3535
mouse.wheelDelta = 0;
3636
mouse.button = -1;
37-
mouse.pixelRatio = mouse.element.getAttribute('data-pixel-ratio') || 1;
37+
mouse.pixelRatio = parseInt(mouse.element.getAttribute('data-pixel-ratio'), 10) || 1;
3838

3939
mouse.sourceEvents = {
4040
mousemove: null,

src/render/Render.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ var Mouse = require('../core/Mouse');
155155
canvas.height = options.height * pixelRatio;
156156
canvas.style.width = options.width + 'px';
157157
canvas.style.height = options.height + 'px';
158-
render.context.scale(pixelRatio, pixelRatio);
159158
};
160159

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

270-
render.context.scale(1 / boundsScaleX, 1 / boundsScaleY);
269+
render.context.setTransform(
270+
render.options.pixelRatio / boundsScaleX, 0, 0,
271+
render.options.pixelRatio / boundsScaleY, 0, 0
272+
);
273+
271274
render.context.translate(-render.bounds.min.x, -render.bounds.min.y);
272275
};
273276

@@ -348,15 +351,19 @@ var Mouse = require('../core/Mouse');
348351
// update mouse
349352
if (render.mouse) {
350353
Mouse.setScale(render.mouse, {
351-
x: (render.bounds.max.x - render.bounds.min.x) / render.canvas.width,
352-
y: (render.bounds.max.y - render.bounds.min.y) / render.canvas.height
354+
x: (render.bounds.max.x - render.bounds.min.x) / render.options.width,
355+
y: (render.bounds.max.y - render.bounds.min.y) / render.options.height
353356
});
354357

355358
Mouse.setOffset(render.mouse, render.bounds.min);
356359
}
357360
} else {
358361
constraints = allConstraints;
359362
bodies = allBodies;
363+
364+
if (render.options.pixelRatio !== 1) {
365+
render.context.setTransform(render.options.pixelRatio, 0, 0, render.options.pixelRatio, 0, 0);
366+
}
360367
}
361368

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

0 commit comments

Comments
 (0)