Moved drawing logic outside of tools. Previews and animations are broken. Performance is somehow degraded

This commit is contained in:
juliandescottes
2012-09-04 14:10:16 +02:00
parent 561c35c882
commit 4c4faa88e6
13 changed files with 249 additions and 263 deletions

View File

@ -7,7 +7,7 @@
var ns = $.namespace("pskl.drawingtools");
ns.SimplePen = function() {
this.toolId = "tool-pen"
this.toolId = "tool-pen";
};
this.previousCol = null;
@ -18,20 +18,17 @@
/**
* @override
*/
ns.SimplePen.prototype.applyToolAt = function(col, row, frame, color, canvas, dpi) {
ns.SimplePen.prototype.applyToolAt = function(col, row, color, drawer) {
this.previousCol = col;
this.previousRow = row;
if (color != frame[col][row]) {
frame[col][row] = color;
}
drawer.frame.setPixel(col, row, color);
// Draw on canvas:
// TODO: Remove that when we have the centralized redraw loop
this.drawPixelInCanvas(col, row, canvas, color, dpi);
drawer.renderFramePixel(col, row);
};
ns.SimplePen.prototype.moveToolAt = function(col, row, frame, color, canvas, dpi) {
ns.SimplePen.prototype.moveToolAt = function(col, row, color, drawer) {
if((Math.abs(col - this.previousCol) > 1) || (Math.abs(row - this.previousRow) > 1)) {
// The pen movement is too fast for the mousemove frequency, there is a gap between the
@ -39,11 +36,11 @@
// We fill the gap by calculating missing dots (simple linear interpolation) and draw them.
var interpolatedPixels = this.getLinePixels_(col, this.previousCol, row, this.previousRow);
for(var i=0, l=interpolatedPixels.length; i<l; i++) {
this.applyToolAt(interpolatedPixels[i].col, interpolatedPixels[i].row, frame, color, canvas, dpi);
this.applyToolAt(interpolatedPixels[i].col, interpolatedPixels[i].row, color, drawer);
}
}
else {
this.applyToolAt(col, row, frame, color, canvas, dpi);
this.applyToolAt(col, row, color, drawer);
}
this.previousCol = col;