mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Add interpolation when using the pen tool quickly
This commit is contained in:
@ -10,6 +10,9 @@
|
||||
this.toolId = "tool-pen"
|
||||
};
|
||||
|
||||
this.previousCol = null;
|
||||
this.previousRow = null;
|
||||
|
||||
pskl.utils.inherit(ns.SimplePen, ns.BaseTool);
|
||||
|
||||
/**
|
||||
@ -17,6 +20,9 @@
|
||||
*/
|
||||
ns.SimplePen.prototype.applyToolAt = function(col, row, frame, color, canvas, dpi) {
|
||||
|
||||
this.previousCol = col;
|
||||
this.previousRow = row;
|
||||
|
||||
// Change model:
|
||||
var color = pskl.utils.normalizeColor(color);
|
||||
if (color != frame[col][row]) {
|
||||
@ -29,6 +35,21 @@
|
||||
};
|
||||
|
||||
ns.SimplePen.prototype.moveToolAt = function(col, row, frame, color, canvas, dpi) {
|
||||
this.applyToolAt(col, row, frame, color, canvas, dpi);
|
||||
|
||||
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
|
||||
// current point and the previously drawn one.
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.applyToolAt(col, row, frame, color, canvas, dpi);
|
||||
}
|
||||
|
||||
this.previousCol = col;
|
||||
this.previousRow = row;
|
||||
};
|
||||
})();
|
||||
|
Reference in New Issue
Block a user