Enhancement : modifiers for Mirror pen

This commit is contained in:
jdescottes
2014-07-05 17:04:18 +02:00
parent 26a463c4b4
commit 96fc5f2418
2 changed files with 30 additions and 19 deletions

View File

@@ -22,13 +22,14 @@
* @override * @override
*/ */
ns.SimplePen.prototype.applyToolAt = function(col, row, color, frame, overlay, event) { ns.SimplePen.prototype.applyToolAt = function(col, row, color, frame, overlay, event) {
this.previousCol = col;
this.previousRow = row;
overlay.setPixel(col, row, color); overlay.setPixel(col, row, color);
if (color === Constants.TRANSPARENT_COLOR) { if (color === Constants.TRANSPARENT_COLOR) {
frame.setPixel(col, row, color); frame.setPixel(col, row, color);
} }
this.previousCol = col;
this.previousRow = row;
this.pixels.push({ this.pixels.push({
col : col, col : col,
row : row, row : row,

View File

@@ -5,22 +5,19 @@
this.superclass.constructor.call(this); this.superclass.constructor.call(this);
this.toolId = "tool-vertical-mirror-pen"; this.toolId = "tool-vertical-mirror-pen";
this.helpText = "vertical mirror pen tool"; this.helpText = "Vertical Mirror pen tool (hold CTRL for Horizontal, hold SHIFT for both)";
this.swap = null;
}; };
pskl.utils.inherit(ns.VerticalMirrorPen, ns.SimplePen); pskl.utils.inherit(ns.VerticalMirrorPen, ns.SimplePen);
ns.VerticalMirrorPen.prototype.backupPreviousPositions_ = function () {
ns.VerticalMirrorPen.prototype.setMirrorContext = function() { this.backupPreviousCol = this.previousCol;
this.swap = this.previousCol; this.backupPreviousRow = this.previousRow;
this.previousCol = this.mirroredPreviousCol;
}; };
ns.VerticalMirrorPen.prototype.unsetMirrorContext = function() { ns.VerticalMirrorPen.prototype.restorePreviousPositions_ = function () {
this.mirroredPreviousCol = this.previousCol; this.previousCol = this.backupPreviousCol;
this.previousCol = this.swap; this.previousRow = this.backupPreviousRow;
}; };
/** /**
@@ -28,19 +25,32 @@
*/ */
ns.VerticalMirrorPen.prototype.applyToolAt = function(col, row, color, frame, overlay, event) { ns.VerticalMirrorPen.prototype.applyToolAt = function(col, row, color, frame, overlay, event) {
this.superclass.applyToolAt.call(this, col, row, color, frame, overlay); this.superclass.applyToolAt.call(this, col, row, color, frame, overlay);
this.backupPreviousPositions_();
var mirroredCol = this.getSymmetricCol_(col, frame); var mirroredCol = this.getSymmetricCol_(col, frame);
this.mirroredPreviousCol = mirroredCol; var mirroredRow = this.getSymmetricRow_(row, frame);
this.setMirrorContext(); if (!event.ctrlKey) {
this.superclass.applyToolAt.call(this, mirroredCol, row, color, frame, overlay); this.superclass.applyToolAt.call(this, mirroredCol, row, color, frame, overlay);
this.unsetMirrorContext(); }
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) { ns.VerticalMirrorPen.prototype.getSymmetricCol_ = function(col, frame) {
return frame.getWidth() - col - 1; return frame.getWidth() - col - 1;
}; };
ns.VerticalMirrorPen.prototype.getSymmetricRow_ = function(row, frame) {
return frame.getHeight() - row - 1;
};
})(); })();