0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-23 09:26:51 -05:00

added scale support to Render

This commit is contained in:
liabru 2014-05-04 12:37:45 +01:00
parent 0c107b21ed
commit 1f8ee5ccca

View file

@ -132,6 +132,11 @@ var Render = {};
context.globalCompositeOperation = 'source-over';
// handle bounds
var boundsWidth = render.bounds.max.x - render.bounds.min.x,
boundsHeight = render.bounds.max.y - render.bounds.min.y,
boundsScaleX = boundsWidth / render.options.width,
boundsScaleY = boundsHeight / render.options.height;
if (options.hasBounds) {
// filter out bodies that are not in view
for (i = 0; i < allBodies.length; i++) {
@ -158,7 +163,8 @@ var Render = {};
constraints.push(constraint);
}
// translate the view
// transform the view
context.scale(1 / boundsScaleX, 1 / boundsScaleY);
context.translate(-render.bounds.min.x, -render.bounds.min.y);
} else {
constraints = allConstraints;
@ -199,8 +205,10 @@ var Render = {};
if (options.showDebug)
Render.debug(engine, context);
if (options.hasBounds)
context.translate(render.bounds.min.x, render.bounds.min.y);
if (options.hasBounds) {
// revert view transforms
context.setTransform(1, 0, 0, 1, 0, 0);
}
};
/**
@ -751,8 +759,15 @@ var Render = {};
options = render.options,
bounds;
if (options.hasBounds)
if (options.hasBounds) {
var boundsWidth = render.bounds.max.x - render.bounds.min.x,
boundsHeight = render.bounds.max.y - render.bounds.min.y,
boundsScaleX = boundsWidth / render.options.width,
boundsScaleY = boundsHeight / render.options.height;
context.scale(1 / boundsScaleX, 1 / boundsScaleY);
context.translate(-render.bounds.min.x, -render.bounds.min.y);
}
for (var i = 0; i < selected.length; i++) {
var item = selected[i].data;
@ -812,7 +827,7 @@ var Render = {};
}
if (options.hasBounds)
context.translate(render.bounds.min.x, render.bounds.min.y);
context.setTransform(1, 0, 0, 1, 0, 0);
};
/**