diff --git a/js/selection/BaseSelection.js b/js/selection/BaseSelection.js index 2458cd1d..e0a1fc81 100644 --- a/js/selection/BaseSelection.js +++ b/js/selection/BaseSelection.js @@ -7,6 +7,7 @@ ns.BaseSelection.prototype.reset = function () { this.pixels = []; + this.hasPastedContent = false; }; ns.BaseSelection.prototype.move = function (colDiff, rowDiff) { @@ -28,5 +29,6 @@ pixelWithCopiedColor.copiedColor = targetFrame.getPixel(pixelWithCopiedColor.col, pixelWithCopiedColor.row); } + this.hasPastedContent = true; }; })(); \ No newline at end of file diff --git a/js/selection/SelectionManager.js b/js/selection/SelectionManager.js index 8cb7a2cc..621c805d 100644 --- a/js/selection/SelectionManager.js +++ b/js/selection/SelectionManager.js @@ -72,7 +72,7 @@ }; ns.SelectionManager.prototype.onPaste_ = function(evt) { - if(this.currentSelection) { + if(this.currentSelection && this.currentSelection.hasPastedContent) { var pixels = this.currentSelection.pixels; var currentFrame = this.framesheet.getCurrentFrame(); for(var i=0, l=pixels.length; i 0) { - loopCount ++; - - var currentItem = queue.pop(); - frame.setPixel(currentItem.col, currentItem.row, replacementColor); - pixels.push({"col": currentItem.col, "row": currentItem.row }); - - for (var i = 0; i < 4; i++) { - var nextCol = currentItem.col + dx[i] - var nextRow = currentItem.row + dy[i] - try { - if (frame.containsPixel(nextCol, nextRow) && frame.getPixel(nextCol, nextRow) == targetColor) { - queue.push({"col": nextCol, "row": nextRow }); - } - } catch(e) { - // Frame out of bound exception. - } - } - - // Security loop breaker: - if(loopCount > 10 * cellCount) { - console.log("loop breaker called") - break; - } - } - return pixels; + return paintedPixels; }, + /** + * Apply the paintbucket tool in a frame at the (col, row) initial position + * with the replacement color. + * + * @param frame pskl.model.Frame The frame target in which we want to paintbucket + * @param col number Column coordinate in the frame + * @param row number Row coordinate in the frame + * @param replacementColor string Hexadecimal color used to fill the area + * + * @return an array of the pixel coordinates paint with the replacement color + */ paintSimilarConnectedPixelsFromFrame: function(frame, col, row, replacementColor) { /** * Queue linear Flood-fill (node, target-color, replacement-color): @@ -146,6 +110,7 @@ * * @private */ + var paintedPixels = []; var queue = []; var dy = [-1, 0, 1, 0]; var dx = [0, 1, 0, -1]; @@ -168,7 +133,8 @@ var currentItem = queue.pop(); frame.setPixel(currentItem.col, currentItem.row, replacementColor); - + paintedPixels.push({"col": currentItem.col, "row": currentItem.row }); + for (var i = 0; i < 4; i++) { var nextCol = currentItem.col + dx[i] var nextRow = currentItem.row + dy[i] @@ -187,6 +153,7 @@ break; } } + return paintedPixels; } }; })(); \ No newline at end of file