2012-08-31 08:45:07 +00:00
|
|
|
/*
|
|
|
|
* @provide pskl.drawingtools.SimplePen
|
|
|
|
*
|
|
|
|
* @require pskl.utils
|
|
|
|
*/
|
|
|
|
(function() {
|
|
|
|
var ns = $.namespace("pskl.drawingtools");
|
|
|
|
|
|
|
|
ns.SimplePen = function() {
|
|
|
|
this.toolId = "tool-pen"
|
|
|
|
};
|
|
|
|
|
2012-09-02 15:49:28 +00:00
|
|
|
this.previousCol = null;
|
|
|
|
this.previousRow = null;
|
|
|
|
|
2012-08-31 08:45:07 +00:00
|
|
|
pskl.utils.inherit(ns.SimplePen, ns.BaseTool);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
2012-09-01 22:44:55 +00:00
|
|
|
ns.SimplePen.prototype.applyToolAt = function(col, row, frame, color, canvas, dpi) {
|
|
|
|
|
2012-09-02 15:49:28 +00:00
|
|
|
this.previousCol = col;
|
|
|
|
this.previousRow = row;
|
|
|
|
|
2012-09-01 22:44:55 +00:00
|
|
|
// Change model:
|
2012-08-31 08:45:07 +00:00
|
|
|
var color = pskl.utils.normalizeColor(color);
|
|
|
|
if (color != frame[col][row]) {
|
|
|
|
frame[col][row] = color;
|
|
|
|
}
|
|
|
|
|
2012-09-01 22:44:55 +00:00
|
|
|
// Draw on canvas:
|
|
|
|
// TODO: Remove that when we have the centralized redraw loop
|
|
|
|
this.drawPixelInCanvas(col, row, canvas, color, dpi);
|
2012-08-31 08:45:07 +00:00
|
|
|
};
|
|
|
|
|
2012-09-01 22:44:55 +00:00
|
|
|
ns.SimplePen.prototype.moveToolAt = function(col, row, frame, color, canvas, dpi) {
|
2012-09-02 15:49:28 +00:00
|
|
|
|
|
|
|
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;
|
2012-08-31 08:45:07 +00:00
|
|
|
};
|
2012-09-02 23:34:11 +00:00
|
|
|
|
|
|
|
ns.SimplePen.prototype.releaseToolAt = function(col, row, frame, color, canvas, dpi) {
|
|
|
|
// TODO: Create a afterRelease event hook or out that deep in the model
|
|
|
|
$.publish(Events.FRAMESHEET_UPDATED);
|
|
|
|
};
|
2012-08-31 08:45:07 +00:00
|
|
|
})();
|