mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Removing states in class members and using a SimplePen#draw method instead.
This commit is contained in:
parent
5a469202e9
commit
90c2ed3470
@ -16,22 +16,14 @@
|
|||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
ns.DitheringTool.prototype.getToolColor = function() {
|
ns.DitheringTool.prototype.applyToolAt = function(col, row, frame, overlay, event) {
|
||||||
var usePrimaryColor = (this.col_ + this.row_) % 2;
|
var usePrimaryColor = (col + row) % 2;
|
||||||
usePrimaryColor =
|
usePrimaryColor =
|
||||||
pskl.app.mouseStateService.isRightButtonPressed() ? !usePrimaryColor : usePrimaryColor;
|
pskl.app.mouseStateService.isRightButtonPressed() ? !usePrimaryColor : usePrimaryColor;
|
||||||
var ditheringColor = usePrimaryColor ?
|
var ditheringColor = usePrimaryColor ?
|
||||||
pskl.app.selectedColorsService.getPrimaryColor() :
|
pskl.app.selectedColorsService.getPrimaryColor() :
|
||||||
pskl.app.selectedColorsService.getSecondaryColor();
|
pskl.app.selectedColorsService.getSecondaryColor();
|
||||||
return ditheringColor;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
this.draw(ditheringColor, col, row, frame, overlay);
|
||||||
* @override
|
|
||||||
*/
|
|
||||||
ns.DitheringTool.prototype.applyToolAt = function(col, row, frame, overlay, event) {
|
|
||||||
this.col_ = col;
|
|
||||||
this.row_ = row;
|
|
||||||
this.superclass.applyToolAt.call(this, col, row, frame, overlay, event);
|
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
@ -41,42 +41,44 @@
|
|||||||
/**
|
/**
|
||||||
* @Override
|
* @Override
|
||||||
*/
|
*/
|
||||||
ns.Lighten.prototype.getToolColor = function() {
|
ns.Lighten.prototype.applyToolAt = function(col, row, frame, overlay, event, mouseButton) {
|
||||||
var color = this.superclass.getToolColor.call();
|
var modifiedColor = this.getModifiedColor_(col, row, frame, overlay, event);
|
||||||
|
this.draw(modifiedColor, col, row, frame, overlay);
|
||||||
|
};
|
||||||
|
|
||||||
var usedPixels = this.isDarken_ ? this.usedPixels_.darken : this.usedPixels_.lighten;
|
ns.Lighten.prototype.getModifiedColor_ = function(col, row, frame, overlay, event) {
|
||||||
var key = this.col_ + '-' + this.row_;
|
var overlayColor = overlay.getPixel(col, row);
|
||||||
var doNotModify = this.isTransparent_ || (this.isSinglePass_ && usedPixels[key]);
|
var frameColor = frame.getPixel(col, row);
|
||||||
|
var pixelColor = overlayColor === Constants.TRANSPARENT_COLOR ? frameColor : overlayColor;
|
||||||
|
var isDarken = pskl.utils.UserAgent.isMac ? event.metaKey : event.ctrlKey;
|
||||||
|
var isTransparent = pixelColor === Constants.TRANSPARENT_COLOR;
|
||||||
|
var isSinglePass = event.shiftKey;
|
||||||
|
|
||||||
|
var usedPixels = isDarken ? this.usedPixels_.darken : this.usedPixels_.lighten;
|
||||||
|
var key = col + '-' + row;
|
||||||
|
var doNotModify = isTransparent || (isSinglePass && usedPixels[key]);
|
||||||
|
|
||||||
|
var color;
|
||||||
if (doNotModify) {
|
if (doNotModify) {
|
||||||
color = window.tinycolor(this.pixelColor_);
|
color = window.tinycolor(pixelColor);
|
||||||
} else {
|
} else {
|
||||||
var step = this.isSinglePass_ ? DEFAULT_STEP * 2 : DEFAULT_STEP;
|
var step = isSinglePass ? DEFAULT_STEP * 2 : DEFAULT_STEP;
|
||||||
if (this.isDarken_) {
|
if (isDarken) {
|
||||||
color = window.tinycolor.darken(this.pixelColor_, step);
|
color = window.tinycolor.darken(pixelColor, step);
|
||||||
} else {
|
} else {
|
||||||
color = window.tinycolor.lighten(this.pixelColor_, step);
|
color = window.tinycolor.lighten(pixelColor, step);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (color) {
|
if (color) {
|
||||||
usedPixels[key] = true;
|
// Convert tinycolor color to string format.
|
||||||
|
color = color.toRgbString();
|
||||||
|
} else {
|
||||||
|
// Not sure why this check exists in the first place.
|
||||||
|
// Fallback to the always defined SimplePen tool color in this case.
|
||||||
|
color = this.getToolColor();
|
||||||
}
|
}
|
||||||
return color.toRgbString();
|
usedPixels[key] = true;
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
return color;
|
||||||
* @Override
|
|
||||||
*/
|
|
||||||
ns.Lighten.prototype.applyToolAt = function(col, row, frame, overlay, event, mouseButton) {
|
|
||||||
var overlayColor = overlay.getPixel(col, row);
|
|
||||||
var frameColor = frame.getPixel(col, row);
|
|
||||||
|
|
||||||
this.col_ = col;
|
|
||||||
this.row_ = row;
|
|
||||||
this.pixelColor_ = overlayColor === Constants.TRANSPARENT_COLOR ? frameColor : overlayColor;
|
|
||||||
this.isDarken_ = pskl.utils.UserAgent.isMac ? event.metaKey : event.ctrlKey;
|
|
||||||
this.isTransparent_ = this.pixelColor_ === Constants.TRANSPARENT_COLOR;
|
|
||||||
this.isSinglePass_ = event.shiftKey;
|
|
||||||
|
|
||||||
this.superclass.applyToolAt.call(this, col, row, frame, overlay, event);
|
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
@ -22,11 +22,15 @@
|
|||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
ns.SimplePen.prototype.applyToolAt = function(col, row, frame, overlay, event) {
|
ns.SimplePen.prototype.applyToolAt = function(col, row, frame, overlay, event) {
|
||||||
|
var color = this.getToolColor();
|
||||||
|
this.draw(color, col, row, frame, overlay);
|
||||||
|
};
|
||||||
|
|
||||||
|
ns.SimplePen.prototype.draw = function(color, col, row, frame, overlay) {
|
||||||
this.previousCol = col;
|
this.previousCol = col;
|
||||||
this.previousRow = row;
|
this.previousRow = row;
|
||||||
var color = this.getToolColor();
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,9 @@
|
|||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
ns.VerticalMirrorPen.prototype.applyToolAt = function(col, row, frame, overlay, event) {
|
ns.VerticalMirrorPen.prototype.applyToolAt = function(col, row, frame, overlay, event) {
|
||||||
this.superclass.applyToolAt.call(this, col, row, frame, overlay);
|
var color = this.getToolColor();
|
||||||
|
this.draw(color, col, row, frame, overlay);
|
||||||
|
|
||||||
this.backupPreviousPositions_();
|
this.backupPreviousPositions_();
|
||||||
|
|
||||||
var mirroredCol = this.getSymmetricCol_(col, frame);
|
var mirroredCol = this.getSymmetricCol_(col, frame);
|
||||||
@ -37,15 +39,15 @@
|
|||||||
|
|
||||||
var hasCtrlKey = pskl.utils.UserAgent.isMac ? event.metaKey : event.ctrlKey;
|
var hasCtrlKey = pskl.utils.UserAgent.isMac ? event.metaKey : event.ctrlKey;
|
||||||
if (!hasCtrlKey) {
|
if (!hasCtrlKey) {
|
||||||
this.superclass.applyToolAt.call(this, mirroredCol, row, frame, overlay);
|
this.draw(color, mirroredCol, row, frame, overlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.shiftKey || hasCtrlKey) {
|
if (event.shiftKey || hasCtrlKey) {
|
||||||
this.superclass.applyToolAt.call(this, col, mirroredRow, frame, overlay);
|
this.draw(color, col, mirroredRow, frame, overlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.shiftKey) {
|
if (event.shiftKey) {
|
||||||
this.superclass.applyToolAt.call(this, mirroredCol, mirroredRow, frame, overlay);
|
this.draw(color, mirroredCol, mirroredRow, frame, overlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.restorePreviousPositions_();
|
this.restorePreviousPositions_();
|
||||||
|
Loading…
Reference in New Issue
Block a user