Skip to content

Commit

Permalink
added Render.setSize, closes #955, closes #595
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Mar 26, 2023
1 parent 013698b commit fc05839
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/render/Render.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,36 @@ var Mouse = require('../core/Mouse');
canvas.style.height = options.height + 'px';
};

/**
* Sets the render `width` and `height`.
*
* Updates the canvas accounting for `render.options.pixelRatio`.
*
* Updates the bottom right render bound `render.bounds.max` relative to the provided `width` and `height`.
* The top left render bound `render.bounds.min` isn't changed.
*
* Follow this call with `Render.lookAt` if you need to change the render bounds.
*
* See also `Render.setPixelRatio`.
* @method setSize
* @param {render} render
* @param {number} width The width (in CSS pixels)
* @param {number} height The height (in CSS pixels)
*/
Render.setSize = function(render, width, height) {
render.options.width = width;
render.options.height = height;
render.bounds.max.x = render.bounds.min.x + width;
render.bounds.max.y = render.bounds.min.y + height;

if (render.options.pixelRatio !== 1) {
Render.setPixelRatio(render, render.options.pixelRatio);
} else {
render.canvas.width = width;
render.canvas.height = height;
}
};

/**
* Positions and sizes the viewport around the given object bounds.
* Objects must have at least one of the following properties:
Expand Down

0 comments on commit fc05839

Please sign in to comment.