mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Small updates to FrameRenderer for fun
This commit is contained in:
parent
df405d917f
commit
e4373ad133
@ -1,16 +1,13 @@
|
|||||||
(function () {
|
(function () {
|
||||||
var ns = $.namespace("pskl.rendering");
|
var ns = $.namespace("pskl.rendering");
|
||||||
|
|
||||||
this.dpi = null;
|
|
||||||
this.canvas = null;
|
|
||||||
|
|
||||||
ns.FrameRenderer = function (container, renderingOptions, className) {
|
ns.FrameRenderer = function (container, renderingOptions, className) {
|
||||||
if(container == undefined) {
|
if(container == undefined) {
|
||||||
throw "Bad FrameRenderer initialization. <container> undefined.";
|
throw "Bad FrameRenderer initialization. <container> undefined.";
|
||||||
}
|
}
|
||||||
this.container = container;
|
this.container = container;
|
||||||
|
|
||||||
if(renderingOptions == undefined || renderingOptions.dpi == undefined || isNaN(dpi)) {
|
if(renderingOptions == undefined || renderingOptions.dpi == undefined) {
|
||||||
throw "Bad FrameRenderer initialization. <dpi> not well defined.";
|
throw "Bad FrameRenderer initialization. <dpi> not well defined.";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,24 +63,25 @@
|
|||||||
ns.FrameRenderer.prototype.getCanvas_ = function (frame) {
|
ns.FrameRenderer.prototype.getCanvas_ = function (frame) {
|
||||||
if(this.canvasConfigDirty) {
|
if(this.canvasConfigDirty) {
|
||||||
$(this.canvas).remove();
|
$(this.canvas).remove();
|
||||||
var width = frame.getWidth(),
|
this.canvas = this.createCanvasForFrame_(frame);
|
||||||
height = frame.getHeight();
|
|
||||||
|
|
||||||
var canvas = document.createElement("canvas");
|
|
||||||
canvas.setAttribute("width", width * this.dpi);
|
|
||||||
canvas.setAttribute("height", height * this.dpi);
|
|
||||||
|
|
||||||
var canvasClassname = "canvas";
|
|
||||||
if(this.className) {
|
|
||||||
canvasClassname += " " + this.className;
|
|
||||||
}
|
|
||||||
canvas.setAttribute("class", canvasClassname);
|
|
||||||
|
|
||||||
this.canvas = canvas;
|
|
||||||
this.container.appendChild(this.canvas);
|
this.container.appendChild(this.canvas);
|
||||||
|
|
||||||
this.canvasConfigDirty = false;
|
this.canvasConfigDirty = false;
|
||||||
}
|
}
|
||||||
return this.canvas;
|
return this.canvas;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ns.FrameRenderer.prototype.createCanvasForFrame_ = function (frame) {
|
||||||
|
var canvas = document.createElement("canvas");
|
||||||
|
canvas.setAttribute("width", frame.getWidth() * this.dpi);
|
||||||
|
canvas.setAttribute("height", frame.getHeight() * this.dpi);
|
||||||
|
|
||||||
|
canvas.classList.add("canvas");
|
||||||
|
if(this.className) canvas.classList.add(this.className);
|
||||||
|
|
||||||
|
return canvas;
|
||||||
|
};
|
||||||
})();
|
})();
|
Loading…
Reference in New Issue
Block a user