diff --git a/src/js/drawingtools/SimplePen.js b/src/js/drawingtools/SimplePen.js index f36ec66..3f8bab6 100644 --- a/src/js/drawingtools/SimplePen.js +++ b/src/js/drawingtools/SimplePen.js @@ -22,13 +22,14 @@ * @override */ ns.SimplePen.prototype.applyToolAt = function(col, row, color, frame, overlay, event) { + this.previousCol = col; + this.previousRow = row; + overlay.setPixel(col, row, color); if (color === Constants.TRANSPARENT_COLOR) { frame.setPixel(col, row, color); } - this.previousCol = col; - this.previousRow = row; this.pixels.push({ col : col, row : row, diff --git a/src/js/drawingtools/VerticalMirrorPen.js b/src/js/drawingtools/VerticalMirrorPen.js index 44841ea..e2e5e39 100644 --- a/src/js/drawingtools/VerticalMirrorPen.js +++ b/src/js/drawingtools/VerticalMirrorPen.js @@ -5,22 +5,19 @@ this.superclass.constructor.call(this); this.toolId = "tool-vertical-mirror-pen"; - this.helpText = "vertical mirror pen tool"; - - this.swap = null; + this.helpText = "Vertical Mirror pen tool (hold CTRL for Horizontal, hold SHIFT for both)"; }; pskl.utils.inherit(ns.VerticalMirrorPen, ns.SimplePen); - - ns.VerticalMirrorPen.prototype.setMirrorContext = function() { - this.swap = this.previousCol; - this.previousCol = this.mirroredPreviousCol; + ns.VerticalMirrorPen.prototype.backupPreviousPositions_ = function () { + this.backupPreviousCol = this.previousCol; + this.backupPreviousRow = this.previousRow; }; - ns.VerticalMirrorPen.prototype.unsetMirrorContext = function() { - this.mirroredPreviousCol = this.previousCol; - this.previousCol = this.swap; + ns.VerticalMirrorPen.prototype.restorePreviousPositions_ = function () { + this.previousCol = this.backupPreviousCol; + this.previousRow = this.backupPreviousRow; }; /** @@ -28,19 +25,32 @@ */ ns.VerticalMirrorPen.prototype.applyToolAt = function(col, row, color, frame, overlay, event) { this.superclass.applyToolAt.call(this, col, row, color, frame, overlay); + this.backupPreviousPositions_(); var mirroredCol = this.getSymmetricCol_(col, frame); - this.mirroredPreviousCol = mirroredCol; + var mirroredRow = this.getSymmetricRow_(row, frame); - this.setMirrorContext(); - this.superclass.applyToolAt.call(this, mirroredCol, row, color, frame, overlay); - this.unsetMirrorContext(); + if (!event.ctrlKey) { + this.superclass.applyToolAt.call(this, mirroredCol, row, color, frame, overlay); + } + + if (event.shiftKey || event.ctrlKey) { + this.superclass.applyToolAt.call(this, col, mirroredRow, color, frame, overlay); + } + + if (event.shiftKey) { + this.superclass.applyToolAt.call(this, mirroredCol, mirroredRow, color, frame, overlay); + } + + + this.restorePreviousPositions_(); }; - /** - * @private - */ ns.VerticalMirrorPen.prototype.getSymmetricCol_ = function(col, frame) { return frame.getWidth() - col - 1; }; + + ns.VerticalMirrorPen.prototype.getSymmetricRow_ = function(row, frame) { + return frame.getHeight() - row - 1; + }; })();