Merge pull request #200 from juliandescottes/enhancement-horizontal-mirror
Enhancement : modifiers for Mirror pen
This commit is contained in:
commit
84e757768e
2 changed files with 30 additions and 19 deletions
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
})();
|
||||
|
|
Loading…
Reference in a new issue