2012-09-06 23:21:05 +00:00
|
|
|
/*
|
|
|
|
* @provide pskl.drawingtools.Move
|
|
|
|
*
|
|
|
|
* @require pskl.utils
|
|
|
|
*/
|
|
|
|
(function() {
|
|
|
|
var ns = $.namespace("pskl.drawingtools");
|
|
|
|
|
|
|
|
ns.Move = function() {
|
|
|
|
this.toolId = "tool-move"
|
2012-09-15 18:25:45 +00:00
|
|
|
this.helpText = "Move tool";
|
2012-09-06 23:21:05 +00:00
|
|
|
|
|
|
|
// Stroke's first point coordinates (set in applyToolAt)
|
|
|
|
this.startCol = null;
|
|
|
|
this.startRow = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
pskl.utils.inherit(ns.Move, ns.BaseTool);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
2012-09-10 21:26:12 +00:00
|
|
|
ns.Move.prototype.applyToolAt = function(col, row, color, frame, overlay) {
|
2012-09-06 23:21:05 +00:00
|
|
|
this.startCol = col;
|
|
|
|
this.startRow = row;
|
2012-09-10 21:26:12 +00:00
|
|
|
this.frameClone = frame.clone();
|
2012-09-06 23:21:05 +00:00
|
|
|
};
|
|
|
|
|
2012-09-10 21:26:12 +00:00
|
|
|
ns.Move.prototype.moveToolAt = function(col, row, color, frame, overlay) {
|
2012-09-06 23:21:05 +00:00
|
|
|
var colDiff = col - this.startCol, rowDiff = row - this.startRow;
|
2012-09-16 05:56:22 +00:00
|
|
|
this.shiftFrame(colDiff, rowDiff, frame, this.frameClone);
|
2012-09-06 23:21:05 +00: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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
2012-09-10 21:26:12 +00:00
|
|
|
ns.Move.prototype.releaseToolAt = function(col, row, color, frame, overlay) {
|
|
|
|
this.moveToolAt(col, row, color, frame, overlay);
|
2012-09-06 23:21:05 +00:00
|
|
|
};
|
|
|
|
})();
|