mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Fixed CanvasRenderer regression + added unit test
This commit is contained in:
parent
123ea31191
commit
5cb1d0cd03
@ -50,10 +50,11 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
ns.CanvasRenderer.prototype.renderLine_ = function (color, x, y, width, context) {
|
ns.CanvasRenderer.prototype.renderLine_ = function (color, x, y, width, context) {
|
||||||
if(color != Constants.TRANSPARENT_COLOR) {
|
if(color == Constants.TRANSPARENT_COLOR) {
|
||||||
|
color = this.transparentColor_;
|
||||||
|
}
|
||||||
context.fillStyle = color;
|
context.fillStyle = color;
|
||||||
context.fillRect(x, y, 1, width);
|
context.fillRect(x, y, 1, width);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ns.CanvasRenderer.prototype.createCanvas_ = function (zoom) {
|
ns.CanvasRenderer.prototype.createCanvas_ = function (zoom) {
|
||||||
|
39
test/js/rendering/CanvasRendererTest.js
Normal file
39
test/js/rendering/CanvasRendererTest.js
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
describe("Canvas Renderer test", function() {
|
||||||
|
var BLACK = '#000000';
|
||||||
|
var WHITE = '#ffffff';
|
||||||
|
var TRANS = Constants.TRANSPARENT_COLOR;
|
||||||
|
|
||||||
|
var toFrameGrid = function (normalGrid) {
|
||||||
|
var frameGrid = [];
|
||||||
|
var w = normalGrid[0].length;
|
||||||
|
var h = normalGrid.length;
|
||||||
|
for (var x = 0 ; x < w ; x++) {
|
||||||
|
frameGrid[x] = [];
|
||||||
|
for (var y = 0 ; y < h ; y++) {
|
||||||
|
frameGrid[x][y] = normalGrid[y][x];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return frameGrid;
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(function() {});
|
||||||
|
afterEach(function() {});
|
||||||
|
|
||||||
|
it("draws transparent as white by default", function() {
|
||||||
|
// create frame
|
||||||
|
var frame = pskl.model.Frame.fromPixelGrid(toFrameGrid([
|
||||||
|
[BLACK, TRANS],
|
||||||
|
[TRANS, BLACK]
|
||||||
|
]));
|
||||||
|
|
||||||
|
var renderer = new pskl.rendering.CanvasRenderer(frame, 1);
|
||||||
|
var canvas = renderer.render();
|
||||||
|
|
||||||
|
var frameFromCanvas = pskl.utils.FrameUtils.createFromImage(canvas);
|
||||||
|
|
||||||
|
expect(frameFromCanvas.getPixel(0,0)).toBe(BLACK);
|
||||||
|
expect(frameFromCanvas.getPixel(0,1)).toBe(WHITE);
|
||||||
|
expect(frameFromCanvas.getPixel(1,0)).toBe(WHITE);
|
||||||
|
expect(frameFromCanvas.getPixel(1,1)).toBe(BLACK);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user