mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Moving (rendering related) DPI into FrameRenderer domain object
This commit is contained in:
parent
022773d3ab
commit
9411b2e3ae
@ -8,7 +8,7 @@
|
||||
|
||||
this.fps = parseInt($("#preview-fps")[0].value, 10);
|
||||
|
||||
this.renderer = new pskl.rendering.FrameRenderer();
|
||||
this.renderer = new pskl.rendering.FrameRenderer(dpi);
|
||||
};
|
||||
|
||||
ns.AnimatedPreviewController.prototype.init = function () {
|
||||
@ -55,7 +55,7 @@
|
||||
this.animIndex = 0;
|
||||
}
|
||||
|
||||
this.renderer.render(this.framesheet.getFrameByIndex(this.animIndex), this.previewCanvas, this.dpi);
|
||||
this.renderer.render(this.framesheet.getFrameByIndex(this.animIndex), this.previewCanvas);
|
||||
this.animIndex++;
|
||||
this.startAnimationTimer();
|
||||
};
|
||||
|
@ -11,19 +11,19 @@
|
||||
this.container = container;
|
||||
this.mainCanvas = this.createMainCanvas();
|
||||
this.overlayCanvas = this.createOverlayCanvas();
|
||||
this.renderer = new pskl.rendering.FrameRenderer();
|
||||
this.renderer = new pskl.rendering.FrameRenderer(dpi);
|
||||
};
|
||||
|
||||
ns.DrawingController.prototype.renderFrame = function () {
|
||||
this.renderer.render(this.frame, this.mainCanvas, this.dpi);
|
||||
this.renderer.render(this.frame, this.mainCanvas);
|
||||
};
|
||||
|
||||
ns.DrawingController.prototype.renderFramePixel = function (col, row) {
|
||||
this.renderer.drawPixel(col, row, this.frame, this.mainCanvas, this.dpi);
|
||||
this.renderer.drawPixel(col, row, this.frame, this.mainCanvas);
|
||||
};
|
||||
|
||||
ns.DrawingController.prototype.renderOverlay = function () {
|
||||
this.renderer.render(this.overlay, this.overlayCanvas, this.dpi);
|
||||
this.renderer.render(this.overlay, this.overlayCanvas);
|
||||
};
|
||||
|
||||
ns.DrawingController.prototype.clearOverlay = function () {
|
||||
|
@ -6,7 +6,7 @@
|
||||
this.framesheet = framesheet;
|
||||
this.container = container;
|
||||
|
||||
this.renderer = new pskl.rendering.FrameRenderer();
|
||||
this.renderer = new pskl.rendering.FrameRenderer(dpi);
|
||||
};
|
||||
|
||||
ns.PreviewFilmController.prototype.init = function() {
|
||||
@ -69,7 +69,7 @@
|
||||
piskel.duplicateFrame(tileNumber);
|
||||
});
|
||||
|
||||
this.renderer.render(this.framesheet.getFrameByIndex(tileNumber), canvasPreview, this.dpi);
|
||||
this.renderer.render(this.framesheet.getFrameByIndex(tileNumber), canvasPreview);
|
||||
canvasContainer.appendChild(canvasPreview);
|
||||
previewTileRoot.appendChild(canvasContainer);
|
||||
previewTileRoot.appendChild(canvasPreviewDuplicateAction);
|
||||
|
@ -1,20 +1,29 @@
|
||||
(function () {
|
||||
var ns = $.namespace("pskl.rendering");
|
||||
ns.FrameRenderer = function () {};
|
||||
|
||||
ns.FrameRenderer.prototype.render = function (frame, canvas, dpi) {
|
||||
this.dpi = null;
|
||||
|
||||
ns.FrameRenderer = function (dpi) {
|
||||
if(dpi == undefined || isNaN(dpi)) {
|
||||
throw "Bad FrameRenderer initialization. <dpi> not well defined.";
|
||||
}
|
||||
|
||||
this.dpi = dpi;
|
||||
};
|
||||
|
||||
ns.FrameRenderer.prototype.render = function (frame, canvas) {
|
||||
for(var col = 0, width = frame.getWidth(); col < width; col++) {
|
||||
for(var row = 0, height = frame.getHeight(); row < height; row++) {
|
||||
this.drawPixel(col, row, frame, canvas, dpi);
|
||||
this.drawPixel(col, row, frame, canvas, this.dpi);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ns.FrameRenderer.prototype.drawPixel = function (col, row, frame, canvas, dpi) {
|
||||
ns.FrameRenderer.prototype.drawPixel = function (col, row, frame, canvas) {
|
||||
var context = canvas.getContext('2d');
|
||||
var color = frame.getPixel(col, row);
|
||||
if(color == Constants.TRANSPARENT_COLOR) {
|
||||
context.clearRect(col * dpi, row * dpi, dpi, dpi);
|
||||
context.clearRect(col * this.dpi, row * this.dpi, this.dpi, this.dpi);
|
||||
}
|
||||
else {
|
||||
if(color != Constants.SELECTION_TRANSPARENT_COLOR) {
|
||||
@ -22,7 +31,7 @@
|
||||
$.publish(Events.COLOR_USED, [color]);
|
||||
}
|
||||
context.fillStyle = color;
|
||||
context.fillRect(col * dpi, row * dpi, dpi, dpi);
|
||||
context.fillRect(col * this.dpi, row * this.dpi, this.dpi, this.dpi);
|
||||
}
|
||||
};
|
||||
})();
|
Loading…
Reference in New Issue
Block a user