2013-09-28 23:10:12 +04:00
|
|
|
/**
|
2013-05-28 01:42:53 +04:00
|
|
|
* @provide pskl.drawingtools.Move
|
|
|
|
*
|
|
|
|
* @require pskl.utils
|
|
|
|
*/
|
|
|
|
(function() {
|
2013-08-10 14:11:16 +04:00
|
|
|
var ns = $.namespace("pskl.drawingtools");
|
2013-05-28 01:42:53 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
ns.Move = function() {
|
2014-02-12 01:04:44 +04:00
|
|
|
this.toolId = ns.Move.TOOL_ID;
|
2013-08-10 14:11:16 +04:00
|
|
|
this.helpText = "Move tool";
|
2013-09-29 01:52:51 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
// Stroke's first point coordinates (set in applyToolAt)
|
|
|
|
this.startCol = null;
|
|
|
|
this.startRow = null;
|
|
|
|
};
|
2013-05-28 01:42:53 +04:00
|
|
|
|
2014-02-12 01:04:44 +04:00
|
|
|
ns.Move.TOOL_ID = "tool-move";
|
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
pskl.utils.inherit(ns.Move, ns.BaseTool);
|
2013-09-29 01:52:51 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
2013-12-06 01:12:48 +04:00
|
|
|
ns.Move.prototype.applyToolAt = function(col, row, color, frame, overlay, event) {
|
2013-08-10 14:11:16 +04:00
|
|
|
this.startCol = col;
|
|
|
|
this.startRow = row;
|
|
|
|
this.frameClone = frame.clone();
|
|
|
|
};
|
2013-05-28 01:42:53 +04:00
|
|
|
|
2013-12-06 01:12:48 +04:00
|
|
|
ns.Move.prototype.moveToolAt = function(col, row, color, frame, overlay, event) {
|
2013-08-10 14:11:16 +04:00
|
|
|
var colDiff = col - this.startCol, rowDiff = row - this.startRow;
|
|
|
|
this.shiftFrame(colDiff, rowDiff, frame, this.frameClone);
|
|
|
|
};
|
2013-05-28 01:42:53 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
ns.Move.prototype.shiftFrame = function (colDiff, rowDiff, frame, reference) {
|
|
|
|
var color;
|
|
|
|
for (var col = 0 ; col < frame.getWidth() ; col++) {
|
|
|
|
for (var row = 0 ; row < frame.getHeight() ; row++) {
|
|
|
|
if (reference.containsPixel(col - colDiff, row - rowDiff)) {
|
|
|
|
color = reference.getPixel(col - colDiff, row - rowDiff);
|
|
|
|
} else {
|
|
|
|
color = Constants.TRANSPARENT_COLOR;
|
|
|
|
}
|
|
|
|
frame.setPixel(col, row, color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2013-05-28 01:42:53 +04:00
|
|
|
|
2013-08-10 14:11:16 +04:00
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
2013-12-06 01:12:48 +04:00
|
|
|
ns.Move.prototype.releaseToolAt = function(col, row, color, frame, overlay, event) {
|
2013-08-10 14:11:16 +04:00
|
|
|
this.moveToolAt(col, row, color, frame, overlay);
|
|
|
|
};
|
2013-05-28 01:42:53 +04:00
|
|
|
})();
|