Issue #256 : apply move tool to all layers / all frames

This commit is contained in:
jdescottes 2015-09-02 00:36:03 +02:00
parent 6b6674a04d
commit 479df8ced7
3 changed files with 47 additions and 8 deletions

View File

@ -0,0 +1,23 @@
var ns = $.namespace('pskl.tools');
ns.ToolsHelper = {
/**
* Retrieve a list of frames containing either :
* - only the current frame (useAllLayers = false, useAllFrames = false)
* - only the frames of the current layer (useAllLayers = false, useAllFrames = true)
* - only the frames at the currentIndex in each layer (useAllLayers = true, useAllFrames = false)
* - all frames (useAllLayers = true, useAllFrames = true)
*
* @param {Boolean} useAllLayers true if frames from all layers should be returned
* @param {Boolean} useAllFrames true if frames at any index should be returned
* @return {Array[Frame]} list of Frame instances, can be empty
*/
getTargetFrames : function (useAllLayers, useAllFrames) {
var currentFrameIndex = pskl.app.piskelController.getCurrentFrameIndex();
var layers = useAllLayers ? pskl.app.piskelController.getLayers() : [pskl.app.piskelController.getCurrentLayer()];
return layers.reduce(function (previous, layer) {
var frames = useAllFrames ? layer.getFrames() : [layer.getFrameAt(currentFrameIndex)];
return previous.concat(frames);
}, []);
}
};

View File

@ -25,13 +25,14 @@
ns.Move.prototype.applyToolAt = function(col, row, color, frame, overlay, event) {
this.startCol = col;
this.startRow = row;
this.frameClone = frame.clone();
this.currentFrame = frame;
this.currentFrameClone = frame.clone();
};
ns.Move.prototype.moveToolAt = function(col, row, color, frame, overlay, event) {
var colDiff = col - this.startCol;
var rowDiff = row - this.startRow;
this.shiftFrame(colDiff, rowDiff, frame, this.frameClone, event);
this.shiftFrame(colDiff, rowDiff, frame, this.currentFrameClone, event);
};
ns.Move.prototype.shiftFrame = function (colDiff, rowDiff, frame, reference, event) {
@ -42,7 +43,7 @@
for (var row = 0 ; row < h ; row++) {
var x = col - colDiff;
var y = row - rowDiff;
if (event.shiftKey) {
if (event.altKey) {
x = (x + w) % w;
y = (y + h) % h;
}
@ -60,19 +61,33 @@
* @override
*/
ns.Move.prototype.releaseToolAt = function(col, row, color, frame, overlay, event) {
this.moveToolAt(col, row, color, frame, overlay, event);
var colDiff = col - this.startCol;
var rowDiff = row - this.startRow;
pskl.tools.ToolsHelper.getTargetFrames(event.ctrlKey, event.shiftKey).forEach(function (f) {
// for the current frame, the backup clone should be reused as reference
// the current frame has been modified by the user action already
var reference = this.currentFrame == f ? this.currentFrameClone : f.clone();
this.shiftFrame(colDiff, rowDiff, f, reference, event);
}.bind(this));
this.raiseSaveStateEvent({
colDiff : col - this.startCol,
rowDiff : row - this.startRow,
colDiff : colDiff,
rowDiff : rowDiff,
ctrlKey : event.ctrlKey,
altKey : event.altKey,
shiftKey : event.shiftKey
});
};
ns.Move.prototype.replay = function(frame, replayData) {
var event = {
shiftKey : replayData.shiftKey
shiftKey : replayData.shiftKey,
altKey : replayData.altKey,
ctrlKey : replayData.ctrlKey
};
this.shiftFrame(replayData.colDiff, replayData.rowDiff, frame, frame.clone(), event);
pskl.tools.ToolsHelper.getTargetFrames(event.ctrlKey, event.shiftKey).forEach(function (frame) {
this.shiftFrame(replayData.colDiff, replayData.rowDiff, frame, frame.clone(), event);
}.bind(this));
};
})();

View File

@ -162,6 +162,7 @@
"js/service/FileDropperService.js",
// Tools
"js/tools/ToolsHelper.js",
"js/tools/Tool.js",
"js/tools/IconMarkupRenderer.js",
"js/tools/drawing/BaseTool.js",