fix : renderer resize on window resize

This commit is contained in:
jdescottes 2013-11-02 00:00:38 +01:00
parent 8a380b6c78
commit e0d63bf295
3 changed files with 14 additions and 5 deletions

View File

@ -10,10 +10,11 @@
this.setFPS(Constants.DEFAULT.FPS); this.setFPS(Constants.DEFAULT.FPS);
var zoom = this.calculateZoom_(); var zoom = this.calculateZoom_();
var frame = this.piskelController.getCurrentFrame();
var renderingOptions = { var renderingOptions = {
"zoom": zoom, "zoom": zoom,
"height" : this.piskelController.getCurrentFrame().getHeight() * zoom, "height" : frame.getHeight() * zoom,
"width" : this.piskelController.getCurrentFrame().getWidth() * zoom "width" : frame.getWidth() * zoom
}; };
this.renderer = new pskl.rendering.frame.FrameRenderer(this.container, renderingOptions); this.renderer = new pskl.rendering.frame.FrameRenderer(this.container, renderingOptions);
@ -58,15 +59,18 @@
* Calculate the preview DPI depending on the framesheet size * Calculate the preview DPI depending on the framesheet size
*/ */
ns.AnimatedPreviewController.prototype.calculateZoom_ = function () { ns.AnimatedPreviewController.prototype.calculateZoom_ = function () {
var frame = this.piskelController.getCurrentFrame();
var previewSize = 200, var previewSize = 200,
hZoom = previewSize / this.piskelController.getCurrentFrame().getHeight(), hZoom = previewSize / frame.getHeight(),
wZoom = previewSize / this.piskelController.getCurrentFrame().getWidth(); wZoom = previewSize / frame.getWidth();
return Math.min(hZoom, wZoom); return Math.min(hZoom, wZoom);
}; };
ns.AnimatedPreviewController.prototype.updateZoom_ = function () { ns.AnimatedPreviewController.prototype.updateZoom_ = function () {
var frame = this.piskelController.getCurrentFrame();
var zoom = this.calculateZoom_(); var zoom = this.calculateZoom_();
this.renderer.setZoom(zoom); this.renderer.setZoom(zoom);
this.renderer.setDisplaySize(frame.getWidth() * zoom, frame.getHeight() * zoom);
}; };
})(); })();

View File

@ -110,6 +110,11 @@
} }
}, },
ns.DrawingController.prototype.onFrameSizeChanged_ = function () {
this.compositeRenderer.setZoom(this.calculateZoom_());
this.compositeRenderer.setDisplaySize(this.getContainerWidth_(), this.getContainerHeight_());
};
/** /**
* @private * @private
*/ */

View File

@ -212,7 +212,7 @@
* @private * @private
*/ */
ns.FrameRenderer.prototype.renderFrame_ = function (frame) { ns.FrameRenderer.prototype.renderFrame_ = function (frame) {
if (!this.canvas) { if (!this.canvas || frame.getWidth() != this.canvas.width || frame.getHeight() != this.canvas.height) {
this.canvas = pskl.CanvasUtils.createCanvas(frame.getWidth(), frame.getHeight()); this.canvas = pskl.CanvasUtils.createCanvas(frame.getWidth(), frame.getHeight());
} }