mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Moved drawing logic outside of tools. Previews and animations are broken. Performance is somehow degraded
This commit is contained in:
@ -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;
|
||||
|
Reference in New Issue
Block a user